@rulecad/pcb 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +81 -3
  2. package/circuit.mjs +627 -53
  3. package/package.json +6 -3
  4. package/pcb.mjs +812 -33
package/README.md CHANGED
@@ -39,6 +39,74 @@ export function main(v) {
39
39
  - **Parts from KiCad:** `fromKicad(text)` turns a KiCad footprint (`.kicad_mod`) into pad data (y up) and its
40
40
  courtyard. Keep the result in a rule set's `"footprints"` with its source and pin names (`labels: { pin1: 'GND' }`),
41
41
  then place it with `footprint(name, data, x, y, o)`: a design reads rule sets, never files or the network.
42
+ - **Whole boards from KiCad (clones):** `fromKicadPcb(text)` reads a published board (`.kicad_pcb`, KiCad 6 or later)
43
+ as a circuit: its parts (each with its pads, value and LCSC number, where the source put it), its nets, the nets it
44
+ fills as planes, its outline and holes. `cad clone` keeps it in a rule set's `"circuit"` with its source and licence.
45
+ `clone(v.<set>.circuit)` gives a board's `parts` and `nets` from it, and `notes` on what boards here can't carry
46
+ yet (castellated pads, oval pads, holes set off-centre in a pad, more than 2 layers: plane nets are left out of the
47
+ routing). `sameCircuit(json, circuit)` checks that a board joins exactly the pins the source joins, and names any
48
+ that differ: the layout can change, the circuit can't.
49
+ - **Placement learnt from the source:** `learnPlacement(circuit)` keeps each small part (a capacitor, a resistor, an
50
+ LED) near the pin it serves on a bigger part, as the source has it: a decoupling capacitor by its power pin, a
51
+ crystal's capacitor by the crystal. It goes by the part's most particular net (the one joining the fewest pins), so
52
+ GND doesn't decide. `cad clone` keeps these rules in `circuit.placement`, where `max` (mm) can be edited.
53
+ `arrange(circuit, { U3: { x, y, rotation } })` moves parts, and their small parts move and turn with them;
54
+ `placementChecks(circuit)` names any small part out of reach of its pin.
55
+ - **Reshaping a clone:** `moveGroup(circuit, refs, { turn, dx, dy })` moves a block of parts as one, keeping the
56
+ source's proven layout of an area (a chip and all its small parts) while the board around it changes. With
57
+ `{ keep: true }` the source's own tracks and vias come too, wherever they join only that block's pads, and only the
58
+ connections leaving the block are routed: dense areas round a fine-pitch chip keep their proven routing, and the
59
+ router has far less to do. A track from one of the block's pins out to a part elsewhere keeps its stretch inside the
60
+ block (a chip's escape), and is routed on from where it leaves.
61
+ `withFootprint(circuit, 'J2', pads)` puts a part on new pads with the same pins, so its nets can't change: new edge
62
+ pins for a new board shape. A design returns `{ board, clone: { circuit, arranged } }`, and `cad check` then also
63
+ checks the circuit is the source's and every small part is still by its pin.
64
+ `addPins(circuit, 'J2', pads)` adds pins the source doesn't have, each on one of its nets (a second 3V3) or, with
65
+ `joins`, a new net to a pin it leaves free (a spare GPIO); the circuit check expects them and names each one.
66
+ - **As the source has it:** on a clone, a pad as close to the board's edge as the source has it (a mid-mount USB-C
67
+ socket in its notch), or a part that reaches past the outline there too, is said in the checks rather than failed.
68
+ The same thing new to your layout fails as usual.
69
+ - **4 layers and planes:** `layers: 4` (or 6) puts tracks on the outer layers and `planes: { GND: { layer: 'inner1',
70
+ pins } }` fills inner layers with plane nets. Before routing, each SMD pad of a plane net gets a via beside it (or
71
+ a short track to one nearby; a pad with its pin's own plated hole in it, such as a chip's centre pad with thermal
72
+ vias, needs none; a pad with no room is routed to the nearest pad of its net that reaches the plane). A plane net's pads
73
+ are tied only to their own links when routing, not to every pad of the net (they're joined by the plane). The planes are
74
+ poured with tscircuit's copper pour solver, clear of other nets' holes and vias, with thermal spokes; the checks
75
+ confirm every plane pad reaches its copper, and the inner layers get their own Gerbers (`.G1`, `.G2`). `clone()`
76
+ gives a 4-layer source's plane nets their planes, with the source's via size and clearance.
77
+ - **Routing to a clearance:** `clearance` (mm) is the gap the autorouter keeps from everything in its way (a clone:
78
+ the source's own). After routing, any connection in a design-rule error is pulled up and routed again with every good
79
+ track fixed in place, a minute per try, each round asking for a little more room and the best round kept. Then, with
80
+ `neck` (mm, the fab's smallest track), a track still a little too close to another is straightened where the router
81
+ doubled back, moved in where it hugs the board's edge, or narrowed where they pass. Existing vias reach the router at
82
+ their real size. `effort` asks the router to search harder, at more time.
83
+ - **Smoothing:** with `smooth: true`, the router's tracks are pulled tight once routed
84
+ ([@rulecad/smooth](../smooth)): wiggles, detours and doubling-backs straightened wherever the straight run keeps
85
+ `clearance`, sharp bends cut across. Only the router's tracks move, and drawn tracks never do. A clone's kept
86
+ routing stays as it was, with one exception: an escape (the stub of a source's track that a routed track carries on
87
+ from) is cut back where the routed track turns straight back on it, never into its first segment from the pin. A
88
+ track the design checks then find in a new error goes back as it was, and a board where a cut causes one is smoothed
89
+ again without cuts. For a clone that keeps its source's routing, the checks confirm every kept track and via is still
90
+ exactly where the source has it, and name each escape cut back and how much track went.
91
+ - **Labels clear of copper:** `clearLabels(silk, circuit)` slides each silkscreen label across its reading direction to
92
+ the nearest place clear of every pad and of the labels before it (the fab trims silkscreen off copper, so a label
93
+ on a pad loses letters). A label for a pin hemmed in by its neighbours (`to`: where the pin is) goes to the nearest
94
+ clear place instead, with a small triangle beside it pointing at the pin. Silkscreen text takes a `rotation`.
95
+ - **Schematics without a layout:** parts with no place on the schematic (a clone's) are laid out in rows, biggest
96
+ first, each pin drawn once and labelled with its net, in place of wires across the sheet. After routing, silkscreen
97
+ labels the router's vias landed on slide clear too.
98
+ - **Off the BOM and placement files:** a part with `bom: false` (edge pads, test points) isn't in the BOM, and one with
99
+ `place: false` isn't in the placement file. `fromKicadPcb` reads both from KiCad's footprint attributes.
100
+ - **Parts in 3D:** `fromKicadPcb` keeps each part's 3D model (its path, offset, scale, turn), and `cad clone` fetches
101
+ them into the workspace's `models/`: KiCad's library models as meshes (`wrlMesh` reads its VRML), and a model
102
+ whose shape can't be shared (no licence), or comes only as STEP, as a box its size (`stepBounds`). The board's
103
+ build then has a `components` part beside `board`, each model where its part is (`partModels`), so fit checks
104
+ see the real parts. `--no-models` skips them.
105
+ - **Pad shapes:** round SMD pads stay round, and rounded pads keep their corner radius, so clearances are measured to
106
+ the real copper.
107
+ - **Castellated and oval pads:** a pad `{ castellated: true }` is a half hole on the board's edge (tracks join it on
108
+ its inner side, mid-way across its copper ring), checked against JLCPCB's rules for castellated holes instead of the edge clearance. A pad
109
+ `{ rect: { w, h, offset } }` is an oval (a rounded rectangle) round its hole, which can sit off-centre.
42
110
  - **Any board shape:** give `outline: [{ x, y }, ...]` in place of a centre and size. `shape.rounded(w, h, r)`,
43
111
  `shape.bevelled(w, h, b)`, `shape.circle(d)` and `shape.rect(w, h)` make common ones. The router keeps tracks
44
112
  inside the outline, and a check finds any pad outside it.
@@ -52,8 +120,11 @@ export function main(v) {
52
120
  buttons) and a holes fit can check the screws find their inserts.
53
121
  - **Routing:** connections no rule draws go to tscircuit's capacity autorouter. Its tracks come back as pieces of each
54
122
  net, named here by the pads they end on; where a piece ends on a one-sided pad from the other layer, a via is added
55
- clear of the pad; and the build fails if any pad is left without a track. Drawn tracks can name their `layer`.
56
- - **Keyboards** are one recipe built on the same parts: every matrix track drawn by rule, one diode per key.
123
+ clear of the pad; a track may change layer inside a plated hole or a via, whose copper already joins the layers; and the build fails if any pad is left without a track. Drawn tracks can name their `layer`.
124
+ - **Keyboards** are one recipe built on the same parts: every matrix track drawn by rule, one diode per key. With the
125
+ Pico beside the keys, each row and column has a lane of its own to its pin (rows on the back, columns on the
126
+ front), given out nearest the Pico first to whichever lane's run covers none of the others' pins, so none cross,
127
+ from a single key up to the Pico's twenty GPIO; the Pico stands out far enough for the lanes.
57
128
 
58
129
  A keyboard:
59
130
 
@@ -72,11 +143,18 @@ npx cad preview macropad/board # copper from above, the schematic, and the bo
72
143
  npx cad export macropad/board # <name>-fab.zip for JLCPCB, KiCad files, the matrix for your firmware
73
144
  ```
74
145
 
146
+ - The checks are tscircuit's design rules and JLCPCB's limits measured from the board itself: track widths, holes (vias
147
+ too), each via's and plated hole's ring (under `annular_min` fails, under the recommended `annular` warns), the
148
+ silkscreen's line widths and text heights, castellated holes, the board's size, and the matrix. A board says what
149
+ vias the router may make (`via_hole`, `via_pad`; the recommended ring unless it says) and what silkscreen it draws
150
+ (`silk_line`, `silk_text`); the keyboard recipe takes them from the fab's rules.
75
151
  - The board is also a solid, so it takes part in fit checks: switches on the board, plate over it, board in the case.
76
152
  - A Pico under the board has its connections autorouted (that needs Node 22 or newer; boards drawn wholly by rule build on
77
153
  Node 20 too). That takes minutes; then the build cache keeps it.
78
154
  Everything else is drawn by rule.
79
155
  - The autorouter and footprint versions are pinned, so a board builds the same until rulecad moves them on; each move is
80
156
  checked against boards built before it (same tracks, same checks, same fab files). Nothing to add to your
81
- package.json.
157
+ package.json. tscircuit itself is pinned too: the Gerber writer lists it as a peer, so npm would otherwise install
158
+ the newest, and since its 0.0.3032 that has pulled in an old circuit-json that the design checks can't load
159
+ (tscircuit/circuit-json-to-gerber#200).
82
160
  - Ordering is your click: `cad export` makes the fab zip and never places an order.