gokul/macro-six-usbc

A six-key macro keyboard PCB paired with a separate physical enclosure.

Version
0.1.16
License
unset
Stars
0

Use with the tscircuit CLI

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

tsci clone gokul/macro-six-usbc  # download the package files into ./macro-six-usbc
tsci add gokul/macro-six-usbc    # add it to your project as @tsci/gokul.macro-six-usbc

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.

outputs/release/simulation/power-simulation.ts

SchematicSchematic preview for outputs/release/simulation/power-simulation.ts
import createEngine from '@tscircuit/ngspice-spice-engine'
import { strict as assert } from 'node:assert'
const board=await Bun.file(`${import.meta.dir}/candidate.circuit.json`).json()
const component=(name:string)=>board.find(e=>e.type==='source_component'&&e.name===name)
const netFor=(name:string,pin:number)=>{
 const c=component(name)
 const p=board.find(e=>e.type==='source_port'&&e.source_component_id===c.source_component_id&&e.pin_number===pin)
 const t=board.find(e=>e.type==='source_trace'&&e.connected_source_port_ids.includes(p.source_port_id)&&e.connected_source_net_ids.length)
 const n=board.find(e=>e.type==='source_net'&&e.source_net_id===t.connected_source_net_ids[0]).name
 return n==='GND'?'0':n
}
const engine=await createEngine()
const results=[]
for(const state of ['off','rgb-off','normal','full-white'] as const) for(const supply of [4.4,5,5.25]) {
 const mainOn=state!=='off', rgbOn=state==='normal'||state==='full-white'
 // Assumed cable+connector resistance, fuse resistance, and device loads; not measurements.
 const lines=['* Macro Six power-path approximation; NOT a manufacturer MOSFET model',`VUSB VBUS 0 ${supply}`,`RFUSE ${netFor('F1',1)} ${netFor('F1',2)} 1.5`,'.model PSW SW(Ron=0.085 Roff=1e9 Vt=1.3 Vh=0)', '.model BODY D(Is=1e-12 N=1.5)', '.model GREEN D(Is=1e-20 N=2 Rs=10)']
 for(const name of ['R_MAIN_PULL','R_RGB_PULL','R_PWR'])lines.push(`${name} ${netFor(name,1)} ${netFor(name,2)} ${component(name).resistance}`)
 for(const name of ['C_BULK','C_V1','C_V2','C_V3','C_V4','C_V5','C_LED1','C_LED2','C_LED3','C_LED4','C_LED5','C_LED6'])lines.push(`${name} ${netFor(name,1)} ${netFor(name,2)} ${component(name).capacitance}`)
 for(const name of ['Q_MAIN','Q_RGB']){
  const c=component(name)
  for(const [pin,role] of [[1,'gate'],[2,'source'],[3,'drain']] as const)assert(board.find(e=>e.type==='source_port'&&e.source_component_id===c.source_component_id&&e.pin_number===pin).port_hints.includes(role))
  const g=netFor(name,1),s=netFor(name,2),d=netFor(name,3)
  lines.push(`S${name} ${s} ${d} ${s} ${g} PSW`,`D${name} ${d} ${s} BODY`)
 }
 lines.push(`RMAIN_CONTROL MAIN_GATE 0 ${mainOn?0.1:1e12}`,`RRGB_CONTROL RGB_GATE ${rgbOn?'0':'VCC'} 0.1`,'DPOWER PWR_ANODE 0 GREEN','BMCU VCC 0 I=0.02*min(max(V(VCC)/3.5,0),1)',`BRGB LED_5V 0 I=${state==='full-white'?0.216:0.03}*min(max(V(LED_5V)/3.5,0),1)`,'.op','.end')
 const netlist=lines.join('\n')
 await Bun.write(`${import.meta.dir}/power-${state}-${supply}.cir`,netlist)
 const {simulationResultCircuitJson:output}=await engine.simulate(netlist)
 const voltage=(name:string)=>output.find(e=>e.type==='simulation_dc_operating_point_voltage'&&e.name?.toLowerCase()===name.toLowerCase())?.voltage
 const row={state,supply,vcc:voltage('VCC'),led:voltage('LED_5V'),gate:voltage('MAIN_GATE')}
 assert.equal(typeof row.vcc,'number'); assert.equal(typeof row.led,'number')
 if(!mainOn){assert(row.vcc<0.001);assert(row.led<0.001)}
 else {assert(row.vcc>3.8);if(!rgbOn)assert(row.led<0.001);else assert(row.led>3.8)}
 results.push(row)
}
await Bun.write(`${import.meta.dir}/power-results.json`,JSON.stringify(results,null,2))
console.log(JSON.stringify(results,null,2))
console.log('PASS: 12 bounded DC power-path scenarios; not full-board or transient validation')