seveibar/am3352-dev-board

A 324-ball TI AM3352 ARM processor with DDR3, LCD, USB, Ethernet, storage, serial, analog, clock, reset, power, and JTAG interfaces, paired with configurable JST-GH board connectors and constrained PCB routing.

Version
1.0.2
License
unset
Stars
0

scripts/finish-pmic.py

import json,runpy
from pathlib import Path
from shapely.geometry import Point,LineString
x=runpy.run_path('scripts/audit-copper.py');d=json.loads(Path('design/routed-copper.json').read_text());c=x['c'];sid={n['name']:n['source_net_id'] for n in c if n['type']=='source_net'}
items=[('SW2',[(-20.025,-1.2),(-19.6,-1.2),(-18.4125,-.0125),(-18.4125,.5)],False),('PWRONRSTn',[(-21.2,-.025),(-21.2,.8)],True)];removed=set()
for name,pts,via in items:
 net=x['find'](sid[name]);line=LineString(pts);v=Point(pts[-1])
 for g,m in zip(x['shapes'],x['meta']):
  if m[1]==net or m[2].startswith('pcb_copper_pour'):continue
  if (m[0]=='top' and g.distance(line)<.149999) or (via and g.distance(v)<.249999):
   assert not m[3],('PMIC path hits a component pad',name,m)
   removed.add(m[2].removesuffix('_via'))
for key,rs in d['nets'].items():d['nets'][key]=[r for i,r in enumerate(rs) if f'fr_{key}_{i}' not in removed]
for name,pts,via in items:
 key=sid[name];d['nets'].setdefault(key,[]).append([{'route_type':'wire','x':a,'y':b,'width':.1,'layer':'top'} for a,b in pts]);d['sourceTraceIds'][key]=next(t['source_trace_id'] for t in c if t['type']=='source_trace' and key in t.get('connected_source_net_ids',[]))
 if via:
  a,b=pts[-1];d['nets'][key].append([{'route_type':'wire','x':a,'y':b,'width':.1,'layer':'top'},{'route_type':'via','x':a,'y':b,'from_layer':'top','to_layer':'bottom','via_diameter':.3,'via_hole_diameter':.15},{'route_type':'wire','x':a,'y':b,'width':.1,'layer':'bottom'}])
Path('design/routed-copper.json').write_text(json.dumps(d,separators=(',',':'))+'\n');print('Reserved PMIC switch and power-good escape; reroute',removed)