8000 Fix status DotStar writing · adafruit/circuitpython@6001b64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6001b64

Browse files
committed
Fix status DotStar writing
1 parent 8e14522 commit 6001b64

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

supervisor/shared/rgb_led_status.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ static digitalio_digitalinout_obj_t status_neopixel;
3939

4040
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
4141
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+
4346
#ifdef CIRCUITPY_BITBANG_APA102
4447
#include "shared-bindings/bitbangio/SPI.h"
4548
#include "shared-module/bitbangio/types.h"
@@ -104,10 +107,12 @@ void rgb_led_status_init() {
104107
apa102_sck_in_use = false;
105108
#ifdef CIRCUITPY_BITBANG_APA102
106109
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);
108113
#else
109114
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);
111116
#endif
112117
#endif
113118

@@ -120,7 +125,7 @@ void rgb_led_status_init() {
120125
common_hal_pulseio_pwmout_never_reset(&rgb_status_r);
121126
}
122127
}
123-
128+
124129
if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_G)) {
125130
pwmout_result_t green_result = common_hal_pulseio_pwmout_construct(&rgb_status_g, CP_RGB_STATUS_G, 0, 50000, false);
126131

@@ -186,9 +191,9 @@ void new_status_color(uint32_t rgb) {
186191
status_apa102_color[7] = (rgb_adjusted >> 16) & 0xff;
187192

188193
#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);
190195
#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);
192197
#endif
193198
#endif
194199

@@ -229,20 +234,20 @@ void temp_status_color(uint32_t rgb) {
229234
if (apa102_mosi_in_use || apa102_sck_in_use) {
230235
return;
231236
}
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};
233238
#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);
235240
#else
236-
common_hal_busio_spi_write(&status_apa102, colors, 12);
241+
common_hal_busio_spi_write(&status_apa102, colors, APA102_BUFFER_LENGTH);
237242
#endif
238243
#endif
239244
#if defined(CP_RGB_STATUS_LED)
240245
uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF;
241246
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
242247
uint8_t blue_u8 = rgb_adjusted & 0xFF;
243-
248+
244249
uint16_t temp_status_color_rgb[3] = {0};
245-
250+
246251
#if defined(CP_RGB_STATUS_INVERTED_PWM)
247252
temp_status_color_rgb[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
248253
temp_status_color_rgb[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
@@ -265,9 +270,9 @@ void clear_temp_status() {
265270
#endif
266271
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
267272
#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);
269274
#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);
271276
#endif
272277
#endif
273278
#if defined(CP_RGB_STATUS_LED)

0 commit comments

Comments
 (0)
0