use super::Channel;
use crate::iomuxc;
pub struct Output<P> {
pin: P,
channel: Channel,
}
impl<P, const N: u8, const M: u8> Output<P>
where
P: iomuxc::flexpwm::Pin<
Module = iomuxc::consts::Const<N>,
Output = iomuxc::flexpwm::A,
Submodule = iomuxc::consts::Const<M>,
>,
{
pub fn new_a(pin: P) -> Self {
Output::new(pin, Channel::A)
}
}
impl<P, const N: u8, const M: u8> Output<P>
where
P: iomuxc::flexpwm::Pin<
Module = iomuxc::consts::Const<N>,
Output = iomuxc::flexpwm::B,
Submodule = iomuxc::consts::Const<M>,
>,
{
pub fn new_b(pin: P) -> Self {
Output::new(pin, Channel::B)
}
}
impl<P, const N: u8, const M: u8> Output<P>
where
P: iomuxc::flexpwm::Pin<
Module = iomuxc::consts::Const<N>,
Submodule = iomuxc::consts::Const<M>,
>,
{
const MASK: super::Mask = super::Submodule::<N, M>::MASK;
fn new(mut pin: P, channel: Channel) -> Self {
iomuxc::flexpwm::prepare(&mut pin);
Output { pin, channel }
}
pub fn release(self, pwm: &mut super::Pwm<N>) -> P {
self.set_output_enable(pwm, false);
self.pin
}
pub fn output_enable(&self, pwm: &super::Pwm<N>) -> bool {
pwm.output_enable(self.channel).intersects(Self::MASK)
}
pub fn set_output_enable(&self, pwm: &mut super::Pwm<N>, enable: bool) {
pwm.rmw_outen(self.channel, Self::MASK, enable);
}
pub fn turn_on(&self, sm: &super::Submodule<N, M>) -> i16 {
sm.turn_on(self.channel)
}
pub fn turn_off(&self, sm: &super::Submodule<N, M>) -> i16 {
sm.turn_off(self.channel)
}
pub fn set_turn_on(&self, sm: &super::Submodule<N, M>, compare: i16) {
sm.set_turn_on(self.channel, compare)
}
pub fn set_turn_off(&self, sm: &super::Submodule<N, M>, compare: i16) {
sm.set_turn_off(self.channel, compare)
}
}