diff options
| author | Nick Brassel <nick@tzarc.org> | 2020-07-16 16:39:49 +1000 |
|---|---|---|
| committer | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-08-29 14:30:02 -0700 |
| commit | c6b7a0d386c347f20117943831a0215659d37c47 (patch) | |
| tree | 0b53a602c61b58842dba0f9dc3080371bfe1c027 | |
| parent | 8a4a0c25fdb2c4d0ac3ac8fd5f6ba14b56f4cd28 (diff) | |
| download | qmk_firmware-c6b7a0d386c347f20117943831a0215659d37c47.tar.gz qmk_firmware-c6b7a0d386c347f20117943831a0215659d37c47.zip | |
Add support for DMAMUX-capable MCU configuration with WS2812 PWM driver. (#9471)
| -rw-r--r-- | docs/ws2812_driver.md | 3 | ||||
| -rw-r--r-- | drivers/chibios/ws2812_pwm.c | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md index 941e1bde0..c1b96329e 100644 --- a/docs/ws2812_driver.md +++ b/docs/ws2812_driver.md | |||
| @@ -92,6 +92,7 @@ Configure the hardware via your config.h: | |||
| 92 | #define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2 | 92 | #define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2 |
| 93 | #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. | 93 | #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. |
| 94 | #define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. | 94 | #define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. |
| 95 | #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM2_UP // DMAMUX configuration for TIMx_UP -- only required if your MCU has a DMAMUX peripheral, see the respective reference manual for the appropriate values for your MCU. | ||
| 95 | ``` | 96 | ``` |
| 96 | 97 | ||
| 97 | You must also turn on the PWM feature in your halconf.h and mcuconf.h | 98 | You must also turn on the PWM feature in your halconf.h and mcuconf.h |
| @@ -117,5 +118,5 @@ Note: This only applies to STM32 boards. | |||
| 117 | 118 | ||
| 118 | To configure the `RGB_DI_PIN` to open drain configuration add this to your config.h file: | 119 | To configure the `RGB_DI_PIN` to open drain configuration add this to your config.h file: |
| 119 | ```c | 120 | ```c |
| 120 | #define WS2812_EXTERNAL_PULLUP | 121 | #define WS2812_EXTERNAL_PULLUP |
| 121 | ``` | 122 | ``` |
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c index 7113db11e..d93fa2473 100644 --- a/drivers/chibios/ws2812_pwm.c +++ b/drivers/chibios/ws2812_pwm.c | |||
| @@ -23,6 +23,9 @@ | |||
| 23 | #ifndef WS2812_DMA_CHANNEL | 23 | #ifndef WS2812_DMA_CHANNEL |
| 24 | # define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP | 24 | # define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP |
| 25 | #endif | 25 | #endif |
| 26 | #if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) && !defined(WS2812_DMAMUX_ID) | ||
| 27 | # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" | ||
| 28 | #endif | ||
| 26 | 29 | ||
| 27 | // Push Pull or Open Drain Configuration | 30 | // Push Pull or Open Drain Configuration |
| 28 | // Default Push Pull | 31 | // Default Push Pull |
| @@ -184,6 +187,11 @@ void ws2812_init(void) { | |||
| 184 | dmaStreamSetMode(WS2812_DMA_STREAM, STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_WORD | STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); | 187 | dmaStreamSetMode(WS2812_DMA_STREAM, STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_WORD | STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); |
| 185 | // M2P: Memory 2 Periph; PL: Priority Level | 188 | // M2P: Memory 2 Periph; PL: Priority Level |
| 186 | 189 | ||
| 190 | #if (STM32_DMA_SUPPORTS_DMAMUX == TRUE) | ||
| 191 | // If the MCU has a DMAMUX we need to assign the correct resource | ||
| 192 | dmaSetRequestSource(WS2812_DMA_STREAM, WS2812_DMAMUX_ID); | ||
| 193 | #endif | ||
| 194 | |||
| 187 | // Start DMA | 195 | // Start DMA |
| 188 | dmaStreamEnable(WS2812_DMA_STREAM); | 196 | dmaStreamEnable(WS2812_DMA_STREAM); |
| 189 | 197 | ||
