summaryrefslogtreecommitdiff
path: root/platforms
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2024-03-03 04:16:47 +1100
committerGitHub <noreply@github.com>2024-03-02 17:16:47 +0000
commit569b0c70beceb1bbd2b2c5e9cc4f0ff9209995f3 (patch)
treeb2b280071523c452ca0771df3977e79de1165891 /platforms
parent3bf1ce5cf80facc4136a8a2100e050d52cd3d029 (diff)
WS2812 PWM: prefix for DMA defines (#23111)
* WS2812 PWM: prefix for DMA defines * Add backward compatibility defines
Diffstat (limited to 'platforms')
-rw-r--r--platforms/chibios/boards/BONSAI_C4/configs/config.h8
-rw-r--r--platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c18
-rw-r--r--platforms/chibios/drivers/ws2812_pwm.c60
3 files changed, 49 insertions, 37 deletions
diff --git a/platforms/chibios/boards/BONSAI_C4/configs/config.h b/platforms/chibios/boards/BONSAI_C4/configs/config.h
index 193b028bde..e933cd6fd1 100644
--- a/platforms/chibios/boards/BONSAI_C4/configs/config.h
+++ b/platforms/chibios/boards/BONSAI_C4/configs/config.h
@@ -77,11 +77,11 @@
77# ifndef WS2812_PWM_PAL_MODE 77# ifndef WS2812_PWM_PAL_MODE
78# define WS2812_PWM_PAL_MODE 1 78# define WS2812_PWM_PAL_MODE 1
79# endif 79# endif
80# ifndef WS2812_DMA_STREAM 80# ifndef WS2812_PWM_DMA_STREAM
81# define WS2812_DMA_STREAM STM32_DMA2_STREAM5 81# define WS2812_PWM_DMA_STREAM STM32_DMA2_STREAM5
82# endif 82# endif
83# ifndef WS2812_DMA_CHANNEL 83# ifndef WS2812_PWM_DMA_CHANNEL
84# define WS2812_DMA_CHANNEL 6 84# define WS2812_PWM_DMA_CHANNEL 6
85# endif 85# endif
86#endif 86#endif
87 87
diff --git a/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c b/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c
index de317e269a..799d96b3c6 100644
--- a/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c
+++ b/platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c
@@ -136,7 +136,7 @@ static const pio_program_t ws2812_program = {
136}; 136};
137 137
138static uint32_t WS2812_BUFFER[WS2812_LED_COUNT]; 138static uint32_t WS2812_BUFFER[WS2812_LED_COUNT];
139static const rp_dma_channel_t* WS2812_DMA_CHANNEL; 139static const rp_dma_channel_t* dma_channel;
140static uint32_t RP_DMA_MODE_WS2812; 140static uint32_t RP_DMA_MODE_WS2812;
141static int STATE_MACHINE = -1; 141static int STATE_MACHINE = -1;
142 142
@@ -236,9 +236,9 @@ bool ws2812_init(void) {
236 pio_sm_init(pio, STATE_MACHINE, offset, &config); 236 pio_sm_init(pio, STATE_MACHINE, offset, &config);
237 pio_sm_set_enabled(pio, STATE_MACHINE, true); 237 pio_sm_set_enabled(pio, STATE_MACHINE, true);
238 238
239 WS2812_DMA_CHANNEL = dmaChannelAlloc(RP_DMA_CHANNEL_ID_ANY, RP_DMA_PRIORITY_WS2812, (rp_dmaisr_t)ws2812_dma_callback, NULL); 239 dma_channel = dmaChannelAlloc(RP_DMA_CHANNEL_ID_ANY, RP_DMA_PRIORITY_WS2812, (rp_dmaisr_t)ws2812_dma_callback, NULL);
240 dmaChannelEnableInterruptX(WS2812_DMA_CHANNEL); 240 dmaChannelEnableInterruptX(dma_channel);
241 dmaChannelSetDestinationX(WS2812_DMA_CHANNEL, (uint32_t)&pio->txf[STATE_MACHINE]); 241 dmaChannelSetDestinationX(dma_channel, (uint32_t)&pio->txf[STATE_MACHINE]);
242 242
243 // clang-format off 243 // clang-format off
244 RP_DMA_MODE_WS2812 = DMA_CTRL_TRIG_INCR_READ | 244 RP_DMA_MODE_WS2812 = DMA_CTRL_TRIG_INCR_READ |
@@ -256,7 +256,7 @@ static inline void sync_ws2812_transfer(void) {
256 // count of LEDs in milliseconds. This is safely much longer than it 256 // count of LEDs in milliseconds. This is safely much longer than it
257 // would take to push all the data out. 257 // would take to push all the data out.
258 dprintln("ERROR: WS2812 DMA transfer has stalled, aborting!"); 258 dprintln("ERROR: WS2812 DMA transfer has stalled, aborting!");
259 dmaChannelDisableX(WS2812_DMA_CHANNEL); 259 dmaChannelDisableX(dma_channel);
260 pio_sm_clear_fifos(pio, STATE_MACHINE); 260 pio_sm_clear_fifos(pio, STATE_MACHINE);
261 pio_sm_restart(pio, STATE_MACHINE); 261 pio_sm_restart(pio, STATE_MACHINE);
262 chSemReset(&TRANSFER_COUNTER, 0); 262 chSemReset(&TRANSFER_COUNTER, 0);
@@ -284,8 +284,8 @@ void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
284#endif 284#endif
285 } 285 }
286 286
287 dmaChannelSetSourceX(WS2812_DMA_CHANNEL, (uint32_t)WS2812_BUFFER); 287 dmaChannelSetSourceX(dma_channel, (uint32_t)WS2812_BUFFER);
288 dmaChannelSetCounterX(WS2812_DMA_CHANNEL, leds); 288 dmaChannelSetCounterX(dma_channel, leds);
289 dmaChannelSetModeX(WS2812_DMA_CHANNEL, RP_DMA_MODE_WS2812); 289 dmaChannelSetModeX(dma_channel, RP_DMA_MODE_WS2812);
290 dmaChannelEnableX(WS2812_DMA_CHANNEL); 290 dmaChannelEnableX(dma_channel);
291} 291}
diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c
index 6bba22767f..e0b3bfd5b5 100644
--- a/platforms/chibios/drivers/ws2812_pwm.c
+++ b/platforms/chibios/drivers/ws2812_pwm.c
@@ -2,6 +2,18 @@
2#include "gpio.h" 2#include "gpio.h"
3#include "chibios_config.h" 3#include "chibios_config.h"
4 4
5// ======== DEPRECATED DEFINES - DO NOT USE ========
6#ifdef WS2812_DMA_STREAM
7# define WS2812_PWM_DMA_STREAM WS2812_DMA_STREAM
8#endif
9#ifdef WS2812_DMA_CHANNEL
10# define WS2812_PWM_DMA_CHANNEL WS2812_DMA_CHANNEL
11#endif
12#ifdef WS2812_DMAMUX_ID
13# define WS2812_PWM_DMAMUX_ID WS2812_DMAMUX_ID
14#endif
15// ========
16
5/* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */ 17/* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */
6 18
7#ifdef RGBW 19#ifdef RGBW
@@ -19,14 +31,14 @@
19#ifndef WS2812_PWM_PAL_MODE 31#ifndef WS2812_PWM_PAL_MODE
20# define WS2812_PWM_PAL_MODE 2 // DI Pin's alternate function value 32# define WS2812_PWM_PAL_MODE 2 // DI Pin's alternate function value
21#endif 33#endif
22#ifndef WS2812_DMA_STREAM 34#ifndef WS2812_PWM_DMA_STREAM
23# define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP 35# define WS2812_PWM_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP
24#endif 36#endif
25#ifndef WS2812_DMA_CHANNEL 37#ifndef WS2812_PWM_DMA_CHANNEL
26# define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP 38# define WS2812_PWM_DMA_CHANNEL 2 // DMA Channel for TIMx_UP
27#endif 39#endif
28#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_DMAMUX_ID) 40#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_PWM_DMAMUX_ID)
29# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" 41# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_PWM_DMAMUX_ID STM32_DMAMUX1_TIM?_UP"
30#endif 42#endif
31 43
32/* Summarize https://www.st.com/resource/en/application_note/an4013-stm32-crossseries-timer-overview-stmicroelectronics.pdf to 44/* Summarize https://www.st.com/resource/en/application_note/an4013-stm32-crossseries-timer-overview-stmicroelectronics.pdf to
@@ -270,20 +282,20 @@
270// For all other STM32 DMA transfer will automatically zero pad. We only need to set the right peripheral width. 282// For all other STM32 DMA transfer will automatically zero pad. We only need to set the right peripheral width.
271#if defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32F7XX) 283#if defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32F7XX)
272# if defined(WS2812_PWM_TIMER_32BIT) 284# if defined(WS2812_PWM_TIMER_32BIT)
273# define WS2812_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_WORD 285# define WS2812_PWM_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_WORD
274# define WS2812_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_WORD 286# define WS2812_PWM_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_WORD
275typedef uint32_t ws2812_buffer_t; 287typedef uint32_t ws2812_buffer_t;
276# else 288# else
277# define WS2812_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_HWORD 289# define WS2812_PWM_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_HWORD
278# define WS2812_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_HWORD 290# define WS2812_PWM_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_HWORD
279typedef uint16_t ws2812_buffer_t; 291typedef uint16_t ws2812_buffer_t;
280# endif 292# endif
281#else 293#else
282# define WS2812_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_BYTE 294# define WS2812_PWM_DMA_MEMORY_WIDTH STM32_DMA_CR_MSIZE_BYTE
283# if defined(WS2812_PWM_TIMER_32BIT) 295# if defined(WS2812_PWM_TIMER_32BIT)
284# define WS2812_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_WORD 296# define WS2812_PWM_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_WORD
285# else 297# else
286# define WS2812_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_HWORD 298# define WS2812_PWM_DMA_PERIPHERAL_WIDTH STM32_DMA_CR_PSIZE_HWORD
287# endif 299# endif
288typedef uint8_t ws2812_buffer_t; 300typedef uint8_t ws2812_buffer_t;
289#endif 301#endif
@@ -326,26 +338,26 @@ void ws2812_init(void) {
326 // Configure DMA 338 // Configure DMA
327 // dmaInit(); // Joe added this 339 // dmaInit(); // Joe added this
328#if defined(WB32F3G71xx) || defined(WB32FQ95xx) 340#if defined(WB32F3G71xx) || defined(WB32FQ95xx)
329 dmaStreamAlloc(WS2812_DMA_STREAM - WB32_DMA_STREAM(0), 10, NULL, NULL); 341 dmaStreamAlloc(WS2812_PWM_DMA_STREAM - WB32_DMA_STREAM(0), 10, NULL, NULL);
330 dmaStreamSetSource(WS2812_DMA_STREAM, ws2812_frame_buffer); 342 dmaStreamSetSource(WS2812_PWM_DMA_STREAM, ws2812_frame_buffer);
331 dmaStreamSetDestination(WS2812_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register 343 dmaStreamSetDestination(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register
332 dmaStreamSetMode(WS2812_DMA_STREAM, WB32_DMA_CHCFG_HWHIF(WS2812_DMA_CHANNEL) | WB32_DMA_CHCFG_DIR_M2P | WB32_DMA_CHCFG_PSIZE_WORD | WB32_DMA_CHCFG_MSIZE_WORD | WB32_DMA_CHCFG_MINC | WB32_DMA_CHCFG_CIRC | WB32_DMA_CHCFG_TCIE | WB32_DMA_CHCFG_PL(3)); 344 dmaStreamSetMode(WS2812_PWM_DMA_STREAM, WB32_DMA_CHCFG_HWHIF(WS2812_PWM_DMA_CHANNEL) | WB32_DMA_CHCFG_DIR_M2P | WB32_DMA_CHCFG_PSIZE_WORD | WB32_DMA_CHCFG_MSIZE_WORD | WB32_DMA_CHCFG_MINC | WB32_DMA_CHCFG_CIRC | WB32_DMA_CHCFG_TCIE | WB32_DMA_CHCFG_PL(3));
333#else 345#else
334 dmaStreamAlloc(WS2812_DMA_STREAM - STM32_DMA_STREAM(0), 10, NULL, NULL); 346 dmaStreamAlloc(WS2812_PWM_DMA_STREAM - STM32_DMA_STREAM(0), 10, NULL, NULL);
335 dmaStreamSetPeripheral(WS2812_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register 347 dmaStreamSetPeripheral(WS2812_PWM_DMA_STREAM, &(WS2812_PWM_DRIVER.tim->CCR[WS2812_PWM_CHANNEL - 1])); // Ziel ist der An-Zeit im Cap-Comp-Register
336 dmaStreamSetMemory0(WS2812_DMA_STREAM, ws2812_frame_buffer); 348 dmaStreamSetMemory0(WS2812_PWM_DMA_STREAM, ws2812_frame_buffer);
337 dmaStreamSetMode(WS2812_DMA_STREAM, STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | WS2812_DMA_PERIPHERAL_WIDTH | WS2812_DMA_MEMORY_WIDTH | STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); 349 dmaStreamSetMode(WS2812_PWM_DMA_STREAM, STM32_DMA_CR_CHSEL(WS2812_PWM_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | WS2812_PWM_DMA_PERIPHERAL_WIDTH | WS2812_PWM_DMA_MEMORY_WIDTH | STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3));
338#endif 350#endif
339 dmaStreamSetTransactionSize(WS2812_DMA_STREAM, WS2812_BIT_N); 351 dmaStreamSetTransactionSize(WS2812_PWM_DMA_STREAM, WS2812_BIT_N);
340 // M2P: Memory 2 Periph; PL: Priority Level 352 // M2P: Memory 2 Periph; PL: Priority Level
341 353
342#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) 354#if (STM32_DMA_SUPPORTS_DMAMUX == TRUE)
343 // If the MCU has a DMAMUX we need to assign the correct resource 355 // If the MCU has a DMAMUX we need to assign the correct resource
344 dmaSetRequestSource(WS2812_DMA_STREAM, WS2812_DMAMUX_ID); 356 dmaSetRequestSource(WS2812_PWM_DMA_STREAM, WS2812_PWM_DMAMUX_ID);
345#endif 357#endif
346 358
347 // Start DMA 359 // Start DMA
348 dmaStreamEnable(WS2812_DMA_STREAM); 360 dmaStreamEnable(WS2812_PWM_DMA_STREAM);
349 361
350 // Configure PWM 362 // Configure PWM
351 // NOTE: It's required that preload be enabled on the timer channel CCR register. This is currently enabled in the 363 // NOTE: It's required that preload be enabled on the timer channel CCR register. This is currently enabled in the