mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-27 12:20:37 +00:00
Merge pull request #4323 from phycrax/rename_pwminput_new
embassy-stm32: Rename PWM Input constructors, add warning on usable timer peripherals
This commit is contained in:
commit
93a8435535
@ -7,6 +7,10 @@ use crate::time::Hertz;
|
||||
use crate::Peri;
|
||||
|
||||
/// PWM Input driver.
|
||||
///
|
||||
/// Only works with CH1 or CH2
|
||||
/// Note: Not all timer peripherals are supported
|
||||
/// Double check your chips reference manual
|
||||
pub struct PwmInput<'d, T: GeneralInstance4Channel> {
|
||||
channel: Channel,
|
||||
inner: Timer<'d, T>,
|
||||
@ -14,14 +18,14 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> {
|
||||
|
||||
impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
|
||||
/// Create a new PWM input driver.
|
||||
pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1>>, pull: Pull, freq: Hertz) -> Self {
|
||||
pub fn new_ch1(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1>>, pull: Pull, freq: Hertz) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
|
||||
Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2)
|
||||
}
|
||||
|
||||
/// Create a new PWM input driver.
|
||||
pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2>>, pull: Pull, freq: Hertz) -> Self {
|
||||
pub fn new_ch2(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2>>, pull: Pull, freq: Hertz) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
|
||||
Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1)
|
||||
@ -37,6 +41,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
|
||||
|
||||
// Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6
|
||||
// or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode
|
||||
// or ST RM0440 (STM32G4) chapter 30.4.8 PWM input mode
|
||||
inner.set_input_ti_selection(ch1, InputTISelection::Normal);
|
||||
inner.set_input_capture_mode(ch1, InputCaptureMode::Rising);
|
||||
|
||||
|
@ -38,7 +38,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
unwrap!(spawner.spawn(blinky(p.PC13)));
|
||||
|
||||
let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(10));
|
||||
let mut pwm_input = PwmInput::new_ch1(p.TIM2, p.PA0, Pull::None, khz(10));
|
||||
pwm_input.enable();
|
||||
|
||||
loop {
|
||||
|
@ -38,7 +38,7 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
unwrap!(spawner.spawn(blinky(p.PB2)));
|
||||
|
||||
let mut pwm_input = PwmInput::new(p.TIM3, p.PA6, Pull::None, khz(10));
|
||||
let mut pwm_input = PwmInput::new_ch1(p.TIM3, p.PA6, Pull::None, khz(10));
|
||||
pwm_input.enable();
|
||||
|
||||
loop {
|
||||
|
@ -47,7 +47,7 @@ async fn main(spawner: Spawner) {
|
||||
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));
|
||||
let mut pwm_input = PwmInput::new_ch1(p.TIM2, p.PA0, Pull::None, khz(1000));
|
||||
pwm_input.enable();
|
||||
|
||||
loop {
|
||||
|
Loading…
x
Reference in New Issue
Block a user