-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpio: Implement and test embedded-hal 1
- Loading branch information
Showing
4 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use super::*; | ||
|
||
use core::convert::Infallible; | ||
use embedded_hal::digital::{ErrorType, InputPin, OutputPin}; | ||
|
||
impl ErrorType for InputGPIO { | ||
type Error = Infallible; | ||
} | ||
|
||
impl InputPin for InputGPIO { | ||
fn is_high(&mut self) -> Result<bool, Infallible> { | ||
Ok(unsafe { gpio_read(self.to_c()) } != 0) | ||
} | ||
|
||
fn is_low(&mut self) -> Result<bool, Infallible> { | ||
Ok(unsafe { gpio_read(self.to_c()) } == 0) | ||
} | ||
} | ||
|
||
impl ErrorType for OutputGPIO { | ||
type Error = Infallible; | ||
} | ||
|
||
impl OutputPin for OutputGPIO { | ||
fn set_high(&mut self) -> Result<(), Infallible> { | ||
unsafe { gpio_set(self.to_c()) }; | ||
Ok(()) | ||
} | ||
|
||
fn set_low(&mut self) -> Result<(), Infallible> { | ||
unsafe { gpio_clear(self.to_c()) }; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ErrorType for InOutGPIO { | ||
type Error = Infallible; | ||
} | ||
|
||
impl InputPin for InOutGPIO { | ||
fn is_high(&mut self) -> Result<bool, Infallible> { | ||
Ok(unsafe { gpio_read(self.to_c()) } != 0) | ||
} | ||
|
||
fn is_low(&mut self) -> Result<bool, Infallible> { | ||
Ok(unsafe { gpio_read(self.to_c()) } == 0) | ||
} | ||
} | ||
|
||
impl OutputPin for InOutGPIO { | ||
fn set_high(&mut self) -> Result<(), Infallible> { | ||
unsafe { gpio_set(self.to_c()) }; | ||
Ok(()) | ||
} | ||
|
||
fn set_low(&mut self) -> Result<(), Infallible> { | ||
unsafe { gpio_clear(self.to_c()) }; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters