aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin/ws2812_pwm.rs
diff options
context:
space:
mode:
authoreZio Pan <[email protected]>2024-01-02 13:30:13 +0800
committereZio Pan <[email protected]>2024-01-02 14:01:09 +0800
commitc276da5fcb93ce20da0c2f3bfccdeb7e0fee67a7 (patch)
tree2da944cf42dedda8c15a186ec725a49a0025dc03 /examples/stm32f4/src/bin/ws2812_pwm.rs
parentf5a218a018d3ecd899db0ec5460a4e00dac78abe (diff)
ask a DMA Channel only when use .gen_waveform()
Diffstat (limited to 'examples/stm32f4/src/bin/ws2812_pwm.rs')
-rw-r--r--examples/stm32f4/src/bin/ws2812_pwm.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/stm32f4/src/bin/ws2812_pwm.rs b/examples/stm32f4/src/bin/ws2812_pwm.rs
index 93a89f16a..239709253 100644
--- a/examples/stm32f4/src/bin/ws2812_pwm.rs
+++ b/examples/stm32f4/src/bin/ws2812_pwm.rs
@@ -45,7 +45,7 @@ async fn main(_spawner: Spawner) {
45 device_config.rcc.sys = Sysclk::PLL1_P; 45 device_config.rcc.sys = Sysclk::PLL1_P;
46 } 46 }
47 47
48 let dp = embassy_stm32::init(device_config); 48 let mut dp = embassy_stm32::init(device_config);
49 49
50 let mut ws2812_pwm = SimplePwm::new( 50 let mut ws2812_pwm = SimplePwm::new(
51 dp.TIM3, 51 dp.TIM3,
@@ -55,7 +55,6 @@ async fn main(_spawner: Spawner) {
55 None, 55 None,
56 khz(800), // data rate of ws2812 56 khz(800), // data rate of ws2812
57 CountingMode::EdgeAlignedUp, 57 CountingMode::EdgeAlignedUp,
58 dp.DMA1_CH2,
59 ); 58 );
60 59
61 // construct ws2812 non-return-to-zero (NRZ) code bit by bit 60 // construct ws2812 non-return-to-zero (NRZ) code bit by bit
@@ -91,7 +90,8 @@ async fn main(_spawner: Spawner) {
91 90
92 loop { 91 loop {
93 for &color in color_list { 92 for &color in color_list {
94 ws2812_pwm.gen_waveform(pwm_channel, color).await; 93 // with &mut, we can easily reuse same DMA channel multiple times
94 ws2812_pwm.gen_waveform(&mut dp.DMA1_CH2, pwm_channel, color).await;
95 // ws2812 need at least 50 us low level input to confirm the input data and change it's state 95 // ws2812 need at least 50 us low level input to confirm the input data and change it's state
96 Timer::after_micros(50).await; 96 Timer::after_micros(50).await;
97 // wait until ticker tick 97 // wait until ticker tick