Add AFType::Input for input configurations.
This commit is contained in:
parent
259e84e68e
commit
2cbb8a7ece
2 changed files with 16 additions and 14 deletions
|
@ -354,9 +354,7 @@ pub(crate) mod sealed {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum AFType {
|
pub enum AFType {
|
||||||
// InputFloating,
|
Input,
|
||||||
// InputPullUp,
|
|
||||||
// InputPullDown,
|
|
||||||
OutputPushPull,
|
OutputPushPull,
|
||||||
OutputOpenDrain,
|
OutputOpenDrain,
|
||||||
}
|
}
|
||||||
|
@ -405,7 +403,12 @@ pub(crate) mod sealed {
|
||||||
let n = self._pin() as usize;
|
let n = self._pin() as usize;
|
||||||
let crlh = if n < 8 { 0 } else { 1 };
|
let crlh = if n < 8 { 0 } else { 1 };
|
||||||
match af_type {
|
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 => {
|
AFType::OutputPushPull => {
|
||||||
r.cr(crlh).modify(|w| {
|
r.cr(crlh).modify(|w| {
|
||||||
w.set_mode(n % 8, vals::Mode::OUTPUT50);
|
w.set_mode(n % 8, vals::Mode::OUTPUT50);
|
||||||
|
@ -428,6 +431,7 @@ pub(crate) mod sealed {
|
||||||
.afr(pin / 8)
|
.afr(pin / 8)
|
||||||
.modify(|w| w.set_afr(pin % 8, vals::Afr(af_num)));
|
.modify(|w| w.set_afr(pin % 8, vals::Afr(af_num)));
|
||||||
match af_type {
|
match af_type {
|
||||||
|
AFType::Input => {}
|
||||||
AFType::OutputPushPull => {
|
AFType::OutputPushPull => {
|
||||||
block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL))
|
block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
#![macro_use]
|
#![macro_use]
|
||||||
|
|
||||||
use crate::dma::NoDma;
|
use crate::dma::NoDma;
|
||||||
use crate::gpio::{
|
use crate::gpio::sealed::AFType;
|
||||||
sealed::{
|
use crate::gpio::sealed::Pin;
|
||||||
AFType::{OutputOpenDrain, OutputPushPull},
|
use crate::gpio::{AnyPin, NoPin};
|
||||||
Pin,
|
|
||||||
},
|
|
||||||
AnyPin, NoPin,
|
|
||||||
};
|
|
||||||
use crate::pac::spi;
|
use crate::pac::spi;
|
||||||
use crate::peripherals;
|
use crate::peripherals;
|
||||||
use crate::spi::{
|
use crate::spi::{
|
||||||
|
@ -87,9 +83,11 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||||
let miso = miso.degrade_optional();
|
let miso = miso.degrade_optional();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
sck.as_ref().map(|x| x.set_as_af(sck_af, OutputPushPull));
|
sck.as_ref()
|
||||||
mosi.as_ref().map(|x| x.set_as_af(mosi_af, OutputPushPull));
|
.map(|x| x.set_as_af(sck_af, AFType::OutputPushPull));
|
||||||
miso.as_ref().map(|x| x.set_as_af(miso_af, OutputOpenDrain));
|
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 {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue