Skip to content

Swap PWM channel argument to pass by reference #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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