diff options
| author | Tobias Pisani <[email protected]> | 2021-10-11 22:50:33 +0200 |
|---|---|---|
| committer | Tobias Pisani <[email protected]> | 2021-10-11 22:57:21 +0200 |
| commit | 2cbb8a7ece70f5d489b8527f80de708693d9f55b (patch) | |
| tree | b16308bc4d772ea308c103f65aeaf73510ba1fec | |
| parent | 259e84e68e32894a77b6050ee7cbdc9211865447 (diff) | |
Add AFType::Input for input configurations.
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 12 | ||||
| -rw-r--r-- | 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 { | |||
| 354 | #[derive(Debug)] | 354 | #[derive(Debug)] |
| 355 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 355 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 356 | pub enum AFType { | 356 | pub enum AFType { |
| 357 | // InputFloating, | 357 | Input, |
| 358 | // InputPullUp, | ||
| 359 | // InputPullDown, | ||
| 360 | OutputPushPull, | 358 | OutputPushPull, |
| 361 | OutputOpenDrain, | 359 | OutputOpenDrain, |
| 362 | } | 360 | } |
| @@ -405,7 +403,12 @@ pub(crate) mod sealed { | |||
| 405 | let n = self._pin() as usize; | 403 | let n = self._pin() as usize; |
| 406 | let crlh = if n < 8 { 0 } else { 1 }; | 404 | let crlh = if n < 8 { 0 } else { 1 }; |
| 407 | match af_type { | 405 | match af_type { |
| 408 | // TODO: Do we need to configure input AF pins differently? | 406 | AFType::Input => { |
| 407 | r.cr(crlh).modify(|w| { | ||
| 408 | w.set_mode(n % 8, vals::Mode::INPUT); | ||
| 409 | w.set_cnf(n % 8, vals::Cnf::PUSHPULL); | ||
| 410 | }); | ||
| 411 | } | ||
| 409 | AFType::OutputPushPull => { | 412 | AFType::OutputPushPull => { |
| 410 | r.cr(crlh).modify(|w| { | 413 | r.cr(crlh).modify(|w| { |
| 411 | w.set_mode(n % 8, vals::Mode::OUTPUT50); | 414 | w.set_mode(n % 8, vals::Mode::OUTPUT50); |
| @@ -428,6 +431,7 @@ pub(crate) mod sealed { | |||
| 428 | .afr(pin / 8) | 431 | .afr(pin / 8) |
| 429 | .modify(|w| w.set_afr(pin % 8, vals::Afr(af_num))); | 432 | .modify(|w| w.set_afr(pin % 8, vals::Afr(af_num))); |
| 430 | match af_type { | 433 | match af_type { |
| 434 | AFType::Input => {} | ||
| 431 | AFType::OutputPushPull => { | 435 | AFType::OutputPushPull => { |
| 432 | block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) | 436 | block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) |
| 433 | } | 437 | } |
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 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::dma::NoDma; | 3 | use crate::dma::NoDma; |
| 4 | use crate::gpio::{ | 4 | use crate::gpio::sealed::AFType; |
| 5 | sealed::{ | 5 | use crate::gpio::sealed::Pin; |
| 6 | AFType::{OutputOpenDrain, OutputPushPull}, | 6 | use crate::gpio::{AnyPin, NoPin}; |
| 7 | Pin, | ||
| 8 | }, | ||
| 9 | AnyPin, NoPin, | ||
| 10 | }; | ||
| 11 | use crate::pac::spi; | 7 | use crate::pac::spi; |
| 12 | use crate::peripherals; | 8 | use crate::peripherals; |
| 13 | use crate::spi::{ | 9 | use crate::spi::{ |
| @@ -87,9 +83,11 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 87 | let miso = miso.degrade_optional(); | 83 | let miso = miso.degrade_optional(); |
| 88 | 84 | ||
| 89 | unsafe { | 85 | unsafe { |
| 90 | sck.as_ref().map(|x| x.set_as_af(sck_af, OutputPushPull)); | 86 | sck.as_ref() |
| 91 | mosi.as_ref().map(|x| x.set_as_af(mosi_af, OutputPushPull)); | 87 | .map(|x| x.set_as_af(sck_af, AFType::OutputPushPull)); |
| 92 | miso.as_ref().map(|x| x.set_as_af(miso_af, OutputOpenDrain)); | 88 | mosi.as_ref() |
| 89 | .map(|x| x.set_as_af(mosi_af, AFType::OutputPushPull)); | ||
| 90 | miso.as_ref().map(|x| x.set_as_af(miso_af, AFType::Input)); | ||
| 93 | } | 91 | } |
| 94 | 92 | ||
| 95 | unsafe { | 93 | unsafe { |
