main
John Lauer
Preserve board29, component assets and scaffold-fit correction candidate with reviewed footage
c54169e
#!/usr/bin/env python3
"""Generate Adom IC symbols from reviewed package pin tables, preserving provenance."""
import json,subprocess,sys
from pathlib import Path
import sexp
P=Path(__file__).resolve().parents[1]; net=json.loads((P/'design/netlist.json').read_text())
mcu=sexp.pins(sexp.flatten('STM32G0B1KCTx',sexp.lib_symbols(P/'libraries/MCU_ST_STM32G0.kicad_sym'),'MCU_ST_STM32G0'))
tables={
'U1':[(n,name,'power_in' if name in ['VDD','VSS'] else 'bidirectional') for n,name,*_ in mcu],
'U2':[(1,'VDD','power_in'),(2,'VOUT','output'),(3,'NC','no_connect'),(4,'AGND','power_in'),(5,'SPI2C','input'),(6,'SCL','input'),(7,'A0','input'),(8,'SDA','bidirectional'),(9,'NC','no_connect'),(10,'VREFIO','bidirectional')],
'U3':[(1,'OUT','output'),(2,'V-','power_in'),(3,'IN+','input'),(4,'IN-','input'),(5,'V+','power_in')],
'U4':[(1,'A1','input'),(2,'A0','input'),(3,'ALERT','open_collector'),(4,'SDA','bidirectional'),(5,'SCL','input'),(6,'VS','power_in'),(7,'GND','power_in'),(8,'VBUS','input'),(9,'IN-','input'),(10,'IN+','input')],
'U5':[(1,'SW','open_collector'),(2,'GND','power_in'),(3,'FB','input'),(4,'EN','input'),(5,'VIN','power_in')],
'U6':[(1,'WDO','open_collector'),(2,'GND','power_in'),(3,'EN_N','input'),(4,'WDI','input'),(5,'VCC','power_in')],
'U7':[(1,'OUT_B','open_collector'),(2,'OUT_A','open_collector'),(3,'VCC','power_in'),(4,'IN-_A','input'),(5,'IN+_A','input'),(6,'IN-_B','input'),(7,'IN+_B','input'),(8,'IN-_D','input'),(9,'IN+_D','input'),(10,'IN-_C','input'),(11,'IN+_C','input'),(12,'GND','power_in'),(13,'OUT_C','open_collector'),(14,'OUT_D','open_collector')],
'U8':[(1,'CLK','input'),(2,'GND','power_in'),(3,'D','input'),(4,'Q','output'),(5,'VCC','power_in'),(6,'CLR_N','input')],
'U9':[(1,'IN','power_in'),(2,'GND','power_in'),(3,'EN','input'),(4,'NC','no_connect'),(5,'OUT','power_out')],
}
urls={'U1':'https://www.st.com/resource/en/datasheet/stm32g0b1kc.pdf','U2':'https://www.ti.com/lit/ds/symlink/dac80501.pdf','U3':'https://www.ti.com/lit/ds/symlink/opa189.pdf','U4':'https://www.ti.com/lit/ds/symlink/ina226.pdf','U5':'https://www.ti.com/lit/ds/symlink/tps61040.pdf','U6':'https://www.st.com/resource/en/datasheet/stwd100.pdf','U7':'https://www.ti.com/lit/ds/symlink/lm339b.pdf','U8':'https://www.ti.com/lit/ds/symlink/sn74lvc1g175.pdf','U9':'https://www.ti.com/lit/ds/symlink/tlv755p.pdf'}
for c in net['components']:
if c['ref'] not in tables:continue
ref=c['ref'];d=P/'kicad/symbol-work'/c['mpn'];d.mkdir(parents=True,exist_ok=True)
pins=[]
for n,name,typ in tables[ref]:
group='Supply' if typ.startswith('power') else ('Port A' if ref=='U1' and name.startswith('PA') else 'Signals')
pins.append({'number':str(n),'name':name,'type':typ,'group':group,'side':'right' if typ in ('output','open_collector','power_out','power_in') else 'left'})
obj={'symbolName':c['mpn'],'mpn':c['mpn'],'manufacturer':'STMicroelectronics' if ref in ('U1','U6') else 'Texas Instruments','referencePrefix':'U','package':c['fp'],'description':c['block']+'; custom load R0 engineering symbol','datasheetUrl':urls[ref],'pins':pins,'preferences':{'pinLayout':'left-right','chipNameCentered':False}}
(d/'symbol-input.json').write_text(json.dumps(obj,indent=2))
(d/'README.md').write_text('# '+c['mpn']+'\n\nPin table from [manufacturer datasheet]('+urls[ref]+'). Native KiCad library independently checked where available. Draft symbol, full review pending.\n\n| Pin | Name | Electrical type |\n|---|---|---|\n'+'\n'.join(f'| {n} | {name} | {t} |' for n,name,t in tables[ref])+'\n')
r=subprocess.run(['adom-symbol','create','--file',str(d/'symbol-input.json'),'--out',str(d)],capture_output=True,text=True)
(d/'create.log').write_text(r.stdout+r.stderr);print(ref,c['mpn'],r.returncode)