-
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.
Merges: #73
- Loading branch information
Showing
17 changed files
with
456 additions
and
96 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use super::*; | ||
|
||
use embedded_hal_0_2::digital::v2::{InputPin, OutputPin, ToggleableOutputPin}; | ||
|
||
impl InputPin for InputGPIO { | ||
type Error = Never; | ||
|
||
fn is_high(&self) -> Result<bool, Never> { | ||
Ok(unsafe { gpio_read(self.to_c()) } != 0) | ||
} | ||
|
||
fn is_low(&self) -> Result<bool, Never> { | ||
Ok(unsafe { gpio_read(self.to_c()) } == 0) | ||
} | ||
} | ||
|
||
impl OutputPin for OutputGPIO { | ||
type Error = Never; | ||
|
||
fn set_high(&mut self) -> Result<(), Never> { | ||
unsafe { gpio_set(self.to_c()) }; | ||
Ok(()) | ||
} | ||
|
||
fn set_low(&mut self) -> Result<(), Never> { | ||
unsafe { gpio_clear(self.to_c()) }; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ToggleableOutputPin for OutputGPIO { | ||
type Error = Never; | ||
|
||
fn toggle(&mut self) -> Result<(), Never> { | ||
unsafe { gpio_toggle(self.to_c()) }; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl InputPin for InOutGPIO { | ||
type Error = Never; | ||
|
||
fn is_high(&self) -> Result<bool, Never> { | ||
Ok(unsafe { gpio_read(self.to_c()) } != 0) | ||
} | ||
|
||
fn is_low(&self) -> Result<bool, Never> { | ||
Ok(unsafe { gpio_read(self.to_c()) } == 0) | ||
} | ||
} | ||
|
||
impl OutputPin for InOutGPIO { | ||
type Error = Never; | ||
|
||
fn set_high(&mut self) -> Result<(), Never> { | ||
unsafe { gpio_set(self.to_c()) }; | ||
Ok(()) | ||
} | ||
|
||
fn set_low(&mut self) -> Result<(), Never> { | ||
unsafe { gpio_clear(self.to_c()) }; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ToggleableOutputPin for InOutGPIO { | ||
type Error = Never; | ||
|
||
fn toggle(&mut self) -> Result<(), Never> { | ||
unsafe { gpio_toggle(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use super::*; | ||
|
||
use core::convert::Infallible; | ||
use embedded_hal::digital::{ErrorType, InputPin, OutputPin, PinState}; | ||
|
||
impl ErrorType for InputGPIO { | ||
type Error = Infallible; | ||
} | ||
|
||
impl InputPin for InputGPIO { | ||
fn is_high(&mut self) -> Result<bool, Infallible> { | ||
Ok(InputGPIO::is_high(self)) | ||
} | ||
|
||
fn is_low(&mut self) -> Result<bool, Infallible> { | ||
Ok(InputGPIO::is_low(self)) | ||
} | ||
} | ||
|
||
impl ErrorType for OutputGPIO { | ||
type Error = Infallible; | ||
} | ||
|
||
impl OutputPin for OutputGPIO { | ||
fn set_high(&mut self) -> Result<(), Infallible> { | ||
Ok(OutputGPIO::set_high(self)) | ||
} | ||
|
||
fn set_low(&mut self) -> Result<(), Infallible> { | ||
Ok(OutputGPIO::set_low(self)) | ||
} | ||
|
||
fn set_state(&mut self, state: PinState) -> Result<(), Infallible> { | ||
Ok(OutputGPIO::set_state(self, state.into())) | ||
} | ||
} | ||
|
||
impl ErrorType for InOutGPIO { | ||
type Error = Infallible; | ||
} | ||
|
||
impl InputPin for InOutGPIO { | ||
fn is_high(&mut self) -> Result<bool, Infallible> { | ||
Ok(InOutGPIO::is_high(self)) | ||
} | ||
|
||
fn is_low(&mut self) -> Result<bool, Infallible> { | ||
Ok(InOutGPIO::is_low(self)) | ||
} | ||
} | ||
|
||
impl OutputPin for InOutGPIO { | ||
fn set_high(&mut self) -> Result<(), Infallible> { | ||
Ok(InOutGPIO::set_high(self)) | ||
} | ||
|
||
fn set_low(&mut self) -> Result<(), Infallible> { | ||
Ok(InOutGPIO::set_low(self)) | ||
} | ||
|
||
fn set_state(&mut self, state: PinState) -> Result<(), Infallible> { | ||
Ok(InOutGPIO::set_state(self, state.into())) | ||
} | ||
} |
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
Oops, something went wrong.