Skip to content

Commit 5484a2d

Browse files
authored
Merge pull request #5219 from tannewt/multiple_status_dotstars
Support multiple status dotstars
2 parents cd912e1 + f9f3894 commit 5484a2d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#define MICROPY_HW_APA102_MOSI (&pin_GPIO14)
3333
#define MICROPY_HW_APA102_SCK (&pin_GPIO15)
34+
#define MICROPY_HW_APA102_COUNT (5)
3435

3536
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
3637

supervisor/shared/status_leds.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "supervisor/shared/status_leds.h"
2828

29+
#include <string.h>
30+
2931
#include "mphalport.h"
3032
#include "shared-bindings/microcontroller/Pin.h"
3133
#include "supervisor/shared/tick.h"
@@ -52,8 +54,12 @@ static digitalio_digitalinout_obj_t status_neopixel;
5254
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
5355
uint8_t rgb_status_brightness = 50;
5456

55-
#define APA102_BUFFER_LENGTH 12
56-
static uint8_t status_apa102_color[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff};
57+
#ifndef MICROPY_HW_APA102_COUNT
58+
#define MICROPY_HW_APA102_COUNT (1)
59+
#endif
60+
61+
#define APA102_BUFFER_LENGTH (4 + 4 * MICROPY_HW_APA102_COUNT + 4)
62+
static uint8_t status_apa102_color[APA102_BUFFER_LENGTH];
5763

5864
#if CIRCUITPY_BITBANG_APA102
5965
#include "shared-bindings/bitbangio/SPI.h"
@@ -142,6 +148,8 @@ void status_led_init() {
142148
common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
143149
common_hal_digitalio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL);
144150
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
151+
// Set every byte to 0xff except the start 4 bytes that make up the header.
152+
memset(status_apa102_color + 4, 0xff, APA102_BUFFER_LENGTH - 4);
145153
#if CIRCUITPY_BITBANG_APA102
146154
shared_module_bitbangio_spi_construct(&status_apa102,
147155
MICROPY_HW_APA102_SCK,
@@ -259,9 +267,12 @@ void new_status_color(uint32_t rgb) {
259267
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3 * MICROPY_HW_NEOPIXEL_COUNT);
260268

261269
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
262-
status_apa102_color[5] = rgb_adjusted & 0xff;
263-
status_apa102_color[6] = (rgb_adjusted >> 8) & 0xff;
264-
status_apa102_color[7] = (rgb_adjusted >> 16) & 0xff;
270+
for (size_t i = 0; i < MICROPY_HW_APA102_COUNT; i++) {
271+
// Skip 4 + offset to skip the header bytes too.
272+
status_apa102_color[4 * i + 4 + 1] = rgb_adjusted & 0xff;
273+
status_apa102_color[4 * i + 4 + 2] = (rgb_adjusted >> 8) & 0xff;
274+
status_apa102_color[4 * i + 4 + 3] = (rgb_adjusted >> 16) & 0xff;
275+
}
265276

266277
#if CIRCUITPY_BITBANG_APA102
267278
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);

0 commit comments

Comments
 (0)