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-controller

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.

firmware/test_diagnostic_lockout.py

"""Execute the real diagnostic entrypoint with a simulated bus/GPIO interface."""
import contextlib,io,runpy,types,unittest
from pathlib import Path
from unittest.mock import patch
from test_pd_profile import Device,Clock,FACTORY
from pd_profile import nvm_9v_image
from pd_nvm import NVM

class DiagnosticLockoutTests(unittest.TestCase):
    def exercise(self, corrupt_runtime=False, old_nvm=False):
        bus=Device();bus.image[:]=nvm_9v_image(FACTORY)
        if old_nvm:bus.image[26]|=1
        bus.reload();bus.regs[0x91:0x95]=((2<<28)|(200<<10)|200).to_bytes(4,'little');bus.regs[0x29]=0x18
        if corrupt_runtime:bus.regs[0x88]|=4  # obsolete USB communications flag
        writes=[]
        class Pin:
            OUT=1;IN=0
            def __init__(self,number,mode=None,value=None):
                self.number=number;self.level=0
                if value is not None:self.value(value)
            def value(self,value=None):
                if value is None:return self.level
                self.level=value;writes.append((self.number,value))
            def off(self):self.value(0)
            def on(self):self.value(1)
        class ADC:
            def __init__(self,number):self.number=number
            def read_u16(self):return round(9000*65535*15/(3300*235)) if self.number==26 else 0
        class TestClock(Clock):
            def sleep_ms(self,delay):
                self.now+=delay
                if self.now>=300:raise KeyboardInterrupt()
        clock=TestClock()
        machine=types.SimpleNamespace(Pin=Pin,ADC=ADC,I2C=lambda *a,**k:bus,WDT=lambda **k:types.SimpleNamespace(feed=lambda:None))
        select=types.SimpleNamespace(POLLIN=1,poll=lambda:types.SimpleNamespace(register=lambda *a:None,poll=lambda *a:[]))
        stdout=io.StringIO()
        with patch.dict('sys.modules',{'machine':machine,'time':clock,'select':select}),patch('pd_nvm.NVM',lambda b:NVM(b,clock=clock)),contextlib.redirect_stdout(stdout):
            with self.assertRaises((KeyboardInterrupt,OSError)):
                runpy.run_path(str(Path(__file__).with_name('power_manager.py')),run_name='__main__')
        self.assertTrue(any(pin==2 for pin,_ in writes));self.assertTrue(any(pin==3 for pin,_ in writes))
        self.assertTrue(all(value==0 for pin,value in writes if pin in (2,3)),writes)
        return stdout.getvalue()
    def test_valid_pd_never_enables_motor(self):self.exercise()
    def test_runtime_corruption_keeps_motor_off(self):
        self.assertIn('USB data',self.exercise(corrupt_runtime=True))
    def test_old_nvm_keeps_motor_off(self):self.exercise(old_nvm=True)

if __name__=='__main__':unittest.main()