From 2cbb8a7ece70f5d489b8527f80de708693d9f55b Mon Sep 17 00:00:00 2001 From: Tobias Pisani Date: Mon, 11 Oct 2021 22:50:33 +0200 Subject: [PATCH] Add AFType::Input for input configurations. --- embassy-stm32/src/gpio.rs | 12 ++++++++---- embassy-stm32/src/spi/v1.rs | 18 ++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 7c331fbb4..246cdb041 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -354,9 +354,7 @@ pub(crate) mod sealed { #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum AFType { - // InputFloating, - // InputPullUp, - // InputPullDown, + Input, OutputPushPull, OutputOpenDrain, } @@ -405,7 +403,12 @@ pub(crate) mod sealed { let n = self._pin() as usize; let crlh = if n < 8 { 0 } else { 1 }; match af_type { - // TODO: Do we need to configure input AF pins differently? + AFType::Input => { + r.cr(crlh).modify(|w| { + w.set_mode(n % 8, vals::Mode::INPUT); + w.set_cnf(n % 8, vals::Cnf::PUSHPULL); + }); + } AFType::OutputPushPull => { r.cr(crlh).modify(|w| { w.set_mode(n % 8, vals::Mode::OUTPUT50); @@ -428,6 +431,7 @@ pub(crate) mod sealed { .afr(pin / 8) .modify(|w| w.set_afr(pin % 8, vals::Afr(af_num))); match af_type { + AFType::Input => {} AFType::OutputPushPull => { block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) } diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index 6f8f8afb6..d4fa888c9 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs @@ -1,13 +1,9 @@ #![macro_use] use crate::dma::NoDma; -use crate::gpio::{ - sealed::{ - AFType::{OutputOpenDrain, OutputPushPull}, - Pin, - }, - AnyPin, NoPin, -}; +use crate::gpio::sealed::AFType; +use crate::gpio::sealed::Pin; +use crate::gpio::{AnyPin, NoPin}; use crate::pac::spi; use crate::peripherals; use crate::spi::{ @@ -87,9 +83,11 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { let miso = miso.degrade_optional(); unsafe { - sck.as_ref().map(|x| x.set_as_af(sck_af, OutputPushPull)); - mosi.as_ref().map(|x| x.set_as_af(mosi_af, OutputPushPull)); - miso.as_ref().map(|x| x.set_as_af(miso_af, OutputOpenDrain)); + sck.as_ref() + .map(|x| x.set_as_af(sck_af, AFType::OutputPushPull)); + mosi.as_ref() + .map(|x| x.set_as_af(mosi_af, AFType::OutputPushPull)); + miso.as_ref().map(|x| x.set_as_af(miso_af, AFType::Input)); } unsafe {