mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-22 12:54:14 +01:00
OP-1312 Add support for Revolution (right now always active on pin3). Configurability not yet added
This commit is contained in:
parent
28859d2305
commit
a0b857337f
@ -96,13 +96,17 @@ void PIOS_WS2811_Init(const struct pios_ws2811_cfg *ws2811_cfg, const struct pio
|
|||||||
|
|
||||||
fb = (ledbuf_t *)pvPortMalloc(PIOS_WS2811_BUFFER_SIZE * sizeof(ledbuf_t));
|
fb = (ledbuf_t *)pvPortMalloc(PIOS_WS2811_BUFFER_SIZE * sizeof(ledbuf_t));
|
||||||
memset(fb, 0, PIOS_WS2811_BUFFER_SIZE * sizeof(ledbuf_t));
|
memset(fb, 0, PIOS_WS2811_BUFFER_SIZE * sizeof(ledbuf_t));
|
||||||
|
Color ledoff = { 0, 0, 0 };
|
||||||
|
for (uint8_t i = 0; i < PIOS_WS2811_NUMLEDS; i++) {
|
||||||
|
PIOS_WS2811_setColorRGB(ledoff, i, false);
|
||||||
|
}
|
||||||
// Setup timers
|
// Setup timers
|
||||||
setupTimer();
|
setupTimer();
|
||||||
setupDMA();
|
setupDMA();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupTimer(){
|
void setupTimer()
|
||||||
|
{
|
||||||
// Stop timer
|
// Stop timer
|
||||||
TIM_Cmd(pios_ws2811_cfg->timer, DISABLE);
|
TIM_Cmd(pios_ws2811_cfg->timer, DISABLE);
|
||||||
// Configure timebase and internal clock
|
// Configure timebase and internal clock
|
||||||
@ -137,7 +141,8 @@ void setupTimer(){
|
|||||||
genericTIM_OCxInit(pios_ws2811_cfg->timer, &oc, pios_ws2811_cfg->timerCh2);
|
genericTIM_OCxInit(pios_ws2811_cfg->timer, &oc, pios_ws2811_cfg->timerCh2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void genericTIM_OCxInit(TIM_TypeDef* TIMx, const TIM_OCInitTypeDef* TIM_OCInitStruct, uint8_t ch){
|
void genericTIM_OCxInit(TIM_TypeDef *TIMx, const TIM_OCInitTypeDef *TIM_OCInitStruct, uint8_t ch)
|
||||||
|
{
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 1:
|
case 1:
|
||||||
TIM_OC1Init(TIMx, TIM_OCInitStruct);
|
TIM_OC1Init(TIMx, TIM_OCInitStruct);
|
||||||
@ -154,7 +159,8 @@ void genericTIM_OCxInit(TIM_TypeDef* TIMx, const TIM_OCInitTypeDef* TIM_OCInitSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void genericTIM_OCxPreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload, uint8_t ch){
|
void genericTIM_OCxPreloadConfig(TIM_TypeDef *TIMx, uint16_t TIM_OCPreload, uint8_t ch)
|
||||||
|
{
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 1:
|
case 1:
|
||||||
TIM_OC1PreloadConfig(TIMx, TIM_OCPreload);
|
TIM_OC1PreloadConfig(TIMx, TIM_OCPreload);
|
||||||
@ -172,8 +178,8 @@ void genericTIM_OCxPreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload, uint
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setupDMA()
|
||||||
void setupDMA(){
|
{
|
||||||
// Configure Ch1
|
// Configure Ch1
|
||||||
DMA_Init(pios_ws2811_cfg->streamCh1, (DMA_InitTypeDef *)&pios_ws2811_cfg->dmaInitCh1);
|
DMA_Init(pios_ws2811_cfg->streamCh1, (DMA_InitTypeDef *)&pios_ws2811_cfg->dmaInitCh1);
|
||||||
pios_ws2811_cfg->streamCh1->PAR = (uint32_t)&pios_ws2811_pin_cfg->gpio->BSRRH;
|
pios_ws2811_cfg->streamCh1->PAR = (uint32_t)&pios_ws2811_pin_cfg->gpio->BSRRH;
|
||||||
@ -198,11 +204,12 @@ void setupDMA(){
|
|||||||
DMA_Cmd(pios_ws2811_cfg->streamCh2, ENABLE);
|
DMA_Cmd(pios_ws2811_cfg->streamCh2, ENABLE);
|
||||||
DMA_Cmd(pios_ws2811_cfg->streamCh1, ENABLE);
|
DMA_Cmd(pios_ws2811_cfg->streamCh1, ENABLE);
|
||||||
DMA_Cmd(pios_ws2811_cfg->streamUpdate, ENABLE);
|
DMA_Cmd(pios_ws2811_cfg->streamUpdate, ENABLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setColor(uint8_t color, ledbuf_t *buf) {
|
void setColor(uint8_t color, ledbuf_t *buf)
|
||||||
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
buf[i] = ((color << i) & 0b10000000 ? 0x0 : dmaSource);
|
buf[i] = ((color << i) & 0b10000000 ? 0x0 : dmaSource);
|
||||||
}
|
}
|
||||||
@ -214,7 +221,8 @@ void setColor(uint8_t color, ledbuf_t *buf) {
|
|||||||
* @param led led number
|
* @param led led number
|
||||||
* @param update Perform an update after changing led color
|
* @param update Perform an update after changing led color
|
||||||
*/
|
*/
|
||||||
void PIOS_WS2811_setColorRGB(Color c, uint8_t led, bool update) {
|
void PIOS_WS2811_setColorRGB(Color c, uint8_t led, bool update)
|
||||||
|
{
|
||||||
if (led > PIOS_WS2811_NUMLEDS) {
|
if (led > PIOS_WS2811_NUMLEDS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -229,7 +237,8 @@ void PIOS_WS2811_setColorRGB(Color c, uint8_t led, bool update) {
|
|||||||
/**
|
/**
|
||||||
* trigger an update cycle if not already running
|
* trigger an update cycle if not already running
|
||||||
*/
|
*/
|
||||||
void PIOS_WS2811_Update(){
|
void PIOS_WS2811_Update()
|
||||||
|
{
|
||||||
// does not start if framebuffer is not allocated (init has not been called yet) or a transfer is still on going
|
// does not start if framebuffer is not allocated (init has not been called yet) or a transfer is still on going
|
||||||
if (!fb || (pios_ws2811_cfg->timer->CR1 & TIM_CR1_CEN)) {
|
if (!fb || (pios_ws2811_cfg->timer->CR1 & TIM_CR1_CEN)) {
|
||||||
return;
|
return;
|
||||||
@ -245,7 +254,8 @@ void PIOS_WS2811_Update(){
|
|||||||
* Stop timer once the complete framebuffer has been sent
|
* Stop timer once the complete framebuffer has been sent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PIOS_WS2811_DMA_irq_handler(){
|
void PIOS_WS2811_DMA_irq_handler()
|
||||||
|
{
|
||||||
TIM_Cmd(pios_ws2811_cfg->timer, DISABLE);
|
TIM_Cmd(pios_ws2811_cfg->timer, DISABLE);
|
||||||
DMA_ClearFlag(pios_ws2811_cfg->streamCh1, pios_ws2811_cfg->irq.flags);
|
DMA_ClearFlag(pios_ws2811_cfg->streamCh1, pios_ws2811_cfg->irq.flags);
|
||||||
}
|
}
|
||||||
|
@ -1962,3 +1962,118 @@ const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
|
|||||||
.data_tx_ep = 1,
|
.data_tx_ep = 1,
|
||||||
};
|
};
|
||||||
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
|
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
|
||||||
|
|
||||||
|
#ifdef PIOS_INCLUDE_WS2811
|
||||||
|
#include <pios_ws2811.h>
|
||||||
|
#define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
|
||||||
|
|
||||||
|
void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
|
||||||
|
|
||||||
|
const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.gpioInit = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_3,
|
||||||
|
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_OUT,
|
||||||
|
.GPIO_OType = GPIO_OType_PP,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct pios_ws2811_cfg pios_ws2811_cfg = {
|
||||||
|
// master mode selection Note: configure TIM_CR2_MMS_2 master mode selection
|
||||||
|
|
||||||
|
.timer = TIM1,
|
||||||
|
.timerInit = {
|
||||||
|
.TIM_Prescaler = PIOS_WS2811_TIM_DIVIDER - 1,
|
||||||
|
.TIM_ClockDivision = TIM_CKD_DIV1,
|
||||||
|
.TIM_CounterMode = TIM_CounterMode_Up,
|
||||||
|
// period (1.25 uS per period
|
||||||
|
.TIM_Period = PIOS_WS2811_TIM_PERIOD,
|
||||||
|
.TIM_RepetitionCounter = 0x0000,
|
||||||
|
},
|
||||||
|
|
||||||
|
.timerCh1 = 1,
|
||||||
|
.streamCh1 = DMA2_Stream1,
|
||||||
|
|
||||||
|
.timerCh2 = 3,
|
||||||
|
.streamCh2 = DMA2_Stream6,
|
||||||
|
|
||||||
|
.streamUpdate = DMA2_Stream5,
|
||||||
|
|
||||||
|
// DMA ch1, triggered by channel3 pwm signal. if FB indicates, reset output value early to indicate "0" bit to ws2812
|
||||||
|
.dmaInitCh1 = {
|
||||||
|
.DMA_BufferSize = PIOS_WS2811_BUFFER_SIZE,
|
||||||
|
.DMA_Channel = DMA_Channel_6,
|
||||||
|
.DMA_DIR = DMA_DIR_MemoryToPeripheral,
|
||||||
|
.DMA_FIFOMode = DMA_FIFOMode_Enable,
|
||||||
|
.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull,
|
||||||
|
.DMA_Memory0BaseAddr = 0,
|
||||||
|
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
|
||||||
|
.DMA_MemoryDataSize = PIOS_WS2811_MEMORYDATASIZE,
|
||||||
|
.DMA_MemoryInc = DMA_MemoryInc_Enable,
|
||||||
|
.DMA_Mode = DMA_Mode_Circular,
|
||||||
|
.DMA_PeripheralBaseAddr = 0,
|
||||||
|
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
|
||||||
|
.DMA_PeripheralDataSize = PIOS_WS2811_PERIPHERALDATASIZE,
|
||||||
|
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
|
||||||
|
.DMA_Priority = DMA_Priority_VeryHigh,
|
||||||
|
},
|
||||||
|
.dmaItCh1 = DMA_IT_TEIF1 | DMA_IT_TCIF1,
|
||||||
|
// DMA stream 6, triggered by channel1 update event. reset output value late to indicate "1" bit to ws2812.
|
||||||
|
|
||||||
|
.dmaInitCh2 = {
|
||||||
|
.DMA_BufferSize = 1,
|
||||||
|
.DMA_Channel = DMA_Channel_6,
|
||||||
|
.DMA_DIR = DMA_DIR_MemoryToPeripheral,
|
||||||
|
.DMA_FIFOMode = DMA_FIFOMode_Enable,
|
||||||
|
.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull,
|
||||||
|
.DMA_Memory0BaseAddr = 0,
|
||||||
|
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
|
||||||
|
.DMA_MemoryDataSize = PIOS_WS2811_MEMORYDATASIZE,
|
||||||
|
.DMA_MemoryInc = DMA_MemoryInc_Disable,
|
||||||
|
.DMA_Mode = DMA_Mode_Circular,
|
||||||
|
.DMA_PeripheralBaseAddr = 0,
|
||||||
|
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
|
||||||
|
.DMA_PeripheralDataSize = PIOS_WS2811_PERIPHERALDATASIZE,
|
||||||
|
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
|
||||||
|
.DMA_Priority = DMA_Priority_VeryHigh,
|
||||||
|
},
|
||||||
|
.dmaItCh2 = DMA_IT_TEIF2 | DMA_IT_TCIF2,
|
||||||
|
// triggered by pwm update event. output high at beginning of signal
|
||||||
|
.dmaInitUpdate = {
|
||||||
|
.DMA_BufferSize = 1,
|
||||||
|
.DMA_Channel = DMA_Channel_6,
|
||||||
|
.DMA_DIR = DMA_DIR_MemoryToPeripheral,
|
||||||
|
.DMA_FIFOMode = DMA_FIFOMode_Enable,
|
||||||
|
.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull,
|
||||||
|
.DMA_Memory0BaseAddr = 0,
|
||||||
|
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
|
||||||
|
.DMA_MemoryDataSize = PIOS_WS2811_MEMORYDATASIZE,
|
||||||
|
.DMA_MemoryInc = DMA_MemoryInc_Disable,
|
||||||
|
.DMA_Mode = DMA_Mode_Circular,
|
||||||
|
.DMA_PeripheralBaseAddr = 0,
|
||||||
|
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
|
||||||
|
.DMA_PeripheralDataSize = PIOS_WS2811_PERIPHERALDATASIZE,
|
||||||
|
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
|
||||||
|
.DMA_Priority = DMA_Priority_High
|
||||||
|
},
|
||||||
|
.dmaItUpdate = DMA_IT_TEIF6 | DMA_IT_TCIF6,
|
||||||
|
.dmaSource = TIM_DMA_CC1 | TIM_DMA_CC3 | TIM_DMA_Update,
|
||||||
|
.irq = {
|
||||||
|
// Note this is the stream ID that triggers interrupts (in this case TX)
|
||||||
|
.flags = (DMA_IT_TCIF1),
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = DMA2_Stream1_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
void PIOS_WS2811_irq_handler(void)
|
||||||
|
{
|
||||||
|
/* Call into the generic code to handle the IRQ for this specific device */
|
||||||
|
PIOS_WS2811_DMA_irq_handler();
|
||||||
|
}
|
||||||
|
#endif // PIOS_INCLUDE_WS2811
|
||||||
|
@ -89,6 +89,8 @@
|
|||||||
#define PIOS_INCLUDE_ETASV3
|
#define PIOS_INCLUDE_ETASV3
|
||||||
#define PIOS_INCLUDE_MS4525DO
|
#define PIOS_INCLUDE_MS4525DO
|
||||||
|
|
||||||
|
#define PIOS_INCLUDE_WS2811
|
||||||
|
|
||||||
/* #define PIOS_INCLUDE_HCSR04 */
|
/* #define PIOS_INCLUDE_HCSR04 */
|
||||||
|
|
||||||
/* PIOS receiver drivers */
|
/* PIOS receiver drivers */
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <oplinkreceiver.h>
|
#include <oplinkreceiver.h>
|
||||||
#include <pios_oplinkrcvr_priv.h>
|
#include <pios_oplinkrcvr_priv.h>
|
||||||
#include <taskinfo.h>
|
#include <taskinfo.h>
|
||||||
|
#include <pios_ws2811.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pull in the board-specific static HW definitions.
|
* Pull in the board-specific static HW definitions.
|
||||||
@ -945,6 +946,11 @@ void PIOS_Board_Init(void)
|
|||||||
PIOS_MPU6000_Init(pios_spi_gyro_id, 0, &pios_mpu6000_cfg);
|
PIOS_MPU6000_Init(pios_spi_gyro_id, 0, &pios_mpu6000_cfg);
|
||||||
PIOS_MPU6000_CONFIG_Configure();
|
PIOS_MPU6000_CONFIG_Configure();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PIOS_INCLUDE_WS2811
|
||||||
|
#include <pios_ws2811.h>
|
||||||
|
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg);
|
||||||
|
#endif // PIOS_INCLUDE_WS2811
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user