Skip to content

Commit

Permalink
Change internal_pull_{up,down}() to "consuming self, returning Self".
Browse files Browse the repository at this point in the history
This enables us to write ergonomic constructs like

```
let pin = gpiob
	.into_alternate()
	.internal_pull_up(true)
	.set_open_drain();
```
  • Loading branch information
Windfisch committed Dec 9, 2021
1 parent 510d135 commit c1a2528
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,16 @@ impl<MODE, const P: char, const N: u8> Pin<Output<MODE>, P, N> {

impl<const P: char, const N: u8> Pin<Output<OpenDrain>, P, N> {
/// Enables / disables the internal pull up
pub fn internal_pull_up(&mut self, on: bool) {
pub fn internal_pull_up(self, on: bool) -> Self {
let offset = 2 * { N };
let value = if on { 0b01 } else { 0b00 };
unsafe {
(*Gpio::<P>::ptr())
.pupdr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset)))
};

self
}

/// Enables / disables the internal pull down
Expand Down

0 comments on commit c1a2528

Please sign in to comment.