stm32: exti: update api

This commit is contained in:
xoviat 2021-03-17 20:56:48 -05:00
parent ccf2ea77f0
commit 81d99ff1a0
2 changed files with 7 additions and 26 deletions

View File

@ -22,7 +22,7 @@ pub struct ExtiPin<T: gpio::ExtiPin + WithInterrupt> {
}
impl<T: gpio::ExtiPin + WithInterrupt> ExtiPin<T> {
fn new(mut pin: T, interrupt: T::Interrupt) -> Self {
pub fn new(mut pin: T, interrupt: T::Interrupt) -> Self {
let mut syscfg: SysCfg = unsafe { mem::transmute(()) };
cortex_m::interrupt::free(|_| {

View File

@ -13,34 +13,16 @@ use crate::hal::{
use crate::interrupt;
use crate::pac::EXTI;
pub struct ExtiManager {
syscfg: SYSCFG,
}
impl<'a> ExtiManager {
pub fn new(_exti: Exti, syscfg: SYSCFG) -> Self {
Self { syscfg }
}
pub fn new_pin<T>(&'static self, pin: T, interrupt: T::Interrupt) -> ExtiPin<T>
where
T: PinWithInterrupt,
{
ExtiPin {
pin,
interrupt,
mgr: self,
}
}
}
pub struct ExtiPin<T: PinWithInterrupt> {
pin: T,
interrupt: T::Interrupt,
mgr: &'static ExtiManager,
}
impl<T: PinWithInterrupt + 'static> ExtiPin<T> {
pub fn new(pin: T, interrupt: T::Interrupt) -> ExtiPin<T> {
ExtiPin { pin, interrupt }
}
fn wait_for_edge<'a>(
self: Pin<&'a mut Self>,
edge: TriggerEdge,
@ -57,10 +39,9 @@ impl<T: PinWithInterrupt + 'static> ExtiPin<T> {
let fut = InterruptFuture::new(&mut s.interrupt);
let port = s.pin.port();
let syscfg = &s.mgr.syscfg as *const _ as *mut SYSCFG;
cortex_m::interrupt::free(|_| {
let syscfg = unsafe { &mut *syscfg };
exti.listen_gpio(syscfg, port, line, edge);
let mut syscfg: SYSCFG = unsafe { mem::transmute(()) };
exti.listen_gpio(&mut syscfg, port, line, edge);
});
fut.await;