Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / light_ws2811strip.h
blob9e0b6bd23325db88c5d5b475852a5d4c5245a70c
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "platform.h"
25 #include "drivers/io_types.h"
27 #define WS2811_LED_STRIP_LENGTH 32
29 #define WS2811_BITS_PER_LED_MAX 32
31 #if defined(USE_WS2811_SINGLE_COLOUR)
32 #define WS2811_DATA_BUFFER_SIZE 1
33 #define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE * WS2811_BITS_PER_LED_MAX)
34 // Do 2 extra iterations of the DMA transfer with the output set to low to generate the > 50us delay.
35 #define WS2811_DELAY_ITERATIONS 2
36 #else
37 #define WS2811_DATA_BUFFER_SIZE WS2811_LED_STRIP_LENGTH
38 // for 50us delay
39 #define WS2811_DELAY_BUFFER_LENGTH 42
40 // number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes)
41 #define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE * WS2811_BITS_PER_LED_MAX + WS2811_DELAY_BUFFER_LENGTH)
42 #endif
44 #ifdef USE_LEDSTRIP_CACHE_MGMT
45 // WS2811_DMA_BUFFER_SIZE is multiples of uint32_t
46 // Number of bytes required for buffer
47 #define WS2811_DMA_BUF_BYTES (WS2811_DMA_BUFFER_SIZE * sizeof(uint32_t))
48 // Number of bytes required to cache align buffer
49 #define WS2811_DMA_BUF_CACHE_ALIGN_BYTES ((WS2811_DMA_BUF_BYTES + 0x20) & ~0x1f)
50 // Size of array to create a cache aligned buffer
51 #define WS2811_DMA_BUF_CACHE_ALIGN_LENGTH (WS2811_DMA_BUF_CACHE_ALIGN_BYTES / sizeof(uint32_t))
52 extern uint32_t ledStripDMABuffer[WS2811_DMA_BUF_CACHE_ALIGN_LENGTH];
53 #else
54 #if defined(STM32F1) || defined(STM32F3)
55 extern uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE];
56 #else
57 extern uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE];
58 #endif
59 #endif
61 #define WS2811_TIMER_MHZ 48
62 #define WS2811_CARRIER_HZ 800000
64 // Enumeration to match the string options defined in lookupLedStripFormatRGB in settings.c
65 typedef enum {
66 LED_GRB,
67 LED_RGB,
68 LED_GRBW
69 } ledStripFormatRGB_e;
71 void ws2811LedStripInit(ioTag_t ioTag);
72 void ws2811LedStripEnable(void);
74 bool ws2811LedStripHardwareInit(ioTag_t ioTag);
75 void ws2811LedStripDMAEnable(void);
77 void ws2811UpdateStrip(ledStripFormatRGB_e ledFormat, uint8_t brightness);
79 void setLedHsv(uint16_t index, const hsvColor_t *color);
80 void getLedHsv(uint16_t index, hsvColor_t *color);
82 void scaleLedValue(uint16_t index, const uint8_t scalePercent);
83 void setLedValue(uint16_t index, const uint8_t value);
85 void setStripColor(const hsvColor_t *color);
86 void setStripColors(const hsvColor_t *colors);
88 void setUsedLedCount(unsigned ledCount);
90 bool isWS2811LedStripReady(void);
92 extern volatile bool ws2811LedDataTransferInProgress;
94 extern uint16_t BIT_COMPARE_1;
95 extern uint16_t BIT_COMPARE_0;