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_mct8329.py
import unittest
from mct8329 import Mct8329, ProfileCheck, CONFIG_REGISTERS
class Bus:
def __init__(self, nack=None, read_busy=0):
self.events = []
self.nack, self.read_busy = nack, read_busy
self.data = iter(b"\x78\x56\x34\x12")
def start(self): self.events.append(("start",))
def stop(self): self.events.append(("stop",))
def write(self, data):
self.events.append(("write", bytes(data)))
if data == b"\xc1" and self.read_busy:
self.read_busy -= 1
return 0
return 0 if data == self.nack else 1
def readinto(self, buf, nack):
self.events.append(("read", nack))
buf[0] = next(self.data)
def sleep_us(self, delay): self.events.append(("delay", delay))
class MctTests(unittest.TestCase):
def test_ti_read_frame_byte_order_ack_and_interbyte_delay(self):
bus = Bus()
value = Mct8329(bus, bus).read_register(0xA6)
self.assertEqual(value, 0x12345678)
self.assertEqual([e[1] for e in bus.events if e[0] == "write"],
[b"\xc0", b"\x90", b"\x00", b"\xa6", b"\xc1"])
self.assertEqual([e[1] for e in bus.events if e[0] == "read"],
[False, False, False, True])
for i, event in enumerate(bus.events):
if event[0] in ("write", "read"):
self.assertEqual(bus.events[i+1], ("delay", 100))
self.assertEqual(bus.events[-1], ("stop",))
def test_busy_read_retries_address_without_resending_control(self):
bus = Bus(read_busy=2)
self.assertEqual(Mct8329(bus, bus).read_register(0xA6), 0x12345678)
self.assertEqual(bus.events.count(("write", b"\xc1")), 3)
self.assertEqual(bus.events.count(("write", b"\xa6")), 1)
def test_nacks_are_bounded_and_bus_is_released(self):
for bus in (Bus(nack=b"\xc0"), Bus(nack=b"\xa6"), Bus(read_busy=20)):
with self.assertRaises(OSError): Mct8329(bus, bus).read_register(0xA6)
self.assertEqual(bus.events[-1], ("stop",))
self.assertLessEqual(bus.events.count(("write", b"\xc1")), 3)
def test_read_only_allowlist_excludes_eeprom_commands(self):
bus = Bus()
for reg in (0xE6, 0xA7, -1, 0x10080):
with self.assertRaises(ValueError): Mct8329(bus, bus).read_register(reg)
self.assertEqual(bus.events, [])
def test_full_profile_and_rolling_verification_detect_drift(self):
regs = {reg: reg for reg in CONFIG_REGISTERS}
class Reader:
def read_register(self, reg): return regs[reg]
check = ProfileCheck(Reader(), dict(regs))
check.verify_all()
regs[0xAE] ^= 1
for _ in range(23): check.verify_next()
with self.assertRaises(OSError): check.verify_next()
if __name__ == "__main__": unittest.main()