diff --git a/examples/mfrc522.rs b/examples/mfrc522.rs index cbb57e76..cddc2555 100644 --- a/examples/mfrc522.rs +++ b/examples/mfrc522.rs @@ -32,9 +32,9 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); - let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); + let sck = gpioa.pa5; let miso = gpioa.pa6; - let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); + let mosi = gpioa.pa7; let spi = Spi::new( dp.SPI1, (sck, miso, mosi, &mut afio.mapr), diff --git a/src/gpio.rs b/src/gpio.rs index 69e2d8f0..6718f45d 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -648,6 +648,40 @@ impl Pin { self } } +impl Pin { + /// Set the internal pull-up and pull-down resistor + pub fn set_internal_resistor(&mut self, pull: Pull) { + match pull { + Pull::None => { + let gpio = unsafe { &(*gpiox::

()) }; + match N { + 0..=7 => { + gpio.crl().modify(|_, w| w.cnf(N).variant(Cnf::OpenDrain)); + } + 8..=15 => { + gpio.crh() + .modify(|_, w| unsafe { w.cnf(N - 16).bits(Cnf::OpenDrain as u8) }); + } + _ => unreachable!(), + } + } + Pull::Up => { + self.mode::(); + self._set_pull_up() + } + Pull::Down => { + self.mode::(); + self._set_pull_down() + } + } + } + + /// Set the internal pull-up and pull-down resistor + pub fn internal_resistor(mut self, pull: Pull) -> Self { + self.set_internal_resistor(pull); + self + } +} impl Pin> { #[inline] @@ -787,9 +821,7 @@ macro_rules! impl_temp_output { &mut self, _cr: &mut ::Cr, mut f: impl FnMut(&mut Pin), - ) where - Pin: HL, - { + ) { self.mode::<$mode>(); let mut temp = Pin::::new(); f(&mut temp); @@ -807,9 +839,7 @@ macro_rules! impl_temp_output { _cr: &mut ::Cr, state: PinState, mut f: impl FnMut(&mut Pin), - ) where - Pin: HL, - { + ) { self._set_state(state); self.mode::<$mode>(); let mut temp = Pin::::new(); @@ -826,9 +856,7 @@ macro_rules! impl_temp_input { &mut self, _cr: &mut ::Cr, mut f: impl FnMut(&mut Pin), - ) - where Pin::: HL - { + ) { self.mode::<$mode>(); let mut temp = Pin::::new() $(.$pull())?; f(&mut temp); @@ -975,10 +1003,7 @@ impl PinMode for Alternate { const CNF: Cnf = Cnf::AltOpenDrain; } -impl Pin -where - Self: HL, -{ +impl Pin { fn mode(&mut self) { let gpio = unsafe { &(*gpiox::

()) }; @@ -996,7 +1021,12 @@ where _ => unreachable!(), } } +} +impl Pin +where + Self: HL, +{ #[inline] pub(crate) fn into_mode( mut self,