MustafaMulla29/rp2040-bldc-motor-controller
Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.
- Version
- 2.0.40
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/rp2040-bldc-motor-controller # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controllerIn 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.
scripts/export-factory-review.mjs
/** Pack native fabrication outputs with the independently reviewed assembly CSVs.
* Does not change any Gerber copper, drill, mask, paste or silkscreen geometry.
*/
import {spawnSync} from 'node:child_process'
import {readFileSync,writeFileSync,readdirSync} from 'node:fs'
import {resolve,dirname} from 'node:path'
import {fileURLToPath} from 'node:url'
import {createHash} from 'node:crypto'
import {zipSync,unzipSync,strToU8} from 'fflate'
const root=resolve(dirname(fileURLToPath(import.meta.url)),'..')
function run(command,args){
const r=spawnSync(command,args,{cwd:root,encoding:'utf8',maxBuffer:12e6})
if(r.status!==0)throw Error((r.stdout??'')+(r.stderr??'')+String(r.error??''))
return(r.stdout??'')+(r.stderr??'')
}
console.log(run('bun',['scripts/prepare-assembly.mjs']))
const input=resolve(root,'dist/index/circuit.json'),native=resolve(root,'dist/assembly-review/native-export.zip')
const pcbHash=createHash('sha256').update(readFileSync(input)).digest('hex')
for(const [file,key] of [
['dist/pd-config.json','sha256'],['dist/rgb-status.json','sha256'],
['dist/current-budget-review.json','sha256'],['dist/pd-electrical-review.json','board_sha256'],
['assembly/dist/results/usb-routing.json','sha256'],['assembly/dist/results/pcb-validation.json','sha256'],
['dist/system/integration-check.json','pcbCircuitSha256'],
['dist/release-validation.json','pcbSha256'],
['manufacturing/parts-availability.json','pcbSha256'],
]){
const report=JSON.parse(readFileSync(resolve(root,file)))
if(report[key]!==pcbHash)throw Error('Stale factory-review evidence: '+file)
if(report.failures?.length)throw Error('Unresolved findings in '+file)
}
const release=JSON.parse(readFileSync(resolve(root,'dist/release-validation.json')))
const order=JSON.parse(readFileSync(resolve(root,'manufacturing/order-request.json')))
if(JSON.stringify(order)!==JSON.stringify(release.order))throw Error('Order scope changed since release review')
if(order.fabricatedBoards!==order.assembledBoards+order.bareBoards)throw Error('Board quantities do not balance')
for(const [file,hash] of Object.entries(release.designAndFirmwareSha256)){
if(createHash('sha256').update(readFileSync(resolve(root,file))).digest('hex')!==hash)throw Error('Source changed since release review: '+file)
}
if(createHash('sha256').update(readFileSync(resolve(root,'manufacturing/parts-availability.json'))).digest('hex')!==release.partsAvailabilitySha256)throw Error('Parts screen changed since release review')
const log=run(resolve(root,'node_modules/.bin/tsci'),['export',input,'-f','gerbers','-o',native])
writeFileSync(resolve(root,'dist/assembly-review/native-export.log'),log)
console.log(run('bun',['scripts/check-native-stencil.mjs']))
const entries=unzipSync(readFileSync(native)),fab={}
// The native CSVs contain fallback positions/angles; supply the reviewed files
// separately. This is file selection, not alteration of manufacturing geometry.
for(const[name,bytes]of Object.entries(entries))if(/\.(gbr|drl)$/i.test(name))fab[name]=bytes
for(const required of ['F_Cu.gbr','In1_Cu.gbr','In2_Cu.gbr','B_Cu.gbr','F_Paste.gbr','B_Paste.gbr','drill-L1-L4.drl','drill_npth.drl','Edge_Cuts.gbr'])if(!fab[required])throw Error('Missing native fabrication file '+required)
const pack={'board-gerbers.zip':zipSync(fab)}
writeFileSync(resolve(root,'dist/board-gerbers.zip'),pack['board-gerbers.zip'])
for(const name of ['bom.csv','cpl-reviewed.csv','assembly-scope.csv','orientation-review.json','native-stencil-review.json'])pack[name]=readFileSync(resolve(root,'dist/assembly-review',name))
for(const name of ['CURRENT-REVISION.md','assembly-instructions.md','motor-harness.md','stencil-u7.svg','stencil-u7.json','stackup.json','current-budget.json'])pack[name]=readFileSync(resolve(root,'manufacturing',name))
for(const name of ['order-request.json','factory-review-request.md','prototype-programming.md','parts-availability.json','parts-availability.csv','replacement-qualification.json','stencil-process-screen.json','q7-replacement-review.json'])pack[name]=readFileSync(resolve(root,'manufacturing',name))
pack['release-validation.json']=readFileSync(resolve(root,'dist/release-validation.json'))
pack['pcb-validation.json']=readFileSync(resolve(root,'assembly/dist/results/pcb-validation.json'))
for(const name of ['knob-firmware.md','validation.md'])pack[name]=readFileSync(resolve(root,'docs',name))
for(const name of readdirSync(resolve(root,'firmware'))){
if(name.endsWith('.py')&&!name.startsWith('test_'))pack['firmware-reference/'+name]=readFileSync(resolve(root,'firmware',name))
}
pack['firmware-reference/README.txt']=strToU8('REFERENCE SOURCE ONLY — DO NOT FACTORY FLASH\nDeliver unprogrammed prototypes. Read prototype-programming.md in the package root. motor_setup.PROFILE remains None; no commissioned motor settings or calibration are supplied.\n')
pack['offboard-parts.csv']=readFileSync(resolve(root,'docs/offboard-parts.csv'))
pack['connectors-and-firmware.md']=readFileSync(resolve(root,'docs/connectors-and-firmware.md'))
pack['order-readiness.md']=readFileSync(resolve(root,'docs/order-readiness.md'))
pack['pd-only-design.md']=readFileSync(resolve(root,'docs/pd-only-design.md'))
pack['rgb-status-check.json']=readFileSync(resolve(root,'dist/rgb-status.json'))
pack['current-budget-review.json']=readFileSync(resolve(root,'dist/current-budget-review.json'))
pack['usb-routing.json']=readFileSync(resolve(root,'assembly/dist/results/usb-routing.json'))
pack['bringup-acceptance.md']=readFileSync(resolve(root,'docs/bringup-acceptance.md'))
pack['pd-config-check.json']=readFileSync(resolve(root,'dist/pd-config.json'))
pack['pd-electrical-review.json']=readFileSync(resolve(root,'dist/pd-electrical-review.json'))
pack['integration-check.json']=readFileSync(resolve(root,'dist/system/integration-check.json'))
pack['README-FIRST.txt']=strToU8('FACTORY ENGINEERING REVIEW PACKAGE — NOT PRODUCTION APPROVED\nOrder scope: '+order.fabricatedBoards+' PCBs total; '+order.assembledBoards+' assembled and '+order.bareBoards+' bare. Deliver unprogrammed.\nRead factory-review-request.md, parts-availability.csv, assembly-instructions.md and order-readiness.md before quoting or fabrication.\nAll Gerber/drill geometry is the unmodified native tscircuit export. U7 exports six rectangular paste windows natively; review the requested R0.05 corner rounding and stencil process in the accompanying instruction.\nUse cpl-reviewed.csv for assembly; all BOM components are included. Confirm factory-library alignment in the placement preview.\nFactory approval is still required for the stencil, actual USB impedance geometry, stock and top-side placement and through-hole soldering.\nCircuit SHA-256: '+pcbHash+'\n')
const hashes=Object.fromEntries(Object.entries(pack).map(([k,v])=>[k,createHash('sha256').update(v).digest('hex')]))
pack['manifest.json']=strToU8(JSON.stringify({status:'FACTORY_REVIEW_REQUIRED',createdAt:new Date().toISOString(),pcbSha256:pcbHash,order,files:hashes},null,2)+'\n')
const target=resolve(root,'dist/factory-review.zip');writeFileSync(target,zipSync(pack))
console.log('Factory review package:',target)