0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/preview-cap-placement.ts
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {Resvg} from '@resvg/resvg-js'
import {decouplingCaps} from '../src/DecouplingNetwork'
mkdirSync('previews',{recursive:true})
const json=JSON.parse(readFileSync('dist/six-layer-placed.circuit.json','utf8'))
const scale=58
const xy=(x:number,y:number)=>[600+x*scale,650-y*scale]
const parts:string[]=[]
for(const pad of json.filter((e:any)=>e.type==='pcb_smtpad'&&e.layer==='top')){
const [x,y]=xy(pad.x,pad.y);parts.push(`<circle cx="${x}" cy="${y}" r="${.2*scale}" fill="#334155"/>`)
}
for(const t of json.filter((e:any)=>e.type==='pcb_trace')){
const points=t.route.filter((p:any)=>p.layer==='bottom').map((p:any)=>xy(p.x,p.y).join(',')).join(' ')
parts.push(`<polyline points="${points}" fill="none" stroke="#60a5fa" stroke-width="${.127*scale}" stroke-linejoin="round"/>`)
}
for(const pad of json.filter((e:any)=>e.type==='pcb_smtpad'&&e.layer==='bottom')){
const [x,y]=xy(pad.x,pad.y);parts.push(`<rect x="${x-pad.width*scale/2}" y="${y-pad.height*scale/2}" width="${pad.width*scale}" height="${pad.height*scale}" fill="#60a5fa"/>`)
}
for(const v of json.filter((e:any)=>e.type==='pcb_via')){
const [x,y]=xy(v.x,v.y);parts.push(`<circle cx="${x}" cy="${y}" r="${.2*scale}" fill="#f87171"/><circle cx="${x}" cy="${y}" r="${.1*scale}" fill="#0f172a"/>`)
}
for(const sc of json.filter((e:any)=>e.type==='source_component'&&/^C\d+$/.test(e.name))){
const pc=json.find((e:any)=>e.type==='pcb_component'&&e.source_component_id===sc.source_component_id)
const [x,y]=xy(pc.center.x,pc.center.y);parts.push(`<text x="${x}" y="${y-23}" text-anchor="middle" fill="#fff" font-size="15" paint-order="stroke" stroke="#0f172a" stroke-width="4">${sc.name}</text>`)
}
const svg=`<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="1220"><rect width="1200" height="1220" fill="#0f172a"/><g font-family="sans-serif"><text x="35" y="42" fill="white" font-size="27">AM3352 · ${decouplingCaps.length} bottom-side supply capacitors</text><text x="35" y="76" fill="#94a3b8" font-size="19">55 under the BGA · 27 within its 1 mm padding · six layers · through-hole vias</text><rect x="107" y="157" width="986" height="986" fill="none" stroke="#e2e8f0" stroke-width="2" stroke-dasharray="8 8"/><rect x="165" y="215" width="870" height="870" fill="none" stroke="#64748b" stroke-width="2"/>${parts.join('')}<text x="35" y="1190" fill="#94a3b8" font-size="18">Gray: BGA pads · Blue: bottom capacitor copper · Red: through vias · Dashed: 17 mm fanout boundary</text></g></svg>`
writeFileSync('previews/decoupling.svg',svg)
writeFileSync('previews/decoupling.png',new Resvg(svg).render().asPng())