diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h index 105205f191..9020c243b1 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h @@ -3,6 +3,9 @@ #define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_NEOPIXEL (&pin_PB23) +#define MICROPY_HW_NEOPIXEL_COUNT (10) + // Don't allow touch on A0 (PA02), because it's connected to the speaker. #define PA02_NO_TOUCH (true) diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h index 852e9651b1..5073c5e403 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h @@ -3,6 +3,9 @@ #define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_NEOPIXEL (&pin_PB23) +#define MICROPY_HW_NEOPIXEL_COUNT (10) + // Don't allow touch on A0 (PA02), because it's connected to the speaker. #define PA02_NO_TOUCH (true) diff --git a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h index a0bb560752..20cfc617a2 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h @@ -3,6 +3,9 @@ #define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_NEOPIXEL (&pin_PB23) +#define MICROPY_HW_NEOPIXEL_COUNT (10) + // Don't allow touch on A0 (PA02), because it's connected to the speaker. #define PA02_NO_TOUCH (true) diff --git a/ports/nrf/boards/circuitplayground_bluefruit/board.c b/ports/nrf/boards/circuitplayground_bluefruit/board.c index a0013e7215..938d92aff1 100644 --- a/ports/nrf/boards/circuitplayground_bluefruit/board.c +++ b/ports/nrf/boards/circuitplayground_bluefruit/board.c @@ -33,14 +33,7 @@ #include "nrf_gpio.h" void board_init(void) { -} - -bool board_requests_safe_mode(void) { - return false; -} - -void reset_board(void) { - // Turn off board.POWER_SWITCH (power-saving switch) on each soft reload, to prevent confusion. + // Turn on power to sensors and neopixels. nrf_gpio_cfg(POWER_SWITCH_PIN->number, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, @@ -48,6 +41,23 @@ void reset_board(void) { NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); nrf_gpio_pin_write(POWER_SWITCH_PIN->number, false); +} +void board_deinit(void) { + // Turn off power to sensors and neopixels. + nrf_gpio_cfg(POWER_SWITCH_PIN->number, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0S1, + NRF_GPIO_PIN_NOSENSE); + nrf_gpio_pin_write(POWER_SWITCH_PIN->number, true); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { board_reset_user_neopixels(&pin_P0_13, 10); } diff --git a/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h b/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h index da32230a6f..69bff08761 100644 --- a/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h +++ b/ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h @@ -32,6 +32,9 @@ #define MICROPY_HW_LED_STATUS (&pin_P1_14) +#define MICROPY_HW_NEOPIXEL (&pin_P0_13) +#define MICROPY_HW_NEOPIXEL_COUNT (10) + // Board does not have a 32kHz crystal. It does have a 32MHz crystal. #define BOARD_HAS_32KHZ_XTAL (0) diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index d57aba1973..6c89026223 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -39,9 +39,14 @@ static digitalio_digitalinout_obj_t _status_power; #ifdef MICROPY_HW_NEOPIXEL uint8_t rgb_status_brightness = 63; - #include "shared-bindings/digitalio/DigitalInOut.h" - #include "shared-bindings/neopixel_write/__init__.h" -static uint8_t status_neopixel_color[3]; +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/neopixel_write/__init__.h" + +#ifndef MICROPY_HW_NEOPIXEL_COUNT +#define MICROPY_HW_NEOPIXEL_COUNT (1) +#endif + +static uint8_t status_neopixel_color[3 * MICROPY_HW_NEOPIXEL_COUNT]; static digitalio_digitalinout_obj_t status_neopixel; #elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK) @@ -240,10 +245,12 @@ void new_status_color(uint32_t rgb) { #endif #ifdef MICROPY_HW_NEOPIXEL - status_neopixel_color[0] = (rgb_adjusted >> 8) & 0xff; - status_neopixel_color[1] = (rgb_adjusted >> 16) & 0xff; - status_neopixel_color[2] = rgb_adjusted & 0xff; - common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3); + for (size_t i = 0; i < MICROPY_HW_NEOPIXEL_COUNT; i++) { + status_neopixel_color[3 * i + 0] = (rgb_adjusted >> 8) & 0xff; + status_neopixel_color[3 * i + 1] = (rgb_adjusted >> 16) & 0xff; + status_neopixel_color[3 * i + 2] = rgb_adjusted & 0xff; + } + common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3 * MICROPY_HW_NEOPIXEL_COUNT); #elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK) status_apa102_color[5] = rgb_adjusted & 0xff;