Merge pull request #74 from michaelbeaumont/deref-stm32f4

embassy-stm32f4: Add embedded_hal::digital::v2::* for ExtiPin
This commit is contained in:
Dario Nieuwenhuis 2021-03-14 23:47:56 +01:00 committed by GitHub
commit e44079492c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ use crate::hal::gpio;
use crate::hal::gpio::{Edge, ExtiPin as HalExtiPin}; use crate::hal::gpio::{Edge, ExtiPin as HalExtiPin};
use crate::hal::syscfg::SysCfg; use crate::hal::syscfg::SysCfg;
use crate::pac::EXTI; use crate::pac::EXTI;
use embedded_hal::digital::v2 as digital;
use crate::interrupt; use crate::interrupt;
@ -42,6 +43,52 @@ pub struct ExtiPin<T: HalExtiPin + WithInterrupt> {
_mgr: &'static ExtiManager, _mgr: &'static ExtiManager,
} }
impl<T: HalExtiPin + WithInterrupt + digital::OutputPin> digital::OutputPin for ExtiPin<T> {
type Error = T::Error;
fn set_low(&mut self) -> Result<(), Self::Error> {
self.pin.set_low()
}
fn set_high(&mut self) -> Result<(), Self::Error> {
self.pin.set_high()
}
}
impl<T: HalExtiPin + WithInterrupt + digital::StatefulOutputPin> digital::StatefulOutputPin
for ExtiPin<T>
{
fn is_set_low(&self) -> Result<bool, Self::Error> {
self.pin.is_set_low()
}
fn is_set_high(&self) -> Result<bool, Self::Error> {
self.pin.is_set_high()
}
}
impl<T: HalExtiPin + WithInterrupt + digital::ToggleableOutputPin> digital::ToggleableOutputPin
for ExtiPin<T>
{
type Error = T::Error;
fn toggle(&mut self) -> Result<(), Self::Error> {
self.pin.toggle()
}
}
impl<T: HalExtiPin + WithInterrupt + digital::InputPin> digital::InputPin for ExtiPin<T> {
type Error = T::Error;
fn is_high(&self) -> Result<bool, Self::Error> {
self.pin.is_high()
}
fn is_low(&self) -> Result<bool, Self::Error> {
self.pin.is_low()
}
}
/* /*
Irq Handler Description Irq Handler Description
EXTI0_IRQn EXTI0_IRQHandler Handler for pins connected to line 0 EXTI0_IRQn EXTI0_IRQHandler Handler for pins connected to line 0