1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Improve speed of LED STRIP code.

Shaved about 150us each strip update.

This commit leaves in some timing trace code for the CC3D target, the
results of which can be seen in the debug variables for the sections
being timed.

A later commit will remove/disable the timing code.
This commit is contained in:
Dominic Clifton 2014-09-20 01:00:13 +01:00
parent 36dac872b8
commit e847a6347d
9 changed files with 189 additions and 15 deletions

View file

@ -25,9 +25,12 @@
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "platform.h"
#include "build_config.h"
#include "common/color.h"
#include "common/colorconversion.h"
#include "drivers/light_ws2811strip.h"
@ -75,6 +78,7 @@ void setStripColors(const hsvColor_t *colors)
void ws2811LedStripInit(void)
{
memset(&ledStripDMABuffer, 0, WS2811_DMA_BUFFER_SIZE);
ws2811LedStripHardwareInit();
ws2811UpdateStrip();
}
@ -84,10 +88,22 @@ bool isWS2811LedStripReady(void)
return !ws2811LedDataTransferInProgress;
}
static uint16_t dmaBufferOffset;
STATIC_UNIT_TESTED uint16_t dmaBufferOffset;
static int16_t ledIndex;
void updateLEDDMABuffer(uint8_t componentValue)
#define USE_FAST_DMA_BUFFER_IMPL
#ifdef USE_FAST_DMA_BUFFER_IMPL
STATIC_UNIT_TESTED void fastUpdateLEDDMABuffer(rgbColor24bpp_t *color)
{
uint32_t grb = (color->rgb.g << 16) | (color->rgb.r << 8) | (color->rgb.b);
for (int8_t index = 23; index >= 0; index--) {
ledStripDMABuffer[dmaBufferOffset++] = (grb & (1 << index)) ? BIT_COMPARE_1 : BIT_COMPARE_0;
}
}
#else
STATIC_UNIT_TESTED void updateLEDDMABuffer(uint8_t componentValue)
{
uint8_t bitIndex;
@ -95,15 +111,16 @@ void updateLEDDMABuffer(uint8_t componentValue)
{
if ((componentValue << bitIndex) & 0x80 ) // data sent MSB first, j = 0 is MSB j = 7 is LSB
{
ledStripDMABuffer[dmaBufferOffset] = 17; // compare value for logical 1
ledStripDMABuffer[dmaBufferOffset] = BIT_COMPARE_1;
}
else
{
ledStripDMABuffer[dmaBufferOffset] = 9; // compare value for logical 0
ledStripDMABuffer[dmaBufferOffset] = BIT_COMPARE_0; // compare value for logical 0
}
dmaBufferOffset++;
}
}
#endif
/*
* This method is non-blocking unless an existing LED update is in progress.
@ -128,20 +145,17 @@ void ws2811UpdateStrip(void)
{
rgb24 = hsvToRgb24(&ledColorBuffer[ledIndex]);
#ifdef USE_FAST_DMA_BUFFER_IMPL
fastUpdateLEDDMABuffer(rgb24);
#else
updateLEDDMABuffer(rgb24->rgb.g);
updateLEDDMABuffer(rgb24->rgb.r);
updateLEDDMABuffer(rgb24->rgb.b);
#endif
ledIndex++;
}
// add needed delay at end of byte cycle, pulsewidth = 0
while(dmaBufferOffset < WS2811_DMA_BUFFER_SIZE)
{
ledStripDMABuffer[dmaBufferOffset] = 0;
dmaBufferOffset++;
}
ws2811LedDataTransferInProgress = 1;
ws2811LedStripDMAEnable();
}