Skip to content

Commit 8d79487

Browse files
committed
feature: add boardgen command for generating parts files.
This adds a Go utility that generates SVG and JSON files for adding a new board to the TinyGo Playground simulator parts library. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 1d52c0b commit 8d79487

4 files changed

Lines changed: 1734 additions & 0 deletions

File tree

cmd/boardgen/README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# boardgen
2+
3+
`boardgen` is a Go utility that generates SVG and JSON files for adding a new
4+
board to the TinyGo Playground simulator [parts library](../../parts/).
5+
6+
The generated files follow the style conventions documented in
7+
[parts/README.md](../../parts/README.md): hand-written SVG style, millimeter
8+
units (1px == 1mm), absolute SVG path commands, and consistent pin/LED shapes
9+
across boards.
10+
11+
## Usage
12+
13+
```bash
14+
go run ./cmd/boardgen [flags]
15+
```
16+
17+
### Examples
18+
19+
**Pico-like board** (horizontal, 20 pins top/bottom, USB on the left, built-in LED):
20+
21+
```bash
22+
go run ./cmd/boardgen \
23+
-name my-pico \
24+
-human "My Pico Board" \
25+
-pins-top 20 -pins-bottom 20 \
26+
-usb left -led \
27+
-output ./parts
28+
```
29+
30+
**Vertical board** (15 pins on each side, USB on top):
31+
32+
```bash
33+
go run ./cmd/boardgen \
34+
-name my-nano \
35+
-pins-left 15 -pins-right 15 \
36+
-usb top -led \
37+
-orientation vertical \
38+
-output ./parts
39+
```
40+
41+
**Four-sided board** (pins on all edges, custom PCB color):
42+
43+
```bash
44+
go run ./cmd/boardgen \
45+
-name my-devkit \
46+
-pins-top 10 -pins-bottom 10 \
47+
-pins-left 8 -pins-right 8 \
48+
-usb left -led \
49+
-color "#10A2A1" \
50+
-output ./parts
51+
```
52+
53+
**Minimal board** (only bottom pins, no USB, no LED):
54+
55+
```bash
56+
go run ./cmd/boardgen \
57+
-name my-breakout \
58+
-pins-bottom 8 \
59+
-output ./parts
60+
```
61+
62+
**Fixed-size board** (explicit dimensions, rectangular GND pads):
63+
64+
```bash
65+
go run ./cmd/boardgen \
66+
-name my-wide-board \
67+
-pins-top 10 -pins-bottom 10 \
68+
-width 60 -height 30 \
69+
-rect-gnd \
70+
-usb left -led \
71+
-output ./parts
72+
```
73+
74+
## Flags
75+
76+
| Flag | Description | Default |
77+
|------|-------------|---------|
78+
| `-name` | Board name — used for filenames (`<name>.svg`, `<name>.json`) | *required* |
79+
| `-human` | Human-readable board name shown in the UI | title-cased `-name` |
80+
| `-orientation` | Board orientation: `horizontal` or `vertical` | `horizontal` |
81+
| `-pins-top` | Number of pins on the top edge | `0` |
82+
| `-pins-bottom` | Number of pins on the bottom edge | `0` |
83+
| `-pins-left` | Number of pins on the left edge | `0` |
84+
| `-pins-right` | Number of pins on the right edge | `0` |
85+
| `-usb` | Side for the USB port: `left`, `right`, `top`, or `bottom` | *(none)* |
86+
| `-led` | Include a built-in LED (placed next to the USB port) | `false` |
87+
| `-color` | PCB color as a hex string | `#006837` |
88+
| `-width` | Board width in mm (0 = auto-sized from pins) | `0` |
89+
| `-height` | Board height in mm (0 = auto-sized from pins) | `0` |
90+
| `-rect-gnd` | Use rectangular pad shape for GND pins (taller, rounded corners) | `false` |
91+
| `-format` | Firmware format string (e.g. `uf2`, `hex`) | `uf2` |
92+
| `-output` | Output directory for generated files | `.` |
93+
94+
## What it generates
95+
96+
### SVG file (`<name>.svg`)
97+
98+
A board image that matches the project's visual conventions:
99+
100+
- **Millimeter units**`viewBox` matches the physical board size so that
101+
1px == 1mm.
102+
- **Castellated pads** — half-circle pad shapes matching the Raspberry Pi Pico
103+
style. When `-rect-gnd` is set, GND pads use a distinct taller rectangular
104+
shape with small rounded corners; otherwise all pads share the same
105+
half-circle shape.
106+
- **Pin attributes** — each pad has `data-pin` (and `data-title` where the
107+
display name differs) for the simulator to connect wires.
108+
- **USB port** — a `#ccc` rectangle protruding 1.3mm past the board edge on the
109+
specified side.
110+
- **LED** — an animated `data-part="led"` element using CSS custom properties
111+
(`--color`, `--shadow`) for the simulator to control brightness.
112+
113+
### JSON file (`<name>.json`)
114+
115+
A complete board configuration for the simulator:
116+
117+
- **MCU part** with `GPIO0``GPIOn` pin mapping.
118+
- **LED part** (when `-led` is set) with color and current values.
119+
- **Wire table** connecting SVG `data-pin` names to MCU GPIOs, power (`vcc`),
120+
and ground (`gnd`).
121+
- **`firmwareFormat`** and **`baseCurrent`** fields.
122+
123+
## Pin assignment
124+
125+
Pins are assigned automatically:
126+
127+
1. **GPIO pins** are numbered sequentially starting from `GP0`, distributed
128+
across sides in reading order: top → right → bottom → left.
129+
2. **GND pins** are auto-inserted after every 5 GPIO pins on each side.
130+
3. **Power pins** — when `-usb` is specified, the first three positions on the
131+
USB side are reserved for `VBUS`, `GND`, and `3V3`.
132+
4. The **LED** (when enabled) is wired to the last GPIO pin.
133+
134+
## Board sizing
135+
136+
Board dimensions are computed automatically from the pin counts:
137+
138+
- Each pin occupies one **pitch** unit (2.54mm).
139+
- Pad-depth zones (3.22mm) are added at edges that have pins.
140+
- Corner gaps prevent overlapping when perpendicular sides both have pins.
141+
- A minimum board dimension of 12mm is enforced.
142+
- When USB is present, the `viewBox` extends to include the protruding port.
143+
144+
You can override the auto-computed size with `-width` and/or `-height` (in mm).
145+
This is useful when you want a specific physical board size, or need extra space
146+
between pin rows. The pin rows are still positioned based on the computed
147+
pad-depth offsets, so the board will simply be larger in the overridden
148+
dimension(s).

cmd/boardgen/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/tinygo-org/playground/cmd/boardgen
2+
3+
go 1.21

0 commit comments

Comments
 (0)