mirror of
https://github.com/D-Modem/hardware.git
synced 2026-11-28 17:48:05 -08:00
Schematic: generated from the netlist script, checked against it
hardware/schematic/build_schematic.py draws pico-serial.kicad_sch (KiCad 9 format, one A2 sheet) from hardware/netlist/build_netlist.py: parts grouped into blocks by function, each pin a short wire to a net label or power symbol, no-connect flags on unused pins, PWR_FLAGs on GND and VBUS. It refuses to write unless the connectivity read back from the drawing matches the netlist exactly and nothing overlaps. The SP3238E and MAX3243E get their own symbol library (KiCad has neither); other symbols are cached from kicad-symbols 9.0 so it runs offline. The netlist now targets KiCad 9.0 libraries: pin names as KiCad 9 has them (SWD, VREG_IN, GPIO26_ADC0 ...) and the USB-C shield pin S1; it is checked against kicad-symbols and kicad-footprints 9.0.6. Pin numbers and nets are unchanged. Not yet opened in KiCad (not available here); parses with kiutils. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013PRsUCpxazyipPn5UGGkF8
This commit is contained in:
13 files changed
+14869
-53
No files matched your search
@@ -0,0 +1 @@
|
||||
__pycache__/
|
||||
+57
-21
@@ -1,8 +1,12 @@
|
||||
# pico-serial hardware
|
||||
|
||||
`netlist/build_netlist.py` defines every part and every connection on the
|
||||
board. The netlist, the readable net list and the JLC parts list are all
|
||||
generated from it, so change the script, not the outputs.
|
||||
board. The netlist, the readable net list, the JLC parts list and the
|
||||
schematic are all generated from it, so change the script, not the
|
||||
outputs.
|
||||
|
||||
Everything targets **KiCad 9**: KiCad 9 file formats and the KiCad 9.0
|
||||
symbol and footprint libraries. KiCad 10 opens it too.
|
||||
|
||||
| File | What it is |
|
||||
|---|---|
|
||||
@@ -10,21 +14,29 @@ generated from it, so change the script, not the outputs.
|
||||
| `netlist/pico-serial.net` | KiCad netlist (generated) |
|
||||
| `netlist/NETLIST.md` | Every net and every part, readable (generated) |
|
||||
| `netlist/bom-jlc.csv` | JLC assembly parts list with LCSC numbers (generated) |
|
||||
| `schematic/build_schematic.py` | Draws the schematic from the netlist script |
|
||||
| `schematic/pico-serial.kicad_sch` | KiCad schematic, one A2 sheet (generated) |
|
||||
| `schematic/pico-serial.kicad_sym` | SP3238E and MAX3243E symbols, which KiCad doesn't ship (generated) |
|
||||
| `schematic/preview.svg` | Rough drawing of the sheet for a quick look (generated) |
|
||||
|
||||
## Regenerate
|
||||
|
||||
```sh
|
||||
cd hardware/netlist
|
||||
python3 build_netlist.py # checks + writes the outputs
|
||||
python3 hardware/netlist/build_netlist.py # checks + netlist, NETLIST.md, BOM
|
||||
python3 hardware/schematic/build_schematic.py # checks + schematic and preview
|
||||
```
|
||||
|
||||
To also check every pin against KiCad's own libraries, point it at
|
||||
checkouts of the official symbol and footprint libraries:
|
||||
Neither needs KiCad or a network connection. The schematic script uses
|
||||
symbols cached in `schematic/lib/symbol-cache.sexp`.
|
||||
|
||||
To check every pin against KiCad's own libraries, and to refresh the
|
||||
symbol cache, point the scripts at the KiCad 9.0 library checkouts:
|
||||
|
||||
```sh
|
||||
git clone --depth 1 https://gitlab.com/kicad/libraries/kicad-symbols.git
|
||||
git clone --depth 1 https://gitlab.com/kicad/libraries/kicad-footprints.git
|
||||
python3 build_netlist.py --kicad-sym kicad-symbols --kicad-fp kicad-footprints
|
||||
git clone --depth 1 --branch 9.0.6 https://gitlab.com/kicad/libraries/kicad-symbols.git
|
||||
git clone --depth 1 --branch 9.0.6 https://gitlab.com/kicad/libraries/kicad-footprints.git
|
||||
python3 hardware/netlist/build_netlist.py --kicad-sym kicad-symbols --kicad-fp kicad-footprints
|
||||
python3 hardware/schematic/build_schematic.py --kicad-sym9 kicad-symbols
|
||||
```
|
||||
|
||||
It stops with an error, and writes nothing, if:
|
||||
@@ -67,21 +79,45 @@ from the datasheets (MaxLinear SP3238E rev 1.0.1; TI MAX3243E SLLS657E,
|
||||
Table 6-2) and marked as such in the script. Every other part's pins
|
||||
match KiCad's library symbols.
|
||||
|
||||
## The schematic
|
||||
|
||||
`schematic/pico-serial.kicad_sch` is one A2 sheet in blocks:
|
||||
- USB-C, protection and supply;
|
||||
- RP2040 and its decoupling;
|
||||
- crystal, flash and buttons;
|
||||
- chip A (DCE) and chip B (DTE), each with its charge-pump capacitors;
|
||||
- the DB25;
|
||||
- the optional LEDs;
|
||||
- test pads and the power flags ERC needs.
|
||||
|
||||
Every pin ends in a short wire with a net label or power symbol, so parts
|
||||
connect by name, not by long wires. Each part carries its LCSC number, a
|
||||
note on its purpose, and its footprint.
|
||||
|
||||
The schematic script refuses to write if:
|
||||
- the connections read back from the drawing differ from the netlist in
|
||||
any way (a missing pin, an extra join, a pin touching the middle of a
|
||||
wire);
|
||||
- any two texts, labels or symbols overlap.
|
||||
|
||||
It's generated, so hand edits are overwritten on the next run. Either
|
||||
change `build_netlist.py` and regenerate, or stop generating and edit in
|
||||
KiCad from then on.
|
||||
|
||||
## Using it in KiCad
|
||||
|
||||
1. Create a project and open the PCB editor.
|
||||
2. **File → Import → Netlist…**, choose `pico-serial.net`, then **Update
|
||||
PCB**. The footprints come from KiCad's standard libraries.
|
||||
3. LCSC numbers are in each footprint's `LCSC` field; the DNP field marks
|
||||
the LEDs.
|
||||
1. Open `schematic/pico-serial.kicad_pro` in KiCad 9 or 10. The project
|
||||
table points at `pico-serial.kicad_sym`, which has the two RS-232
|
||||
symbols. Every symbol is also embedded in the schematic.
|
||||
2. Run ERC.
|
||||
3. Open the PCB editor and choose **Tools → Update PCB from Schematic**
|
||||
(or import `netlist/pico-serial.net`). Footprints come from KiCad's
|
||||
standard libraries.
|
||||
|
||||
The import hasn't been tried in KiCad yet: KiCad couldn't be installed
|
||||
where this was made. The file follows KiCad's netlist format (version
|
||||
"E") and parses cleanly, but expect to fix small issues on the first
|
||||
import.
|
||||
|
||||
There is no schematic yet. This netlist goes straight to layout. A
|
||||
generated KiCad schematic can come next if wanted.
|
||||
Neither file has been opened in KiCad yet: KiCad couldn't be installed
|
||||
where they were made. Both parse cleanly, and the schematic also passes
|
||||
an independent parser (kiutils). Expect small fixes the first time
|
||||
KiCad opens them.
|
||||
|
||||
## Before layout
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ Generated by `build_netlist.py`; edit that script, not this file.
|
||||
| Net | Pins |
|
||||
|---|---|
|
||||
| `+1V1` | C13.1, C14.1, C15.1, TP3.1 (1), U1.23 (DVDD), U1.45 (VREG_VOUT), U1.50 (DVDD) |
|
||||
| `+3V3` | C3.1, C4.1, C5.1, C6.1, C7.1, C8.1, C9.1, C10.1, C11.1, C12.1, C18.1, C23.1, C24.1, C29.1, C30.1, R10.1, TP2.1 (1), U1.1 (IOVDD), U1.10 (IOVDD), U1.22 (IOVDD), U1.33 (IOVDD), U1.42 (IOVDD), U1.43 (ADC_AVDD), U1.44 (VREG_VIN), U1.48 (USB_VDD), U1.49 (IOVDD), U2.8 (VCC), U3.5 (VOUT), U5.26 (VCC), U6.26 (VCC) |
|
||||
| `+3V3` | C3.1, C4.1, C5.1, C6.1, C7.1, C8.1, C9.1, C10.1, C11.1, C12.1, C18.1, C23.1, C24.1, C29.1, C30.1, R10.1, TP2.1 (1), U1.1 (IOVDD), U1.10 (IOVDD), U1.22 (IOVDD), U1.33 (IOVDD), U1.42 (IOVDD), U1.43 (ADC_AVDD), U1.44 (VREG_IN), U1.48 (USB_VDD), U1.49 (IOVDD), U2.8 (VCC), U3.5 (VOUT), U5.26 (VCC), U6.26 (VCC) |
|
||||
| `A_CTS` | U1.4 (GPIO2), U5.20 (R2OUT) |
|
||||
| `A_DCD` | U1.7 (GPIO5), U5.19 (T4IN) |
|
||||
| `A_DSR` | U1.6 (GPIO4), U5.22 (T3IN) |
|
||||
@@ -47,15 +47,15 @@ Generated by `build_netlist.py`; edit that script, not this file.
|
||||
| `CPB_VM` | C28.1, U6.3 (V-) |
|
||||
| `CPB_VP` | C27.1, U6.27 (V+) |
|
||||
| `DB25_FG` | J2.1 (1), R11.1 |
|
||||
| `GND` | C1.2, C2.2, C3.2, C4.2, C5.2, C6.2, C7.2, C8.2, C9.2, C10.2, C11.2, C12.2, C13.2, C14.2, C15.2, C16.2, C17.2, C18.2, C21.2, C22.2, C23.2, C24.2, C27.2, C28.2, C29.2, C30.2, D1.2 (A), D2.1 (K), D3.1 (K), D4.1 (K), D5.1 (K), D6.1 (K), D7.1 (K), J1.A1 (GND), J1.A12 (GND), J1.B1 (GND), J1.B12 (GND), J2.7 (7), R1.2, R2.2, R3.2, R5.2, R11.2, R12.2, R13.2, R14.2, SW1.2 (2), SW2.2 (2), TP4.1 (1), U1.19 (TESTEN), U1.57 (GND), U2.4 (GND), U3.2 (GND), U4.2 (GND), U5.2 (GND), U6.25 (GND), Y1.2 (G), Y1.4 (G) |
|
||||
| `GP28` | TP8.1 (1), U1.40 (GPIO28/ADC2) |
|
||||
| `GND` | C1.2, C2.2, C3.2, C4.2, C5.2, C6.2, C7.2, C8.2, C9.2, C10.2, C11.2, C12.2, C13.2, C14.2, C15.2, C16.2, C17.2, C18.2, C21.2, C22.2, C23.2, C24.2, C27.2, C28.2, C29.2, C30.2, D1.2 (A), D2.1 (K), D3.1 (K), D4.1 (K), D5.1 (K), D6.1 (K), D7.1 (K), J1.A1 (GND), J1.A12 (GND), J1.B1 (GND), J1.B12 (GND), J2.7 (7), R1.2, R2.2, R3.2, R5.2, R11.2, R12.2, R13.2, R14.2, SW1.2 (2), SW2.2 (2), TP4.1 (1), U1.19 (TESTEN), U1.57 (GND), U2.4 (GND), U3.2 (GND), U4.2 (GND), U5.2 (GND), U6.25 (GND), Y1.2 (2), Y1.4 (4) |
|
||||
| `GP28` | TP8.1 (1), U1.40 (GPIO28_ADC2) |
|
||||
| `LED_CD` | R17.1, U1.36 (GPIO24) |
|
||||
| `LED_CD_A` | D4.2 (A), R17.2 |
|
||||
| `LED_PWR` | R15.1, U1.34 (GPIO22) |
|
||||
| `LED_PWR_A` | D2.2 (A), R15.2 |
|
||||
| `LED_RD` | R19.1, U1.38 (GPIO26/ADC0) |
|
||||
| `LED_RD` | R19.1, U1.38 (GPIO26_ADC0) |
|
||||
| `LED_RD_A` | D6.2 (A), R19.2 |
|
||||
| `LED_RI` | R20.1, U1.39 (GPIO27/ADC1) |
|
||||
| `LED_RI` | R20.1, U1.39 (GPIO27_ADC1) |
|
||||
| `LED_RI_A` | D7.2 (A), R20.2 |
|
||||
| `LED_SD` | R18.1, U1.37 (GPIO25) |
|
||||
| `LED_SD_A` | D5.2 (A), R18.2 |
|
||||
@@ -66,7 +66,7 @@ Generated by `build_netlist.py`; edit that script, not this file.
|
||||
| `QSPI_SD1` | U1.55 (QSPI_SD1), U2.2 (DO/IO_{1}) |
|
||||
| `QSPI_SD2` | U1.54 (QSPI_SD2), U2.3 (~{WP}/IO_{2}) |
|
||||
| `QSPI_SD3` | U1.51 (QSPI_SD3), U2.7 (~{HOLD}/~{RESET}/IO_{3}) |
|
||||
| `QSPI_SS` | R9.1, U1.56 (~{QSPI_SS}), U2.1 (~{CS}) |
|
||||
| `QSPI_SS` | R9.1, U1.56 (QSPI_SS), U2.1 (~{CS}) |
|
||||
| `RS_CTS` | J2.5 (5), U5.6 (T2OUT), U6.5 (RIN2) |
|
||||
| `RS_DCD` | J2.8 (8), U5.10 (T4OUT), U6.7 (RIN4) |
|
||||
| `RS_DSR` | J2.6 (6), U5.7 (T3OUT), U6.6 (RIN3) |
|
||||
@@ -78,15 +78,15 @@ Generated by `build_netlist.py`; edit that script, not this file.
|
||||
| `RS_TXD` | J2.2 (2), U5.8 (R1IN), U6.9 (DOUT1) |
|
||||
| `RUN` | R10.2, SW2.1 (1), TP7.1 (1), U1.26 (RUN) |
|
||||
| `SWCLK` | TP5.1 (1), U1.24 (SWCLK) |
|
||||
| `SWDIO` | TP6.1 (1), U1.25 (SWDIO) |
|
||||
| `SWDIO` | TP6.1 (1), U1.25 (SWD) |
|
||||
| `USB_CONN_DM` | J1.A7 (D-), J1.B7 (D-), R7.1, U4.3 (I/O2), U4.4 (I/O2) |
|
||||
| `USB_CONN_DP` | J1.A6 (D+), J1.B6 (D+), R6.1, U4.1 (I/O1), U4.6 (I/O1) |
|
||||
| `USB_DM` | R7.2, U1.46 (USB_DM) |
|
||||
| `USB_DP` | R6.2, U1.47 (USB_DP) |
|
||||
| `USB_SHIELD` | C1.1, J1.SH (SHIELD), R3.1 |
|
||||
| `USB_SHIELD` | C1.1, J1.S1 (SHIELD), R3.1 |
|
||||
| `VBUS` | C2.1, D1.1 (K), F1.2, R4.1, TP1.1 (1), U3.1 (VIN), U3.3 (EN), U4.5 (VBUS) |
|
||||
| `VBUS_IN` | F1.1, J1.A4 (VBUS), J1.A9 (VBUS), J1.B4 (VBUS), J1.B9 (VBUS) |
|
||||
| `VBUS_SENSE` | R4.2, R5.1, U1.41 (GPIO29/ADC3) |
|
||||
| `VBUS_SENSE` | R4.2, R5.1, U1.41 (GPIO29_ADC3) |
|
||||
| `XIN` | C16.1, U1.20 (XIN), Y1.1 (1) |
|
||||
| `XOUT` | R8.1, U1.21 (XOUT) |
|
||||
| `XTAL_OUT` | C17.1, R8.2, Y1.3 (3) |
|
||||
|
||||
@@ -26,7 +26,7 @@ from collections import defaultdict
|
||||
# the two RS-232 chips; theirs come from the datasheets:
|
||||
# SP3238E MaxLinear rev 1.0.1, pin description table
|
||||
# MAX3243E TI SLLS657E, Table 6-2 (DB/DW/PW 28-pin)
|
||||
# Pin types follow KiCad's names.
|
||||
# Pin names and types follow KiCad 9.0 (kicad-symbols tag 9.0.x).
|
||||
# ---------------------------------------------------------------------------
|
||||
P, PI, PO, I, O, B, NC = "passive", "power_in", "power_out", "input", "output", "bidirectional", "no_connect"
|
||||
|
||||
@@ -35,15 +35,15 @@ RP2040 = {
|
||||
"6": ("GPIO4", B), "7": ("GPIO5", B), "8": ("GPIO6", B), "9": ("GPIO7", B), "10": ("IOVDD", P),
|
||||
"11": ("GPIO8", B), "12": ("GPIO9", B), "13": ("GPIO10", B), "14": ("GPIO11", B), "15": ("GPIO12", B),
|
||||
"16": ("GPIO13", B), "17": ("GPIO14", B), "18": ("GPIO15", B), "19": ("TESTEN", I), "20": ("XIN", I),
|
||||
"21": ("XOUT", O), "22": ("IOVDD", P), "23": ("DVDD", PI), "24": ("SWCLK", I), "25": ("SWDIO", B),
|
||||
"21": ("XOUT", O), "22": ("IOVDD", P), "23": ("DVDD", PI), "24": ("SWCLK", I), "25": ("SWD", B),
|
||||
"26": ("RUN", I), "27": ("GPIO16", B), "28": ("GPIO17", B), "29": ("GPIO18", B), "30": ("GPIO19", B),
|
||||
"31": ("GPIO20", B), "32": ("GPIO21", B), "33": ("IOVDD", P), "34": ("GPIO22", B), "35": ("GPIO23", B),
|
||||
"36": ("GPIO24", B), "37": ("GPIO25", B), "38": ("GPIO26/ADC0", B), "39": ("GPIO27/ADC1", B),
|
||||
"40": ("GPIO28/ADC2", B), "41": ("GPIO29/ADC3", B), "42": ("IOVDD", P), "43": ("ADC_AVDD", PI),
|
||||
"44": ("VREG_VIN", PI), "45": ("VREG_VOUT", PO), "46": ("USB_DM", B), "47": ("USB_DP", B),
|
||||
"36": ("GPIO24", B), "37": ("GPIO25", B), "38": ("GPIO26_ADC0", B), "39": ("GPIO27_ADC1", B),
|
||||
"40": ("GPIO28_ADC2", B), "41": ("GPIO29_ADC3", B), "42": ("IOVDD", P), "43": ("ADC_AVDD", PI),
|
||||
"44": ("VREG_IN", PI), "45": ("VREG_VOUT", PO), "46": ("USB_DM", B), "47": ("USB_DP", B),
|
||||
"48": ("USB_VDD", PI), "49": ("IOVDD", P), "50": ("DVDD", P), "51": ("QSPI_SD3", B),
|
||||
"52": ("QSPI_SCLK", O), "53": ("QSPI_SD0", B), "54": ("QSPI_SD2", B), "55": ("QSPI_SD1", B),
|
||||
"56": ("~{QSPI_SS}", O), "57": ("GND", PI),
|
||||
"56": ("QSPI_SS", O), "57": ("GND", PI),
|
||||
}
|
||||
SP3238E = {
|
||||
"1": ("C2+", P), "2": ("GND", PI), "3": ("C2-", P), "4": ("V-", P), "5": ("T1OUT", O),
|
||||
@@ -70,9 +70,9 @@ USBLC6 = {"1": ("I/O1", P), "2": ("GND", P), "3": ("I/O2", P), "4": ("I/O2", P),
|
||||
USB_C16 = {"A1": ("GND", P), "A4": ("VBUS", P), "A5": ("CC1", B), "A6": ("D+", B), "A7": ("D-", B),
|
||||
"A8": ("SBU1", B), "A9": ("VBUS", P), "A12": ("GND", P), "B1": ("GND", P), "B4": ("VBUS", P),
|
||||
"B5": ("CC2", B), "B6": ("D+", B), "B7": ("D-", B), "B8": ("SBU2", B), "B9": ("VBUS", P),
|
||||
"B12": ("GND", P), "SH": ("SHIELD", P)}
|
||||
"B12": ("GND", P), "S1": ("SHIELD", P)}
|
||||
DB25F = {str(n): (str(n) if n <= 13 else f"P{n}", P) for n in range(1, 26)}
|
||||
XTAL4 = {"1": ("1", P), "2": ("G", P), "3": ("3", P), "4": ("G", P)}
|
||||
XTAL4 = {"1": ("1", P), "2": ("2", P), "3": ("3", P), "4": ("4", P)}
|
||||
TWO = {"1": ("~", P), "2": ("~", P)}
|
||||
DIODE = {"1": ("K", P), "2": ("A", P)}
|
||||
SW = {"1": ("1", P), "2": ("2", P)}
|
||||
@@ -105,6 +105,12 @@ parts = {} # ref -> dict
|
||||
nets = defaultdict(list) # net -> [(ref, pin)]
|
||||
noconnect = set() # (ref, pin)
|
||||
counters = defaultdict(int)
|
||||
BLOCK = None # schematic block the next parts belong to
|
||||
|
||||
|
||||
def block(name):
|
||||
global BLOCK
|
||||
BLOCK = name
|
||||
|
||||
|
||||
def part(prefix, value, pins, footprint, lcsc="", note="", dnp=False, assembly="jlc", desc="", ref=None):
|
||||
@@ -113,7 +119,7 @@ def part(prefix, value, pins, footprint, lcsc="", note="", dnp=False, assembly="
|
||||
ref = f"{prefix}{counters[prefix]}"
|
||||
assert ref not in parts, ref
|
||||
parts[ref] = dict(ref=ref, value=value, pins=pins, footprint=footprint, lcsc=lcsc,
|
||||
note=note, dnp=dnp, assembly=assembly, desc=desc)
|
||||
note=note, dnp=dnp, assembly=assembly, desc=desc, block=BLOCK)
|
||||
return ref
|
||||
|
||||
|
||||
@@ -153,6 +159,7 @@ GND, VBUS_IN, VBUS, V33, V11 = "GND", "VBUS_IN", "VBUS", "+3V3", "+1V1"
|
||||
SUPPLIES = {GND, VBUS_IN, VBUS, V33, V11}
|
||||
|
||||
# --- §4.4 USB-C (UFP) -------------------------------------------------------
|
||||
block("usb")
|
||||
J1 = part("J", "USB_C", USB_C16, "Connector_USB:USB_C_Receptacle_HRO_TYPE-C-31-M-12", "C165948",
|
||||
desc="HRO TYPE-C-31-M-12")
|
||||
conn(GND, *[(J1, p) for p in ("A1", "A12", "B1", "B12")])
|
||||
@@ -161,7 +168,7 @@ conn("CC1", (J1, "A5"))
|
||||
conn("CC2", (J1, "B5"))
|
||||
conn("USB_CONN_DP", (J1, "A6"), (J1, "B6"))
|
||||
conn("USB_CONN_DM", (J1, "A7"), (J1, "B7"))
|
||||
conn("USB_SHIELD", (J1, "SH"))
|
||||
conn("USB_SHIELD", (J1, "S1"))
|
||||
nc(J1, "A8", "B8")
|
||||
passive("R", "5.1k", "CC1", GND, "CC1 Rd: separate resistor per CC pin")
|
||||
passive("R", "5.1k", "CC2", GND, "CC2 Rd")
|
||||
@@ -186,6 +193,7 @@ passive("R", "100k", VBUS, "VBUS_SENSE", "VBUS divider top")
|
||||
passive("R", "100k", "VBUS_SENSE", GND, "VBUS divider bottom")
|
||||
|
||||
# --- §4.2 RP2040 ------------------------------------------------------------
|
||||
block("mcu")
|
||||
U1 = part("U", "RP2040", RP2040, "Package_DFN_QFN:QFN-56-1EP_7x7mm_P0.4mm_EP3.2x3.2mm", "C2040", ref="U1")
|
||||
for p in ("1", "10", "22", "33", "42", "49"):
|
||||
conn(V33, (U1, p))
|
||||
@@ -203,6 +211,7 @@ passive("R", "27R", "USB_CONN_DP", "USB_DP", "USB D+ series")
|
||||
passive("R", "27R", "USB_CONN_DM", "USB_DM", "USB D- series")
|
||||
|
||||
# crystal: 15 pF each side, 1k in series with XOUT
|
||||
block("clock")
|
||||
Y1 = part("Y", "12MHz", XTAL4, "Crystal:Crystal_SMD_3225-4Pin_3.2x2.5mm", "C20625731", desc="Abracon ABM8-272-T3")
|
||||
conn("XIN", (U1, "20"), (Y1, "1"))
|
||||
conn("XOUT", (U1, "21"))
|
||||
@@ -233,8 +242,10 @@ passive("R", "10k", V33, "RUN", "RUN pull-up; RP2040 has a weak internal one, th
|
||||
conn("SWCLK", (U1, "24")); conn("SWDIO", (U1, "25"))
|
||||
|
||||
# --- §4.5 RS-232: chip A (DCE, SP3238E) and chip B (DTE, MAX3243E) -----------
|
||||
block("rsa")
|
||||
UA = part("U", "SP3238EEA", SP3238E, "Package_SO:SSOP-28_5.3x10.2mm_P0.65mm", "C49669",
|
||||
desc="MaxLinear SP3238EEA-L/TR, chip A, DCE", ref="U5")
|
||||
block("rsb")
|
||||
UB = part("U", "MAX3243EIDBR", MAX3243E, "Package_SO:SSOP-28_5.3x10.2mm_P0.65mm", "C353887",
|
||||
desc="TI MAX3243EIDBR, chip B, DTE", ref="U6")
|
||||
|
||||
@@ -252,9 +263,12 @@ def charge_pump(u, c1p, c1m, c2p, c2m, vp, vm, vcc, gnd, tag):
|
||||
passive("C", "100nF", V33, GND, f"chip {tag[-1]} VCC")
|
||||
|
||||
|
||||
block("rsa")
|
||||
charge_pump(UA, "28", "25", "1", "3", "27", "4", "26", "2", "CPA")
|
||||
block("rsb")
|
||||
charge_pump(UB, "28", "24", "1", "2", "27", "3", "26", "25", "CPB")
|
||||
|
||||
block("db25")
|
||||
J2 = part("J", "DB25_Female", DB25F, "Connector_Dsub:DSUB-25_Socket_EdgeMount_P2.77mm", "C19601171",
|
||||
assembly="hand", desc="MH Connectors MHDB25SS, solder cups straddling the board edge")
|
||||
|
||||
@@ -307,13 +321,17 @@ for g, (net, node) in GPIO.items():
|
||||
conn(net, (U1, GPIO_PIN[g]), node)
|
||||
# GP18 drives chip A ONLINE and chip B FORCEON together
|
||||
conn("RS_FORCEON", (U1, GPIO_PIN[18]), (UA, "13"), (UB, "23"))
|
||||
block("rsa")
|
||||
passive("R", "100k", "A_SHDN_N", GND, "chip A off until firmware decides")
|
||||
block("rsb")
|
||||
passive("R", "100k", "B_FORCEOFF_N", GND, "chip B off until firmware decides")
|
||||
block("rsa")
|
||||
passive("R", "100k", "RS_FORCEON", GND, "auto power-down on until firmware decides")
|
||||
nc(UB, "20") # ROUT2B unused (INVALID covers detection)
|
||||
conn("VBUS_SENSE", (U1, GPIO_PIN[29]))
|
||||
|
||||
# --- §4.8 optional LEDs (not fitted by default) ---------------------------------
|
||||
block("led")
|
||||
for g, name in zip(range(22, 28), ("PWR", "TR", "CD", "SD", "RD", "RI")):
|
||||
led = part("D", f"LED_{name}", DIODE, "LED_SMD:LED_0603_1608Metric", "C2286", dnp=True,
|
||||
desc=f"{name} status LED, optional")
|
||||
@@ -322,6 +340,7 @@ for g, name in zip(range(22, 28), ("PWR", "TR", "CD", "SD", "RD", "RI")):
|
||||
conn(f"LED_{name}_A", (led, "2")); conn(GND, (led, "1"))
|
||||
|
||||
# --- test pads ----------------------------------------------------------------
|
||||
block("tp")
|
||||
conn("GP28", (U1, GPIO_PIN[28]))
|
||||
for net, label in ((VBUS, "VBUS"), (V33, "3V3"), (V11, "1V1"), (GND, "GND"), ("SWCLK", "SWCLK"),
|
||||
("SWDIO", "SWDIO"), ("RUN", "RUN"), ("GP28", "GP28"), ("A_TX", "A_TX"),
|
||||
@@ -366,9 +385,23 @@ def check():
|
||||
return errs, warns
|
||||
|
||||
|
||||
def parse_sym(libdir, lib, name, seen=()):
|
||||
path = os.path.join(libdir, f"{lib}.kicad_symdir", f"{name}.kicad_sym")
|
||||
t = open(path).read()
|
||||
def sym_text(libdir, lib, name):
|
||||
"""One symbol's text, from a KiCad 9 single-file library or a KiCad 10 .kicad_symdir."""
|
||||
d = os.path.join(libdir, f"{lib}.kicad_symdir", f"{name}.kicad_sym")
|
||||
if os.path.exists(d):
|
||||
return open(d).read()
|
||||
t = open(os.path.join(libdir, f"{lib}.kicad_sym")).read()
|
||||
i = t.index(f'\n\t(symbol "{name}"') + 2
|
||||
depth = 0
|
||||
for j in range(i, len(t)):
|
||||
depth += {"(": 1, ")": -1}.get(t[j], 0)
|
||||
if depth == 0:
|
||||
return t[i:j + 1]
|
||||
raise ValueError(name)
|
||||
|
||||
|
||||
def parse_sym(libdir, lib, name):
|
||||
t = sym_text(libdir, lib, name)
|
||||
m = re.search(r'\(extends "([^"]+)"\)', t)
|
||||
if m:
|
||||
return parse_sym(libdir, lib, m.group(1))
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
(node (ref "U1") (pin "33") (pinfunction "IOVDD") (pintype "passive"))
|
||||
(node (ref "U1") (pin "42") (pinfunction "IOVDD") (pintype "passive"))
|
||||
(node (ref "U1") (pin "43") (pinfunction "ADC_AVDD") (pintype "power_in"))
|
||||
(node (ref "U1") (pin "44") (pinfunction "VREG_VIN") (pintype "power_in"))
|
||||
(node (ref "U1") (pin "44") (pinfunction "VREG_IN") (pintype "power_in"))
|
||||
(node (ref "U1") (pin "48") (pinfunction "USB_VDD") (pintype "power_in"))
|
||||
(node (ref "U1") (pin "49") (pinfunction "IOVDD") (pintype "passive"))
|
||||
(node (ref "U2") (pin "8") (pinfunction "VCC") (pintype "power_in"))
|
||||
@@ -336,12 +336,12 @@
|
||||
(node (ref "U4") (pin "2") (pinfunction "GND") (pintype "passive"))
|
||||
(node (ref "U5") (pin "2") (pinfunction "GND") (pintype "power_in"))
|
||||
(node (ref "U6") (pin "25") (pinfunction "GND") (pintype "power_in"))
|
||||
(node (ref "Y1") (pin "2") (pinfunction "G") (pintype "passive"))
|
||||
(node (ref "Y1") (pin "4") (pinfunction "G") (pintype "passive"))
|
||||
(node (ref "Y1") (pin "2") (pinfunction "2") (pintype "passive"))
|
||||
(node (ref "Y1") (pin "4") (pinfunction "4") (pintype "passive"))
|
||||
)
|
||||
(net (code "41") (name "/GP28")
|
||||
(node (ref "TP8") (pin "1") (pinfunction "1") (pintype "passive"))
|
||||
(node (ref "U1") (pin "40") (pinfunction "GPIO28/ADC2") (pintype "bidirectional"))
|
||||
(node (ref "U1") (pin "40") (pinfunction "GPIO28_ADC2") (pintype "bidirectional"))
|
||||
)
|
||||
(net (code "42") (name "/LED_CD")
|
||||
(node (ref "R17") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
@@ -361,7 +361,7 @@
|
||||
)
|
||||
(net (code "46") (name "/LED_RD")
|
||||
(node (ref "R19") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
(node (ref "U1") (pin "38") (pinfunction "GPIO26/ADC0") (pintype "bidirectional"))
|
||||
(node (ref "U1") (pin "38") (pinfunction "GPIO26_ADC0") (pintype "bidirectional"))
|
||||
)
|
||||
(net (code "47") (name "/LED_RD_A")
|
||||
(node (ref "D6") (pin "2") (pinfunction "A") (pintype "passive"))
|
||||
@@ -369,7 +369,7 @@
|
||||
)
|
||||
(net (code "48") (name "/LED_RI")
|
||||
(node (ref "R20") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
(node (ref "U1") (pin "39") (pinfunction "GPIO27/ADC1") (pintype "bidirectional"))
|
||||
(node (ref "U1") (pin "39") (pinfunction "GPIO27_ADC1") (pintype "bidirectional"))
|
||||
)
|
||||
(net (code "49") (name "/LED_RI_A")
|
||||
(node (ref "D7") (pin "2") (pinfunction "A") (pintype "passive"))
|
||||
@@ -413,7 +413,7 @@
|
||||
)
|
||||
(net (code "59") (name "/QSPI_SS")
|
||||
(node (ref "R9") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
(node (ref "U1") (pin "56") (pinfunction "~{QSPI_SS}") (pintype "output"))
|
||||
(node (ref "U1") (pin "56") (pinfunction "QSPI_SS") (pintype "output"))
|
||||
(node (ref "U2") (pin "1") (pinfunction "~{CS}") (pintype "input"))
|
||||
)
|
||||
(net (code "60") (name "/RS_CTS")
|
||||
@@ -474,7 +474,7 @@
|
||||
)
|
||||
(net (code "71") (name "/SWDIO")
|
||||
(node (ref "TP6") (pin "1") (pinfunction "1") (pintype "passive"))
|
||||
(node (ref "U1") (pin "25") (pinfunction "SWDIO") (pintype "bidirectional"))
|
||||
(node (ref "U1") (pin "25") (pinfunction "SWD") (pintype "bidirectional"))
|
||||
)
|
||||
(net (code "72") (name "/USB_CONN_DM")
|
||||
(node (ref "J1") (pin "A7") (pinfunction "D-") (pintype "bidirectional"))
|
||||
@@ -500,7 +500,7 @@
|
||||
)
|
||||
(net (code "76") (name "/USB_SHIELD")
|
||||
(node (ref "C1") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
(node (ref "J1") (pin "SH") (pinfunction "SHIELD") (pintype "passive"))
|
||||
(node (ref "J1") (pin "S1") (pinfunction "SHIELD") (pintype "passive"))
|
||||
(node (ref "R3") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
)
|
||||
(net (code "77") (name "VBUS")
|
||||
@@ -523,7 +523,7 @@
|
||||
(net (code "79") (name "/VBUS_SENSE")
|
||||
(node (ref "R4") (pin "2") (pinfunction "~") (pintype "passive"))
|
||||
(node (ref "R5") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
(node (ref "U1") (pin "41") (pinfunction "GPIO29/ADC3") (pintype "bidirectional"))
|
||||
(node (ref "U1") (pin "41") (pinfunction "GPIO29_ADC3") (pintype "bidirectional"))
|
||||
)
|
||||
(net (code "80") (name "/XIN")
|
||||
(node (ref "C16") (pin "1") (pinfunction "~") (pintype "passive"))
|
||||
|
||||
@@ -0,0 +1,904 @@
|
||||
#!/usr/bin/env python3
|
||||
"""pico-serial schematic, generated from ../netlist/build_netlist.py.
|
||||
|
||||
Writes, next to this script:
|
||||
pico-serial.kicad_sch KiCad 9 schematic (opens in KiCad 9 and 10)
|
||||
pico-serial.kicad_pro minimal project file
|
||||
pico-serial.kicad_sym symbols KiCad doesn't ship (SP3238E, MAX3243E)
|
||||
sym-lib-table points KiCad at pico-serial.kicad_sym
|
||||
preview.svg a rough drawing of the sheet, for a quick look
|
||||
|
||||
Every pin gets a short wire ending in a net label or a power symbol, and
|
||||
parts are grouped into blocks by function. Unused pins get no-connect
|
||||
flags.
|
||||
|
||||
Checks before writing (exit 1 on any error):
|
||||
- the connectivity read back from the drawing matches the netlist exactly
|
||||
(same nets, same pins, nothing joined by accident)
|
||||
- no two labels, symbols or texts overlap
|
||||
|
||||
Symbols come from KiCad's official library, 9.0 branch. They are cached in
|
||||
lib/symbol-cache.sexp so this runs offline; refresh the cache with
|
||||
--kicad-sym9 <kicad-symbols checkout at tag 9.0.x>
|
||||
"""
|
||||
import argparse, datetime, math, os, sys, uuid
|
||||
from collections import defaultdict
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, os.path.join(HERE, "..", "netlist"))
|
||||
sys.path.insert(0, HERE)
|
||||
import sexpr # noqa: E402
|
||||
from sexpr import Sym, find, first # noqa: E402
|
||||
|
||||
_argv, sys.argv = sys.argv, sys.argv[:1]
|
||||
import build_netlist as N # noqa: E402 (builds the circuit on import)
|
||||
sys.argv = _argv
|
||||
|
||||
PROJECT = "pico-serial"
|
||||
NS = uuid.UUID("0b4c1d1e-5e7a-4c2b-8c51-9f0a7d3e6b21")
|
||||
GRID = 1.27
|
||||
STUB = 2.54
|
||||
FONT = 1.27
|
||||
CHAR_W = 1.27 * 0.82 # average stroke-font character width at 1.27 mm
|
||||
POWER = {"GND": "power:GND", "+3V3": "power:+3V3", "+1V1": "power:+1V1", "VBUS": "power:VBUS"}
|
||||
BODY_UP = {"power:+3V3", "power:+1V1", "power:VBUS", "power:PWR_FLAG"} # graphic above the pin
|
||||
BLOCKS = [ # key, title, max width (mm)
|
||||
("usb", "USB-C, protection and 3.3 V supply", 195),
|
||||
("mcu", "RP2040 and its decoupling", 165),
|
||||
("clock", "Crystal, QSPI flash, BOOTSEL and RESET", 130),
|
||||
("rsa", "Chip A: SP3238E, modem side (DCE)", 120),
|
||||
("rsb", "Chip B: MAX3243E, computer side (DTE)", 120),
|
||||
("db25", "DB25 female (hand-fitted)", 45),
|
||||
("led", "Status LEDs (optional, not fitted)", 118),
|
||||
("tp", "Test pads", 100),
|
||||
("flags", "Power flags for ERC", 60),
|
||||
]
|
||||
# rows of columns; a column stacks its blocks top to bottom
|
||||
SHEET_ROWS = [[["usb"], ["clock"], ["db25"], ["led"]], [["mcu"], ["rsa"], ["rsb"], ["tp", "flags"]]]
|
||||
FLAGS_SIZE = (35.56, 15.24)
|
||||
|
||||
|
||||
def uid(*parts):
|
||||
return str(uuid.uuid5(NS, "/".join(map(str, parts))))
|
||||
|
||||
|
||||
def snap(v, g=GRID):
|
||||
return round(round(v / g) * g, 4)
|
||||
|
||||
|
||||
def text_w(s, size=FONT):
|
||||
return len(s) * size * 0.82 + 0.4
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# Symbols
|
||||
# ===========================================================================
|
||||
LIB_OF = {}
|
||||
|
||||
|
||||
def lib_id(ref):
|
||||
p = N.parts[ref]
|
||||
pins = p["pins"]
|
||||
if pins is N.SP3238E:
|
||||
return "pico-serial:SP3238E"
|
||||
if pins is N.MAX3243E:
|
||||
return "pico-serial:MAX3243E"
|
||||
if pins is N.TWO:
|
||||
return {"R": "Device:R", "C": "Device:C", "F": "Device:Polyfuse"}[ref.rstrip("0123456789")]
|
||||
if pins is N.DIODE:
|
||||
return "Device:LED" if p["value"].startswith("LED") else "Device:D_Zener"
|
||||
lib, name = N.SYMBOLS[id(pins)]
|
||||
return f"{lib}:{name}"
|
||||
|
||||
|
||||
def custom_symbol(name, left, right, top, bottom, desc, fp, ds):
|
||||
"""A plain box: logic pins left, RS-232 and charge pump right, VCC top, GND bottom."""
|
||||
pins_tab = N.SP3238E if name == "SP3238E" else N.MAX3243E
|
||||
by_name = {}
|
||||
for num, (pname, ty) in pins_tab.items():
|
||||
by_name.setdefault(pname, []).append((num, ty))
|
||||
rows = max(len(left), len(right))
|
||||
h = (rows + 1) * 2.54
|
||||
top_y, w = snap(h / 2, 2.54), 12.7
|
||||
body = [Sym("rectangle"), [Sym("start"), -w, top_y], [Sym("end"), w, -top_y],
|
||||
[Sym("stroke"), [Sym("width"), 0.254], [Sym("type"), Sym("default")]],
|
||||
[Sym("fill"), [Sym("type"), Sym("background")]]]
|
||||
pins = []
|
||||
|
||||
def pin(pname, x, y, ang):
|
||||
num, ty = by_name[pname].pop(0)
|
||||
pins.append([Sym("pin"), Sym(ty), Sym("line"), [Sym("at"), x, y, ang], [Sym("length"), 3.81],
|
||||
[Sym("name"), pname, [Sym("effects"), [Sym("font"), [Sym("size"), 1.27, 1.27]]]],
|
||||
[Sym("number"), num, [Sym("effects"), [Sym("font"), [Sym("size"), 1.27, 1.27]]]]])
|
||||
for i, pn in enumerate(left):
|
||||
if pn:
|
||||
pin(pn, -w - 3.81, top_y - 2.54 * (i + 1), 0)
|
||||
for i, pn in enumerate(right):
|
||||
if pn:
|
||||
pin(pn, w + 3.81, top_y - 2.54 * (i + 1), 180)
|
||||
for i, pn in enumerate(top):
|
||||
pin(pn, -2.54 * (len(top) - 1) / 2 + 2.54 * i, top_y + 3.81, 270)
|
||||
for i, pn in enumerate(bottom):
|
||||
pin(pn, -2.54 * (len(bottom) - 1) / 2 + 2.54 * i, -top_y - 3.81, 90)
|
||||
assert not any(by_name.values()), f"{name}: pins not placed: {by_name}"
|
||||
|
||||
def prop(k, v, x, y, hide=False):
|
||||
eff = [Sym("effects"), [Sym("font"), [Sym("size"), 1.27, 1.27]]]
|
||||
if hide:
|
||||
eff.append([Sym("hide"), Sym("yes")])
|
||||
return [Sym("property"), k, v, [Sym("at"), x, y, 0], eff]
|
||||
return [Sym("symbol"), name, [Sym("exclude_from_sim"), Sym("no")], [Sym("in_bom"), Sym("yes")],
|
||||
[Sym("on_board"), Sym("yes")],
|
||||
prop("Reference", "U", -w, top_y + 1.27), prop("Value", name, -w, -top_y - 1.27),
|
||||
prop("Footprint", fp, 0, 0, True), prop("Datasheet", ds, 0, 0, True),
|
||||
prop("Description", desc, 0, 0, True),
|
||||
[Sym("symbol"), f"{name}_0_1", body], [Sym("symbol"), f"{name}_1_1", *pins],
|
||||
[Sym("embedded_fonts"), Sym("no")]]
|
||||
|
||||
|
||||
CUSTOM = {
|
||||
"SP3238E": custom_symbol(
|
||||
"SP3238E",
|
||||
left=["T1IN", "T2IN", "T3IN", "T4IN", "T5IN", None, "R1OUT", "R2OUT", "R3OUT", "R1OUTB", None,
|
||||
"ONLINE", "~{SHUTDOWN}", "STATUS"],
|
||||
right=["T1OUT", "T2OUT", "T3OUT", "T4OUT", "T5OUT", None, "R1IN", "R2IN", "R3IN", None,
|
||||
"C1+", "C1-", "C2+", "C2-", "V+", "V-"],
|
||||
top=["VCC"], bottom=["GND"],
|
||||
desc="3 V to 5.5 V RS-232 transceiver, 5 drivers / 3 receivers, AUTO ON-LINE, +-15 kV ESD",
|
||||
fp="Package_SO:SSOP-28_5.3x10.2mm_P0.65mm", ds="https://www.maxlinear.com/ds/sp3238e.pdf"),
|
||||
"MAX3243E": custom_symbol(
|
||||
"MAX3243E",
|
||||
left=["DIN1", "DIN2", "DIN3", None, "ROUT1", "ROUT2", "ROUT3", "ROUT4", "ROUT5", "ROUT2B", None,
|
||||
"~{FORCEOFF}", "FORCEON", "INVALID"],
|
||||
right=["DOUT1", "DOUT2", "DOUT3", None, "RIN1", "RIN2", "RIN3", "RIN4", "RIN5", None,
|
||||
"C1+", "C1-", "C2+", "C2-", "V+", "V-"],
|
||||
top=["VCC"], bottom=["GND"],
|
||||
desc="3 V to 5.5 V RS-232 transceiver, 3 drivers / 5 receivers, auto-powerdown, +-15 kV ESD",
|
||||
fp="Package_SO:SSOP-28_5.3x10.2mm_P0.65mm", ds="https://www.ti.com/lit/ds/symlink/max3243e.pdf"),
|
||||
}
|
||||
|
||||
CACHE = os.path.join(HERE, "lib", "symbol-cache.sexp")
|
||||
|
||||
|
||||
def needed_lib_ids():
|
||||
ids = {lib_id(r) for r in N.parts} | set(POWER.values()) | {"power:PWR_FLAG"}
|
||||
return sorted(i for i in ids if not i.startswith("pico-serial:"))
|
||||
|
||||
|
||||
def load_from_kicad(libdir):
|
||||
out = {}
|
||||
files = {}
|
||||
for lid in needed_lib_ids():
|
||||
lib, name = lid.split(":")
|
||||
if lib not in files:
|
||||
files[lib] = {first_atom(s): s for s in find(sexpr.parse(open(os.path.join(libdir, f"{lib}.kicad_sym")).read()), "symbol")}
|
||||
out[lid] = flatten(files[lib], name, lid)
|
||||
os.makedirs(os.path.dirname(CACHE), exist_ok=True)
|
||||
with open(CACHE, "w") as f:
|
||||
f.write(";; Symbols used by pico-serial, from KiCad's official library (kicad-symbols 9.0 branch,\n")
|
||||
f.write(";; CC-BY-SA 4.0 with the KiCad libraries exception). Generated by build_schematic.py.\n")
|
||||
f.write(sexpr.dump([Sym("cache")] + [out[k] for k in sorted(out)]) + "\n")
|
||||
return out
|
||||
|
||||
|
||||
def first_atom(node):
|
||||
return node[1]
|
||||
|
||||
|
||||
def flatten(symbols, name, lid):
|
||||
"""A library symbol with `extends` resolved, renamed to lib_id, as eeschema embeds it."""
|
||||
s = symbols[name]
|
||||
ext = first(s, "extends")
|
||||
if ext is None:
|
||||
node = [Sym("symbol"), lid] + s[2:]
|
||||
return node
|
||||
parent = flatten(symbols, ext[1], lid)
|
||||
child_props = {p[1]: p for p in find(s, "property")}
|
||||
out = [Sym("symbol"), lid]
|
||||
for item in parent[2:]:
|
||||
if isinstance(item, list) and item[0] == "property" and item[1] in child_props:
|
||||
out.append(child_props.pop(item[1]))
|
||||
elif isinstance(item, list) and item[0] == "symbol":
|
||||
sub = list(item)
|
||||
sub[1] = name + sub[1][len(ext[1]):]
|
||||
out.append(sub)
|
||||
else:
|
||||
out.append(item)
|
||||
# any property only the child has goes before the units
|
||||
extra = list(child_props.values())
|
||||
k = next(i for i, x in enumerate(out) if isinstance(x, list) and x[0] == "symbol")
|
||||
out[k:k] = extra
|
||||
for i, x in enumerate(out): # child's own flags win
|
||||
if isinstance(x, list) and x[0] in ("in_bom", "on_board", "exclude_from_sim", "power"):
|
||||
c = first(s, x[0])
|
||||
if c is not None:
|
||||
out[i] = c
|
||||
return out
|
||||
|
||||
|
||||
def load_symbols(libdir):
|
||||
syms = load_from_kicad(libdir) if libdir else {
|
||||
n[1]: n for n in find(sexpr.parse(open(CACHE).read()), "symbol")}
|
||||
for name, node in CUSTOM.items():
|
||||
syms[f"pico-serial:{name}"] = [Sym("symbol"), f"pico-serial:{name}"] + node[2:]
|
||||
missing = [i for i in needed_lib_ids() if i not in syms]
|
||||
if missing:
|
||||
raise SystemExit(f"symbols missing from cache, run with --kicad-sym9: {missing}")
|
||||
return syms
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
class Geo:
|
||||
"""Graphics and pins of one symbol, in library coordinates (y up)."""
|
||||
|
||||
def __init__(self, node):
|
||||
self.node = node
|
||||
self.pins, self.shapes = [], []
|
||||
name = node[1].split(":")[1]
|
||||
for sub in find(node, "symbol"):
|
||||
tag = sub[1][len(name) + 1:].split("_")
|
||||
if len(tag) == 2 and tag[1] == "2": # De Morgan body style: skip
|
||||
continue
|
||||
for g in sub[2:]:
|
||||
if not isinstance(g, list):
|
||||
continue
|
||||
k = g[0]
|
||||
if k == "pin":
|
||||
at = first(g, "at")
|
||||
hide = any(x == "hide" for x in g) or (first(g, "hide") or [None, "no"])[1] == "yes"
|
||||
self.pins.append(dict(
|
||||
type=str(g[1]), x=float(at[1]), y=float(at[2]), ang=float(at[3]) if len(at) > 3 else 0,
|
||||
length=float(first(g, "length")[1]), name=first(g, "name")[1],
|
||||
number=first(g, "number")[1], hide=hide))
|
||||
elif k in ("rectangle", "polyline", "circle", "arc", "bezier"):
|
||||
self.shapes.append(g)
|
||||
self.hide_names = self._hidden("pin_names")
|
||||
self.hide_numbers = self._hidden("pin_numbers")
|
||||
off = first(first(node, "pin_names") or [], "offset")
|
||||
self.name_offset = float(off[1]) if off else 0.508
|
||||
self.power = first(node, "power") is not None
|
||||
|
||||
def _hidden(self, key):
|
||||
n = first(self.node, key)
|
||||
if n is None:
|
||||
return False
|
||||
return any(x == "hide" for x in n) or (first(n, "hide") or [None, "no"])[1] == "yes"
|
||||
|
||||
def shape_points(self):
|
||||
pins, self.pins = self.pins, []
|
||||
try:
|
||||
yield from self.points()
|
||||
finally:
|
||||
self.pins = pins
|
||||
|
||||
def points(self):
|
||||
for g in self.shapes:
|
||||
k = g[0]
|
||||
if k == "rectangle":
|
||||
for key in ("start", "end"):
|
||||
a = first(g, key)
|
||||
yield float(a[1]), float(a[2])
|
||||
elif k in ("polyline", "bezier"):
|
||||
for xy in find(first(g, "pts"), "xy"):
|
||||
yield float(xy[1]), float(xy[2])
|
||||
elif k == "circle":
|
||||
c, r = first(g, "center"), float(first(g, "radius")[1])
|
||||
yield float(c[1]) - r, float(c[2]) - r
|
||||
yield float(c[1]) + r, float(c[2]) + r
|
||||
elif k == "arc":
|
||||
for key in ("start", "mid", "end"):
|
||||
a = first(g, key)
|
||||
yield float(a[1]), float(a[2])
|
||||
for p in self.pins:
|
||||
yield p["x"], p["y"]
|
||||
dx, dy = DIRS[p["ang"]]
|
||||
yield p["x"] + dx * p["length"], p["y"] + dy * p["length"]
|
||||
|
||||
|
||||
DIRS = {0: (1, 0), 90: (0, 1), 180: (-1, 0), 270: (0, -1)}
|
||||
|
||||
|
||||
def xf(x, y, ox, oy, rot=0):
|
||||
"""library point -> sheet point for a symbol at (ox, oy) rotated rot degrees CCW."""
|
||||
r = math.radians(rot)
|
||||
xr, yr = x * math.cos(r) - y * math.sin(r), x * math.sin(r) + y * math.cos(r)
|
||||
return round(ox + xr, 4), round(oy - yr, 4)
|
||||
|
||||
|
||||
def out_dir(pin_ang, rot=0):
|
||||
"""Sheet-space unit vector pointing away from the body at a pin's end."""
|
||||
dx, dy = DIRS[pin_ang]
|
||||
r = math.radians(rot)
|
||||
ox, oy = -(dx * math.cos(r) - dy * math.sin(r)), -(dx * math.sin(r) + dy * math.cos(r))
|
||||
return round(ox), round(-oy)
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# Placement: a "cell" is one symbol with its stubs, labels, power symbols
|
||||
# and property texts, built at the origin and then moved into place.
|
||||
# ===========================================================================
|
||||
class Box:
|
||||
def __init__(self, x0, y0, x1, y1, owner, kind):
|
||||
self.x0, self.y0, self.x1, self.y1 = min(x0, x1), min(y0, y1), max(x0, x1), max(y0, y1)
|
||||
self.owner, self.kind = owner, kind
|
||||
|
||||
def moved(self, dx, dy):
|
||||
return Box(self.x0 + dx, self.y0 + dy, self.x1 + dx, self.y1 + dy, self.owner, self.kind)
|
||||
|
||||
def hits(self, o, gap=0.0):
|
||||
return not (self.x1 + gap <= o.x0 or o.x1 + gap <= self.x0 or self.y1 + gap <= o.y0 or o.y1 + gap <= self.y0)
|
||||
|
||||
|
||||
NET_OF = {}
|
||||
for _net, _members in N.nets.items():
|
||||
for _m in _members:
|
||||
NET_OF[_m] = _net
|
||||
|
||||
|
||||
class Cell:
|
||||
def __init__(self, ref, syms):
|
||||
self.ref = ref
|
||||
self.lid = lib_id(ref)
|
||||
self.geo = Geo(syms[self.lid])
|
||||
self.wires, self.labels, self.powers, self.ncs = [], [], [], []
|
||||
self.boxes = []
|
||||
self.props = {}
|
||||
part = N.parts[ref]
|
||||
pts = list(self.geo.points())
|
||||
xs = [x for x, _ in pts]
|
||||
ys = [-y for _, y in pts]
|
||||
bx0, bx1, by0, by1 = min(xs), max(xs), min(ys), max(ys)
|
||||
self.boxes.append(Box(bx0, by0, bx1, by1, ref, "symbol"))
|
||||
shp = [p for p in Geo.shape_points(self.geo)] or pts
|
||||
self.body = (min(x for x, _ in shp), min(-y for _, y in shp), max(x for x, _ in shp), max(-y for _, y in shp))
|
||||
self.vertical_only = all(DIRS[p["ang"]][0] == 0 for p in self.geo.pins)
|
||||
# one stub per distinct pin end (stacked hidden pins share it)
|
||||
ends = defaultdict(list)
|
||||
for p in self.geo.pins:
|
||||
ends[(p["x"], p["y"])].append(p)
|
||||
for (x, y), plist in ends.items():
|
||||
nets = {NET_OF.get((ref, p["number"])) for p in plist}
|
||||
ncs = {(ref, p["number"]) in N.noconnect for p in plist}
|
||||
if len(nets) > 1 or (True in ncs and nets != {None}):
|
||||
raise SystemExit(f"{ref}: stacked pins {[p['number'] for p in plist]} disagree: {nets}")
|
||||
sx, sy = xf(x, y, 0, 0)
|
||||
net = nets.pop()
|
||||
if net is None:
|
||||
self.ncs.append((sx, sy))
|
||||
continue
|
||||
vis = [p for p in plist if not p["hide"]] or plist
|
||||
ux, uy = out_dir(vis[0]["ang"])
|
||||
ex, ey = snap(sx + ux * STUB), snap(sy + uy * STUB)
|
||||
self.wires.append(((sx, sy), (ex, ey)))
|
||||
if net in POWER:
|
||||
self.add_power(POWER[net], net, ex, ey, ux, uy)
|
||||
else:
|
||||
self.add_label(net, ex, ey, ux, uy)
|
||||
self.place_props(part)
|
||||
|
||||
def add_label(self, net, x, y, ux, uy):
|
||||
ang = {(1, 0): 0, (0, -1): 90, (-1, 0): 180, (0, 1): 270}[(ux, uy)]
|
||||
w = text_w(net)
|
||||
self.labels.append((net, x, y, ang))
|
||||
if ux:
|
||||
self.boxes.append(Box(x, y - 1.55, x + ux * w, y - 0.2, self.ref, "label " + net))
|
||||
else:
|
||||
self.boxes.append(Box(x - 1.55, y, x - 0.2, y + uy * w, self.ref, "label " + net))
|
||||
|
||||
def add_power(self, lid, value, x, y, ux, uy):
|
||||
up = lid in BODY_UP
|
||||
# rotation (CCW) that turns the symbol's body toward (ux, uy)
|
||||
rot = ({(0, -1): 0, (-1, 0): 90, (0, 1): 180, (1, 0): 270} if up else
|
||||
{(0, 1): 0, (1, 0): 90, (0, -1): 180, (-1, 0): 270})[(ux, uy)]
|
||||
w = text_w(value)
|
||||
name = "power " + value
|
||||
if uy: # text turned vertical, so neighbours 2.54 mm apart don't collide
|
||||
ty = y + uy * 3.6
|
||||
vat = (x, ty, "left" if uy < 0 else "right", 90)
|
||||
self.boxes.append(Box(x - 1.2, y + uy * 0.2, x + 1.2, y + uy * 2.8, self.ref, name))
|
||||
self.boxes.append(Box(x - 0.75, ty, x + 0.75, ty + uy * w, self.ref, name + " text"))
|
||||
else:
|
||||
tx = x + ux * 3.3
|
||||
vat = (tx, y, "left" if ux > 0 else "right", 0)
|
||||
self.boxes.append(Box(x + ux * 0.2, y - 1.0, x + ux * 2.8, y + 1.0, self.ref, name))
|
||||
self.boxes.append(Box(tx, y - 0.7, tx + ux * w, y + 0.7, self.ref, name + " text"))
|
||||
self.powers.append((lid, value, x, y, rot, vat))
|
||||
|
||||
def place_props(self, part):
|
||||
"""Reference and value where nothing else is: beside a vertical two-pin part,
|
||||
otherwise above and below everything the part has drawn."""
|
||||
ref, val = self.ref, part["value"] + (" (DNP)" if part["dnp"] else "")
|
||||
self.value_text = val
|
||||
x0, y0, x1, y1 = self.body
|
||||
if self.vertical_only and (x1 - x0) < 8:
|
||||
x = x1 + 1.27
|
||||
self.props["Reference"] = (snap(x), -0.635, "left")
|
||||
self.props["Value"] = (snap(x), 1.905, "left")
|
||||
for t, (px, py, _) in self.props.items():
|
||||
self.boxes.append(Box(px, py - 0.7, px + text_w(ref if t == "Reference" else val), py + 0.7, ref, t))
|
||||
return
|
||||
top = min(b.y0 for b in self.boxes)
|
||||
bot = max(b.y1 for b in self.boxes)
|
||||
wide = (x1 - x0) >= 8
|
||||
def put(t, s, y):
|
||||
if wide:
|
||||
px, j = x0, "left"
|
||||
bx = (px, px + text_w(s))
|
||||
else:
|
||||
px, j = (x0 + x1) / 2, "center"
|
||||
bx = (px - text_w(s) / 2, px + text_w(s) / 2)
|
||||
self.props[t] = (snap(px), snap(y), j)
|
||||
self.boxes.append(Box(bx[0], snap(y) - 0.7, bx[1], snap(y) + 0.7, ref, t))
|
||||
put("Reference", ref, top - 1.27)
|
||||
put("Value", val, bot + 1.27)
|
||||
|
||||
def bbox(self):
|
||||
return (min(b.x0 for b in self.boxes), min(b.y0 for b in self.boxes),
|
||||
max(b.x1 for b in self.boxes), max(b.y1 for b in self.boxes))
|
||||
|
||||
|
||||
def order_key(ref):
|
||||
p = N.parts[ref]
|
||||
kind = 0 if ref[0] in "UJ" else 1 if ref.startswith(("Y", "SW", "F", "D")) and not p["dnp"] else 2
|
||||
return (kind, N.natural(ref))
|
||||
|
||||
|
||||
def layout(syms):
|
||||
cells = {r: Cell(r, syms) for r in N.parts}
|
||||
placed, titles = {}, []
|
||||
block_size = {}
|
||||
block_items = {}
|
||||
for key, title, maxw in BLOCKS:
|
||||
refs = sorted((r for r in N.parts if N.parts[r]["block"] == key), key=order_key)
|
||||
x = y = 0.0
|
||||
row_h = 0.0
|
||||
items = []
|
||||
left = 0.0
|
||||
if refs and refs[0][0] in "UJ": # the block's chip on the left, the rest in a grid beside it
|
||||
r = refs.pop(0)
|
||||
x0, y0, x1, y1 = cells[r].bbox()
|
||||
items.append((r, snap(-x0 + 2.54, 2.54), snap(-y0 + 2.54, 2.54)))
|
||||
left = items[0][1] + x1 + 5.08
|
||||
x = left
|
||||
for r in refs:
|
||||
c = cells[r]
|
||||
x0, y0, x1, y1 = c.bbox()
|
||||
w, h = x1 - x0, y1 - y0
|
||||
if x > left and x + w > maxw:
|
||||
x, y, row_h = left, y + row_h + 3.81, 0.0
|
||||
ox, oy = snap(x - x0, 2.54), snap(y - y0, 2.54)
|
||||
if ox + x0 < x - 1e-6:
|
||||
ox += 2.54
|
||||
if oy + y0 < y - 1e-6:
|
||||
oy += 2.54
|
||||
items.append((r, ox, oy))
|
||||
x = ox + x1 + 2.54
|
||||
row_h = max(row_h, oy + y1 - y)
|
||||
block_items[key] = items
|
||||
bw = max((ox + cells[r].bbox()[2] for r, ox, oy in items), default=0)
|
||||
bh = max((oy + cells[r].bbox()[3] for r, ox, oy in items), default=0)
|
||||
block_size[key] = (bw, bh)
|
||||
block_size["flags"] = FLAGS_SIZE
|
||||
# blocks onto the sheet, row by row
|
||||
margin, title_h, gap = 17.78, 7.62, 10.16
|
||||
y = margin
|
||||
sheet_w = 0
|
||||
origins = {}
|
||||
names = dict((k, t) for k, t, _ in BLOCKS)
|
||||
for row in SHEET_ROWS:
|
||||
x = margin
|
||||
rh = 0
|
||||
for column in row:
|
||||
cy, cw = y, 0
|
||||
for key in column:
|
||||
bw, bh = block_size[key]
|
||||
bx, by = snap(x, 2.54), snap(cy + title_h, 2.54)
|
||||
origins[key] = (bx, by)
|
||||
titles.append((names[key], bx, by - 3.81))
|
||||
for r, ox, oy in block_items[key]:
|
||||
placed[r] = (snap(bx + ox, 2.54), snap(by + oy, 2.54))
|
||||
cy = by + bh + gap
|
||||
cw = max(cw, bw)
|
||||
x = snap(x, 2.54) + cw + gap
|
||||
rh = max(rh, cy - y - gap)
|
||||
sheet_w = max(sheet_w, x)
|
||||
y += rh + gap
|
||||
return cells, placed, titles, (sheet_w + margin, y + margin), origins
|
||||
|
||||
|
||||
PAPER = [("A3", 420, 297), ("A2", 594, 420), ("A1", 841, 594), ("A0", 1189, 841)]
|
||||
|
||||
|
||||
def pick_paper(w, h):
|
||||
for name, pw, ph in PAPER:
|
||||
if w <= pw - 10 and h <= ph - 10:
|
||||
return name, pw, ph
|
||||
raise SystemExit(f"drawing {w:.0f} x {h:.0f} mm doesn't fit A0")
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# Writing the schematic
|
||||
# ===========================================================================
|
||||
def eff(size=FONT, justify=None, hide=False, bold=False):
|
||||
font = [Sym("font"), [Sym("size"), size, size]]
|
||||
if bold:
|
||||
font.append([Sym("bold"), Sym("yes")])
|
||||
e = [Sym("effects"), font]
|
||||
if justify:
|
||||
e.append([Sym("justify")] + [Sym(j) for j in justify.split()])
|
||||
if hide:
|
||||
e.append([Sym("hide"), Sym("yes")])
|
||||
return e
|
||||
|
||||
|
||||
def prop(k, v, x, y, justify=None, hide=False, ang=0):
|
||||
return [Sym("property"), k, v, [Sym("at"), x, y, ang], eff(justify=justify, hide=hide)]
|
||||
|
||||
|
||||
def build(syms):
|
||||
cells, placed, titles, (w, h), origins = layout(syms)
|
||||
paper, pw, ph = pick_paper(w, h)
|
||||
root = uid("root")
|
||||
items = []
|
||||
pwr_n = [0]
|
||||
|
||||
def instance(lid, ref, x, y, rot, props, pins, dnp=False, in_bom=True, on_board=True):
|
||||
node = [Sym("symbol"), [Sym("lib_id"), lid], [Sym("at"), x, y, rot], [Sym("unit"), 1],
|
||||
[Sym("exclude_from_sim"), Sym("no")], [Sym("in_bom"), Sym("yes" if in_bom else "no")],
|
||||
[Sym("on_board"), Sym("yes" if on_board else "no")], [Sym("dnp"), Sym("yes" if dnp else "no")],
|
||||
[Sym("uuid"), uid("sym", ref)]]
|
||||
node += props
|
||||
node += [[Sym("pin"), n, [Sym("uuid"), uid("pin", ref, n)]] for n in pins]
|
||||
node.append([Sym("instances"), [Sym("project"), PROJECT, [Sym("path"), f"/{root}",
|
||||
[Sym("reference"), ref], [Sym("unit"), 1]]]])
|
||||
return node
|
||||
|
||||
def power_symbol(lid, value, x, y, rot, vat):
|
||||
pwr_n[0] += 1
|
||||
ref = f"#PWR{pwr_n[0]:03d}"
|
||||
vx, vy, j, va = vat
|
||||
return instance(lid, ref, x, y, rot,
|
||||
[prop("Reference", ref, x, y, hide=True),
|
||||
prop("Value", value, vx, vy, justify=None if j == "center" else j, ang=va),
|
||||
prop("Footprint", "", x, y, hide=True), prop("Datasheet", "", x, y, hide=True),
|
||||
prop("Description", "", x, y, hide=True)], ["1"])
|
||||
|
||||
world = [] # for checks: (kind, data)
|
||||
boxes = []
|
||||
for ref in sorted(N.parts, key=N.natural):
|
||||
c, (X, Y) = cells[ref], placed[ref]
|
||||
part = N.parts[ref]
|
||||
props = []
|
||||
for k in ("Reference", "Value"):
|
||||
px, py, j = c.props[k]
|
||||
props.append(prop(k, ref if k == "Reference" else part["value"], X + px, Y + py,
|
||||
justify=None if j == "center" else j))
|
||||
props.append(prop("Footprint", part["footprint"], X, Y, hide=True))
|
||||
lsym = syms[c.lid]
|
||||
ds = next((p[2] for p in find(lsym, "property") if p[1] == "Datasheet"), "")
|
||||
props.append(prop("Datasheet", ds, X, Y, hide=True))
|
||||
desc = part["desc"] or next((p[2] for p in find(lsym, "property") if p[1] == "Description"), "")
|
||||
props.append(prop("Description", desc, X, Y, hide=True))
|
||||
if part["lcsc"]:
|
||||
props.append(prop("LCSC", part["lcsc"], X, Y, hide=True))
|
||||
if part["note"]:
|
||||
props.append(prop("Note", part["note"], X, Y, hide=True))
|
||||
pins = sorted({p["number"] for p in c.geo.pins}, key=N.natural)
|
||||
items.append(instance(c.lid, ref, X, Y, 0, props, pins, dnp=part["dnp"],
|
||||
in_bom=part["assembly"] != "none"))
|
||||
for p in c.geo.pins:
|
||||
world.append(("pin", (ref, p["number"]), xf(p["x"], p["y"], X, Y)))
|
||||
for (a, b) in c.wires:
|
||||
pa, pb = (a[0] + X, a[1] + Y), (b[0] + X, b[1] + Y)
|
||||
items.append([Sym("wire"), [Sym("pts"), [Sym("xy"), *pa], [Sym("xy"), *pb]],
|
||||
[Sym("stroke"), [Sym("width"), 0], [Sym("type"), Sym("default")]],
|
||||
[Sym("uuid"), uid("wire", ref, *pa)]])
|
||||
world.append(("wire", None, (pa, pb)))
|
||||
for net, x, y, ang in c.labels:
|
||||
j = "left bottom" if ang in (0, 90) else "right bottom"
|
||||
items.append([Sym("label"), net, [Sym("at"), x + X, y + Y, ang], eff(justify=j),
|
||||
[Sym("uuid"), uid("label", ref, x, y)]])
|
||||
world.append(("label", net, (x + X, y + Y)))
|
||||
for lid, value, x, y, rot, (vx, vy, j, va) in c.powers:
|
||||
items.append(power_symbol(lid, value, x + X, y + Y, rot, (vx + X, vy + Y, j, va)))
|
||||
world.append(("power", value, (x + X, y + Y)))
|
||||
for x, y in c.ncs:
|
||||
items.append([Sym("no_connect"), [Sym("at"), x + X, y + Y], [Sym("uuid"), uid("nc", ref, x, y)]])
|
||||
world.append(("nc", None, (x + X, y + Y)))
|
||||
boxes += [b.moved(X, Y) for b in c.boxes]
|
||||
|
||||
# power flags: GND and VBUS have no power output pin on them
|
||||
fx, fy = snap(origins["flags"][0] + 2.54, 2.54), snap(origins["flags"][1] + 7.62, 2.54)
|
||||
flags = [("GND", "power:GND", fx, fy), ("VBUS", "power:VBUS", fx + 15.24, fy)]
|
||||
for i, (net, lid, x, y) in enumerate(flags, 1):
|
||||
up = lid in BODY_UP
|
||||
items.append(power_symbol(lid, net, x, y, 0, (x, y + (-5.08 if up else 5.08), "center", 0)))
|
||||
world.append(("power", net, (x, y)))
|
||||
fxp = x + 5.08
|
||||
items.append([Sym("wire"), [Sym("pts"), [Sym("xy"), x, y], [Sym("xy"), fxp, y]],
|
||||
[Sym("stroke"), [Sym("width"), 0], [Sym("type"), Sym("default")]], [Sym("uuid"), uid("flagwire", net)]])
|
||||
world.append(("wire", None, ((x, y), (fxp, y))))
|
||||
ref = f"#FLG{i:02d}"
|
||||
items.append(instance("power:PWR_FLAG", ref, fxp, y, 0,
|
||||
[prop("Reference", ref, fxp, y, hide=True),
|
||||
prop("Value", "PWR_FLAG", fxp, y - 3.81, justify="left"),
|
||||
prop("Footprint", "", fxp, y, hide=True), prop("Datasheet", "", fxp, y, hide=True),
|
||||
prop("Description", "", fxp, y, hide=True)], ["1"]))
|
||||
world.append(("flag", net, (fxp, y)))
|
||||
items.append(text_node("GND and VBUS have no power-output pin", fx - 2.54, fy + 10.16, 1.27))
|
||||
|
||||
for t, x, y in titles:
|
||||
items.append(text_node(t, x, y, 2.0, bold=True))
|
||||
boxes.append(Box(x, y - 2.2, x + text_w(t, 2.0) * 1.05, y + 0.4, "title", "title " + t))
|
||||
|
||||
note = ("Generated by hardware/schematic/build_schematic.py from hardware/netlist/build_netlist.py. "
|
||||
"Edit the netlist script and regenerate; hand edits here are lost.")
|
||||
items.append(text_node(note, 20.32, ph - 12.7, 1.27))
|
||||
|
||||
sch = [Sym("kicad_sch"), [Sym("version"), Sym("20250114")], [Sym("generator"), "eeschema"],
|
||||
[Sym("generator_version"), "9.0"], [Sym("uuid"), root], [Sym("paper"), paper],
|
||||
[Sym("title_block"), [Sym("title"), "pico-serial: USB-C to DB25 RS-232 (DCE/DTE)"],
|
||||
[Sym("date"), datetime.date.today().isoformat()], [Sym("rev"), "0.3"],
|
||||
[Sym("comment"), 1, "RP2040, SP3238E (DCE) + MAX3243E (DTE) on one female DB25"],
|
||||
[Sym("comment"), 2, "See SPEC.md; parts and nets come from hardware/netlist/build_netlist.py"]],
|
||||
[Sym("lib_symbols")] + [syms[k] for k in sorted({lib_id(r) for r in N.parts} | set(POWER.values()) | {"power:PWR_FLAG"})]]
|
||||
sch += items
|
||||
sch += [[Sym("sheet_instances"), [Sym("path"), "/", [Sym("page"), "1"]]], [Sym("embedded_fonts"), Sym("no")]]
|
||||
return sch, world, boxes, cells, placed, (paper, pw, ph)
|
||||
|
||||
|
||||
def text_node(s, x, y, size, bold=False):
|
||||
return [Sym("text"), s, [Sym("exclude_from_sim"), Sym("no")], [Sym("at"), x, y, 0],
|
||||
eff(size=size, justify="left bottom", bold=bold), [Sym("uuid"), uid("text", s)]]
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# Checks
|
||||
# ===========================================================================
|
||||
def connectivity(world):
|
||||
"""Nets as KiCad would see them: by coincident points, labels and power names."""
|
||||
parent = {}
|
||||
|
||||
def f(a):
|
||||
parent.setdefault(a, a)
|
||||
while parent[a] != a:
|
||||
parent[a] = parent[parent[a]]
|
||||
a = parent[a]
|
||||
return a
|
||||
|
||||
def u(a, b):
|
||||
parent[f(a)] = f(b)
|
||||
|
||||
def pt(p):
|
||||
return ("pt", round(p[0], 3), round(p[1], 3))
|
||||
segs = []
|
||||
for kind, data, geo in world:
|
||||
if kind == "wire":
|
||||
a, b = geo
|
||||
u(pt(a), pt(b))
|
||||
segs.append((a, b))
|
||||
elif kind == "pin":
|
||||
u(("pin",) + data, pt(geo))
|
||||
elif kind == "label":
|
||||
u(("net", data), pt(geo))
|
||||
elif kind in ("power", "flag"):
|
||||
u(("net", data), pt(geo))
|
||||
elif kind == "nc":
|
||||
f(pt(geo))
|
||||
# a point in the middle of a wire would join it in KiCad (with a junction): forbid
|
||||
errs = []
|
||||
for kind, data, geo in world:
|
||||
if kind in ("pin", "label", "power", "nc"):
|
||||
for a, b in segs:
|
||||
near = any(abs(geo[0] - e[0]) < 1e-3 and abs(geo[1] - e[1]) < 1e-3 for e in (a, b))
|
||||
if on_segment(geo, a, b) and not near:
|
||||
errs.append(f"{kind} {data} at {geo} sits on the middle of a wire")
|
||||
nets = defaultdict(set)
|
||||
for k in list(parent):
|
||||
if k[0] == "pin":
|
||||
nets[f(k)].add((k[1], k[2]))
|
||||
return [frozenset(v) for v in nets.values()], errs, f
|
||||
|
||||
|
||||
def on_segment(p, a, b):
|
||||
(x, y), (x0, y0), (x1, y1) = p, a, b
|
||||
if abs((x1 - x0) * (y - y0) - (y1 - y0) * (x - x0)) > 1e-6:
|
||||
return False
|
||||
return min(x0, x1) - 1e-6 <= x <= max(x0, x1) + 1e-6 and min(y0, y1) - 1e-6 <= y <= max(y0, y1) + 1e-6
|
||||
|
||||
|
||||
def check(world, boxes, cells):
|
||||
errs = []
|
||||
got, e2, _ = connectivity(world)
|
||||
errs += e2
|
||||
want = [frozenset(m) for m in N.nets.values()]
|
||||
# pins left open: each should be a net of one (its own) in the drawing
|
||||
got_multi = {g for g in got if len(g) > 1}
|
||||
want_set = set(want)
|
||||
# stacked pins of one symbol at the same point come out joined; that's fine if the
|
||||
# netlist has them on one net. Compare after dropping singletons.
|
||||
for g in got_multi - want_set:
|
||||
errs.append(f"drawing has a net the netlist doesn't: {sorted(g)}")
|
||||
for w_ in want_set - got_multi:
|
||||
errs.append(f"netlist net not drawn as one net: {sorted(w_)}")
|
||||
for g in got:
|
||||
if len(g) == 1:
|
||||
(m,) = g
|
||||
if m not in N.noconnect:
|
||||
errs.append(f"pin {m} is isolated in the drawing but not marked NC")
|
||||
# overlaps (text, labels, bodies): a label touching its own wire end is fine
|
||||
bs = sorted(boxes, key=lambda b: b.x0)
|
||||
for i, a in enumerate(bs):
|
||||
for b in bs[i + 1:]:
|
||||
if b.x0 >= a.x1:
|
||||
break
|
||||
if a.hits(b, gap=-0.05) and not (a.owner == b.owner and "symbol" in (a.kind, b.kind)):
|
||||
errs.append(f"overlap: {a.owner} {a.kind} / {b.owner} {b.kind}")
|
||||
return errs
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# Preview (rough SVG: shapes, pins, labels; good enough to eyeball layout)
|
||||
# ===========================================================================
|
||||
def preview(sch, syms, path, pw, ph):
|
||||
S = 4 # px per mm
|
||||
out = [f'<svg xmlns="http://www.w3.org/2000/svg" width="{pw * S:.0f}" height="{ph * S:.0f}" '
|
||||
f'viewBox="0 0 {pw} {ph}" font-family="Helvetica, Arial, sans-serif">',
|
||||
'<rect width="100%" height="100%" fill="#f5f4ee"/>',
|
||||
f'<rect x="10" y="10" width="{pw - 20}" height="{ph - 20}" fill="none" stroke="#8a2f2f" stroke-width="0.25"/>']
|
||||
col_body, col_line, col_wire, col_text, col_label = "#fffbd8", "#8a2f2f", "#1b7a3a", "#1a3d8f", "#222"
|
||||
|
||||
def T(x, y, s, size=1.27, anchor="start", rot=0, color=col_text, weight="normal", baseline="auto"):
|
||||
tr = f' transform="rotate({-rot} {x:.3f} {y:.3f})"' if rot else ""
|
||||
s = s.replace("&", "&").replace("<", "<").replace("~{", "").replace("}", "")
|
||||
return (f'<text x="{x:.3f}" y="{y:.3f}" font-size="{size * 1.15:.2f}" text-anchor="{anchor}" fill="{color}" '
|
||||
f'font-weight="{weight}" dominant-baseline="{baseline}"{tr}>{s}</text>')
|
||||
for node in sch:
|
||||
if not isinstance(node, list):
|
||||
continue
|
||||
k = node[0]
|
||||
if k == "wire":
|
||||
(a, b) = [tuple(float(v) for v in xy[1:]) for xy in find(first(node, "pts"), "xy")]
|
||||
out.append(f'<line x1="{a[0]}" y1="{a[1]}" x2="{b[0]}" y2="{b[1]}" stroke="{col_wire}" stroke-width="0.15"/>')
|
||||
elif k == "label":
|
||||
at = first(node, "at")
|
||||
x, y, ang = float(at[1]), float(at[2]), float(at[3])
|
||||
anchor = "start" if ang in (0, 90) else "end"
|
||||
rot = 90 if ang in (90, 270) else 0
|
||||
out.append(T(x, y - 0.3 if not rot else y, node[1], anchor=anchor, rot=rot, color=col_label)
|
||||
if not rot else T(x - 0.3, y, node[1], anchor=anchor, rot=rot, color=col_label))
|
||||
elif k == "no_connect":
|
||||
at = first(node, "at")
|
||||
x, y = float(at[1]), float(at[2])
|
||||
out.append(f'<path d="M{x - .6},{y - .6}L{x + .6},{y + .6}M{x - .6},{y + .6}L{x + .6},{y - .6}" '
|
||||
f'stroke="#1a3d8f" stroke-width="0.15"/>')
|
||||
elif k == "text":
|
||||
at = first(node, "at")
|
||||
size = float(first(first(first(node, "effects"), "font"), "size")[1])
|
||||
bold = first(first(first(node, "effects"), "font"), "bold") is not None
|
||||
out.append(T(float(at[1]), float(at[2]), node[1], size=size, color="#333",
|
||||
weight="bold" if bold else "normal"))
|
||||
elif k == "symbol":
|
||||
lid = first(node, "lib_id")[1]
|
||||
at = first(node, "at")
|
||||
X, Y, rot = float(at[1]), float(at[2]), float(at[3])
|
||||
g = Geo(syms[lid])
|
||||
|
||||
def P(x, y):
|
||||
return xf(x, y, X, Y, rot)
|
||||
for s in g.shapes:
|
||||
kind = s[0]
|
||||
fill = first(first(s, "fill") or [], "type")
|
||||
fc = col_body if fill and fill[1] == "background" else ("#8a2f2f" if fill and fill[1] == "outline" else "none")
|
||||
if kind == "rectangle":
|
||||
a, b = P(*map(float, first(s, "start")[1:3])), P(*map(float, first(s, "end")[1:3]))
|
||||
out.append(f'<rect x="{min(a[0], b[0])}" y="{min(a[1], b[1])}" width="{abs(a[0] - b[0])}" '
|
||||
f'height="{abs(a[1] - b[1])}" fill="{fc}" stroke="{col_line}" stroke-width="0.2"/>')
|
||||
elif kind in ("polyline", "bezier"):
|
||||
pts = " ".join("%.3f,%.3f" % P(float(xy[1]), float(xy[2])) for xy in find(first(s, "pts"), "xy"))
|
||||
out.append(f'<polyline points="{pts}" fill="{fc}" stroke="{col_line}" stroke-width="0.2"/>')
|
||||
elif kind == "circle":
|
||||
c = P(*map(float, first(s, "center")[1:3]))
|
||||
out.append(f'<circle cx="{c[0]}" cy="{c[1]}" r="{first(s, "radius")[1]}" fill="{fc}" '
|
||||
f'stroke="{col_line}" stroke-width="0.2"/>')
|
||||
elif kind == "arc":
|
||||
a, m, b = (P(*map(float, first(s, key)[1:3])) for key in ("start", "mid", "end"))
|
||||
out.append(arc_path(a, m, b, col_line))
|
||||
for p in g.pins:
|
||||
if p["hide"]:
|
||||
continue
|
||||
dx, dy = DIRS[p["ang"]]
|
||||
a = P(p["x"], p["y"])
|
||||
b = P(p["x"] + dx * p["length"], p["y"] + dy * p["length"])
|
||||
out.append(f'<line x1="{a[0]}" y1="{a[1]}" x2="{b[0]}" y2="{b[1]}" stroke="{col_line}" stroke-width="0.2"/>')
|
||||
if g.power or p["length"] == 0:
|
||||
continue
|
||||
sx, sy = b[0] - a[0], b[1] - a[1]
|
||||
L = math.hypot(sx, sy) or 1
|
||||
ux, uy = sx / L, sy / L
|
||||
if not g.hide_names and p["name"] not in ("~", ""):
|
||||
off = g.name_offset if g.name_offset > 0 else 0
|
||||
if off:
|
||||
nx, ny = b[0] + ux * (off + 0.3), b[1] + uy * (off + 0.3)
|
||||
anchor = "start" if ux > 0.5 else "end" if ux < -0.5 else "middle"
|
||||
r = 90 if abs(uy) > 0.5 else 0
|
||||
if r:
|
||||
anchor = "start" if uy < 0 else "end"
|
||||
out.append(T(nx, ny + (0.45 if not r else 0), p["name"], size=1.0, anchor=anchor, rot=r, color="#2b5e88"))
|
||||
if not g.hide_numbers:
|
||||
mx, my = (a[0] + b[0]) / 2, (a[1] + b[1]) / 2
|
||||
if abs(uy) > 0.5:
|
||||
out.append(T(mx - 0.4, my, p["number"], size=0.9, anchor="middle", rot=90, color="#8a2f2f"))
|
||||
else:
|
||||
out.append(T(mx, my - 0.35, p["number"], size=0.9, anchor="middle", color="#8a2f2f"))
|
||||
for pr in find(node, "property"):
|
||||
e = first(pr, "effects")
|
||||
if first(e, "hide") is not None or not pr[2]:
|
||||
continue
|
||||
pat = first(pr, "at")
|
||||
j = first(e, "justify")
|
||||
anchor = "middle"
|
||||
if j is not None and "left" in j:
|
||||
anchor = "start"
|
||||
elif j is not None and "right" in j:
|
||||
anchor = "end"
|
||||
dnp = first(node, "dnp")[1] == "yes"
|
||||
ang = float(pat[3]) if len(pat) > 3 else 0
|
||||
out.append(T(float(pat[1]), float(pat[2]), pr[2] + (" (DNP)" if dnp and pr[1] == "Value" else ""),
|
||||
anchor=anchor, rot=ang, color="#0b5c5c" if pr[1] == "Reference" else "#444",
|
||||
baseline="middle"))
|
||||
out.append("</svg>")
|
||||
open(path, "w").write("\n".join(out))
|
||||
|
||||
|
||||
def arc_path(a, m, b, color):
|
||||
(x1, y1), (x2, y2), (x3, y3) = a, m, b
|
||||
d = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))
|
||||
if abs(d) < 1e-9:
|
||||
return f'<line x1="{x1}" y1="{y1}" x2="{x3}" y2="{y3}" stroke="{color}" stroke-width="0.2"/>'
|
||||
ux = ((x1 ** 2 + y1 ** 2) * (y2 - y3) + (x2 ** 2 + y2 ** 2) * (y3 - y1) + (x3 ** 2 + y3 ** 2) * (y1 - y2)) / d
|
||||
uy = ((x1 ** 2 + y1 ** 2) * (x3 - x2) + (x2 ** 2 + y2 ** 2) * (x1 - x3) + (x3 ** 2 + y3 ** 2) * (x2 - x1)) / d
|
||||
r = math.hypot(x1 - ux, y1 - uy)
|
||||
cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
|
||||
sweep = 1 if cross > 0 else 0
|
||||
large = 0
|
||||
return (f'<path d="M{x1:.3f},{y1:.3f} A{r:.3f},{r:.3f} 0 {large} {sweep} {x3:.3f},{y3:.3f}" fill="none" '
|
||||
f'stroke="{color}" stroke-width="0.2"/>')
|
||||
|
||||
|
||||
def write_lib(path):
|
||||
lib = [Sym("kicad_symbol_lib"), [Sym("version"), Sym("20241209")], [Sym("generator"), "kicad_symbol_editor"],
|
||||
[Sym("generator_version"), "9.0"]] + [CUSTOM[k] for k in sorted(CUSTOM)]
|
||||
open(path, "w").write(sexpr.dump(lib) + "\n")
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
||||
ap.add_argument("--kicad-sym9", help="kicad-symbols checkout (9.0 tag), refreshes lib/symbol-cache.sexp")
|
||||
a = ap.parse_args()
|
||||
syms = load_symbols(a.kicad_sym9)
|
||||
sch, world, boxes, cells, placed, (paper, pw, ph) = build(syms)
|
||||
errs = check(world, boxes, cells)
|
||||
for e in errs:
|
||||
print("ERROR:", e)
|
||||
if errs:
|
||||
sys.exit(1)
|
||||
text = sexpr.dump(sch) + "\n"
|
||||
sexpr.parse(text) # round-trips
|
||||
open(os.path.join(HERE, f"{PROJECT}.kicad_sch"), "w").write(text)
|
||||
write_lib(os.path.join(HERE, f"{PROJECT}.kicad_sym"))
|
||||
open(os.path.join(HERE, "sym-lib-table"), "w").write(
|
||||
'(sym_lib_table\n\t(version 7)\n\t(lib (name "pico-serial") (type "KiCad") '
|
||||
'(uri "${KIPRJMOD}/pico-serial.kicad_sym") (options "") (descr "SP3238E, MAX3243E"))\n)\n')
|
||||
pro = os.path.join(HERE, f"{PROJECT}.kicad_pro")
|
||||
if not os.path.exists(pro):
|
||||
open(pro, "w").write('{\n "meta": {\n "filename": "pico-serial.kicad_pro",\n "version": 3\n }\n}\n')
|
||||
preview(sch, syms, os.path.join(HERE, "preview.svg"), pw, ph)
|
||||
n_sym = sum(1 for x in sch if isinstance(x, list) and x[0] == "symbol")
|
||||
n_lab = sum(1 for x in sch if isinstance(x, list) and x[0] == "label")
|
||||
print(f"ok: {paper} sheet, {len(N.parts)} parts, {n_sym - len(N.parts)} power symbols/flags, "
|
||||
f"{n_lab} labels; drawing connects exactly as the netlist ({len(N.nets)} nets)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"meta": {
|
||||
"filename": "pico-serial.kicad_pro",
|
||||
"version": 3
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,401 @@
|
||||
(kicad_symbol_lib
|
||||
(version 20241209)
|
||||
(generator "kicad_symbol_editor")
|
||||
(generator_version "9.0")
|
||||
(symbol "MAX3243E"
|
||||
(exclude_from_sim no)
|
||||
(in_bom yes)
|
||||
(on_board yes)
|
||||
(property "Reference" "U" (at -12.7 21.59 0) (effects (font (size 1.27 1.27))))
|
||||
(property "Value" "MAX3243E" (at -12.7 -21.59 0) (effects (font (size 1.27 1.27))))
|
||||
(property "Footprint" "Package_SO:SSOP-28_5.3x10.2mm_P0.65mm"
|
||||
(at 0 0 0)
|
||||
(effects (font (size 1.27 1.27)) (hide yes))
|
||||
)
|
||||
(property "Datasheet" "https://www.ti.com/lit/ds/symlink/max3243e.pdf"
|
||||
(at 0 0 0)
|
||||
(effects (font (size 1.27 1.27)) (hide yes))
|
||||
)
|
||||
(property "Description" "3 V to 5.5 V RS-232 transceiver, 3 drivers / 5 receivers, auto-powerdown, +-15 kV ESD"
|
||||
(at 0 0 0)
|
||||
(effects (font (size 1.27 1.27)) (hide yes))
|
||||
)
|
||||
(symbol "MAX3243E_0_1"
|
||||
(rectangle
|
||||
(start -12.7 20.32)
|
||||
(end 12.7 -20.32)
|
||||
(stroke (width 0.254) (type default))
|
||||
(fill (type background))
|
||||
)
|
||||
)
|
||||
(symbol "MAX3243E_1_1"
|
||||
(pin input line
|
||||
(at -16.51 17.78 0)
|
||||
(length 3.81)
|
||||
(name "DIN1" (effects (font (size 1.27 1.27))))
|
||||
(number "14" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 15.24 0)
|
||||
(length 3.81)
|
||||
(name "DIN2" (effects (font (size 1.27 1.27))))
|
||||
(number "13" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 12.7 0)
|
||||
(length 3.81)
|
||||
(name "DIN3" (effects (font (size 1.27 1.27))))
|
||||
(number "12" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 7.62 0)
|
||||
(length 3.81)
|
||||
(name "ROUT1" (effects (font (size 1.27 1.27))))
|
||||
(number "19" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 5.08 0)
|
||||
(length 3.81)
|
||||
(name "ROUT2" (effects (font (size 1.27 1.27))))
|
||||
(number "18" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 2.54 0)
|
||||
(length 3.81)
|
||||
(name "ROUT3" (effects (font (size 1.27 1.27))))
|
||||
(number "17" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 0 0)
|
||||
(length 3.81)
|
||||
(name "ROUT4" (effects (font (size 1.27 1.27))))
|
||||
(number "16" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 -2.54 0)
|
||||
(length 3.81)
|
||||
(name "ROUT5" (effects (font (size 1.27 1.27))))
|
||||
(number "15" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 -5.08 0)
|
||||
(length 3.81)
|
||||
(name "ROUT2B" (effects (font (size 1.27 1.27))))
|
||||
(number "20" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 -10.16 0)
|
||||
(length 3.81)
|
||||
(name "~{FORCEOFF}" (effects (font (size 1.27 1.27))))
|
||||
(number "22" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 -12.7 0)
|
||||
(length 3.81)
|
||||
(name "FORCEON" (effects (font (size 1.27 1.27))))
|
||||
(number "23" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 -15.24 0)
|
||||
(length 3.81)
|
||||
(name "INVALID" (effects (font (size 1.27 1.27))))
|
||||
(number "21" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 17.78 180)
|
||||
(length 3.81)
|
||||
(name "DOUT1" (effects (font (size 1.27 1.27))))
|
||||
(number "9" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 15.24 180)
|
||||
(length 3.81)
|
||||
(name "DOUT2" (effects (font (size 1.27 1.27))))
|
||||
(number "10" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 12.7 180)
|
||||
(length 3.81)
|
||||
(name "DOUT3" (effects (font (size 1.27 1.27))))
|
||||
(number "11" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 7.62 180)
|
||||
(length 3.81)
|
||||
(name "RIN1" (effects (font (size 1.27 1.27))))
|
||||
(number "4" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 5.08 180)
|
||||
(length 3.81)
|
||||
(name "RIN2" (effects (font (size 1.27 1.27))))
|
||||
(number "5" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 2.54 180)
|
||||
(length 3.81)
|
||||
(name "RIN3" (effects (font (size 1.27 1.27))))
|
||||
(number "6" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 0 180)
|
||||
(length 3.81)
|
||||
(name "RIN4" (effects (font (size 1.27 1.27))))
|
||||
(number "7" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 -2.54 180)
|
||||
(length 3.81)
|
||||
(name "RIN5" (effects (font (size 1.27 1.27))))
|
||||
(number "8" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -7.62 180)
|
||||
(length 3.81)
|
||||
(name "C1+" (effects (font (size 1.27 1.27))))
|
||||
(number "28" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -10.16 180)
|
||||
(length 3.81)
|
||||
(name "C1-" (effects (font (size 1.27 1.27))))
|
||||
(number "24" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -12.7 180)
|
||||
(length 3.81)
|
||||
(name "C2+" (effects (font (size 1.27 1.27))))
|
||||
(number "1" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -15.24 180)
|
||||
(length 3.81)
|
||||
(name "C2-" (effects (font (size 1.27 1.27))))
|
||||
(number "2" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -17.78 180)
|
||||
(length 3.81)
|
||||
(name "V+" (effects (font (size 1.27 1.27))))
|
||||
(number "27" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -20.32 180)
|
||||
(length 3.81)
|
||||
(name "V-" (effects (font (size 1.27 1.27))))
|
||||
(number "3" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin power_in line
|
||||
(at 0 24.13 270)
|
||||
(length 3.81)
|
||||
(name "VCC" (effects (font (size 1.27 1.27))))
|
||||
(number "26" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin power_in line
|
||||
(at 0 -24.13 90)
|
||||
(length 3.81)
|
||||
(name "GND" (effects (font (size 1.27 1.27))))
|
||||
(number "25" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
)
|
||||
(embedded_fonts no)
|
||||
)
|
||||
(symbol "SP3238E"
|
||||
(exclude_from_sim no)
|
||||
(in_bom yes)
|
||||
(on_board yes)
|
||||
(property "Reference" "U" (at -12.7 21.59 0) (effects (font (size 1.27 1.27))))
|
||||
(property "Value" "SP3238E" (at -12.7 -21.59 0) (effects (font (size 1.27 1.27))))
|
||||
(property "Footprint" "Package_SO:SSOP-28_5.3x10.2mm_P0.65mm"
|
||||
(at 0 0 0)
|
||||
(effects (font (size 1.27 1.27)) (hide yes))
|
||||
)
|
||||
(property "Datasheet" "https://www.maxlinear.com/ds/sp3238e.pdf"
|
||||
(at 0 0 0)
|
||||
(effects (font (size 1.27 1.27)) (hide yes))
|
||||
)
|
||||
(property "Description" "3 V to 5.5 V RS-232 transceiver, 5 drivers / 3 receivers, AUTO ON-LINE, +-15 kV ESD"
|
||||
(at 0 0 0)
|
||||
(effects (font (size 1.27 1.27)) (hide yes))
|
||||
)
|
||||
(symbol "SP3238E_0_1"
|
||||
(rectangle
|
||||
(start -12.7 20.32)
|
||||
(end 12.7 -20.32)
|
||||
(stroke (width 0.254) (type default))
|
||||
(fill (type background))
|
||||
)
|
||||
)
|
||||
(symbol "SP3238E_1_1"
|
||||
(pin input line
|
||||
(at -16.51 17.78 0)
|
||||
(length 3.81)
|
||||
(name "T1IN" (effects (font (size 1.27 1.27))))
|
||||
(number "24" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 15.24 0)
|
||||
(length 3.81)
|
||||
(name "T2IN" (effects (font (size 1.27 1.27))))
|
||||
(number "23" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 12.7 0)
|
||||
(length 3.81)
|
||||
(name "T3IN" (effects (font (size 1.27 1.27))))
|
||||
(number "22" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 10.16 0)
|
||||
(length 3.81)
|
||||
(name "T4IN" (effects (font (size 1.27 1.27))))
|
||||
(number "19" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 7.62 0)
|
||||
(length 3.81)
|
||||
(name "T5IN" (effects (font (size 1.27 1.27))))
|
||||
(number "17" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 2.54 0)
|
||||
(length 3.81)
|
||||
(name "R1OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "21" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 0 0)
|
||||
(length 3.81)
|
||||
(name "R2OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "20" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 -2.54 0)
|
||||
(length 3.81)
|
||||
(name "R3OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "18" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 -5.08 0)
|
||||
(length 3.81)
|
||||
(name "R1OUTB" (effects (font (size 1.27 1.27))))
|
||||
(number "16" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 -10.16 0)
|
||||
(length 3.81)
|
||||
(name "ONLINE" (effects (font (size 1.27 1.27))))
|
||||
(number "13" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at -16.51 -12.7 0)
|
||||
(length 3.81)
|
||||
(name "~{SHUTDOWN}" (effects (font (size 1.27 1.27))))
|
||||
(number "14" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at -16.51 -15.24 0)
|
||||
(length 3.81)
|
||||
(name "STATUS" (effects (font (size 1.27 1.27))))
|
||||
(number "15" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 17.78 180)
|
||||
(length 3.81)
|
||||
(name "T1OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "5" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 15.24 180)
|
||||
(length 3.81)
|
||||
(name "T2OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "6" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 12.7 180)
|
||||
(length 3.81)
|
||||
(name "T3OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "7" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 10.16 180)
|
||||
(length 3.81)
|
||||
(name "T4OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "10" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin output line
|
||||
(at 16.51 7.62 180)
|
||||
(length 3.81)
|
||||
(name "T5OUT" (effects (font (size 1.27 1.27))))
|
||||
(number "12" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 2.54 180)
|
||||
(length 3.81)
|
||||
(name "R1IN" (effects (font (size 1.27 1.27))))
|
||||
(number "8" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 0 180)
|
||||
(length 3.81)
|
||||
(name "R2IN" (effects (font (size 1.27 1.27))))
|
||||
(number "9" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin input line
|
||||
(at 16.51 -2.54 180)
|
||||
(length 3.81)
|
||||
(name "R3IN" (effects (font (size 1.27 1.27))))
|
||||
(number "11" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -7.62 180)
|
||||
(length 3.81)
|
||||
(name "C1+" (effects (font (size 1.27 1.27))))
|
||||
(number "28" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -10.16 180)
|
||||
(length 3.81)
|
||||
(name "C1-" (effects (font (size 1.27 1.27))))
|
||||
(number "25" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -12.7 180)
|
||||
(length 3.81)
|
||||
(name "C2+" (effects (font (size 1.27 1.27))))
|
||||
(number "1" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -15.24 180)
|
||||
(length 3.81)
|
||||
(name "C2-" (effects (font (size 1.27 1.27))))
|
||||
(number "3" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -17.78 180)
|
||||
(length 3.81)
|
||||
(name "V+" (effects (font (size 1.27 1.27))))
|
||||
(number "27" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin passive line
|
||||
(at 16.51 -20.32 180)
|
||||
(length 3.81)
|
||||
(name "V-" (effects (font (size 1.27 1.27))))
|
||||
(number "4" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin power_in line
|
||||
(at 0 24.13 270)
|
||||
(length 3.81)
|
||||
(name "VCC" (effects (font (size 1.27 1.27))))
|
||||
(number "26" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
(pin power_in line
|
||||
(at 0 -24.13 90)
|
||||
(length 3.81)
|
||||
(name "GND" (effects (font (size 1.27 1.27))))
|
||||
(number "2" (effects (font (size 1.27 1.27))))
|
||||
)
|
||||
)
|
||||
(embedded_fonts no)
|
||||
)
|
||||
)
|
||||
File diff suppressed because it is too large.
Load diff
|
After Width: | Height: | Size: 221 KiB |
@@ -0,0 +1,87 @@
|
||||
"""Minimal reader/writer for KiCad's s-expression files.
|
||||
|
||||
A node is a Python list whose first item is its keyword. Atoms are Sym
|
||||
(bare words and numbers) or str (quoted strings), so quoting survives a
|
||||
round trip.
|
||||
"""
|
||||
import re
|
||||
|
||||
|
||||
class Sym(str):
|
||||
"""A bare (unquoted) atom."""
|
||||
|
||||
|
||||
_TOKEN = re.compile(r'\s*(?:(\()|(\))|"((?:[^"\\]|\\.)*)"|([^\s()"]+))', re.S)
|
||||
|
||||
|
||||
def parse(text):
|
||||
"""Parse one top-level node. Lines starting with ;; are comments."""
|
||||
text = "\n".join(l for l in text.split("\n") if not l.lstrip().startswith(";;"))
|
||||
stack, out, pos = [], None, 0
|
||||
while True:
|
||||
m = _TOKEN.match(text, pos)
|
||||
if not m or m.end() == pos:
|
||||
if text[pos:].strip():
|
||||
raise ValueError(f"cannot parse at {pos}: {text[pos:pos + 40]!r}")
|
||||
break
|
||||
pos = m.end()
|
||||
lp, rp, s, a = m.groups()
|
||||
if lp:
|
||||
stack.append([])
|
||||
elif rp:
|
||||
node = stack.pop()
|
||||
if stack:
|
||||
stack[-1].append(node)
|
||||
else:
|
||||
out = node
|
||||
elif s is not None:
|
||||
stack[-1].append(re.sub(r'\\(.)', r'\1', s))
|
||||
else:
|
||||
stack[-1].append(Sym(a))
|
||||
if stack:
|
||||
raise ValueError("unbalanced parentheses")
|
||||
return out
|
||||
|
||||
|
||||
def q(s):
|
||||
return '"' + str(s).replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n") + '"'
|
||||
|
||||
|
||||
def atom(x):
|
||||
if isinstance(x, Sym):
|
||||
return str(x)
|
||||
if isinstance(x, bool):
|
||||
return "yes" if x else "no"
|
||||
if isinstance(x, (int, float)):
|
||||
return num(x)
|
||||
return q(x)
|
||||
|
||||
|
||||
def num(v):
|
||||
s = f"{v:.4f}".rstrip("0").rstrip(".")
|
||||
return "0" if s in ("-0", "") else s
|
||||
|
||||
|
||||
def dump(node, indent=0):
|
||||
"""KiCad-style layout: short nodes on one line, others one child per line."""
|
||||
if not isinstance(node, list):
|
||||
return atom(node)
|
||||
head = [atom(x) for x in node if not isinstance(x, list)]
|
||||
kids = [x for x in node if isinstance(x, list)]
|
||||
line = "(" + " ".join(head)
|
||||
if not kids:
|
||||
return line + ")"
|
||||
flat = line + " " + " ".join(dump(k, 0) for k in kids) + ")"
|
||||
if len(flat) + indent <= 100 and "\n" not in flat:
|
||||
return flat
|
||||
pad = "\t" * (indent + 1)
|
||||
return line + "\n" + "\n".join(pad + dump(k, indent + 1) for k in kids) + "\n" + "\t" * indent + ")"
|
||||
|
||||
|
||||
def find(node, key):
|
||||
return [x for x in node if isinstance(x, list) and x and x[0] == key]
|
||||
|
||||
|
||||
def first(node, key, default=None):
|
||||
r = find(node, key)
|
||||
return r[0] if r else default
|
||||
@@ -0,0 +1,4 @@
|
||||
(sym_lib_table
|
||||
(version 7)
|
||||
(lib (name "pico-serial") (type "KiCad") (uri "${KIPRJMOD}/pico-serial.kicad_sym") (options "") (descr "SP3238E, MAX3243E"))
|
||||
)
|
||||
Reference in new issue
Block a user