update credits
[librepilot.git] / flight / pios / stm32f4xx / inc / pios_ws2811_cfg.h
blobaf3876519d1b0176b0dd028e594bb8016c03dd33
1 /**
2 ******************************************************************************
4 * @file pios_ws2811_cfg.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
6 * @brief A driver for ws2811 rgb led controller.
7 * this is a plain PiOS port of the very clever solution
8 * implemented by Omri Iluz in the chibios driver here:
9 * https://github.com/omriiluz/WS2812B-LED-Driver-ChibiOS
10 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef PIOS_WS2811_CFG_H_
29 #define PIOS_WS2811_CFG_H_
31 #include <stdint.h>
32 #include <pios_gpio.h>
33 #include <pios_stm32.h>
34 #include <pios_gpio_priv.h>
35 #include <stm32f4xx.h>
36 #include <stm32f4xx_tim.h>
37 #include <stm32f4xx_dma.h>
38 #include <optypes.h>
39 #include <pios_ws2811.h>
41 #define PIOS_WS2811_BUFFER_SIZE (((PIOS_WS2811_NUMLEDS) * 24))
42 #define PIOS_WS2811_MEMORYDATASIZE DMA_MemoryDataSize_HalfWord
43 #define PIOS_WS2811_PERIPHERALDATASIZE DMA_PeripheralDataSize_HalfWord
44 #define PIOS_WS2811_TIM_PERIOD 20
46 // Following times are keept on the lower side to accounts
47 // for bus contentions and irq response time
48 #define PIOS_WS2811_T0_HIGH_PERIOD 32 // .35us +/- 150nS
49 #define PIOS_WS2811_T1_HIGH_PERIOD 70 // .70us +/- 150nS
51 #define PIOS_WS2811_DMA_CH1_CONFIG(channel) \
52 { \
53 .DMA_BufferSize = PIOS_WS2811_BUFFER_SIZE, \
54 .DMA_Channel = channel, \
55 .DMA_DIR = DMA_DIR_MemoryToPeripheral, \
56 .DMA_FIFOMode = DMA_FIFOMode_Enable, \
57 .DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull, \
58 .DMA_Memory0BaseAddr = 0, \
59 .DMA_MemoryBurst = DMA_MemoryBurst_INC4, \
60 .DMA_MemoryDataSize = PIOS_WS2811_MEMORYDATASIZE, \
61 .DMA_MemoryInc = DMA_MemoryInc_Enable, \
62 .DMA_Mode = DMA_Mode_Circular, \
63 .DMA_PeripheralBaseAddr = 0, \
64 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single, \
65 .DMA_PeripheralDataSize = PIOS_WS2811_PERIPHERALDATASIZE, \
66 .DMA_PeripheralInc = DMA_PeripheralInc_Disable, \
67 .DMA_Priority = DMA_Priority_VeryHigh, }
69 #define PIOS_WS2811_DMA_CH2_CONFIG(channel) \
70 { \
71 .DMA_BufferSize = 4, \
72 .DMA_Channel = channel, \
73 .DMA_DIR = DMA_DIR_MemoryToPeripheral, \
74 .DMA_FIFOMode = DMA_FIFOMode_Enable, \
75 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full, \
76 .DMA_Memory0BaseAddr = 0, \
77 .DMA_MemoryBurst = DMA_MemoryBurst_INC4, \
78 .DMA_MemoryDataSize = PIOS_WS2811_MEMORYDATASIZE, \
79 .DMA_MemoryInc = DMA_MemoryInc_Enable, \
80 .DMA_Mode = DMA_Mode_Circular, \
81 .DMA_PeripheralBaseAddr = 0, \
82 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single, \
83 .DMA_PeripheralDataSize = PIOS_WS2811_PERIPHERALDATASIZE, \
84 .DMA_PeripheralInc = DMA_PeripheralInc_Disable, \
85 .DMA_Priority = DMA_Priority_VeryHigh, }
87 #define PIOS_WS2811_DMA_UPDATE_CONFIG(channel) \
88 { \
89 .DMA_BufferSize = 4, \
90 .DMA_Channel = channel, \
91 .DMA_DIR = DMA_DIR_MemoryToPeripheral, \
92 .DMA_FIFOMode = DMA_FIFOMode_Enable, \
93 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full, \
94 .DMA_Memory0BaseAddr = 0, \
95 .DMA_MemoryBurst = DMA_MemoryBurst_INC4, \
96 .DMA_MemoryDataSize = PIOS_WS2811_MEMORYDATASIZE, \
97 .DMA_MemoryInc = DMA_MemoryInc_Enable, \
98 .DMA_Mode = DMA_Mode_Circular, \
99 .DMA_PeripheralBaseAddr = 0, \
100 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single, \
101 .DMA_PeripheralDataSize = PIOS_WS2811_PERIPHERALDATASIZE, \
102 .DMA_PeripheralInc = DMA_PeripheralInc_Disable, \
103 .DMA_Priority = DMA_Priority_High }
106 typedef uint16_t ledbuf_t;
108 struct pios_ws2811_pin_cfg {
109 GPIO_TypeDef *gpio;
110 GPIO_InitTypeDef gpioInit;
112 struct pios_ws2811_cfg {
113 TIM_TimeBaseInitTypeDef timerInit;
114 TIM_TypeDef *timer;
115 uint8_t timerCh1;
116 uint8_t timerCh2;
118 DMA_InitTypeDef dmaInitCh1;
119 DMA_Stream_TypeDef *streamCh1;
120 uint32_t dmaItCh1;
122 DMA_InitTypeDef dmaInitCh2;
123 DMA_Stream_TypeDef *streamCh2;
124 uint32_t dmaItCh2;
126 DMA_InitTypeDef dmaInitUpdate;
127 DMA_Stream_TypeDef *streamUpdate;
128 uint32_t dmaItUpdate;
129 uint16_t dmaSource;
130 struct stm32_irq irq;
133 void PIOS_WS2811_Init(uint32_t *dev_id, const struct pios_ws2811_cfg *ws2811_cfg, const struct pios_ws2811_pin_cfg *ws2811_pin_cfg);
135 void PIOS_WS2811_DMA_irq_handler();
136 #endif /* PIOS_WS2811_H_ */