From cdeb0857a9fec1bde99d492e7d4ef3713a29b921 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 25 Oct 2019 11:15:34 -0400 Subject: Initial Itsy nRF52840 defn --- supervisor/shared/rgb_led_status.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'supervisor') diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 4d9371516..0a03094ea 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -74,8 +74,14 @@ uint16_t status_rgb_color[3] = { static uint32_t current_status_color = 0; #endif - +static bool rgb_led_status_init_in_progress = false; void rgb_led_status_init() { + if (rgb_led_status_init_in_progress) { + // Avoid recursion. + return; + } + rgb_led_status_init_in_progress = true; + #ifdef MICROPY_HW_NEOPIXEL common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL); // Pretend we aren't using the pins. digitalio.DigitalInOut @@ -91,10 +97,9 @@ void rgb_led_status_init() { mp_const_none); #else if (!common_hal_busio_spi_deinited(&status_apa102)) { - // Don't use spi_deinit because that leads to infinite - // recursion because reset_pin_number may call - // rgb_led_status_init. - spi_m_sync_disable(&status_apa102.spi_desc); + // This may call us recursively if reset_pin_number() is called, + // The rgb_led_status_init_in_progress guard will prevent further recursion. + common_hal_busio_spi_deinit(&status_apa102); } common_hal_busio_spi_construct(&status_apa102, MICROPY_HW_APA102_SCK, @@ -149,6 +154,8 @@ void rgb_led_status_init() { current_status_color = 0x1000000; // Not a valid color new_status_color(rgb); #endif + + rgb_led_status_init_in_progress = false; } void reset_status_led() { -- cgit v1.2.3 From ab6fd34828d0cf33ac10375cb68ea1c71e08c657 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 25 Oct 2019 22:32:43 -0400 Subject: add object types to rgb status objects;mark spi rgb objects as never_reset --- .../itsybitsy_nrf52840_express/mpconfigboard.mk | 2 +- supervisor/shared/rgb_led_status.c | 31 ++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'supervisor') diff --git a/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.mk b/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.mk index 11be3121f..d290077e7 100644 --- a/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.mk +++ b/ports/nrf/boards/itsybitsy_nrf52840_express/mpconfigboard.mk @@ -21,7 +21,7 @@ endif NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 -# Don't use up a hardware SPI peripheral for the status DotStar: we only have two or three. +# Don't use up a hardware SPI peripheral for the status DotStar: we only have one or two. CIRCUITPY_BITBANG_APA102 = 1 QSPI_FLASH_FILESYSTEM = 1 diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 0a03094ea..ebb20b4cc 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -46,10 +46,18 @@ static uint8_t status_apa102_color[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, 0, #if CIRCUITPY_BITBANG_APA102 #include "shared-bindings/bitbangio/SPI.h" #include "shared-module/bitbangio/types.h" -static bitbangio_spi_obj_t status_apa102; +static bitbangio_spi_obj_t status_apa102 = { + .base = { + .type = &bitbangio_spi_type, + }, +}; #else #include "shared-bindings/busio/SPI.h" -busio_spi_obj_t status_apa102; +busio_spi_obj_t status_apa102 = { + .base = { + .type = &busio_spi_type, + }, +}; #endif #endif @@ -59,9 +67,21 @@ busio_spi_obj_t status_apa102; #include "shared-bindings/pulseio/PWMOut.h" #include "shared-bindings/microcontroller/Pin.h" -pulseio_pwmout_obj_t rgb_status_r; -pulseio_pwmout_obj_t rgb_status_g; -pulseio_pwmout_obj_t rgb_status_b; +pulseio_pwmout_obj_t rgb_status_r = { + .base = { + .type = &pulseio_pwmout_type, + }, +}; +pulseio_pwmout_obj_t rgb_status_g = { + .base = { + .type = &pulseio_pwmout_type, + }, +}; +pulseio_pwmout_obj_t rgb_status_b = { + .base = { + .type = &pulseio_pwmout_type, + }, +}; uint8_t rgb_status_brightness = 0xFF; @@ -105,6 +125,7 @@ void rgb_led_status_init() { MICROPY_HW_APA102_SCK, MICROPY_HW_APA102_MOSI, mp_const_none); + common_hal_busio_spi_never_reset(&status_apa102); #endif // Pretend we aren't using the pins. bitbangio.SPI will // mark them as used. -- cgit v1.2.3