fix(rgbled): double-buffer WS2812 strip to eliminate races (#7304)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
462b0351ef
commit
ac4c4d7b6b
@@ -23,7 +23,6 @@
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_spi.h"
|
||||
#include "stm32_ws2812.h"
|
||||
#include "vs1053b.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
@@ -115,45 +114,6 @@ void audioInit()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SIXPOS_SWITCH_INDEX)
|
||||
uint8_t lastADCState = 0;
|
||||
uint8_t sixPosState = 0;
|
||||
bool dirty = true;
|
||||
uint16_t getSixPosAnalogValue(uint16_t adcValue)
|
||||
{
|
||||
uint8_t currentADCState = 0;
|
||||
if (adcValue > 3800)
|
||||
currentADCState = 6;
|
||||
else if (adcValue > 3100)
|
||||
currentADCState = 5;
|
||||
else if (adcValue > 2300)
|
||||
currentADCState = 4;
|
||||
else if (adcValue > 1500)
|
||||
currentADCState = 3;
|
||||
else if (adcValue > 1000)
|
||||
currentADCState = 2;
|
||||
else if (adcValue > 400)
|
||||
currentADCState = 1;
|
||||
if (lastADCState != currentADCState) {
|
||||
lastADCState = currentADCState;
|
||||
} else if (lastADCState != 0 && lastADCState - 1 != sixPosState) {
|
||||
sixPosState = lastADCState - 1;
|
||||
dirty = true;
|
||||
}
|
||||
if (dirty) {
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
if (i == sixPosState) {
|
||||
ws2812_set_color(i, SIXPOS_LED_RED, SIXPOS_LED_GREEN, SIXPOS_LED_BLUE);
|
||||
} else {
|
||||
ws2812_set_color(i, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
rgbLedColorApply();
|
||||
}
|
||||
return (4096/5)*(sixPosState);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAS_IMU)
|
||||
#include "drivers/lsm6ds.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
|
||||
@@ -185,10 +185,6 @@ uint32_t pwrPressedDuration();
|
||||
void usbChargerInit();
|
||||
bool usbChargerLed();
|
||||
|
||||
#if defined(RADIO_V16)
|
||||
uint16_t getSixPosAnalogValue(uint16_t adcValue);
|
||||
#endif
|
||||
|
||||
// Led driver
|
||||
void ledInit();
|
||||
void ledOff();
|
||||
@@ -246,6 +242,10 @@ bool isBacklightEnabled();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_V16)
|
||||
uint16_t getSixPosAnalogValue(uint16_t adcValue);
|
||||
#endif
|
||||
|
||||
// Audio driver
|
||||
void audioInit();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user