26
26
27
27
#include "supervisor/shared/status_leds.h"
28
28
29
+ #include <string.h>
30
+
29
31
#include "mphalport.h"
30
32
#include "shared-bindings/microcontroller/Pin.h"
31
33
#include "supervisor/shared/tick.h"
@@ -52,8 +54,12 @@ static digitalio_digitalinout_obj_t status_neopixel;
52
54
#elif defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )
53
55
uint8_t rgb_status_brightness = 50 ;
54
56
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 ];
57
63
58
64
#if CIRCUITPY_BITBANG_APA102
59
65
#include "shared-bindings/bitbangio/SPI.h"
@@ -142,6 +148,8 @@ void status_led_init() {
142
148
common_hal_digitalio_digitalinout_construct (& status_neopixel , MICROPY_HW_NEOPIXEL );
143
149
common_hal_digitalio_digitalinout_switch_to_output (& status_neopixel , false, DRIVE_MODE_PUSH_PULL );
144
150
#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 );
145
153
#if CIRCUITPY_BITBANG_APA102
146
154
shared_module_bitbangio_spi_construct (& status_apa102 ,
147
155
MICROPY_HW_APA102_SCK ,
@@ -259,9 +267,12 @@ void new_status_color(uint32_t rgb) {
259
267
common_hal_neopixel_write (& status_neopixel , status_neopixel_color , 3 * MICROPY_HW_NEOPIXEL_COUNT );
260
268
261
269
#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
+ }
265
276
266
277
#if CIRCUITPY_BITBANG_APA102
267
278
shared_module_bitbangio_spi_write (& status_apa102 , status_apa102_color , APA102_BUFFER_LENGTH );
0 commit comments