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

Implement IoPin #256

Merged
merged 3 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ features = ["stm32h743v", "rt", "quadspi", "sdmmc", "fmc", "usb_hs", "rtc", "eth
targets = ["thumbv7em-none-eabihf"]

[dependencies]
embedded-hal = "0.2.4"
embedded-hal = "0.2.6"
embedded-dma = "0.1.2"
cortex-m = "^0.7.1"
stm32h7 = "^0.14.0"
Expand Down
42 changes: 41 additions & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ macro_rules! gpio {
pub mod $gpiox {
use core::marker::PhantomData;

use embedded_hal::digital::v2::{InputPin, OutputPin,
use embedded_hal::digital::v2::{InputPin, OutputPin, IoPin, PinState,
StatefulOutputPin, toggleable};

use crate::rcc::{rec, ResetEnable};
Expand Down Expand Up @@ -767,6 +767,46 @@ macro_rules! gpio {
}
}

impl IoPin<Self, Self>
for $PXi<Output<OpenDrain>>
{
type Error = Never;
fn into_input_pin(self) -> Result<Self, Never> {
Ok(self)
}
fn into_output_pin(mut self, state: PinState) -> Result<Self, Never> {
self.set_state(state).unwrap(); // Infallible
Ok(self)
}
}

impl IoPin<$PXi<Input<Floating>>, Self>
for $PXi<Output<PushPull>>
{
type Error = Never;
fn into_input_pin(self) -> Result<$PXi<Input<Floating>>, Never> {
Ok(self.into_floating_input())
}
fn into_output_pin(mut self, state: PinState) -> Result<Self, Never> {
self.set_state(state).unwrap(); // Infallible
Ok(self)
}
}

impl IoPin<Self, $PXi<Output<PushPull>>>
for $PXi<Input<Floating>>
{
type Error = Never;
fn into_input_pin(self) -> Result<Self, Never> {
Ok(self)
}
fn into_output_pin(self, state: PinState) -> Result<$PXi<Output<PushPull>>, Never> {
let mut pin = self.into_push_pull_output();
pin.set_state(state).unwrap(); // Infallible
Ok(pin)
}
}

impl<MODE> ExtiPin for $PXi<Input<MODE>> {
/// Configure EXTI Line $i to trigger from this pin.
fn make_interrupt_source(&mut self, syscfg: &mut SYSCFG) {
Expand Down