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/stm32g0 | |
| parent | 8eb80c6816a1f6ea7814acd4f48f07e79891f804 (diff) | |
| parent | f2646b29a6b0a741fc424f88c5ca3dc25fce9369 (diff) | |
Merge pull request #3317 from GrantM11235/simplepwmchannel
embassy-stm32: Add SimplePwmChannel
Diffstat (limited to 'examples/stm32g0')
| -rw-r--r-- | examples/stm32g0/src/bin/input_capture.rs | 8 | ||||
| -rw-r--r-- | examples/stm32g0/src/bin/pwm_input.rs | 10 |
2 files changed, 8 insertions, 10 deletions
diff --git a/examples/stm32g0/src/bin/input_capture.rs b/examples/stm32g0/src/bin/input_capture.rs index 69fdae96d..bc814cb13 100644 --- a/examples/stm32g0/src/bin/input_capture.rs +++ b/examples/stm32g0/src/bin/input_capture.rs | |||
| @@ -47,10 +47,10 @@ async fn main(spawner: Spawner) { | |||
| 47 | unwrap!(spawner.spawn(blinky(p.PB1))); | 47 | unwrap!(spawner.spawn(blinky(p.PB1))); |
| 48 | 48 | ||
| 49 | // Connect PB1 and PA8 with a 1k Ohm resistor | 49 | // Connect PB1 and PA8 with a 1k Ohm resistor |
| 50 | let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull); | 50 | let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull); |
| 51 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(1), Default::default()); | 51 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default()); |
| 52 | pwm.enable(Channel::Ch1); | 52 | pwm.ch1().enable(); |
| 53 | pwm.set_duty(Channel::Ch1, 50); | 53 | pwm.ch1().set_duty_cycle(50); |
| 54 | 54 | ||
| 55 | let ch1 = CapturePin::new_ch1(p.PA0, Pull::None); | 55 | let ch1 = CapturePin::new_ch1(p.PA0, Pull::None); |
| 56 | let mut ic = InputCapture::new(p.TIM2, Some(ch1), None, None, None, Irqs, khz(1000), Default::default()); | 56 | let mut ic = InputCapture::new(p.TIM2, Some(ch1), None, None, None, Irqs, khz(1000), Default::default()); |
diff --git a/examples/stm32g0/src/bin/pwm_input.rs b/examples/stm32g0/src/bin/pwm_input.rs index 152ecda86..db9cf4f8a 100644 --- a/examples/stm32g0/src/bin/pwm_input.rs +++ b/examples/stm32g0/src/bin/pwm_input.rs | |||
| @@ -14,7 +14,6 @@ use embassy_stm32::gpio::{Level, Output, OutputType, Pull, Speed}; | |||
| 14 | use embassy_stm32::time::khz; | 14 | use embassy_stm32::time::khz; |
| 15 | use embassy_stm32::timer::pwm_input::PwmInput; | 15 | use embassy_stm32::timer::pwm_input::PwmInput; |
| 16 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 16 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 17 | use embassy_stm32::timer::Channel; | ||
| 18 | use embassy_stm32::{bind_interrupts, peripherals, timer}; | 17 | use embassy_stm32::{bind_interrupts, peripherals, timer}; |
| 19 | use embassy_time::Timer; | 18 | use embassy_time::Timer; |
| 20 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -43,11 +42,10 @@ async fn main(spawner: Spawner) { | |||
| 43 | 42 | ||
| 44 | unwrap!(spawner.spawn(blinky(p.PB1))); | 43 | unwrap!(spawner.spawn(blinky(p.PB1))); |
| 45 | // Connect PA8 and PA6 with a 1k Ohm resistor | 44 | // Connect PA8 and PA6 with a 1k Ohm resistor |
| 46 | let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull); | 45 | let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull); |
| 47 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(1), Default::default()); | 46 | let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default()); |
| 48 | let max = pwm.get_max_duty(); | 47 | pwm.ch1().set_duty_cycle_fraction(1, 4); |
| 49 | pwm.set_duty(Channel::Ch1, max / 4); | 48 | pwm.ch1().enable(); |
| 50 | pwm.enable(Channel::Ch1); | ||
| 51 | 49 | ||
| 52 | let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000)); | 50 | let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000)); |
| 53 | pwm_input.enable(); | 51 | pwm_input.enable(); |
