Skip to content

Commit

Permalink
Merge #246
Browse files Browse the repository at this point in the history
246: Swap PWM channel argument to pass by reference r=eldruin a=ryankurte

Swap PWM channel arguments to be passed by reference to alleviate need for cloning / reconstructing channel objects per #244

Co-authored-by: ryan <ryan@kurte.nz>
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
  • Loading branch information
3 people authored Mar 11, 2021
2 parents eae6c99 + 1c6869d commit d3ca28e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
- Swap PWM channel arguments to references

## [v1.0.0-alpha.4] - 2020-11-11

Expand Down
20 changes: 10 additions & 10 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
/// let max_duty = pwm.try_get_max_duty().unwrap();
///
/// // brightest LED
/// pwm.try_set_duty(Channel::_1, max_duty).unwrap();
/// pwm.try_set_duty(&Channel::_1, max_duty).unwrap();
///
/// // dimmer LED
/// pwm.try_set_duty(Channel::_2, max_duty / 4).unwrap();
/// pwm.try_set_duty(&Channel::_2, max_duty / 4).unwrap();
/// }
///
/// # use core::convert::Infallible;
Expand All @@ -39,11 +39,11 @@
/// # type Channel = Channel;
/// # type Time = KiloHertz;
/// # type Duty = u16;
/// # fn try_disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
/// # fn try_enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
/// # fn try_get_duty(&self, _: Channel) -> Result<u16, Self::Error> { unimplemented!() }
/// # fn try_disable(&mut self, _: &Channel) -> Result<(), Self::Error> { unimplemented!() }
/// # fn try_enable(&mut self, _: &Channel) -> Result<(), Self::Error> { unimplemented!() }
/// # fn try_get_duty(&self, _: &Channel) -> Result<u16, Self::Error> { unimplemented!() }
/// # fn try_get_max_duty(&self) -> Result<u16, Self::Error> { Ok(0) }
/// # fn try_set_duty(&mut self, _: Channel, _: u16) -> Result<(), Self::Error> { Ok(()) }
/// # fn try_set_duty(&mut self, _: &Channel, _: u16) -> Result<(), Self::Error> { Ok(()) }
/// # fn try_get_period(&self) -> Result<KiloHertz, Self::Error> { unimplemented!() }
/// # fn try_set_period<T>(&mut self, _: T) -> Result<(), Self::Error> where T: Into<KiloHertz> { Ok(()) }
/// # }
Expand All @@ -70,10 +70,10 @@ pub trait Pwm {
type Duty;

/// Disables a PWM `channel`
fn try_disable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
fn try_disable(&mut self, channel: &Self::Channel) -> Result<(), Self::Error>;

/// Enables a PWM `channel`
fn try_enable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
fn try_enable(&mut self, channel: &Self::Channel) -> Result<(), Self::Error>;

/// Returns the current PWM period
fn try_get_period(&self) -> Result<Self::Time, Self::Error>;
Expand All @@ -82,13 +82,13 @@ pub trait Pwm {
///
/// While the pin is transitioning to the new duty cycle after a `try_set_duty` call, this may
/// return the old or the new duty cycle depending on the implementation.
fn try_get_duty(&self, channel: Self::Channel) -> Result<Self::Duty, Self::Error>;
fn try_get_duty(&self, channel: &Self::Channel) -> Result<Self::Duty, Self::Error>;

/// Returns the maximum duty cycle value
fn try_get_max_duty(&self) -> Result<Self::Duty, Self::Error>;

/// Sets a new duty cycle
fn try_set_duty(&mut self, channel: Self::Channel, duty: Self::Duty)
fn try_set_duty(&mut self, channel: &Self::Channel, duty: Self::Duty)
-> Result<(), Self::Error>;

/// Sets a new PWM period
Expand Down

0 comments on commit d3ca28e

Please sign in to comment.