diff options
| author | eZio Pan <[email protected]> | 2023-12-16 02:15:56 +0800 |
|---|---|---|
| committer | eZio Pan <[email protected]> | 2023-12-16 02:15:56 +0800 |
| commit | ea1e1973eb88a3a57e7f4e2ad97d32e5fcd8b8d1 (patch) | |
| tree | 9e299aab04d255a9927161730ab8285ed52d48c7 /examples | |
| parent | 77e372e842c64b95e94fff93a711112514588841 (diff) | |
unify channel assign
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index 0c3444a47..52cc665c7 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs | |||
| @@ -85,8 +85,10 @@ async fn main(_spawner: Spawner) { | |||
| 85 | 85 | ||
| 86 | let color_list = [&turn_off, &dim_white]; | 86 | let color_list = [&turn_off, &dim_white]; |
| 87 | 87 | ||
| 88 | let pwm_channel = Channel::Ch1; | ||
| 89 | |||
| 88 | // make sure PWM output keep low on first start | 90 | // make sure PWM output keep low on first start |
| 89 | ws2812_pwm.set_duty(Channel::Ch1, 0); | 91 | ws2812_pwm.set_duty(pwm_channel, 0); |
| 90 | 92 | ||
| 91 | { | 93 | { |
| 92 | use embassy_stm32::dma::{Burst, FifoThreshold, Transfer, TransferOptions}; | 94 | use embassy_stm32::dma::{Burst, FifoThreshold, Transfer, TransferOptions}; |
| @@ -100,7 +102,7 @@ async fn main(_spawner: Spawner) { | |||
| 100 | 102 | ||
| 101 | loop { | 103 | loop { |
| 102 | // start PWM output | 104 | // start PWM output |
| 103 | ws2812_pwm.enable(Channel::Ch1); | 105 | ws2812_pwm.enable(pwm_channel); |
| 104 | 106 | ||
| 105 | unsafe { | 107 | unsafe { |
| 106 | Transfer::new_write( | 108 | Transfer::new_write( |
| @@ -108,7 +110,7 @@ async fn main(_spawner: Spawner) { | |||
| 108 | &mut dp.DMA1_CH2, | 110 | &mut dp.DMA1_CH2, |
| 109 | 5, | 111 | 5, |
| 110 | color_list[color_list_index], | 112 | color_list[color_list_index], |
| 111 | pac::TIM3.ccr(0).as_ptr() as *mut _, | 113 | pac::TIM3.ccr(pwm_channel.raw()).as_ptr() as *mut _, |
| 112 | dma_transfer_option, | 114 | dma_transfer_option, |
| 113 | ) | 115 | ) |
| 114 | .await; | 116 | .await; |
| @@ -117,7 +119,7 @@ async fn main(_spawner: Spawner) { | |||
| 117 | } | 119 | } |
| 118 | 120 | ||
| 119 | // stop PWM output for saving some energy | 121 | // stop PWM output for saving some energy |
| 120 | ws2812_pwm.disable(Channel::Ch1); | 122 | ws2812_pwm.disable(pwm_channel); |
| 121 | 123 | ||
| 122 | // wait another half second, so that we can see color change | 124 | // wait another half second, so that we can see color change |
| 123 | Timer::after_millis(500).await; | 125 | Timer::after_millis(500).await; |
