MustafaMulla29/usb-pd-motherboard

4-layer USB-C PD hub motherboard with 20 V USB-C input, Linux T113-S3 computer, CH338F USB hub, four individually controlled 5–20 V PD outputs, USB data/camera ports, regulated rails, and hardware watchdog/E-stop safety interlock.

Version
1.0.24
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone MustafaMulla29/usb-pd-motherboard  # download the package files into ./usb-pd-motherboard
tsci add MustafaMulla29/usb-pd-motherboard    # add it to your project as @tsci/MustafaMulla29.usb-pd-motherboard

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

tools/router/freespace.py

"""Find free placement spots: python3 -I tools/router/freespace.py <circuit.json> W H tx ty [ignore_name,...] [n]
Occupancy = pads, plated holes, holes, courtyards of every component (0.3 mm margin). Prints the n nearest free centres."""
import json,sys,math
cj=json.load(open(sys.argv[1])); W,H,tx,ty=map(float,sys.argv[2:6])
ign=set(sys.argv[6].split(',')) if len(sys.argv)>6 else set(); n=int(sys.argv[7]) if len(sys.argv)>7 else 6
src={e['source_component_id']:e['name'] for e in cj if e['type']=='source_component'}
pc={e['pcb_component_id']:src.get(e.get('source_component_id')) for e in cj if e['type']=='pcb_component'}
P=0.1; X0,Y0=-45,-49; NX,NY=901,981; M=0.3
occ=bytearray(NX*NY)
def fill(x0,y0,x1,y1):
    for j in range(max(0,int((y0-M-Y0)/P)),min(NY-1,int((y1+M-Y0)/P)+1)+1):
        a=max(0,int((x0-M-X0)/P)); b=min(NX-1,int((x1+M-X0)/P)+1)
        if b>=a: occ[j*NX+a:j*NX+b+1]=b'\1'*(b-a+1)
for e in cj:
    if pc.get(e.get('pcb_component_id')) in ign: continue
    t=e['type']
    if t=='pcb_smtpad' and e.get('shape')!='polygon':
        w=e.get('width') or e.get('radius',0)*2; h=e.get('height') or e.get('radius',0)*2
        if e.get('ccw_rotation') in (90,270): w,h=h,w
        fill(e['x']-w/2,e['y']-h/2,e['x']+w/2,e['y']+h/2)
    elif t=='pcb_smtpad':
        xs=[p['x'] for p in e['points']]; ys=[p['y'] for p in e['points']]; fill(min(xs),min(ys),max(xs),max(ys))
    elif t in('pcb_plated_hole','pcb_hole'):
        d=max(e.get('outer_diameter',0) or 0,e.get('hole_diameter',0) or 0,e.get('outer_width',0) or 0,e.get('outer_height',0) or 0,e.get('hole_width',0) or 0,e.get('hole_height',0) or 0)
        fill(e['x']-d/2,e['y']-d/2,e['x']+d/2,e['y']+d/2)
    elif t=='pcb_courtyard_rect':
        c=e['center']; fill(c['x']-e['width']/2,c['y']-e['height']/2,c['x']+e['width']/2,c['y']+e['height']/2)
    elif t=='pcb_courtyard_outline':
        xs=[p['x'] for p in e['outline']]; ys=[p['y'] for p in e['outline']]; fill(min(xs),min(ys),max(xs),max(ys))
# integral image
S=[[0]*(NX+1) for _ in range(NY+1)]
for j in range(NY):
    r=0; Sj=S[j+1]; Sp=S[j]; base=j*NX
    for i in range(NX):
        r+=occ[base+i]; Sj[i+1]=Sp[i+1]+r
res=[]
wi,hi=int(W/P/2+.999),int(H/P/2+.999)
for j in range(hi+3,NY-hi-3):
    for i in range(wi+3,NX-wi-3):
        if S[j+hi+1][i+wi+1]-S[j-hi][i+wi+1]-S[j+hi+1][i-wi]+S[j-hi][i-wi]==0:
            x,y=X0+i*P,Y0+j*P; res.append((math.hypot(x-tx,y-ty),round(x,1),round(y,1)))
res.sort(); out=[]
for d,x,y in res:
    if all(math.hypot(x-a,y-b)>1.0 for _,a,b in out): out.append((round(d,1),x,y))
    if len(out)>=n: break
print(out)