feat: support for HelloRadioSky V16 (#5317)

Co-authored-by: Peter Feerick <pfeerick@users.noreply.github.com>
This commit is contained in:
richardclli
2024-09-02 09:45:59 +10:00
committed by GitHub
co-authored by Peter Feerick
parent 4426f56cb9
commit 17bf9dc813
45 changed files with 1062 additions and 46 deletions
@@ -82,22 +82,23 @@ static void _led_dbg_init() {
#endif
#if defined(STM32_SUPPORT_32BIT_TIMERS)
typedef uint32_t led_timer_value_t;
#else
typedef uint16_t led_timer_value_t;
#endif
uint8_t pulse_inc = 1;
// DMA buffer contains pulses for 2 LED at a time
// (allows for refill at HT and TC)
#if defined(STM32_SUPPORT_32BIT_TIMERS)
static led_timer_value_t _led_dma_buffer[WS2821_DMA_BUFFER_LEN * 2] __DMA;
#else
static led_timer_value_t _led_dma_buffer[WS2821_DMA_BUFFER_LEN] __DMA;
#endif
static uint8_t _led_seq_cnt;
static void _fill_byte(uint8_t c, led_timer_value_t* dma_buffer)
{
for (int i = 0; i < 8; i++) {
dma_buffer[i] = c & 0x80 ? WS2812_ONE : WS2812_ZERO;
dma_buffer[i*pulse_inc] = c & 0x80 ? WS2812_ONE : WS2812_ZERO;
c <<= 1;
}
}
@@ -106,14 +107,14 @@ static void _fill_pulses(const uint8_t* colors, led_timer_value_t* dma_buffer, u
{
for (uint32_t i = 0; i < len; i++) {
_fill_byte(*colors, dma_buffer);
dma_buffer += 8;
dma_buffer += 8 * pulse_inc;
colors++;
}
}
static inline uint32_t _calc_offset(uint8_t tc)
{
return tc * WS2821_DMA_BUFFER_HALF_LEN;
return tc * WS2821_DMA_BUFFER_HALF_LEN * pulse_inc;
}
static void _update_dma_buffer(const stm32_pulse_timer_t* tim, uint8_t tc)
@@ -131,7 +132,7 @@ static void _update_dma_buffer(const stm32_pulse_timer_t* tim, uint8_t tc)
// no need to reset the buffer after 2 cycles
if (_led_seq_cnt < _led_strip_len + 2) {
auto offset = _calc_offset(tc);
auto size = WS2821_DMA_BUFFER_HALF_LEN * sizeof(led_timer_value_t);
auto size = WS2821_DMA_BUFFER_HALF_LEN * sizeof(led_timer_value_t) * pulse_inc;
memset(&_led_dma_buffer[offset], 0, size);
}
_led_seq_cnt++;
@@ -191,7 +192,7 @@ static void _init_timer(const stm32_pulse_timer_t* tim)
_led_set_dma_periph_addr(tim);
LL_DMA_SetMode(tim->DMAx, tim->DMA_Stream, LL_DMA_MODE_CIRCULAR);
LL_DMA_SetDataLength(tim->DMAx, tim->DMA_Stream, WS2821_DMA_BUFFER_LEN);
LL_DMA_SetDataLength(tim->DMAx, tim->DMA_Stream, WS2821_DMA_BUFFER_LEN * pulse_inc);
LL_DMA_SetMemoryAddress(tim->DMAx, tim->DMA_Stream, (uint32_t)_led_dma_buffer);
// we need to use a higher prio to avoid having
@@ -202,6 +203,7 @@ static void _init_timer(const stm32_pulse_timer_t* tim)
void ws2812_init(const stm32_pulse_timer_t* timer, uint8_t strip_len, uint8_t type)
{
WS2812_DBG_INIT;
pulse_inc = IS_TIM_32B_COUNTER_INSTANCE(timer->TIMx) ? 2 : 1;
memset(_led_colors, 0, sizeof(_led_colors));
memset(_led_dma_buffer, 0, sizeof(_led_dma_buffer));
@@ -32,7 +32,7 @@
// Maximum number of supported LEDs
#if !defined(WS2812_MAX_LEDS)
# define WS2812_MAX_LEDS 8
# define WS2812_MAX_LEDS 48
#endif
// Number of LED periods used for trailing reset