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/render-ddr.ts
import { convertCircuitJsonToPcbSvg } from 'circuit-to-svg'
import { Resvg } from '@resvg/resvg-js'
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
import { assertLayoutProfile, getAM3352Bounds, getAM3352Layers, getAM3352PowerPlanes, LAYOUT_PROFILES } from '../src/profiles'
const profile=process.argv[2]??'ddr_left'
assertLayoutProfile(profile)
const settings=LAYOUT_PROFILES[profile]
const json=JSON.parse(readFileSync(`src/generated/${profile}.circuit.json`,'utf8'))
const layers=getAM3352Layers(profile)
const planes=getAM3352PowerPlanes(profile)
const bounds=getAM3352Bounds(profile)
const viewport={minX:bounds.minX-2,maxX:bounds.maxX+2,minY:bounds.minY-2,maxY:bounds.maxY+2}
const directory=`previews/${profile}`
mkdirSync(directory,{recursive:true})
const panelSize=720,marginTop=110,rowHeight=765
const height=marginTop+Math.ceil(layers.length/2)*rowHeight
const panels=layers.map((layer,i)=>{
const svg=convertCircuitJsonToPcbSvg(json.filter((e:any)=>!e.type.startsWith('pcb_fabrication_note')),{layer:layer as any,width:1400,height:1400,viewport,shouldDrawRatsNest:false})
writeFileSync(`${directory}/${layer}.svg`,svg)
writeFileSync(`${directory}/${layer}.png`,new Resvg(svg).render().asPng())
const x=20+(i%2)*760,y=marginTop+Math.floor(i/2)*rowHeight
const plane=planes.filter(p=>p.layer===layer).map(p=>p.netName).join(', ')
const label=`${layer.toUpperCase()}${plane?` · ${plane}`:' · signal routing'}`
return `<text x="${x}" y="${y}" font-family="sans-serif" font-size="22" fill="white">${label}</text>`+svg.replace(/<svg /,`<svg viewBox="0 0 1400 1400" x="${x}" y="${y+15}" `).replace(/width="1400"/,`width="${panelSize}"`).replace(/height="1400"/,`height="${panelSize}"`)
})
const combined=`<svg xmlns="http://www.w3.org/2000/svg" width="1520" height="${height}" viewBox="0 0 1520 ${height}"><rect width="1520" height="${height}" fill="#10151c"/><text x="20" y="38" font-family="sans-serif" font-size="28" fill="white">AM3352 · ${profile} · saved copper</text><text x="20" y="72" font-family="sans-serif" font-size="20" fill="#a8bacb">${settings.fanoutWidthMm} × ${settings.fanoutHeightMm} mm boundary · ${settings.layerCount} copper layers · through-hole vias · geometry preview</text>${panels.join('')}</svg>`
writeFileSync(`previews/${profile}.svg`,combined)
writeFileSync(`previews/${profile}.png`,new Resvg(combined).render().asPng())
console.log(`Rendered ${profile}: ${layers.length} copper-layer previews and contact sheet`)