feat: Support for WS2812 RGB LEDs (#3909)

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
This commit is contained in:
Raphael Coeffic
2023-10-14 14:06:55 +10:00
committed by GitHub
co-authored by 3djc
parent f8ad3a7bda
commit b22a1b5d32
60 changed files with 788 additions and 122 deletions
@@ -22,6 +22,7 @@
#include "hal/module_port.h"
#include "stm32_serial_driver.h"
#include "stm32_softserial_driver.h"
#include "stm32_dma.h"
#include "module_ports.h"
#include "board.h"
@@ -86,7 +87,7 @@ static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(INTMODULE_TIMER_Channel),
"Unsupported timer channel");
// Make sure the DMA channel is supported
static_assert(__STM32_PULSE_IS_DMA_STREAM_SUPPORTED(INTMODULE_TIMER_DMA_STREAM),
static_assert(__STM32_DMA_IS_STREAM_SUPPORTED(INTMODULE_TIMER_DMA_STREAM),
"Unsupported DMA stream");
#if !defined(INTMODULE_TIMER_DMA_IRQHandler)
@@ -198,7 +199,7 @@ static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(EXTMODULE_TIMER_Channel),
"Unsupported timer channel");
// Make sure the DMA channel is supported
static_assert(__STM32_PULSE_IS_DMA_STREAM_SUPPORTED(EXTMODULE_TIMER_DMA_STREAM_LL),
static_assert(__STM32_DMA_IS_STREAM_SUPPORTED(EXTMODULE_TIMER_DMA_STREAM_LL),
"Unsupported DMA stream");
#if !defined(EXTMODULE_TIMER_DMA_IRQHandler)
+115
View File
@@ -0,0 +1,115 @@
/*
* Copyright (C) EdgeTx
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*/
#include "stm32_pulse_driver.h"
#include "rgb_leds.h"
#include "hal.h"
#include "opentx.h"
#if defined(LED_STRIP_GPIO)
#include "stm32_ws2812.h"
#include "stm32_dma.h"
#if !defined(SIMU)
#include <FreeRTOS/include/FreeRTOS.h>
#include <FreeRTOS/include/timers.h>
#endif
extern const stm32_pulse_timer_t _led_timer;
static TimerHandle_t rgbLedTimer = nullptr;
static StaticTimer_t rgbLedTimerBuffer;
void rgbSetLedColor(uint8_t led, uint8_t r, uint8_t g, uint8_t b)
{
ws2812_set_color(led, r, g, b);
}
void rgbLedColorApply()
{
ws2812_update(&_led_timer);;
}
static void rgbLedTimerCb(TimerHandle_t xTimer)
{
(void)xTimer;
ws2812_update(&_led_timer);
}
void rgbLedStart()
{
if (!rgbLedTimer) {
rgbLedTimer =
xTimerCreateStatic("rgbLed", LED_STRIP_REFRESH_PERIOD / RTOS_MS_PER_TICK, pdTRUE, (void*)0,
rgbLedTimerCb, &rgbLedTimerBuffer);
}
if (rgbLedTimer) {
if( xTimerStart( rgbLedTimer, 0 ) != pdPASS ) {
/* The timer could not be set into the Active state. */
}
}
}
void rgbLedStop()
{
if (rgbLedTimer) {
if( xTimerStop( rgbLedTimer, 5 / RTOS_MS_PER_TICK ) != pdPASS ) {
/* The timer could not be stopped. */
}
}
}
const stm32_pulse_timer_t _led_timer = {
.GPIOx = LED_STRIP_GPIO,
.GPIO_Pin = LED_STRIP_GPIO_PIN_DATA,
.GPIO_Alternate = LED_STRIP_GPIO_PIN_AF,
.TIMx = LED_STRIP_TIMER,
.TIM_Freq = LED_STRIP_TIMER_FREQ,
.TIM_Channel = LED_STRIP_TIMER_CHANNEL,
.TIM_IRQn = (IRQn_Type)-1,
.DMAx = LED_STRIP_TIMER_DMA,
.DMA_Stream = LED_STRIP_TIMER_DMA_STREAM,
.DMA_Channel = LED_STRIP_TIMER_DMA_CHANNEL,
.DMA_IRQn = LED_STRIP_TIMER_DMA_IRQn,
.DMA_TC_CallbackPtr = nullptr,
};
// Make sure the timer channel is supported
static_assert(__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(LED_STRIP_TIMER_CHANNEL),
"Unsupported timer channel");
// Make sure the DMA channel is supported
static_assert(__STM32_DMA_IS_STREAM_SUPPORTED(LED_STRIP_TIMER_DMA_STREAM),
"Unsupported DMA stream");
#if !defined(LED_STRIP_TIMER_DMA_IRQHandler)
#error "Missing LED_STRIP_TIMER_DMA_IRQHandler definition"
#endif
extern "C" void LED_STRIP_TIMER_DMA_IRQHandler()
{
ws2812_dma_isr(&_led_timer);
}
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (C) EdgeTx
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*/
#pragma once
void rgbLedStart();
void rgbLedStop();
void rgbSetLedColor(unsigned char, unsigned char, unsigned char, unsigned char);
void rgbLedColorApply();
// void boardInitRGBLed();