Devesh36/pocket-audio-player

A portable, rechargeable microSD audio player built around an RP2040, SPI flash, USB‑C charging/power management, LCD/button controls, PCM5102A I²S DAC, and TPA6132A headphone amplifier in a 3D‑printed enclosure.

Version
1.0.12
License
unset
Stars
0

scripts/check-display-power.ts

// Verify the exported source connectivity against manufacturer pinouts.
const c=await Bun.file('dist/index/circuit.json').json()
const components=c.filter((x:any)=>x.type==='source_component'),ports=c.filter((x:any)=>x.type==='source_port'),nets=c.filter((x:any)=>x.type==='source_net')
const results:any[]=[]
function expectNet(ref:string,pin:number,net:string){
 const comp=components.find((x:any)=>x.name===ref),p=ports.find((x:any)=>x.source_component_id===comp?.source_component_id&&x.pin_number===pin),n=nets.find((x:any)=>x.name===net)
 if(!p||!n||p.subcircuit_connectivity_map_key!==n.subcircuit_connectivity_map_key)throw new Error(`${ref}.${pin} must connect to ${net}`)
 results.push({ref,pin,net})
}
const lcd=['LCD_BL','LCD_RST','LCD_DC','LCD_CS','LCD_CLK','LCD_DIN','GND','V3V3','GND','GND']
lcd.forEach((net,i)=>expectNet('J_LCD',i+1,net))
for(const [pin,net] of [[30,'LCD_BL'],[31,'LCD_DC'],[32,'LCD_RST'],[37,'LCD_CS'],[38,'LCD_CLK'],[39,'LCD_DIN'],[40,'BAT_SENSE'],[6,'SD_MISO'],[7,'SD_CS'],[8,'SD_CLK'],[9,'SD_MOSI']] as const)expectNet('U1',pin,net)
expectNet('J_BAT',1,'GND');expectNet('J_BAT',2,'VBAT')
expectNet('U_CHG',2,'GND');expectNet('U_CHG',3,'VBAT');expectNet('U_CHG',4,'VBUS');expectNet('U_CHG',5,'CHG_PROG')
expectNet('J_USB',15,'VBUS');expectNet('J_USB',16,'VBUS')
expectNet('R_PROG',1,'CHG_PROG');expectNet('R_PROG',2,'GND')
if(components.find((x:any)=>x.name==='R_PROG')?.resistance!==10000)throw new Error('Charging current must retain R_PROG=10 kΩ')
const vbus=nets.find((x:any)=>x.name==='VBUS'),vbat=nets.find((x:any)=>x.name==='VBAT')
if(vbus.subcircuit_connectivity_map_key===vbat.subcircuit_connectivity_map_key)throw new Error('USB 5 V is shorted to battery')
const errors=c.filter((x:any)=>x.type.startsWith('pcb_')&&x.type.includes('error'))
if(errors.length)throw new Error(`${errors.length} PCB errors remain`)
await Bun.write('dist/index/display-power-check.json',JSON.stringify({checks:'passed',displayBus:'SPI1 GP26/27; microSD SPI0 GP4-7',battery:'JST-PH pin 1 GND, pin 2 VBAT; charged through MCP73831 from USB-C',chargeCurrentMaNominal:100,results},null,2))
console.log(`Verified ${results.length} display/battery/storage connections; VBUS and VBAT isolated; zero PCB errors`)