Skip to content

Commit d3ca28e

Browse files
bors[bot]ryankurteeldruin
authored
Merge #246
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 <[email protected]> Co-authored-by: Diego Barrios Romero <[email protected]>
2 parents eae6c99 + 1c6869d commit d3ca28e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
### Changed
13+
- Swap PWM channel arguments to references
1314

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

src/pwm.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
/// let max_duty = pwm.try_get_max_duty().unwrap();
2323
///
2424
/// // brightest LED
25-
/// pwm.try_set_duty(Channel::_1, max_duty).unwrap();
25+
/// pwm.try_set_duty(&Channel::_1, max_duty).unwrap();
2626
///
2727
/// // dimmer LED
28-
/// pwm.try_set_duty(Channel::_2, max_duty / 4).unwrap();
28+
/// pwm.try_set_duty(&Channel::_2, max_duty / 4).unwrap();
2929
/// }
3030
///
3131
/// # use core::convert::Infallible;
@@ -39,11 +39,11 @@
3939
/// # type Channel = Channel;
4040
/// # type Time = KiloHertz;
4141
/// # type Duty = u16;
42-
/// # fn try_disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
43-
/// # fn try_enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
44-
/// # fn try_get_duty(&self, _: Channel) -> Result<u16, Self::Error> { unimplemented!() }
42+
/// # fn try_disable(&mut self, _: &Channel) -> Result<(), Self::Error> { unimplemented!() }
43+
/// # fn try_enable(&mut self, _: &Channel) -> Result<(), Self::Error> { unimplemented!() }
44+
/// # fn try_get_duty(&self, _: &Channel) -> Result<u16, Self::Error> { unimplemented!() }
4545
/// # fn try_get_max_duty(&self) -> Result<u16, Self::Error> { Ok(0) }
46-
/// # fn try_set_duty(&mut self, _: Channel, _: u16) -> Result<(), Self::Error> { Ok(()) }
46+
/// # fn try_set_duty(&mut self, _: &Channel, _: u16) -> Result<(), Self::Error> { Ok(()) }
4747
/// # fn try_get_period(&self) -> Result<KiloHertz, Self::Error> { unimplemented!() }
4848
/// # fn try_set_period<T>(&mut self, _: T) -> Result<(), Self::Error> where T: Into<KiloHertz> { Ok(()) }
4949
/// # }
@@ -70,10 +70,10 @@ pub trait Pwm {
7070
type Duty;
7171

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

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

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

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

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

9494
/// Sets a new PWM period

0 commit comments

Comments
 (0)