stm32: centralize gpio reg access in the gpio module.

This commit is contained in:
Dario Nieuwenhuis
2022-02-24 02:36:30 +01:00
parent 29aa51a1ad
commit bf80504ac7
9 changed files with 115 additions and 288 deletions

View File

@ -11,9 +11,7 @@ use embassy_hal_common::unborrow;
use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU};
use crate::gpio::sealed::Pin as __GpioPin;
use crate::gpio::Pin as GpioPin;
use crate::gpio::{sealed::AFType, AnyPin, Speed};
use crate::pac::gpio::vals::Ospeedr;
use crate::pac::{ETH, RCC, SYSCFG};
mod descriptors;
@ -308,15 +306,12 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop
dma.dmaomr().modify(|w| w.set_sr(DmaomrSr::STOPPED));
}
for pin in self.pins.iter_mut() {
// NOTE(unsafe) Exclusive access to the regs
critical_section::with(|_| unsafe {
pin.set_as_analog();
pin.block()
.ospeedr()
.modify(|w| w.set_ospeedr(pin.pin() as usize, Ospeedr::LOWSPEED));
})
}
// NOTE(unsafe) Exclusive access to the regs
critical_section::with(|_| unsafe {
for pin in self.pins.iter_mut() {
pin.set_as_disconnected();
}
})
}
}

View File

@ -304,13 +304,12 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop
dma.dmacrx_cr().modify(|w| w.set_sr(false));
}
for pin in self.pins.iter_mut() {
// NOTE(unsafe) Exclusive access to the regs
critical_section::with(|_| unsafe {
pin.set_as_analog();
pin.set_speed(Speed::Low);
})
}
// NOTE(unsafe) Exclusive access to the regs
critical_section::with(|_| unsafe {
for pin in self.pins.iter_mut() {
pin.set_as_disconnected();
}
})
}
}