1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

LP-512 ws2811 led support for F3.

This commit is contained in:
Vladimir Zidar 2017-05-22 16:31:13 +02:00
parent 9ae89cedf3
commit e25cc40503
28 changed files with 466 additions and 96 deletions

View File

@ -37,7 +37,6 @@
#include "inc/notify.h"
#include "inc/sequences.h"
#include <pios_mem.h>
#include <hwsettings.h>
#define SAMPLE_PERIOD_MS 250
// private types
@ -54,13 +53,7 @@ static void checkAlarm(uint8_t alarm, uint8_t *last_alarm, uint32_t *last_alm_ti
static AlarmStatus_t *alarmStatus;
int32_t NotifyInitialize(void)
{
uint8_t ws281xOutStatus;
HwSettingsWS2811LED_OutGet(&ws281xOutStatus);
// Todo: Until further applications exists for WS2811 notify enabled status is tied to ws281x output configuration
bool enabled = ws281xOutStatus != HWSETTINGS_WS2811LED_OUT_DISABLED;
if (enabled) {
if (PIOS_WS2811_DEVICE) {
alarmStatus = (AlarmStatus_t *)pios_malloc(sizeof(AlarmStatus_t) * alarmsMapSize);
for (uint8_t i = 0; i < alarmsMapSize; i++) {
alarmStatus[i].lastAlarm = SYSTEMALARMS_ALARM_OK;

View File

@ -37,6 +37,23 @@
#define NELEMENTS(x) (sizeof(x) / sizeof((x)[0]))
/**
* @brief preprocessor magic
*
*/
#define _CONCAT5(a, b, c, d, e) a##b##c##d##e
#define _EVAL5(a, b, c, d, e) _CONCAT5(a, b, c, d, e)
#define _CONCAT4(a, b, c, d) a##b##c##d
#define _EVAL4(a, b, c, d) _CONCAT4(a, b, c, d)
#define _CONCAT3(a, b, c) a##b##c
#define _EVAL3(a, b, c) _CONCAT3(a, b, c)
#define _CONCAT2(a, b) a##b
#define _EVAL2(a, b) _CONCAT4(a, b)
/**
* @brief Compiler barrier: Disables compiler load/store reordering across the barrier
*

View File

@ -0,0 +1,78 @@
/**
******************************************************************************
*
* @file pios_ws2811_cfg.h
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
* @brief A driver for ws2811 rgb led controller.
* this is a port of the CleanFlight/BetaFlight implementation.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PIOS_WS2811_CFG_H_
#define PIOS_WS2811_CFG_H_
struct pios_ws2811_cfg {
TIM_TypeDef *timer;
uint8_t timer_chan;
struct stm32_gpio pin;
uint32_t remap;
uint16_t timer_dma_source;
DMA_Channel_TypeDef *dma_chan;
uint32_t dma_tcif;
uint8_t dma_irqn;
};
#define PIOS_WS2811_CONFIG(_timer, _channel, _gpio, _pin) \
{ \
.timer = _timer, \
.timer_chan = TIM_Channel_##_channel, \
.pin = { \
.gpio = GPIO##_gpio, \
.init = { \
.GPIO_Pin = GPIO_Pin_##_pin, \
.GPIO_Speed = GPIO_Speed_2MHz, \
.GPIO_Mode = GPIO_Mode_AF, \
.GPIO_OType = GPIO_OType_PP, \
.GPIO_PuPd = GPIO_PuPd_UP \
}, \
.pin_source = GPIO_PinSource##_pin, \
}, \
.remap = GPIO_AF_P##_gpio##_pin##_##_timer, \
.timer_dma_source = TIM_DMA_CC##_channel, \
.dma_chan = _EVAL4(DMA, _timer##_CH##_channel##_DMA_INSTANCE, _Channel, _timer##_CH##_channel##_DMA_CHANNEL), \
.dma_tcif = _EVAL4(DMA, _timer##_CH##_channel##_DMA_INSTANCE, _IT_TC, _timer##_CH##_channel##_DMA_CHANNEL), \
.dma_irqn = _EVAL5(DMA, _timer##_CH##_channel##_DMA_INSTANCE, _Channel, _timer##_CH##_channel##_DMA_CHANNEL, _IRQn), \
}
#define DMA0_Channel0 0
#define DMA0_IT_TC0 0
#define DMA0_Channel0_IRQn 0
void PIOS_WS2811_Init(uint32_t *dev_id, const struct pios_ws2811_cfg *ws2811_cfg);
void PIOS_WS2811_DMA_irq_handler();
#endif /* PIOS_WS2811_CFG_H_ */

View File

@ -39,6 +39,8 @@
#include <pios_spi_priv.h>
#define SPI_MAX_BLOCK_PIO 12800
static bool PIOS_SPI_validate(__attribute__((unused)) struct pios_spi_dev *com_dev)
{
/* Should check device magic here */
@ -168,7 +170,10 @@ int32_t PIOS_SPI_Init(uint32_t *spi_id, const struct pios_spi_cfg *cfg)
break;
}
bool use_dma = spi_dev->cfg->dma.rx.channel && spi_dev->cfg->dma.tx.channel;
/* Enable DMA clock */
if (use_dma) {
RCC_AHBPeriphClockCmd(spi_dev->cfg->dma.ahb_clk, ENABLE);
/* Configure DMA for SPI Rx */
@ -178,6 +183,7 @@ int32_t PIOS_SPI_Init(uint32_t *spi_id, const struct pios_spi_cfg *cfg)
/* Configure DMA for SPI Tx */
DMA_Cmd(spi_dev->cfg->dma.tx.channel, DISABLE);
DMA_Init(spi_dev->cfg->dma.tx.channel, (DMA_InitTypeDef *)&(spi_dev->cfg->dma.tx.init));
}
/* Initialize the SPI block */
SPI_I2S_DeInit(spi_dev->cfg->regs);
@ -197,7 +203,9 @@ int32_t PIOS_SPI_Init(uint32_t *spi_id, const struct pios_spi_cfg *cfg)
SPI_Cmd(spi_dev->cfg->regs, ENABLE);
/* Enable SPI interrupts to DMA */
if (use_dma) {
SPI_I2S_DMACmd(spi_dev->cfg->regs, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, ENABLE);
}
/* Configure DMA interrupt */
NVIC_Init((NVIC_InitTypeDef *)&(spi_dev->cfg->dma.irq.init));
@ -455,6 +463,7 @@ int32_t PIOS_SPI_TransferByte(uint32_t spi_id, uint8_t b)
return rx_byte;
}
/**
* Transfers a block of bytes via PIO.
*
@ -467,15 +476,10 @@ int32_t PIOS_SPI_TransferByte(uint32_t spi_id, uint8_t b)
* \return >= 0 if no error during transfer
* \return -1 if disabled SPI port selected
*/
int32_t PIOS_SPI_TransferBlock(uint32_t spi_id, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len, __attribute__((unused)) void *callback)
static int32_t PIOS_SPI_TransferBlock_PIO(struct pios_spi_dev *spi_dev, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len, __attribute__((unused)) void *callback)
{
struct pios_spi_dev *spi_dev = (struct pios_spi_dev *)spi_id;
uint8_t b;
bool valid = PIOS_SPI_validate(spi_dev);
PIOS_Assert(valid)
while (len--) {
/* get the byte to send */
b = send_buffer ? *(send_buffer++) : 0xff;
@ -527,14 +531,8 @@ int32_t PIOS_SPI_TransferBlock(uint32_t spi_id, const uint8_t *send_buffer, uint
* \return -1 if disabled SPI port selected
* \return -3 if function has been called during an ongoing DMA transfer
*/
int32_t _PIOS_SPI_TransferBlock(uint32_t spi_id, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len, void *callback)
static int32_t PIOS_SPI_TransferBlock_DMA(struct pios_spi_dev *spi_dev, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len, void *callback)
{
struct pios_spi_dev *spi_dev = (struct pios_spi_dev *)spi_id;
bool valid = PIOS_SPI_validate(spi_dev);
PIOS_Assert(valid)
DMA_InitTypeDef dma_init;
/* Exit if ongoing transfer */
@ -659,6 +657,21 @@ int32_t _PIOS_SPI_TransferBlock(uint32_t spi_id, const uint8_t *send_buffer, uin
return 0;
}
int32_t PIOS_SPI_TransferBlock(uint32_t spi_id, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len, void *callback)
{
struct pios_spi_dev *spi_dev = (struct pios_spi_dev *)spi_id;
bool valid = PIOS_SPI_validate(spi_dev);
PIOS_Assert(valid)
if ((len > SPI_MAX_BLOCK_PIO) && spi_dev->cfg->dma.rx.channel && spi_dev->cfg->dma.tx.channel) {
return PIOS_SPI_TransferBlock_DMA(spi_dev, send_buffer, receive_buffer, len, callback);
}
return PIOS_SPI_TransferBlock_PIO(spi_dev, send_buffer, receive_buffer, len, callback);
}
/**
* Check if a transfer is in progress
* \param[in] spi SPI number (0 or 1)

View File

@ -0,0 +1,208 @@
/**
******************************************************************************
*
* @file pios_ws2811.c
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
* @brief A driver for ws2811 rgb led controller.
* this is a port of the CleanFlight/BetaFlight implementation.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pios.h"
#include "pios_ws2811.h"
#include "pios_ws2811_cfg.h"
#define WS2811_BITS_PER_LED 24
// for 50us delay
#define WS2811_DELAY_BUFFER_LENGTH 42
#define WS2811_DATA_BUFFER_SIZE (WS2811_BITS_PER_LED * PIOS_WS2811_NUMLEDS)
// number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes)
#define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE + WS2811_DELAY_BUFFER_LENGTH)
#define WS2811_TIMER_HZ 24000000
#define WS2811_TIMER_PERIOD 29
// timer compare value for logical 1
#define BIT_COMPARE_1 17
// timer compare value for logical 0
#define BIT_COMPARE_0 9
#define PIOS_WS2811_MAGIC 0x00281100
struct pios_ws2811_dev {
uint32_t magic;
const struct pios_ws2811_cfg *config;
uint8_t dma_buffer[WS2811_DMA_BUFFER_SIZE];
bool dma_active;
};
struct pios_ws2811_dev *ws2811_dev;
void PIOS_WS2811_Init(uint32_t *dev_id, const struct pios_ws2811_cfg *ws2811_cfg)
{
if (ws2811_dev) {
return;
}
ws2811_dev = (struct pios_ws2811_dev *)pios_malloc(sizeof(*ws2811_dev));
PIOS_Assert(ws2811_dev);
memset(ws2811_dev, 0, sizeof(*ws2811_dev));
ws2811_dev->magic = PIOS_WS2811_MAGIC;
ws2811_dev->config = ws2811_cfg;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
DMA_InitTypeDef DMA_InitStructure;
GPIO_Init(ws2811_cfg->pin.gpio, (GPIO_InitTypeDef *)&ws2811_cfg->pin.init);
GPIO_PinAFConfig(ws2811_cfg->pin.gpio, ws2811_cfg->pin.pin_source, ws2811_cfg->remap);
/* Compute the prescaler value */
uint16_t prescalerValue = (uint16_t)(SystemCoreClock / WS2811_TIMER_HZ) - 1;
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = WS2811_TIMER_PERIOD; // 800kHz
TIM_TimeBaseStructure.TIM_Prescaler = prescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(ws2811_cfg->timer, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
switch (ws2811_cfg->timer_chan) {
case TIM_Channel_1:
TIM_OC1Init(ws2811_cfg->timer, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(ws2811_cfg->timer, TIM_OCPreload_Enable);
break;
case TIM_Channel_2:
TIM_OC2Init(ws2811_cfg->timer, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(ws2811_cfg->timer, TIM_OCPreload_Enable);
break;
case TIM_Channel_3:
TIM_OC3Init(ws2811_cfg->timer, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(ws2811_cfg->timer, TIM_OCPreload_Enable);
break;
case TIM_Channel_4:
TIM_OC4Init(ws2811_cfg->timer, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(ws2811_cfg->timer, TIM_OCPreload_Enable);
break;
}
TIM_CtrlPWMOutputs(ws2811_cfg->timer, ENABLE);
/* configure DMA */
// NVIC setup here
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ws2811_cfg->dma_irqn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_DeInit(ws2811_cfg->dma_chan);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ws2811_cfg->timer->CCR1 + ws2811_cfg->timer_chan;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ws2811_dev->dma_buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = WS2811_DMA_BUFFER_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(ws2811_cfg->dma_chan, &DMA_InitStructure);
TIM_DMACmd(ws2811_cfg->timer, ws2811_cfg->timer_dma_source, ENABLE);
DMA_ITConfig(ws2811_cfg->dma_chan, DMA_IT_TC, ENABLE);
*dev_id = (uint32_t) ws2811_dev;
}
void PIOS_WS2811_DMA_irq_handler()
{
if (!ws2811_dev) {
return;
}
if (DMA_GetITStatus(ws2811_dev->config->dma_tcif)) {
ws2811_dev->dma_active = false;
DMA_Cmd(ws2811_dev->config->dma_chan, DISABLE);
DMA_ClearITPendingBit(ws2811_dev->config->dma_tcif);
}
}
/**
* Set a led color
* @param c color
* @param led led number
* @param update Perform an update after changing led color
*/
void PIOS_WS2811_setColorRGB(Color_t c, uint8_t led, bool update)
{
if (!ws2811_dev || (led >= PIOS_WS2811_NUMLEDS)) {
return;
}
int offset = led * WS2811_BITS_PER_LED;
uint32_t grb = (c.G << 16) | (c.R << 8) | (c.B);
for (int bit = (WS2811_BITS_PER_LED - 1); bit >= 0; --bit) {
ws2811_dev->dma_buffer[offset++] = (grb & (1 << bit)) ? BIT_COMPARE_1 : BIT_COMPARE_0;
}
if (update) {
PIOS_WS2811_Update();
}
}
void PIOS_WS2811_Update()
{
if (!ws2811_dev || ws2811_dev->dma_active) {
return;
}
ws2811_dev->dma_active = true;
DMA_SetCurrDataCounter(ws2811_dev->config->dma_chan, WS2811_DMA_BUFFER_SIZE); // load number of bytes to be transferred
TIM_SetCounter(ws2811_dev->config->timer, 0);
TIM_Cmd(ws2811_dev->config->timer, ENABLE);
DMA_Cmd(ws2811_dev->config->dma_chan, ENABLE);
}

View File

@ -130,7 +130,7 @@ struct pios_ws2811_cfg {
struct stm32_irq irq;
};
void PIOS_WS2811_Init(const struct pios_ws2811_cfg *ws2811_cfg, const struct pios_ws2811_pin_cfg *ws2811_pin_cfg);
void PIOS_WS2811_Init(uint32_t *dev_id, const struct pios_ws2811_cfg *ws2811_cfg, const struct pios_ws2811_pin_cfg *ws2811_pin_cfg);
void PIOS_WS2811_DMA_irq_handler();
#endif /* PIOS_WS2811_H_ */

View File

@ -163,7 +163,9 @@ static void genericTIM_OCxPreloadConfig(TIM_TypeDef *TIMx, uint16_t TIM_OCPreloa
*
*/
void PIOS_WS2811_Init(const struct pios_ws2811_cfg *ws2811_cfg, const struct pios_ws2811_pin_cfg *ws2811_pin_cfg)
#define PIOS_WS2811_MAGIC 0x00281100
void PIOS_WS2811_Init(uint32_t *dev_id, const struct pios_ws2811_cfg *ws2811_cfg, const struct pios_ws2811_pin_cfg *ws2811_pin_cfg)
{
assert_param(ws2811_cfg);
assert_param(ws2811_pin_cfg);
@ -184,6 +186,9 @@ void PIOS_WS2811_Init(const struct pios_ws2811_cfg *ws2811_cfg, const struct pio
// Setup timers
setupTimer();
setupDMA();
//
*dev_id = PIOS_WS2811_MAGIC;
}
void setupTimer()

View File

@ -163,6 +163,11 @@ extern uint32_t pios_com_msp_id;
extern uint32_t pios_com_mavlink_id;
#define PIOS_COM_MAVLINK (pios_com_mavlink_id)
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// ADC
// PIOS_ADC_PinGet(0) = Gyro Z

View File

@ -51,10 +51,13 @@
*/
#include "../board_hw_defs.c"
uintptr_t pios_uavo_settings_fs_id;
uintptr_t pios_user_fs_id;
#ifdef PIOS_INCLUDE_WS2811
uint32_t pios_ws2811_id;
#endif
static const PIOS_BOARD_IO_UART_Function flexiio_function_map[] = {
[HWSETTINGS_RM_RCVRPORT_PPMTELEMETRY] = PIOS_BOARD_IO_UART_TELEMETRY,
[HWSETTINGS_RM_RCVRPORT_PPMDEBUGCONSOLE] = PIOS_BOARD_IO_UART_DEBUGCONSOLE,
@ -239,7 +242,6 @@ void PIOS_Board_Init(void)
PIOS_BOARD_IO_Configure_USB();
#endif
/* Configure main USART port */
uint8_t hwsettings_mainport;
HwSettingsRM_MainPortGet(&hwsettings_mainport);
@ -323,7 +325,7 @@ void PIOS_Board_Init(void)
PIOS_BOARD_Sensors_Configure();
#ifdef PIOS_INCLUDE_WS2811
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg);
PIOS_WS2811_Init(&pios_ws2811_id, &pios_ws2811_cfg, &pios_ws2811_pin_cfg);
#endif // PIOS_INCLUDE_WS2811
#ifdef PIOS_INCLUDE_ADC

View File

@ -134,6 +134,11 @@ extern uint32_t pios_i2c_flexiport_adapter_id;
// -------------------------
#define PIOS_COM_MAX_DEVS 4
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// Packet Handler
// -------------------------

View File

@ -163,6 +163,12 @@ extern uint32_t pios_com_msp_id;
extern uint32_t pios_com_mavlink_id;
#define PIOS_COM_MAVLINK (pios_com_mavlink_id)
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// ADC
// PIOS_ADC_PinGet(0) = Current sensor

View File

@ -54,6 +54,10 @@
uintptr_t pios_uavo_settings_fs_id;
uintptr_t pios_user_fs_id;
#ifdef PIOS_INCLUDE_WS2811
uint32_t pios_ws2811_id;
#endif
static const PIOS_BOARD_IO_UART_Function flexiio_function_map[] = {
[HWSETTINGS_RM_RCVRPORT_PPMTELEMETRY] = PIOS_BOARD_IO_UART_TELEMETRY,
[HWSETTINGS_RM_RCVRPORT_PPMDEBUGCONSOLE] = PIOS_BOARD_IO_UART_DEBUGCONSOLE,
@ -325,7 +329,7 @@ void PIOS_Board_Init(void)
HwSettingsWS2811LED_OutGet(&ws2811_pin_settings);
if (ws2811_pin_settings != HWSETTINGS_WS2811LED_OUT_DISABLED && ws2811_pin_settings < NELEMENTS(pios_ws2811_pin_cfg)) {
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg[ws2811_pin_settings]);
PIOS_WS2811_Init(&pios_ws2811_id, &pios_ws2811_cfg, &pios_ws2811_pin_cfg[ws2811_pin_settings]);
}
#endif // PIOS_INCLUDE_WS2811

View File

@ -154,6 +154,11 @@ extern uint32_t pios_i2c_flexiport_adapter_id;
// -------------------------
#define PIOS_COM_MAX_DEVS 4
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// Packet Handler
// -------------------------

View File

@ -56,6 +56,10 @@
uintptr_t pios_uavo_settings_fs_id;
uintptr_t pios_user_fs_id;
#ifdef PIOS_INCLUDE_WS2811
uint32_t pios_ws2811_id;
#endif
static SystemAlarmsExtendedAlarmStatusOptions RevoNanoConfigHook();
static void ActuatorSettingsUpdatedCb(UAVObjEvent *ev);
@ -203,7 +207,6 @@ void PIOS_Board_Init(void)
PIOS_BOARD_IO_Configure_UART(&pios_usart_flexi_cfg, flexi_function_map[hwsettings_flexiport]);
}
/* Configure main USART port */
uint8_t hwsettings_mainport;
HwSettingsRM_MainPortGet(&hwsettings_mainport);
@ -263,7 +266,7 @@ void PIOS_Board_Init(void)
// No other choices but servo pin 1 on nano
if (ws2811_pin_settings != HWSETTINGS_WS2811LED_OUT_DISABLED) {
pios_tim_servoport_all_pins[0] = dummmy_timer; // free timer 1
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg[0]);
PIOS_WS2811_Init(&pios_ws2811_id, &pios_ws2811_cfg, &pios_ws2811_pin_cfg[0]);
}
#endif // PIOS_INCLUDE_WS2811

View File

@ -130,6 +130,11 @@ extern uint32_t pios_i2c_flexiport_adapter_id;
#define PIOS_I2C_MS4525DO_ADAPTER (PIOS_I2C_FLEXI_ADAPTER)
#define PIOS_I2C_EXTERNAL_ADAPTER (PIOS_I2C_FLEXI_ADAPTER)
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// PIOS_USART
//

View File

@ -137,6 +137,11 @@ extern uint32_t pios_i2c_flexiport_adapter_id;
// -------------------------
#define PIOS_COM_MAX_DEVS 4
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// ------------------------
// TELEMETRY
// ------------------------

View File

@ -56,6 +56,10 @@
uintptr_t pios_uavo_settings_fs_id;
uintptr_t pios_user_fs_id;
#ifdef PIOS_INCLUDE_WS2811
uint32_t pios_ws2811_id;
#endif
static const PIOS_BOARD_IO_UART_Function rcvr_function_map[] = {
[HWSETTINGS_SPK2_RCVRPORT_SBUS] = PIOS_BOARD_IO_UART_SBUS,
[HWSETTINGS_SPK2_RCVRPORT_DSM] = PIOS_BOARD_IO_UART_DSM_RCVR,
@ -283,7 +287,7 @@ void PIOS_Board_Init(void)
HwSettingsWS2811LED_OutGet(&ws2811_pin_settings);
if (ws2811_pin_settings != HWSETTINGS_WS2811LED_OUT_DISABLED && ws2811_pin_settings < NELEMENTS(pios_ws2811_pin_cfg)) {
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg[ws2811_pin_settings]);
PIOS_WS2811_Init(&pios_ws2811_id, &pios_ws2811_cfg, &pios_ws2811_pin_cfg[ws2811_pin_settings]);
}
#endif // PIOS_INCLUDE_WS2811

View File

@ -156,6 +156,11 @@ extern uint32_t pios_i2c_flexiport_adapter_id;
// -------------------------
#define PIOS_COM_MAX_DEVS 4
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// Packet Handler
// -------------------------

View File

@ -502,6 +502,8 @@ static const struct pios_tim_clock_cfg tim_17_cfg = {
#define GPIO_AF_PA2_TIM15 GPIO_AF_9
#define GPIO_AF_PA3_TIM15 GPIO_AF_9
#define TIM1_CH1_DMA_INSTANCE 1
#define TIM1_CH1_DMA_CHANNEL 2
static const struct pios_tim_channel pios_tim_servoport_io1_io2_pins[] = {
TIM_SERVO_CHANNEL_CONFIG(TIM16, 1, A, 6), // bank 1
@ -793,6 +795,17 @@ void PIOS_I2C_er_irq_handler(void)
#endif /* PIOS_INCLUDE_RCVR */
#if defined(PIOS_INCLUDE_WS2811)
#include "pios_ws2811_cfg.h"
static const struct pios_ws2811_cfg pios_ws2811_cfg = PIOS_WS2811_CONFIG(TIM1, 1, A, 8);
void DMA1_Channel2_IRQHandler()
{
PIOS_WS2811_DMA_irq_handler();
}
#endif /* PIOS_INCLUDE_WS2811 */
#if defined(PIOS_INCLUDE_ADC)
#include "pios_adc_priv.h"

View File

@ -48,7 +48,7 @@ MODULES += FirmwareIAP
#MODULES += Osd/osdoutout
#MODULES += Logging
MODULES += Telemetry
#MODULES += Notify
MODULES += Notify
OPTMODULES += Airspeed
OPTMODULES += AutoTune

View File

@ -96,6 +96,8 @@
#define PIOS_SENSOR_RATE 500.0f
#define PIOS_INCLUDE_WS2811
/* PIOS receiver drivers */
#define PIOS_INCLUDE_PWM
#define PIOS_INCLUDE_PPM

View File

@ -70,6 +70,10 @@ static void hwSPRacingF3SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *e
uintptr_t pios_uavo_settings_fs_id;
uintptr_t pios_user_fs_id = 0;
#ifdef PIOS_INCLUDE_WS2811
uint32_t pios_ws2811_id;
#endif
/**
* PIOS_Board_Init()
* initializes all the core subsystems on this specific hardware
@ -242,6 +246,9 @@ void PIOS_Board_Init(void)
switch (boardHwSettings.LEDPort) {
case HWSPRACINGF3SETTINGS_LEDPORT_WS2811:
#if defined(PIOS_INCLUDE_WS2811)
PIOS_WS2811_Init(&pios_ws2811_id, &pios_ws2811_cfg);
#endif
break;
case HWSPRACINGF3SETTINGS_LEDPORT_OUTPUT:
break;

View File

@ -134,6 +134,11 @@ extern uint32_t pios_i2c_id;
// -------------------------
#define PIOS_COM_MAX_DEVS 3
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// ADC
// PIOS_ADC_PinGet(0) = Current sensor

View File

@ -64,10 +64,6 @@ const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused))
/* Gyro interface */
void PIOS_SPI_MPU9250_irq_handler(void);
void DMA1_Channel2_IRQHandler() __attribute__((alias("PIOS_SPI_MPU9250_irq_handler")));
void DMA1_Channel3_IRQHandler() __attribute__((alias("PIOS_SPI_MPU9250_irq_handler")));
static const struct pios_spi_cfg pios_spi_mpu9250_cfg = {
.regs = SPI1,
.init = {
@ -82,48 +78,6 @@ static const struct pios_spi_cfg pios_spi_mpu9250_cfg = {
.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16, /* 10 Mhz */
},
.use_crc = false,
.dma = {
.ahb_clk = RCC_AHBPeriph_DMA1,
.irq = {
.flags = (DMA1_FLAG_TC2 | DMA1_FLAG_TE2 | DMA1_FLAG_HT2 | DMA1_FLAG_GL2),
.init = {
.NVIC_IRQChannel = DMA1_Channel2_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.channel = DMA1_Channel2,
.init = {
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
.DMA_DIR = DMA_DIR_PeripheralSRC,
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
.DMA_MemoryInc = DMA_MemoryInc_Enable,
.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
.DMA_Mode = DMA_Mode_Normal,
.DMA_Priority = DMA_Priority_Medium,
.DMA_M2M = DMA_M2M_Disable,
},
},
.tx = {
.channel = DMA1_Channel3,
.init = {
.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
.DMA_DIR = DMA_DIR_PeripheralDST,
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
.DMA_MemoryInc = DMA_MemoryInc_Enable,
.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
.DMA_Mode = DMA_Mode_Normal,
.DMA_Priority = DMA_Priority_Medium,
.DMA_M2M = DMA_M2M_Disable,
},
},
},
.remap = GPIO_AF_5,
.sclk = {
.gpio = GPIOB,
@ -171,11 +125,6 @@ static const struct pios_spi_cfg pios_spi_mpu9250_cfg = {
};
uint32_t pios_spi_mpu9250_id;
void PIOS_SPI_MPU9250_irq_handler(void)
{
/* Call into the generic code to handle the IRQ for this specific device */
PIOS_SPI_IRQ_Handler(pios_spi_mpu9250_id);
}
/* SDCARD Interface
*
@ -449,6 +398,11 @@ static const struct pios_tim_clock_cfg tim_17_cfg = {
#define GPIO_AF_PA3_TIM15 GPIO_AF_9
#define GPIO_AF_PA6_TIM3 GPIO_AF_2
#define GPIO_AF_PA7_TIM3 GPIO_AF_2
#define GPIO_AF_PA10_TIM2 GPIO_AF_10
#define TIM1_CH1_DMA_INSTANCE 1
#define TIM1_CH1_DMA_CHANNEL 2
static const struct pios_tim_channel pios_tim_servoport_pins[] = {
TIM_SERVO_CHANNEL_CONFIG(TIM2, 1, A, 0), // bank 1
@ -714,6 +668,17 @@ const struct pios_usb_cfg *PIOS_BOARD_HW_DEFS_GetUsbCfg(__attribute__((unused))
}
#endif /* PIOS_INCLUDE_USB */
#if defined(PIOS_INCLUDE_WS2811)
#include "pios_ws2811_cfg.h"
static const struct pios_ws2811_cfg pios_ws2811_cfg = PIOS_WS2811_CONFIG(TIM1, 1, A, 8);
void DMA1_Channel2_IRQHandler()
{
PIOS_WS2811_DMA_irq_handler();
}
#endif /* PIOS_INCLUDE_WS2811 */
#if defined(PIOS_INCLUDE_ADC)
#include "pios_adc_priv.h"

View File

@ -46,7 +46,7 @@ MODULES += FirmwareIAP
#MODULES += Osd/osdoutout
#MODULES += Logging
MODULES += Telemetry
#MODULES += Notify
MODULES += Notify
OPTMODULES += Airspeed
OPTMODULES += AutoTune

View File

@ -99,6 +99,8 @@
#define PIOS_SENSOR_RATE 500.0f
#define PIOS_INCLUDE_WS2811
/* PIOS receiver drivers */
#define PIOS_INCLUDE_PWM
#define PIOS_INCLUDE_PPM

View File

@ -58,6 +58,11 @@
uintptr_t pios_uavo_settings_fs_id;
uintptr_t pios_user_fs_id = 0;
#ifdef PIOS_INCLUDE_WS2811
uint32_t pios_ws2811_id;
#endif
static HwSPRacingF3EVOSettingsData boardHwSettings;
static void hwSPRacingF3EVOSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
@ -223,6 +228,9 @@ void PIOS_Board_Init(void)
switch (boardHwSettings.LEDPort) {
case HWSPRACINGF3EVOSETTINGS_LEDPORT_WS2811:
#if defined(PIOS_INCLUDE_WS2811)
PIOS_WS2811_Init(&pios_ws2811_id, &pios_ws2811_cfg);
#endif
break;
case HWSPRACINGF3EVOSETTINGS_LEDPORT_OUTPUT:
break;

View File

@ -136,6 +136,11 @@ extern uint32_t pios_spi_mpu9250_id;
#define PIOS_COM_MAX_DEVS 3
#ifdef PIOS_INCLUDE_WS2811
extern uint32_t pios_ws2811_id;
#define PIOS_WS2811_DEVICE (pios_ws2811_id)
#endif
// -------------------------
// ADC
// PIOS_ADC_PinGet(0) = Current sensor