Skip to content

Commit

Permalink
Add internal_pull_down() method
Browse files Browse the repository at this point in the history
For symmetry with internal_pull_up().
  • Loading branch information
Windfisch committed Dec 9, 2021
1 parent d1123d8 commit 510d135
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,19 @@ impl<const P: char, const N: u8> Pin<Output<OpenDrain>, P, N> {
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset)))
};
}

/// Enables / disables the internal pull down
pub fn internal_pull_down(self, on: bool) -> Self {
let offset = 2 * { N };
let value = if on { 0b10 } else { 0b00 };
unsafe {
(*Gpio::<P>::ptr())
.pupdr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset)))
};

self
}
}

impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N> {
Expand Down Expand Up @@ -337,6 +350,19 @@ impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N>

self
}

/// Enables / disables the internal pull down
pub fn internal_pull_down(self, on: bool) -> Self {
let offset = 2 * { N };
let value = if on { 0b10 } else { 0b00 };
unsafe {
(*Gpio::<P>::ptr())
.pupdr
.modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset)))
};

self
}
}

impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N> {
Expand Down

0 comments on commit 510d135

Please sign in to comment.