Skip to content
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

Implemented InputPin trait for output pins #105

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ macro_rules! gpio {
}
}

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXx<Output<MODE>> {
teskje marked this conversation as resolved.
Show resolved Hide resolved
type Error = Infallible;

fn is_high(&self) -> Result<bool, Self::Error> {
Ok(!self.is_low()?)
}

fn is_low(&self) -> Result<bool, Self::Error> {
// NOTE(unsafe) atomic read with no side effects
Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 })
}
}

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXx<Input<MODE>> {
type Error = Infallible;
Expand Down Expand Up @@ -673,6 +687,20 @@ macro_rules! gpio {
}
}

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXi<Output<MODE>> {
type Error = Infallible;

fn is_high(&self) -> Result<bool, Self::Error> {
Ok(!self.is_low()?)
}

fn is_low(&self) -> Result<bool, Self::Error> {
// NOTE(unsafe) atomic read with no side effects
Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << $i) == 0 })
}
}

#[cfg(feature = "unproven")]
impl<MODE> InputPin for $PXi<Input<MODE>> {
type Error = Infallible;
Expand Down
2 changes: 1 addition & 1 deletion src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct APB1 {
}

impl APB1 {
pub(crate) fn enr(&mut self) -> &rcc::APB1ENR {
teskje marked this conversation as resolved.
Show resolved Hide resolved
pub fn enr(&mut self) -> &rcc::APB1ENR {
// NOTE(unsafe) this proxy grants exclusive access to this register
unsafe { &(*RCC::ptr()).apb1enr }
}
Expand Down