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.
firmware/test_oled_bringup.py
"""Run the real OLED entrypoint/driver with simulated pins and power loss."""
import contextlib
import io
import types
import unittest
from unittest.mock import patch
from oled_bringup import run
from test_oled_ssd1309 import Bus
def raw_voltage(mv): return round(mv * 65535 * 15 / (3300 * 235))
class BringupTests(unittest.TestCase):
def exercise(self, failure):
writes, pins, texts, delays = [], {}, [], []
checks = 0
interrupted = False
class Pin:
IN, OUT = 0, 1
def __init__(self, number, mode=None, value=0):
self.number = number
if mode is not None: pins[number] = value
def value(self): return pins.get(self.number, 0)
def init(self, **kwargs): pass
class UiBus(Bus):
def writeto(self, address, data):
super().writeto(address, data)
writes.append((address, bytes(data)))
if failure == "oled_nack" and checks >= 4 and data == b'\x00\xae':
raise OSError("OLED NACK during shutdown")
class PdBus:
def readfrom_mem(self, address, register, length):
if register == 0x91:
rdo = (2 << 28) | (300 << 10) | 300
if checks >= 4 and failure in ("pd_loss", "oled_nack"):
rdo = 0
return rdo.to_bytes(4, "little")
return b'\x18'
def verify(*args, **kwargs):
nonlocal checks
checks += 1
if checks >= 4 and failure == "pd_bus":
raise OSError("PD bus failure")
def sleep_ms(ms):
nonlocal interrupted
delays.append(ms)
if failure == "interrupt" and ms == 100 and not interrupted:
interrupted = True
raise KeyboardInterrupt()
if failure == "startup_interrupt" and ms == 150 and not interrupted:
interrupted = True
raise KeyboardInterrupt()
class FrameBuffer:
def __init__(self, *args): pass
def text(self, text, *args): texts.append(text)
def rect(self, *args): pass
machine = types.SimpleNamespace(Pin=Pin,
ADC=lambda pin:types.SimpleNamespace(read_u16=lambda:raw_voltage(9000)),
I2C=lambda number, **kwargs:UiBus() if number == 0 else PdBus())
framebuf = types.SimpleNamespace(FrameBuffer=FrameBuffer, MONO_VLSB=0)
output = io.StringIO()
expected = KeyboardInterrupt if "interrupt" in failure else OSError
with patch.dict("sys.modules", {"machine":machine, "framebuf":framebuf,
"time":types.SimpleNamespace(sleep_ms=sleep_ms)}), \
patch("oled_bringup.verify_runtime", side_effect=verify), \
contextlib.redirect_stdout(output):
with self.assertRaises(expected) as raised:
run()
self.assertIn((0x70, b'\x01\xfe'), writes) # reached real boost enable
self.assertEqual(writes[-2:], [(0x3c, b'\x00\xae'), (0x70, b'\x01\xff')])
self.assertEqual((pins[2], pins[3]), (0, 0))
self.assertNotIn((0x3c, b'\x00\xae\x8d\x10'), writes)
self.assertEqual(delays[-1], 700)
if failure != "startup_interrupt":
self.assertIn('1.54 OLED TEST', texts)
self.assertIn((0x3c, b'\x00\xaf'), writes)
if failure == "oled_nack":
self.assertIn("verified 3 A", str(raised.exception)) # original cause retained
self.assertIn("OLED shutdown failed", output.getvalue())
def test_pd_contract_lost_after_initialization(self): self.exercise("pd_loss")
def test_pd_bus_error_after_initialization(self): self.exercise("pd_bus")
def test_ctrl_c_while_running(self): self.exercise("interrupt")
def test_ctrl_c_after_boost_enable_before_constructor_returns(self):
self.exercise("startup_interrupt")
def test_oled_nack_during_shutdown_still_disables_boost(self):
self.exercise("oled_nack")
if __name__ == '__main__': unittest.main()