aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src
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
parentf5a218a018d3ecd899db0ec5460a4e00dac78abe (diff)
ask a DMA Channel only when use .gen_waveform()
Diffstat (limited to 'examples/stm32f4/src')
-rw-r--r--examples/stm32f4/src/bin/pwm.rs12
-rw-r--r--examples/stm32f4/src/bin/ws2812_pwm.rs6
2 files changed, 4 insertions, 14 deletions
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
index 92bc42ec8..8844a9f0e 100644
--- a/examples/stm32f4/src/bin/pwm.rs
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -3,7 +3,6 @@
3 3
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::dma;
7use embassy_stm32::gpio::OutputType; 6use embassy_stm32::gpio::OutputType;
8use embassy_stm32::time::khz; 7use embassy_stm32::time::khz;
9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; 8use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
@@ -17,16 +16,7 @@ async fn main(_spawner: Spawner) {
17 info!("Hello World!"); 16 info!("Hello World!");
18 17
19 let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull); 18 let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
20 let mut pwm = SimplePwm::new( 19 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10), Default::default());
21 p.TIM1,
22 Some(ch1),
23 None,
24 None,
25 None,
26 khz(10),
27 Default::default(),
28 dma::NoDma,
29 );
30 let max = pwm.get_max_duty(); 20 let max = pwm.get_max_duty();
31 pwm.enable(Channel::Ch1); 21 pwm.enable(Channel::Ch1);
32 22
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