Skip to content

Commit 72d9761

Browse files
Abse2001Your Name
andauthored
contribution-board performance test (#114)
Co-authored-by: Your Name <[email protected]>
1 parent 1826d26 commit 72d9761

File tree

4 files changed

+1125
-0
lines changed

4 files changed

+1125
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import type { Meta } from "@storybook/react"
2+
import { Circuit } from "@tscircuit/core"
3+
import type React from "react"
4+
import { PCBViewer } from "../../../PCBViewer"
5+
import { usePICO_W } from "./usePICO"
6+
import { useHS91L02W2C01 } from "./useHS91L02W2C01"
7+
import { WS2812B_2020 as LedWithIc } from "./useWS2812B_2020"
8+
9+
export const contributionBoard: React.FC = () => {
10+
const circuit = new Circuit()
11+
type Point = { x: number; y: number }
12+
13+
type GridCellPositions = {
14+
index: number
15+
center: Point
16+
topLeft: Point
17+
bottomRight: Point
18+
}
19+
20+
type GridOptions = {
21+
rows: number
22+
cols: number
23+
xSpacing?: number
24+
ySpacing?: number
25+
width?: number
26+
height?: number
27+
offsetX?: number
28+
offsetY?: number
29+
yDirection?: "cartesian" | "up-is-negative"
30+
}
31+
32+
// ToDO import from tscircuit utils in the future
33+
function grid({
34+
rows,
35+
cols,
36+
xSpacing,
37+
ySpacing,
38+
width,
39+
height,
40+
offsetX = 0,
41+
offsetY = 0,
42+
yDirection = "cartesian",
43+
}: GridOptions): GridCellPositions[] {
44+
// Calculate cell dimensions
45+
const cellWidth = width ? width / cols : (xSpacing ?? 1)
46+
const cellHeight = height ? height / rows : (ySpacing ?? 1)
47+
48+
const cells: GridCellPositions[] = []
49+
50+
for (let row = 0; row < rows; row++) {
51+
for (let col = 0; col < cols; col++) {
52+
const index = row * cols + col
53+
54+
// Calculate center position
55+
const centerX = offsetX + col * cellWidth + cellWidth / 2
56+
const rawCenterY = offsetY + row * cellHeight + cellHeight / 2
57+
58+
// Adjust Y coordinate based on yDirection
59+
const centerY =
60+
yDirection === "cartesian"
61+
? offsetY + (rows - 1 - row) * cellHeight + cellHeight / 2
62+
: rawCenterY
63+
64+
cells.push({
65+
row,
66+
col,
67+
index,
68+
center: { x: centerX, y: centerY },
69+
topLeft: {
70+
x: centerX - cellWidth / 2,
71+
y: centerY + cellHeight / 2,
72+
},
73+
bottomRight: {
74+
x: centerX + cellWidth / 2,
75+
y: centerY - cellHeight / 2,
76+
},
77+
} as any)
78+
}
79+
}
80+
81+
return cells
82+
}
83+
84+
const U1 = usePICO_W("U1")
85+
const U2 = useHS91L02W2C01("U2")
86+
circuit.add(
87+
<board width="316mm" height="52mm" routingDisabled>
88+
<U1 pcbRotation="90deg" pcbX={-122 - 15} pcbY={0} />
89+
<U2
90+
GND="net.GND"
91+
VCC={"net.V5"}
92+
SDA={U1.GP26_ADC0_I2C1SDA}
93+
SCL={U1.GP27_ADC1_I2C1SCL}
94+
schX={-7}
95+
schY={0}
96+
pcbX={-122 + 5}
97+
pcbY={19}
98+
/>
99+
{grid({
100+
cols: 53,
101+
rows: 7,
102+
xSpacing: 5,
103+
ySpacing: 5,
104+
offsetX: 3 - 122,
105+
offsetY: -32 / 2 - 7.5,
106+
}).map(({ center, index }) => {
107+
const ledName = `LED${index + 1}`
108+
const prevLedName = index > 0 ? `LED${index}` : null
109+
const capName = `C_${ledName}`
110+
const ledSchX = ((center.x / 2) * 8) / 5 + 2 + 101
111+
const ledSchY = 5 + center.y / 1.5
112+
return (
113+
<>
114+
<LedWithIc
115+
schX={ledSchX}
116+
schY={ledSchY}
117+
name={ledName}
118+
pcbX={center.x}
119+
pcbY={center.y}
120+
/>
121+
<trace from={`.${ledName} .GND`} to="net.GND" />
122+
<trace from={`.${ledName} .VDD`} to="net.V5" />
123+
{prevLedName && (
124+
<trace from={`.${prevLedName} .DO`} to={`.${ledName} .DI`} />
125+
)}
126+
<capacitor
127+
name={capName}
128+
footprint="0402"
129+
capacitance="100nF"
130+
pcbX={center.x}
131+
pcbY={center.y - 2.2}
132+
pcbRotation="180deg"
133+
schX={ledSchX}
134+
schY={ledSchY - 1.1}
135+
schRotation="180deg"
136+
/>
137+
<trace from={`.${capName} .neg`} to="net.GND" />
138+
<trace from={`.${capName} .pos`} to="net.V5" />
139+
</>
140+
)
141+
})}
142+
143+
<capacitor
144+
name="C1"
145+
capacitance="100uF"
146+
footprint="1206"
147+
schX={5}
148+
pcbX={-122}
149+
pcbRotation="90deg"
150+
schRotation="270deg"
151+
/>
152+
<trace from=".C1 .neg" to="net.GND" />
153+
<trace from=".C1 .pos" to="net.V5" />
154+
155+
<trace from=".LED1 .DI" to={U1.GP11_SPI1TX_I2C1SCL} />
156+
<trace from={U1.GND1} to="net.GND" />
157+
<trace from={U1.GND2} to="net.GND" />
158+
<trace from={U1.GND3} to="net.GND" />
159+
<trace from={U1.GND4} to="net.GND" />
160+
<trace from={U1.GND5} to="net.GND" />
161+
<trace from={U1.GND6} to="net.GND" />
162+
<trace from={U1.GND7} to="net.GND" />
163+
164+
<trace from={U1.VBUS} to="net.V5" />
165+
<footprint>
166+
<hole pcbX={-32 - 122} pcbY={20} diameter="4.8mm" />
167+
<hole pcbX={-32 - 122} pcbY={-20} diameter="4.8mm" />
168+
<hole pcbX={32 + 122} pcbY={20} diameter="4.8mm" />
169+
<hole pcbX={32 + 122} pcbY={-20} diameter="4.8mm" />
170+
</footprint>
171+
</board>,
172+
)
173+
174+
const soup = circuit.getCircuitJson()
175+
176+
return (
177+
<div style={{ backgroundColor: "black" }}>
178+
<PCBViewer soup={soup} />
179+
</div>
180+
)
181+
}
182+
183+
const meta: Meta<typeof contributionBoard> = {
184+
title: "contribution-board-performance-test/contribution-board",
185+
component: contributionBoard,
186+
}
187+
188+
export default meta
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { createUseComponent } from "@tscircuit/core"
2+
import type { CommonLayoutProps } from "@tscircuit/props"
3+
4+
const pinLabels = {
5+
pin1: ["pin1", "GND"],
6+
pin2: ["pin2", "VCC"],
7+
pin3: ["pin3", "SCL"],
8+
pin4: ["pin4", "SDA"],
9+
} as const
10+
11+
interface Props extends CommonLayoutProps {
12+
name: string
13+
}
14+
15+
export const HS91L02W2C01 = (props: Props) => {
16+
return (
17+
<chip
18+
{...props}
19+
cadModel={{
20+
objUrl:
21+
"https://modelcdn.tscircuit.com/easyeda_models/download?uuid=9018832d564840e08b96db89bf75c8cc&pn=C5248081",
22+
rotationOffset: { x: 0, y: 0, z: 0 },
23+
positionOffset: { x: 16.05, y: 1.5, z: 0 },
24+
}}
25+
pinLabels={pinLabels}
26+
supplierPartNumbers={{
27+
jlcpcb: ["C5248081"],
28+
}}
29+
manufacturerPartNumber="HS91L02W2C01"
30+
footprint={
31+
<footprint>
32+
<platedhole
33+
portHints={["pin1"]}
34+
pcbX="0mm"
35+
pcbY="-3.8099999999999454mm"
36+
outerDiameter="1.5999967999999998mm"
37+
holeDiameter="0.9999979999999999mm"
38+
shape="circle"
39+
/>
40+
<platedhole
41+
portHints={["pin2"]}
42+
pcbX="0mm"
43+
pcbY="-1.2699999999999818mm"
44+
outerDiameter="1.5999967999999998mm"
45+
holeDiameter="0.9999979999999999mm"
46+
shape="circle"
47+
/>
48+
<platedhole
49+
portHints={["pin3"]}
50+
pcbX="0mm"
51+
pcbY="1.2699999999999818mm"
52+
outerDiameter="1.5999967999999998mm"
53+
holeDiameter="0.9999979999999999mm"
54+
shape="circle"
55+
/>
56+
<platedhole
57+
portHints={["pin4"]}
58+
pcbX="0mm"
59+
pcbY="3.810000000000059mm"
60+
outerDiameter="1.5999967999999998mm"
61+
holeDiameter="0.9999979999999999mm"
62+
shape="circle"
63+
/>
64+
<silkscreenpath
65+
route={[
66+
{ x: -1.4999970000000076, y: 5.999987999999917 },
67+
{ x: 36.49992699999984, y: 5.999987999999917 },
68+
{ x: 36.49992699999984, y: -5.999987999999917 },
69+
{ x: -1.4999970000000076, y: -5.999987999999917 },
70+
{ x: -1.4999970000000076, y: 5.999987999999917 },
71+
]}
72+
/>
73+
<silkscreentext
74+
text="1"
75+
pcbX="1.659127999999896mm"
76+
pcbY="-5.676899999999932mm"
77+
anchorAlignment="bottom_left"
78+
fontSize="2mm"
79+
/>
80+
</footprint>
81+
}
82+
/>
83+
)
84+
}
85+
86+
export const useHS91L02W2C01 = createUseComponent(HS91L02W2C01, pinLabels)

0 commit comments

Comments
 (0)