diff options
| author | eZio Pan <[email protected]> | 2024-01-02 13:30:13 +0800 |
|---|---|---|
| committer | eZio Pan <[email protected]> | 2024-01-02 14:01:09 +0800 |
| commit | c276da5fcb93ce20da0c2f3bfccdeb7e0fee67a7 (patch) | |
| tree | 2da944cf42dedda8c15a186ec725a49a0025dc03 /examples | |
| parent | f5a218a018d3ecd899db0ec5460a4e00dac78abe (diff) | |
ask a DMA Channel only when use .gen_waveform()
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/src/bin/pwm.rs | 12 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/ws2812_pwm.rs | 6 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/pwm.rs | 12 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/pwm.rs | 13 |
4 files changed, 7 insertions, 36 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 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::dma; | ||
| 7 | use embassy_stm32::gpio::OutputType; | 6 | use embassy_stm32::gpio::OutputType; |
| 8 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 9 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 8 | use 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 |
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 9fa004c3e..d4809a481 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::dma; | ||
| 7 | use embassy_stm32::gpio::OutputType; | 6 | use embassy_stm32::gpio::OutputType; |
| 8 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 9 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 8 | use 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.PC0, OutputType::PushPull); | 18 | let ch1 = PwmPin::new_ch1(p.PC0, 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/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index de155fc94..1e48ba67b 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -7,7 +7,7 @@ use embassy_stm32::gpio::OutputType; | |||
| 7 | use embassy_stm32::time::khz; | 7 | use embassy_stm32::time::khz; |
| 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 8 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 9 | use embassy_stm32::timer::Channel; | 9 | use embassy_stm32::timer::Channel; |
| 10 | use embassy_stm32::{dma, Config}; | 10 | use embassy_stm32::Config; |
| 11 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| @@ -38,16 +38,7 @@ async fn main(_spawner: Spawner) { | |||
| 38 | info!("Hello World!"); | 38 | info!("Hello World!"); |
| 39 | 39 | ||
| 40 | let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull); | 40 | let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull); |
| 41 | let mut pwm = SimplePwm::new( | 41 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10), Default::default()); |
| 42 | p.TIM3, | ||
| 43 | Some(ch1), | ||
| 44 | None, | ||
| 45 | None, | ||
| 46 | None, | ||
| 47 | khz(10), | ||
| 48 | Default::default(), | ||
| 49 | dma::NoDma, | ||
| 50 | ); | ||
| 51 | let max = pwm.get_max_duty(); | 42 | let max = pwm.get_max_duty(); |
| 52 | pwm.enable(Channel::Ch1); | 43 | pwm.enable(Channel::Ch1); |
| 53 | 44 | ||
