mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-28 04:40:39 +00:00
Added function to channel_impl to allow full configuration of the pin
This commit is contained in:
parent
0edd45e610
commit
f22649e008
@ -10,7 +10,7 @@ use super::OutputPin;
|
||||
#[cfg(any(lptim_v2a, lptim_v2b))]
|
||||
use super::{channel::Channel, timer::ChannelDirection, Channel1Pin, Channel2Pin};
|
||||
use super::{BasicInstance, Instance};
|
||||
use crate::gpio::{AfType, AnyPin, OutputType, Speed};
|
||||
use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed};
|
||||
use crate::time::Hertz;
|
||||
use crate::Peripheral;
|
||||
|
||||
@ -29,6 +29,15 @@ pub struct PwmPin<'d, T, C> {
|
||||
phantom: PhantomData<(T, C)>,
|
||||
}
|
||||
|
||||
/// PWM pin config
|
||||
///
|
||||
/// This configures the pwm pin settings
|
||||
pub struct PwmPinConfig {
|
||||
pub output_type: OutputType,
|
||||
pub speed: Speed,
|
||||
pub pull: Pull,
|
||||
}
|
||||
|
||||
macro_rules! channel_impl {
|
||||
($new_chx:ident, $channel:ident, $pin_trait:ident) => {
|
||||
impl<'d, T: BasicInstance> PwmPin<'d, T, $channel> {
|
||||
@ -47,6 +56,24 @@ macro_rules! channel_impl {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
#[doc = concat!("Create a new ", stringify!($channel), "_with_config PWM pin instance.")]
|
||||
pub fn $new_chx_with_config(
|
||||
pin: impl Peripheral<P = impl $pin_trait<T>> + 'd,
|
||||
pin_config: PwmPinConfig,
|
||||
) -> Self {
|
||||
into_ref!(pin);
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
|
||||
);
|
||||
});
|
||||
PwmPin {
|
||||
_pin: pin.map_into(),
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
|
||||
|
||||
use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer};
|
||||
use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits};
|
||||
use crate::gpio::{AfType, AnyPin, OutputType, Speed};
|
||||
use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed};
|
||||
use crate::time::Hertz;
|
||||
use crate::Peripheral;
|
||||
|
||||
@ -28,6 +28,15 @@ pub struct PwmPin<'d, T, C> {
|
||||
phantom: PhantomData<(T, C)>,
|
||||
}
|
||||
|
||||
/// PWM pin config
|
||||
///
|
||||
/// This configures the pwm pin settings
|
||||
pub struct PwmPinConfig {
|
||||
pub output_type: OutputType,
|
||||
pub speed: Speed,
|
||||
pub pull: Pull,
|
||||
}
|
||||
|
||||
macro_rules! channel_impl {
|
||||
($new_chx:ident, $channel:ident, $pin_trait:ident) => {
|
||||
impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> {
|
||||
@ -43,6 +52,24 @@ macro_rules! channel_impl {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
#[doc = concat!("Create a new ", stringify!($channel), "_with_config PWM pin instance.")]
|
||||
pub fn $new_chx_with_config(
|
||||
pin: impl Peripheral<P = impl $pin_trait<T>> + 'd,
|
||||
pin_config: PwmPinConfig,
|
||||
) -> Self {
|
||||
into_ref!(pin);
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
|
||||
);
|
||||
});
|
||||
PwmPin {
|
||||
_pin: pin.map_into(),
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user