diff options
author | Sergey Vlasov <sigprof@gmail.com> | 2021-03-03 07:26:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-02 20:26:06 -0800 |
commit | 18a333ec6bc9051ae7ec63a809d725c5c5f77046 (patch) | |
tree | f2f34dfe316a4c5c6d1ad065c7512a32d46e5820 | |
parent | 8f5d2e546e69e09edd28ff68f3d3a894f96087a7 (diff) | |
download | qmk_firmware-18a333ec6bc9051ae7ec63a809d725c5c5f77046.tar.gz qmk_firmware-18a333ec6bc9051ae7ec63a809d725c5c5f77046.zip |
Add support for complementary outputs to the WS2812 PWM driver (#11988)
-rw-r--r-- | docs/ws2812_driver.md | 3 | ||||
-rw-r--r-- | drivers/chibios/ws2812_pwm.c | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md index cca6827ec..fa14f02fd 100644 --- a/docs/ws2812_driver.md +++ b/docs/ws2812_driver.md | |||
@@ -102,11 +102,14 @@ Configure the hardware via your config.h: | |||
102 | #define WS2812_PWM_DRIVER PWMD2 // default: PWMD2 | 102 | #define WS2812_PWM_DRIVER PWMD2 // default: PWMD2 |
103 | #define WS2812_PWM_CHANNEL 2 // default: 2 | 103 | #define WS2812_PWM_CHANNEL 2 // default: 2 |
104 | #define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2 | 104 | #define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2 |
105 | //#define WS2812_PWM_COMPLEMENTARY_OUTPUT // Define for a complementary timer output (TIMx_CHyN); omit for a normal timer output (TIMx_CHy). | ||
105 | #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. | 106 | #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. |
106 | #define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. | 107 | #define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. |
107 | #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. | 108 | #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. |
108 | ``` | 109 | ``` |
109 | 110 | ||
111 | Note that using a complementary timer output (TIMx_CHyN) is possible only for advanced-control timers (TIM1, TIM8, TIM20 on STM32), and the `STM32_PWM_USE_ADVANCED` option in mcuconf.h must be set to `TRUE`. Complementary outputs of general-purpose timers are not supported due to ChibiOS limitations. | ||
112 | |||
110 | You must also turn on the PWM feature in your halconf.h and mcuconf.h | 113 | You must also turn on the PWM feature in your halconf.h and mcuconf.h |
111 | 114 | ||
112 | #### Testing Notes | 115 | #### Testing Notes |
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c index 140120d48..e6af55b6b 100644 --- a/drivers/chibios/ws2812_pwm.c +++ b/drivers/chibios/ws2812_pwm.c | |||
@@ -27,6 +27,15 @@ | |||
27 | # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" | 27 | # error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #ifndef WS2812_PWM_COMPLEMENTARY_OUTPUT | ||
31 | # define WS2812_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH | ||
32 | #else | ||
33 | # if !STM32_PWM_USE_ADVANCED | ||
34 | # error "WS2812_PWM_COMPLEMENTARY_OUTPUT requires STM32_PWM_USE_ADVANCED == TRUE" | ||
35 | # endif | ||
36 | # define WS2812_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH | ||
37 | #endif | ||
38 | |||
30 | // Push Pull or Open Drain Configuration | 39 | // Push Pull or Open Drain Configuration |
31 | // Default Push Pull | 40 | // Default Push Pull |
32 | #ifndef WS2812_EXTERNAL_PULLUP | 41 | #ifndef WS2812_EXTERNAL_PULLUP |
@@ -247,7 +256,7 @@ void ws2812_init(void) { | |||
247 | .channels = | 256 | .channels = |
248 | { | 257 | { |
249 | [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled | 258 | [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled |
250 | [WS2812_PWM_CHANNEL - 1] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about | 259 | [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about |
251 | }, | 260 | }, |
252 | .cr2 = 0, | 261 | .cr2 = 0, |
253 | .dier = TIM_DIER_UDE, // DMA on update event for next period | 262 | .dier = TIM_DIER_UDE, // DMA on update event for next period |