Support multiple status dotstars
Only supporting one left a white dotstar stranded. Fixes #5170
This commit is contained in:
parent
da320c30f0
commit
f9f3894888
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#define MICROPY_HW_APA102_MOSI (&pin_GPIO14)
|
#define MICROPY_HW_APA102_MOSI (&pin_GPIO14)
|
||||||
#define MICROPY_HW_APA102_SCK (&pin_GPIO15)
|
#define MICROPY_HW_APA102_SCK (&pin_GPIO15)
|
||||||
|
#define MICROPY_HW_APA102_COUNT (5)
|
||||||
|
|
||||||
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
|
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include "supervisor/shared/status_leds.h"
|
#include "supervisor/shared/status_leds.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "mphalport.h"
|
#include "mphalport.h"
|
||||||
#include "shared-bindings/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "supervisor/shared/tick.h"
|
#include "supervisor/shared/tick.h"
|
||||||
@ -52,8 +54,12 @@ static digitalio_digitalinout_obj_t status_neopixel;
|
|||||||
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
||||||
uint8_t rgb_status_brightness = 50;
|
uint8_t rgb_status_brightness = 50;
|
||||||
|
|
||||||
#define APA102_BUFFER_LENGTH 12
|
#ifndef MICROPY_HW_APA102_COUNT
|
||||||
static uint8_t status_apa102_color[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff};
|
#define MICROPY_HW_APA102_COUNT (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define APA102_BUFFER_LENGTH (4 + 4 * MICROPY_HW_APA102_COUNT + 4)
|
||||||
|
static uint8_t status_apa102_color[APA102_BUFFER_LENGTH];
|
||||||
|
|
||||||
#if CIRCUITPY_BITBANG_APA102
|
#if CIRCUITPY_BITBANG_APA102
|
||||||
#include "shared-bindings/bitbangio/SPI.h"
|
#include "shared-bindings/bitbangio/SPI.h"
|
||||||
@ -142,6 +148,8 @@ void status_led_init() {
|
|||||||
common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
|
common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
|
||||||
common_hal_digitalio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL);
|
common_hal_digitalio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL);
|
||||||
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
||||||
|
// Set every byte to 0xff except the start 4 bytes that make up the header.
|
||||||
|
memset(status_apa102_color + 4, 0xff, APA102_BUFFER_LENGTH - 4);
|
||||||
#if CIRCUITPY_BITBANG_APA102
|
#if CIRCUITPY_BITBANG_APA102
|
||||||
shared_module_bitbangio_spi_construct(&status_apa102,
|
shared_module_bitbangio_spi_construct(&status_apa102,
|
||||||
MICROPY_HW_APA102_SCK,
|
MICROPY_HW_APA102_SCK,
|
||||||
@ -259,9 +267,12 @@ void new_status_color(uint32_t rgb) {
|
|||||||
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3 * MICROPY_HW_NEOPIXEL_COUNT);
|
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3 * MICROPY_HW_NEOPIXEL_COUNT);
|
||||||
|
|
||||||
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
||||||
status_apa102_color[5] = rgb_adjusted & 0xff;
|
for (size_t i = 0; i < MICROPY_HW_APA102_COUNT; i++) {
|
||||||
status_apa102_color[6] = (rgb_adjusted >> 8) & 0xff;
|
// Skip 4 + offset to skip the header bytes too.
|
||||||
status_apa102_color[7] = (rgb_adjusted >> 16) & 0xff;
|
status_apa102_color[4 * i + 4 + 1] = rgb_adjusted & 0xff;
|
||||||
|
status_apa102_color[4 * i + 4 + 2] = (rgb_adjusted >> 8) & 0xff;
|
||||||
|
status_apa102_color[4 * i + 4 + 3] = (rgb_adjusted >> 16) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
#if CIRCUITPY_BITBANG_APA102
|
#if CIRCUITPY_BITBANG_APA102
|
||||||
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
|
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
|
||||||
|
Loading…
Reference in New Issue
Block a user