diff options
| author | Ulf Lilleengen <[email protected]> | 2024-10-23 10:30:13 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-10-23 10:30:13 +0000 |
| commit | 8803128707b8bd9fc9dcea392a62dfd42aa822d2 (patch) | |
| tree | f7ce53e194af927e02b015bf8e5dcd837169a70e /examples/stm32h7/src/bin | |
| parent | 8eb80c6816a1f6ea7814acd4f48f07e79891f804 (diff) | |
| parent | f2646b29a6b0a741fc424f88c5ca3dc25fce9369 (diff) | |
Merge pull request #3317 from GrantM11235/simplepwmchannel
embassy-stm32: Add SimplePwmChannel
Diffstat (limited to 'examples/stm32h7/src/bin')
| -rw-r--r-- | examples/stm32h7/src/bin/pwm.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index 1e48ba67b..a1c53fc3f 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -6,7 +6,6 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::gpio::OutputType; | 6 | 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; | ||
| 10 | use embassy_stm32::Config; | 9 | use embassy_stm32::Config; |
| 11 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -37,22 +36,22 @@ async fn main(_spawner: Spawner) { | |||
| 37 | let p = embassy_stm32::init(config); | 36 | let p = embassy_stm32::init(config); |
| 38 | info!("Hello World!"); | 37 | info!("Hello World!"); |
| 39 | 38 | ||
| 40 | let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull); | 39 | let ch1_pin = PwmPin::new_ch1(p.PA6, OutputType::PushPull); |
| 41 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10), Default::default()); | 40 | let mut pwm = SimplePwm::new(p.TIM3, Some(ch1_pin), None, None, None, khz(10), Default::default()); |
| 42 | let max = pwm.get_max_duty(); | 41 | let mut ch1 = pwm.ch1(); |
| 43 | pwm.enable(Channel::Ch1); | 42 | ch1.enable(); |
| 44 | 43 | ||
| 45 | info!("PWM initialized"); | 44 | info!("PWM initialized"); |
| 46 | info!("PWM max duty {}", max); | 45 | info!("PWM max duty {}", ch1.max_duty_cycle()); |
| 47 | 46 | ||
| 48 | loop { | 47 | loop { |
| 49 | pwm.set_duty(Channel::Ch1, 0); | 48 | ch1.set_duty_cycle_fully_off(); |
| 50 | Timer::after_millis(300).await; | 49 | Timer::after_millis(300).await; |
| 51 | pwm.set_duty(Channel::Ch1, max / 4); | 50 | ch1.set_duty_cycle_fraction(1, 4); |
| 52 | Timer::after_millis(300).await; | 51 | Timer::after_millis(300).await; |
| 53 | pwm.set_duty(Channel::Ch1, max / 2); | 52 | ch1.set_duty_cycle_fraction(1, 2); |
| 54 | Timer::after_millis(300).await; | 53 | Timer::after_millis(300).await; |
| 55 | pwm.set_duty(Channel::Ch1, max - 1); | 54 | ch1.set_duty_cycle(ch1.max_duty_cycle() - 1); |
| 56 | Timer::after_millis(300).await; | 55 | Timer::after_millis(300).await; |
| 57 | } | 56 | } |
| 58 | } | 57 | } |
