1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 12:25:20 +03:00

Optimize ledstrip DMA buffer update and bug fix (#8830)

Optimize ledstrip DMA buffer update and bug fix
This commit is contained in:
Michael Keller 2019-09-07 12:17:36 +12:00 committed by GitHub
commit c3b490b40f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View file

@ -57,6 +57,8 @@ uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE];
static ioTag_t ledStripIoTag;
static bool ws2811Initialised = false;
volatile bool ws2811LedDataTransferInProgress = false;
static unsigned usedLedCount = 0;
static bool needsFullRefresh = true;
uint16_t BIT_COMPARE_1 = 0;
uint16_t BIT_COMPARE_0 = 0;
@ -87,18 +89,27 @@ void scaleLedValue(uint16_t index, const uint8_t scalePercent)
void setStripColor(const hsvColor_t *color)
{
for (unsigned index = 0; index < WS2811_DATA_BUFFER_SIZE; index++) {
for (unsigned index = 0; index < usedLedCount; index++) {
ledColorBuffer[index] = *color;
}
}
void setStripColors(const hsvColor_t *colors)
{
for (unsigned index = 0; index < WS2811_DATA_BUFFER_SIZE; index++) {
for (unsigned index = 0; index < usedLedCount; index++) {
setLedHsv(index, colors++);
}
}
void setUsedLedCount(unsigned ledCount)
{
usedLedCount = (ledCount < WS2811_DATA_BUFFER_SIZE) ? ledCount : WS2811_DATA_BUFFER_SIZE;
// Update all possible positions on the next update in case the count
// decreased otherwise LEDs on the end could be left in their previous state
needsFullRefresh = true;
}
void ws2811LedStripInit(ioTag_t ioTag)
{
memset(ledStripDMABuffer, 0, sizeof(ledStripDMABuffer));
@ -129,6 +140,7 @@ bool isWS2811LedStripReady(void)
STATIC_UNIT_TESTED void updateLEDDMABuffer(ledStripFormatRGB_e ledFormat, rgbColor24bpp_t *color, unsigned ledIndex)
{
uint32_t packed_colour;
switch (ledFormat) {
@ -163,11 +175,14 @@ void ws2811UpdateStrip(ledStripFormatRGB_e ledFormat)
// fill transmit buffer with correct compare values to achieve
// correct pulse widths according to color values
while (ledIndex < WS2811_DATA_BUFFER_SIZE) {
rgbColor24bpp_t *rgb24 = hsvToRgb24(&ledColorBuffer[ledIndex]);
const unsigned ledUpdateCount = needsFullRefresh ? WS2811_DATA_BUFFER_SIZE : usedLedCount;
const hsvColor_t hsvBlack = { 0, 0, 0 };
while (ledIndex < ledUpdateCount) {
rgbColor24bpp_t *rgb24 = hsvToRgb24(ledIndex < usedLedCount ? &ledColorBuffer[ledIndex] : &hsvBlack);
updateLEDDMABuffer(ledFormat, rgb24, ledIndex++);
}
needsFullRefresh = false;
ws2811LedDataTransferInProgress = true;
ws2811LedStripDMAEnable();

View file

@ -67,6 +67,8 @@ void setLedValue(uint16_t index, const uint8_t value);
void setStripColor(const hsvColor_t *color);
void setStripColors(const hsvColor_t *colors);
void setUsedLedCount(unsigned ledCount);
bool isWS2811LedStripReady(void);
#if defined(STM32F1) || defined(STM32F3)

View file

@ -269,6 +269,7 @@ STATIC_UNIT_TESTED void updateLedCount(void)
ledCounts.count = count;
ledCounts.ring = countRing;
ledCounts.larson = countScanner;
setUsedLedCount(ledCounts.count);
}
void reevaluateLedConfig(void)

View file

@ -394,4 +394,7 @@ uint8_t getRssiPercent(void) { return 0; }
bool isFlipOverAfterCrashActive(void) { return false; }
void ws2811LedStripEnable(void) { }
void setUsedLedCount(unsigned) { };
}