From 41f92f5f7464414afdb15d3eede0199e26c0cab7 Mon Sep 17 00:00:00 2001 From: Akarsh Simha Date: Fri, 7 Nov 2025 23:02:15 +0000 Subject: [PATCH 1/3] Fix setup.py --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 23dd359..dbc938c 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,8 @@ author='execuc', author_email='', license='MIT', - packages=['source/machine'], + packages=['machine'], + package_dir={'machine': 'source/machine'}, zip_safe=False, install_requires=["pyserial>=3.5", "hid>=1.0.4", "micropython-cpython-ustruct==0.0", "micropython-cpython-micropython==0.1.1"]) From 31a2b2c5df9b28ea211c2b916d3a6ad211d0b267 Mon Sep 17 00:00:00 2001 From: Akarsh Simha Date: Fri, 7 Nov 2025 23:02:41 +0000 Subject: [PATCH 2/3] Fix mismatched method name in spi read operation --- source/machine/spi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/machine/spi.py b/source/machine/spi.py index 82adb4c..b11b3c2 100644 --- a/source/machine/spi.py +++ b/source/machine/spi.py @@ -29,7 +29,7 @@ def deinit(self): def read(self, nbytes, write=0): buf = bytearray(nbytes) - self.readfrom_into(buf, write) + self._read_from_into(buf, write) return buf def readinto(self, buf, write=0): From 0ea4855f5b94c0e0428247f347545465b9978fb0 Mon Sep 17 00:00:00 2001 From: Akarsh Simha Date: Fri, 7 Nov 2025 23:03:11 +0000 Subject: [PATCH 3/3] Support SPI mode option --- firmware/source/interfaces/SpiMaster.cpp | 1 + source/machine/spi.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/source/interfaces/SpiMaster.cpp b/firmware/source/interfaces/SpiMaster.cpp index 13b885b..2a3cce1 100644 --- a/firmware/source/interfaces/SpiMaster.cpp +++ b/firmware/source/interfaces/SpiMaster.cpp @@ -74,6 +74,7 @@ CmdStatus SPIMaster::init(uint8_t const *cmd) { uint32_t baudrate = convertBytesToUInt32(&cmd[2]); spi_init(_spiInst, baudrate); + spi_set_format(_spiInst, 8, (mode & 0x02) ? SPI_CPOL_1 : SPI_CPOL_0, (mode & 0x01) ? SPI_CPHA_1 : SPI_CPHA_0, SPI_MSB_FIRST); gpio_set_function(_clkGP, GPIO_FUNC_SPI); gpio_set_function(_mosiGP, GPIO_FUNC_SPI); gpio_set_function(_misoGP, GPIO_FUNC_SPI); diff --git a/source/machine/spi.py b/source/machine/spi.py index b11b3c2..5f30e0d 100644 --- a/source/machine/spi.py +++ b/source/machine/spi.py @@ -11,9 +11,8 @@ def __init__(self, *, spi_index=0): def __del__(self): self.deinit() - def init(self, baudrate=1000000): + def init(self, baudrate=1000000, mode=0x00): report_id = report_const.SPI0_INIT if self.spi_index == 0 else report_const.SPI1_INIT - mode = 0x00 # to implement res = self._device.send_report(bytes([report_id, mode]) + baudrate.to_bytes(4, byteorder='little')) if res[1] != report_const.OK: raise RuntimeError("SPI init error.")