From 639fed2ae0bb0f2d7a234f2c39a97660b90bada1 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 7 Nov 2023 13:35:22 -0800 Subject: [PATCH 01/55] Add slave_mode parameter to the SPI bus constructor --- ports/atmel-samd/common-hal/busio/SPI.c | 5 ++++- ports/broadcom/common-hal/busio/SPI.c | 5 ++++- ports/cxd56/common-hal/busio/SPI.c | 5 ++++- ports/espressif/common-hal/busio/SPI.c | 5 ++++- ports/mimxrt10xx/common-hal/busio/SPI.c | 5 ++++- ports/nrf/common-hal/busio/SPI.c | 5 ++++- ports/raspberrypi/common-hal/busio/SPI.c | 5 ++++- ports/silabs/common-hal/busio/SPI.c | 5 ++++- ports/stm/common-hal/busio/SPI.c | 5 ++++- shared-bindings/busio/SPI.c | 8 ++++++-- shared-bindings/busio/SPI.h | 2 +- 11 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 5b7a4948164e1..f768056addffa 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -44,7 +44,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { Sercom *sercom = NULL; uint8_t sercom_index; uint32_t clock_pinmux = 0; @@ -60,6 +60,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } // Ensure the object starts in its deinit state. self->clock_pin = NO_PIN; diff --git a/ports/broadcom/common-hal/busio/SPI.c b/ports/broadcom/common-hal/busio/SPI.c index 5f21f09241b27..187c991569d69 100644 --- a/ports/broadcom/common-hal/busio/SPI.c +++ b/ports/broadcom/common-hal/busio/SPI.c @@ -77,7 +77,7 @@ void reset_spi(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { size_t instance_index = NUM_SPI; BP_Function_Enum clock_alt = 0; BP_Function_Enum mosi_alt = 0; @@ -86,6 +86,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } // BCM_VERSION != 2711 have 3 SPI but as listed in peripherals/gen/pins.c two are on // index 0, once one index 0 SPI is found the other will throw an invalid_pins error. diff --git a/ports/cxd56/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c index 115cee3a319c7..7c5771323eabc 100644 --- a/ports/cxd56/common-hal/busio/SPI.c +++ b/ports/cxd56/common-hal/busio/SPI.c @@ -36,12 +36,15 @@ #include "shared-bindings/microcontroller/Pin.h" void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, - const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { int port = -1; if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } if (clock->number == PIN_SPI4_SCK && (mosi == NULL || mosi->number == PIN_SPI4_MOSI) && diff --git a/ports/espressif/common-hal/busio/SPI.c b/ports/espressif/common-hal/busio/SPI.c index b79b908ef91e6..b909245f095f7 100644 --- a/ports/espressif/common-hal/busio/SPI.c +++ b/ports/espressif/common-hal/busio/SPI.c @@ -77,7 +77,7 @@ static void set_spi_config(busio_spi_obj_t *self, void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { const spi_bus_config_t bus_config = { .mosi_io_num = mosi != NULL ? mosi->number : -1, @@ -90,6 +90,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } for (spi_host_device_t host_id = SPI2_HOST; host_id < SOC_SPI_PERIPH_NUM; host_id++) { if (spi_bus_is_free(host_id)) { diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index 5d61028950bb3..511ad9edc0dca 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -91,7 +91,7 @@ void spi_reset(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { const uint32_t sck_count = MP_ARRAY_SIZE(mcu_spi_sck_list); const uint32_t miso_count = MP_ARRAY_SIZE(mcu_spi_sdi_list); @@ -101,6 +101,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } for (uint i = 0; i < sck_count; i++) { if (mcu_spi_sck_list[i].pin != clock) { diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index fa4845b19baed..2783f757a130d 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -143,11 +143,14 @@ static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) return 0; } -void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { +void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } // Find a free instance, with most desirable (highest freq and not shared) allocated first. self->spim_peripheral = NULL; diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index 30958cfcdc444..d85b628c9b822 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -54,12 +54,15 @@ void reset_spi(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { size_t instance_index = NO_INSTANCE; if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } if (clock->number % 4 == 2) { instance_index = (clock->number / 8) % 2; diff --git a/ports/silabs/common-hal/busio/SPI.c b/ports/silabs/common-hal/busio/SPI.c index ff41b89054774..6fcdbf4097d7d 100644 --- a/ports/silabs/common-hal/busio/SPI.c +++ b/ports/silabs/common-hal/busio/SPI.c @@ -53,13 +53,16 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, - bool half_duplex) { + bool half_duplex, bool slave_mode) { Ecode_t sc = ECODE_OK; if (half_duplex) { mp_raise_NotImplementedError( MP_ERROR_TEXT("Half duplex SPI is not implemented")); } + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } if ((sck != NULL) && (mosi != NULL) && (miso != NULL)) { if (sck->function_list[FN_EUSART1_SCLK] == 1 diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index aef04c15ad79b..2e8ecff422966 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -167,7 +167,10 @@ STATIC int check_pins(busio_spi_obj_t *self, void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex) { + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + if (slave_mode) { + mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); + } int periph_index = check_pins(self, sck, mosi, miso); SPI_TypeDef *SPIx = mcu_spi_banks[periph_index - 1]; diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 45c9327a3f4ed..f52034d9be122 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -74,6 +74,7 @@ //| MOSI: Optional[microcontroller.Pin] = None, //| MISO: Optional[microcontroller.Pin] = None, //| half_duplex: bool = False, +//| slave_mode: bool = False //| ) -> None: //| """Construct an SPI object on the given pins. //| @@ -96,8 +97,10 @@ //| :param ~microcontroller.Pin MOSI: the Main Out Selected In pin. //| :param ~microcontroller.Pin MISO: the Main In Selected Out pin. //| :param bool half_duplex: True when MOSI is used for bidirectional data. False when SPI is full-duplex or simplex. +//| :param-bool slave_mode: True when the chip is operating as a slave. False when the chip is operating as a master. //| //| **Limitations:** ``half_duplex`` is available only on STM; other chips do not have the hardware support. +//| **Limitations:** ``slave_mode`` is available only on SAMD51; other chips do not have the firmware support. //| """ //| ... @@ -106,12 +109,13 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BUSIO_SPI busio_spi_obj_t *self = mp_obj_malloc(busio_spi_obj_t, &busio_spi_type); - enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_half_duplex }; + enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_half_duplex, ARG_slave_mode }; static const mp_arg_t allowed_args[] = { { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_MOSI, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_half_duplex, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_slave_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -124,7 +128,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz mp_raise_ValueError(MP_ERROR_TEXT("Must provide MISO or MOSI pin")); } - common_hal_busio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool); + common_hal_busio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool, args[ARG_slave_mode].u_bool); return MP_OBJ_FROM_PTR(self); #else raise_ValueError_invalid_pins(); diff --git a/shared-bindings/busio/SPI.h b/shared-bindings/busio/SPI.h index 3b8f831219e9d..108f0e3cc3a22 100644 --- a/shared-bindings/busio/SPI.h +++ b/shared-bindings/busio/SPI.h @@ -38,7 +38,7 @@ extern const mp_obj_type_t busio_spi_type; // Construct an underlying SPI object. extern void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex); + const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode); extern void common_hal_busio_spi_deinit(busio_spi_obj_t *self); extern bool common_hal_busio_spi_deinited(busio_spi_obj_t *self); From b4598025b2e5c7e7b960d407a650efc087cbc43e Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 7 Nov 2023 13:51:57 -0800 Subject: [PATCH 02/55] Update SPI construction usages --- locale/circuitpython.pot | 7 +++++++ ports/atmel-samd/boards/hallowing_m4_express/board.c | 2 +- ports/atmel-samd/boards/monster_m4sk/board.c | 2 +- ports/atmel-samd/boards/openbook_m4/board.c | 2 +- ports/atmel-samd/boards/pewpew_lcd/board.c | 2 +- ports/atmel-samd/boards/pewpew_m4/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pygamer/board.c | 2 +- ports/atmel-samd/boards/seeeduino_wio_terminal/board.c | 2 +- ports/atmel-samd/common-hal/busio/SPI.h | 1 + ports/espressif/boards/adafruit_funhouse/board.c | 2 +- .../espressif/boards/adafruit_magtag_2.9_grayscale/board.c | 2 +- ports/espressif/boards/espressif_esp32s3_box/board.c | 2 +- ports/espressif/boards/espressif_esp32s3_box_lite/board.c | 2 +- .../espressif/boards/espressif_esp32s3_usb_otg_n8/board.c | 2 +- ports/espressif/boards/hardkernel_odroid_go/board.c | 2 +- ports/espressif/boards/hiibot_iots2/board.c | 4 +++- ports/espressif/boards/lilygo_tembed_esp32s3/board.c | 2 +- ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c | 4 +++- .../boards/lilygo_ttgo_tdisplay_esp32_16m/board.c | 4 +++- ports/espressif/boards/lilygo_twatch_2020_v3/board.c | 3 ++- ports/espressif/boards/m5stack_atoms3/board.c | 2 +- ports/espressif/boards/m5stack_stick_c/board.c | 2 +- ports/espressif/boards/m5stack_stick_c_plus/board.c | 2 +- ports/espressif/boards/morpheans_morphesp-240/board.c | 4 +++- ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c | 4 +++- ports/nrf/boards/clue_nrf52840_express/board.c | 2 +- ports/nrf/boards/espruino_banglejs2/board.c | 2 +- ports/nrf/boards/hiibot_bluefi/board.c | 2 +- ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c | 2 +- ports/nrf/boards/ohs2020_badge/board.c | 2 +- ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c | 2 +- ports/raspberrypi/boards/hack_club_sprig/board.c | 2 +- ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c | 4 +++- ports/raspberrypi/boards/pajenicko_picopad/board.c | 2 +- ports/raspberrypi/boards/pimoroni_badger2040/board.c | 2 +- ports/raspberrypi/boards/pimoroni_picosystem/board.c | 2 +- ports/raspberrypi/boards/ugame22/board.c | 2 +- ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c | 3 ++- shared-bindings/busio/SPI.c | 2 +- shared-module/board/__init__.c | 2 +- supervisor/shared/external_flash/spi_flash.c | 2 +- supervisor/shared/status_leds.c | 1 + 43 files changed, 63 insertions(+), 40 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 6969ff220fe3c..0310a699f97f1 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1955,6 +1955,13 @@ msgstr "" msgid "Size not supported" msgstr "" +#: ports/atmel-samd/common-hal/busio/SPI.c ports/cxd56/common-hal/busio/SPI.c +#: ports/espressif/common-hal/busio/SPI.c +#: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/SPI.c +#: ports/raspberrypi/common-hal/busio/SPI.c ports/stm/common-hal/busio/SPI.c +msgid "Slave mode SPI is not implemented" +msgstr "" + #: shared-bindings/alarm/SleepMemory.c shared-bindings/memorymap/AddressRange.c #: shared-bindings/nvm/ByteArray.c msgid "Slice and value different lengths." diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index 82d8cea619b6a..3896bc415d694 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index 34948b6a34b5a..3dc9d0ed9d689 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index d6911c7a07c3a..435a626a15ff7 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -59,7 +59,7 @@ uint8_t refresh_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pewpew_lcd/board.c b/ports/atmel-samd/boards/pewpew_lcd/board.c index 643494017d41b..91f9a92d4abcf 100644 --- a/ports/atmel-samd/boards/pewpew_lcd/board.c +++ b/ports/atmel-samd/boards/pewpew_lcd/board.c @@ -48,7 +48,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index ba37a9ddcea89..ddb4429a65f2f 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -99,7 +99,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 8314f354a2967..d99ef24e4c2f8 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 746298f578fe6..e1ac504cd0ad2 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c index a4e563017a581..053551b99dfee 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c @@ -67,7 +67,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false); + common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 2fced6d642eea..7d7c39e66bb03 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -40,6 +40,7 @@ typedef struct { uint8_t clock_pin; uint8_t MOSI_pin; uint8_t MISO_pin; + bool slave_mode; } busio_spi_obj_t; #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/espressif/boards/adafruit_funhouse/board.c b/ports/espressif/boards/adafruit_funhouse/board.c index a19ceda837732..d21486775599d 100644 --- a/ports/espressif/boards/adafruit_funhouse/board.c +++ b/ports/espressif/boards/adafruit_funhouse/board.c @@ -52,7 +52,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index 841c241b31c38..e81d21a5584bd 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -116,7 +116,7 @@ const uint8_t refresh_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_box/board.c b/ports/espressif/boards/espressif_esp32s3_box/board.c index 3ab932c83ae02..4aa3c1de17a4b 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box/board.c @@ -45,7 +45,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c index fe9cc993e8030..efbbd74c53042 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c @@ -46,7 +46,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c index 3dd272b622adf..ec36b1cca3003 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c @@ -73,7 +73,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/hardkernel_odroid_go/board.c b/ports/espressif/boards/hardkernel_odroid_go/board.c index 141a891d57390..71ff8c20a5740 100644 --- a/ports/espressif/boards/hardkernel_odroid_go/board.c +++ b/ports/espressif/boards/hardkernel_odroid_go/board.c @@ -65,7 +65,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/hiibot_iots2/board.c b/ports/espressif/boards/hiibot_iots2/board.c index 8720aa1b5c052..39497f7c06049 100644 --- a/ports/espressif/boards/hiibot_iots2/board.c +++ b/ports/espressif/boards/hiibot_iots2/board.c @@ -73,7 +73,9 @@ static void display_init(void) { &pin_GPIO34, // CLK &pin_GPIO33, // MOSI NULL, // MISO not connected - false); // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master + ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c index 8039f618f0c28..62c1b9ed20d85 100644 --- a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c +++ b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c @@ -45,7 +45,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c index e2970b5bfca74..ca840ff737a28 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c @@ -73,7 +73,9 @@ static void display_init(void) { &pin_GPIO36, // CLK &pin_GPIO35, // MOSI NULL, // MISO not connected - false); // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master + ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c index 1821f7de49e71..d556701550bc0 100644 --- a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c +++ b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c @@ -53,7 +53,9 @@ static void display_init(void) { &pin_GPIO18, // CLK &pin_GPIO19, // MOSI NULL, // MISO not connected - false); // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master + ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c index 4952093652686..6fa7ad6fc67cb 100644 --- a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c +++ b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c @@ -56,7 +56,8 @@ static void display_init(void) { &pin_GPIO18, // CLK &pin_GPIO19, // MOSI NULL, // MISO not connected - false // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/m5stack_atoms3/board.c b/ports/espressif/boards/m5stack_atoms3/board.c index 5b7faf2bec408..0f23ed903f84e 100644 --- a/ports/espressif/boards/m5stack_atoms3/board.c +++ b/ports/espressif/boards/m5stack_atoms3/board.c @@ -54,7 +54,7 @@ void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; // busio_spi_obj_t *spi = common_hal_board_create_spi(0); busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/m5stack_stick_c/board.c b/ports/espressif/boards/m5stack_stick_c/board.c index 4d33b21c583b3..693b7eefe783b 100644 --- a/ports/espressif/boards/m5stack_stick_c/board.c +++ b/ports/espressif/boards/m5stack_stick_c/board.c @@ -167,7 +167,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/m5stack_stick_c_plus/board.c b/ports/espressif/boards/m5stack_stick_c_plus/board.c index 6d58e3a0a4276..08a3561b52813 100644 --- a/ports/espressif/boards/m5stack_stick_c_plus/board.c +++ b/ports/espressif/boards/m5stack_stick_c_plus/board.c @@ -167,7 +167,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/morpheans_morphesp-240/board.c b/ports/espressif/boards/morpheans_morphesp-240/board.c index cd3e0c6103120..bb72f9994f3d1 100644 --- a/ports/espressif/boards/morpheans_morphesp-240/board.c +++ b/ports/espressif/boards/morpheans_morphesp-240/board.c @@ -149,7 +149,9 @@ void board_init(void) { &pin_GPIO12, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected - false); // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master + ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c index 97d3bcabbefb0..29524dcb45ec9 100644 --- a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c +++ b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c @@ -72,7 +72,9 @@ static void display_init(void) { &pin_GPIO10, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected - false); // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master + ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index 4478e0f3ba29a..76db779a22f2a 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, false); + common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/espruino_banglejs2/board.c b/ports/nrf/boards/espruino_banglejs2/board.c index dc741744c8536..6d4dfa861910c 100644 --- a/ports/nrf/boards/espruino_banglejs2/board.c +++ b/ports/nrf/boards/espruino_banglejs2/board.c @@ -52,7 +52,7 @@ void board_init(void) { fb->base.type = &sharpdisplay_framebuffer_type; busio_spi_obj_t *spi = &fb->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_26, &pin_P0_27, NULL, false); + common_hal_busio_spi_construct(spi, &pin_P0_26, &pin_P0_27, NULL, false, false); common_hal_busio_spi_never_reset(spi); common_hal_sharpdisplay_framebuffer_construct(fb, spi, &pin_P0_05, 500000, 176, 176, true); diff --git a/ports/nrf/boards/hiibot_bluefi/board.c b/ports/nrf/boards/hiibot_bluefi/board.c index d07b31673339e..8ed3f27013dde 100644 --- a/ports/nrf/boards/hiibot_bluefi/board.c +++ b/ports/nrf/boards/hiibot_bluefi/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, false); // SCK, MOSI, MISO, not half-duplex + common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, false, false); // SCK, MOSI, MISO, not half-duplex common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c index a22d96e95980b..810972cc8ceee 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c +++ b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 7b48e1985dd77..9098644d58507 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 0006b80260a96..0d142d1c4b6c2 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -61,7 +61,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/hack_club_sprig/board.c b/ports/raspberrypi/boards/hack_club_sprig/board.c index e101e26d3dced..d8126872aba32 100644 --- a/ports/raspberrypi/boards/hack_club_sprig/board.c +++ b/ports/raspberrypi/boards/hack_club_sprig/board.c @@ -80,7 +80,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c b/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c index 411f1cbfa7515..afddb2b6a51c7 100644 --- a/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c +++ b/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c @@ -74,7 +74,9 @@ static void display_init(void) { &pin_GPIO2, // CLK &pin_GPIO3, // MOSI NULL, // MISO not connected - false); // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master + ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/raspberrypi/boards/pajenicko_picopad/board.c b/ports/raspberrypi/boards/pajenicko_picopad/board.c index c02c65d160e32..57af6d9cdc384 100644 --- a/ports/raspberrypi/boards/pajenicko_picopad/board.c +++ b/ports/raspberrypi/boards/pajenicko_picopad/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/pimoroni_badger2040/board.c b/ports/raspberrypi/boards/pimoroni_badger2040/board.c index b602f8cb65ac8..dd2f4b3f8a869 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040/board.c @@ -276,7 +276,7 @@ void board_init(void) { // Set up the SPI object used to control the display fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false, false); common_hal_busio_spi_never_reset(spi); // Set up the DisplayIO pin object diff --git a/ports/raspberrypi/boards/pimoroni_picosystem/board.c b/ports/raspberrypi/boards/pimoroni_picosystem/board.c index 5ee79715930cd..cdf679922cdef 100644 --- a/ports/raspberrypi/boards/pimoroni_picosystem/board.c +++ b/ports/raspberrypi/boards/pimoroni_picosystem/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/ugame22/board.c b/ports/raspberrypi/boards/ugame22/board.c index 48a26f9da04de..f29df0f6d691c 100644 --- a/ports/raspberrypi/boards/ugame22/board.c +++ b/ports/raspberrypi/boards/ugame22/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, false); + common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c index 31750619da45b..eb5433cdb1878 100644 --- a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c +++ b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c @@ -70,7 +70,8 @@ static void display_init(void) { &pin_GPIO10, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected - false // Not half-duplex + false, // Not half-duplex + false // operate SPI bus as master ); common_hal_busio_spi_never_reset(spi); diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index f52034d9be122..14fb48b17dfe4 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -74,7 +74,7 @@ //| MOSI: Optional[microcontroller.Pin] = None, //| MISO: Optional[microcontroller.Pin] = None, //| half_duplex: bool = False, -//| slave_mode: bool = False +//| slave_mode: bool = False, //| ) -> None: //| """Construct an SPI object on the given pins. //| diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 08a9761ed5f7e..b02260743d050 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -130,7 +130,7 @@ mp_obj_t common_hal_board_create_spi(const mp_int_t instance) { assert_pin_free(spi_pin[instance].mosi); assert_pin_free(spi_pin[instance].miso); - common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso, false); + common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso, false, false); spi_obj_created[instance] = true; return &spi_obj[instance]; diff --git a/supervisor/shared/external_flash/spi_flash.c b/supervisor/shared/external_flash/spi_flash.c index abff3437134d8..52073a3c22ca3 100644 --- a/supervisor/shared/external_flash/spi_flash.c +++ b/supervisor/shared/external_flash/spi_flash.c @@ -149,7 +149,7 @@ void spi_flash_init(void) { common_hal_digitalio_digitalinout_never_reset(&cs_pin); supervisor_flash_spi_bus.base.type = &busio_spi_type; - common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, false); + common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, false, false); common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus); common_hal_busio_spi_configure(&supervisor_flash_spi_bus, SPI_FLASH_MAX_BAUDRATE, 0, 0, 8); diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index 414b35dd41641..15f125e845e4b 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -164,6 +164,7 @@ void status_led_init() { MICROPY_HW_APA102_SCK, MICROPY_HW_APA102_MOSI, NULL, + false, false); #endif #if CIRCUITPY_BITBANG_APA102 From 58e1ee71e1797b1fa52a12a59b800df0e71e4688 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 7 Nov 2023 15:42:08 -0800 Subject: [PATCH 03/55] Attempt to change MODE to peripheral --- ports/atmel-samd/common-hal/busio/SPI.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index f768056addffa..b562e83ea5054 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -60,9 +60,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } // Ensure the object starts in its deinit state. self->clock_pin = NO_PIN; @@ -148,6 +145,10 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // Pads must be set after spi_m_sync_init(), which uses default values from // the prototypical SERCOM. + uint32_t SPI_CONFIG_OFFSETS[] = {0x40003000, 0x40003400, 0x43000000, 0x43000400, 0x43000800, 0x43000C00}; + if (slave_mode) { + *((uint32_t*) SPI_CONFIG_OFFSETS[sercom_index]) &= (1<<2); + } hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); From 844419391f42a70c62ebc2d8e403cb11303770e0 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 3 Dec 2023 18:21:19 -0800 Subject: [PATCH 04/55] fix inversion bitmath error --- ports/atmel-samd/common-hal/busio/SPI.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index b562e83ea5054..295753b13d63c 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -147,7 +147,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // the prototypical SERCOM. uint32_t SPI_CONFIG_OFFSETS[] = {0x40003000, 0x40003400, 0x43000000, 0x43000400, 0x43000800, 0x43000C00}; if (slave_mode) { - *((uint32_t*) SPI_CONFIG_OFFSETS[sercom_index]) &= (1<<2); + *((uint32_t*) SPI_CONFIG_OFFSETS[sercom_index]) &= ~(1<<2); } hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); From b98ff017d479a70604c39cb9811bd8793fe5fb3a Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 3 Dec 2023 18:32:00 -0800 Subject: [PATCH 05/55] add build script --- build-samd51-interpreter | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 build-samd51-interpreter diff --git a/build-samd51-interpreter b/build-samd51-interpreter new file mode 100644 index 0000000000000..c5ee30dadd739 --- /dev/null +++ b/build-samd51-interpreter @@ -0,0 +1,15 @@ +if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null +then + true +else + export PATH=/mnt/d/Files/Documents/School/UCLA/Organizations/BruinSpace/Rapid-CDH/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH +fi +cd ports/atmel-samd +make --debug -j8 BOARD=metro_m4_express +cd ../.. +echo "Compilation complete! Press ^C to confirm and exit." +while true; +do + paplay /usr/share/sounds/freedesktop/stereo/complete.oga + sleep 5s +done \ No newline at end of file From c969a6471555bc429a716a82158535a4b5964faf Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 3 Dec 2023 18:34:07 -0800 Subject: [PATCH 06/55] working edits to spi and can attempts --- .../boards/metro_m4_express/mpconfigboard.mk | 1 + ports/atmel-samd/common-hal/busio/SPI.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk index 61bc46ea4b923..c14177dff878c 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk @@ -11,6 +11,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 +CIRCUITPY_CANIO = 0 CIRCUITPY_FLOPPYIO = 0 CIRCUITPY_SYNTHIO = 0 diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 295753b13d63c..d23a2029ba2cf 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -58,7 +58,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, uint8_t dopo = 255; if (half_duplex) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); + mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented but true")); } // Ensure the object starts in its deinit state. @@ -145,10 +145,12 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // Pads must be set after spi_m_sync_init(), which uses default values from // the prototypical SERCOM. - uint32_t SPI_CONFIG_OFFSETS[] = {0x40003000, 0x40003400, 0x43000000, 0x43000400, 0x43000800, 0x43000C00}; - if (slave_mode) { - *((uint32_t*) SPI_CONFIG_OFFSETS[sercom_index]) &= ~(1<<2); - } + + // hri_sercomspi_write_CTRLA_MODE_bf(sercom, slave_mode ? 2 : 3); // this line makes circuitpython crash on a call to "mySpi.write()" + // uint32_t SPI_CONFIG_OFFSETS[] = {0x40003000, 0x40003400, 0x43000000, 0x43000400, 0x43000800, 0x43000C00}; + // if (slave_mode) { + // *((uint32_t*) SPI_CONFIG_OFFSETS[sercom_index]) &= ~(1<<2); + // } hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); @@ -161,7 +163,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, mp_raise_OSError(MP_EIO); } - gpio_set_pin_direction(clock->number, GPIO_DIRECTION_OUT); + gpio_set_pin_direction(clock->number, slave_mode ? GPIO_DIRECTION_IN : GPIO_DIRECTION_OUT); gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); gpio_set_pin_function(clock->number, clock_pinmux); claim_pin(clock); @@ -170,7 +172,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (mosi_none) { self->MOSI_pin = NO_PIN; } else { - gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_OUT); + gpio_set_pin_direction(mosi->number, slave_mode ? GPIO_DIRECTION_IN : GPIO_DIRECTION_OUT); gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); gpio_set_pin_function(mosi->number, mosi_pinmux); self->MOSI_pin = mosi->number; @@ -180,7 +182,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (miso_none) { self->MISO_pin = NO_PIN; } else { - gpio_set_pin_direction(miso->number, GPIO_DIRECTION_IN); + gpio_set_pin_direction(miso->number, slave_mode ? GPIO_DIRECTION_OUT : GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF); gpio_set_pin_function(miso->number, miso_pinmux); self->MISO_pin = miso->number; From 82a6f9571db64ce48bdfcc5ff731ad11ec9c2b40 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 5 Dec 2023 17:20:46 -0800 Subject: [PATCH 07/55] SPI responds to clock with this change, data transfer still ununcertain and parameter passing has issues --- ports/atmel-samd/common-hal/busio/SPI.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index d23a2029ba2cf..aafd31eed96fa 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -58,7 +58,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, uint8_t dopo = 255; if (half_duplex) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented but true")); + mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } // Ensure the object starts in its deinit state. @@ -146,11 +146,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // Pads must be set after spi_m_sync_init(), which uses default values from // the prototypical SERCOM. - // hri_sercomspi_write_CTRLA_MODE_bf(sercom, slave_mode ? 2 : 3); // this line makes circuitpython crash on a call to "mySpi.write()" - // uint32_t SPI_CONFIG_OFFSETS[] = {0x40003000, 0x40003400, 0x43000000, 0x43000400, 0x43000800, 0x43000C00}; - // if (slave_mode) { - // *((uint32_t*) SPI_CONFIG_OFFSETS[sercom_index]) &= ~(1<<2); - // } + hri_sercomspi_write_CTRLA_MODE_bf(sercom, slave_mode ? 2 : 3); hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); From 9c8401b205d92779029c3d3c4a2b25cb4052df1f Mon Sep 17 00:00:00 2001 From: anniexiang01 Date: Tue, 5 Dec 2023 17:37:57 -0800 Subject: [PATCH 08/55] build interpreter (mac version) --- build-samd51-interpreter-mac | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 build-samd51-interpreter-mac diff --git a/build-samd51-interpreter-mac b/build-samd51-interpreter-mac new file mode 100755 index 0000000000000..e71493182523d --- /dev/null +++ b/build-samd51-interpreter-mac @@ -0,0 +1,16 @@ +if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null; then + true +else + export PATH=/Volumes/Circuit_Python_Case_Sensitive_Disk/bruinspace-circuitpython/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH +fi + +cd ports/atmel-samd +make --debug -j8 BOARD=metro_m4_express +cd ../.. + +echo "Compilation complete! Press ^C to confirm and exit." + +while true; do + afplay /System/Library/Sounds/Ping.aiff + sleep 5s +done From 8a552f16537bfe7ba92af7f05442c243883a6320 Mon Sep 17 00:00:00 2001 From: anniexiang01 Date: Tue, 5 Dec 2023 19:28:51 -0800 Subject: [PATCH 09/55] potential fix for busio SPI parameters --- shared-bindings/busio/SPI.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 14fb48b17dfe4..45a39a714d477 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -114,8 +114,8 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_MOSI, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_half_duplex, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} }, - { MP_QSTR_slave_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_slave_mode, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); From b983bf98bcc1d3ee9033c67b4dcd8e8ad240c480 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 2 Apr 2024 12:51:56 -0700 Subject: [PATCH 10/55] add SS pin and fix DIPO/DOPO assignment --- locale/circuitpython.pot | 11 +- .../boards/hallowing_m4_express/board.c | 2 +- ports/atmel-samd/boards/monster_m4sk/board.c | 2 +- ports/atmel-samd/boards/openbook_m4/board.c | 2 +- ports/atmel-samd/boards/pewpew_lcd/board.c | 2 +- ports/atmel-samd/boards/pewpew_m4/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pygamer/board.c | 2 +- .../boards/seeeduino_wio_terminal/board.c | 2 +- ports/atmel-samd/common-hal/busio/SPI.c | 112 ++++++++++++++---- ports/atmel-samd/common-hal/busio/SPI.h | 1 + ports/broadcom/common-hal/busio/SPI.c | 2 +- ports/cxd56/common-hal/busio/SPI.c | 2 +- .../boards/adafruit_funhouse/board.c | 2 +- .../adafruit_magtag_2.9_grayscale/board.c | 2 +- .../boards/espressif_esp32s3_box/board.c | 2 +- .../boards/espressif_esp32s3_box_lite/board.c | 2 +- .../espressif_esp32s3_usb_otg_n8/board.c | 2 +- .../boards/hardkernel_odroid_go/board.c | 2 +- ports/espressif/boards/hiibot_iots2/board.c | 1 + .../boards/lilygo_tembed_esp32s3/board.c | 2 +- .../boards/lilygo_ttgo_t8_s2_st7789/board.c | 1 + .../lilygo_ttgo_tdisplay_esp32_16m/board.c | 1 + .../boards/lilygo_twatch_2020_v3/board.c | 1 + ports/espressif/boards/m5stack_atoms3/board.c | 2 +- .../espressif/boards/m5stack_stick_c/board.c | 2 +- .../boards/m5stack_stick_c_plus/board.c | 2 +- .../boards/morpheans_morphesp-240/board.c | 1 + .../waveshare_esp32_s2_pico_lcd/board.c | 1 + ports/espressif/common-hal/busio/SPI.c | 2 +- ports/mimxrt10xx/common-hal/busio/SPI.c | 2 +- .../nrf/boards/clue_nrf52840_express/board.c | 2 +- ports/nrf/boards/espruino_banglejs2/board.c | 2 +- ports/nrf/boards/hiibot_bluefi/board.c | 2 +- .../makerdiary_nrf52840_m2_devkit/board.c | 2 +- ports/nrf/boards/ohs2020_badge/board.c | 2 +- ports/nrf/common-hal/busio/SPI.c | 2 +- .../boards/adafruit_macropad_rp2040/board.c | 2 +- .../boards/hack_club_sprig/board.c | 2 +- .../boards/lilygo_t_display_rp2040/board.c | 1 + .../boards/pajenicko_picopad/board.c | 2 +- .../boards/pimoroni_badger2040/board.c | 2 +- .../boards/pimoroni_picosystem/board.c | 2 +- ports/raspberrypi/boards/ugame22/board.c | 2 +- .../boards/waveshare_rp2040_lcd_0_96/board.c | 1 + ports/raspberrypi/common-hal/busio/SPI.c | 2 +- ports/silabs/common-hal/busio/SPI.c | 1 + ports/stm/common-hal/busio/SPI.c | 2 +- shared-bindings/busio/SPI.c | 13 +- shared-bindings/busio/SPI.h | 2 +- shared-module/board/__init__.c | 2 +- supervisor/shared/external_flash/spi_flash.c | 2 +- supervisor/shared/status_leds.c | 1 + 53 files changed, 157 insertions(+), 68 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 0310a699f97f1..7f0c85f55bb01 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1142,6 +1142,10 @@ msgstr "" msgid "Hard fault: memory access or instruction error." msgstr "" +#: shared-bindings/busio/SPI.c +msgid "Hardware SS pin only supported for slave mode" +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/UART.c ports/stm/common-hal/busio/I2C.c #: ports/stm/common-hal/busio/SPI.c ports/stm/common-hal/busio/UART.c @@ -1415,6 +1419,10 @@ msgstr "" msgid "Must provide MISO or MOSI pin" msgstr "" +#: shared-bindings/busio/SPI.c +msgid "Must provide SS pin to operate in slave mode" +msgstr "" + #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "Must use a multiple of 6 rgb pins, not %d" @@ -1955,8 +1963,7 @@ msgstr "" msgid "Size not supported" msgstr "" -#: ports/atmel-samd/common-hal/busio/SPI.c ports/cxd56/common-hal/busio/SPI.c -#: ports/espressif/common-hal/busio/SPI.c +#: ports/cxd56/common-hal/busio/SPI.c ports/espressif/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/SPI.c #: ports/raspberrypi/common-hal/busio/SPI.c ports/stm/common-hal/busio/SPI.c msgid "Slave mode SPI is not implemented" diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index 3896bc415d694..d8218d7151aa1 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index 3dc9d0ed9d689..2b015443ddeec 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index 435a626a15ff7..079544f42b996 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -59,7 +59,7 @@ uint8_t refresh_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pewpew_lcd/board.c b/ports/atmel-samd/boards/pewpew_lcd/board.c index 91f9a92d4abcf..7d1915226398b 100644 --- a/ports/atmel-samd/boards/pewpew_lcd/board.c +++ b/ports/atmel-samd/boards/pewpew_lcd/board.c @@ -48,7 +48,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index ddb4429a65f2f..e55ef0899a0fc 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -99,7 +99,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index d99ef24e4c2f8..b1063eb4767cb 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index e1ac504cd0ad2..57b6d58f7cf7d 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c index 053551b99dfee..077d6c2262c7b 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c @@ -67,7 +67,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index aafd31eed96fa..5744d28198c9e 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -44,7 +44,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { Sercom *sercom = NULL; uint8_t sercom_index; uint32_t clock_pinmux = 0; @@ -52,6 +52,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, bool miso_none = miso == NULL; uint32_t mosi_pinmux = 0; uint32_t miso_pinmux = 0; + uint32_t ss_pinmux = 0; uint8_t clock_pad = 0; uint8_t mosi_pad = 0; uint8_t miso_pad = 0; @@ -96,35 +97,87 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { continue; } - for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { - if (!mosi_none) { - if (sercom_index == mosi->sercom[j].index) { - mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D); - mosi_pad = mosi->sercom[j].pad; - dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); - if (dopo > 0x3) { - continue; // pad combination not possible + if (slave_mode) { + // find miso_pad first, since it corresponds to dopo which takes limited values + for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { + if (!miso_none) { + if (sercom_index == miso->sercom[j].index) { + miso_pinmux = PINMUX(miso->number, (j == 0) ? MUX_C : MUX_D); + miso_pad = miso->sercom[j].pad; + dopo = samd_peripherals_get_spi_dopo(clock_pad, miso_pad); + if (dopo > 0x3) { + continue; // pad combination not possible + } + if (mosi_none) { + for (int m = 0; m < NUM_SERCOMS_PER_PIN; m++) { + if (sercom_index == ss->sercom[m].index) { + ss_pinmux = PINMUX(ss->number, (m == 0) ? MUX_C : MUX_D); + sercom = potential_sercom; + break; + } + } + if (sercom != NULL) { + break; + } + } + } else { + continue; } - if (miso_none) { - sercom = potential_sercom; - break; + } + if (!mosi_none) { + for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { + if (sercom_index == mosi->sercom[k].index) { + mosi_pinmux = PINMUX(mosi->number, (k == 0) ? MUX_C : MUX_D); + mosi_pad = mosi->sercom[k].pad; + for (int m = 0; m < NUM_SERCOMS_PER_PIN; m++) { + if (sercom_index == ss->sercom[m].index) { + ss_pinmux = PINMUX(ss->number, (m == 0) ? MUX_C : MUX_D); + sercom = potential_sercom; + break; + } + } + if (sercom != NULL) { + break; + } + } } - } else { - continue; + } + if (sercom != NULL) { + break; } } - if (!miso_none) { - for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { - if (sercom_index == miso->sercom[k].index) { - miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D); - miso_pad = miso->sercom[k].pad; - sercom = potential_sercom; - break; + } else { + // find mosi_pad first, since it corresponds to dopo which takes limited values + for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { + if (!mosi_none) { + if (sercom_index == mosi->sercom[j].index) { + mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D); + mosi_pad = mosi->sercom[j].pad; + dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); + if (dopo > 0x3) { + continue; // pad combination not possible + } + if (miso_none) { + sercom = potential_sercom; + break; + } + } else { + continue; } } - } - if (sercom != NULL) { - break; + if (!miso_none) { + for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { + if (sercom_index == miso->sercom[k].index) { + miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D); + miso_pad = miso->sercom[k].pad; + sercom = potential_sercom; + break; + } + } + } + if (sercom != NULL) { + break; + } } } if (sercom != NULL) { @@ -147,8 +200,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // the prototypical SERCOM. hri_sercomspi_write_CTRLA_MODE_bf(sercom, slave_mode ? 2 : 3); + self->slave_mode = slave_mode; hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); - hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); + hri_sercomspi_write_CTRLA_DIPO_bf(sercom, slave_mode ? mosi_pad : miso_pad); // Always start at 250khz which is what SD cards need. They are sensitive to // SPI bus noise before they are put into SPI mode. @@ -185,6 +239,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, claim_pin(miso); } + if (slave_mode) { + gpio_set_pin_direction(ss->number, slave_mode ? GPIO_DIRECTION_OUT : GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(ss->number, GPIO_PULL_OFF); + gpio_set_pin_function(ss->number, ss_pinmux); + self->SS_pin = ss->number; + claim_pin(ss); + } + spi_m_sync_enable(&self->spi_desc); } diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 7d7c39e66bb03..227847c8dee17 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -40,6 +40,7 @@ typedef struct { uint8_t clock_pin; uint8_t MOSI_pin; uint8_t MISO_pin; + uint8_t SS_pin; bool slave_mode; } busio_spi_obj_t; diff --git a/ports/broadcom/common-hal/busio/SPI.c b/ports/broadcom/common-hal/busio/SPI.c index 187c991569d69..62a1bb5ce091c 100644 --- a/ports/broadcom/common-hal/busio/SPI.c +++ b/ports/broadcom/common-hal/busio/SPI.c @@ -77,7 +77,7 @@ void reset_spi(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { size_t instance_index = NUM_SPI; BP_Function_Enum clock_alt = 0; BP_Function_Enum mosi_alt = 0; diff --git a/ports/cxd56/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c index 7c5771323eabc..682409a766cbb 100644 --- a/ports/cxd56/common-hal/busio/SPI.c +++ b/ports/cxd56/common-hal/busio/SPI.c @@ -36,7 +36,7 @@ #include "shared-bindings/microcontroller/Pin.h" void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, - const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { int port = -1; if (half_duplex) { diff --git a/ports/espressif/boards/adafruit_funhouse/board.c b/ports/espressif/boards/adafruit_funhouse/board.c index d21486775599d..761a478daaea3 100644 --- a/ports/espressif/boards/adafruit_funhouse/board.c +++ b/ports/espressif/boards/adafruit_funhouse/board.c @@ -52,7 +52,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index e81d21a5584bd..3d21b3f8bda32 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -116,7 +116,7 @@ const uint8_t refresh_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_box/board.c b/ports/espressif/boards/espressif_esp32s3_box/board.c index 4aa3c1de17a4b..a3f3de39ea1dc 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box/board.c @@ -45,7 +45,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c index efbbd74c53042..818f290c08da5 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c @@ -46,7 +46,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c index ec36b1cca3003..25bf86c43534e 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c @@ -73,7 +73,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/hardkernel_odroid_go/board.c b/ports/espressif/boards/hardkernel_odroid_go/board.c index 71ff8c20a5740..4c3d4fa4bb0f8 100644 --- a/ports/espressif/boards/hardkernel_odroid_go/board.c +++ b/ports/espressif/boards/hardkernel_odroid_go/board.c @@ -65,7 +65,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/hiibot_iots2/board.c b/ports/espressif/boards/hiibot_iots2/board.c index 39497f7c06049..cc453f16b52c7 100644 --- a/ports/espressif/boards/hiibot_iots2/board.c +++ b/ports/espressif/boards/hiibot_iots2/board.c @@ -73,6 +73,7 @@ static void display_init(void) { &pin_GPIO34, // CLK &pin_GPIO33, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c index 62c1b9ed20d85..d77508380bfac 100644 --- a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c +++ b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c @@ -45,7 +45,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c index ca840ff737a28..82f9a34658f09 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c @@ -73,6 +73,7 @@ static void display_init(void) { &pin_GPIO36, // CLK &pin_GPIO35, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c index d556701550bc0..0ccff151d36a8 100644 --- a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c +++ b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c @@ -53,6 +53,7 @@ static void display_init(void) { &pin_GPIO18, // CLK &pin_GPIO19, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c index 6fa7ad6fc67cb..25bd47d130f94 100644 --- a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c +++ b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c @@ -56,6 +56,7 @@ static void display_init(void) { &pin_GPIO18, // CLK &pin_GPIO19, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/espressif/boards/m5stack_atoms3/board.c b/ports/espressif/boards/m5stack_atoms3/board.c index 0f23ed903f84e..b1af08ee1cdcd 100644 --- a/ports/espressif/boards/m5stack_atoms3/board.c +++ b/ports/espressif/boards/m5stack_atoms3/board.c @@ -54,7 +54,7 @@ void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; // busio_spi_obj_t *spi = common_hal_board_create_spi(0); busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/m5stack_stick_c/board.c b/ports/espressif/boards/m5stack_stick_c/board.c index 693b7eefe783b..3ab7c5f03e975 100644 --- a/ports/espressif/boards/m5stack_stick_c/board.c +++ b/ports/espressif/boards/m5stack_stick_c/board.c @@ -167,7 +167,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/m5stack_stick_c_plus/board.c b/ports/espressif/boards/m5stack_stick_c_plus/board.c index 08a3561b52813..610262dbe01d1 100644 --- a/ports/espressif/boards/m5stack_stick_c_plus/board.c +++ b/ports/espressif/boards/m5stack_stick_c_plus/board.c @@ -167,7 +167,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/morpheans_morphesp-240/board.c b/ports/espressif/boards/morpheans_morphesp-240/board.c index bb72f9994f3d1..73d7b279ba4d4 100644 --- a/ports/espressif/boards/morpheans_morphesp-240/board.c +++ b/ports/espressif/boards/morpheans_morphesp-240/board.c @@ -149,6 +149,7 @@ void board_init(void) { &pin_GPIO12, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c index 29524dcb45ec9..6e2ef5c17dcea 100644 --- a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c +++ b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c @@ -72,6 +72,7 @@ static void display_init(void) { &pin_GPIO10, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/espressif/common-hal/busio/SPI.c b/ports/espressif/common-hal/busio/SPI.c index b909245f095f7..16e9fc76fc083 100644 --- a/ports/espressif/common-hal/busio/SPI.c +++ b/ports/espressif/common-hal/busio/SPI.c @@ -77,7 +77,7 @@ static void set_spi_config(busio_spi_obj_t *self, void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { const spi_bus_config_t bus_config = { .mosi_io_num = mosi != NULL ? mosi->number : -1, diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index 511ad9edc0dca..8e648a2499826 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -91,7 +91,7 @@ void spi_reset(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { const uint32_t sck_count = MP_ARRAY_SIZE(mcu_spi_sck_list); const uint32_t miso_count = MP_ARRAY_SIZE(mcu_spi_sdi_list); diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index 76db779a22f2a..f013f646ad014 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/espruino_banglejs2/board.c b/ports/nrf/boards/espruino_banglejs2/board.c index 6d4dfa861910c..f3213d1508aa7 100644 --- a/ports/nrf/boards/espruino_banglejs2/board.c +++ b/ports/nrf/boards/espruino_banglejs2/board.c @@ -52,7 +52,7 @@ void board_init(void) { fb->base.type = &sharpdisplay_framebuffer_type; busio_spi_obj_t *spi = &fb->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_26, &pin_P0_27, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_26, &pin_P0_27, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); common_hal_sharpdisplay_framebuffer_construct(fb, spi, &pin_P0_05, 500000, 176, 176, true); diff --git a/ports/nrf/boards/hiibot_bluefi/board.c b/ports/nrf/boards/hiibot_bluefi/board.c index 8ed3f27013dde..400f601646811 100644 --- a/ports/nrf/boards/hiibot_bluefi/board.c +++ b/ports/nrf/boards/hiibot_bluefi/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, false, false); // SCK, MOSI, MISO, not half-duplex + common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, NULL, false, false); // SCK, MOSI, MISO, not half-duplex common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c index 810972cc8ceee..bd94cd8cf99ea 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c +++ b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 9098644d58507..3c69db91504d9 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 2783f757a130d..10bae0b3d24ea 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -143,7 +143,7 @@ static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) return 0; } -void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { +void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 0d142d1c4b6c2..1b55f3744f093 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -61,7 +61,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/hack_club_sprig/board.c b/ports/raspberrypi/boards/hack_club_sprig/board.c index d8126872aba32..0d3c56dab9512 100644 --- a/ports/raspberrypi/boards/hack_club_sprig/board.c +++ b/ports/raspberrypi/boards/hack_club_sprig/board.c @@ -80,7 +80,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c b/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c index afddb2b6a51c7..3519297ae46af 100644 --- a/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c +++ b/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c @@ -74,6 +74,7 @@ static void display_init(void) { &pin_GPIO2, // CLK &pin_GPIO3, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/raspberrypi/boards/pajenicko_picopad/board.c b/ports/raspberrypi/boards/pajenicko_picopad/board.c index 57af6d9cdc384..c361363068a48 100644 --- a/ports/raspberrypi/boards/pajenicko_picopad/board.c +++ b/ports/raspberrypi/boards/pajenicko_picopad/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/pimoroni_badger2040/board.c b/ports/raspberrypi/boards/pimoroni_badger2040/board.c index dd2f4b3f8a869..1b2263bece822 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040/board.c @@ -276,7 +276,7 @@ void board_init(void) { // Set up the SPI object used to control the display fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, NULL, false, false); common_hal_busio_spi_never_reset(spi); // Set up the DisplayIO pin object diff --git a/ports/raspberrypi/boards/pimoroni_picosystem/board.c b/ports/raspberrypi/boards/pimoroni_picosystem/board.c index cdf679922cdef..d733988f24f58 100644 --- a/ports/raspberrypi/boards/pimoroni_picosystem/board.c +++ b/ports/raspberrypi/boards/pimoroni_picosystem/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/ugame22/board.c b/ports/raspberrypi/boards/ugame22/board.c index f29df0f6d691c..8718c15c4ffc9 100644 --- a/ports/raspberrypi/boards/ugame22/board.c +++ b/ports/raspberrypi/boards/ugame22/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, NULL, false, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c index eb5433cdb1878..65c8cd856eaac 100644 --- a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c +++ b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c @@ -70,6 +70,7 @@ static void display_init(void) { &pin_GPIO10, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected + NULL, // SS not connected false, // Not half-duplex false // operate SPI bus as master ); diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index d85b628c9b822..eb533fb131e33 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -54,7 +54,7 @@ void reset_spi(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { size_t instance_index = NO_INSTANCE; if (half_duplex) { diff --git a/ports/silabs/common-hal/busio/SPI.c b/ports/silabs/common-hal/busio/SPI.c index 6fcdbf4097d7d..b89edb714300d 100644 --- a/ports/silabs/common-hal/busio/SPI.c +++ b/ports/silabs/common-hal/busio/SPI.c @@ -53,6 +53,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, + const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { Ecode_t sc = ECODE_OK; diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index 2e8ecff422966..b0b401c077b3a 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -167,7 +167,7 @@ STATIC int check_pins(busio_spi_obj_t *self, void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { if (slave_mode) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); } diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index 45a39a714d477..ea38a681fd4a2 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -73,6 +73,7 @@ //| clock: microcontroller.Pin, //| MOSI: Optional[microcontroller.Pin] = None, //| MISO: Optional[microcontroller.Pin] = None, +//| SS: Optional[microcontroller.Pin] = None, //| half_duplex: bool = False, //| slave_mode: bool = False, //| ) -> None: @@ -109,11 +110,12 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BUSIO_SPI busio_spi_obj_t *self = mp_obj_malloc(busio_spi_obj_t, &busio_spi_type); - enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_half_duplex, ARG_slave_mode }; + enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_SS, ARG_half_duplex, ARG_slave_mode }; static const mp_arg_t allowed_args[] = { { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_MOSI, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_SS, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_slave_mode, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; @@ -123,12 +125,19 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock); const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj, MP_QSTR_mosi); const mcu_pin_obj_t *miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj, MP_QSTR_miso); + const mcu_pin_obj_t *ss = validate_obj_is_free_pin_or_none(args[ARG_SS].u_obj, MP_QSTR_ss); if (!miso && !mosi) { mp_raise_ValueError(MP_ERROR_TEXT("Must provide MISO or MOSI pin")); } + if (args[ARG_slave_mode].u_bool && !ss) { + mp_raise_ValueError(MP_ERROR_TEXT("Must provide SS pin to operate in slave mode")); + } + if (!args[ARG_slave_mode].u_bool && ss) { + mp_raise_ValueError(MP_ERROR_TEXT("Hardware SS pin only supported for slave mode")); + } - common_hal_busio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool, args[ARG_slave_mode].u_bool); + common_hal_busio_spi_construct(self, clock, mosi, miso, ss, args[ARG_half_duplex].u_bool, args[ARG_slave_mode].u_bool); return MP_OBJ_FROM_PTR(self); #else raise_ValueError_invalid_pins(); diff --git a/shared-bindings/busio/SPI.h b/shared-bindings/busio/SPI.h index 108f0e3cc3a22..a1cc6da4e7592 100644 --- a/shared-bindings/busio/SPI.h +++ b/shared-bindings/busio/SPI.h @@ -38,7 +38,7 @@ extern const mp_obj_type_t busio_spi_type; // Construct an underlying SPI object. extern void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, bool half_duplex, bool slave_mode); + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode); extern void common_hal_busio_spi_deinit(busio_spi_obj_t *self); extern bool common_hal_busio_spi_deinited(busio_spi_obj_t *self); diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index b02260743d050..af56ec1a998df 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -130,7 +130,7 @@ mp_obj_t common_hal_board_create_spi(const mp_int_t instance) { assert_pin_free(spi_pin[instance].mosi); assert_pin_free(spi_pin[instance].miso); - common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso, false, false); + common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso, NULL, false, false); spi_obj_created[instance] = true; return &spi_obj[instance]; diff --git a/supervisor/shared/external_flash/spi_flash.c b/supervisor/shared/external_flash/spi_flash.c index 52073a3c22ca3..3911fb8801666 100644 --- a/supervisor/shared/external_flash/spi_flash.c +++ b/supervisor/shared/external_flash/spi_flash.c @@ -149,7 +149,7 @@ void spi_flash_init(void) { common_hal_digitalio_digitalinout_never_reset(&cs_pin); supervisor_flash_spi_bus.base.type = &busio_spi_type; - common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, false, false); + common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, NULL, false, false); common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus); common_hal_busio_spi_configure(&supervisor_flash_spi_bus, SPI_FLASH_MAX_BAUDRATE, 0, 0, 8); diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index 15f125e845e4b..c66747ad0df10 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -164,6 +164,7 @@ void status_led_init() { MICROPY_HW_APA102_SCK, MICROPY_HW_APA102_MOSI, NULL, + NULL, false, false); #endif From c06f9e18dfef1e40e8bb7b82aa73e70b0c7bdc0b Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 3 May 2024 20:05:35 -0700 Subject: [PATCH 11/55] hey wait we dont need a crystal --- ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h index 3b9ca9666988b..722a737786f48 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h @@ -12,7 +12,7 @@ #define MICROPY_HW_NEOPIXEL (&pin_PB22) -#define BOARD_HAS_CRYSTAL 1 +#define BOARD_HAS_CRYSTAL 0 #define DEFAULT_I2C_BUS_SCL (&pin_PB03) #define DEFAULT_I2C_BUS_SDA (&pin_PB02) From bd106660f4daf15d239164d65d4b43ceeb1c6f8e Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 3 May 2024 20:08:37 -0700 Subject: [PATCH 12/55] update dma code to use new allocation interface --- ports/atmel-samd/audio_dma.c | 25 ++----------------- ports/atmel-samd/audio_dma.h | 3 --- .../atmel-samd/common-hal/audiobusio/PDMIn.c | 2 +- .../imagecapture/ParallelImageCapture.c | 2 +- ports/atmel-samd/peripherals | 2 +- 5 files changed, 5 insertions(+), 29 deletions(-) diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c index 287ef41b35c16..2d410785efe92 100644 --- a/ports/atmel-samd/audio_dma.c +++ b/ports/atmel-samd/audio_dma.c @@ -50,8 +50,6 @@ static audio_dma_t *audio_dma_state[AUDIO_DMA_CHANNEL_COUNT]; // This cannot be in audio_dma_state because it's volatile. static volatile bool audio_dma_pending[AUDIO_DMA_CHANNEL_COUNT]; -static bool audio_dma_allocated[AUDIO_DMA_CHANNEL_COUNT]; - uint8_t find_sync_event_channel_raise() { uint8_t event_channel = find_sync_event_channel(); if (event_channel >= EVSYS_SYNCH_NUM) { @@ -60,24 +58,6 @@ uint8_t find_sync_event_channel_raise() { return event_channel; } -uint8_t dma_allocate_channel(void) { - uint8_t channel; - for (channel = 0; channel < AUDIO_DMA_CHANNEL_COUNT; channel++) { - if (!audio_dma_allocated[channel]) { - audio_dma_allocated[channel] = true; - return channel; - } - } - return channel; // i.e., return failure -} - -void dma_free_channel(uint8_t channel) { - assert(channel < AUDIO_DMA_CHANNEL_COUNT); - assert(audio_dma_allocated[channel]); - audio_dma_disable_channel(channel); - audio_dma_allocated[channel] = false; -} - void audio_dma_disable_channel(uint8_t channel) { if (channel >= AUDIO_DMA_CHANNEL_COUNT) { return; @@ -211,7 +191,7 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma, bool output_signed, uint32_t output_register_address, uint8_t dma_trigger_source) { - uint8_t dma_channel = dma_allocate_channel(); + uint8_t dma_channel = dma_allocate_channel(true); if (dma_channel >= AUDIO_DMA_CHANNEL_COUNT) { return AUDIO_DMA_DMA_BUSY; } @@ -362,8 +342,7 @@ void audio_dma_reset(void) { for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) { audio_dma_state[i] = NULL; audio_dma_pending[i] = false; - audio_dma_allocated[i] = false; - audio_dma_disable_channel(i); + dma_free_channel(i); dma_descriptor(i)->BTCTRL.bit.VALID = false; MP_STATE_PORT(playing_audio)[i] = NULL; } diff --git a/ports/atmel-samd/audio_dma.h b/ports/atmel-samd/audio_dma.h index cc41b0ae78d97..f9e808fb02c85 100644 --- a/ports/atmel-samd/audio_dma.h +++ b/ports/atmel-samd/audio_dma.h @@ -68,9 +68,6 @@ uint8_t audiosample_channel_count(mp_obj_t sample_obj); void audio_dma_init(audio_dma_t *dma); void audio_dma_reset(void); -uint8_t dma_allocate_channel(void); -void dma_free_channel(uint8_t channel); - // This sets everything up but doesn't start the timer. // Sample is the python object for the sample to play. // loop is true if we should loop the sample. diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c index c4ab65562a70c..49358e0a51662 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -384,7 +384,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) { // output_buffer_length is the number of slots, not the number of bytes. uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t *self, uint16_t *output_buffer, uint32_t output_buffer_length) { - uint8_t dma_channel = dma_allocate_channel(); + uint8_t dma_channel = dma_allocate_channel(true); pdmin_event_channel = find_sync_event_channel_raise(); pdmin_dma_block_done = false; diff --git a/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c b/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c index 8f789f232b2d0..0df48e10f6193 100644 --- a/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c @@ -155,7 +155,7 @@ void common_hal_imagecapture_parallelimagecapture_singleshot_capture(imagecaptur mp_buffer_info_t bufinfo; mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_RW); - uint8_t dma_channel = dma_allocate_channel(); + uint8_t dma_channel = dma_allocate_channel(true); uint32_t *dest = bufinfo.buf; size_t count = bufinfo.len / 4; // PCC receives 4 bytes (2 pixels) at a time diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index 82e514b6e0d1a..52c9dd499e652 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit 82e514b6e0d1a2b09dc73be9973663b6b837a817 +Subproject commit 52c9dd499e652324ab266665521f19c137756fe2 From 5490a82a4c5f0faa4296232a515eec59d82aa7f8 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 3 May 2024 20:09:22 -0700 Subject: [PATCH 13/55] add async spi interface --- ports/atmel-samd/common-hal/busio/SPI.c | 67 +++++++++++ ports/atmel-samd/common-hal/busio/SPI.h | 1 + shared-bindings/busio/SPI.c | 148 ++++++++++++++++++++++++ shared-bindings/busio/SPI.h | 13 +++ 4 files changed, 229 insertions(+) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 148d282593a1f..df209ff38eaff 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -247,6 +247,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, claim_pin(ss); } + self->running_dma.failure = 1; // not started + spi_m_sync_enable(&self->spi_desc); } @@ -329,6 +331,9 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, if (len == 0) { return true; } + if (self->running_dma.failure != 1) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); + } int32_t status; if (len >= 16) { size_t bytes_remaining = len; @@ -359,6 +364,9 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self, if (len == 0) { return true; } + if (self->running_dma.failure != 1) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); + } int32_t status; if (len >= 16) { status = sercom_dma_read(self->spi_desc.dev.prvt, data, len, write_value); @@ -377,6 +385,9 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou if (len == 0) { return true; } + if (self->running_dma.failure != 1) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); + } int32_t status; if (len >= 16) { status = sercom_dma_transfer(self->spi_desc.dev.prvt, data_out, data_in, len); @@ -390,6 +401,62 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou return status >= 0; // Status is number of chars read or an error code < 0. } +void common_hal_busio_spi_transfer_async_start(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) { + if (len == 0) { + return; + } + if (self->running_dma.failure != 1) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); + } + Sercom* sercom = self->spi_desc.dev.prvt; + self->running_dma = shared_dma_transfer_start(sercom, data_out, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, data_in, len, 0); + + // There is an issue where if an unexpected SPI transfer is received before the user calls "end" for the in-progress, expected + // transfer, the SERCOM has an error and gets confused. This can be detected from INTFLAG.ERROR. I think the code in + // ports/atmel-samd/peripherals/samd/dma.c at line 277 (as of this commit; it's the part that reads s->SPI.INTFLAG.bit.RXC and + // s->SPI.DATA.reg) is supposed to fix this, but experimentation seems to show that it does not in fact fix anything. Anyways, if + // the ERROR bit is set, let's just reset the peripheral and then setup the transfer again -- that seems to work. + if (hri_sercomspi_get_INTFLAG_ERROR_bit(sercom)) { + shared_dma_transfer_close(self->running_dma); + + // disable the sercom + spi_m_sync_disable(&self->spi_desc); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + + // save configurations + hri_sercomspi_ctrla_reg_t ctrla_saved_val = hri_sercomspi_get_CTRLA_reg(sercom, -1); // -1 mask is all ones: save all bits + hri_sercomspi_ctrlb_reg_t ctrlb_saved_val = hri_sercomspi_get_CTRLB_reg(sercom, -1); // -1 mask is all ones: save all bits + hri_sercomspi_baud_reg_t baud_saved_val = hri_sercomspi_get_BAUD_reg(sercom, -1); // -1 mask is all ones: save all bits + // reset + hri_sercomspi_set_CTRLA_SWRST_bit(sercom); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + // re-write configurations + hri_sercomspi_write_CTRLA_reg(sercom, ctrla_saved_val); + hri_sercomspi_write_CTRLB_reg(sercom, ctrlb_saved_val); + hri_sercomspi_write_BAUD_reg (sercom, baud_saved_val); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + + // re-enable the sercom + spi_m_sync_enable(&self->spi_desc); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + + self->running_dma = shared_dma_transfer_start(sercom, data_out, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, data_in, len, 0); + } +} + +bool common_hal_busio_spi_transfer_async_check(busio_spi_obj_t *self) { + return self->running_dma.failure == 1 || shared_dma_transfer_finished(self->running_dma); +} + +int common_hal_busio_spi_transfer_async_end(busio_spi_obj_t *self) { + if (self->running_dma.failure == 1) { + return 0; + } + int res = shared_dma_transfer_close(self->running_dma); + self->running_dma.failure = 1; + return res; +} + uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self) { return samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt)); } diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 227847c8dee17..95cc8d379f08a 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -42,6 +42,7 @@ typedef struct { uint8_t MISO_pin; uint8_t SS_pin; bool slave_mode; + dma_descr_t running_dma; } busio_spi_obj_t; #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index ea38a681fd4a2..f9036af3e6595 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -481,6 +481,146 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_get_frequency_obj, busio_spi_obj_get_frequen MP_PROPERTY_GETTER(busio_spi_frequency_obj, (mp_obj_t)&busio_spi_get_frequency_obj); + +#if CIRCUITPY_SAMD + +//| import sys +//| def async_transfer_start( +//| self, +//| out_buffer: ReadableBuffer, +//| in_buffer: WriteableBuffer, +//| *, +//| out_start: int = 0, +//| out_end: int = sys.maxsize, +//| in_start: int = 0, +//| in_end: int = sys.maxsize +//| ) -> None: +//| """Write out the data in ``out_buffer`` while simultaneously reading data into ``in_buffer``. +//| The SPI object must be locked. Note: this method returns immediately, and the data will not +//| actually be transferred until some time has passed. Use `async_transfer_finished` and +//| `async_transfer_end` to check on the status of the transfer and close out its resources. +//| +//| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced +//| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data. +//| The number of bytes written will be the length of ``out_buffer[out_start:out_end]``. +//| +//| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced +//| as if ``in_buffer[in_start:in_end]`` were passed, +//| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``. +//| +//| The lengths of the slices defined by ``out_buffer[out_start:out_end]`` +//| and ``in_buffer[in_start:in_end]`` must be equal. +//| If buffer slice lengths are both 0, nothing happens. +//| +//| Note: This method is currently only available on atmel-samd` ports of CircuitPython. +//| +//| :param ReadableBuffer out_buffer: write out bytes from this buffer +//| :param WriteableBuffer in_buffer: read bytes into this buffer +//| :param int out_start: beginning of ``out_buffer`` slice +//| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)`` +//| :param int in_start: beginning of ``in_buffer`` slice +//| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)`` +//| """ +//| ... + +STATIC mp_obj_t busio_spi_start_async_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_out_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_in_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_out_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_out_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, + { MP_QSTR_in_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_in_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, + }; + busio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + check_lock(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_buffer_info_t buf_out_info; + mp_get_buffer_raise(args[ARG_out_buffer].u_obj, &buf_out_info, MP_BUFFER_READ); + int out_stride_in_bytes = mp_binary_get_size('@', buf_out_info.typecode, NULL); + int32_t out_start = args[ARG_out_start].u_int; + size_t out_length = buf_out_info.len / out_stride_in_bytes; + normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length); + + mp_buffer_info_t buf_in_info; + mp_get_buffer_raise(args[ARG_in_buffer].u_obj, &buf_in_info, MP_BUFFER_WRITE); + int in_stride_in_bytes = mp_binary_get_size('@', buf_in_info.typecode, NULL); + int32_t in_start = args[ARG_in_start].u_int; + size_t in_length = buf_in_info.len / in_stride_in_bytes; + normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length); + + // Treat start and length in terms of bytes from now on. + out_start *= out_stride_in_bytes; + out_length *= out_stride_in_bytes; + in_start *= in_stride_in_bytes; + in_length *= in_stride_in_bytes; + + if (out_length != in_length) { + mp_raise_ValueError(MP_ERROR_TEXT("buffer slices must be of equal length")); + } + + common_hal_busio_spi_transfer_async_start(self, + ((uint8_t *)buf_out_info.buf) + out_start, + ((uint8_t *)buf_in_info.buf) + in_start, + out_length); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_start_transfer_obj, 1, busio_spi_start_async_transfer); + +//| import sys +//| def async_transfer_finished( +//| self +//| ) -> None: +//| """Check whether or not the last async transfer started on this SPI object has finished. If +//| no transfer was started, this method behaves as though the most recent transfer has finished +//| and returns `True`. Otherwise, it returns `False`. +//| +//| Note: This method is currently only available on atmel-samd` ports of CircuitPython. +//| """ +//| ... +STATIC mp_obj_t busio_spi_obj_check_async_transfer(mp_obj_t self_in) { + busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return common_hal_busio_spi_transfer_async_check(self) ? mp_const_true : mp_const_false; +} +MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_check_transfer_obj, busio_spi_obj_check_async_transfer); + +//| import sys +//| def async_transfer_end( +//| self +//| ) -> None: +//| """Return the status code with which the last async transfer on this SPI object completed. This +//| method MUST be called for all transfers, regardless of user interest in status code. The resources +//| for the transfer will be left open until this method is called. Once this method is called, the +//| peripheral resets and is ready for another transfer. The return code of this method also resets to +//| its pre-transfer state: repeated calls to this method may produce different codes. +//| +//| Return code 0: No transfer has occured, either because `start_async_transfer` was never called, or because +//| it was called with zero-length buffers. +//| Return code -1: The transfer failed because no DMA channels are available. +//| Return code -2: The transfer executed, but the DMA controller indicates that either some data is +//| untransferred, that a software issue prevented the data transfer from completing, or that some other error +//| has occured within the DMA controller. +//| Return code -3: An unaligned buffer was passed to the QSPI peripheral, which prevents the DMA controller from +//| appropriately chunking the transfer. +//| Return code n>0: A transfer of `n` bytes in each direction has succeeded. +//| +//| Note: This method is currently only available on atmel-samd` ports of CircuitPython. +//| """ +//| ... +STATIC mp_obj_t busio_spi_obj_end_async_transfer(mp_obj_t self_in) { + busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_busio_spi_transfer_async_end(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_end_transfer_obj, busio_spi_obj_end_async_transfer); + +#endif // CIRCUITPY_SAMD + #endif // CIRCUITPY_BUSIO_SPI @@ -498,6 +638,14 @@ STATIC const mp_rom_map_elem_t busio_spi_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&busio_spi_write_obj) }, { MP_ROM_QSTR(MP_QSTR_write_readinto), MP_ROM_PTR(&busio_spi_write_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&busio_spi_frequency_obj) } + + #if CIRCUITPY_SAMD + , + { MP_ROM_QSTR(MP_QSTR_async_transfer_start), MP_ROM_PTR(&busio_spi_start_transfer_obj) }, + { MP_ROM_QSTR(MP_QSTR_async_transfer_finished), MP_ROM_PTR(&busio_spi_check_transfer_obj) }, + { MP_ROM_QSTR(MP_QSTR_async_transfer_end), MP_ROM_PTR(&busio_spi_end_transfer_obj) } + #endif // CIRCUITPY_SAMD + #endif // CIRCUITPY_BUSIO_SPI }; STATIC MP_DEFINE_CONST_DICT(busio_spi_locals_dict, busio_spi_locals_dict_table); diff --git a/shared-bindings/busio/SPI.h b/shared-bindings/busio/SPI.h index a1cc6da4e7592..c56ed5dd463b5 100644 --- a/shared-bindings/busio/SPI.h +++ b/shared-bindings/busio/SPI.h @@ -58,6 +58,19 @@ extern bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size // Reads and write len bytes simultaneously. extern bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len); +#if CIRCUITPY_SAMD + +// Initiates a transfer that reads and write len bytes simultaneously +extern void common_hal_busio_spi_transfer_async_start(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len); + +// Reads the state of the in-progress transfer +extern bool common_hal_busio_spi_transfer_async_check(busio_spi_obj_t *self); + +// Cleans up the completed transfer and returns any error code produced by the transfer +extern int common_hal_busio_spi_transfer_async_end(busio_spi_obj_t *self); + +#endif // CIRCUITPY_SAMD + // Return actual SPI bus frequency. uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self); From cfa4425d3443ebb54ace97f78d477a34079b44cd Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 5 May 2024 22:12:30 -0700 Subject: [PATCH 14/55] enable preloading data register --- ports/atmel-samd/common-hal/busio/SPI.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index df209ff38eaff..d80fc3dd79f89 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -203,6 +203,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, self->slave_mode = slave_mode; hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); hri_sercomspi_write_CTRLA_DIPO_bf(sercom, slave_mode ? mosi_pad : miso_pad); + hri_sercomspi_write_CTRLB_PLOADEN_bit(sercom, slave_mode); // Always start at 250khz which is what SD cards need. They are sensitive to // SPI bus noise before they are put into SPI mode. From 5c2149580b86001998b8db71d3e3c9108b19c4cd Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 19 May 2024 17:43:29 -0700 Subject: [PATCH 15/55] update samd-peripherals submodule to point to a bruinspace-owned fork --- .gitmodules | 2 +- ports/atmel-samd/peripherals | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8934f17d7cb61..f4b5626dd52ed 100644 --- a/.gitmodules +++ b/.gitmodules @@ -59,7 +59,7 @@ url = https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git [submodule "ports/atmel-samd/peripherals"] path = ports/atmel-samd/peripherals - url = https://github.com/adafruit/samd-peripherals.git + url = https://github.com/Bruin-Spacecraft-Group/bruinspace-samd-peripherals.git [submodule "frozen/Adafruit_CircuitPython_Crickit"] path = frozen/Adafruit_CircuitPython_Crickit url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index 52c9dd499e652..87483f3281fe6 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit 52c9dd499e652324ab266665521f19c137756fe2 +Subproject commit 87483f3281fe6a05c9e66ae62615205f74675c49 From 4d151a02969b760ee60085eb7d1f518394ac69d9 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 19 May 2024 22:56:15 -0700 Subject: [PATCH 16/55] update reference submodule commit hash --- ports/atmel-samd/peripherals | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index 87483f3281fe6..fd82c8b829b8d 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit 87483f3281fe6a05c9e66ae62615205f74675c49 +Subproject commit fd82c8b829b8d72eb0e45de16ac9db43a77ac764 From 26e838b5f9b7a98d6075d3859bc914e4b60cb66c Mon Sep 17 00:00:00 2001 From: Annie Xiang Date: Mon, 20 May 2024 00:29:59 -0700 Subject: [PATCH 17/55] added board configurations for RAPID-0 CDH, ADCS, and EPS boards. reverted Metro M4 Express board configurations to original --- .../boards/metro_m4_express/mpconfigboard.h | 2 +- .../boards/metro_m4_express/mpconfigboard.mk | 1 - ports/atmel-samd/boards/rapid0_adcs/board.c | 29 ++++++++ .../boards/rapid0_adcs/mpconfigboard.h | 29 ++++++++ .../boards/rapid0_adcs/mpconfigboard.mk | 27 +++++++ ports/atmel-samd/boards/rapid0_adcs/pins.c | 74 +++++++++++++++++++ ports/atmel-samd/boards/rapid0_cdh/board.c | 29 ++++++++ .../boards/rapid0_cdh/mpconfigboard.h | 45 +++++++++++ .../boards/rapid0_cdh/mpconfigboard.mk | 27 +++++++ ports/atmel-samd/boards/rapid0_cdh/pins.c | 66 +++++++++++++++++ ports/atmel-samd/boards/rapid0_eps/board.c | 29 ++++++++ .../boards/rapid0_eps/mpconfigboard.h | 29 ++++++++ .../boards/rapid0_eps/mpconfigboard.mk | 27 +++++++ ports/atmel-samd/boards/rapid0_eps/pins.c | 50 +++++++++++++ ports/atmel-samd/peripherals | 2 +- 15 files changed, 463 insertions(+), 3 deletions(-) create mode 100644 ports/atmel-samd/boards/rapid0_adcs/board.c create mode 100644 ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/rapid0_adcs/pins.c create mode 100644 ports/atmel-samd/boards/rapid0_cdh/board.c create mode 100644 ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/rapid0_cdh/pins.c create mode 100644 ports/atmel-samd/boards/rapid0_eps/board.c create mode 100644 ports/atmel-samd/boards/rapid0_eps/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/rapid0_eps/pins.c diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h index 722a737786f48..3b9ca9666988b 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h @@ -12,7 +12,7 @@ #define MICROPY_HW_NEOPIXEL (&pin_PB22) -#define BOARD_HAS_CRYSTAL 0 +#define BOARD_HAS_CRYSTAL 1 #define DEFAULT_I2C_BUS_SCL (&pin_PB03) #define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk index e44bc7fcb81dc..4f01c141e4849 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk @@ -11,7 +11,6 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ" LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 -CIRCUITPY_CANIO = 0 CIRCUITPY_FLOPPYIO = 0 CIRCUITPY_JPEGIO = 0 CIRCUITPY_SYNTHIO = 0 diff --git a/ports/atmel-samd/boards/rapid0_adcs/board.c b/ports/atmel-samd/boards/rapid0_adcs/board.c new file mode 100644 index 0000000000000..fb1ce4fb834f0 --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_adcs/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h new file mode 100644 index 0000000000000..37ebc23aafe7f --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h @@ -0,0 +1,29 @@ +#define MICROPY_HW_BOARD_NAME "RAPID-0 ADCS" +#define MICROPY_HW_MCU_NAME "samd51n20" + +#define CIRCUITPY_MCU_FAMILY samd51 + +// This is for Rev F which is green + +#define MICROPY_HW_LED_TX (&pin_PA27) +#define MICROPY_HW_LED_RX (&pin_PB06) + +#define MICROPY_HW_LED_STATUS (&pin_PA16) + +#define MICROPY_HW_NEOPIXEL (&pin_PB22) + +#define BOARD_HAS_CRYSTAL 0 + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) + +#define DEFAULT_SPI_BUS_SCK (&pin_PA13) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA12) +#define DEFAULT_SPI_BUS_MISO (&pin_PA14) + +#define DEFAULT_UART_BUS_RX (&pin_PA23) +#define DEFAULT_UART_BUS_TX (&pin_PA22) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk new file mode 100644 index 0000000000000..08ead98e934be --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk @@ -0,0 +1,27 @@ +USB_VID = 0x239A +USB_PID = 0x8021 +USB_PRODUCT = "RAPID-0 ADCS" +USB_MANUFACTURER = "Bruin Spacecraft Group" + +CHIP_VARIANT = SAMD51J19A +CHIP_FAMILY = samd51 + +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = "MX25L51245G" +LONGINT_IMPL = MPZ + +CIRCUITPY__EVE = 1 +CIRCUITPY_CANIO = 0 +CIRCUITPY_FLOPPYIO = 0 +CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SYNTHIO = 0 + +# We don't have room for the fonts for terminalio for certain languages, +# so turn off terminalio, and if it's off and displayio is on, +# force a clean build. +# Note that we cannot test $(CIRCUITPY_DISPLAYIO) directly with an +# ifeq, because it's not set yet. +ifneq (,$(filter $(TRANSLATION),ja ko ru)) +CIRCUITPY_TERMINALIO = 0 +RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) +endif diff --git a/ports/atmel-samd/boards/rapid0_adcs/pins.c b/ports/atmel-samd/boards/rapid0_adcs/pins.c new file mode 100644 index 0000000000000..32aaec3865cd3 --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_adcs/pins.c @@ -0,0 +1,74 @@ +#include "shared-bindings/board/__init__.h" + +// This mapping only includes functional names because pins broken +// out on connectors are labeled with their MCU name available from +// microcontroller.pin. +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PC15) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO1_CS), MP_ROM_PTR(&pin_PB19) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO2_CS), MP_ROM_PTR(&pin_PB20) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO3_CS), MP_ROM_PTR(&pin_PB21) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_MAG1), MP_ROM_PTR(&pin_PA02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAG2), MP_ROM_PTR(&pin_PA01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAG3), MP_ROM_PTR(&pin_PA00) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_MAG_SPI_MOSI), MP_ROM_PTR(&pin_PA16) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAG_SPI_MISO), MP_ROM_PTR(&pin_PA18) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAG_SPI_SLCK), MP_ROM_PTR(&pin_PA17) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO_SPI_MOSI), MP_ROM_PTR(&pin_PA12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO_SPI_MISO), MP_ROM_PTR(&pin_PA14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO_SPI_SLCK), MP_ROM_PTR(&pin_PA13) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_MOSI), MP_ROM_PTR(&pin_PB15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_MISO), MP_ROM_PTR(&pin_PB12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_SLCK), MP_ROM_PTR(&pin_PB13) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ADCS_SPI_CS), MP_ROM_PTR(&pin_PB14) }, + + + // { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB08) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB09) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA23) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA23) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA22) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA22) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PB17) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PB16) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB14) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB15) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB12) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA21) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA20) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA17) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA16) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA16) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB02) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB03) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB22) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA12) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA14) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PB06) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PA27) }, + // { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + // { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + // { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/atmel-samd/boards/rapid0_cdh/board.c b/ports/atmel-samd/boards/rapid0_cdh/board.c new file mode 100644 index 0000000000000..fb1ce4fb834f0 --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_cdh/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h new file mode 100644 index 0000000000000..7760bf030add8 --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h @@ -0,0 +1,45 @@ +#define MICROPY_HW_BOARD_NAME "RAPID-0 CDH" +#define MICROPY_HW_MCU_NAME "samd51j19" + +#define CIRCUITPY_MCU_FAMILY samd51 + +// This is for Rev F which is green + +// #define MICROPY_HW_LED_TX (&pin_PA27) +// #define MICROPY_HW_LED_RX (&pin_PB06) + +// #define MICROPY_HW_LED_STATUS (&pin_PA16) + +// #define MICROPY_HW_NEOPIXEL (&pin_PB22) + +#define BOARD_HAS_CRYSTAL 0 + +#define CAMERA_I2C_SCL (&pin_PB03) +#define CAMERA_I2C_SDA (&pin_PB04) + +#define CAMERA_SPI_SCK (&pin_PA05) +#define CAMERA_SPI_MISO (&pin_PA04) +#define CAMERA_SPI_MOSI (&pin_PA07) +#define CAMERA_SPI_CS (&pin_PA06) + +#define INTERSUBSYSTEM_SPI_SCK (&pin_PB17) +#define INTERSUBSYSTEM_SPI_MISO (&pin_PA21) +#define INTERSUBSYSTEM_SPI_MOSI (&pin_PB16) + +#define ADCS_SPI_CS (&pin_PA20) +#define EPS_SPI_CS (&pin_PB00) +#define PAYLOAD_SPI_CS (&pin_PB01) + +// #define DEFAULT_I2C_BUS_SCL (&pin_PB03) +// #define DEFAULT_I2C_BUS_SDA (&pin_PB02) + +// #define DEFAULT_SPI_BUS_SCK (&pin_PA13) +// #define DEFAULT_SPI_BUS_MOSI (&pin_PA12) +// #define DEFAULT_SPI_BUS_MISO (&pin_PA14) + +// #define DEFAULT_UART_BUS_RX (&pin_PA23) +// #define DEFAULT_UART_BUS_TX (&pin_PA22) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk new file mode 100644 index 0000000000000..5cbcd10ea84bd --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk @@ -0,0 +1,27 @@ +USB_VID = 0x239A +USB_PID = 0x8021 +USB_PRODUCT = "RAPID-0 CDH" +USB_MANUFACTURER = "Bruin Spacecraft Group" + +CHIP_VARIANT = SAMD51J19A +CHIP_FAMILY = samd51 + +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = "GD25Q16C" +LONGINT_IMPL = MPZ + +CIRCUITPY__EVE = 1 +CIRCUITPY_CANIO = 0 +CIRCUITPY_FLOPPYIO = 0 +CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SYNTHIO = 0 + +# We don't have room for the fonts for terminalio for certain languages, +# so turn off terminalio, and if it's off and displayio is on, +# force a clean build. +# Note that we cannot test $(CIRCUITPY_DISPLAYIO) directly with an +# ifeq, because it's not set yet. +ifneq (,$(filter $(TRANSLATION),ja ko ru)) +CIRCUITPY_TERMINALIO = 0 +RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) +endif diff --git a/ports/atmel-samd/boards/rapid0_cdh/pins.c b/ports/atmel-samd/boards/rapid0_cdh/pins.c new file mode 100644 index 0000000000000..315b2c39a44cd --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_cdh/pins.c @@ -0,0 +1,66 @@ +#include "shared-bindings/board/__init__.h" + +// This mapping only includes functional names because pins broken +// out on connectors are labeled with their MCU name available from +// microcontroller.pin. +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SCL), MP_ROM_PTR(&pin_PB03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SDA), MP_ROM_PTR(&pin_PB04) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_SCK), MP_ROM_PTR(&pin_PA05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_MISO), MP_ROM_PTR(&pin_PA04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_MOSI), MP_ROM_PTR(&pin_PA07) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_CS), MP_ROM_PTR(&pin_PA06) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_INTERSUBSYSTEM_SPI_SCK), MP_ROM_PTR(&pin_PB17) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_INTERSUBSYSTEM_SPI_MISO), MP_ROM_PTR(&pin_PA21) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_INTERSUBSYSTEM_SPI_MOSI), MP_ROM_PTR(&pin_PB16) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_ADCS_SPI_CS), MP_ROM_PTR(&pin_PA20) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_EPS_SPI_CS), MP_ROM_PTR(&pin_PB00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_PAYLOAD_SPI_CS), MP_ROM_PTR(&pin_PB01) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB08) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB09) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA23) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA23) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA22) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA22) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PB17) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PB16) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB14) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB15) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB12) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA21) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA20) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA17) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA16) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA16) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB02) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB03) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB22) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA12) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA14) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PB06) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PA27) }, + // { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + // { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + // { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/atmel-samd/boards/rapid0_eps/board.c b/ports/atmel-samd/boards/rapid0_eps/board.c new file mode 100644 index 0000000000000..fb1ce4fb834f0 --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_eps/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.h b/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.h new file mode 100644 index 0000000000000..63e75d0ba08d4 --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.h @@ -0,0 +1,29 @@ +#define MICROPY_HW_BOARD_NAME "RAPID-0 EPS" +#define MICROPY_HW_MCU_NAME "samd51j19" + +#define CIRCUITPY_MCU_FAMILY samd51 + +// This is for Rev F which is green + +#define MICROPY_HW_LED_TX (&pin_PA27) +#define MICROPY_HW_LED_RX (&pin_PB06) + +#define MICROPY_HW_LED_STATUS (&pin_PA16) + +#define MICROPY_HW_NEOPIXEL (&pin_PB22) + +#define BOARD_HAS_CRYSTAL 0 + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) + +#define DEFAULT_SPI_BUS_SCK (&pin_PA13) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA12) +#define DEFAULT_SPI_BUS_MISO (&pin_PA14) + +#define DEFAULT_UART_BUS_RX (&pin_PA23) +#define DEFAULT_UART_BUS_TX (&pin_PA22) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk new file mode 100644 index 0000000000000..41a6f5d6dd9ea --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk @@ -0,0 +1,27 @@ +USB_VID = 0x239A +USB_PID = 0x8021 +USB_PRODUCT = "RAPID-0 EPS" +USB_MANUFACTURER = "Bruin Spacecraft Group" + +CHIP_VARIANT = SAMD51J19A +CHIP_FAMILY = samd51 + +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = "GD25Q16C" +LONGINT_IMPL = MPZ + +CIRCUITPY__EVE = 1 +CIRCUITPY_CANIO = 0 +CIRCUITPY_FLOPPYIO = 0 +CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SYNTHIO = 0 + +# We don't have room for the fonts for terminalio for certain languages, +# so turn off terminalio, and if it's off and displayio is on, +# force a clean build. +# Note that we cannot test $(CIRCUITPY_DISPLAYIO) directly with an +# ifeq, because it's not set yet. +ifneq (,$(filter $(TRANSLATION),ja ko ru)) +CIRCUITPY_TERMINALIO = 0 +RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) +endif diff --git a/ports/atmel-samd/boards/rapid0_eps/pins.c b/ports/atmel-samd/boards/rapid0_eps/pins.c new file mode 100644 index 0000000000000..f7e50f645388c --- /dev/null +++ b/ports/atmel-samd/boards/rapid0_eps/pins.c @@ -0,0 +1,50 @@ +#include "shared-bindings/board/__init__.h" + +// This mapping only includes functional names because pins broken +// out on connectors are labeled with their MCU name available from +// microcontroller.pin. +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB08) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB09) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA23) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA23) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA22) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA22) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PB17) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PB16) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB13) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA21) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA20) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA17) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA16) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA16) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB03) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB22) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA13) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA14) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PB06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index 87483f3281fe6..e5e716f6548ee 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit 87483f3281fe6a05c9e66ae62615205f74675c49 +Subproject commit e5e716f6548ee8643952023e3b6c38000cec3f8e From 0ae5be8acc2a82548610665b77b4a28928df8d86 Mon Sep 17 00:00:00 2001 From: Annie Xiang <94214374+anniexiang01@users.noreply.github.com> Date: Tue, 21 May 2024 14:03:54 -0700 Subject: [PATCH 18/55] corrected board family on rapid0_adcs mpconfigboard.mk file --- ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk index 08ead98e934be..c0f98ba40ae16 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk @@ -1,9 +1,9 @@ -USB_VID = 0x239A -USB_PID = 0x8021 +USB_VID = 0x239A # should change as this is adafruit's vendor ID +USB_PID = 0x8021 # similar to above USB_PRODUCT = "RAPID-0 ADCS" USB_MANUFACTURER = "Bruin Spacecraft Group" -CHIP_VARIANT = SAMD51J19A +CHIP_VARIANT = SAMD51N20 CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 From a73df58d34439228aa6614c99b82ce90642abcfb Mon Sep 17 00:00:00 2001 From: anniexiang01 Date: Tue, 21 May 2024 14:40:55 -0700 Subject: [PATCH 19/55] Updated USB VID, PID, and PRODUCT to reflect sublicense given by Microchip --- ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk | 6 +++--- ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk | 6 +++--- ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk index c0f98ba40ae16..bfa955d332ec5 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk @@ -1,6 +1,6 @@ -USB_VID = 0x239A # should change as this is adafruit's vendor ID -USB_PID = 0x8021 # similar to above -USB_PRODUCT = "RAPID-0 ADCS" +USB_VID = 0x04D8 +USB_PID = 0xE5B3 +USB_PRODUCT = "RAPID-0" USB_MANUFACTURER = "Bruin Spacecraft Group" CHIP_VARIANT = SAMD51N20 diff --git a/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk index 5cbcd10ea84bd..2a5e00fb7f1d5 100644 --- a/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk +++ b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.mk @@ -1,6 +1,6 @@ -USB_VID = 0x239A -USB_PID = 0x8021 -USB_PRODUCT = "RAPID-0 CDH" +USB_VID = 0x04D8 +USB_PID = 0xE5B3 +USB_PRODUCT = "RAPID-0" USB_MANUFACTURER = "Bruin Spacecraft Group" CHIP_VARIANT = SAMD51J19A diff --git a/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk index 41a6f5d6dd9ea..2a5e00fb7f1d5 100644 --- a/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk +++ b/ports/atmel-samd/boards/rapid0_eps/mpconfigboard.mk @@ -1,6 +1,6 @@ -USB_VID = 0x239A -USB_PID = 0x8021 -USB_PRODUCT = "RAPID-0 EPS" +USB_VID = 0x04D8 +USB_PID = 0xE5B3 +USB_PRODUCT = "RAPID-0" USB_MANUFACTURER = "Bruin Spacecraft Group" CHIP_VARIANT = SAMD51J19A From d4df61e134576d094f2c57d2e959d1ad435cbd63 Mon Sep 17 00:00:00 2001 From: anniexiang01 Date: Fri, 24 May 2024 13:00:08 -0700 Subject: [PATCH 20/55] updated adcs board files to be based on the bdmicro vina d51, new build scripts to build firmware for rapid0 boards, updated peripherals submodule --- build-rapid0-mac | 18 +++ build-rapid0-ubuntu | 17 ++ ports/atmel-samd/boards/rapid0_adcs/board.c | 2 + .../boards/rapid0_adcs/mpconfigboard.h | 8 +- .../boards/rapid0_adcs/mpconfigboard.mk | 18 +-- ports/atmel-samd/boards/rapid0_adcs/pins.c | 153 +++++++++++++----- ports/atmel-samd/peripherals | 2 +- 7 files changed, 154 insertions(+), 64 deletions(-) create mode 100755 build-rapid0-mac create mode 100644 build-rapid0-ubuntu diff --git a/build-rapid0-mac b/build-rapid0-mac new file mode 100755 index 0000000000000..01fba1bdc1a86 --- /dev/null +++ b/build-rapid0-mac @@ -0,0 +1,18 @@ +if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null; then + true +else + export PATH=/Volumes/Circuit_Python_Case_Sensitive_Disk/bruinspace-circuitpython/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH +fi + +cd ports/atmel-samd +make --debug -j8 BOARD=rapid0_adcs +make --debug -j8 BOARD=rapid0_cdh +make --debug -j8 BOARD=rapid0_eps +cd ../.. + +echo "Compilation complete! Press ^C to confirm and exit." + +while true; do + afplay /System/Library/Sounds/Ping.aiff + sleep 5s +done diff --git a/build-rapid0-ubuntu b/build-rapid0-ubuntu new file mode 100644 index 0000000000000..b2fcec5053f62 --- /dev/null +++ b/build-rapid0-ubuntu @@ -0,0 +1,17 @@ +if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null +then + true +else + export PATH=/mnt/d/Files/Documents/School/UCLA/Organizations/BruinSpace/Rapid-CDH/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH +fi +cd ports/atmel-samd +make --debug -j8 BOARD=rapid0_adcs +make --debug -j8 BOARD=rapid0_cdh +make --debug -j8 BOARD=rapid0_eps +cd ../.. +echo "Compilation complete! Press ^C to confirm and exit." +while true; +do + paplay /usr/share/sounds/freedesktop/stereo/complete.oga + sleep 5s +done \ No newline at end of file diff --git a/ports/atmel-samd/boards/rapid0_adcs/board.c b/ports/atmel-samd/boards/rapid0_adcs/board.c index fb1ce4fb834f0..1bba99ac06573 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/board.c +++ b/ports/atmel-samd/boards/rapid0_adcs/board.c @@ -25,5 +25,7 @@ */ #include "supervisor/board.h" +#include "mpconfigboard.h" +#include "hal/include/hal_gpio.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h index 37ebc23aafe7f..6c35ade3b5c5b 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h @@ -3,7 +3,7 @@ #define CIRCUITPY_MCU_FAMILY samd51 -// This is for Rev F which is green +#define BOARD_HAS_CRYSTAL 0 #define MICROPY_HW_LED_TX (&pin_PA27) #define MICROPY_HW_LED_RX (&pin_PB06) @@ -12,8 +12,6 @@ #define MICROPY_HW_NEOPIXEL (&pin_PB22) -#define BOARD_HAS_CRYSTAL 0 - #define DEFAULT_I2C_BUS_SCL (&pin_PB03) #define DEFAULT_I2C_BUS_SDA (&pin_PB02) @@ -25,5 +23,5 @@ #define DEFAULT_UART_BUS_TX (&pin_PA22) // USB is always used internally so skip the pin objects for it. -#define IGNORE_PIN_PA24 1 -#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk index bfa955d332ec5..c990d0c87ae77 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk @@ -3,25 +3,9 @@ USB_PID = 0xE5B3 USB_PRODUCT = "RAPID-0" USB_MANUFACTURER = "Bruin Spacecraft Group" -CHIP_VARIANT = SAMD51N20 +CHIP_VARIANT = SAMD51N20A CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "MX25L51245G" LONGINT_IMPL = MPZ - -CIRCUITPY__EVE = 1 -CIRCUITPY_CANIO = 0 -CIRCUITPY_FLOPPYIO = 0 -CIRCUITPY_JPEGIO = 0 -CIRCUITPY_SYNTHIO = 0 - -# We don't have room for the fonts for terminalio for certain languages, -# so turn off terminalio, and if it's off and displayio is on, -# force a clean build. -# Note that we cannot test $(CIRCUITPY_DISPLAYIO) directly with an -# ifeq, because it's not set yet. -ifneq (,$(filter $(TRANSLATION),ja ko ru)) -CIRCUITPY_TERMINALIO = 0 -RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) -endif diff --git a/ports/atmel-samd/boards/rapid0_adcs/pins.c b/ports/atmel-samd/boards/rapid0_adcs/pins.c index 32aaec3865cd3..45d23f5042627 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/pins.c +++ b/ports/atmel-samd/boards/rapid0_adcs/pins.c @@ -1,8 +1,8 @@ +// More than one revision of this board is available. +// This board specifies the most up to date PCB Revision + #include "shared-bindings/board/__init__.h" -// This mapping only includes functional names because pins broken -// out on connectors are labeled with their MCU name available from -// microcontroller.pin. STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS @@ -29,44 +29,115 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_SLCK), MP_ROM_PTR(&pin_PB13) }, { MP_OBJ_NEW_QSTR(MP_QSTR_ADCS_SPI_CS), MP_ROM_PTR(&pin_PB14) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB08) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB09) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA23) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA23) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA22) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA22) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PB17) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PB16) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB13) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB14) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB15) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB12) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA21) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA20) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA17) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA16) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA16) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB02) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB03) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB22) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA13) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA12) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA14) }, - - // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PB06) }, - // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PA27) }, + // { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA04) }, + // { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA06) }, + // { MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_PB07) }, + // { MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PC00) }, + // { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA07) }, + // { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PB08) }, + // { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB09) }, + // { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PC02) }, + // { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PC03) }, + // { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PB04) }, + // { MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_PB05) }, + // { MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_PB06) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_1), MP_ROM_PTR(&pin_PA17) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_UART_TX), MP_ROM_PTR(&pin_PA17) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_MOSI), MP_ROM_PTR(&pin_PA17) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_I2C_SDA), MP_ROM_PTR(&pin_PA17) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_MOSI), MP_ROM_PTR(&pin_PA17) }, + // { MP_ROM_QSTR(MP_QSTR_ESP01_TX), MP_ROM_PTR(&pin_PA17) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_10), MP_ROM_PTR(&pin_PC01) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_IRQ), MP_ROM_PTR(&pin_PC01) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_11), MP_ROM_PTR(&pin_PC10) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_GPIO_3), MP_ROM_PTR(&pin_PC10) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_12), MP_ROM_PTR(&pin_PC11) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_GPIO_1), MP_ROM_PTR(&pin_PC11) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_3), MP_ROM_PTR(&pin_PA18) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_UART_RTS), MP_ROM_PTR(&pin_PA18) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_SS), MP_ROM_PTR(&pin_PA18) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_SS), MP_ROM_PTR(&pin_PA18) }, + // { MP_ROM_QSTR(MP_QSTR_ESP01_GPIO0), MP_ROM_PTR(&pin_PA18) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_4), MP_ROM_PTR(&pin_PC14) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_RESET), MP_ROM_PTR(&pin_PC14) }, + // { MP_ROM_QSTR(MP_QSTR_ESP01_RESET), MP_ROM_PTR(&pin_PC14) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_5), MP_ROM_PTR(&pin_PA19) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_UART_CTS), MP_ROM_PTR(&pin_PA19) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_MISO), MP_ROM_PTR(&pin_PA19) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_MISO), MP_ROM_PTR(&pin_PA19) }, + // { MP_ROM_QSTR(MP_QSTR_ESP01_GPIO2), MP_ROM_PTR(&pin_PA19) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_6), MP_ROM_PTR(&pin_PC15) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_EN), MP_ROM_PTR(&pin_PC15) }, + // { MP_ROM_QSTR(MP_QSTR_ESP01_CH_PD), MP_ROM_PTR(&pin_PC15) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_8), MP_ROM_PTR(&pin_PA16) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_UART_RX), MP_ROM_PTR(&pin_PA16) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_SCK), MP_ROM_PTR(&pin_PA16) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_I2C_SCL), MP_ROM_PTR(&pin_PA16) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_SCK), MP_ROM_PTR(&pin_PA16) }, + // { MP_ROM_QSTR(MP_QSTR_ESP01_RX), MP_ROM_PTR(&pin_PA16) }, + // { MP_ROM_QSTR(MP_QSTR_AUX_9), MP_ROM_PTR(&pin_PA27) }, + // { MP_ROM_QSTR(MP_QSTR_ATW01_WAKE), MP_ROM_PTR(&pin_PA27) }, + // { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PB31) }, + // { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PC16) }, + // { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PC13) }, + // { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA14) }, + // { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA15) }, + // { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB12) }, + // { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PB13) }, + // { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA21) }, + // { MP_ROM_QSTR(MP_QSTR_I2S_SDO), MP_ROM_PTR(&pin_PA21) }, + // { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_PA22) }, + // { MP_ROM_QSTR(MP_QSTR_I2S_SDI), MP_ROM_PTR(&pin_PA22) }, + // { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_PA20) }, + // { MP_ROM_QSTR(MP_QSTR_I2S_FS_0), MP_ROM_PTR(&pin_PA20) }, + // { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_PB16) }, + // { MP_ROM_QSTR(MP_QSTR_I2S_SCK_0), MP_ROM_PTR(&pin_PB16) }, + // { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_PB17) }, + // { MP_ROM_QSTR(MP_QSTR_I2S_MCK_0), MP_ROM_PTR(&pin_PB17) }, + // { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PC17) }, + // { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PC18) }, + // { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PC19) }, + // { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PC20) }, + // { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PC21) }, + // { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB18) }, + // { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PB19) }, + // { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PC12) }, + // { MP_ROM_QSTR(MP_QSTR_DAC0), MP_ROM_PTR(&pin_PA02) }, + // { MP_ROM_QSTR(MP_QSTR_DAC1), MP_ROM_PTR(&pin_PA05) }, + // { MP_ROM_QSTR(MP_QSTR_I2C1_SCL), MP_ROM_PTR(&pin_PA12) }, + // { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA12) }, + // { MP_ROM_QSTR(MP_QSTR_I2C1_SDA), MP_ROM_PTR(&pin_PA13) }, + // { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA13) }, + // { MP_ROM_QSTR(MP_QSTR_LED_AUX), MP_ROM_PTR(&pin_PC26) }, + // { MP_ROM_QSTR(MP_QSTR_LED_B), MP_ROM_PTR(&pin_PA23) }, + // { MP_ROM_QSTR(MP_QSTR_LED_STATUS), MP_ROM_PTR(&pin_PA23) }, + // { MP_ROM_QSTR(MP_QSTR_LED_G), MP_ROM_PTR(&pin_PB15) }, + // { MP_ROM_QSTR(MP_QSTR_LED_QSPI), MP_ROM_PTR(&pin_PC07) }, + // { MP_ROM_QSTR(MP_QSTR_LED_R), MP_ROM_PTR(&pin_PB14) }, + // { MP_ROM_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PC05) }, + // { MP_ROM_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PC06) }, + // { MP_ROM_QSTR(MP_QSTR_RS485_RE), MP_ROM_PTR(&pin_PB01) }, + // { MP_ROM_QSTR(MP_QSTR_RS485_RX), MP_ROM_PTR(&pin_PB03) }, + // { MP_ROM_QSTR(MP_QSTR_RS485_TE), MP_ROM_PTR(&pin_PB00) }, + // { MP_ROM_QSTR(MP_QSTR_RS485_TX), MP_ROM_PTR(&pin_PB02) }, + // { MP_ROM_QSTR(MP_QSTR_SPI1_MISO), MP_ROM_PTR(&pin_PB23) }, + // { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PB23) }, + // { MP_ROM_QSTR(MP_QSTR_SPI1_MOSI), MP_ROM_PTR(&pin_PC27) }, + // { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PC27) }, + // { MP_ROM_QSTR(MP_QSTR_SPI1_SCK), MP_ROM_PTR(&pin_PC28) }, + // { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PC28) }, + // { MP_ROM_QSTR(MP_QSTR_SPI1_SS), MP_ROM_PTR(&pin_PB22) }, + // { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PB22) }, + // { MP_ROM_QSTR(MP_QSTR_UART1_CTS), MP_ROM_PTR(&pin_PC25) }, + // { MP_ROM_QSTR(MP_QSTR_UART1_RTS), MP_ROM_PTR(&pin_PC24) }, + // { MP_ROM_QSTR(MP_QSTR_UART1_RX), MP_ROM_PTR(&pin_PB24) }, + // { MP_ROM_QSTR(MP_QSTR_UART1_TX), MP_ROM_PTR(&pin_PB25) }, + // { MP_ROM_QSTR(MP_QSTR_UART2_RX), MP_ROM_PTR(&pin_PB20) }, + // { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB20) }, + // { MP_ROM_QSTR(MP_QSTR_I2C2_SCL), MP_ROM_PTR(&pin_PB20) }, + // { MP_ROM_QSTR(MP_QSTR_UART2_TX), MP_ROM_PTR(&pin_PB21) }, + // { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB21) }, + // { MP_ROM_QSTR(MP_QSTR_I2C2_SDA), MP_ROM_PTR(&pin_PB21) }, // { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, // { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, // { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index e5e716f6548ee..fd82c8b829b8d 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit e5e716f6548ee8643952023e3b6c38000cec3f8e +Subproject commit fd82c8b829b8d72eb0e45de16ac9db43a77ac764 From dcc97d7353e12a627e063e7539920b1d4282c609 Mon Sep 17 00:00:00 2001 From: anniexiang01 Date: Sat, 25 May 2024 01:50:56 -0700 Subject: [PATCH 21/55] fixed rapid0-cdh pin error --- ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h | 2 +- ports/atmel-samd/boards/rapid0_cdh/pins.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h index 7760bf030add8..941074a8f08ca 100644 --- a/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h +++ b/ports/atmel-samd/boards/rapid0_cdh/mpconfigboard.h @@ -15,7 +15,7 @@ #define BOARD_HAS_CRYSTAL 0 #define CAMERA_I2C_SCL (&pin_PB03) -#define CAMERA_I2C_SDA (&pin_PB04) +#define CAMERA_I2C_SDA (&pin_PB02) #define CAMERA_SPI_SCK (&pin_PA05) #define CAMERA_SPI_MISO (&pin_PA04) diff --git a/ports/atmel-samd/boards/rapid0_cdh/pins.c b/ports/atmel-samd/boards/rapid0_cdh/pins.c index 315b2c39a44cd..388b988a8f424 100644 --- a/ports/atmel-samd/boards/rapid0_cdh/pins.c +++ b/ports/atmel-samd/boards/rapid0_cdh/pins.c @@ -7,7 +7,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SCL), MP_ROM_PTR(&pin_PB03) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SDA), MP_ROM_PTR(&pin_PB04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SDA), MP_ROM_PTR(&pin_PB02) }, { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_SCK), MP_ROM_PTR(&pin_PA05) }, { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_MISO), MP_ROM_PTR(&pin_PA04) }, From 14136fc67adff23f4b45950db962b823137a2910 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sat, 29 Jun 2024 22:47:34 -0700 Subject: [PATCH 22/55] restore metro_m4_express configuration --- ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h | 2 +- ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h index 722a737786f48..3b9ca9666988b 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h @@ -12,7 +12,7 @@ #define MICROPY_HW_NEOPIXEL (&pin_PB22) -#define BOARD_HAS_CRYSTAL 0 +#define BOARD_HAS_CRYSTAL 1 #define DEFAULT_I2C_BUS_SCL (&pin_PB03) #define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk index e44bc7fcb81dc..4f01c141e4849 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk @@ -11,7 +11,6 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ" LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 -CIRCUITPY_CANIO = 0 CIRCUITPY_FLOPPYIO = 0 CIRCUITPY_JPEGIO = 0 CIRCUITPY_SYNTHIO = 0 From 555f1a3f35a9c9f64ae539a2a97ba6fe8aba672a Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sat, 29 Jun 2024 23:04:44 -0700 Subject: [PATCH 23/55] remove extraneous build files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9cb1e9ea5e497..04c580cd77c7e 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ bin/ circuitpython-stubs/ test-stubs/ build-*/ +build-* # Test failure outputs ###################### From d0486671d5df26cbcddb91093019cc970856e755 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sat, 29 Jun 2024 23:29:31 -0700 Subject: [PATCH 24/55] remove extraneous build files --- build-samd51-interpreter | 15 --------------- build-samd51-interpreter-mac | 16 ---------------- 2 files changed, 31 deletions(-) delete mode 100644 build-samd51-interpreter delete mode 100755 build-samd51-interpreter-mac diff --git a/build-samd51-interpreter b/build-samd51-interpreter deleted file mode 100644 index c5ee30dadd739..0000000000000 --- a/build-samd51-interpreter +++ /dev/null @@ -1,15 +0,0 @@ -if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null -then - true -else - export PATH=/mnt/d/Files/Documents/School/UCLA/Organizations/BruinSpace/Rapid-CDH/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH -fi -cd ports/atmel-samd -make --debug -j8 BOARD=metro_m4_express -cd ../.. -echo "Compilation complete! Press ^C to confirm and exit." -while true; -do - paplay /usr/share/sounds/freedesktop/stereo/complete.oga - sleep 5s -done \ No newline at end of file diff --git a/build-samd51-interpreter-mac b/build-samd51-interpreter-mac deleted file mode 100755 index e71493182523d..0000000000000 --- a/build-samd51-interpreter-mac +++ /dev/null @@ -1,16 +0,0 @@ -if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null; then - true -else - export PATH=/Volumes/Circuit_Python_Case_Sensitive_Disk/bruinspace-circuitpython/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH -fi - -cd ports/atmel-samd -make --debug -j8 BOARD=metro_m4_express -cd ../.. - -echo "Compilation complete! Press ^C to confirm and exit." - -while true; do - afplay /System/Library/Sounds/Ping.aiff - sleep 5s -done From 4696d07c5d373aba75db6a4fb0eb01fc3d0d04c6 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sat, 27 Jul 2024 21:45:38 -0700 Subject: [PATCH 25/55] set SPI drive strength to high --- ports/atmel-samd/common-hal/busio/SPI.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index d80fc3dd79f89..116a239e30916 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -218,6 +218,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); gpio_set_pin_function(clock->number, clock_pinmux); claim_pin(clock); + hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(clock->number), GPIO_PIN(clock->number)); self->clock_pin = clock->number; if (mosi_none) { @@ -228,6 +229,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, gpio_set_pin_function(mosi->number, mosi_pinmux); self->MOSI_pin = mosi->number; claim_pin(mosi); + hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(mosi->number), GPIO_PIN(mosi->number)); } if (miso_none) { @@ -238,6 +240,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, gpio_set_pin_function(miso->number, miso_pinmux); self->MISO_pin = miso->number; claim_pin(miso); + hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(miso->number), GPIO_PIN(miso->number)); } if (slave_mode) { @@ -246,6 +249,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, gpio_set_pin_function(ss->number, ss_pinmux); self->SS_pin = ss->number; claim_pin(ss); + hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(ss->number), GPIO_PIN(ss->number)); } self->running_dma.failure = 1; // not started From 1fc4d72789c88f5155818926ad990d61c0cd1630 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Thu, 17 Oct 2024 23:14:56 -0700 Subject: [PATCH 26/55] haha! adcs works now --- ports/atmel-samd/boards/rapid0_adcs/board.c | 2 - .../boards/rapid0_adcs/mpconfigboard.h | 44 +++-- .../boards/rapid0_adcs/mpconfigboard.mk | 18 +- ports/atmel-samd/boards/rapid0_adcs/pins.c | 179 +++++------------- 4 files changed, 98 insertions(+), 145 deletions(-) diff --git a/ports/atmel-samd/boards/rapid0_adcs/board.c b/ports/atmel-samd/boards/rapid0_adcs/board.c index 1bba99ac06573..fb1ce4fb834f0 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/board.c +++ b/ports/atmel-samd/boards/rapid0_adcs/board.c @@ -25,7 +25,5 @@ */ #include "supervisor/board.h" -#include "mpconfigboard.h" -#include "hal/include/hal_gpio.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h index 6c35ade3b5c5b..cfecca3164d56 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.h @@ -3,25 +3,43 @@ #define CIRCUITPY_MCU_FAMILY samd51 +// This is for Rev F which is green + +// #define MICROPY_HW_LED_TX (&pin_PA27) +// #define MICROPY_HW_LED_RX (&pin_PB06) + +// #define MICROPY_HW_LED_STATUS (&pin_PA16) + +// #define MICROPY_HW_NEOPIXEL (&pin_PB22) + #define BOARD_HAS_CRYSTAL 0 -#define MICROPY_HW_LED_TX (&pin_PA27) -#define MICROPY_HW_LED_RX (&pin_PB06) +#define CAMERA_I2C_SCL (&pin_PB03) +#define CAMERA_I2C_SDA (&pin_PB02) + +#define CAMERA_SPI_SCK (&pin_PA05) +#define CAMERA_SPI_MISO (&pin_PA04) +#define CAMERA_SPI_MOSI (&pin_PA07) +#define CAMERA_SPI_CS (&pin_PA06) -#define MICROPY_HW_LED_STATUS (&pin_PA16) +#define INTERSUBSYSTEM_SPI_SCK (&pin_PB17) +#define INTERSUBSYSTEM_SPI_MISO (&pin_PA21) +#define INTERSUBSYSTEM_SPI_MOSI (&pin_PB16) -#define MICROPY_HW_NEOPIXEL (&pin_PB22) +#define ADCS_SPI_CS (&pin_PA20) +#define EPS_SPI_CS (&pin_PB00) +#define PAYLOAD_SPI_CS (&pin_PB01) -#define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) +// #define DEFAULT_I2C_BUS_SCL (&pin_PB03) +// #define DEFAULT_I2C_BUS_SDA (&pin_PB02) -#define DEFAULT_SPI_BUS_SCK (&pin_PA13) -#define DEFAULT_SPI_BUS_MOSI (&pin_PA12) -#define DEFAULT_SPI_BUS_MISO (&pin_PA14) +// #define DEFAULT_SPI_BUS_SCK (&pin_PA13) +// #define DEFAULT_SPI_BUS_MOSI (&pin_PA12) +// #define DEFAULT_SPI_BUS_MISO (&pin_PA14) -#define DEFAULT_UART_BUS_RX (&pin_PA23) -#define DEFAULT_UART_BUS_TX (&pin_PA22) +// #define DEFAULT_UART_BUS_RX (&pin_PA23) +// #define DEFAULT_UART_BUS_TX (&pin_PA22) // USB is always used internally so skip the pin objects for it. -#define IGNORE_PIN_PA24 1 -#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk index c990d0c87ae77..a7b18c7f14b3b 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk +++ b/ports/atmel-samd/boards/rapid0_adcs/mpconfigboard.mk @@ -7,5 +7,21 @@ CHIP_VARIANT = SAMD51N20A CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 -EXTERNAL_FLASH_DEVICES = "MX25L51245G" +EXTERNAL_FLASH_DEVICES = "GD25Q16C" LONGINT_IMPL = MPZ + +CIRCUITPY__EVE = 1 +CIRCUITPY_CANIO = 0 +CIRCUITPY_FLOPPYIO = 0 +CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SYNTHIO = 0 + +# We don't have room for the fonts for terminalio for certain languages, +# so turn off terminalio, and if it's off and displayio is on, +# force a clean build. +# Note that we cannot test $(CIRCUITPY_DISPLAYIO) directly with an +# ifeq, because it's not set yet. +ifneq (,$(filter $(TRANSLATION),ja ko ru)) +CIRCUITPY_TERMINALIO = 0 +RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) +endif diff --git a/ports/atmel-samd/boards/rapid0_adcs/pins.c b/ports/atmel-samd/boards/rapid0_adcs/pins.c index 45d23f5042627..388b988a8f424 100644 --- a/ports/atmel-samd/boards/rapid0_adcs/pins.c +++ b/ports/atmel-samd/boards/rapid0_adcs/pins.c @@ -1,143 +1,64 @@ -// More than one revision of this board is available. -// This board specifies the most up to date PCB Revision - #include "shared-bindings/board/__init__.h" +// This mapping only includes functional names because pins broken +// out on connectors are labeled with their MCU name available from +// microcontroller.pin. STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PC15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SCL), MP_ROM_PTR(&pin_PB03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_I2C_SDA), MP_ROM_PTR(&pin_PB02) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_SCK), MP_ROM_PTR(&pin_PA05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_MISO), MP_ROM_PTR(&pin_PA04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_MOSI), MP_ROM_PTR(&pin_PA07) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CAMERA_SPI_CS), MP_ROM_PTR(&pin_PA06) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_INTERSUBSYSTEM_SPI_SCK), MP_ROM_PTR(&pin_PB17) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_INTERSUBSYSTEM_SPI_MISO), MP_ROM_PTR(&pin_PA21) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_INTERSUBSYSTEM_SPI_MOSI), MP_ROM_PTR(&pin_PB16) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_ADCS_SPI_CS), MP_ROM_PTR(&pin_PA20) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_EPS_SPI_CS), MP_ROM_PTR(&pin_PB00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_PAYLOAD_SPI_CS), MP_ROM_PTR(&pin_PB01) }, + + // { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB08) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB09) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO1_CS), MP_ROM_PTR(&pin_PB19) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO2_CS), MP_ROM_PTR(&pin_PB20) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO3_CS), MP_ROM_PTR(&pin_PB21) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA23) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA23) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA22) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA22) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PB17) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PB16) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB14) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB15) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB12) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA21) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA20) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA17) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MAG1), MP_ROM_PTR(&pin_PA02) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MAG2), MP_ROM_PTR(&pin_PA01) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MAG3), MP_ROM_PTR(&pin_PA00) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA16) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA16) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MAG_SPI_MOSI), MP_ROM_PTR(&pin_PA16) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MAG_SPI_MISO), MP_ROM_PTR(&pin_PA18) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MAG_SPI_SLCK), MP_ROM_PTR(&pin_PA17) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB02) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB03) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO_SPI_MOSI), MP_ROM_PTR(&pin_PA12) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO_SPI_MISO), MP_ROM_PTR(&pin_PA14) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_GYRO_SPI_SLCK), MP_ROM_PTR(&pin_PA13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB22) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_MOSI), MP_ROM_PTR(&pin_PB15) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_MISO), MP_ROM_PTR(&pin_PB12) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_CDH_SPI_SLCK), MP_ROM_PTR(&pin_PB13) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ADCS_SPI_CS), MP_ROM_PTR(&pin_PB14) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA13) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA12) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA14) }, - // { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA04) }, - // { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA06) }, - // { MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_PB07) }, - // { MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PC00) }, - // { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA07) }, - // { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PB08) }, - // { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB09) }, - // { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PC02) }, - // { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PC03) }, - // { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PB04) }, - // { MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_PB05) }, - // { MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_PB06) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_1), MP_ROM_PTR(&pin_PA17) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_UART_TX), MP_ROM_PTR(&pin_PA17) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_MOSI), MP_ROM_PTR(&pin_PA17) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_I2C_SDA), MP_ROM_PTR(&pin_PA17) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_MOSI), MP_ROM_PTR(&pin_PA17) }, - // { MP_ROM_QSTR(MP_QSTR_ESP01_TX), MP_ROM_PTR(&pin_PA17) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_10), MP_ROM_PTR(&pin_PC01) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_IRQ), MP_ROM_PTR(&pin_PC01) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_11), MP_ROM_PTR(&pin_PC10) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_GPIO_3), MP_ROM_PTR(&pin_PC10) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_12), MP_ROM_PTR(&pin_PC11) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_GPIO_1), MP_ROM_PTR(&pin_PC11) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_3), MP_ROM_PTR(&pin_PA18) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_UART_RTS), MP_ROM_PTR(&pin_PA18) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_SS), MP_ROM_PTR(&pin_PA18) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_SS), MP_ROM_PTR(&pin_PA18) }, - // { MP_ROM_QSTR(MP_QSTR_ESP01_GPIO0), MP_ROM_PTR(&pin_PA18) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_4), MP_ROM_PTR(&pin_PC14) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_RESET), MP_ROM_PTR(&pin_PC14) }, - // { MP_ROM_QSTR(MP_QSTR_ESP01_RESET), MP_ROM_PTR(&pin_PC14) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_5), MP_ROM_PTR(&pin_PA19) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_UART_CTS), MP_ROM_PTR(&pin_PA19) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_MISO), MP_ROM_PTR(&pin_PA19) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_MISO), MP_ROM_PTR(&pin_PA19) }, - // { MP_ROM_QSTR(MP_QSTR_ESP01_GPIO2), MP_ROM_PTR(&pin_PA19) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_6), MP_ROM_PTR(&pin_PC15) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_EN), MP_ROM_PTR(&pin_PC15) }, - // { MP_ROM_QSTR(MP_QSTR_ESP01_CH_PD), MP_ROM_PTR(&pin_PC15) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_8), MP_ROM_PTR(&pin_PA16) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_UART_RX), MP_ROM_PTR(&pin_PA16) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_SPI_SCK), MP_ROM_PTR(&pin_PA16) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_I2C_SCL), MP_ROM_PTR(&pin_PA16) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_SCK), MP_ROM_PTR(&pin_PA16) }, - // { MP_ROM_QSTR(MP_QSTR_ESP01_RX), MP_ROM_PTR(&pin_PA16) }, - // { MP_ROM_QSTR(MP_QSTR_AUX_9), MP_ROM_PTR(&pin_PA27) }, - // { MP_ROM_QSTR(MP_QSTR_ATW01_WAKE), MP_ROM_PTR(&pin_PA27) }, - // { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PB31) }, - // { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PC16) }, - // { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PC13) }, - // { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA14) }, - // { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA15) }, - // { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB12) }, - // { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PB13) }, - // { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA21) }, - // { MP_ROM_QSTR(MP_QSTR_I2S_SDO), MP_ROM_PTR(&pin_PA21) }, - // { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_PA22) }, - // { MP_ROM_QSTR(MP_QSTR_I2S_SDI), MP_ROM_PTR(&pin_PA22) }, - // { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_PA20) }, - // { MP_ROM_QSTR(MP_QSTR_I2S_FS_0), MP_ROM_PTR(&pin_PA20) }, - // { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_PB16) }, - // { MP_ROM_QSTR(MP_QSTR_I2S_SCK_0), MP_ROM_PTR(&pin_PB16) }, - // { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_PB17) }, - // { MP_ROM_QSTR(MP_QSTR_I2S_MCK_0), MP_ROM_PTR(&pin_PB17) }, - // { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PC17) }, - // { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PC18) }, - // { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PC19) }, - // { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PC20) }, - // { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PC21) }, - // { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB18) }, - // { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PB19) }, - // { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PC12) }, - // { MP_ROM_QSTR(MP_QSTR_DAC0), MP_ROM_PTR(&pin_PA02) }, - // { MP_ROM_QSTR(MP_QSTR_DAC1), MP_ROM_PTR(&pin_PA05) }, - // { MP_ROM_QSTR(MP_QSTR_I2C1_SCL), MP_ROM_PTR(&pin_PA12) }, - // { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA12) }, - // { MP_ROM_QSTR(MP_QSTR_I2C1_SDA), MP_ROM_PTR(&pin_PA13) }, - // { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA13) }, - // { MP_ROM_QSTR(MP_QSTR_LED_AUX), MP_ROM_PTR(&pin_PC26) }, - // { MP_ROM_QSTR(MP_QSTR_LED_B), MP_ROM_PTR(&pin_PA23) }, - // { MP_ROM_QSTR(MP_QSTR_LED_STATUS), MP_ROM_PTR(&pin_PA23) }, - // { MP_ROM_QSTR(MP_QSTR_LED_G), MP_ROM_PTR(&pin_PB15) }, - // { MP_ROM_QSTR(MP_QSTR_LED_QSPI), MP_ROM_PTR(&pin_PC07) }, - // { MP_ROM_QSTR(MP_QSTR_LED_R), MP_ROM_PTR(&pin_PB14) }, - // { MP_ROM_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PC05) }, - // { MP_ROM_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PC06) }, - // { MP_ROM_QSTR(MP_QSTR_RS485_RE), MP_ROM_PTR(&pin_PB01) }, - // { MP_ROM_QSTR(MP_QSTR_RS485_RX), MP_ROM_PTR(&pin_PB03) }, - // { MP_ROM_QSTR(MP_QSTR_RS485_TE), MP_ROM_PTR(&pin_PB00) }, - // { MP_ROM_QSTR(MP_QSTR_RS485_TX), MP_ROM_PTR(&pin_PB02) }, - // { MP_ROM_QSTR(MP_QSTR_SPI1_MISO), MP_ROM_PTR(&pin_PB23) }, - // { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PB23) }, - // { MP_ROM_QSTR(MP_QSTR_SPI1_MOSI), MP_ROM_PTR(&pin_PC27) }, - // { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PC27) }, - // { MP_ROM_QSTR(MP_QSTR_SPI1_SCK), MP_ROM_PTR(&pin_PC28) }, - // { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PC28) }, - // { MP_ROM_QSTR(MP_QSTR_SPI1_SS), MP_ROM_PTR(&pin_PB22) }, - // { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PB22) }, - // { MP_ROM_QSTR(MP_QSTR_UART1_CTS), MP_ROM_PTR(&pin_PC25) }, - // { MP_ROM_QSTR(MP_QSTR_UART1_RTS), MP_ROM_PTR(&pin_PC24) }, - // { MP_ROM_QSTR(MP_QSTR_UART1_RX), MP_ROM_PTR(&pin_PB24) }, - // { MP_ROM_QSTR(MP_QSTR_UART1_TX), MP_ROM_PTR(&pin_PB25) }, - // { MP_ROM_QSTR(MP_QSTR_UART2_RX), MP_ROM_PTR(&pin_PB20) }, - // { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB20) }, - // { MP_ROM_QSTR(MP_QSTR_I2C2_SCL), MP_ROM_PTR(&pin_PB20) }, - // { MP_ROM_QSTR(MP_QSTR_UART2_TX), MP_ROM_PTR(&pin_PB21) }, - // { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB21) }, - // { MP_ROM_QSTR(MP_QSTR_I2C2_SDA), MP_ROM_PTR(&pin_PB21) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), MP_ROM_PTR(&pin_PB06) }, + // { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), MP_ROM_PTR(&pin_PA27) }, // { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, // { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, // { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, From 2ba0b563b9370a91c2f25c01bed0c74b7b65ab3f Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Wed, 30 Oct 2024 18:43:22 -0700 Subject: [PATCH 27/55] add annie's new rapid-0 firmware build workflow --- .github/workflows/build-rapid-0.yaml | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/build-rapid-0.yaml diff --git a/.github/workflows/build-rapid-0.yaml b/.github/workflows/build-rapid-0.yaml new file mode 100644 index 0000000000000..c36407914e7ad --- /dev/null +++ b/.github/workflows/build-rapid-0.yaml @@ -0,0 +1,53 @@ +name: Build RAPID-0 Boards + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + board: [rapid0_adcs, rapid0_cdh, rapid0_eps] + steps: + - name: Set up repository + uses: actions/checkout@v4 + with: + submodules: false + show-progress: false + fetch-depth: 1 + - name: Set up python + uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Set up ports + id: set-up-port + uses: ./.github/actions/deps/ports + with: + board: ${{ matrix.board }} + - name: Set up submodules + id: set-up-submodules + uses: ./.github/actions/deps/submodules + with: + action: cache + version: true + - name: Set up external + uses: ./.github/actions/deps/external + with: + action: cache + port: ${{ steps.set-up-port.outputs.port }} + - name: Set up mpy-cross + if: steps.set-up-submodules.outputs.frozen == 'True' + uses: ./.github/actions/mpy_cross + with: + cp-version: ${{ steps.set-up-submodules.outputs.version }} + download: false + - name: Build boards + run: make -j4 -C ports/atmel-samd BOARD=${{ matrix.board }} + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.board }} + path: ports/atmel-samd/build-${{ matrix.board }}/firmware.* + overwrite: true + From a7b3de416a279aeaa41b7ae7e735f69caf445e77 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Thu, 31 Oct 2024 19:20:43 -0700 Subject: [PATCH 28/55] add SPITarget interface (HAL still unimplemented) --- docs/porting.rst | 1 + .../boards/winterbloom_sol/mpconfigboard.mk | 1 - .../common-hal/spitarget/SPITarget.c | 257 ++++++++++++++++++ .../common-hal/spitarget/SPITarget.h | 45 +++ .../common-hal/spitarget/__init__.c | 1 + ports/atmel-samd/mpconfigport.mk | 2 + py/circuitpy_defns.mk | 5 + py/circuitpy_mpconfig.mk | 3 + shared-bindings/spitarget/SPITarget.c | 207 ++++++++++++++ shared-bindings/spitarget/SPITarget.h | 47 ++++ shared-bindings/spitarget/__init__.c | 40 +++ 11 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 ports/atmel-samd/common-hal/spitarget/SPITarget.c create mode 100644 ports/atmel-samd/common-hal/spitarget/SPITarget.h create mode 100644 ports/atmel-samd/common-hal/spitarget/__init__.c create mode 100644 shared-bindings/spitarget/SPITarget.c create mode 100644 shared-bindings/spitarget/SPITarget.h create mode 100644 shared-bindings/spitarget/__init__.c diff --git a/docs/porting.rst b/docs/porting.rst index f4ed2ab4cc86e..9cb28b7e5d4ac 100644 --- a/docs/porting.rst +++ b/docs/porting.rst @@ -72,6 +72,7 @@ as a natural "TODO" list. An example minimal build list is shown below: CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_I2CTARGET = 0 + CIRCUITPY_SPITARGET = 0 # Requires SPI, PulseIO (stub ok): CIRCUITPY_DISPLAYIO = 0 diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk index 17638a0ebd181..a364a2ee01205 100644 --- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk @@ -22,7 +22,6 @@ CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_KEYPAD = 0 -CIRCUITPY_I2CTARGET = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_PS2IO = 0 diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c new file mode 100644 index 0000000000000..c7d9973897fb4 --- /dev/null +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -0,0 +1,257 @@ +// /* +// * This file is part of the MicroPython project, http://micropython.org/ +// * +// * The MIT License (MIT) +// * +// * Copyright (c) 2018 Noralf Trønnes +// * +// * Permission is hereby granted, free of charge, to any person obtaining a copy +// * of this software and associated documentation files (the "Software"), to deal +// * in the Software without restriction, including without limitation the rights +// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// * copies of the Software, and to permit persons to whom the Software is +// * furnished to do so, subject to the following conditions: +// * +// * The above copyright notice and this permission notice shall be included in +// * all copies or substantial portions of the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// * THE SOFTWARE. +// */ + +// #include "shared-bindings/i2ctarget/I2CTarget.h" +// #include "shared-bindings/microcontroller/Pin.h" +// #include "common-hal/busio/I2C.h" + +// #include "shared/runtime/interrupt_char.h" +// #include "py/mperrno.h" +// #include "py/mphal.h" +// #include "py/runtime.h" + +// #include "hal/include/hal_gpio.h" +// #include "peripherals/samd/sercom.h" + +// void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self, +// const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, +// uint8_t *addresses, unsigned int num_addresses, bool smbus) { +// uint8_t sercom_index; +// uint32_t sda_pinmux, scl_pinmux; +// Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); +// if (sercom == NULL) { +// raise_ValueError_invalid_pins(); +// } +// self->sercom = sercom; + +// gpio_set_pin_function(sda->number, GPIO_PIN_FUNCTION_OFF); +// gpio_set_pin_function(scl->number, GPIO_PIN_FUNCTION_OFF); +// gpio_set_pin_function(sda->number, sda_pinmux); +// gpio_set_pin_function(scl->number, scl_pinmux); + +// self->sda_pin = sda->number; +// self->scl_pin = scl->number; +// claim_pin(sda); +// claim_pin(scl); + +// samd_peripherals_sercom_clock_init(sercom, sercom_index); + +// #ifdef SAM_D5X_E5X +// sercom->I2CS.CTRLC.bit.SDASETUP = 0x08; +// #endif + +// sercom->I2CS.CTRLA.bit.SWRST = 1; +// while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) { +// } + +// sercom->I2CS.CTRLB.bit.AACKEN = 0; // Automatic acknowledge is disabled. + +// if (num_addresses == 1) { +// sercom->I2CS.CTRLB.bit.AMODE = 0x0; // MASK +// sercom->I2CS.ADDR.bit.ADDR = addresses[0]; +// sercom->I2CS.ADDR.bit.ADDRMASK = 0x00; // Match exact address +// } else if (num_addresses == 2) { +// sercom->I2CS.CTRLB.bit.AMODE = 0x1; // 2_ADDRS +// sercom->I2CS.ADDR.bit.ADDR = addresses[0]; +// sercom->I2CS.ADDR.bit.ADDRMASK = addresses[1]; +// } else { +// uint32_t combined = 0; // all addresses OR'ed +// uint32_t differ = 0; // bits that differ between addresses +// for (unsigned int i = 0; i < num_addresses; i++) { +// combined |= addresses[i]; +// differ |= addresses[0] ^ addresses[i]; +// } +// sercom->I2CS.CTRLB.bit.AMODE = 0x0; // MASK +// sercom->I2CS.ADDR.bit.ADDR = combined; +// sercom->I2CS.ADDR.bit.ADDRMASK = differ; +// } +// self->addresses = addresses; +// self->num_addresses = num_addresses; + +// if (smbus) { +// sercom->I2CS.CTRLA.bit.LOWTOUTEN = 1; // Errata 12003 +// sercom->I2CS.CTRLA.bit.SEXTTOEN = 1; // SCL Low Extend/Cumulative Time-Out 25ms +// } +// sercom->I2CS.CTRLA.bit.SCLSM = 0; // Clock stretch before ack +// sercom->I2CS.CTRLA.bit.MODE = 0x04; // Device mode +// sercom->I2CS.CTRLA.bit.ENABLE = 1; +// } + +// bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self) { +// return self->sda_pin == NO_PIN; +// } + +// void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) { +// if (common_hal_i2ctarget_i2c_target_deinited(self)) { +// return; +// } + +// self->sercom->I2CS.CTRLA.bit.ENABLE = 0; + +// reset_pin_number(self->sda_pin); +// reset_pin_number(self->scl_pin); +// self->sda_pin = NO_PIN; +// self->scl_pin = NO_PIN; +// } + +// static int i2c_target_check_error(i2ctarget_i2c_target_obj_t *self, bool raise) { +// if (!self->sercom->I2CS.INTFLAG.bit.ERROR) { +// return 0; +// } + +// int err = MP_EIO; + +// if (self->sercom->I2CS.STATUS.bit.LOWTOUT || self->sercom->I2CS.STATUS.bit.SEXTTOUT) { +// err = MP_ETIMEDOUT; +// } + +// self->sercom->I2CS.INTFLAG.reg = SERCOM_I2CS_INTFLAG_ERROR; // Clear flag + +// if (raise) { +// mp_raise_OSError(err); +// } +// return -err; +// } + +// int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { +// int err = i2c_target_check_error(self, false); +// if (err) { +// return err; +// } + +// if (!self->sercom->I2CS.INTFLAG.bit.AMATCH) { +// return 0; +// } + +// self->writing = false; + +// *address = self->sercom->I2CS.DATA.reg >> 1; +// *is_read = self->sercom->I2CS.STATUS.bit.DIR; +// *is_restart = self->sercom->I2CS.STATUS.bit.SR; + +// for (unsigned int i = 0; i < self->num_addresses; i++) { +// if (*address == self->addresses[i]) { +// common_hal_i2ctarget_i2c_target_ack(self, true); +// return 1; +// } +// } + +// // This should clear AMATCH, but it doesn't... +// common_hal_i2ctarget_i2c_target_ack(self, false); +// return 0; +// } + +// int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) { +// for (int t = 0; t < 100 && !self->sercom->I2CS.INTFLAG.reg; t++) { +// mp_hal_delay_us(10); +// } + +// i2c_target_check_error(self, true); + +// if (!self->sercom->I2CS.INTFLAG.bit.DRDY || +// self->sercom->I2CS.INTFLAG.bit.PREC || +// self->sercom->I2CS.INTFLAG.bit.AMATCH) { +// return 0; +// } + +// *data = self->sercom->I2CS.DATA.reg; +// return 1; +// } + +// int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) { +// for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { +// mp_hal_delay_us(10); +// } + +// i2c_target_check_error(self, true); + +// if (self->sercom->I2CS.INTFLAG.bit.PREC) { +// return 0; +// } + +// // RXNACK can carry over from the previous transfer +// if (self->writing && self->sercom->I2CS.STATUS.bit.RXNACK) { +// return 0; +// } + +// self->writing = true; + +// if (!self->sercom->I2CS.INTFLAG.bit.DRDY) { +// return 0; +// } + +// self->sercom->I2CS.DATA.bit.DATA = data; // Send data + +// return 1; +// } + +// void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) { +// self->sercom->I2CS.CTRLB.bit.ACKACT = !ack; +// self->sercom->I2CS.CTRLB.bit.CMD = 0x03; +// } + +// void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) { +// for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { +// mp_hal_delay_us(10); +// } + +// if (self->sercom->I2CS.INTFLAG.bit.AMATCH || !self->sercom->I2CS.STATUS.bit.CLKHOLD) { +// return; +// } + +// if (!self->sercom->I2CS.STATUS.bit.DIR) { +// common_hal_i2ctarget_i2c_target_ack(self, false); +// } else { +// int i = 0; +// while (self->sercom->I2CS.INTFLAG.reg == SERCOM_I2CS_INTFLAG_DRDY) { +// if (mp_hal_is_interrupted()) { +// return; +// } + +// self->sercom->I2CS.DATA.bit.DATA = 0xff; // Send dummy byte + +// // Wait for a result (if any). +// // test_byte_word.py::TestWord::test_write_seq leaves us with no INTFLAGs set in some of the tests +// for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { +// mp_hal_delay_us(10); +// } + +// if (++i > 1000) { // Avoid getting stuck "forever" +// mp_raise_OSError(MP_EIO); +// } +// } +// } + +// if (self->sercom->I2CS.INTFLAG.bit.AMATCH) { +// return; +// } + +// if (self->sercom->I2CS.STATUS.bit.CLKHOLD) { +// // Unable to release the clock. +// // The device might have to be re-initialized to get unstuck. +// mp_raise_OSError(MP_EIO); +// } +// } diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.h b/ports/atmel-samd/common-hal/spitarget/SPITarget.h new file mode 100644 index 0000000000000..73cfb650a4198 --- /dev/null +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.h @@ -0,0 +1,45 @@ +// /* +// * This file is part of the MicroPython project, http://micropython.org/ +// * +// * The MIT License (MIT) +// * +// * Copyright (c) 2018 Noralf Trønnes +// * +// * Permission is hereby granted, free of charge, to any person obtaining a copy +// * of this software and associated documentation files (the "Software"), to deal +// * in the Software without restriction, including without limitation the rights +// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// * copies of the Software, and to permit persons to whom the Software is +// * furnished to do so, subject to the following conditions: +// * +// * The above copyright notice and this permission notice shall be included in +// * all copies or substantial portions of the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// * THE SOFTWARE. +// */ + +// #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H +// #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H + +// #include "common-hal/microcontroller/Pin.h" +// #include "py/obj.h" + +// typedef struct { +// mp_obj_base_t base; + +// uint8_t *addresses; +// unsigned int num_addresses; + +// Sercom *sercom; +// uint8_t scl_pin; +// uint8_t sda_pin; +// bool writing; +// } i2ctarget_i2c_target_obj_t; + +// #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H diff --git a/ports/atmel-samd/common-hal/spitarget/__init__.c b/ports/atmel-samd/common-hal/spitarget/__init__.c new file mode 100644 index 0000000000000..c0ce8cef9a164 --- /dev/null +++ b/ports/atmel-samd/common-hal/spitarget/__init__.c @@ -0,0 +1 @@ +// No spitarget module functions. diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 1e18fee5f8133..d8028b5f327b1 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -46,6 +46,7 @@ CIRCUITPY_OS_GETENV ?= 0 CIRCUITPY_PIXELMAP ?= 0 CIRCUITPY_RE ?= 0 CIRCUITPY_SDCARDIO ?= 0 +CIRCUITPY_SPITARGET ?= 0 CIRCUITPY_SYNTHIO ?= 0 CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1 CIRCUITPY_TRACEBACK ?= 0 @@ -105,6 +106,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_PS2IO ?= 1 CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FRAMEBUFFERIO) CIRCUITPY_SAMD ?= 1 +CIRCUITPY_SPITARGET ?= 1 CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12 CIRCUITPY_ULAB_OPTIMIZE_SIZE ?= 1 CIRCUITPY_WATCHDOG ?= 1 diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 62acd69ae1a5f..bb8f8099e23a6 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -351,6 +351,9 @@ endif ifeq ($(CIRCUITPY_SOCKETPOOL),1) SRC_PATTERNS += socketpool/% endif +ifeq ($(CIRCUITPY_SPITARGET),1) +SRC_PATTERNS += spitarget/% +endif ifeq ($(CIRCUITPY_SSL),1) SRC_PATTERNS += ssl/% endif @@ -516,6 +519,8 @@ SRC_COMMON_HAL_ALL = \ socketpool/__init__.c \ socketpool/SocketPool.c \ socketpool/Socket.c \ + spitarget/SPITarget.c \ + spitarget/__init__.c \ supervisor/Runtime.c \ supervisor/__init__.c \ usb_host/__init__.c \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index fc9fdcbd31afa..d3774258fbed6 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -476,6 +476,9 @@ CFLAGS += -DCIRCUITPY_SKIP_SAFE_MODE_WAIT=$(CIRCUITPY_SKIP_SAFE_MODE_WAIT) CIRCUITPY_SOCKETPOOL ?= $(CIRCUITPY_WIFI) CFLAGS += -DCIRCUITPY_SOCKETPOOL=$(CIRCUITPY_SOCKETPOOL) +CIRCUITPY_SPITARGET ?= 0 +CFLAGS += -DCIRCUITPY_SPITARGET=$(CIRCUITPY_SPITARGET) + CIRCUITPY_SSL ?= $(CIRCUITPY_WIFI) CFLAGS += -DCIRCUITPY_SSL=$(CIRCUITPY_SSL) diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c new file mode 100644 index 0000000000000..886585820e38f --- /dev/null +++ b/shared-bindings/spitarget/SPITarget.c @@ -0,0 +1,207 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Noralf Trønnes + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/spitarget/SPITarget.h" +#include "shared-bindings/time/__init__.h" +#include "shared-bindings/util.h" + +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" +#include "shared/runtime/interrupt_char.h" + +#include "py/mperrno.h" +#include "py/mphal.h" +#include "py/obj.h" +#include "py/objproperty.h" +#include "py/runtime.h" + +//| class SPITarget: +//| """Serial Peripheral Interface protocol target""" +//| +//| def __init__( +//| self, +//| sck: microcontroller.Pin, +//| mosi: microcontroller.Pin, +//| miso: microcontroller.Pin, +//| ss: microcontroller.Pin +//| ) -> None: +//| """I2C is a two-wire protocol for communicating between devices. +//| This implements the secondary (aka target or peripheral) side. +//| +//| :param ~microcontroller.Pin sck: The SPI clock pin +//| :param ~microcontroller.Pin mosi: The pin transferring data from the main to the secondary +//| :param ~microcontroller.Pin miso: The pin transferring data from the secondary to the main +//| :param ~microcontroller.Pin ss: The secondary selection pin""" +//| ... +STATIC mp_obj_t spitarget_spi_target_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + enum { ARG_sck, ARG_mosi, ARG_miso, ARG_ss }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_sck, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_mosi, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_miso, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_ss, MP_ARG_REQUIRED | MP_ARG_OBJ }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + const mcu_pin_obj_t *sck = validate_obj_is_free_pin(args[ARG_sck].u_obj, MP_QSTR_sck); + const mcu_pin_obj_t *mosi = validate_obj_is_free_pin(args[ARG_mosi].u_obj, MP_QSTR_mosi); + const mcu_pin_obj_t *miso = validate_obj_is_free_pin(args[ARG_miso].u_obj, MP_QSTR_miso); + const mcu_pin_obj_t *ss = validate_obj_is_free_pin(args[ARG_ss].u_obj, MP_QSTR_ss); + + common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Releases control of the underlying hardware so other classes can use it.""" +//| ... +STATIC mp_obj_t spitarget_spi_target_obj_deinit(mp_obj_t self_in) { + mp_check_self(mp_obj_is_type(self_in, &spitarget_spi_target_type)); + spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_spitarget_spi_target_deinit(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(spitarget_spi_target_deinit_obj, spitarget_spi_target_obj_deinit); + +//| def __enter__(self) -> SPITarget: +//| """No-op used in Context Managers.""" +//| ... +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Automatically deinitializes the hardware on context exit. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +STATIC mp_obj_t spitarget_spi_target_obj___exit__(size_t n_args, const mp_obj_t *args) { + mp_check_self(mp_obj_is_type(args[0], &spitarget_spi_target_target_type)); + spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); + common_hal_spitarget_spi_target_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, 4, spitarget_spi_target_obj___exit__); + +//| def load_packet(self, mosi_packet: bytearray, miso_packet: bytearray) -> None: +//| """Queue data for the next SPI transfer from the main device. +//| If a packet has already been queued for this SPI bus but has not yet been transferred, an error will be raised. +//| +//| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request.""" +//| +STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); + spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + if (common_hal_spitarget_spi_target_deinited(self)) { + raise_deinited_error(); + } + enum { ARG_mosi_packet, ARG_miso_packet }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_mosi_packet, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_miso_packet, MP_ARG_REQUIRED | MP_ARG_OBJ }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_buffer_info_t mosi_bufinfo; + mp_get_buffer_raise(args[ARG_mosi_packet].u_obj, &mosi_bufinfo, MP_BUFFER_READ); + + mp_buffer_info_t miso_bufinfo; + mp_get_buffer_raise(args[ARG_mosi_packet].u_obj, &miso_bufinfo, MP_BUFFER_READ); + + if (miso_bufinfo.len != mosi_bufinfo.len) { + mp_raise_ValueError(MP_ERROR_TEXT("Packet buffers for an SPI transfer must have the same length.")); + } + + common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spitarget_spi_target_load_packet); + +//| def try_transfer(self, *, timeout: float = -1) -> bool: +//| """Wait for an SPI transfer from the main device. +//| +//| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once +//| :return: True if the transfer is complete, or False if no response received before the timeout +//| :rtype: ~bool""" +//| +STATIC mp_obj_t spitarget_spi_target_try_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); + spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + if (common_hal_spitarget_spi_target_deinited(self)) { + raise_deinited_error(); + } + enum { ARG_timeout }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + #if MICROPY_PY_BUILTINS_FLOAT + float f = mp_obj_get_float(args[ARG_timeout].u_obj) * 1000; + int timeout_ms = (int)f; + #else + int timeout_ms = mp_obj_get_int(args[ARG_timeout].u_obj) * 1000; + #endif + + bool forever = false; + uint64_t timeout_end = 0; + if (timeout_ms == 0) { + forever = true; + } else if (timeout_ms > 0) { + timeout_end = common_hal_time_monotonic_ms() + timeout_ms; + } + + do { + if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { + common_hal_spitarget_spi_target_transfer_close(self); + return mp_const_true; + } + mp_hal_delay_us(10); + } while (forever || common_hal_time_monotonic_ms() < timeout_end); + + return mp_const_false; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_try_transfer_obj, 1, spitarget_spi_target_try_transfer); + +STATIC const mp_rom_map_elem_t spitarget_spi_target_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&spitarget_spi_target_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&spitarget_spi_target___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_load_packet), MP_ROM_PTR(&spitarget_spi_target_load_packet_obj) }, + { MP_ROM_QSTR(MP_QSTR_try_transfer), MP_ROM_PTR(&spitarget_spi_target_try_transfer_obj) }, + +}; + +STATIC MP_DEFINE_CONST_DICT(spitarget_spi_target_locals_dict, spitarget_spi_target_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + spitarget_spi_target_type, + MP_QSTR_SPITarget, + MP_TYPE_FLAG_NONE, + make_new, spitarget_spi_target_make_new, + locals_dict, &spitarget_spi_target_locals_dict + ); diff --git a/shared-bindings/spitarget/SPITarget.h b/shared-bindings/spitarget/SPITarget.h new file mode 100644 index 0000000000000..d562b1db8c92b --- /dev/null +++ b/shared-bindings/spitarget/SPITarget.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Noralf Trønnes + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SPI_TARGET_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SPI_TARGET_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/spitarget/SPITarget.h" + +extern const mp_obj_type_t spitarget_spi_target_type; + +extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss); +extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); +extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + +extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + const uint8_t *mosi_packet, uint8_t *miso_packet, size_t len); +extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); +extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SPI_TARGET_H diff --git a/shared-bindings/spitarget/__init__.c b/shared-bindings/spitarget/__init__.c new file mode 100644 index 0000000000000..f92e1b29271f1 --- /dev/null +++ b/shared-bindings/spitarget/__init__.c @@ -0,0 +1,40 @@ +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/spitarget/SPITarget.h" + +#include "py/runtime.h" + +//| """Serial Peripheral Interface protocol target +//| +//| The `spitarget` module contains classes to support an SPI target. +//| +//| Example emulating a target :: +//| +//| import board +//| from spitarget import SPITarget +//| +//| TODO +//| +//| This example sets up an SPI device that can be accessed from Linux like this:: +//| +//| $ TODO command +//| TODO result +//| $ TODO command + +STATIC const mp_rom_map_elem_t spitarget_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_spitarget) }, + { MP_ROM_QSTR(MP_QSTR_SPITarget), MP_ROM_PTR(&spitarget_spi_target_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(spitarget_module_globals, spitarget_module_globals_table); + +const mp_obj_module_t spitarget_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&spitarget_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_spitarget, spitarget_module); From 289f42064fab96168853dec31808b47d3e661543 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 00:04:57 -0700 Subject: [PATCH 29/55] implement the spitarget methods --- ports/atmel-samd/common-hal/busio/SPI.c | 1 - .../common-hal/spitarget/SPITarget.c | 480 ++++++++---------- .../common-hal/spitarget/SPITarget.h | 54 +- stderr.txt | 339 +++++++++++++ 4 files changed, 577 insertions(+), 297 deletions(-) create mode 100644 stderr.txt diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index d80fc3dd79f89..26613b41bbd4a 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -37,7 +37,6 @@ #include "hal/include/hal_gpio.h" #include "hal/include/hal_spi_m_sync.h" -#include "hal/include/hpl_spi_m_sync.h" #include "samd/dma.h" #include "samd/sercom.h" diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index c7d9973897fb4..2b0c885c0219d 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -1,257 +1,223 @@ -// /* -// * This file is part of the MicroPython project, http://micropython.org/ -// * -// * The MIT License (MIT) -// * -// * Copyright (c) 2018 Noralf Trønnes -// * -// * Permission is hereby granted, free of charge, to any person obtaining a copy -// * of this software and associated documentation files (the "Software"), to deal -// * in the Software without restriction, including without limitation the rights -// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// * copies of the Software, and to permit persons to whom the Software is -// * furnished to do so, subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in -// * all copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// * THE SOFTWARE. -// */ - -// #include "shared-bindings/i2ctarget/I2CTarget.h" -// #include "shared-bindings/microcontroller/Pin.h" -// #include "common-hal/busio/I2C.h" - -// #include "shared/runtime/interrupt_char.h" -// #include "py/mperrno.h" -// #include "py/mphal.h" -// #include "py/runtime.h" - -// #include "hal/include/hal_gpio.h" -// #include "peripherals/samd/sercom.h" - -// void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self, -// const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, -// uint8_t *addresses, unsigned int num_addresses, bool smbus) { -// uint8_t sercom_index; -// uint32_t sda_pinmux, scl_pinmux; -// Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); -// if (sercom == NULL) { -// raise_ValueError_invalid_pins(); -// } -// self->sercom = sercom; - -// gpio_set_pin_function(sda->number, GPIO_PIN_FUNCTION_OFF); -// gpio_set_pin_function(scl->number, GPIO_PIN_FUNCTION_OFF); -// gpio_set_pin_function(sda->number, sda_pinmux); -// gpio_set_pin_function(scl->number, scl_pinmux); - -// self->sda_pin = sda->number; -// self->scl_pin = scl->number; -// claim_pin(sda); -// claim_pin(scl); - -// samd_peripherals_sercom_clock_init(sercom, sercom_index); - -// #ifdef SAM_D5X_E5X -// sercom->I2CS.CTRLC.bit.SDASETUP = 0x08; -// #endif - -// sercom->I2CS.CTRLA.bit.SWRST = 1; -// while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) { -// } - -// sercom->I2CS.CTRLB.bit.AACKEN = 0; // Automatic acknowledge is disabled. - -// if (num_addresses == 1) { -// sercom->I2CS.CTRLB.bit.AMODE = 0x0; // MASK -// sercom->I2CS.ADDR.bit.ADDR = addresses[0]; -// sercom->I2CS.ADDR.bit.ADDRMASK = 0x00; // Match exact address -// } else if (num_addresses == 2) { -// sercom->I2CS.CTRLB.bit.AMODE = 0x1; // 2_ADDRS -// sercom->I2CS.ADDR.bit.ADDR = addresses[0]; -// sercom->I2CS.ADDR.bit.ADDRMASK = addresses[1]; -// } else { -// uint32_t combined = 0; // all addresses OR'ed -// uint32_t differ = 0; // bits that differ between addresses -// for (unsigned int i = 0; i < num_addresses; i++) { -// combined |= addresses[i]; -// differ |= addresses[0] ^ addresses[i]; -// } -// sercom->I2CS.CTRLB.bit.AMODE = 0x0; // MASK -// sercom->I2CS.ADDR.bit.ADDR = combined; -// sercom->I2CS.ADDR.bit.ADDRMASK = differ; -// } -// self->addresses = addresses; -// self->num_addresses = num_addresses; - -// if (smbus) { -// sercom->I2CS.CTRLA.bit.LOWTOUTEN = 1; // Errata 12003 -// sercom->I2CS.CTRLA.bit.SEXTTOEN = 1; // SCL Low Extend/Cumulative Time-Out 25ms -// } -// sercom->I2CS.CTRLA.bit.SCLSM = 0; // Clock stretch before ack -// sercom->I2CS.CTRLA.bit.MODE = 0x04; // Device mode -// sercom->I2CS.CTRLA.bit.ENABLE = 1; -// } - -// bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self) { -// return self->sda_pin == NO_PIN; -// } - -// void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) { -// if (common_hal_i2ctarget_i2c_target_deinited(self)) { -// return; -// } - -// self->sercom->I2CS.CTRLA.bit.ENABLE = 0; - -// reset_pin_number(self->sda_pin); -// reset_pin_number(self->scl_pin); -// self->sda_pin = NO_PIN; -// self->scl_pin = NO_PIN; -// } - -// static int i2c_target_check_error(i2ctarget_i2c_target_obj_t *self, bool raise) { -// if (!self->sercom->I2CS.INTFLAG.bit.ERROR) { -// return 0; -// } - -// int err = MP_EIO; - -// if (self->sercom->I2CS.STATUS.bit.LOWTOUT || self->sercom->I2CS.STATUS.bit.SEXTTOUT) { -// err = MP_ETIMEDOUT; -// } - -// self->sercom->I2CS.INTFLAG.reg = SERCOM_I2CS_INTFLAG_ERROR; // Clear flag - -// if (raise) { -// mp_raise_OSError(err); -// } -// return -err; -// } - -// int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { -// int err = i2c_target_check_error(self, false); -// if (err) { -// return err; -// } - -// if (!self->sercom->I2CS.INTFLAG.bit.AMATCH) { -// return 0; -// } - -// self->writing = false; - -// *address = self->sercom->I2CS.DATA.reg >> 1; -// *is_read = self->sercom->I2CS.STATUS.bit.DIR; -// *is_restart = self->sercom->I2CS.STATUS.bit.SR; - -// for (unsigned int i = 0; i < self->num_addresses; i++) { -// if (*address == self->addresses[i]) { -// common_hal_i2ctarget_i2c_target_ack(self, true); -// return 1; -// } -// } - -// // This should clear AMATCH, but it doesn't... -// common_hal_i2ctarget_i2c_target_ack(self, false); -// return 0; -// } - -// int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) { -// for (int t = 0; t < 100 && !self->sercom->I2CS.INTFLAG.reg; t++) { -// mp_hal_delay_us(10); -// } - -// i2c_target_check_error(self, true); - -// if (!self->sercom->I2CS.INTFLAG.bit.DRDY || -// self->sercom->I2CS.INTFLAG.bit.PREC || -// self->sercom->I2CS.INTFLAG.bit.AMATCH) { -// return 0; -// } - -// *data = self->sercom->I2CS.DATA.reg; -// return 1; -// } - -// int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) { -// for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { -// mp_hal_delay_us(10); -// } - -// i2c_target_check_error(self, true); - -// if (self->sercom->I2CS.INTFLAG.bit.PREC) { -// return 0; -// } - -// // RXNACK can carry over from the previous transfer -// if (self->writing && self->sercom->I2CS.STATUS.bit.RXNACK) { -// return 0; -// } - -// self->writing = true; - -// if (!self->sercom->I2CS.INTFLAG.bit.DRDY) { -// return 0; -// } - -// self->sercom->I2CS.DATA.bit.DATA = data; // Send data - -// return 1; -// } - -// void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) { -// self->sercom->I2CS.CTRLB.bit.ACKACT = !ack; -// self->sercom->I2CS.CTRLB.bit.CMD = 0x03; -// } - -// void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) { -// for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { -// mp_hal_delay_us(10); -// } - -// if (self->sercom->I2CS.INTFLAG.bit.AMATCH || !self->sercom->I2CS.STATUS.bit.CLKHOLD) { -// return; -// } - -// if (!self->sercom->I2CS.STATUS.bit.DIR) { -// common_hal_i2ctarget_i2c_target_ack(self, false); -// } else { -// int i = 0; -// while (self->sercom->I2CS.INTFLAG.reg == SERCOM_I2CS_INTFLAG_DRDY) { -// if (mp_hal_is_interrupted()) { -// return; -// } - -// self->sercom->I2CS.DATA.bit.DATA = 0xff; // Send dummy byte - -// // Wait for a result (if any). -// // test_byte_word.py::TestWord::test_write_seq leaves us with no INTFLAGs set in some of the tests -// for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { -// mp_hal_delay_us(10); -// } - -// if (++i > 1000) { // Avoid getting stuck "forever" -// mp_raise_OSError(MP_EIO); -// } -// } -// } - -// if (self->sercom->I2CS.INTFLAG.bit.AMATCH) { -// return; -// } - -// if (self->sercom->I2CS.STATUS.bit.CLKHOLD) { -// // Unable to release the clock. -// // The device might have to be re-initialized to get unstuck. -// mp_raise_OSError(MP_EIO); -// } -// } +#include "common-hal/spitarget/SPITarget.h" + +#include "hpl_sercom_config.h" +#include "samd/sercom.h" + +void common_hal_spitarget_spi_target_construct(busio_spi_obj_t *self, + const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, + const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss) { + Sercom *sercom = NULL; + uint8_t sercom_index; + uint32_t clock_pinmux = 0; + uint32_t mosi_pinmux = 0; + uint32_t miso_pinmux = 0; + uint32_t ss_pinmux = 0; + uint8_t clock_pad = 0; + uint8_t mosi_pad = 0; + uint8_t miso_pad = 0; + uint8_t dopo = 255; + + // Ensure the object starts in its deinit state. + self->clock_pin = NO_PIN; + + // Special case for SAMR21 boards. (feather_radiofruit_zigbee) + #if defined(PIN_PC19F_SERCOM4_PAD0) + if (miso == &pin_PC19) { + if (mosi == &pin_PB30 && clock == &pin_PC18) { + sercom = SERCOM4; + sercom_index = 4; + clock_pinmux = MUX_F; + mosi_pinmux = MUX_F; + miso_pinmux = MUX_F; + clock_pad = 3; + mosi_pad = 2; + miso_pad = 0; + dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); + } + // Error, leave SERCOM unset to throw an exception later. + } else + #endif + { + for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { + sercom_index = sck->sercom[i].index; // 2 for SERCOM2, etc. + if (sercom_index >= SERCOM_INST_NUM) { + continue; + } + Sercom *potential_sercom = sercom_insts[sercom_index]; + if (potential_sercom->SPI.CTRLA.bit.ENABLE != 0) { + continue; + } + clock_pinmux = PINMUX(clock->number, (i == 0) ? MUX_C : MUX_D); + clock_pad = clock->sercom[i].pad; + if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { + continue; + } + // find miso_pad first, since it corresponds to dopo which takes limited values + for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { + if (sercom_index == miso->sercom[j].index) { + miso_pinmux = PINMUX(miso->number, (j == 0) ? MUX_C : MUX_D); + miso_pad = miso->sercom[j].pad; + dopo = samd_peripherals_get_spi_dopo(clock_pad, miso_pad); + if (dopo > 0x3) { + continue; // pad combination not possible + } + } else { + continue; + } + for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { + if (sercom_index == mosi->sercom[k].index) { + mosi_pinmux = PINMUX(mosi->number, (k == 0) ? MUX_C : MUX_D); + mosi_pad = mosi->sercom[k].pad; + for (int m = 0; m < NUM_SERCOMS_PER_PIN; m++) { + if (sercom_index == ss->sercom[m].index) { + ss_pinmux = PINMUX(ss->number, (m == 0) ? MUX_C : MUX_D); + sercom = potential_sercom; + break; + } + } + if (sercom != NULL) { + break; + } + } + } + if (sercom != NULL) { + break; + } + } + if (sercom != NULL) { + break; + } + } + } + if (sercom == NULL) { + raise_ValueError_invalid_pins(); + } + + // Set up SPI clocks on SERCOM. + samd_peripherals_sercom_clock_init(sercom, sercom_index); + + if (spi_m_sync_init(&self->spi_desc, sercom) != ERR_NONE) { + mp_raise_OSError(MP_EIO); + } + + // Pads must be set after spi_m_sync_init(), which uses default values from + // the prototypical SERCOM. + + hri_sercomspi_write_CTRLA_MODE_bf(sercom, 2); + hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); + hri_sercomspi_write_CTRLA_DIPO_bf(sercom, mosi_pad); + hri_sercomspi_write_CTRLB_PLOADEN_bit(sercom, 1); + + // Always start at 250khz which is what SD cards need. They are sensitive to + // SPI bus noise before they are put into SPI mode. + uint8_t baud_value = samd_peripherals_spi_baudrate_to_baud_reg_value(250000); + if (spi_m_sync_set_baudrate(&self->spi_desc, baud_value) != ERR_NONE) { + // spi_m_sync_set_baudrate does not check for validity, just whether the device is + // busy or not + mp_raise_OSError(MP_EIO); + } + + gpio_set_pin_direction(clock->number, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); + gpio_set_pin_function(clock->number, clock_pinmux); + claim_pin(clock); + self->clock_pin = clock->number; + + gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); + gpio_set_pin_function(mosi->number, mosi_pinmux); + self->MOSI_pin = mosi->number; + claim_pin(mosi); + + gpio_set_pin_direction(miso->number, GPIO_DIRECTION_OUT); + gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF); + gpio_set_pin_function(miso->number, miso_pinmux); + self->MISO_pin = miso->number; + claim_pin(miso); + + gpio_set_pin_direction(ss->number, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(ss->number, GPIO_PULL_OFF); + gpio_set_pin_function(ss->number, ss_pinmux); + self->SS_pin = ss->number; + claim_pin(ss); + + self->running_dma.failure = 1; // not started + + spi_m_sync_enable(&self->spi_desc); +} + +void common_hal_spitarget_spi_target_deinit(busio_spi_obj_t *self) { + if (common_hal_busio_spi_deinited(self)) { + return; + } + allow_reset_sercom(self->spi_desc.dev.prvt); + + spi_m_sync_disable(&self->spi_desc); + spi_m_sync_deinit(&self->spi_desc); + reset_pin_number(self->clock_pin); + reset_pin_number(self->MOSI_pin); + reset_pin_number(self->MISO_pin); + reset_pin_number(self->SS_pin); + self->clock_pin = NO_PIN; +} + +void common_hal_spitarget_spi_target_deinited(busio_spi_obj_t *self) { + return self->clock_pin == NO_PIN; +} + +void common_hal_spitarget_spi_target_transfer_start(busio_spi_obj_t *self, + uint8_t *miso_packet, uint8_t *mosi_packet, size_t len) { + if (len == 0) { + return; + } + if (self->running_dma.failure != 1) { + mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); + } + Sercom* sercom = self->spi_desc.dev.prvt; + self->running_dma = shared_dma_transfer_start(sercom, miso_packet, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, mosi_packet, len, 0); + + // There is an issue where if an unexpected SPI transfer is received before the user calls "end" for the in-progress, expected + // transfer, the SERCOM has an error and gets confused. This can be detected from INTFLAG.ERROR. I think the code in + // ports/atmel-samd/peripherals/samd/dma.c at line 277 (as of this commit; it's the part that reads s->SPI.INTFLAG.bit.RXC and + // s->SPI.DATA.reg) is supposed to fix this, but experimentation seems to show that it does not in fact fix anything. Anyways, if + // the ERROR bit is set, let's just reset the peripheral and then setup the transfer again -- that seems to work. + if (hri_sercomspi_get_INTFLAG_ERROR_bit(sercom)) { + shared_dma_transfer_close(self->running_dma); + + // disable the sercom + spi_m_sync_disable(&self->spi_desc); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + + // save configurations + hri_sercomspi_ctrla_reg_t ctrla_saved_val = hri_sercomspi_get_CTRLA_reg(sercom, -1); // -1 mask is all ones: save all bits + hri_sercomspi_ctrlb_reg_t ctrlb_saved_val = hri_sercomspi_get_CTRLB_reg(sercom, -1); // -1 mask is all ones: save all bits + hri_sercomspi_baud_reg_t baud_saved_val = hri_sercomspi_get_BAUD_reg(sercom, -1); // -1 mask is all ones: save all bits + // reset + hri_sercomspi_set_CTRLA_SWRST_bit(sercom); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + // re-write configurations + hri_sercomspi_write_CTRLA_reg(sercom, ctrla_saved_val); + hri_sercomspi_write_CTRLB_reg(sercom, ctrlb_saved_val); + hri_sercomspi_write_BAUD_reg (sercom, baud_saved_val); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + + // re-enable the sercom + spi_m_sync_enable(&self->spi_desc); + hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); + + self->running_dma = shared_dma_transfer_start(sercom, miso_packet, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, mosi_packet, len, 0); + } +} + +bool common_hal_spitarget_spi_target_transfer_is_finished(busio_spi_obj_t *self) { + return self->running_dma.failure == 1 || shared_dma_transfer_finished(self->running_dma); +} + +void common_hal_spitarget_spi_target_transfer_close(busio_spi_obj_t *self) { + if (self->running_dma.failure == 1) { + return 0; + } + int res = shared_dma_transfer_close(self->running_dma); + self->running_dma.failure = 1; + return res; +} diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.h b/ports/atmel-samd/common-hal/spitarget/SPITarget.h index 73cfb650a4198..8b8b4b98549b7 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.h +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.h @@ -1,45 +1,21 @@ -// /* -// * This file is part of the MicroPython project, http://micropython.org/ -// * -// * The MIT License (MIT) -// * -// * Copyright (c) 2018 Noralf Trønnes -// * -// * Permission is hereby granted, free of charge, to any person obtaining a copy -// * of this software and associated documentation files (the "Software"), to deal -// * in the Software without restriction, including without limitation the rights -// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// * copies of the Software, and to permit persons to whom the Software is -// * furnished to do so, subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in -// * all copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// * THE SOFTWARE. -// */ +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H -// #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H -// #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H +#include "common-hal/microcontroller/Pin.h" +#include "hal/include/hal_spi_m_sync.h" +#include "py/obj.h" -// #include "common-hal/microcontroller/Pin.h" -// #include "py/obj.h" +typedef struct { + mp_obj_base_t base; -// typedef struct { -// mp_obj_base_t base; + struct spi_m_sync_descriptor spi_desc; -// uint8_t *addresses; -// unsigned int num_addresses; + uint8_t clock_pin; + uint8_t MOSI_pin; + uint8_t MISO_pin; + uint8_t SS_pin; -// Sercom *sercom; -// uint8_t scl_pin; -// uint8_t sda_pin; -// bool writing; -// } i2ctarget_i2c_target_obj_t; + dma_descr_t running_dma; +} spitarget_spi_target_obj_t; -// #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_TARGET_H diff --git a/stderr.txt b/stderr.txt new file mode 100644 index 0000000000000..3ae4b68b7ce03 --- /dev/null +++ b/stderr.txt @@ -0,0 +1,339 @@ +In file included from ../../shared-bindings/spitarget/SPITarget.c:28: +../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' + 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' + 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' + 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' + 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' + 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' + 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ../../shared-bindings/spitarget/__init__.c:7: +../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' + 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' + 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' + 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' + 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_make_new': +../../shared-bindings/spitarget/SPITarget.c:61:5: error: unknown type name 'spitarget_spi_target_obj_t' + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' + 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./samd_peripherals_config.h:30, + from ./peripherals/samd/pins.h:38, + from ./common-hal/microcontroller/Pin.h:32, + from ../../shared-bindings/microcontroller/Pin.h:30, + from ../../shared-bindings/spitarget/SPITarget.c:27: +../../shared-bindings/spitarget/SPITarget.c:61:54: error: 'spitarget_spi_target_obj_t' undeclared (first use in this function); did you mean 'spitarget_spi_target_type'? + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:61:54: note: each undeclared identifier is reported only once for each function it appears in + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^~~~~~~~~~~ +../../py/obj.h:970:61: error: expected expression before ')' token + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^ +../../shared-bindings/spitarget/SPITarget.c:61:40: note: in expansion of macro 'mp_obj_malloc' + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:77:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_construct' [-Werror=implicit-function-declaration] + 77 | common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:77:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_construct' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' + 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +make: *** [../../py/mkrules.mk:85: build-rapid0_adcs/shared-bindings/spitarget/__init__.o] Error 1 +make: *** Waiting for unfinished jobs.... +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj_deinit': +../../shared-bindings/spitarget/SPITarget.c:86:5: error: unknown type name 'spitarget_spi_target_obj_t' + 86 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:87:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinit' [-Werror=implicit-function-declaration] + 87 | common_hal_spitarget_spi_target_deinit(self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:87:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinit' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj___exit__': +../../shared-bindings/spitarget/SPITarget.c:103:5: error: unknown type name 'spitarget_spi_target_obj_t' + 103 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': +../../shared-bindings/spitarget/SPITarget.c:117:5: error: unknown type name 'spitarget_spi_target_obj_t' + 117 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:118:9: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinited' [-Werror=implicit-function-declaration] + 118 | if (common_hal_spitarget_spi_target_deinited(self)) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:118:9: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinited' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c:139:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_start' [-Werror=implicit-function-declaration] + 139 | common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:139:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_start' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_try_transfer': +../../shared-bindings/spitarget/SPITarget.c:152:5: error: unknown type name 'spitarget_spi_target_obj_t' + 152 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:179:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=implicit-function-declaration] + 179 | if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:179:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c:180:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_close' [-Werror=implicit-function-declaration] + 180 | common_hal_spitarget_spi_target_transfer_close(self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:180:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_close' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': +../../shared-bindings/spitarget/SPITarget.c:140:1: error: control reaches end of non-void function [-Werror=return-type] + 140 | } + | ^ +cc1: all warnings being treated as errors +make: *** [../../py/mkrules.mk:85: build-rapid0_adcs/shared-bindings/spitarget/SPITarget.o] Error 1 +In file included from ../../shared-bindings/spitarget/SPITarget.c:28: +../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' + 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' + 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' + 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' + 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' + 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' + 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ../../shared-bindings/spitarget/__init__.c:7: +../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' + 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' + 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' + 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' + 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' + 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' + 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +make: *** [../../py/mkrules.mk:85: build-rapid0_cdh/shared-bindings/spitarget/__init__.o] Error 1 +make: *** Waiting for unfinished jobs.... +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_make_new': +../../shared-bindings/spitarget/SPITarget.c:61:5: error: unknown type name 'spitarget_spi_target_obj_t' + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./samd_peripherals_config.h:30, + from ./peripherals/samd/pins.h:38, + from ./common-hal/microcontroller/Pin.h:32, + from ../../shared-bindings/microcontroller/Pin.h:30, + from ../../shared-bindings/spitarget/SPITarget.c:27: +../../shared-bindings/spitarget/SPITarget.c:61:54: error: 'spitarget_spi_target_obj_t' undeclared (first use in this function); did you mean 'spitarget_spi_target_type'? + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:61:54: note: each undeclared identifier is reported only once for each function it appears in + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^~~~~~~~~~~ +../../py/obj.h:970:61: error: expected expression before ')' token + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^ +../../shared-bindings/spitarget/SPITarget.c:61:40: note: in expansion of macro 'mp_obj_malloc' + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:77:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_construct' [-Werror=implicit-function-declaration] + 77 | common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:77:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_construct' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj_deinit': +../../shared-bindings/spitarget/SPITarget.c:86:5: error: unknown type name 'spitarget_spi_target_obj_t' + 86 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:87:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinit' [-Werror=implicit-function-declaration] + 87 | common_hal_spitarget_spi_target_deinit(self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:87:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinit' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj___exit__': +../../shared-bindings/spitarget/SPITarget.c:103:5: error: unknown type name 'spitarget_spi_target_obj_t' + 103 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': +../../shared-bindings/spitarget/SPITarget.c:117:5: error: unknown type name 'spitarget_spi_target_obj_t' + 117 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:118:9: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinited' [-Werror=implicit-function-declaration] + 118 | if (common_hal_spitarget_spi_target_deinited(self)) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:118:9: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinited' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c:139:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_start' [-Werror=implicit-function-declaration] + 139 | common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:139:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_start' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_try_transfer': +../../shared-bindings/spitarget/SPITarget.c:152:5: error: unknown type name 'spitarget_spi_target_obj_t' + 152 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:179:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=implicit-function-declaration] + 179 | if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:179:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c:180:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_close' [-Werror=implicit-function-declaration] + 180 | common_hal_spitarget_spi_target_transfer_close(self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:180:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_close' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': +../../shared-bindings/spitarget/SPITarget.c:140:1: error: control reaches end of non-void function [-Werror=return-type] + 140 | } + | ^ +cc1: all warnings being treated as errors +make: *** [../../py/mkrules.mk:85: build-rapid0_cdh/shared-bindings/spitarget/SPITarget.o] Error 1 +In file included from ../../shared-bindings/spitarget/SPITarget.c:28: +../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' + 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' + 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' + 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' + 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' + 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' + 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_make_new': +../../shared-bindings/spitarget/SPITarget.c:61:5: error: unknown type name 'spitarget_spi_target_obj_t' + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./samd_peripherals_config.h:30, + from ./peripherals/samd/pins.h:38, + from ./common-hal/microcontroller/Pin.h:32, + from ../../shared-bindings/microcontroller/Pin.h:30, + from ../../shared-bindings/spitarget/SPITarget.c:27: +../../shared-bindings/spitarget/SPITarget.c:61:54: error: 'spitarget_spi_target_obj_t' undeclared (first use in this function); did you mean 'spitarget_spi_target_type'? + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:61:54: note: each undeclared identifier is reported only once for each function it appears in + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^~~~~~~~~~~ +../../py/obj.h:970:61: error: expected expression before ')' token + 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) + | ^ +../../shared-bindings/spitarget/SPITarget.c:61:40: note: in expansion of macro 'mp_obj_malloc' + 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); + | ^~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:77:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_construct' [-Werror=implicit-function-declaration] + 77 | common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:77:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_construct' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj_deinit': +../../shared-bindings/spitarget/SPITarget.c:86:5: error: unknown type name 'spitarget_spi_target_obj_t' + 86 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:87:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinit' [-Werror=implicit-function-declaration] + 87 | common_hal_spitarget_spi_target_deinit(self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:87:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinit' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj___exit__': +../../shared-bindings/spitarget/SPITarget.c:103:5: error: unknown type name 'spitarget_spi_target_obj_t' + 103 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': +../../shared-bindings/spitarget/SPITarget.c:117:5: error: unknown type name 'spitarget_spi_target_obj_t' + 117 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:118:9: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinited' [-Werror=implicit-function-declaration] + 118 | if (common_hal_spitarget_spi_target_deinited(self)) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:118:9: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinited' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c:139:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_start' [-Werror=implicit-function-declaration] + 139 | common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:139:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_start' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_try_transfer': +../../shared-bindings/spitarget/SPITarget.c:152:5: error: unknown type name 'spitarget_spi_target_obj_t' + 152 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:179:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=implicit-function-declaration] + 179 | if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:179:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c:180:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_close' [-Werror=implicit-function-declaration] + 180 | common_hal_spitarget_spi_target_transfer_close(self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.c:180:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_close' [-Werror=nested-externs] +../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': +../../shared-bindings/spitarget/SPITarget.c:140:1: error: control reaches end of non-void function [-Werror=return-type] + 140 | } + | ^ +cc1: all warnings being treated as errors +make: *** [../../py/mkrules.mk:85: build-rapid0_eps/shared-bindings/spitarget/SPITarget.o] Error 1 +make: *** Waiting for unfinished jobs.... +In file included from ../../shared-bindings/spitarget/__init__.c:7: +../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' + 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' + 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' + 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' + 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' + 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' + 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +make: *** [../../py/mkrules.mk:85: build-rapid0_eps/shared-bindings/spitarget/__init__.o] Error 1 From 616ec376e91d39e728091b9bcc7cd2ae57898952 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 00:11:53 -0700 Subject: [PATCH 30/55] fix the type of self within spitarget --- ports/atmel-samd/common-hal/spitarget/SPITarget.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index 2b0c885c0219d..c7cfce2f218d8 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -3,7 +3,7 @@ #include "hpl_sercom_config.h" #include "samd/sercom.h" -void common_hal_spitarget_spi_target_construct(busio_spi_obj_t *self, +void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss) { Sercom *sercom = NULL; @@ -146,7 +146,7 @@ void common_hal_spitarget_spi_target_construct(busio_spi_obj_t *self, spi_m_sync_enable(&self->spi_desc); } -void common_hal_spitarget_spi_target_deinit(busio_spi_obj_t *self) { +void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self) { if (common_hal_busio_spi_deinited(self)) { return; } @@ -161,11 +161,11 @@ void common_hal_spitarget_spi_target_deinit(busio_spi_obj_t *self) { self->clock_pin = NO_PIN; } -void common_hal_spitarget_spi_target_deinited(busio_spi_obj_t *self) { +void common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self) { return self->clock_pin == NO_PIN; } -void common_hal_spitarget_spi_target_transfer_start(busio_spi_obj_t *self, +void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, uint8_t *miso_packet, uint8_t *mosi_packet, size_t len) { if (len == 0) { return; @@ -209,11 +209,11 @@ void common_hal_spitarget_spi_target_transfer_start(busio_spi_obj_t *self, } } -bool common_hal_spitarget_spi_target_transfer_is_finished(busio_spi_obj_t *self) { +bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self) { return self->running_dma.failure == 1 || shared_dma_transfer_finished(self->running_dma); } -void common_hal_spitarget_spi_target_transfer_close(busio_spi_obj_t *self) { +void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self) { if (self->running_dma.failure == 1) { return 0; } From 114d49eb60168d08f307c2d7d7784cb6b71a8d26 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 00:34:00 -0700 Subject: [PATCH 31/55] fix import errors and transfer_close return typing --- .../common-hal/spitarget/SPITarget.c | 17 +- shared-bindings/spitarget/SPITarget.c | 2 +- shared-bindings/spitarget/SPITarget.h | 2 +- stderr.txt | 339 ------------------ 4 files changed, 16 insertions(+), 344 deletions(-) delete mode 100644 stderr.txt diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index c7cfce2f218d8..1234d77e0f1f4 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -1,5 +1,16 @@ #include "common-hal/spitarget/SPITarget.h" +#include "shared-bindings/spitarget/SPITarget.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "py/mperrno.h" +#include "py/runtime.h" + +#include "hpl_sercom_config.h" +#include "peripheral_clk_config.h" + +#include "hal/include/hal_gpio.h" +#include "hal/include/hal_spi_m_sync.h" + #include "hpl_sercom_config.h" #include "samd/sercom.h" @@ -47,7 +58,7 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, if (potential_sercom->SPI.CTRLA.bit.ENABLE != 0) { continue; } - clock_pinmux = PINMUX(clock->number, (i == 0) ? MUX_C : MUX_D); + clock_pinmux = PINMUX(sck->number, (i == 0) ? MUX_C : MUX_D); clock_pad = clock->sercom[i].pad; if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { continue; @@ -120,7 +131,7 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, gpio_set_pin_direction(clock->number, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); gpio_set_pin_function(clock->number, clock_pinmux); - claim_pin(clock); + claim_pin(sck); self->clock_pin = clock->number; gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_IN); @@ -213,7 +224,7 @@ bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_o return self->running_dma.failure == 1 || shared_dma_transfer_finished(self->running_dma); } -void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self) { +int common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self) { if (self->running_dma.failure == 1) { return 0; } diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index 886585820e38f..7fde05fadbcc5 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -177,7 +177,7 @@ STATIC mp_obj_t spitarget_spi_target_try_transfer(size_t n_args, const mp_obj_t do { if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { - common_hal_spitarget_spi_target_transfer_close(self); + common_hal_spitarget_spi_target_transfer_close(self); // implicitly discards error indicator code return mp_const_true; } mp_hal_delay_us(10); diff --git a/shared-bindings/spitarget/SPITarget.h b/shared-bindings/spitarget/SPITarget.h index d562b1db8c92b..0835d0f0d178b 100644 --- a/shared-bindings/spitarget/SPITarget.h +++ b/shared-bindings/spitarget/SPITarget.h @@ -42,6 +42,6 @@ extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, const uint8_t *mosi_packet, uint8_t *miso_packet, size_t len); extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); -extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); +extern int common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SPI_TARGET_H diff --git a/stderr.txt b/stderr.txt deleted file mode 100644 index 3ae4b68b7ce03..0000000000000 --- a/stderr.txt +++ /dev/null @@ -1,339 +0,0 @@ -In file included from ../../shared-bindings/spitarget/SPITarget.c:28: -../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' - 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' - 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' - 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' - 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' - 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' - 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ../../shared-bindings/spitarget/__init__.c:7: -../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' - 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' - 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' - 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' - 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_make_new': -../../shared-bindings/spitarget/SPITarget.c:61:5: error: unknown type name 'spitarget_spi_target_obj_t' - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' - 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./samd_peripherals_config.h:30, - from ./peripherals/samd/pins.h:38, - from ./common-hal/microcontroller/Pin.h:32, - from ../../shared-bindings/microcontroller/Pin.h:30, - from ../../shared-bindings/spitarget/SPITarget.c:27: -../../shared-bindings/spitarget/SPITarget.c:61:54: error: 'spitarget_spi_target_obj_t' undeclared (first use in this function); did you mean 'spitarget_spi_target_type'? - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:61:54: note: each undeclared identifier is reported only once for each function it appears in - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^~~~~~~~~~~ -../../py/obj.h:970:61: error: expected expression before ')' token - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^ -../../shared-bindings/spitarget/SPITarget.c:61:40: note: in expansion of macro 'mp_obj_malloc' - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:77:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_construct' [-Werror=implicit-function-declaration] - 77 | common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:77:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_construct' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' - 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -make: *** [../../py/mkrules.mk:85: build-rapid0_adcs/shared-bindings/spitarget/__init__.o] Error 1 -make: *** Waiting for unfinished jobs.... -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj_deinit': -../../shared-bindings/spitarget/SPITarget.c:86:5: error: unknown type name 'spitarget_spi_target_obj_t' - 86 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:87:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinit' [-Werror=implicit-function-declaration] - 87 | common_hal_spitarget_spi_target_deinit(self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:87:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinit' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj___exit__': -../../shared-bindings/spitarget/SPITarget.c:103:5: error: unknown type name 'spitarget_spi_target_obj_t' - 103 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': -../../shared-bindings/spitarget/SPITarget.c:117:5: error: unknown type name 'spitarget_spi_target_obj_t' - 117 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:118:9: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinited' [-Werror=implicit-function-declaration] - 118 | if (common_hal_spitarget_spi_target_deinited(self)) { - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:118:9: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinited' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c:139:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_start' [-Werror=implicit-function-declaration] - 139 | common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:139:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_start' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_try_transfer': -../../shared-bindings/spitarget/SPITarget.c:152:5: error: unknown type name 'spitarget_spi_target_obj_t' - 152 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:179:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=implicit-function-declaration] - 179 | if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:179:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c:180:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_close' [-Werror=implicit-function-declaration] - 180 | common_hal_spitarget_spi_target_transfer_close(self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:180:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_close' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': -../../shared-bindings/spitarget/SPITarget.c:140:1: error: control reaches end of non-void function [-Werror=return-type] - 140 | } - | ^ -cc1: all warnings being treated as errors -make: *** [../../py/mkrules.mk:85: build-rapid0_adcs/shared-bindings/spitarget/SPITarget.o] Error 1 -In file included from ../../shared-bindings/spitarget/SPITarget.c:28: -../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' - 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' - 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' - 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' - 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' - 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' - 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ../../shared-bindings/spitarget/__init__.c:7: -../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' - 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' - 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' - 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' - 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' - 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' - 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -make: *** [../../py/mkrules.mk:85: build-rapid0_cdh/shared-bindings/spitarget/__init__.o] Error 1 -make: *** Waiting for unfinished jobs.... -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_make_new': -../../shared-bindings/spitarget/SPITarget.c:61:5: error: unknown type name 'spitarget_spi_target_obj_t' - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./samd_peripherals_config.h:30, - from ./peripherals/samd/pins.h:38, - from ./common-hal/microcontroller/Pin.h:32, - from ../../shared-bindings/microcontroller/Pin.h:30, - from ../../shared-bindings/spitarget/SPITarget.c:27: -../../shared-bindings/spitarget/SPITarget.c:61:54: error: 'spitarget_spi_target_obj_t' undeclared (first use in this function); did you mean 'spitarget_spi_target_type'? - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:61:54: note: each undeclared identifier is reported only once for each function it appears in - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^~~~~~~~~~~ -../../py/obj.h:970:61: error: expected expression before ')' token - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^ -../../shared-bindings/spitarget/SPITarget.c:61:40: note: in expansion of macro 'mp_obj_malloc' - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:77:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_construct' [-Werror=implicit-function-declaration] - 77 | common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:77:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_construct' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj_deinit': -../../shared-bindings/spitarget/SPITarget.c:86:5: error: unknown type name 'spitarget_spi_target_obj_t' - 86 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:87:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinit' [-Werror=implicit-function-declaration] - 87 | common_hal_spitarget_spi_target_deinit(self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:87:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinit' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj___exit__': -../../shared-bindings/spitarget/SPITarget.c:103:5: error: unknown type name 'spitarget_spi_target_obj_t' - 103 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': -../../shared-bindings/spitarget/SPITarget.c:117:5: error: unknown type name 'spitarget_spi_target_obj_t' - 117 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:118:9: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinited' [-Werror=implicit-function-declaration] - 118 | if (common_hal_spitarget_spi_target_deinited(self)) { - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:118:9: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinited' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c:139:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_start' [-Werror=implicit-function-declaration] - 139 | common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:139:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_start' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_try_transfer': -../../shared-bindings/spitarget/SPITarget.c:152:5: error: unknown type name 'spitarget_spi_target_obj_t' - 152 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:179:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=implicit-function-declaration] - 179 | if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:179:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c:180:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_close' [-Werror=implicit-function-declaration] - 180 | common_hal_spitarget_spi_target_transfer_close(self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:180:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_close' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': -../../shared-bindings/spitarget/SPITarget.c:140:1: error: control reaches end of non-void function [-Werror=return-type] - 140 | } - | ^ -cc1: all warnings being treated as errors -make: *** [../../py/mkrules.mk:85: build-rapid0_cdh/shared-bindings/spitarget/SPITarget.o] Error 1 -In file included from ../../shared-bindings/spitarget/SPITarget.c:28: -../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' - 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' - 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' - 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' - 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' - 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' - 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_make_new': -../../shared-bindings/spitarget/SPITarget.c:61:5: error: unknown type name 'spitarget_spi_target_obj_t' - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./samd_peripherals_config.h:30, - from ./peripherals/samd/pins.h:38, - from ./common-hal/microcontroller/Pin.h:32, - from ../../shared-bindings/microcontroller/Pin.h:30, - from ../../shared-bindings/spitarget/SPITarget.c:27: -../../shared-bindings/spitarget/SPITarget.c:61:54: error: 'spitarget_spi_target_obj_t' undeclared (first use in this function); did you mean 'spitarget_spi_target_type'? - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:61:54: note: each undeclared identifier is reported only once for each function it appears in - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../py/obj.h:970:48: note: in definition of macro 'mp_obj_malloc' - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^~~~~~~~~~~ -../../py/obj.h:970:61: error: expected expression before ')' token - 970 | #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) - | ^ -../../shared-bindings/spitarget/SPITarget.c:61:40: note: in expansion of macro 'mp_obj_malloc' - 61 | spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); - | ^~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:77:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_construct' [-Werror=implicit-function-declaration] - 77 | common_hal_spitarget_spi_target_construct(self, sck, mosi, miso, ss); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:77:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_construct' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj_deinit': -../../shared-bindings/spitarget/SPITarget.c:86:5: error: unknown type name 'spitarget_spi_target_obj_t' - 86 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:87:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinit' [-Werror=implicit-function-declaration] - 87 | common_hal_spitarget_spi_target_deinit(self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:87:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinit' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_obj___exit__': -../../shared-bindings/spitarget/SPITarget.c:103:5: error: unknown type name 'spitarget_spi_target_obj_t' - 103 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': -../../shared-bindings/spitarget/SPITarget.c:117:5: error: unknown type name 'spitarget_spi_target_obj_t' - 117 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:118:9: error: implicit declaration of function 'common_hal_spitarget_spi_target_deinited' [-Werror=implicit-function-declaration] - 118 | if (common_hal_spitarget_spi_target_deinited(self)) { - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:118:9: error: nested extern declaration of 'common_hal_spitarget_spi_target_deinited' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c:139:5: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_start' [-Werror=implicit-function-declaration] - 139 | common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:139:5: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_start' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_try_transfer': -../../shared-bindings/spitarget/SPITarget.c:152:5: error: unknown type name 'spitarget_spi_target_obj_t' - 152 | spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:179:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=implicit-function-declaration] - 179 | if (common_hal_spitarget_spi_target_transfer_is_finished(self)) { - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:179:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_is_finished' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c:180:13: error: implicit declaration of function 'common_hal_spitarget_spi_target_transfer_close' [-Werror=implicit-function-declaration] - 180 | common_hal_spitarget_spi_target_transfer_close(self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.c:180:13: error: nested extern declaration of 'common_hal_spitarget_spi_target_transfer_close' [-Werror=nested-externs] -../../shared-bindings/spitarget/SPITarget.c: In function 'spitarget_spi_target_load_packet': -../../shared-bindings/spitarget/SPITarget.c:140:1: error: control reaches end of non-void function [-Werror=return-type] - 140 | } - | ^ -cc1: all warnings being treated as errors -make: *** [../../py/mkrules.mk:85: build-rapid0_eps/shared-bindings/spitarget/SPITarget.o] Error 1 -make: *** Waiting for unfinished jobs.... -In file included from ../../shared-bindings/spitarget/__init__.c:7: -../../shared-bindings/spitarget/SPITarget.h:37:55: error: unknown type name 'spitarget_spi_target_obj_t' - 37 | extern void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:39:52: error: unknown type name 'spitarget_spi_target_obj_t' - 39 | extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:40:54: error: unknown type name 'spitarget_spi_target_obj_t' - 40 | extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:42:60: error: unknown type name 'spitarget_spi_target_obj_t' - 42 | extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:44:66: error: unknown type name 'spitarget_spi_target_obj_t' - 44 | extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -../../shared-bindings/spitarget/SPITarget.h:45:60: error: unknown type name 'spitarget_spi_target_obj_t' - 45 | extern void common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~ -make: *** [../../py/mkrules.mk:85: build-rapid0_eps/shared-bindings/spitarget/__init__.o] Error 1 From 5657f8aa670fdaff6f555ea4b45df32e40ecea6e Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 00:45:03 -0700 Subject: [PATCH 32/55] fix typing and naming mismatches --- .../atmel-samd/common-hal/spitarget/SPITarget.c | 16 ++++++++-------- shared-bindings/spitarget/SPITarget.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index 1234d77e0f1f4..66ce9413d988c 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -34,7 +34,7 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, // Special case for SAMR21 boards. (feather_radiofruit_zigbee) #if defined(PIN_PC19F_SERCOM4_PAD0) if (miso == &pin_PC19) { - if (mosi == &pin_PB30 && clock == &pin_PC18) { + if (mosi == &pin_PB30 && sck == &pin_PC18) { sercom = SERCOM4; sercom_index = 4; clock_pinmux = MUX_F; @@ -59,7 +59,7 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, continue; } clock_pinmux = PINMUX(sck->number, (i == 0) ? MUX_C : MUX_D); - clock_pad = clock->sercom[i].pad; + clock_pad = sck->sercom[i].pad; if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { continue; } @@ -128,11 +128,11 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, mp_raise_OSError(MP_EIO); } - gpio_set_pin_direction(clock->number, GPIO_DIRECTION_IN); - gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); - gpio_set_pin_function(clock->number, clock_pinmux); + gpio_set_pin_direction(sck->number, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(sck->number, GPIO_PULL_OFF); + gpio_set_pin_function(sck->number, clock_pinmux); claim_pin(sck); - self->clock_pin = clock->number; + self->clock_pin = sck->number; gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); @@ -172,12 +172,12 @@ void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self) { self->clock_pin = NO_PIN; } -void common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self) { +bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self) { return self->clock_pin == NO_PIN; } void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - uint8_t *miso_packet, uint8_t *mosi_packet, size_t len) { + uint8_t *mosi_packet, const uint8_t *miso_packet, size_t len) { if (len == 0) { return; } diff --git a/shared-bindings/spitarget/SPITarget.h b/shared-bindings/spitarget/SPITarget.h index 0835d0f0d178b..bbfb0f9942eba 100644 --- a/shared-bindings/spitarget/SPITarget.h +++ b/shared-bindings/spitarget/SPITarget.h @@ -40,7 +40,7 @@ extern void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *s extern bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self); extern void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, - const uint8_t *mosi_packet, uint8_t *miso_packet, size_t len); + uint8_t *mosi_packet, const uint8_t *miso_packet, size_t len); extern bool common_hal_spitarget_spi_target_transfer_is_finished(spitarget_spi_target_obj_t *self); extern int common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *self); From 1aad3994cb6daf8acfc61fead939c058dfc4799b Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 01:02:36 -0700 Subject: [PATCH 33/55] ok this is the one --- ports/atmel-samd/common-hal/spitarget/SPITarget.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index 66ce9413d988c..fc6f7f7949569 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -1,4 +1,5 @@ #include "common-hal/spitarget/SPITarget.h" +#include "common-hal/busio/__init__.h" #include "shared-bindings/spitarget/SPITarget.h" #include "shared-bindings/microcontroller/Pin.h" @@ -157,6 +158,10 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, spi_m_sync_enable(&self->spi_desc); } +bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self) { + return self->clock_pin == NO_PIN; +} + void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self) { if (common_hal_busio_spi_deinited(self)) { return; @@ -172,10 +177,6 @@ void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self) { self->clock_pin = NO_PIN; } -bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self) { - return self->clock_pin == NO_PIN; -} - void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, uint8_t *mosi_packet, const uint8_t *miso_packet, size_t len) { if (len == 0) { From ff2fb909aa60a763d1d57096831a0b42786f1b7b Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 01:10:21 -0700 Subject: [PATCH 34/55] fix function name mismatch between call and declaration --- ports/atmel-samd/common-hal/spitarget/SPITarget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index fc6f7f7949569..0252436df7d08 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -163,7 +163,7 @@ bool common_hal_spitarget_spi_target_deinited(spitarget_spi_target_obj_t *self) } void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self) { - if (common_hal_busio_spi_deinited(self)) { + if (common_hal_spitarget_spi_target_deinited(self)) { return; } allow_reset_sercom(self->spi_desc.dev.prvt); From dd7056bb72ee9e3777126ba8a5445c87a81c31ec Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Fri, 1 Nov 2024 01:16:18 -0700 Subject: [PATCH 35/55] return none from bound functions --- shared-bindings/spitarget/SPITarget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index 7fde05fadbcc5..5ba465239af88 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -137,6 +137,7 @@ STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t * } common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spitarget_spi_target_load_packet); From 1875e70dd0fddf67e5e1ced3c7930c6de121d1a1 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 5 Nov 2024 12:23:44 -0800 Subject: [PATCH 36/55] fix buffer mishandling in spitarget bindings --- shared-bindings/spitarget/SPITarget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index 5ba465239af88..e9de54f2b4e4f 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -127,16 +127,16 @@ STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t * mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t mosi_bufinfo; - mp_get_buffer_raise(args[ARG_mosi_packet].u_obj, &mosi_bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_mosi_packet].u_obj, &mosi_bufinfo, MP_BUFFER_WRITE); mp_buffer_info_t miso_bufinfo; - mp_get_buffer_raise(args[ARG_mosi_packet].u_obj, &miso_bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_miso_packet].u_obj, &miso_bufinfo, MP_BUFFER_READ); if (miso_bufinfo.len != mosi_bufinfo.len) { mp_raise_ValueError(MP_ERROR_TEXT("Packet buffers for an SPI transfer must have the same length.")); } - common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)miso_bufinfo.buf), ((uint8_t *)mosi_bufinfo.buf), miso_bufinfo.len); + common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)mosi_bufinfo.buf), ((uint8_t *)miso_bufinfo.buf), mosi_bufinfo.len); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spitarget_spi_target_load_packet); From 0a68f4329c2e0ecfe4f5e4e5ecf82c8bf3f48ee6 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 5 Nov 2024 20:59:05 -0800 Subject: [PATCH 37/55] remove busio.SPI --- ports/atmel-samd/common-hal/busio/SPI.c | 123 ++++++------------------ ports/atmel-samd/common-hal/busio/SPI.h | 2 - shared-bindings/busio/SPI.c | 19 +--- 3 files changed, 33 insertions(+), 111 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 26613b41bbd4a..5d03e74fd15aa 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -42,8 +42,7 @@ #include "samd/sercom.h" void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { Sercom *sercom = NULL; uint8_t sercom_index; uint32_t clock_pinmux = 0; @@ -51,7 +50,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, bool miso_none = miso == NULL; uint32_t mosi_pinmux = 0; uint32_t miso_pinmux = 0; - uint32_t ss_pinmux = 0; uint8_t clock_pad = 0; uint8_t mosi_pad = 0; uint8_t miso_pad = 0; @@ -96,87 +94,36 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { continue; } - if (slave_mode) { - // find miso_pad first, since it corresponds to dopo which takes limited values - for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { - if (!miso_none) { - if (sercom_index == miso->sercom[j].index) { - miso_pinmux = PINMUX(miso->number, (j == 0) ? MUX_C : MUX_D); - miso_pad = miso->sercom[j].pad; - dopo = samd_peripherals_get_spi_dopo(clock_pad, miso_pad); - if (dopo > 0x3) { - continue; // pad combination not possible - } - if (mosi_none) { - for (int m = 0; m < NUM_SERCOMS_PER_PIN; m++) { - if (sercom_index == ss->sercom[m].index) { - ss_pinmux = PINMUX(ss->number, (m == 0) ? MUX_C : MUX_D); - sercom = potential_sercom; - break; - } - } - if (sercom != NULL) { - break; - } - } - } else { - continue; + // find mosi_pad first, since it corresponds to dopo which takes limited values + for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { + if (!mosi_none) { + if (sercom_index == mosi->sercom[j].index) { + mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D); + mosi_pad = mosi->sercom[j].pad; + dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); + if (dopo > 0x3) { + continue; // pad combination not possible } - } - if (!mosi_none) { - for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { - if (sercom_index == mosi->sercom[k].index) { - mosi_pinmux = PINMUX(mosi->number, (k == 0) ? MUX_C : MUX_D); - mosi_pad = mosi->sercom[k].pad; - for (int m = 0; m < NUM_SERCOMS_PER_PIN; m++) { - if (sercom_index == ss->sercom[m].index) { - ss_pinmux = PINMUX(ss->number, (m == 0) ? MUX_C : MUX_D); - sercom = potential_sercom; - break; - } - } - if (sercom != NULL) { - break; - } - } + if (miso_none) { + sercom = potential_sercom; + break; } - } - if (sercom != NULL) { - break; + } else { + continue; } } - } else { - // find mosi_pad first, since it corresponds to dopo which takes limited values - for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { - if (!mosi_none) { - if (sercom_index == mosi->sercom[j].index) { - mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D); - mosi_pad = mosi->sercom[j].pad; - dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); - if (dopo > 0x3) { - continue; // pad combination not possible - } - if (miso_none) { - sercom = potential_sercom; - break; - } - } else { - continue; - } - } - if (!miso_none) { - for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { - if (sercom_index == miso->sercom[k].index) { - miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D); - miso_pad = miso->sercom[k].pad; - sercom = potential_sercom; - break; - } + if (!miso_none) { + for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { + if (sercom_index == miso->sercom[k].index) { + miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D); + miso_pad = miso->sercom[k].pad; + sercom = potential_sercom; + break; } } - if (sercom != NULL) { - break; - } + } + if (sercom != NULL) { + break; } } if (sercom != NULL) { @@ -198,11 +145,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // Pads must be set after spi_m_sync_init(), which uses default values from // the prototypical SERCOM. - hri_sercomspi_write_CTRLA_MODE_bf(sercom, slave_mode ? 2 : 3); - self->slave_mode = slave_mode; + hri_sercomspi_write_CTRLA_MODE_bf(sercom, 3); hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); - hri_sercomspi_write_CTRLA_DIPO_bf(sercom, slave_mode ? mosi_pad : miso_pad); - hri_sercomspi_write_CTRLB_PLOADEN_bit(sercom, slave_mode); + hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); // Always start at 250khz which is what SD cards need. They are sensitive to // SPI bus noise before they are put into SPI mode. @@ -213,7 +158,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, mp_raise_OSError(MP_EIO); } - gpio_set_pin_direction(clock->number, slave_mode ? GPIO_DIRECTION_IN : GPIO_DIRECTION_OUT); + gpio_set_pin_direction(clock->number, GPIO_DIRECTION_OUT); gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); gpio_set_pin_function(clock->number, clock_pinmux); claim_pin(clock); @@ -222,7 +167,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (mosi_none) { self->MOSI_pin = NO_PIN; } else { - gpio_set_pin_direction(mosi->number, slave_mode ? GPIO_DIRECTION_IN : GPIO_DIRECTION_OUT); + gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_OUT); gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); gpio_set_pin_function(mosi->number, mosi_pinmux); self->MOSI_pin = mosi->number; @@ -232,21 +177,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (miso_none) { self->MISO_pin = NO_PIN; } else { - gpio_set_pin_direction(miso->number, slave_mode ? GPIO_DIRECTION_OUT : GPIO_DIRECTION_IN); + gpio_set_pin_direction(miso->number, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF); gpio_set_pin_function(miso->number, miso_pinmux); self->MISO_pin = miso->number; claim_pin(miso); } - if (slave_mode) { - gpio_set_pin_direction(ss->number, slave_mode ? GPIO_DIRECTION_OUT : GPIO_DIRECTION_IN); - gpio_set_pin_pull_mode(ss->number, GPIO_PULL_OFF); - gpio_set_pin_function(ss->number, ss_pinmux); - self->SS_pin = ss->number; - claim_pin(ss); - } - self->running_dma.failure = 1; // not started spi_m_sync_enable(&self->spi_desc); diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 95cc8d379f08a..587d534cbe738 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -40,8 +40,6 @@ typedef struct { uint8_t clock_pin; uint8_t MOSI_pin; uint8_t MISO_pin; - uint8_t SS_pin; - bool slave_mode; dma_descr_t running_dma; } busio_spi_obj_t; diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index f9036af3e6595..b58ffa5db825c 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -73,9 +73,7 @@ //| clock: microcontroller.Pin, //| MOSI: Optional[microcontroller.Pin] = None, //| MISO: Optional[microcontroller.Pin] = None, -//| SS: Optional[microcontroller.Pin] = None, -//| half_duplex: bool = False, -//| slave_mode: bool = False, +//| half_duplex: bool = False //| ) -> None: //| """Construct an SPI object on the given pins. //| @@ -98,10 +96,8 @@ //| :param ~microcontroller.Pin MOSI: the Main Out Selected In pin. //| :param ~microcontroller.Pin MISO: the Main In Selected Out pin. //| :param bool half_duplex: True when MOSI is used for bidirectional data. False when SPI is full-duplex or simplex. -//| :param-bool slave_mode: True when the chip is operating as a slave. False when the chip is operating as a master. //| //| **Limitations:** ``half_duplex`` is available only on STM; other chips do not have the hardware support. -//| **Limitations:** ``slave_mode`` is available only on SAMD51; other chips do not have the firmware support. //| """ //| ... @@ -110,14 +106,12 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BUSIO_SPI busio_spi_obj_t *self = mp_obj_malloc(busio_spi_obj_t, &busio_spi_type); - enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_SS, ARG_half_duplex, ARG_slave_mode }; + enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_half_duplex }; static const mp_arg_t allowed_args[] = { { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_MOSI, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_SS, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, - { MP_QSTR_slave_mode, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -125,19 +119,12 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock); const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj, MP_QSTR_mosi); const mcu_pin_obj_t *miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj, MP_QSTR_miso); - const mcu_pin_obj_t *ss = validate_obj_is_free_pin_or_none(args[ARG_SS].u_obj, MP_QSTR_ss); if (!miso && !mosi) { mp_raise_ValueError(MP_ERROR_TEXT("Must provide MISO or MOSI pin")); } - if (args[ARG_slave_mode].u_bool && !ss) { - mp_raise_ValueError(MP_ERROR_TEXT("Must provide SS pin to operate in slave mode")); - } - if (!args[ARG_slave_mode].u_bool && ss) { - mp_raise_ValueError(MP_ERROR_TEXT("Hardware SS pin only supported for slave mode")); - } - common_hal_busio_spi_construct(self, clock, mosi, miso, ss, args[ARG_half_duplex].u_bool, args[ARG_slave_mode].u_bool); + common_hal_busio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool); return MP_OBJ_FROM_PTR(self); #else raise_ValueError_invalid_pins(); From ea344c3a9c774835af842e11bb0081a53c253fbf Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 5 Nov 2024 21:40:46 -0800 Subject: [PATCH 38/55] repair constructors referencing old API --- ports/atmel-samd/boards/hallowing_m4_express/board.c | 2 +- ports/atmel-samd/boards/monster_m4sk/board.c | 2 +- ports/atmel-samd/boards/openbook_m4/board.c | 2 +- ports/atmel-samd/boards/pewpew_lcd/board.c | 2 +- ports/atmel-samd/boards/pewpew_m4/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- ports/atmel-samd/boards/pygamer/board.c | 2 +- ports/atmel-samd/boards/seeeduino_wio_terminal/board.c | 2 +- ports/broadcom/common-hal/busio/SPI.c | 6 +----- ports/cxd56/common-hal/busio/SPI.c | 5 +---- ports/espressif/boards/adafruit_funhouse/board.c | 2 +- .../espressif/boards/adafruit_magtag_2.9_grayscale/board.c | 2 +- ports/espressif/boards/espressif_esp32s3_box/board.c | 2 +- ports/espressif/boards/espressif_esp32s3_box_lite/board.c | 2 +- ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c | 2 +- ports/espressif/boards/hardkernel_odroid_go/board.c | 2 +- ports/espressif/boards/hiibot_iots2/board.c | 4 +--- ports/espressif/boards/lilygo_tembed_esp32s3/board.c | 2 +- ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c | 4 +--- .../espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c | 4 +--- ports/espressif/boards/lilygo_twatch_2020_v3/board.c | 4 +--- ports/espressif/boards/m5stack_atoms3/board.c | 2 +- ports/espressif/boards/m5stack_stick_c/board.c | 2 +- ports/espressif/boards/m5stack_stick_c_plus/board.c | 2 +- ports/espressif/boards/morpheans_morphesp-240/board.c | 4 +--- ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c | 4 +--- ports/espressif/common-hal/busio/SPI.c | 6 +----- ports/mimxrt10xx/common-hal/busio/SPI.c | 6 +----- ports/nrf/boards/clue_nrf52840_express/board.c | 2 +- ports/nrf/boards/espruino_banglejs2/board.c | 2 +- ports/nrf/boards/hiibot_bluefi/board.c | 2 +- ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c | 2 +- ports/nrf/boards/ohs2020_badge/board.c | 2 +- ports/nrf/common-hal/busio/SPI.c | 5 +---- ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c | 2 +- ports/raspberrypi/boards/hack_club_sprig/board.c | 2 +- ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c | 4 +--- ports/raspberrypi/boards/pajenicko_picopad/board.c | 2 +- ports/raspberrypi/boards/pimoroni_badger2040/board.c | 2 +- ports/raspberrypi/boards/pimoroni_picosystem/board.c | 2 +- ports/raspberrypi/boards/ugame22/board.c | 2 +- ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c | 4 +--- ports/raspberrypi/common-hal/busio/SPI.c | 6 +----- ports/silabs/common-hal/busio/SPI.c | 6 +----- ports/stm/common-hal/busio/SPI.c | 6 +----- shared-bindings/busio/SPI.h | 3 +-- shared-module/board/__init__.c | 2 +- supervisor/shared/external_flash/spi_flash.c | 2 +- supervisor/shared/status_leds.c | 2 -- 49 files changed, 48 insertions(+), 97 deletions(-) diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index d8218d7151aa1..82d8cea619b6a 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index 2b015443ddeec..34948b6a34b5a 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index 079544f42b996..d6911c7a07c3a 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -59,7 +59,7 @@ uint8_t refresh_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pewpew_lcd/board.c b/ports/atmel-samd/boards/pewpew_lcd/board.c index f7357d6908826..3e1a1c1cf62c5 100644 --- a/ports/atmel-samd/boards/pewpew_lcd/board.c +++ b/ports/atmel-samd/boards/pewpew_lcd/board.c @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index e55ef0899a0fc..ba37a9ddcea89 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -99,7 +99,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index b1063eb4767cb..8314f354a2967 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 57b6d58f7cf7d..746298f578fe6 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c index 077d6c2262c7b..a4e563017a581 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c @@ -67,7 +67,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/broadcom/common-hal/busio/SPI.c b/ports/broadcom/common-hal/busio/SPI.c index 62a1bb5ce091c..238c550615e56 100644 --- a/ports/broadcom/common-hal/busio/SPI.c +++ b/ports/broadcom/common-hal/busio/SPI.c @@ -76,8 +76,7 @@ void reset_spi(void) { } void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { size_t instance_index = NUM_SPI; BP_Function_Enum clock_alt = 0; BP_Function_Enum mosi_alt = 0; @@ -86,9 +85,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Half duplex SPI is not implemented")); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } // BCM_VERSION != 2711 have 3 SPI but as listed in peripherals/gen/pins.c two are on // index 0, once one index 0 SPI is found the other will throw an invalid_pins error. diff --git a/ports/cxd56/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c index 9a8212fc347b1..5131028665c01 100644 --- a/ports/cxd56/common-hal/busio/SPI.c +++ b/ports/cxd56/common-hal/busio/SPI.c @@ -36,15 +36,12 @@ #include "shared-bindings/microcontroller/Pin.h" void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, - const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { int port = -1; if (half_duplex) { mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_half_duplex); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } if (clock->number == PIN_SPI4_SCK && (mosi == NULL || mosi->number == PIN_SPI4_MOSI) && diff --git a/ports/espressif/boards/adafruit_funhouse/board.c b/ports/espressif/boards/adafruit_funhouse/board.c index 761a478daaea3..a19ceda837732 100644 --- a/ports/espressif/boards/adafruit_funhouse/board.c +++ b/ports/espressif/boards/adafruit_funhouse/board.c @@ -52,7 +52,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index 3d21b3f8bda32..841c241b31c38 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -116,7 +116,7 @@ const uint8_t refresh_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_box/board.c b/ports/espressif/boards/espressif_esp32s3_box/board.c index a3f3de39ea1dc..3ab932c83ae02 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box/board.c @@ -45,7 +45,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c index 818f290c08da5..fe9cc993e8030 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c @@ -46,7 +46,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c index 25bf86c43534e..3dd272b622adf 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c @@ -73,7 +73,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/hardkernel_odroid_go/board.c b/ports/espressif/boards/hardkernel_odroid_go/board.c index 4c3d4fa4bb0f8..141a891d57390 100644 --- a/ports/espressif/boards/hardkernel_odroid_go/board.c +++ b/ports/espressif/boards/hardkernel_odroid_go/board.c @@ -65,7 +65,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/hiibot_iots2/board.c b/ports/espressif/boards/hiibot_iots2/board.c index cc453f16b52c7..fbad7dc605ee6 100644 --- a/ports/espressif/boards/hiibot_iots2/board.c +++ b/ports/espressif/boards/hiibot_iots2/board.c @@ -73,9 +73,7 @@ static void display_init(void) { &pin_GPIO34, // CLK &pin_GPIO33, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c index d77508380bfac..8039f618f0c28 100644 --- a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c +++ b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c @@ -45,7 +45,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c index d9de096982e58..4abcc75a1c612 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c @@ -73,9 +73,7 @@ static void display_init(void) { &pin_GPIO36, // CLK &pin_GPIO35, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c index 0ccff151d36a8..adee839ccaaf5 100644 --- a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c +++ b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c @@ -53,9 +53,7 @@ static void display_init(void) { &pin_GPIO18, // CLK &pin_GPIO19, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c index 25bd47d130f94..4952093652686 100644 --- a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c +++ b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c @@ -56,9 +56,7 @@ static void display_init(void) { &pin_GPIO18, // CLK &pin_GPIO19, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/m5stack_atoms3/board.c b/ports/espressif/boards/m5stack_atoms3/board.c index aff7d3d30a8aa..1b46c9510756b 100644 --- a/ports/espressif/boards/m5stack_atoms3/board.c +++ b/ports/espressif/boards/m5stack_atoms3/board.c @@ -53,7 +53,7 @@ void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; // busio_spi_obj_t *spi = common_hal_board_create_spi(0); busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO17, &pin_GPIO21, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/m5stack_stick_c/board.c b/ports/espressif/boards/m5stack_stick_c/board.c index 3ab7c5f03e975..4d33b21c583b3 100644 --- a/ports/espressif/boards/m5stack_stick_c/board.c +++ b/ports/espressif/boards/m5stack_stick_c/board.c @@ -167,7 +167,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/m5stack_stick_c_plus/board.c b/ports/espressif/boards/m5stack_stick_c_plus/board.c index 610262dbe01d1..6d58e3a0a4276 100644 --- a/ports/espressif/boards/m5stack_stick_c_plus/board.c +++ b/ports/espressif/boards/m5stack_stick_c_plus/board.c @@ -167,7 +167,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/espressif/boards/morpheans_morphesp-240/board.c b/ports/espressif/boards/morpheans_morphesp-240/board.c index 73d7b279ba4d4..97ee6207b34da 100644 --- a/ports/espressif/boards/morpheans_morphesp-240/board.c +++ b/ports/espressif/boards/morpheans_morphesp-240/board.c @@ -149,9 +149,7 @@ void board_init(void) { &pin_GPIO12, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c index 6e2ef5c17dcea..c5b8e340f07ad 100644 --- a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c +++ b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c @@ -72,9 +72,7 @@ static void display_init(void) { &pin_GPIO10, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/espressif/common-hal/busio/SPI.c b/ports/espressif/common-hal/busio/SPI.c index e3a214b8cb701..ffe8d41c79988 100644 --- a/ports/espressif/common-hal/busio/SPI.c +++ b/ports/espressif/common-hal/busio/SPI.c @@ -76,8 +76,7 @@ static void set_spi_config(busio_spi_obj_t *self, } void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { const spi_bus_config_t bus_config = { .mosi_io_num = mosi != NULL ? mosi->number : -1, @@ -90,9 +89,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_half_duplex); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } for (spi_host_device_t host_id = SPI2_HOST; host_id < SOC_SPI_PERIPH_NUM; host_id++) { if (spi_bus_is_free(host_id)) { diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index ead30396231c8..0fba94b40b51a 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -90,8 +90,7 @@ void spi_reset(void) { } void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { const uint32_t sck_count = MP_ARRAY_SIZE(mcu_spi_sck_list); const uint32_t miso_count = MP_ARRAY_SIZE(mcu_spi_sdi_list); @@ -101,9 +100,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (half_duplex) { mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_half_duplex); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } for (uint i = 0; i < sck_count; i++) { if (mcu_spi_sck_list[i].pin != clock) { diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index f013f646ad014..4478e0f3ba29a 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/espruino_banglejs2/board.c b/ports/nrf/boards/espruino_banglejs2/board.c index f3213d1508aa7..dc741744c8536 100644 --- a/ports/nrf/boards/espruino_banglejs2/board.c +++ b/ports/nrf/boards/espruino_banglejs2/board.c @@ -52,7 +52,7 @@ void board_init(void) { fb->base.type = &sharpdisplay_framebuffer_type; busio_spi_obj_t *spi = &fb->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_26, &pin_P0_27, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_26, &pin_P0_27, NULL, false); common_hal_busio_spi_never_reset(spi); common_hal_sharpdisplay_framebuffer_construct(fb, spi, &pin_P0_05, 500000, 176, 176, true); diff --git a/ports/nrf/boards/hiibot_bluefi/board.c b/ports/nrf/boards/hiibot_bluefi/board.c index 400f601646811..d07b31673339e 100644 --- a/ports/nrf/boards/hiibot_bluefi/board.c +++ b/ports/nrf/boards/hiibot_bluefi/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, NULL, false, false); // SCK, MOSI, MISO, not half-duplex + common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, false); // SCK, MOSI, MISO, not half-duplex common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c index bd94cd8cf99ea..a22d96e95980b 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c +++ b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 3c69db91504d9..7b48e1985dd77 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 5dbda51f72775..48fae8adc3eb6 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -143,14 +143,11 @@ static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) return 0; } -void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { +void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { if (half_duplex) { mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_half_duplex); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } // Find a free instance, with most desirable (highest freq and not shared) allocated first. self->spim_peripheral = NULL; diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 1b55f3744f093..0006b80260a96 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -61,7 +61,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/hack_club_sprig/board.c b/ports/raspberrypi/boards/hack_club_sprig/board.c index 0d3c56dab9512..e101e26d3dced 100644 --- a/ports/raspberrypi/boards/hack_club_sprig/board.c +++ b/ports/raspberrypi/boards/hack_club_sprig/board.c @@ -80,7 +80,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c b/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c index aee49e4baaa60..69320824ff0b8 100644 --- a/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c +++ b/ports/raspberrypi/boards/lilygo_t_display_rp2040/board.c @@ -74,9 +74,7 @@ static void display_init(void) { &pin_GPIO2, // CLK &pin_GPIO3, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/raspberrypi/boards/pajenicko_picopad/board.c b/ports/raspberrypi/boards/pajenicko_picopad/board.c index c361363068a48..c02c65d160e32 100644 --- a/ports/raspberrypi/boards/pajenicko_picopad/board.c +++ b/ports/raspberrypi/boards/pajenicko_picopad/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/pimoroni_badger2040/board.c b/ports/raspberrypi/boards/pimoroni_badger2040/board.c index 1b2263bece822..b602f8cb65ac8 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040/board.c @@ -276,7 +276,7 @@ void board_init(void) { // Set up the SPI object used to control the display fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); common_hal_busio_spi_never_reset(spi); // Set up the DisplayIO pin object diff --git a/ports/raspberrypi/boards/pimoroni_picosystem/board.c b/ports/raspberrypi/boards/pimoroni_picosystem/board.c index d733988f24f58..5ee79715930cd 100644 --- a/ports/raspberrypi/boards/pimoroni_picosystem/board.c +++ b/ports/raspberrypi/boards/pimoroni_picosystem/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/ugame22/board.c b/ports/raspberrypi/boards/ugame22/board.c index 8718c15c4ffc9..48a26f9da04de 100644 --- a/ports/raspberrypi/boards/ugame22/board.c +++ b/ports/raspberrypi/boards/ugame22/board.c @@ -66,7 +66,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; busio_spi_obj_t *spi = &bus->inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, NULL, false, false); + common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, false); common_hal_busio_spi_never_reset(spi); bus->base.type = &fourwire_fourwire_type; diff --git a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c index 65c8cd856eaac..31750619da45b 100644 --- a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c +++ b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c @@ -70,9 +70,7 @@ static void display_init(void) { &pin_GPIO10, // CLK &pin_GPIO11, // MOSI NULL, // MISO not connected - NULL, // SS not connected - false, // Not half-duplex - false // operate SPI bus as master + false // Not half-duplex ); common_hal_busio_spi_never_reset(spi); diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index 819f2d847bc97..f9060ec6414fe 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -53,16 +53,12 @@ void reset_spi(void) { } void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { size_t instance_index = NO_INSTANCE; if (half_duplex) { mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_half_duplex); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } if (clock->number % 4 == 2) { instance_index = (clock->number / 8) % 2; diff --git a/ports/silabs/common-hal/busio/SPI.c b/ports/silabs/common-hal/busio/SPI.c index b89edb714300d..ff41b89054774 100644 --- a/ports/silabs/common-hal/busio/SPI.c +++ b/ports/silabs/common-hal/busio/SPI.c @@ -53,17 +53,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, - const mcu_pin_obj_t *ss, - bool half_duplex, bool slave_mode) { + bool half_duplex) { Ecode_t sc = ECODE_OK; if (half_duplex) { mp_raise_NotImplementedError( MP_ERROR_TEXT("Half duplex SPI is not implemented")); } - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } if ((sck != NULL) && (mosi != NULL) && (miso != NULL)) { if (sck->function_list[FN_EUSART1_SCLK] == 1 diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index b0b401c077b3a..b6f0f0996c131 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -166,11 +166,7 @@ STATIC int check_pins(busio_spi_obj_t *self, } void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode) { - if (slave_mode) { - mp_raise_NotImplementedError(MP_ERROR_TEXT("Slave mode SPI is not implemented")); - } + const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { int periph_index = check_pins(self, sck, mosi, miso); SPI_TypeDef *SPIx = mcu_spi_banks[periph_index - 1]; diff --git a/shared-bindings/busio/SPI.h b/shared-bindings/busio/SPI.h index c56ed5dd463b5..7caae1f947951 100644 --- a/shared-bindings/busio/SPI.h +++ b/shared-bindings/busio/SPI.h @@ -37,8 +37,7 @@ extern const mp_obj_type_t busio_spi_type; // Construct an underlying SPI object. extern void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, - const mcu_pin_obj_t *miso, const mcu_pin_obj_t *ss, bool half_duplex, bool slave_mode); + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex); extern void common_hal_busio_spi_deinit(busio_spi_obj_t *self); extern bool common_hal_busio_spi_deinited(busio_spi_obj_t *self); diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index af56ec1a998df..08a9761ed5f7e 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -130,7 +130,7 @@ mp_obj_t common_hal_board_create_spi(const mp_int_t instance) { assert_pin_free(spi_pin[instance].mosi); assert_pin_free(spi_pin[instance].miso); - common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso, NULL, false, false); + common_hal_busio_spi_construct(self, spi_pin[instance].clock, spi_pin[instance].mosi, spi_pin[instance].miso, false); spi_obj_created[instance] = true; return &spi_obj[instance]; diff --git a/supervisor/shared/external_flash/spi_flash.c b/supervisor/shared/external_flash/spi_flash.c index 3911fb8801666..abff3437134d8 100644 --- a/supervisor/shared/external_flash/spi_flash.c +++ b/supervisor/shared/external_flash/spi_flash.c @@ -149,7 +149,7 @@ void spi_flash_init(void) { common_hal_digitalio_digitalinout_never_reset(&cs_pin); supervisor_flash_spi_bus.base.type = &busio_spi_type; - common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, NULL, false, false); + common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, false); common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus); common_hal_busio_spi_configure(&supervisor_flash_spi_bus, SPI_FLASH_MAX_BAUDRATE, 0, 0, 8); diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index c66747ad0df10..414b35dd41641 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -164,8 +164,6 @@ void status_led_init() { MICROPY_HW_APA102_SCK, MICROPY_HW_APA102_MOSI, NULL, - NULL, - false, false); #endif #if CIRCUITPY_BITBANG_APA102 From 100a0450098a3321dae9d4f7c1cd99fc80ba4a1c Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Wed, 6 Nov 2024 14:17:41 -0800 Subject: [PATCH 39/55] remove asynchronous interface under busio.SPI --- ports/atmel-samd/common-hal/busio/SPI.c | 56 --------- shared-bindings/busio/SPI.c | 146 ------------------------ shared-bindings/busio/SPI.h | 13 --- 3 files changed, 215 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 5d03e74fd15aa..7330442e6eb58 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -338,62 +338,6 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou return status >= 0; // Status is number of chars read or an error code < 0. } -void common_hal_busio_spi_transfer_async_start(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) { - if (len == 0) { - return; - } - if (self->running_dma.failure != 1) { - mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); - } - Sercom* sercom = self->spi_desc.dev.prvt; - self->running_dma = shared_dma_transfer_start(sercom, data_out, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, data_in, len, 0); - - // There is an issue where if an unexpected SPI transfer is received before the user calls "end" for the in-progress, expected - // transfer, the SERCOM has an error and gets confused. This can be detected from INTFLAG.ERROR. I think the code in - // ports/atmel-samd/peripherals/samd/dma.c at line 277 (as of this commit; it's the part that reads s->SPI.INTFLAG.bit.RXC and - // s->SPI.DATA.reg) is supposed to fix this, but experimentation seems to show that it does not in fact fix anything. Anyways, if - // the ERROR bit is set, let's just reset the peripheral and then setup the transfer again -- that seems to work. - if (hri_sercomspi_get_INTFLAG_ERROR_bit(sercom)) { - shared_dma_transfer_close(self->running_dma); - - // disable the sercom - spi_m_sync_disable(&self->spi_desc); - hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); - - // save configurations - hri_sercomspi_ctrla_reg_t ctrla_saved_val = hri_sercomspi_get_CTRLA_reg(sercom, -1); // -1 mask is all ones: save all bits - hri_sercomspi_ctrlb_reg_t ctrlb_saved_val = hri_sercomspi_get_CTRLB_reg(sercom, -1); // -1 mask is all ones: save all bits - hri_sercomspi_baud_reg_t baud_saved_val = hri_sercomspi_get_BAUD_reg(sercom, -1); // -1 mask is all ones: save all bits - // reset - hri_sercomspi_set_CTRLA_SWRST_bit(sercom); - hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); - // re-write configurations - hri_sercomspi_write_CTRLA_reg(sercom, ctrla_saved_val); - hri_sercomspi_write_CTRLB_reg(sercom, ctrlb_saved_val); - hri_sercomspi_write_BAUD_reg (sercom, baud_saved_val); - hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); - - // re-enable the sercom - spi_m_sync_enable(&self->spi_desc); - hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); - - self->running_dma = shared_dma_transfer_start(sercom, data_out, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, data_in, len, 0); - } -} - -bool common_hal_busio_spi_transfer_async_check(busio_spi_obj_t *self) { - return self->running_dma.failure == 1 || shared_dma_transfer_finished(self->running_dma); -} - -int common_hal_busio_spi_transfer_async_end(busio_spi_obj_t *self) { - if (self->running_dma.failure == 1) { - return 0; - } - int res = shared_dma_transfer_close(self->running_dma); - self->running_dma.failure = 1; - return res; -} - uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self) { return samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt)); } diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index b58ffa5db825c..8b264bbdbc4fc 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -469,145 +469,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_get_frequency_obj, busio_spi_obj_get_frequen MP_PROPERTY_GETTER(busio_spi_frequency_obj, (mp_obj_t)&busio_spi_get_frequency_obj); -#if CIRCUITPY_SAMD - -//| import sys -//| def async_transfer_start( -//| self, -//| out_buffer: ReadableBuffer, -//| in_buffer: WriteableBuffer, -//| *, -//| out_start: int = 0, -//| out_end: int = sys.maxsize, -//| in_start: int = 0, -//| in_end: int = sys.maxsize -//| ) -> None: -//| """Write out the data in ``out_buffer`` while simultaneously reading data into ``in_buffer``. -//| The SPI object must be locked. Note: this method returns immediately, and the data will not -//| actually be transferred until some time has passed. Use `async_transfer_finished` and -//| `async_transfer_end` to check on the status of the transfer and close out its resources. -//| -//| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced -//| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data. -//| The number of bytes written will be the length of ``out_buffer[out_start:out_end]``. -//| -//| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced -//| as if ``in_buffer[in_start:in_end]`` were passed, -//| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``. -//| -//| The lengths of the slices defined by ``out_buffer[out_start:out_end]`` -//| and ``in_buffer[in_start:in_end]`` must be equal. -//| If buffer slice lengths are both 0, nothing happens. -//| -//| Note: This method is currently only available on atmel-samd` ports of CircuitPython. -//| -//| :param ReadableBuffer out_buffer: write out bytes from this buffer -//| :param WriteableBuffer in_buffer: read bytes into this buffer -//| :param int out_start: beginning of ``out_buffer`` slice -//| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)`` -//| :param int in_start: beginning of ``in_buffer`` slice -//| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)`` -//| """ -//| ... - -STATIC mp_obj_t busio_spi_start_async_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_out_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_in_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_out_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_out_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, - { MP_QSTR_in_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_in_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} }, - }; - busio_spi_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); - check_lock(self); - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_buffer_info_t buf_out_info; - mp_get_buffer_raise(args[ARG_out_buffer].u_obj, &buf_out_info, MP_BUFFER_READ); - int out_stride_in_bytes = mp_binary_get_size('@', buf_out_info.typecode, NULL); - int32_t out_start = args[ARG_out_start].u_int; - size_t out_length = buf_out_info.len / out_stride_in_bytes; - normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length); - - mp_buffer_info_t buf_in_info; - mp_get_buffer_raise(args[ARG_in_buffer].u_obj, &buf_in_info, MP_BUFFER_WRITE); - int in_stride_in_bytes = mp_binary_get_size('@', buf_in_info.typecode, NULL); - int32_t in_start = args[ARG_in_start].u_int; - size_t in_length = buf_in_info.len / in_stride_in_bytes; - normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length); - - // Treat start and length in terms of bytes from now on. - out_start *= out_stride_in_bytes; - out_length *= out_stride_in_bytes; - in_start *= in_stride_in_bytes; - in_length *= in_stride_in_bytes; - - if (out_length != in_length) { - mp_raise_ValueError(MP_ERROR_TEXT("buffer slices must be of equal length")); - } - - common_hal_busio_spi_transfer_async_start(self, - ((uint8_t *)buf_out_info.buf) + out_start, - ((uint8_t *)buf_in_info.buf) + in_start, - out_length); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_start_transfer_obj, 1, busio_spi_start_async_transfer); - -//| import sys -//| def async_transfer_finished( -//| self -//| ) -> None: -//| """Check whether or not the last async transfer started on this SPI object has finished. If -//| no transfer was started, this method behaves as though the most recent transfer has finished -//| and returns `True`. Otherwise, it returns `False`. -//| -//| Note: This method is currently only available on atmel-samd` ports of CircuitPython. -//| """ -//| ... -STATIC mp_obj_t busio_spi_obj_check_async_transfer(mp_obj_t self_in) { - busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return common_hal_busio_spi_transfer_async_check(self) ? mp_const_true : mp_const_false; -} -MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_check_transfer_obj, busio_spi_obj_check_async_transfer); - -//| import sys -//| def async_transfer_end( -//| self -//| ) -> None: -//| """Return the status code with which the last async transfer on this SPI object completed. This -//| method MUST be called for all transfers, regardless of user interest in status code. The resources -//| for the transfer will be left open until this method is called. Once this method is called, the -//| peripheral resets and is ready for another transfer. The return code of this method also resets to -//| its pre-transfer state: repeated calls to this method may produce different codes. -//| -//| Return code 0: No transfer has occured, either because `start_async_transfer` was never called, or because -//| it was called with zero-length buffers. -//| Return code -1: The transfer failed because no DMA channels are available. -//| Return code -2: The transfer executed, but the DMA controller indicates that either some data is -//| untransferred, that a software issue prevented the data transfer from completing, or that some other error -//| has occured within the DMA controller. -//| Return code -3: An unaligned buffer was passed to the QSPI peripheral, which prevents the DMA controller from -//| appropriately chunking the transfer. -//| Return code n>0: A transfer of `n` bytes in each direction has succeeded. -//| -//| Note: This method is currently only available on atmel-samd` ports of CircuitPython. -//| """ -//| ... -STATIC mp_obj_t busio_spi_obj_end_async_transfer(mp_obj_t self_in) { - busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_busio_spi_transfer_async_end(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_end_transfer_obj, busio_spi_obj_end_async_transfer); - -#endif // CIRCUITPY_SAMD - #endif // CIRCUITPY_BUSIO_SPI @@ -626,13 +487,6 @@ STATIC const mp_rom_map_elem_t busio_spi_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_readinto), MP_ROM_PTR(&busio_spi_write_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&busio_spi_frequency_obj) } - #if CIRCUITPY_SAMD - , - { MP_ROM_QSTR(MP_QSTR_async_transfer_start), MP_ROM_PTR(&busio_spi_start_transfer_obj) }, - { MP_ROM_QSTR(MP_QSTR_async_transfer_finished), MP_ROM_PTR(&busio_spi_check_transfer_obj) }, - { MP_ROM_QSTR(MP_QSTR_async_transfer_end), MP_ROM_PTR(&busio_spi_end_transfer_obj) } - #endif // CIRCUITPY_SAMD - #endif // CIRCUITPY_BUSIO_SPI }; STATIC MP_DEFINE_CONST_DICT(busio_spi_locals_dict, busio_spi_locals_dict_table); diff --git a/shared-bindings/busio/SPI.h b/shared-bindings/busio/SPI.h index 7caae1f947951..2665ecc7e5972 100644 --- a/shared-bindings/busio/SPI.h +++ b/shared-bindings/busio/SPI.h @@ -57,19 +57,6 @@ extern bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size // Reads and write len bytes simultaneously. extern bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len); -#if CIRCUITPY_SAMD - -// Initiates a transfer that reads and write len bytes simultaneously -extern void common_hal_busio_spi_transfer_async_start(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len); - -// Reads the state of the in-progress transfer -extern bool common_hal_busio_spi_transfer_async_check(busio_spi_obj_t *self); - -// Cleans up the completed transfer and returns any error code produced by the transfer -extern int common_hal_busio_spi_transfer_async_end(busio_spi_obj_t *self); - -#endif // CIRCUITPY_SAMD - // Return actual SPI bus frequency. uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self); From 022e1918b5c725a3da13371975484183256b1512 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Wed, 13 Nov 2024 19:09:10 -0800 Subject: [PATCH 40/55] add missing files not found by wildcard --- .github/workflows/build-rapid-0.yaml | 53 ---------------------------- .gitignore | 1 - build-rapid0-mac | 18 ---------- build-rapid0-ubuntu | 17 --------- 4 files changed, 89 deletions(-) delete mode 100644 .github/workflows/build-rapid-0.yaml delete mode 100755 build-rapid0-mac delete mode 100644 build-rapid0-ubuntu diff --git a/.github/workflows/build-rapid-0.yaml b/.github/workflows/build-rapid-0.yaml deleted file mode 100644 index c36407914e7ad..0000000000000 --- a/.github/workflows/build-rapid-0.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: Build RAPID-0 Boards - -on: - push: - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - board: [rapid0_adcs, rapid0_cdh, rapid0_eps] - steps: - - name: Set up repository - uses: actions/checkout@v4 - with: - submodules: false - show-progress: false - fetch-depth: 1 - - name: Set up python - uses: actions/setup-python@v5 - with: - python-version: 3.x - - name: Set up ports - id: set-up-port - uses: ./.github/actions/deps/ports - with: - board: ${{ matrix.board }} - - name: Set up submodules - id: set-up-submodules - uses: ./.github/actions/deps/submodules - with: - action: cache - version: true - - name: Set up external - uses: ./.github/actions/deps/external - with: - action: cache - port: ${{ steps.set-up-port.outputs.port }} - - name: Set up mpy-cross - if: steps.set-up-submodules.outputs.frozen == 'True' - uses: ./.github/actions/mpy_cross - with: - cp-version: ${{ steps.set-up-submodules.outputs.version }} - download: false - - name: Build boards - run: make -j4 -C ports/atmel-samd BOARD=${{ matrix.board }} - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.board }} - path: ports/atmel-samd/build-${{ matrix.board }}/firmware.* - overwrite: true - diff --git a/.gitignore b/.gitignore index 04c580cd77c7e..9cb1e9ea5e497 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,6 @@ bin/ circuitpython-stubs/ test-stubs/ build-*/ -build-* # Test failure outputs ###################### diff --git a/build-rapid0-mac b/build-rapid0-mac deleted file mode 100755 index 01fba1bdc1a86..0000000000000 --- a/build-rapid0-mac +++ /dev/null @@ -1,18 +0,0 @@ -if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null; then - true -else - export PATH=/Volumes/Circuit_Python_Case_Sensitive_Disk/bruinspace-circuitpython/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH -fi - -cd ports/atmel-samd -make --debug -j8 BOARD=rapid0_adcs -make --debug -j8 BOARD=rapid0_cdh -make --debug -j8 BOARD=rapid0_eps -cd ../.. - -echo "Compilation complete! Press ^C to confirm and exit." - -while true; do - afplay /System/Library/Sounds/Ping.aiff - sleep 5s -done diff --git a/build-rapid0-ubuntu b/build-rapid0-ubuntu deleted file mode 100644 index b2fcec5053f62..0000000000000 --- a/build-rapid0-ubuntu +++ /dev/null @@ -1,17 +0,0 @@ -if echo $PATH | grep "gcc-arm-none-eabi" >/dev/null -then - true -else - export PATH=/mnt/d/Files/Documents/School/UCLA/Organizations/BruinSpace/Rapid-CDH/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH -fi -cd ports/atmel-samd -make --debug -j8 BOARD=rapid0_adcs -make --debug -j8 BOARD=rapid0_cdh -make --debug -j8 BOARD=rapid0_eps -cd ../.. -echo "Compilation complete! Press ^C to confirm and exit." -while true; -do - paplay /usr/share/sounds/freedesktop/stereo/complete.oga - sleep 5s -done \ No newline at end of file From d059736bb2450d3fa20ffed3377b18bd59225425 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 25 Nov 2024 19:32:52 -0800 Subject: [PATCH 41/55] push samd-peripherals to merge commit in adafruit repository --- .gitmodules | 2 +- ports/atmel-samd/peripherals | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index f4b5626dd52ed..8934f17d7cb61 100644 --- a/.gitmodules +++ b/.gitmodules @@ -59,7 +59,7 @@ url = https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git [submodule "ports/atmel-samd/peripherals"] path = ports/atmel-samd/peripherals - url = https://github.com/Bruin-Spacecraft-Group/bruinspace-samd-peripherals.git + url = https://github.com/adafruit/samd-peripherals.git [submodule "frozen/Adafruit_CircuitPython_Crickit"] path = frozen/Adafruit_CircuitPython_Crickit url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index fd82c8b829b8d..d3210221bbd01 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit fd82c8b829b8d72eb0e45de16ac9db43a77ac764 +Subproject commit d3210221bbd018ae9d0183ea4640c42cf4bce672 From cd3c95b6af4aa157cb75ccfba1f7e2941140c468 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Sun, 9 Feb 2025 23:11:42 -0800 Subject: [PATCH 42/55] update docs and names for consistency and completeness --- .../common-hal/spitarget/SPITarget.c | 10 +++++ .../common-hal/spitarget/SPITarget.h | 3 ++ shared-bindings/spitarget/SPITarget.c | 9 ++-- shared-bindings/spitarget/__init__.c | 43 +++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index 0252436df7d08..ef1ef599f5242 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -154,6 +154,8 @@ void common_hal_spitarget_spi_target_construct(spitarget_spi_target_obj_t *self, claim_pin(ss); self->running_dma.failure = 1; // not started + self->mosi_packet = NULL; + self->miso_packet = NULL; spi_m_sync_enable(&self->spi_desc); } @@ -185,6 +187,10 @@ void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t * if (self->running_dma.failure != 1) { mp_raise_RuntimeError(MP_ERROR_TEXT("Async SPI transfer in progress on this bus, keep awaiting.")); } + + self->mosi_packet = mosi_packet; + self->miso_packet = miso_packet; + Sercom* sercom = self->spi_desc.dev.prvt; self->running_dma = shared_dma_transfer_start(sercom, miso_packet, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, mosi_packet, len, 0); @@ -231,5 +237,9 @@ int common_hal_spitarget_spi_target_transfer_close(spitarget_spi_target_obj_t *s } int res = shared_dma_transfer_close(self->running_dma); self->running_dma.failure = 1; + + self->mosi_packet = NULL; + self->miso_packet = NULL; + return res; } diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.h b/ports/atmel-samd/common-hal/spitarget/SPITarget.h index c1f233d084164..0b8079d0abee9 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.h +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.h @@ -15,6 +15,9 @@ typedef struct { uint8_t MISO_pin; uint8_t SS_pin; + uint8_t* mosi_packet; + uint8_t* miso_packet; + dma_descr_t running_dma; } spitarget_spi_target_obj_t; diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index 8f558b51722ca..0621298412164 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -85,6 +85,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, //| If a packet has already been queued for this SPI bus but has not yet been transferred, an error will be raised. //| //| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request.""" +//| :param bytearray mosi_packet: Packet to be filled with data from main on next request.""" //| STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); @@ -115,14 +116,14 @@ STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t * } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spitarget_spi_target_load_packet); -//| def try_transfer(self, *, timeout: float = -1) -> bool: +//| def wait_transfer(self, *, timeout: float = -1) -> bool: //| """Wait for an SPI transfer from the main device. //| //| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once //| :return: True if the transfer is complete, or False if no response received before the timeout //| :rtype: ~bool""" //| -STATIC mp_obj_t spitarget_spi_target_try_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t spitarget_spi_target_wait_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); if (common_hal_spitarget_spi_target_deinited(self)) { @@ -160,14 +161,14 @@ STATIC mp_obj_t spitarget_spi_target_try_transfer(size_t n_args, const mp_obj_t return mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_try_transfer_obj, 1, spitarget_spi_target_try_transfer); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_wait_transfer_obj, 1, spitarget_spi_target_wait_transfer); STATIC const mp_rom_map_elem_t spitarget_spi_target_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&spitarget_spi_target_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&spitarget_spi_target___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_load_packet), MP_ROM_PTR(&spitarget_spi_target_load_packet_obj) }, - { MP_ROM_QSTR(MP_QSTR_try_transfer), MP_ROM_PTR(&spitarget_spi_target_try_transfer_obj) }, + { MP_ROM_QSTR(MP_QSTR_wait_transfer), MP_ROM_PTR(&spitarget_spi_target_wait_transfer_obj) }, }; diff --git a/shared-bindings/spitarget/__init__.c b/shared-bindings/spitarget/__init__.c index c91f201d7315f..69f40df52c7fa 100644 --- a/shared-bindings/spitarget/__init__.c +++ b/shared-bindings/spitarget/__init__.c @@ -11,6 +11,49 @@ //| """Serial Peripheral Interface protocol target //| //| The `spitarget` module contains classes to support an SPI target. +//| +//| Example that emulates an SPI analog-to-digital converter:: +//| +//| import board +//| import analogio +//| from spitarget import SPITarget +//| +//| ain0 = analogio.AnalogIn(board.A0) +//| ain1 = analogio.AnalogIn(board.A1) +//| selected_channel = ain0 +//| +//| def map_adc_channel(index): +//| return ain0 if (index == 0) else ain1 +//| +//| mosi_buffer = bytearray(2) +//| miso_buffer = bytearray(2) +//| with SPITarget(sck=board.D12, mosi=board.D13, miso=board.D11, ss=board.D10) as device: +//| while True: +//| # Convert analog signal to array of bytes +//| reading = selected_channel.value +//| miso_buffer[0] = (reading >> 8) & 0xFF +//| miso_buffer[1] = (reading) & 0xFF +//| # Send array of bytes over SPI to main +//| device.load_packet(mosi_buffer, miso_buffer) +//| device.wait_transfer(0) +//| # Handle command from main, which sets the ADC channel +//| selected_channel = map_adc_channel((mosi_buffer[0] << 8) | mosi_buffer[1]) +//| +//| Communicating with the ADC emulator from the REPL of an attached CircuitPython board might look like :: +//| +//| >>> import busio +//| >>> spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +//| >>> spi.try_lock() +//| True +//| >>> spi.write(bytearray([0, 0])) # ADC command: read from A0 +//| >>> adc_result = bytearray(2) +//| >>> spi.readinto(adc_result) +//| >>> adc_result +//| bytearray(b'\xc4\x16') +//| >>> spi.unlock() +//| +//| """ + STATIC const mp_rom_map_elem_t spitarget_module_globals_table[] = { From 193f7007f80014400bc14e053ffa94e76ccd86fa Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 10:46:23 -0800 Subject: [PATCH 43/55] fix typo in documentation comment --- shared-bindings/spitarget/SPITarget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index 0621298412164..ddb0a28a81d5d 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -84,7 +84,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, //| """Queue data for the next SPI transfer from the main device. //| If a packet has already been queued for this SPI bus but has not yet been transferred, an error will be raised. //| -//| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request.""" +//| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request. //| :param bytearray mosi_packet: Packet to be filled with data from main on next request.""" //| STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { From dd7acd5cf817f080fd6247a31d4bbd64a6bb2b87 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 12:17:18 -0800 Subject: [PATCH 44/55] apply pre-commit formatting and translations --- locale/circuitpython.pot | 16 ++++++-- .../common-hal/spitarget/SPITarget.c | 8 ++-- .../common-hal/spitarget/SPITarget.h | 4 +- ports/espressif/bindings/espnow/ESPNow.c | 1 - ports/espressif/tools/update_sdkconfig.py | 6 +-- shared-bindings/_bleio/CharacteristicBuffer.c | 2 - shared-bindings/_bleio/Connection.c | 1 - shared-bindings/_bleio/Descriptor.c | 1 - shared-bindings/_bleio/ScanEntry.c | 1 - shared-bindings/_bleio/ScanResults.c | 2 - shared-bindings/_pixelmap/PixelMap.c | 2 - shared-bindings/adafruit_pixelbuf/PixelBuf.c | 2 - shared-bindings/alarm/SleepMemory.c | 3 -- shared-bindings/busio/SPI.c | 2 +- shared-bindings/canio/Listener.c | 1 - shared-bindings/displayio/Bitmap.c | 1 - shared-bindings/displayio/Group.c | 2 - shared-bindings/displayio/Palette.c | 1 - shared-bindings/displayio/TileGrid.c | 1 - shared-bindings/fontio/BuiltinFont.c | 1 - shared-bindings/keypad/EventQueue.c | 1 - shared-bindings/memorymap/AddressRange.c | 1 - shared-bindings/nvm/ByteArray.c | 1 - shared-bindings/spitarget/SPITarget.c | 6 +-- shared-bindings/storage/__init__.c | 8 ---- shared-bindings/usb_cdc/Serial.c | 6 --- shared-bindings/usb_midi/PortIn.c | 1 - shared-bindings/wifi/ScannedNetworks.c | 2 - tools/analyze_heap_dump.py | 38 +++++++++---------- 29 files changed, 44 insertions(+), 78 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 48d27d14b0be5..d6b12bedc636f 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -594,6 +594,10 @@ msgstr "" msgid "Array values should be single bytes." msgstr "" +#: ports/atmel-samd/common-hal/spitarget/SPITarget.c +msgid "Async SPI transfer in progress on this bus, keep awaiting." +msgstr "" + #: shared-module/memorymonitor/AllocationAlarm.c #, c-format msgid "Attempt to allocate %d blocks" @@ -1693,6 +1697,10 @@ msgstr "" msgid "PWM slice channel A already in use" msgstr "" +#: shared-bindings/spitarget/SPITarget.c +msgid "Packet buffers for an SPI transfer must have the same length." +msgstr "" + #: shared-module/jpegio/JpegDecoder.c msgid "Parameter error" msgstr "" @@ -1985,8 +1993,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c -#: shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Distortion.c +#: shared-module/audiofilters/Filter.c shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2530,8 +2538,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Distortion.c +#: shared-bindings/audiofilters/Filter.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.c b/ports/atmel-samd/common-hal/spitarget/SPITarget.c index ef1ef599f5242..b9062911cc353 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.c +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.c @@ -181,7 +181,7 @@ void common_hal_spitarget_spi_target_deinit(spitarget_spi_target_obj_t *self) { void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t *self, uint8_t *mosi_packet, const uint8_t *miso_packet, size_t len) { - if (len == 0) { + if (len == 0) { return; } if (self->running_dma.failure != 1) { @@ -191,7 +191,7 @@ void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t * self->mosi_packet = mosi_packet; self->miso_packet = miso_packet; - Sercom* sercom = self->spi_desc.dev.prvt; + Sercom *sercom = self->spi_desc.dev.prvt; self->running_dma = shared_dma_transfer_start(sercom, miso_packet, &sercom->SPI.DATA.reg, &sercom->SPI.DATA.reg, mosi_packet, len, 0); // There is an issue where if an unexpected SPI transfer is received before the user calls "end" for the in-progress, expected @@ -209,14 +209,14 @@ void common_hal_spitarget_spi_target_transfer_start(spitarget_spi_target_obj_t * // save configurations hri_sercomspi_ctrla_reg_t ctrla_saved_val = hri_sercomspi_get_CTRLA_reg(sercom, -1); // -1 mask is all ones: save all bits hri_sercomspi_ctrlb_reg_t ctrlb_saved_val = hri_sercomspi_get_CTRLB_reg(sercom, -1); // -1 mask is all ones: save all bits - hri_sercomspi_baud_reg_t baud_saved_val = hri_sercomspi_get_BAUD_reg(sercom, -1); // -1 mask is all ones: save all bits + hri_sercomspi_baud_reg_t baud_saved_val = hri_sercomspi_get_BAUD_reg(sercom, -1); // -1 mask is all ones: save all bits // reset hri_sercomspi_set_CTRLA_SWRST_bit(sercom); hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); // re-write configurations hri_sercomspi_write_CTRLA_reg(sercom, ctrla_saved_val); hri_sercomspi_write_CTRLB_reg(sercom, ctrlb_saved_val); - hri_sercomspi_write_BAUD_reg (sercom, baud_saved_val); + hri_sercomspi_write_BAUD_reg(sercom, baud_saved_val); hri_sercomspi_wait_for_sync(sercom, SERCOM_SPI_SYNCBUSY_MASK); // re-enable the sercom diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.h b/ports/atmel-samd/common-hal/spitarget/SPITarget.h index 0b8079d0abee9..8ca8b8ca86e98 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.h +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.h @@ -15,8 +15,8 @@ typedef struct { uint8_t MISO_pin; uint8_t SS_pin; - uint8_t* mosi_packet; - uint8_t* miso_packet; + uint8_t *mosi_packet; + uint8_t *miso_packet; dma_descr_t running_dma; } spitarget_spi_target_obj_t; diff --git a/ports/espressif/bindings/espnow/ESPNow.c b/ports/espressif/bindings/espnow/ESPNow.c index 80dfac93c12f2..0476d0f5f8cd7 100644 --- a/ports/espressif/bindings/espnow/ESPNow.c +++ b/ports/espressif/bindings/espnow/ESPNow.c @@ -320,7 +320,6 @@ static const mp_stream_p_t espnow_stream_p = { //| This is an easy way to check if the buffer is empty. //| """ //| ... -//| //| def __len__(self) -> int: //| """Return the number of `bytes` available to read. Used to implement ``len()``.""" //| ... diff --git a/ports/espressif/tools/update_sdkconfig.py b/ports/espressif/tools/update_sdkconfig.py index f69e8453742c3..e5d21263174c1 100644 --- a/ports/espressif/tools/update_sdkconfig.py +++ b/ports/espressif/tools/update_sdkconfig.py @@ -195,9 +195,9 @@ def update(debug, board, update_all): ble_enabled = not (value == "0") os.environ["IDF_TARGET"] = target - os.environ["COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE"] = ( - f"build-{board}/esp-idf/kconfigs_projbuild.in" - ) + os.environ[ + "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE" + ] = f"build-{board}/esp-idf/kconfigs_projbuild.in" os.environ["COMPONENT_KCONFIGS_SOURCE_FILE"] = f"build-{board}/esp-idf/kconfigs.in" kconfig_path = pathlib.Path(f"build-{board}/esp-idf/kconfigs.in") diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c index 24b8b146809dd..c4cf98825d9e2 100644 --- a/shared-bindings/_bleio/CharacteristicBuffer.c +++ b/shared-bindings/_bleio/CharacteristicBuffer.c @@ -79,7 +79,6 @@ static void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { //| :return: Data read //| :rtype: bytes or None""" //| ... -//| //| def readinto(self, buf: WriteableBuffer, nbytes: Optional[int] = None) -> Optional[int]: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. //| @@ -88,7 +87,6 @@ static void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { //| :return: number of bytes read and stored into ``buf`` //| :rtype: int or None (on a non-blocking error)""" //| ... -//| //| def readline(self) -> bytes: //| """Read a line, ending in a newline character. //| diff --git a/shared-bindings/_bleio/Connection.c b/shared-bindings/_bleio/Connection.c index ec3f349fcb35e..3aa11c95e6699 100644 --- a/shared-bindings/_bleio/Connection.c +++ b/shared-bindings/_bleio/Connection.c @@ -52,7 +52,6 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) { //| Connections may also be made when another device initiates a connection. To use a Connection //| created by a peer, read the `Adapter.connections` property.""" //| ... -//| //| def disconnect(self) -> None: //| """Disconnects from the remote peripheral. Does nothing if already disconnected.""" //| ... diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c index f8615fd28abb5..51cd348d9f083 100644 --- a/shared-bindings/_bleio/Descriptor.c +++ b/shared-bindings/_bleio/Descriptor.c @@ -24,7 +24,6 @@ //| and attached to a Characteristic by calling `add_to_characteristic()`. //| Remote Descriptor objects are created by `Connection.discover_remote_services()` //| as part of remote Characteristics in the remote Services that are discovered.""" -//| //| @classmethod //| def add_to_characteristic( //| cls, diff --git a/shared-bindings/_bleio/ScanEntry.c b/shared-bindings/_bleio/ScanEntry.c index a2c79b557bd88..981b17706b60d 100644 --- a/shared-bindings/_bleio/ScanEntry.c +++ b/shared-bindings/_bleio/ScanEntry.c @@ -24,7 +24,6 @@ //| def __init__(self) -> None: //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... -//| //| def matches(self, prefixes: ReadableBuffer, *, match_all: bool = True) -> bool: //| """Returns True if the ScanEntry matches all prefixes when ``match_all`` is True. This is stricter //| than the scan filtering which accepts any advertisements that match any of the prefixes diff --git a/shared-bindings/_bleio/ScanResults.c b/shared-bindings/_bleio/ScanResults.c index 81680902e4da9..89d600e117213 100644 --- a/shared-bindings/_bleio/ScanResults.c +++ b/shared-bindings/_bleio/ScanResults.c @@ -29,11 +29,9 @@ static mp_obj_t scanresults_iternext(mp_obj_t self_in) { //| def __init__(self) -> None: //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... -//| //| def __iter__(self) -> Iterator[ScanEntry]: //| """Returns itself since it is the iterator.""" //| ... -//| //| def __next__(self) -> ScanEntry: //| """Returns the next `_bleio.ScanEntry`. Blocks if none have been received and scanning is still //| active. Raises `StopIteration` if scanning is finished and no other results are available. diff --git a/shared-bindings/_pixelmap/PixelMap.c b/shared-bindings/_pixelmap/PixelMap.c index 6bddeaac9c3f5..b82351d58015f 100644 --- a/shared-bindings/_pixelmap/PixelMap.c +++ b/shared-bindings/_pixelmap/PixelMap.c @@ -140,12 +140,10 @@ MP_DEFINE_CONST_FUN_OBJ_2(pixelmap_pixelmap_indices_obj, pixelmap_pixelmap_indic //| def __getitem__(self, index: slice) -> PixelReturnSequence: //| """Retrieve the value of the underlying pixels.""" //| ... -//| //| @overload //| def __getitem__(self, index: int) -> PixelReturnType: //| """Retrieve the value of one of the underlying pixels at 'index'.""" //| ... -//| //| @overload //| def __setitem__(self, index: slice, value: PixelSequence) -> None: ... //| @overload diff --git a/shared-bindings/adafruit_pixelbuf/PixelBuf.c b/shared-bindings/adafruit_pixelbuf/PixelBuf.c index 95b353611f734..b57411950a6da 100644 --- a/shared-bindings/adafruit_pixelbuf/PixelBuf.c +++ b/shared-bindings/adafruit_pixelbuf/PixelBuf.c @@ -248,14 +248,12 @@ static MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_fill_obj, pixelbuf_pixelbuf_f //| between 0 and 255. When in PWM (DotStar) mode, the 4th tuple value is a float of the pixel //| intensity from 0-1.0.""" //| ... -//| //| @overload //| def __getitem__(self, index: int) -> PixelReturnType: //| """Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values //| between 0 and 255. When in PWM (DotStar) mode, the 4th tuple value is a float of the pixel //| intensity from 0-1.0.""" //| ... -//| //| @overload //| def __setitem__(self, index: slice, value: PixelSequence) -> None: ... //| @overload diff --git a/shared-bindings/alarm/SleepMemory.c b/shared-bindings/alarm/SleepMemory.c index cf1b211c6853f..5540d41b5992f 100644 --- a/shared-bindings/alarm/SleepMemory.c +++ b/shared-bindings/alarm/SleepMemory.c @@ -33,13 +33,11 @@ //| def __init__(self) -> None: //| """Not used. Access the sole instance through `alarm.sleep_memory`.""" //| ... -//| //| def __bool__(self) -> bool: //| """``sleep_memory`` is ``True`` if its length is greater than zero. //| This is an easy way to check for its existence. //| """ //| ... -//| //| def __len__(self) -> int: //| """Return the length. This is used by (`len`)""" //| ... @@ -67,7 +65,6 @@ static MP_DEFINE_CONST_DICT(alarm_sleep_memory_locals_dict, alarm_sleep_memory_l //| def __getitem__(self, index: int) -> int: //| """Returns the value at the given index.""" //| ... -//| //| @overload //| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ... //| @overload diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index c55f099fa693b..0c517c827d7c7 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -53,7 +53,7 @@ //| clock: microcontroller.Pin, //| MOSI: Optional[microcontroller.Pin] = None, //| MISO: Optional[microcontroller.Pin] = None, -//| half_duplex: bool = False +//| half_duplex: bool = False, //| ) -> None: //| """Construct an SPI object on the given pins. //| diff --git a/shared-bindings/canio/Listener.c b/shared-bindings/canio/Listener.c index 26b5fb2cbb2ac..f208bc5aff997 100644 --- a/shared-bindings/canio/Listener.c +++ b/shared-bindings/canio/Listener.c @@ -60,7 +60,6 @@ static MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_in_waiting_obj, canio_listener_i //| This method exists so that `Listener` can be used as an //| iterable""" //| ... -//| //| def __next__(self) -> Union[RemoteTransmissionRequest, Message]: //| """Reads a message, after waiting up to self.timeout seconds //| diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 4c8fc97345cf4..ee1f0655a43a8 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -117,7 +117,6 @@ MP_PROPERTY_GETTER(displayio_bitmap_bits_per_value_obj, //| //| print(bitmap[0,1])""" //| ... -//| //| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None: //| """Sets the value at the given index. The index can either be an x,y tuple or an int equal //| to ``y * width + x``. diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 73c3d06988c8d..f7fd2f215e129 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -261,7 +261,6 @@ static mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| //| print(group[0])""" //| ... -//| //| def __setitem__( //| self, //| index: int, @@ -273,7 +272,6 @@ static mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| //| group[0] = sprite""" //| ... -//| //| def __delitem__(self, index: int) -> None: //| """Deletes the value at the given index. //| diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 528df88ec4e7e..fbca7b626ea88 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -84,7 +84,6 @@ static mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| def __getitem__(self, index: int) -> Optional[int]: //| r"""Return the pixel color at the given index as an integer.""" //| ... -//| //| def __setitem__( //| self, index: int, value: Union[int, ReadableBuffer, Tuple[int, int, int]] //| ) -> None: diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 9800480b22a45..533f07a94ba54 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -389,7 +389,6 @@ MP_PROPERTY_GETSET(displayio_tilegrid_bitmap_obj, //| //| print(grid[0])""" //| ... -//| //| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None: //| """Sets the tile index at the given index. The index can either be an x,y tuple or an int equal //| to ``y * width + x``. diff --git a/shared-bindings/fontio/BuiltinFont.c b/shared-bindings/fontio/BuiltinFont.c index 9d3f30675b9ea..0274bbe92cf60 100644 --- a/shared-bindings/fontio/BuiltinFont.c +++ b/shared-bindings/fontio/BuiltinFont.c @@ -27,7 +27,6 @@ //| The two element version is ``(width, height)``, in which //| ``x_offset`` and ``y_offset`` are assumed to be zero.""" //| pass -//| //| def get_glyph(self, codepoint: int) -> Optional[Glyph]: //| """Retrieve the Glyph for a given code point //| diff --git a/shared-bindings/keypad/EventQueue.c b/shared-bindings/keypad/EventQueue.c index e15b19df3b8f8..74fd8cbc163a5 100644 --- a/shared-bindings/keypad/EventQueue.c +++ b/shared-bindings/keypad/EventQueue.c @@ -80,7 +80,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(keypad_eventqueue_clear_obj, keypad_eventqueue_clear); //| This is an easy way to check if the queue is empty. //| """ //| ... -//| //| def __len__(self) -> int: //| """Return the number of events currently in the queue. Used to implement ``len()``.""" //| ... diff --git a/shared-bindings/memorymap/AddressRange.c b/shared-bindings/memorymap/AddressRange.c index 821609bb9331f..97577feac84b3 100644 --- a/shared-bindings/memorymap/AddressRange.c +++ b/shared-bindings/memorymap/AddressRange.c @@ -129,7 +129,6 @@ static MP_DEFINE_CONST_DICT(memorymap_addressrange_locals_dict, memorymap_addres //| when possible. //| All others may use multiple transactions.""" //| ... -//| //| @overload //| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ... //| @overload diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index 7549023247eca..70fea2de90b54 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -55,7 +55,6 @@ static MP_DEFINE_CONST_DICT(nvm_bytearray_locals_dict, nvm_bytearray_locals_dict //| def __getitem__(self, index: int) -> int: //| """Returns the value at the given index.""" //| ... -//| //| @overload //| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ... //| @overload diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index ddb0a28a81d5d..d4bc000e56ef8 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -21,7 +21,7 @@ //| sck: microcontroller.Pin, //| mosi: microcontroller.Pin, //| miso: microcontroller.Pin, -//| ss: microcontroller.Pin +//| ss: microcontroller.Pin, //| ) -> None: //| """SPI is a four-wire protocol for communicating between devices. //| This implements the secondary (aka target or peripheral) side. @@ -85,8 +85,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, //| If a packet has already been queued for this SPI bus but has not yet been transferred, an error will be raised. //| //| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request. -//| :param bytearray mosi_packet: Packet to be filled with data from main on next request.""" -//| +//| :param bytearray mosi_packet: Packet to be filled with data from main on next request. +//| """ STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index e046c11879744..eb42fe0591877 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -255,38 +255,30 @@ static const mp_rom_map_elem_t storage_module_globals_table[] = { //| larger filesystems, but you will need to format the filesystem on another device. //| """ //| ... -//| //| def open(self, path: str, mode: str) -> None: //| """Like builtin ``open()``""" //| ... -//| //| def ilistdir( //| self, path: str //| ) -> Iterator[Union[Tuple[AnyStr, int, int, int], Tuple[AnyStr, int, int]]]: //| """Return an iterator whose values describe files and folders within //| ``path``""" //| ... -//| //| def mkdir(self, path: str) -> None: //| """Like `os.mkdir`""" //| ... -//| //| def rmdir(self, path: str) -> None: //| """Like `os.rmdir`""" //| ... -//| //| def stat(self, path: str) -> Tuple[int, int, int, int, int, int, int, int, int, int]: //| """Like `os.stat`""" //| ... -//| //| def statvfs(self, path: int) -> Tuple[int, int, int, int, int, int, int, int, int, int]: //| """Like `os.statvfs`""" //| ... -//| //| def mount(self, readonly: bool, mkfs: VfsFat) -> None: //| """Don't call this directly, call `storage.mount`.""" //| ... -//| //| def umount(self) -> None: //| """Don't call this directly, call `storage.umount`.""" //| ... diff --git a/shared-bindings/usb_cdc/Serial.c b/shared-bindings/usb_cdc/Serial.c index 1fd5ed4afcfdf..d2413898cf133 100644 --- a/shared-bindings/usb_cdc/Serial.c +++ b/shared-bindings/usb_cdc/Serial.c @@ -21,7 +21,6 @@ //| """You cannot create an instance of `usb_cdc.Serial`. //| The available instances are in the ``usb_cdc.serials`` tuple.""" //| ... -//| //| def read(self, size: int = -1) -> bytes: //| """Read at most ``size`` bytes. If ``size`` exceeds the internal buffer size, //| only the bytes in the buffer will be read. If ``size`` is not specified or is ``-1``, @@ -35,7 +34,6 @@ //| :return: Data read //| :rtype: bytes""" //| ... -//| //| def readinto(self, buf: WriteableBuffer) -> int: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. If `timeout` //| is > 0 or ``None``, keep waiting until the timeout expires or ``len(buf)`` @@ -44,7 +42,6 @@ //| :return: number of bytes read and stored into ``buf`` //| :rtype: int""" //| ... -//| //| def readline(self, size: int = -1) -> Optional[bytes]: //| r"""Read a line ending in a newline character ("\\n"), including the newline. //| Return everything readable if no newline is found and ``timeout`` is 0. @@ -57,7 +54,6 @@ //| :return: the line read //| :rtype: bytes or None""" //| ... -//| //| def readlines(self) -> List[Optional[bytes]]: //| """Read multiple lines as a list, using `readline()`. //| @@ -67,14 +63,12 @@ //| :return: a list of the line read //| :rtype: list""" //| ... -//| //| def write(self, buf: ReadableBuffer) -> int: //| """Write as many bytes as possible from the buffer of bytes. //| //| :return: the number of bytes written //| :rtype: int""" //| ... -//| //| def flush(self) -> None: //| """Force out any unwritten bytes, waiting until they are written.""" //| ... diff --git a/shared-bindings/usb_midi/PortIn.c b/shared-bindings/usb_midi/PortIn.c index 38662a4468cd2..387a22b5e99c6 100644 --- a/shared-bindings/usb_midi/PortIn.c +++ b/shared-bindings/usb_midi/PortIn.c @@ -35,7 +35,6 @@ //| :return: Data read //| :rtype: bytes or None""" //| ... -//| //| def readinto(self, buf: WriteableBuffer, nbytes: Optional[int] = None) -> Optional[bytes]: //| """Read bytes into the ``buf``. If ``nbytes`` is specified then read at most //| that many bytes. Otherwise, read at most ``len(buf)`` bytes. diff --git a/shared-bindings/wifi/ScannedNetworks.c b/shared-bindings/wifi/ScannedNetworks.c index dea3474d423e1..f06439f9c17ff 100644 --- a/shared-bindings/wifi/ScannedNetworks.c +++ b/shared-bindings/wifi/ScannedNetworks.c @@ -30,11 +30,9 @@ static mp_obj_t scannednetworks_iternext(mp_obj_t self_in) { //| def __init__(self) -> None: //| """Cannot be instantiated directly. Use `wifi.Radio.start_scanning_networks`.""" //| ... -//| //| def __iter__(self) -> Iterator[Network]: //| """Returns itself since it is the iterator.""" //| ... -//| //| def __next__(self) -> Network: //| """Returns the next `wifi.Network`. //| Raises `StopIteration` if scanning is finished and no other results are available.""" diff --git a/tools/analyze_heap_dump.py b/tools/analyze_heap_dump.py index a5e5e1d48eabb..18da11c456ff2 100755 --- a/tools/analyze_heap_dump.py +++ b/tools/analyze_heap_dump.py @@ -270,9 +270,9 @@ def load_pointer(address): manual_symbol_map["0x200015e0"] = "mp_state_ctx.vm.dict_main" for i in range(READLINE_HIST_SIZE): - manual_symbol_map["mp_state_ctx+{}".format(148 + i * 4)] = ( - "mp_state_ctx.vm.readline_hist[{}]".format(i) - ) + manual_symbol_map[ + "mp_state_ctx+{}".format(148 + i * 4) + ] = "mp_state_ctx.vm.readline_hist[{}]".format(i) tuple_type = symbols["mp_type_tuple"][0] type_type = symbols["mp_type_type"][0] @@ -534,10 +534,10 @@ def format(obj): ) node.attr["shape"] = "plaintext" node.attr["style"] = "invisible" - node.attr["label"] = ( - '<{}
0x{:08x}
>'.format( - block, rows - ) + node.attr[ + "label" + ] = '<{}
0x{:08x}
>'.format( + block, rows ) for node, degree in ownership_graph.in_degree_iter(): @@ -616,10 +616,10 @@ def format(obj): remaining_bytecode -= 16 for i in range(remaining_bytecode // 16): rows += '' - node.attr["label"] = ( - '<{}
0x{:08x}
>'.format( - block, rows - ) + node.attr[ + "label" + ] = '<{}
0x{:08x}
>'.format( + block, rows ) for block in qstr_chunks: @@ -653,10 +653,10 @@ def format(obj): for i in range(0, len(printable_qstrs), 16): wrapped.append(html.escape(printable_qstrs[i : i + 16])) node = ownership_graph.get_node(block) - node.attr["label"] = ( - '<
0x{:08x}
{}
>'.format( - block, 18 * (len(wrapped) - 1), "
".join(wrapped) - ) + node.attr[ + "label" + ] = '<
0x{:08x}
{}
>'.format( + block, 18 * (len(wrapped) - 1), "
".join(wrapped) ) node.attr["fontname"] = "FiraCode-Bold" node.attr["fontcolor"] = "black" @@ -734,10 +734,10 @@ def format(obj): rows += '{}{}'.format( cells[2 * i][0], cells[2 * i][1], cells[2 * i + 1][0], cells[2 * i + 1][1] ) - node.attr["label"] = ( - '<{}
>'.format( - rows - ) + node.attr[ + "label" + ] = '<{}
>'.format( + rows ) ownership_graph.add_node( From 137c2c5691962058b007070376e240888ce1c30f Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 12:40:47 -0800 Subject: [PATCH 45/55] fix buffer storage declaration --- ports/atmel-samd/common-hal/spitarget/SPITarget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/common-hal/spitarget/SPITarget.h b/ports/atmel-samd/common-hal/spitarget/SPITarget.h index 8ca8b8ca86e98..50f2bcb33094b 100644 --- a/ports/atmel-samd/common-hal/spitarget/SPITarget.h +++ b/ports/atmel-samd/common-hal/spitarget/SPITarget.h @@ -16,7 +16,7 @@ typedef struct { uint8_t SS_pin; uint8_t *mosi_packet; - uint8_t *miso_packet; + const uint8_t *miso_packet; dma_descr_t running_dma; } spitarget_spi_target_obj_t; From 62c2107c352db25aa1571aff5d9172589aa16bc7 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 13:10:47 -0800 Subject: [PATCH 46/55] add manually the pre-commit formatting that could not be automatically applied --- ports/espressif/bindings/espnow/ESPNow.c | 1 + ports/espressif/tools/update_sdkconfig.py | 6 +-- shared-bindings/_bleio/CharacteristicBuffer.c | 2 + shared-bindings/_bleio/Connection.c | 1 + shared-bindings/_bleio/Descriptor.c | 1 + shared-bindings/_bleio/ScanEntry.c | 1 + shared-bindings/_bleio/ScanResults.c | 2 + shared-bindings/_pixelmap/PixelMap.c | 3 ++ shared-bindings/adafruit_pixelbuf/PixelBuf.c | 3 ++ shared-bindings/alarm/SleepMemory.c | 3 ++ shared-bindings/canio/Listener.c | 1 + shared-bindings/displayio/Bitmap.c | 1 + shared-bindings/displayio/Group.c | 2 + shared-bindings/displayio/Palette.c | 1 + shared-bindings/displayio/TileGrid.c | 1 + shared-bindings/fontio/BuiltinFont.c | 1 + shared-bindings/keypad/EventQueue.c | 1 + shared-bindings/memorymap/AddressRange.c | 2 + shared-bindings/nvm/ByteArray.c | 1 + shared-bindings/spitarget/SPITarget.c | 25 ++++++------ shared-bindings/spitarget/__init__.c | 8 ++-- shared-bindings/storage/__init__.c | 8 ++++ shared-bindings/usb_cdc/Serial.c | 6 +++ shared-bindings/usb_midi/PortIn.c | 1 + shared-bindings/wifi/ScannedNetworks.c | 2 + tools/analyze_heap_dump.py | 38 +++++++++---------- 26 files changed, 85 insertions(+), 37 deletions(-) diff --git a/ports/espressif/bindings/espnow/ESPNow.c b/ports/espressif/bindings/espnow/ESPNow.c index 0476d0f5f8cd7..80dfac93c12f2 100644 --- a/ports/espressif/bindings/espnow/ESPNow.c +++ b/ports/espressif/bindings/espnow/ESPNow.c @@ -320,6 +320,7 @@ static const mp_stream_p_t espnow_stream_p = { //| This is an easy way to check if the buffer is empty. //| """ //| ... +//| //| def __len__(self) -> int: //| """Return the number of `bytes` available to read. Used to implement ``len()``.""" //| ... diff --git a/ports/espressif/tools/update_sdkconfig.py b/ports/espressif/tools/update_sdkconfig.py index e5d21263174c1..f69e8453742c3 100644 --- a/ports/espressif/tools/update_sdkconfig.py +++ b/ports/espressif/tools/update_sdkconfig.py @@ -195,9 +195,9 @@ def update(debug, board, update_all): ble_enabled = not (value == "0") os.environ["IDF_TARGET"] = target - os.environ[ - "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE" - ] = f"build-{board}/esp-idf/kconfigs_projbuild.in" + os.environ["COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE"] = ( + f"build-{board}/esp-idf/kconfigs_projbuild.in" + ) os.environ["COMPONENT_KCONFIGS_SOURCE_FILE"] = f"build-{board}/esp-idf/kconfigs.in" kconfig_path = pathlib.Path(f"build-{board}/esp-idf/kconfigs.in") diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c index c4cf98825d9e2..24b8b146809dd 100644 --- a/shared-bindings/_bleio/CharacteristicBuffer.c +++ b/shared-bindings/_bleio/CharacteristicBuffer.c @@ -79,6 +79,7 @@ static void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { //| :return: Data read //| :rtype: bytes or None""" //| ... +//| //| def readinto(self, buf: WriteableBuffer, nbytes: Optional[int] = None) -> Optional[int]: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. //| @@ -87,6 +88,7 @@ static void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { //| :return: number of bytes read and stored into ``buf`` //| :rtype: int or None (on a non-blocking error)""" //| ... +//| //| def readline(self) -> bytes: //| """Read a line, ending in a newline character. //| diff --git a/shared-bindings/_bleio/Connection.c b/shared-bindings/_bleio/Connection.c index 3aa11c95e6699..ec3f349fcb35e 100644 --- a/shared-bindings/_bleio/Connection.c +++ b/shared-bindings/_bleio/Connection.c @@ -52,6 +52,7 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) { //| Connections may also be made when another device initiates a connection. To use a Connection //| created by a peer, read the `Adapter.connections` property.""" //| ... +//| //| def disconnect(self) -> None: //| """Disconnects from the remote peripheral. Does nothing if already disconnected.""" //| ... diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c index 51cd348d9f083..f8615fd28abb5 100644 --- a/shared-bindings/_bleio/Descriptor.c +++ b/shared-bindings/_bleio/Descriptor.c @@ -24,6 +24,7 @@ //| and attached to a Characteristic by calling `add_to_characteristic()`. //| Remote Descriptor objects are created by `Connection.discover_remote_services()` //| as part of remote Characteristics in the remote Services that are discovered.""" +//| //| @classmethod //| def add_to_characteristic( //| cls, diff --git a/shared-bindings/_bleio/ScanEntry.c b/shared-bindings/_bleio/ScanEntry.c index 981b17706b60d..a2c79b557bd88 100644 --- a/shared-bindings/_bleio/ScanEntry.c +++ b/shared-bindings/_bleio/ScanEntry.c @@ -24,6 +24,7 @@ //| def __init__(self) -> None: //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... +//| //| def matches(self, prefixes: ReadableBuffer, *, match_all: bool = True) -> bool: //| """Returns True if the ScanEntry matches all prefixes when ``match_all`` is True. This is stricter //| than the scan filtering which accepts any advertisements that match any of the prefixes diff --git a/shared-bindings/_bleio/ScanResults.c b/shared-bindings/_bleio/ScanResults.c index 89d600e117213..81680902e4da9 100644 --- a/shared-bindings/_bleio/ScanResults.c +++ b/shared-bindings/_bleio/ScanResults.c @@ -29,9 +29,11 @@ static mp_obj_t scanresults_iternext(mp_obj_t self_in) { //| def __init__(self) -> None: //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... +//| //| def __iter__(self) -> Iterator[ScanEntry]: //| """Returns itself since it is the iterator.""" //| ... +//| //| def __next__(self) -> ScanEntry: //| """Returns the next `_bleio.ScanEntry`. Blocks if none have been received and scanning is still //| active. Raises `StopIteration` if scanning is finished and no other results are available. diff --git a/shared-bindings/_pixelmap/PixelMap.c b/shared-bindings/_pixelmap/PixelMap.c index b82351d58015f..c1c5e5040d1db 100644 --- a/shared-bindings/_pixelmap/PixelMap.c +++ b/shared-bindings/_pixelmap/PixelMap.c @@ -140,12 +140,15 @@ MP_DEFINE_CONST_FUN_OBJ_2(pixelmap_pixelmap_indices_obj, pixelmap_pixelmap_indic //| def __getitem__(self, index: slice) -> PixelReturnSequence: //| """Retrieve the value of the underlying pixels.""" //| ... +//| //| @overload //| def __getitem__(self, index: int) -> PixelReturnType: //| """Retrieve the value of one of the underlying pixels at 'index'.""" //| ... +//| //| @overload //| def __setitem__(self, index: slice, value: PixelSequence) -> None: ... +//| //| @overload //| def __setitem__(self, index: int, value: PixelType) -> None: //| """Sets the pixel value at the given index. Value can either be a tuple or integer. Tuples are diff --git a/shared-bindings/adafruit_pixelbuf/PixelBuf.c b/shared-bindings/adafruit_pixelbuf/PixelBuf.c index b57411950a6da..0708d881ade09 100644 --- a/shared-bindings/adafruit_pixelbuf/PixelBuf.c +++ b/shared-bindings/adafruit_pixelbuf/PixelBuf.c @@ -248,14 +248,17 @@ static MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_fill_obj, pixelbuf_pixelbuf_f //| between 0 and 255. When in PWM (DotStar) mode, the 4th tuple value is a float of the pixel //| intensity from 0-1.0.""" //| ... +//| //| @overload //| def __getitem__(self, index: int) -> PixelReturnType: //| """Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values //| between 0 and 255. When in PWM (DotStar) mode, the 4th tuple value is a float of the pixel //| intensity from 0-1.0.""" //| ... +//| //| @overload //| def __setitem__(self, index: slice, value: PixelSequence) -> None: ... +//| //| @overload //| def __setitem__(self, index: int, value: PixelType) -> None: //| """Sets the pixel value at the given index. Value can either be a tuple or integer. Tuples are diff --git a/shared-bindings/alarm/SleepMemory.c b/shared-bindings/alarm/SleepMemory.c index 5540d41b5992f..ba9f5ed5bd15c 100644 --- a/shared-bindings/alarm/SleepMemory.c +++ b/shared-bindings/alarm/SleepMemory.c @@ -33,10 +33,12 @@ //| def __init__(self) -> None: //| """Not used. Access the sole instance through `alarm.sleep_memory`.""" //| ... +//| //| def __bool__(self) -> bool: //| """``sleep_memory`` is ``True`` if its length is greater than zero. //| This is an easy way to check for its existence. //| """ +//| //| ... //| def __len__(self) -> int: //| """Return the length. This is used by (`len`)""" @@ -65,6 +67,7 @@ static MP_DEFINE_CONST_DICT(alarm_sleep_memory_locals_dict, alarm_sleep_memory_l //| def __getitem__(self, index: int) -> int: //| """Returns the value at the given index.""" //| ... +//| //| @overload //| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ... //| @overload diff --git a/shared-bindings/canio/Listener.c b/shared-bindings/canio/Listener.c index f208bc5aff997..26b5fb2cbb2ac 100644 --- a/shared-bindings/canio/Listener.c +++ b/shared-bindings/canio/Listener.c @@ -60,6 +60,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_in_waiting_obj, canio_listener_i //| This method exists so that `Listener` can be used as an //| iterable""" //| ... +//| //| def __next__(self) -> Union[RemoteTransmissionRequest, Message]: //| """Reads a message, after waiting up to self.timeout seconds //| diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index ee1f0655a43a8..4c8fc97345cf4 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -117,6 +117,7 @@ MP_PROPERTY_GETTER(displayio_bitmap_bits_per_value_obj, //| //| print(bitmap[0,1])""" //| ... +//| //| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None: //| """Sets the value at the given index. The index can either be an x,y tuple or an int equal //| to ``y * width + x``. diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index f7fd2f215e129..73c3d06988c8d 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -261,6 +261,7 @@ static mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| //| print(group[0])""" //| ... +//| //| def __setitem__( //| self, //| index: int, @@ -272,6 +273,7 @@ static mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| //| group[0] = sprite""" //| ... +//| //| def __delitem__(self, index: int) -> None: //| """Deletes the value at the given index. //| diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index fbca7b626ea88..528df88ec4e7e 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -84,6 +84,7 @@ static mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { //| def __getitem__(self, index: int) -> Optional[int]: //| r"""Return the pixel color at the given index as an integer.""" //| ... +//| //| def __setitem__( //| self, index: int, value: Union[int, ReadableBuffer, Tuple[int, int, int]] //| ) -> None: diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 533f07a94ba54..9800480b22a45 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -389,6 +389,7 @@ MP_PROPERTY_GETSET(displayio_tilegrid_bitmap_obj, //| //| print(grid[0])""" //| ... +//| //| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None: //| """Sets the tile index at the given index. The index can either be an x,y tuple or an int equal //| to ``y * width + x``. diff --git a/shared-bindings/fontio/BuiltinFont.c b/shared-bindings/fontio/BuiltinFont.c index 0274bbe92cf60..9d3f30675b9ea 100644 --- a/shared-bindings/fontio/BuiltinFont.c +++ b/shared-bindings/fontio/BuiltinFont.c @@ -27,6 +27,7 @@ //| The two element version is ``(width, height)``, in which //| ``x_offset`` and ``y_offset`` are assumed to be zero.""" //| pass +//| //| def get_glyph(self, codepoint: int) -> Optional[Glyph]: //| """Retrieve the Glyph for a given code point //| diff --git a/shared-bindings/keypad/EventQueue.c b/shared-bindings/keypad/EventQueue.c index 74fd8cbc163a5..e15b19df3b8f8 100644 --- a/shared-bindings/keypad/EventQueue.c +++ b/shared-bindings/keypad/EventQueue.c @@ -80,6 +80,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(keypad_eventqueue_clear_obj, keypad_eventqueue_clear); //| This is an easy way to check if the queue is empty. //| """ //| ... +//| //| def __len__(self) -> int: //| """Return the number of events currently in the queue. Used to implement ``len()``.""" //| ... diff --git a/shared-bindings/memorymap/AddressRange.c b/shared-bindings/memorymap/AddressRange.c index 97577feac84b3..6e084f417df01 100644 --- a/shared-bindings/memorymap/AddressRange.c +++ b/shared-bindings/memorymap/AddressRange.c @@ -129,8 +129,10 @@ static MP_DEFINE_CONST_DICT(memorymap_addressrange_locals_dict, memorymap_addres //| when possible. //| All others may use multiple transactions.""" //| ... +//| //| @overload //| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ... +//| //| @overload //| def __setitem__(self, index: int, value: int) -> None: //| """Set the value(s) at the given index. diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index 70fea2de90b54..7549023247eca 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -55,6 +55,7 @@ static MP_DEFINE_CONST_DICT(nvm_bytearray_locals_dict, nvm_bytearray_locals_dict //| def __getitem__(self, index: int) -> int: //| """Returns the value at the given index.""" //| ... +//| //| @overload //| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ... //| @overload diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index d4bc000e56ef8..f0e829d22f876 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -31,7 +31,7 @@ //| :param ~microcontroller.Pin miso: The pin transferring data from the secondary to the main //| :param ~microcontroller.Pin ss: The secondary selection pin""" //| ... -STATIC mp_obj_t spitarget_spi_target_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t spitarget_spi_target_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); enum { ARG_sck, ARG_mosi, ARG_miso, ARG_ss }; static const mp_arg_t allowed_args[] = { @@ -55,7 +55,8 @@ STATIC mp_obj_t spitarget_spi_target_make_new(const mp_obj_type_t *type, size_t //| def deinit(self) -> None: //| """Releases control of the underlying hardware so other classes can use it.""" //| ... -STATIC mp_obj_t spitarget_spi_target_obj_deinit(mp_obj_t self_in) { +//| +static mp_obj_t spitarget_spi_target_obj_deinit(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(self_in); common_hal_spitarget_spi_target_deinit(self); @@ -66,19 +67,21 @@ MP_DEFINE_CONST_FUN_OBJ_1(spitarget_spi_target_deinit_obj, spitarget_spi_target_ //| def __enter__(self) -> SPITarget: //| """No-op used in Context Managers.""" //| ... +//| // Provided by context manager helper. //| def __exit__(self) -> None: //| """Automatically deinitializes the hardware on context exit. See //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... -STATIC mp_obj_t spitarget_spi_target_obj___exit__(size_t n_args, const mp_obj_t *args) { +//| +static mp_obj_t spitarget_spi_target_obj___exit__(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &spitarget_spi_target_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); common_hal_spitarget_spi_target_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, 4, spitarget_spi_target_obj___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, 4, spitarget_spi_target_obj___exit__); //| def load_packet(self, mosi_packet: bytearray, miso_packet: bytearray) -> None: //| """Queue data for the next SPI transfer from the main device. @@ -87,7 +90,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, //| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request. //| :param bytearray mosi_packet: Packet to be filled with data from main on next request. //| """ -STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); if (common_hal_spitarget_spi_target_deinited(self)) { @@ -114,16 +117,16 @@ STATIC mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t * common_hal_spitarget_spi_target_transfer_start(self, ((uint8_t *)mosi_bufinfo.buf), ((uint8_t *)miso_bufinfo.buf), mosi_bufinfo.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spitarget_spi_target_load_packet); +static MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spitarget_spi_target_load_packet); //| def wait_transfer(self, *, timeout: float = -1) -> bool: //| """Wait for an SPI transfer from the main device. //| //| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once //| :return: True if the transfer is complete, or False if no response received before the timeout -//| :rtype: ~bool""" +//| """ //| -STATIC mp_obj_t spitarget_spi_target_wait_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t spitarget_spi_target_wait_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); if (common_hal_spitarget_spi_target_deinited(self)) { @@ -161,9 +164,9 @@ STATIC mp_obj_t spitarget_spi_target_wait_transfer(size_t n_args, const mp_obj_t return mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_wait_transfer_obj, 1, spitarget_spi_target_wait_transfer); +static MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_wait_transfer_obj, 1, spitarget_spi_target_wait_transfer); -STATIC const mp_rom_map_elem_t spitarget_spi_target_locals_dict_table[] = { +static const mp_rom_map_elem_t spitarget_spi_target_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&spitarget_spi_target_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&spitarget_spi_target___exit___obj) }, @@ -172,7 +175,7 @@ STATIC const mp_rom_map_elem_t spitarget_spi_target_locals_dict_table[] = { }; -STATIC MP_DEFINE_CONST_DICT(spitarget_spi_target_locals_dict, spitarget_spi_target_locals_dict_table); +static MP_DEFINE_CONST_DICT(spitarget_spi_target_locals_dict, spitarget_spi_target_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( spitarget_spi_target_type, diff --git a/shared-bindings/spitarget/__init__.c b/shared-bindings/spitarget/__init__.c index 69f40df52c7fa..74ec3ec77892e 100644 --- a/shared-bindings/spitarget/__init__.c +++ b/shared-bindings/spitarget/__init__.c @@ -48,20 +48,20 @@ //| >>> spi.write(bytearray([0, 0])) # ADC command: read from A0 //| >>> adc_result = bytearray(2) //| >>> spi.readinto(adc_result) -//| >>> adc_result -//| bytearray(b'\xc4\x16') +//| >>> list(adc_result) # show output from ADC +//| [196, 22] //| >>> spi.unlock() //| //| """ -STATIC const mp_rom_map_elem_t spitarget_module_globals_table[] = { +static const mp_rom_map_elem_t spitarget_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_spitarget) }, { MP_ROM_QSTR(MP_QSTR_SPITarget), MP_ROM_PTR(&spitarget_spi_target_type) }, }; -STATIC MP_DEFINE_CONST_DICT(spitarget_module_globals, spitarget_module_globals_table); +static MP_DEFINE_CONST_DICT(spitarget_module_globals, spitarget_module_globals_table); const mp_obj_module_t spitarget_module = { .base = { &mp_type_module }, diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index eb42fe0591877..e046c11879744 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -255,30 +255,38 @@ static const mp_rom_map_elem_t storage_module_globals_table[] = { //| larger filesystems, but you will need to format the filesystem on another device. //| """ //| ... +//| //| def open(self, path: str, mode: str) -> None: //| """Like builtin ``open()``""" //| ... +//| //| def ilistdir( //| self, path: str //| ) -> Iterator[Union[Tuple[AnyStr, int, int, int], Tuple[AnyStr, int, int]]]: //| """Return an iterator whose values describe files and folders within //| ``path``""" //| ... +//| //| def mkdir(self, path: str) -> None: //| """Like `os.mkdir`""" //| ... +//| //| def rmdir(self, path: str) -> None: //| """Like `os.rmdir`""" //| ... +//| //| def stat(self, path: str) -> Tuple[int, int, int, int, int, int, int, int, int, int]: //| """Like `os.stat`""" //| ... +//| //| def statvfs(self, path: int) -> Tuple[int, int, int, int, int, int, int, int, int, int]: //| """Like `os.statvfs`""" //| ... +//| //| def mount(self, readonly: bool, mkfs: VfsFat) -> None: //| """Don't call this directly, call `storage.mount`.""" //| ... +//| //| def umount(self) -> None: //| """Don't call this directly, call `storage.umount`.""" //| ... diff --git a/shared-bindings/usb_cdc/Serial.c b/shared-bindings/usb_cdc/Serial.c index d2413898cf133..1fd5ed4afcfdf 100644 --- a/shared-bindings/usb_cdc/Serial.c +++ b/shared-bindings/usb_cdc/Serial.c @@ -21,6 +21,7 @@ //| """You cannot create an instance of `usb_cdc.Serial`. //| The available instances are in the ``usb_cdc.serials`` tuple.""" //| ... +//| //| def read(self, size: int = -1) -> bytes: //| """Read at most ``size`` bytes. If ``size`` exceeds the internal buffer size, //| only the bytes in the buffer will be read. If ``size`` is not specified or is ``-1``, @@ -34,6 +35,7 @@ //| :return: Data read //| :rtype: bytes""" //| ... +//| //| def readinto(self, buf: WriteableBuffer) -> int: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. If `timeout` //| is > 0 or ``None``, keep waiting until the timeout expires or ``len(buf)`` @@ -42,6 +44,7 @@ //| :return: number of bytes read and stored into ``buf`` //| :rtype: int""" //| ... +//| //| def readline(self, size: int = -1) -> Optional[bytes]: //| r"""Read a line ending in a newline character ("\\n"), including the newline. //| Return everything readable if no newline is found and ``timeout`` is 0. @@ -54,6 +57,7 @@ //| :return: the line read //| :rtype: bytes or None""" //| ... +//| //| def readlines(self) -> List[Optional[bytes]]: //| """Read multiple lines as a list, using `readline()`. //| @@ -63,12 +67,14 @@ //| :return: a list of the line read //| :rtype: list""" //| ... +//| //| def write(self, buf: ReadableBuffer) -> int: //| """Write as many bytes as possible from the buffer of bytes. //| //| :return: the number of bytes written //| :rtype: int""" //| ... +//| //| def flush(self) -> None: //| """Force out any unwritten bytes, waiting until they are written.""" //| ... diff --git a/shared-bindings/usb_midi/PortIn.c b/shared-bindings/usb_midi/PortIn.c index 387a22b5e99c6..38662a4468cd2 100644 --- a/shared-bindings/usb_midi/PortIn.c +++ b/shared-bindings/usb_midi/PortIn.c @@ -35,6 +35,7 @@ //| :return: Data read //| :rtype: bytes or None""" //| ... +//| //| def readinto(self, buf: WriteableBuffer, nbytes: Optional[int] = None) -> Optional[bytes]: //| """Read bytes into the ``buf``. If ``nbytes`` is specified then read at most //| that many bytes. Otherwise, read at most ``len(buf)`` bytes. diff --git a/shared-bindings/wifi/ScannedNetworks.c b/shared-bindings/wifi/ScannedNetworks.c index f06439f9c17ff..dea3474d423e1 100644 --- a/shared-bindings/wifi/ScannedNetworks.c +++ b/shared-bindings/wifi/ScannedNetworks.c @@ -30,9 +30,11 @@ static mp_obj_t scannednetworks_iternext(mp_obj_t self_in) { //| def __init__(self) -> None: //| """Cannot be instantiated directly. Use `wifi.Radio.start_scanning_networks`.""" //| ... +//| //| def __iter__(self) -> Iterator[Network]: //| """Returns itself since it is the iterator.""" //| ... +//| //| def __next__(self) -> Network: //| """Returns the next `wifi.Network`. //| Raises `StopIteration` if scanning is finished and no other results are available.""" diff --git a/tools/analyze_heap_dump.py b/tools/analyze_heap_dump.py index 18da11c456ff2..a5e5e1d48eabb 100755 --- a/tools/analyze_heap_dump.py +++ b/tools/analyze_heap_dump.py @@ -270,9 +270,9 @@ def load_pointer(address): manual_symbol_map["0x200015e0"] = "mp_state_ctx.vm.dict_main" for i in range(READLINE_HIST_SIZE): - manual_symbol_map[ - "mp_state_ctx+{}".format(148 + i * 4) - ] = "mp_state_ctx.vm.readline_hist[{}]".format(i) + manual_symbol_map["mp_state_ctx+{}".format(148 + i * 4)] = ( + "mp_state_ctx.vm.readline_hist[{}]".format(i) + ) tuple_type = symbols["mp_type_tuple"][0] type_type = symbols["mp_type_type"][0] @@ -534,10 +534,10 @@ def format(obj): ) node.attr["shape"] = "plaintext" node.attr["style"] = "invisible" - node.attr[ - "label" - ] = '<{}
0x{:08x}
>'.format( - block, rows + node.attr["label"] = ( + '<{}
0x{:08x}
>'.format( + block, rows + ) ) for node, degree in ownership_graph.in_degree_iter(): @@ -616,10 +616,10 @@ def format(obj): remaining_bytecode -= 16 for i in range(remaining_bytecode // 16): rows += '' - node.attr[ - "label" - ] = '<{}
0x{:08x}
>'.format( - block, rows + node.attr["label"] = ( + '<{}
0x{:08x}
>'.format( + block, rows + ) ) for block in qstr_chunks: @@ -653,10 +653,10 @@ def format(obj): for i in range(0, len(printable_qstrs), 16): wrapped.append(html.escape(printable_qstrs[i : i + 16])) node = ownership_graph.get_node(block) - node.attr[ - "label" - ] = '<
0x{:08x}
{}
>'.format( - block, 18 * (len(wrapped) - 1), "
".join(wrapped) + node.attr["label"] = ( + '<
0x{:08x}
{}
>'.format( + block, 18 * (len(wrapped) - 1), "
".join(wrapped) + ) ) node.attr["fontname"] = "FiraCode-Bold" node.attr["fontcolor"] = "black" @@ -734,10 +734,10 @@ def format(obj): rows += '{}{}'.format( cells[2 * i][0], cells[2 * i][1], cells[2 * i + 1][0], cells[2 * i + 1][1] ) - node.attr[ - "label" - ] = '<{}
>'.format( - rows + node.attr["label"] = ( + '<{}
>'.format( + rows + ) ) ownership_graph.add_node( From a4a563293b01fdcb9bc09fb7f9dae6fad572079a Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 14:46:00 -0800 Subject: [PATCH 47/55] limit spitarget to only boards with enough memory for an additional module --- ports/atmel-samd/mpconfigport.mk | 2 +- shared-bindings/alarm/SleepMemory.c | 2 +- shared-bindings/spitarget/SPITarget.c | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 3dde2885d1f68..af62a24e99728 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -119,7 +119,7 @@ CIRCUITPY_MAX3421E ?= $(HAS_1MB_FLASH) CIRCUITPY_PS2IO ?= 1 CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FRAMEBUFFERIO) CIRCUITPY_SAMD ?= 1 -CIRCUITPY_SPITARGET ?= 1 +CIRCUITPY_SPITARGET ?= $(HAS_1MB_FLASH) CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12 CIRCUITPY_ULAB_OPTIMIZE_SIZE ?= 1 CIRCUITPY_WATCHDOG ?= 1 diff --git a/shared-bindings/alarm/SleepMemory.c b/shared-bindings/alarm/SleepMemory.c index 007fb26ec86a8..d783983008c5f 100644 --- a/shared-bindings/alarm/SleepMemory.c +++ b/shared-bindings/alarm/SleepMemory.c @@ -38,8 +38,8 @@ //| """``sleep_memory`` is ``True`` if its length is greater than zero. //| This is an easy way to check for its existence. //| """ -//| //| ... +//| //| def __len__(self) -> int: //| """Return the length. This is used by (`len`)""" //| ... diff --git a/shared-bindings/spitarget/SPITarget.c b/shared-bindings/spitarget/SPITarget.c index f0e829d22f876..eca92d800277b 100644 --- a/shared-bindings/spitarget/SPITarget.c +++ b/shared-bindings/spitarget/SPITarget.c @@ -31,6 +31,7 @@ //| :param ~microcontroller.Pin miso: The pin transferring data from the secondary to the main //| :param ~microcontroller.Pin ss: The secondary selection pin""" //| ... +//| static mp_obj_t spitarget_spi_target_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { spitarget_spi_target_obj_t *self = mp_obj_malloc(spitarget_spi_target_obj_t, &spitarget_spi_target_type); enum { ARG_sck, ARG_mosi, ARG_miso, ARG_ss }; @@ -90,6 +91,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spitarget_spi_target___exit___obj, 4, //| :param bytearray miso_packet: Packet data to be sent from secondary to main on next request. //| :param bytearray mosi_packet: Packet to be filled with data from main on next request. //| """ +//| static mp_obj_t spitarget_spi_target_load_packet(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); @@ -126,6 +128,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(spitarget_spi_target_load_packet_obj, 1, spita //| :return: True if the transfer is complete, or False if no response received before the timeout //| """ //| +//| static mp_obj_t spitarget_spi_target_wait_transfer(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_check_self(mp_obj_is_type(pos_args[0], &spitarget_spi_target_type)); spitarget_spi_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); From 84f9849c5e9dfb6199054c3c2633561620e9009d Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 16:41:37 -0800 Subject: [PATCH 48/55] rebuild zephyr boards --- ports/zephyr-cp/boards/nordic/nrf5340dk/autogen_board_info.toml | 1 + ports/zephyr-cp/boards/nordic/nrf54l15dk/autogen_board_info.toml | 1 + ports/zephyr-cp/boards/nordic/nrf7002dk/autogen_board_info.toml | 1 + ports/zephyr-cp/boards/renesas/ek_ra6m5/autogen_board_info.toml | 1 + ports/zephyr-cp/boards/renesas/ek_ra8d1/autogen_board_info.toml | 1 + .../zephyr-cp/boards/st/nucleo_u575zi_q/autogen_board_info.toml | 1 + ports/zephyr-cp/boards/st/stm32h7b3i_dk/autogen_board_info.toml | 1 + 7 files changed, 7 insertions(+) diff --git a/ports/zephyr-cp/boards/nordic/nrf5340dk/autogen_board_info.toml b/ports/zephyr-cp/boards/nordic/nrf5340dk/autogen_board_info.toml index b497ea7b2cc97..a521b62fb4c30 100644 --- a/ports/zephyr-cp/boards/nordic/nrf5340dk/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/nordic/nrf5340dk/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = false +spitarget = false ssl = false storage = true # Zephyr board has flash struct = true diff --git a/ports/zephyr-cp/boards/nordic/nrf54l15dk/autogen_board_info.toml b/ports/zephyr-cp/boards/nordic/nrf54l15dk/autogen_board_info.toml index 389201b795ea2..d8266a9b8515f 100644 --- a/ports/zephyr-cp/boards/nordic/nrf54l15dk/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/nordic/nrf54l15dk/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = false +spitarget = false ssl = false storage = true # Zephyr board has flash struct = true diff --git a/ports/zephyr-cp/boards/nordic/nrf7002dk/autogen_board_info.toml b/ports/zephyr-cp/boards/nordic/nrf7002dk/autogen_board_info.toml index 228df6e9c45e8..baacdff5dd1e7 100644 --- a/ports/zephyr-cp/boards/nordic/nrf7002dk/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/nordic/nrf7002dk/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = true # Zephyr networking enabled +spitarget = false ssl = true # Zephyr networking enabled storage = true # Zephyr board has flash struct = true diff --git a/ports/zephyr-cp/boards/renesas/ek_ra6m5/autogen_board_info.toml b/ports/zephyr-cp/boards/renesas/ek_ra6m5/autogen_board_info.toml index 7025cc3c1e470..31e979864ac1d 100644 --- a/ports/zephyr-cp/boards/renesas/ek_ra6m5/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/renesas/ek_ra6m5/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = false +spitarget = false ssl = false storage = true # Zephyr board has flash struct = true diff --git a/ports/zephyr-cp/boards/renesas/ek_ra8d1/autogen_board_info.toml b/ports/zephyr-cp/boards/renesas/ek_ra8d1/autogen_board_info.toml index 3134250e940b6..0f366c079bb6b 100644 --- a/ports/zephyr-cp/boards/renesas/ek_ra8d1/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/renesas/ek_ra8d1/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = false +spitarget = false ssl = false storage = true # Zephyr board has flash struct = true diff --git a/ports/zephyr-cp/boards/st/nucleo_u575zi_q/autogen_board_info.toml b/ports/zephyr-cp/boards/st/nucleo_u575zi_q/autogen_board_info.toml index 8b661139835cf..cb20c3e59300e 100644 --- a/ports/zephyr-cp/boards/st/nucleo_u575zi_q/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/st/nucleo_u575zi_q/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = false +spitarget = false ssl = false storage = false struct = true diff --git a/ports/zephyr-cp/boards/st/stm32h7b3i_dk/autogen_board_info.toml b/ports/zephyr-cp/boards/st/stm32h7b3i_dk/autogen_board_info.toml index bc3031f1c47b0..c755838d554a2 100644 --- a/ports/zephyr-cp/boards/st/stm32h7b3i_dk/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/st/stm32h7b3i_dk/autogen_board_info.toml @@ -83,6 +83,7 @@ sdcardio = false sdioio = false sharpdisplay = false socketpool = false +spitarget = false ssl = false storage = true # Zephyr board has flash struct = true From b085b79fd3dd0c7ee764344303c60ef9355aabf8 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 17:39:49 -0800 Subject: [PATCH 49/55] save some flash by configuring each busio.SPI pin with a helper function --- ports/atmel-samd/common-hal/busio/SPI.c | 26 +++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 067bea3c209df..25b3b4c31db0c 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -21,6 +21,14 @@ #include "samd/dma.h" #include "samd/sercom.h" +void setup_pin(const mcu_pin_obj_t *pin, uint32_t pinmux) { + gpio_set_pin_direction(pin->number, GPIO_DIRECTION_OUT); + gpio_set_pin_pull_mode(pin->number, GPIO_PULL_OFF); + gpio_set_pin_function(pin->number, pinmux); + claim_pin(pin); + hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(pin->number), GPIO_PIN(pin->number)); +} + void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso, bool half_duplex) { @@ -139,33 +147,21 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, mp_raise_OSError(MP_EIO); } - gpio_set_pin_direction(clock->number, GPIO_DIRECTION_OUT); - gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); - gpio_set_pin_function(clock->number, clock_pinmux); - claim_pin(clock); - hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(clock->number), GPIO_PIN(clock->number)); + setup_pin(clock, clock_pinmux); self->clock_pin = clock->number; if (mosi_none) { self->MOSI_pin = NO_PIN; } else { - gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_OUT); - gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); - gpio_set_pin_function(mosi->number, mosi_pinmux); + setup_pin(mosi, mosi_pinmux); self->MOSI_pin = mosi->number; - claim_pin(mosi); - hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(mosi->number), GPIO_PIN(mosi->number)); } if (miso_none) { self->MISO_pin = NO_PIN; } else { - gpio_set_pin_direction(miso->number, GPIO_DIRECTION_IN); - gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF); - gpio_set_pin_function(miso->number, miso_pinmux); + setup_pin(miso, miso_pinmux); self->MISO_pin = miso->number; - claim_pin(miso); - hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(miso->number), GPIO_PIN(miso->number)); } spi_m_sync_enable(&self->spi_desc); From 186d6913c5933802bf6c9bb273417c8254cb7907 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 18:02:44 -0800 Subject: [PATCH 50/55] save some flash by configuring each busio.SPI pin with a helper function --- ports/atmel-samd/common-hal/busio/SPI.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 25b3b4c31db0c..5d7633be7f8d3 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -21,13 +21,7 @@ #include "samd/dma.h" #include "samd/sercom.h" -void setup_pin(const mcu_pin_obj_t *pin, uint32_t pinmux) { - gpio_set_pin_direction(pin->number, GPIO_DIRECTION_OUT); - gpio_set_pin_pull_mode(pin->number, GPIO_PULL_OFF); - gpio_set_pin_function(pin->number, pinmux); - claim_pin(pin); - hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(pin->number), GPIO_PIN(pin->number)); -} +void setup_pin(const mcu_pin_obj_t *pin, uint32_t pinmux); void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, @@ -323,3 +317,11 @@ uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t *self) { void *hw = self->spi_desc.dev.prvt; return hri_sercomspi_get_CTRLA_CPOL_bit(hw); } + +void setup_pin(const mcu_pin_obj_t *pin, uint32_t pinmux) { + gpio_set_pin_direction(pin->number, GPIO_DIRECTION_OUT); + gpio_set_pin_pull_mode(pin->number, GPIO_PULL_OFF); + gpio_set_pin_function(pin->number, pinmux); + claim_pin(pin); + hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(pin->number), GPIO_PIN(pin->number)); +} From f3c144e68b687a7b908cb26a5fa96862d9076dcd Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 18:36:07 -0800 Subject: [PATCH 51/55] slightly increase board firmware size to fit --- .../atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h b/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h index 67507f1e4b6d3..a805db57756fa 100644 --- a/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h @@ -15,6 +15,8 @@ #define CIRCUITPY_BOARD_SPI (1) #define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_PA05, .mosi = &pin_PA04, .miso = &pin_PA06}} +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (60 * 1024) + #define IGNORE_PIN_PA00 1 #define IGNORE_PIN_PA03 1 From 2504cd2204ec95eca67c073deed51adb3d1be9bf Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 22:07:31 -0800 Subject: [PATCH 52/55] rollout spitarget to more boards --- ports/atmel-samd/mpconfigport.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index af62a24e99728..3dde2885d1f68 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -119,7 +119,7 @@ CIRCUITPY_MAX3421E ?= $(HAS_1MB_FLASH) CIRCUITPY_PS2IO ?= 1 CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FRAMEBUFFERIO) CIRCUITPY_SAMD ?= 1 -CIRCUITPY_SPITARGET ?= $(HAS_1MB_FLASH) +CIRCUITPY_SPITARGET ?= 1 CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12 CIRCUITPY_ULAB_OPTIMIZE_SIZE ?= 1 CIRCUITPY_WATCHDOG ?= 1 From d9372211f302d71be855bab91eeb7e91040b09c2 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Mon, 10 Feb 2025 22:25:59 -0800 Subject: [PATCH 53/55] remove spitarget from specific samd51 boards that are already tight on space --- ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk | 1 + ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk | 1 + ports/atmel-samd/boards/pybadge/mpconfigboard.mk | 1 + ports/atmel-samd/boards/pygamer/mpconfigboard.mk | 1 + ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk | 1 + ports/atmel-samd/boards/uartlogger2/mpconfigboard.mk | 1 + 6 files changed, 6 insertions(+) diff --git a/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk b/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk index b470a2860e6a5..46aa0b7dc659f 100755 --- a/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk @@ -12,4 +12,5 @@ LONGINT_IMPL = MPZ CIRCUITPY_PS2IO = 1 CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SPITARGET = 0 CIRCUITPY_SYNTHIO = 0 diff --git a/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk b/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk index 95123ae5b85da..8f06d8d1e5168 100644 --- a/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/datalore_ip_m4/mpconfigboard.mk @@ -11,3 +11,4 @@ EXTERNAL_FLASH_DEVICES = "GD25Q16C, W25Q16JVxQ, W25Q16JVxM" LONGINT_IMPL = MPZ CIRCUITPY_SYNTHIO = 0 CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SPITARGET = 0 diff --git a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk index 8005146114a47..5f4f8cb30cd6e 100644 --- a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk @@ -18,6 +18,7 @@ CIRCUITPY_I2CDISPLAYBUS = 0 CIRCUITPY_JPEGIO = 0 CIRCUITPY_KEYPAD = 1 CIRCUITPY_PARALLELDISPLAYBUS= 0 +CIRCUITPY_SPITARGET = 0 CIRCUITPY_STAGE = 1 FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pybadge diff --git a/ports/atmel-samd/boards/pygamer/mpconfigboard.mk b/ports/atmel-samd/boards/pygamer/mpconfigboard.mk index 5149dda508fb4..6f6dee2e1c42b 100644 --- a/ports/atmel-samd/boards/pygamer/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pygamer/mpconfigboard.mk @@ -18,6 +18,7 @@ CIRCUITPY_I2CDISPLAYBUS = 0 CIRCUITPY_JPEGIO = 0 CIRCUITPY_KEYPAD = 1 CIRCUITPY_PARALLELDISPLAYBUS= 0 +CIRCUITPY_SPITARGET = 0 CIRCUITPY_STAGE = 1 FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pygamer diff --git a/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk b/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk index 7c576a0376bdf..16e439d3ef91f 100644 --- a/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk +++ b/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SPITARGET = 0 CIRCUITPY_SYNTHIO = 0 diff --git a/ports/atmel-samd/boards/uartlogger2/mpconfigboard.mk b/ports/atmel-samd/boards/uartlogger2/mpconfigboard.mk index 1181abd9640dc..4b23566f71fd0 100644 --- a/ports/atmel-samd/boards/uartlogger2/mpconfigboard.mk +++ b/ports/atmel-samd/boards/uartlogger2/mpconfigboard.mk @@ -9,5 +9,6 @@ CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" LONGINT_IMPL = MPZ +CIRCUITPY_SPITARGET = 0 CIRCUITPY_SYNTHIO = 0 CIRCUITPY_JPEGIO = 0 From 00a831fc4f9e502e3b20b3f79db47cf57daf733d Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Tue, 11 Feb 2025 01:43:36 -0800 Subject: [PATCH 54/55] update spitarget documentation example to be more complete and responsive --- shared-bindings/spitarget/__init__.c | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/shared-bindings/spitarget/__init__.c b/shared-bindings/spitarget/__init__.c index 74ec3ec77892e..0fcf90ea34be6 100644 --- a/shared-bindings/spitarget/__init__.c +++ b/shared-bindings/spitarget/__init__.c @@ -35,22 +35,40 @@ //| miso_buffer[1] = (reading) & 0xFF //| # Send array of bytes over SPI to main //| device.load_packet(mosi_buffer, miso_buffer) -//| device.wait_transfer(0) +//| while not device.wait_transfer(timeout=-1): +//| pass //| # Handle command from main, which sets the ADC channel //| selected_channel = map_adc_channel((mosi_buffer[0] << 8) | mosi_buffer[1]) //| //| Communicating with the ADC emulator from the REPL of an attached CircuitPython board might look like :: //| +//| >>> import board +//| >>> import digitalio //| >>> import busio +//| >>> import time +//| >>> +//| >>> ## setup //| >>> spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +//| >>> cs = digitalio.DigitalInOut(board.CS) +//| >>> cs.direction = digitalio.Direction.OUTPUT +//| >>> cs.value = True //| >>> spi.try_lock() //| True -//| >>> spi.write(bytearray([0, 0])) # ADC command: read from A0 +//| >>> +//| >>> ## ADC command: read from A0 +//| >>> cs.value = False +//| >>> spi.write(bytearray([0, 0])) +//| >>> cs.value = True +//| >>> +//| >>> # wait for ADC to read a value +//| >>> +//| >>> ## get two-byte output from ADC //| >>> adc_result = bytearray(2) -//| >>> spi.readinto(adc_result) -//| >>> list(adc_result) # show output from ADC -//| [196, 22] -//| >>> spi.unlock() +//| >>> cs.value = False +//| >>> spi.readinto(adc_result, write_value=1) +//| >>> cs.value = True +//| >>> list(adc_result) +//| [0, 255] //| //| """ From 3b864aedd586ef9477cff7e7e361003dd17cc420 Mon Sep 17 00:00:00 2001 From: Randall Scharpf Date: Thu, 13 Feb 2025 10:40:58 -0800 Subject: [PATCH 55/55] restore pixel_trinkey filesystem size --- .../atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h b/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h index a805db57756fa..67507f1e4b6d3 100644 --- a/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/adafruit_pixel_trinkey_m0/mpconfigboard.h @@ -15,8 +15,6 @@ #define CIRCUITPY_BOARD_SPI (1) #define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_PA05, .mosi = &pin_PA04, .miso = &pin_PA06}} -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (60 * 1024) - #define IGNORE_PIN_PA00 1 #define IGNORE_PIN_PA03 1 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy