Skip to content

Commit fa90635

Browse files
authored
Merge pull request #5052 from tannewt/playground_status
Support multiple status neopixels
2 parents 5fbe6d4 + e7fe0d9 commit fa90635

File tree

6 files changed

+43
-14
lines changed

6 files changed

+43
-14
lines changed

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#define MICROPY_HW_LED_STATUS (&pin_PA17)
55

6+
#define MICROPY_HW_NEOPIXEL (&pin_PB23)
7+
#define MICROPY_HW_NEOPIXEL_COUNT (10)
8+
69
// Don't allow touch on A0 (PA02), because it's connected to the speaker.
710
#define PA02_NO_TOUCH (true)
811

ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#define MICROPY_HW_LED_STATUS (&pin_PA17)
55

6+
#define MICROPY_HW_NEOPIXEL (&pin_PB23)
7+
#define MICROPY_HW_NEOPIXEL_COUNT (10)
8+
69
// Don't allow touch on A0 (PA02), because it's connected to the speaker.
710
#define PA02_NO_TOUCH (true)
811

ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#define MICROPY_HW_LED_STATUS (&pin_PA17)
55

6+
#define MICROPY_HW_NEOPIXEL (&pin_PB23)
7+
#define MICROPY_HW_NEOPIXEL_COUNT (10)
8+
69
// Don't allow touch on A0 (PA02), because it's connected to the speaker.
710
#define PA02_NO_TOUCH (true)
811

ports/nrf/boards/circuitplayground_bluefruit/board.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,31 @@
3333
#include "nrf_gpio.h"
3434

3535
void board_init(void) {
36+
// Turn on power to sensors and neopixels.
37+
nrf_gpio_cfg(POWER_SWITCH_PIN->number,
38+
NRF_GPIO_PIN_DIR_OUTPUT,
39+
NRF_GPIO_PIN_INPUT_DISCONNECT,
40+
NRF_GPIO_PIN_NOPULL,
41+
NRF_GPIO_PIN_S0S1,
42+
NRF_GPIO_PIN_NOSENSE);
43+
nrf_gpio_pin_write(POWER_SWITCH_PIN->number, false);
3644
}
3745

38-
bool board_requests_safe_mode(void) {
39-
return false;
40-
}
41-
42-
void reset_board(void) {
43-
// Turn off board.POWER_SWITCH (power-saving switch) on each soft reload, to prevent confusion.
46+
void board_deinit(void) {
47+
// Turn off power to sensors and neopixels.
4448
nrf_gpio_cfg(POWER_SWITCH_PIN->number,
4549
NRF_GPIO_PIN_DIR_OUTPUT,
4650
NRF_GPIO_PIN_INPUT_DISCONNECT,
4751
NRF_GPIO_PIN_NOPULL,
4852
NRF_GPIO_PIN_S0S1,
4953
NRF_GPIO_PIN_NOSENSE);
50-
nrf_gpio_pin_write(POWER_SWITCH_PIN->number, false);
54+
nrf_gpio_pin_write(POWER_SWITCH_PIN->number, true);
55+
}
5156

57+
bool board_requests_safe_mode(void) {
58+
return false;
59+
}
60+
61+
void reset_board(void) {
5262
board_reset_user_neopixels(&pin_P0_13, 10);
5363
}

ports/nrf/boards/circuitplayground_bluefruit/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
#define MICROPY_HW_LED_STATUS (&pin_P1_14)
3434

35+
#define MICROPY_HW_NEOPIXEL (&pin_P0_13)
36+
#define MICROPY_HW_NEOPIXEL_COUNT (10)
37+
3538
// Board does not have a 32kHz crystal. It does have a 32MHz crystal.
3639
#define BOARD_HAS_32KHZ_XTAL (0)
3740

supervisor/shared/status_leds.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ static digitalio_digitalinout_obj_t _status_power;
3939

4040
#ifdef MICROPY_HW_NEOPIXEL
4141
uint8_t rgb_status_brightness = 63;
42-
#include "shared-bindings/digitalio/DigitalInOut.h"
43-
#include "shared-bindings/neopixel_write/__init__.h"
44-
static uint8_t status_neopixel_color[3];
42+
#include "shared-bindings/digitalio/DigitalInOut.h"
43+
#include "shared-bindings/neopixel_write/__init__.h"
44+
45+
#ifndef MICROPY_HW_NEOPIXEL_COUNT
46+
#define MICROPY_HW_NEOPIXEL_COUNT (1)
47+
#endif
48+
49+
static uint8_t status_neopixel_color[3 * MICROPY_HW_NEOPIXEL_COUNT];
4550
static digitalio_digitalinout_obj_t status_neopixel;
4651

4752
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
@@ -240,10 +245,12 @@ void new_status_color(uint32_t rgb) {
240245
#endif
241246

242247
#ifdef MICROPY_HW_NEOPIXEL
243-
status_neopixel_color[0] = (rgb_adjusted >> 8) & 0xff;
244-
status_neopixel_color[1] = (rgb_adjusted >> 16) & 0xff;
245-
status_neopixel_color[2] = rgb_adjusted & 0xff;
246-
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3);
248+
for (size_t i = 0; i < MICROPY_HW_NEOPIXEL_COUNT; i++) {
249+
status_neopixel_color[3 * i + 0] = (rgb_adjusted >> 8) & 0xff;
250+
status_neopixel_color[3 * i + 1] = (rgb_adjusted >> 16) & 0xff;
251+
status_neopixel_color[3 * i + 2] = rgb_adjusted & 0xff;
252+
}
253+
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3 * MICROPY_HW_NEOPIXEL_COUNT);
247254

248255
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
249256
status_apa102_color[5] = rgb_adjusted & 0xff;

0 commit comments

Comments
 (0)