Merge pull request #3317 from GrantM11235/simplepwmchannel

embassy-stm32: Add SimplePwmChannel
This commit is contained in:
Ulf Lilleengen
2024-10-23 10:30:13 +00:00
committed by GitHub
9 changed files with 269 additions and 90 deletions

View File

@@ -47,10 +47,10 @@ async fn main(spawner: Spawner) {
unwrap!(spawner.spawn(blinky(p.PB1)));
// Connect PB1 and PA8 with a 1k Ohm resistor
let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(1), Default::default());
pwm.enable(Channel::Ch1);
pwm.set_duty(Channel::Ch1, 50);
let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default());
pwm.ch1().enable();
pwm.ch1().set_duty_cycle(50);
let ch1 = CapturePin::new_ch1(p.PA0, Pull::None);
let mut ic = InputCapture::new(p.TIM2, Some(ch1), None, None, None, Irqs, khz(1000), Default::default());

View File

@@ -14,7 +14,6 @@ use embassy_stm32::gpio::{Level, Output, OutputType, Pull, Speed};
use embassy_stm32::time::khz;
use embassy_stm32::timer::pwm_input::PwmInput;
use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
use embassy_stm32::timer::Channel;
use embassy_stm32::{bind_interrupts, peripherals, timer};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
@@ -43,11 +42,10 @@ async fn main(spawner: Spawner) {
unwrap!(spawner.spawn(blinky(p.PB1)));
// Connect PA8 and PA6 with a 1k Ohm resistor
let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(1), Default::default());
let max = pwm.get_max_duty();
pwm.set_duty(Channel::Ch1, max / 4);
pwm.enable(Channel::Ch1);
let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default());
pwm.ch1().set_duty_cycle_fraction(1, 4);
pwm.ch1().enable();
let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000));
pwm_input.enable();