Skip to content

Commit

Permalink
Remove AlfFn from PwmBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
little-arhat committed May 2, 2019
1 parent e8cbf7b commit bac857e
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,23 @@
use crate::gpio;
use crate::timer;
use core::marker::PhantomData;
use hal;

/// pwm
pub struct PwmBinding<P: gpio::GPIOPin,
C: timer::TimerChannel,
AF: gpio::AltFnNum>
{
pub struct PwmBinding<P: gpio::GPIOPin, C: timer::TimerChannel> {
pin: P,
channel: C,
_af: PhantomData<AF>,
}

impl<P: gpio::GPIOPin, C: timer::TimerChannel, AF: gpio::AltFnNum>
PwmBinding<P, C, AF>
{
impl<P: gpio::GPIOPin, C: timer::TimerChannel> PwmBinding<P, C> {
/// Consumes PwmBinding returning pin and channel
pub fn release(self) -> (P, C) {
(self.pin, self.channel)
}
}

impl<P: gpio::GPIOPin, C: timer::TimerChannel, AF: gpio::AltFnNum> hal::PwmPin
for PwmBinding<P, C, AF>
impl<P: gpio::GPIOPin, C: timer::TimerChannel> hal::PwmPin
for PwmBinding<P, C>
{
type Duty = u32;
fn disable(&mut self) {
Expand Down Expand Up @@ -77,8 +70,7 @@ macro_rules! pwm {
gpio::$PIN<PT, gpio::AltFn<gpio::$AF, gpio::$PP, SP>>;
type Output = PwmBinding<Self::OutputPin,
timer::$TIM::Channel<timer::$CHN,
timer::Pwm1>,
gpio::$AF>;
timer::Pwm1>>;
fn to_pwm(self,
channel: timer::$TIM::Channel<timer::$CHN, CM>,
sp: SP)
Expand All @@ -89,16 +81,13 @@ macro_rules! pwm {
.alt_fn(gpio::$AF);
let mut channel = channel.mode(timer::Pwm1);
channel.preload($CHPE);
PwmBinding { pin,
channel,
_af: PhantomData }
PwmBinding { pin, channel }
}
}

impl<PT: gpio::PullType, PM: gpio::PinMode, CM: timer::ChMode>
PwmBinding<gpio::$PIN<PT, PM>,
timer::$TIM::Channel<timer::$CHN, CM>,
gpio::$AF>
timer::$TIM::Channel<timer::$CHN, CM>>
{
/// Modify channel's preload
pub fn channel_preload(&mut self, enabled: bool) {
Expand Down

0 comments on commit bac857e

Please sign in to comment.