diff --git a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h index eace9bc9db..05033ad38b 100644 --- a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h @@ -2,8 +2,8 @@ #define MICROPY_HW_MCU_NAME "samd21e18" // Rev B - Black -// #define MICROPY_HW_APA102_MOSI (&pin_PA00) -// #define MICROPY_HW_APA102_SCK (&pin_PA01) +#define MICROPY_HW_APA102_MOSI (&pin_PA00) +#define MICROPY_HW_APA102_SCK (&pin_PA01) #define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA24 | PORT_PA25) #define MICROPY_PORT_B (0) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index c4cd6e66f8..43288cc8bb 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -34,6 +34,7 @@ #include "hal/include/hal_gpio.h" #include "hal/include/hal_spi_m_sync.h" #include "hal/include/hpl_spi_m_sync.h" +#include "supervisor/shared/rgb_led_status.h" #include "peripherals.h" #include "pins.h" @@ -59,7 +60,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (potential_sercom == NULL || #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102) (potential_sercom->SPI.CTRLA.bit.ENABLE != 0 && - potential_sercom != status_apa102.spi_master_instance.hw && + potential_sercom != status_apa102.spi_desc.dev.prvt && !apa102_sck_in_use)) { #else potential_sercom->SPI.CTRLA.bit.ENABLE != 0) { @@ -113,6 +114,10 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // Set up SPI clocks on SERCOM. samd_peripherals_sercom_clock_init(sercom, sercom_index); + #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102) + // if we're re-using the dotstar sercom, make sure it is disabled or the init will fail out + hri_sercomspi_clear_CTRLA_ENABLE_bit(sercom); + #endif if (spi_m_sync_init(&self->spi_desc, sercom) != ERR_NONE) { mp_raise_OSError(MP_EIO); } diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 2899c1f5d8..5b55c1ba2d 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -70,11 +70,11 @@ void rgb_led_status_init() { MICROPY_HW_APA102_MOSI, mp_const_none); #else - if (status_apa102.current_baudrate > 0) { + if (!common_hal_busio_spi_deinited(&status_apa102)) { // Don't use spi_deinit because that leads to infinite // recursion because reset_pin may call // rgb_led_status_init. - spi_disable(&status_apa102.spi_master_instance); + spi_m_sync_disable(&status_apa102.spi_desc); } common_hal_busio_spi_construct(&status_apa102, MICROPY_HW_APA102_SCK,