@@ -39,7 +39,10 @@ static digitalio_digitalinout_obj_t status_neopixel;
39
39
40
40
#if defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )
41
41
uint8_t rgb_status_brightness = 255 ;
42
- static uint8_t status_apa102_color [12 ] = {0 , 0 , 0 , 0 , 0xff , 0 , 0 , 0 };
42
+
43
+ #define APA102_BUFFER_LENGTH 12
44
+ static uint8_t status_apa102_color [APA102_BUFFER_LENGTH ] = {0 , 0 , 0 , 0 , 0xff , 0 , 0 , 0 , 0xff , 0xff , 0xff , 0xff };
45
+
43
46
#ifdef CIRCUITPY_BITBANG_APA102
44
47
#include "shared-bindings/bitbangio/SPI.h"
45
48
#include "shared-module/bitbangio/types.h"
@@ -104,10 +107,12 @@ void rgb_led_status_init() {
104
107
apa102_sck_in_use = false;
105
108
#ifdef CIRCUITPY_BITBANG_APA102
106
109
shared_module_bitbangio_spi_try_lock (& status_apa102 );
107
- shared_module_bitbangio_spi_configure (& status_apa102 , 100000 , 0 , 1 , 8 );
110
+ // Use 1MHz for clock rate. Some APA102's are spec'd 800kHz-1200kHz,
111
+ // though many can run much faster. bitbang will probably run slower.
112
+ shared_module_bitbangio_spi_configure (& status_apa102 , 1000000 , 0 , 0 , 8 );
108
113
#else
109
114
common_hal_busio_spi_try_lock (& status_apa102 );
110
- common_hal_busio_spi_configure (& status_apa102 , 100000 , 0 , 1 , 8 );
115
+ common_hal_busio_spi_configure (& status_apa102 , 1000000 , 0 , 0 , 8 );
111
116
#endif
112
117
#endif
113
118
@@ -120,7 +125,7 @@ void rgb_led_status_init() {
120
125
common_hal_pulseio_pwmout_never_reset (& rgb_status_r );
121
126
}
122
127
}
123
-
128
+
124
129
if (common_hal_mcu_pin_is_free (CP_RGB_STATUS_G )) {
125
130
pwmout_result_t green_result = common_hal_pulseio_pwmout_construct (& rgb_status_g , CP_RGB_STATUS_G , 0 , 50000 , false);
126
131
@@ -186,9 +191,9 @@ void new_status_color(uint32_t rgb) {
186
191
status_apa102_color [7 ] = (rgb_adjusted >> 16 ) & 0xff ;
187
192
188
193
#ifdef CIRCUITPY_BITBANG_APA102
189
- shared_module_bitbangio_spi_write (& status_apa102 , status_apa102_color , 8 );
194
+ shared_module_bitbangio_spi_write (& status_apa102 , status_apa102_color , APA102_BUFFER_LENGTH );
190
195
#else
191
- common_hal_busio_spi_write (& status_apa102 , status_apa102_color , 8 );
196
+ common_hal_busio_spi_write (& status_apa102 , status_apa102_color , APA102_BUFFER_LENGTH );
192
197
#endif
193
198
#endif
194
199
@@ -229,20 +234,20 @@ void temp_status_color(uint32_t rgb) {
229
234
if (apa102_mosi_in_use || apa102_sck_in_use ) {
230
235
return ;
231
236
}
232
- uint8_t colors [12 ] = {0 , 0 , 0 , 0 , 0xff , rgb_adjusted & 0xff , (rgb_adjusted >> 8 ) & 0xff , (rgb_adjusted >> 16 ) & 0xff , 0x0 , 0x0 , 0x0 , 0x0 };
237
+ uint8_t colors [APA102_BUFFER_LENGTH ] = {0 , 0 , 0 , 0 , 0xff , rgb_adjusted & 0xff , (rgb_adjusted >> 8 ) & 0xff , (rgb_adjusted >> 16 ) & 0xff , 0xff , 0xff , 0xff , 0xff };
233
238
#ifdef CIRCUITPY_BITBANG_APA102
234
- shared_module_bitbangio_spi_write (& status_apa102 , colors , 12 );
239
+ shared_module_bitbangio_spi_write (& status_apa102 , colors , APA102_BUFFER_LENGTH );
235
240
#else
236
- common_hal_busio_spi_write (& status_apa102 , colors , 12 );
241
+ common_hal_busio_spi_write (& status_apa102 , colors , APA102_BUFFER_LENGTH );
237
242
#endif
238
243
#endif
239
244
#if defined(CP_RGB_STATUS_LED )
240
245
uint8_t red_u8 = (rgb_adjusted >> 16 ) & 0xFF ;
241
246
uint8_t green_u8 = (rgb_adjusted >> 8 ) & 0xFF ;
242
247
uint8_t blue_u8 = rgb_adjusted & 0xFF ;
243
-
248
+
244
249
uint16_t temp_status_color_rgb [3 ] = {0 };
245
-
250
+
246
251
#if defined(CP_RGB_STATUS_INVERTED_PWM )
247
252
temp_status_color_rgb [0 ] = (1 << 16 ) - 1 - ((uint16_t ) (red_u8 << 8 ) + red_u8 );
248
253
temp_status_color_rgb [1 ] = (1 << 16 ) - 1 - ((uint16_t ) (green_u8 << 8 ) + green_u8 );
@@ -265,9 +270,9 @@ void clear_temp_status() {
265
270
#endif
266
271
#if defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )
267
272
#ifdef CIRCUITPY_BITBANG_APA102
268
- shared_module_bitbangio_spi_write (& status_apa102 , status_apa102_color , 8 );
273
+ shared_module_bitbangio_spi_write (& status_apa102 , status_apa102_color , APA102_BUFFER_LENGTH );
269
274
#else
270
- common_hal_busio_spi_write (& status_apa102 , status_apa102_color , 8 );
275
+ common_hal_busio_spi_write (& status_apa102 , status_apa102_color , APA102_BUFFER_LENGTH );
271
276
#endif
272
277
#endif
273
278
#if defined(CP_RGB_STATUS_LED )
0 commit comments