mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-26 20:00:27 +00:00
stm32/afio: make af_num() unavailable in afio chips.
This commit is contained in:
parent
35f4ae378c
commit
a23c4b7bca
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -17,7 +17,7 @@
|
||||
//"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
|
||||
"rust-analyzer.cargo.features": [
|
||||
// Comment out these features when working on the examples. Most example crates do not have any cargo features.
|
||||
"stm32f446re",
|
||||
"stm32f107rb",
|
||||
"time-driver-any",
|
||||
"unstable-pac",
|
||||
"exti",
|
||||
|
@ -194,10 +194,8 @@ impl<'d> Can<'d> {
|
||||
let info = T::info();
|
||||
let regs = &T::info().regs;
|
||||
|
||||
rx.set_as_af(rx.af_num(), AfType::input(Pull::None));
|
||||
#[cfg(afio)]
|
||||
rx.afio_remap();
|
||||
tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(rx, AfType::input(Pull::None));
|
||||
set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
|
||||
rcc::enable_and_reset::<T>();
|
||||
|
||||
@ -231,8 +229,8 @@ impl<'d> Can<'d> {
|
||||
info.sce_interrupt.enable();
|
||||
}
|
||||
|
||||
rx.set_as_af(rx.af_num(), AfType::input(Pull::None));
|
||||
tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(rx, AfType::input(Pull::None));
|
||||
set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
|
||||
Registers(T::regs()).leave_init_mode();
|
||||
|
||||
|
@ -185,8 +185,8 @@ impl<'d> CanConfigurator<'d> {
|
||||
+ interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>>
|
||||
+ 'd,
|
||||
) -> CanConfigurator<'d> {
|
||||
rx.set_as_af(rx.af_num(), AfType::input(Pull::None));
|
||||
tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(rx, AfType::input(Pull::None));
|
||||
set_as_af!(tx, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
|
||||
rcc::enable_and_reset::<T>();
|
||||
|
||||
|
@ -108,7 +108,7 @@ macro_rules! config_pins {
|
||||
($($pin:ident),*) => {
|
||||
critical_section::with(|_| {
|
||||
$(
|
||||
$pin.set_as_af($pin.af_num(), AfType::input(Pull::None));
|
||||
set_as_af!($pin, AfType::input(Pull::None));
|
||||
)*
|
||||
})
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ impl<'d, T: Instance> DsiHost<'d, T> {
|
||||
rcc::enable_and_reset::<T>();
|
||||
|
||||
// Set Tearing Enable pin according to CubeMx example
|
||||
te.set_as_af(te.af_num(), AfType::output(OutputType::PushPull, Speed::Low));
|
||||
set_as_af!(te, AfType::output(OutputType::PushPull, Speed::Low));
|
||||
/*
|
||||
T::regs().wcr().modify(|w| {
|
||||
w.set_dsien(true);
|
||||
|
@ -69,7 +69,7 @@ macro_rules! config_in_pins {
|
||||
critical_section::with(|_| {
|
||||
$(
|
||||
// TODO properly create a set_as_input function
|
||||
$pin.set_as_af($pin.af_num(), AfType::input(Pull::None));
|
||||
set_as_af!($pin, AfType::input(Pull::None));
|
||||
)*
|
||||
})
|
||||
}
|
||||
@ -80,7 +80,7 @@ macro_rules! config_af_pins {
|
||||
($($pin:ident),*) => {
|
||||
critical_section::with(|_| {
|
||||
$(
|
||||
$pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
)*
|
||||
})
|
||||
};
|
||||
@ -91,7 +91,7 @@ macro_rules! config_pins {
|
||||
($($pin:ident),*) => {
|
||||
critical_section::with(|_| {
|
||||
$(
|
||||
$pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
)*
|
||||
})
|
||||
};
|
||||
@ -150,8 +150,6 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
|
||||
{
|
||||
config_in_pins!(ref_clk, rx_d0, rx_d1);
|
||||
config_af_pins!(mdio, mdc, tx_d0, tx_d1, tx_en);
|
||||
#[cfg(afio)]
|
||||
rx_d0.afio_remap();
|
||||
}
|
||||
|
||||
#[cfg(any(eth_v1b, eth_v1c))]
|
||||
@ -349,8 +347,6 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
|
||||
{
|
||||
config_in_pins!(rx_clk, tx_clk, rx_d0, rx_d1, rx_d2, rx_d3, rxdv);
|
||||
config_af_pins!(mdio, mdc, tx_d0, tx_d1, tx_d2, tx_d3, tx_en);
|
||||
#[cfg(afio)]
|
||||
rx_d0.afio_remap();
|
||||
}
|
||||
|
||||
#[cfg(any(eth_v1b, eth_v1c))]
|
||||
|
@ -57,7 +57,7 @@ macro_rules! config_pins {
|
||||
critical_section::with(|_| {
|
||||
$(
|
||||
// TODO: shouldn't some pins be configured as inputs?
|
||||
$pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
)*
|
||||
})
|
||||
};
|
||||
|
@ -75,7 +75,7 @@ where
|
||||
macro_rules! config_pins {
|
||||
($($pin:ident),*) => {
|
||||
$(
|
||||
$pin.set_as_af($pin.af_num(), AfType::output_pull(OutputType::PushPull, Speed::VeryHigh, Pull::Up));
|
||||
set_as_af!($pin, AfType::output_pull(OutputType::PushPull, Speed::VeryHigh, Pull::Up));
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
@ -150,9 +150,13 @@ impl<'d> Flex<'d> {
|
||||
/// This puts the pin into the AF mode, with the requested number and AF type. This is
|
||||
/// completely unchecked, it can attach the pin to literally any peripheral, so use with care.
|
||||
#[inline]
|
||||
pub fn set_as_af_unchecked(&mut self, af_num: u8, af_type: AfType) {
|
||||
pub fn set_as_af_unchecked(&mut self, #[cfg(not(afio))] af_num: u8, af_type: AfType) {
|
||||
critical_section::with(|_| {
|
||||
self.pin.set_as_af(af_num, af_type);
|
||||
self.pin.set_as_af(
|
||||
#[cfg(not(afio))]
|
||||
af_num,
|
||||
af_type,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -588,7 +592,7 @@ impl AfType {
|
||||
|
||||
#[inline(never)]
|
||||
#[cfg(gpio_v1)]
|
||||
fn set_as_af(pin_port: u8, _af_num: u8, af_type: AfType) {
|
||||
fn set_as_af(pin_port: u8, af_type: AfType) {
|
||||
let pin = unsafe { AnyPin::steal(pin_port) };
|
||||
let r = pin.block();
|
||||
let n = pin._pin() as usize;
|
||||
@ -755,8 +759,13 @@ pub(crate) trait SealedPin {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_as_af(&self, af_num: u8, af_type: AfType) {
|
||||
set_as_af(self.pin_port(), af_num, af_type)
|
||||
fn set_as_af(&self, #[cfg(not(afio))] af_num: u8, af_type: AfType) {
|
||||
set_as_af(
|
||||
self.pin_port(),
|
||||
#[cfg(not(afio))]
|
||||
af_num,
|
||||
af_type,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -79,10 +79,7 @@ macro_rules! advanced_channel_impl {
|
||||
pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
AfType::output(OutputType::PushPull, Speed::VeryHigh),
|
||||
);
|
||||
set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
});
|
||||
PwmPin {
|
||||
_pin: pin.into(),
|
||||
@ -96,10 +93,7 @@ macro_rules! advanced_channel_impl {
|
||||
pub fn $new_chx(pin: Peri<'d, impl $complementary_pin_trait<T>>) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
AfType::output(OutputType::PushPull, Speed::VeryHigh),
|
||||
);
|
||||
set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
});
|
||||
ComplementaryPwmPin {
|
||||
_pin: pin.into(),
|
||||
|
@ -471,8 +471,8 @@ impl<'d, W: Word> I2S<'d, W> {
|
||||
config: Config,
|
||||
function: Function,
|
||||
) -> Self {
|
||||
ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed));
|
||||
ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed));
|
||||
set_as_af!(ws, AfType::output(OutputType::PushPull, config.gpio_speed));
|
||||
set_as_af!(ck, AfType::output(OutputType::PushPull, config.gpio_speed));
|
||||
|
||||
let spi = Spi::new_internal(peri, None, None, {
|
||||
let mut spi_config = SpiConfig::default();
|
||||
|
@ -50,10 +50,7 @@ macro_rules! channel_impl {
|
||||
pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
AfType::output(OutputType::PushPull, Speed::VeryHigh),
|
||||
);
|
||||
set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
});
|
||||
PwmPin {
|
||||
_pin: pin.into(),
|
||||
@ -64,12 +61,12 @@ macro_rules! channel_impl {
|
||||
pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
#[cfg(gpio_v1)]
|
||||
AfType::output(pin_config.output_type, pin_config.speed),
|
||||
#[cfg(gpio_v2)]
|
||||
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
|
||||
#[cfg(gpio_v1)]
|
||||
set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed));
|
||||
#[cfg(gpio_v2)]
|
||||
set_as_af!(
|
||||
pin,
|
||||
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull)
|
||||
);
|
||||
});
|
||||
PwmPin {
|
||||
|
@ -44,6 +44,7 @@ macro_rules! pin_trait {
|
||||
($signal:ident, $instance:path $(, $mode:path)? $(, @$afio:ident)?) => {
|
||||
#[doc = concat!(stringify!($signal), " pin trait")]
|
||||
pub trait $signal<T: $instance $(, M: $mode)? $(, #[cfg(afio)] $afio)?>: crate::gpio::Pin {
|
||||
#[cfg(not(afio))]
|
||||
#[doc = concat!("Get the AF number needed to use this pin as ", stringify!($signal))]
|
||||
fn af_num(&self) -> u8;
|
||||
|
||||
@ -58,10 +59,6 @@ macro_rules! pin_trait_impl {
|
||||
(crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $pin:ident, $af:expr $(, $afio:path)?) => {
|
||||
#[cfg(afio)]
|
||||
impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)? $(, $afio)?> for crate::peripherals::$pin {
|
||||
fn af_num(&self) -> u8 {
|
||||
$af
|
||||
}
|
||||
|
||||
fn afio_remap(&self) {
|
||||
// nothing
|
||||
}
|
||||
@ -92,10 +89,6 @@ macro_rules! pin_trait_afio_impl {
|
||||
(crate::$mod:ident::$trait:ident<$mode:ident>, $instance:ident, $pin:ident, {$reg:ident, $setter:ident, $type:ident, [$($val:expr),+]}) => {
|
||||
$(
|
||||
impl crate::$mod::$trait<crate::peripherals::$instance, crate::$mod::$mode, crate::gpio::$type<$val>> for crate::peripherals::$pin {
|
||||
fn af_num(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
|
||||
fn afio_remap(&self) {
|
||||
pin_trait_afio_impl!(@set $reg, $setter, $val);
|
||||
}
|
||||
@ -105,10 +98,6 @@ macro_rules! pin_trait_afio_impl {
|
||||
(crate::$mod:ident::$trait:ident, $instance:ident, $pin:ident, {$reg:ident, $setter:ident, $type:ident, [$($val:expr),+]}) => {
|
||||
$(
|
||||
impl crate::$mod::$trait<crate::peripherals::$instance, crate::gpio::$type<$val>> for crate::peripherals::$pin {
|
||||
fn af_num(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
|
||||
fn afio_remap(&self) {
|
||||
pin_trait_afio_impl!(@set $reg, $setter, $val);
|
||||
}
|
||||
@ -193,11 +182,32 @@ macro_rules! new_pin {
|
||||
let pin = $name;
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
pin.set_as_af(pin.af_num(), $af_type);
|
||||
pin.set_as_af(
|
||||
#[cfg(not(afio))]
|
||||
pin.af_num(),
|
||||
$af_type,
|
||||
);
|
||||
Some(pin.into())
|
||||
}};
|
||||
}
|
||||
|
||||
/// Macro to configure a pin for alternate function use.
|
||||
/// For AFIO chips (STM32F1), it calls afio_remap().
|
||||
/// For non-AFIO chips, it calls set_as_af() with the pin's af_num().
|
||||
macro_rules! set_as_af {
|
||||
($pin:expr, $af_type:expr) => {
|
||||
#[cfg(afio)]
|
||||
{
|
||||
$pin.set_as_af($af_type);
|
||||
$pin.afio_remap();
|
||||
}
|
||||
#[cfg(not(afio))]
|
||||
{
|
||||
$pin.set_as_af($pin.af_num(), $af_type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(afio)]
|
||||
macro_rules! if_afio {
|
||||
($($t:tt)*) => {
|
||||
|
@ -94,7 +94,7 @@ impl<'d, T: McoInstance> Mco<'d, T> {
|
||||
pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, prescaler: McoPrescaler) -> Self {
|
||||
critical_section::with(|_| unsafe {
|
||||
T::_apply_clock_settings(source, prescaler);
|
||||
pin.set_as_af(pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
});
|
||||
|
||||
Self { phantom: PhantomData }
|
||||
|
@ -558,7 +558,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx);
|
||||
mclk.set_as_af(mclk.af_num(), ck_af_type);
|
||||
set_as_af!(mclk, ck_af_type);
|
||||
|
||||
Self::new_asynchronous(peri, sck, sd, fs, dma, dma_buf, config)
|
||||
}
|
||||
@ -578,9 +578,9 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> {
|
||||
let peri = peri.peri;
|
||||
|
||||
let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx);
|
||||
sd.set_as_af(sd.af_num(), sd_af_type);
|
||||
sck.set_as_af(sck.af_num(), ck_af_type);
|
||||
fs.set_as_af(fs.af_num(), ck_af_type);
|
||||
set_as_af!(sd, sd_af_type);
|
||||
set_as_af!(sck, ck_af_type);
|
||||
set_as_af!(fs, ck_af_type);
|
||||
|
||||
let sub_block = S::WHICH;
|
||||
let request = dma.request();
|
||||
@ -612,7 +612,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> {
|
||||
let peri = peri.peri;
|
||||
|
||||
let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx);
|
||||
sd.set_as_af(sd.af_num(), sd_af_type);
|
||||
set_as_af!(sd, sd_af_type);
|
||||
|
||||
let sub_block = S::WHICH;
|
||||
let request = dma.request();
|
||||
|
@ -428,9 +428,9 @@ impl<'d, T: Instance> Sdmmc<'d, T> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
critical_section::with(|_| {
|
||||
clk.set_as_af(clk.af_num(), CLK_AF);
|
||||
cmd.set_as_af(cmd.af_num(), CMD_AF);
|
||||
d0.set_as_af(d0.af_num(), DATA_AF);
|
||||
set_as_af!(clk, CLK_AF);
|
||||
set_as_af!(cmd, CMD_AF);
|
||||
set_as_af!(d0, DATA_AF);
|
||||
});
|
||||
|
||||
Self::new_inner(
|
||||
@ -464,12 +464,12 @@ impl<'d, T: Instance> Sdmmc<'d, T> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
critical_section::with(|_| {
|
||||
clk.set_as_af(clk.af_num(), CLK_AF);
|
||||
cmd.set_as_af(cmd.af_num(), CMD_AF);
|
||||
d0.set_as_af(d0.af_num(), DATA_AF);
|
||||
d1.set_as_af(d1.af_num(), DATA_AF);
|
||||
d2.set_as_af(d2.af_num(), DATA_AF);
|
||||
d3.set_as_af(d3.af_num(), DATA_AF);
|
||||
set_as_af!(clk, CLK_AF);
|
||||
set_as_af!(cmd, CMD_AF);
|
||||
set_as_af!(d0, DATA_AF);
|
||||
set_as_af!(d1, DATA_AF);
|
||||
set_as_af!(d2, DATA_AF);
|
||||
set_as_af!(d3, DATA_AF);
|
||||
});
|
||||
|
||||
Self::new_inner(
|
||||
@ -510,16 +510,16 @@ impl<'d, T: Instance> Sdmmc<'d, T> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
critical_section::with(|_| {
|
||||
clk.set_as_af(clk.af_num(), CLK_AF);
|
||||
cmd.set_as_af(cmd.af_num(), CMD_AF);
|
||||
d0.set_as_af(d0.af_num(), DATA_AF);
|
||||
d1.set_as_af(d1.af_num(), DATA_AF);
|
||||
d2.set_as_af(d2.af_num(), DATA_AF);
|
||||
d3.set_as_af(d3.af_num(), DATA_AF);
|
||||
d4.set_as_af(d4.af_num(), DATA_AF);
|
||||
d5.set_as_af(d5.af_num(), DATA_AF);
|
||||
d6.set_as_af(d6.af_num(), DATA_AF);
|
||||
d7.set_as_af(d7.af_num(), DATA_AF);
|
||||
set_as_af!(clk, CLK_AF);
|
||||
set_as_af!(cmd, CMD_AF);
|
||||
set_as_af!(d0, DATA_AF);
|
||||
set_as_af!(d1, DATA_AF);
|
||||
set_as_af!(d2, DATA_AF);
|
||||
set_as_af!(d3, DATA_AF);
|
||||
set_as_af!(d4, DATA_AF);
|
||||
set_as_af!(d5, DATA_AF);
|
||||
set_as_af!(d6, DATA_AF);
|
||||
set_as_af!(d7, DATA_AF);
|
||||
});
|
||||
|
||||
Self::new_inner(
|
||||
@ -552,9 +552,9 @@ impl<'d, T: Instance> Sdmmc<'d, T> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
critical_section::with(|_| {
|
||||
clk.set_as_af(clk.af_num(), CLK_AF);
|
||||
cmd.set_as_af(cmd.af_num(), CMD_AF);
|
||||
d0.set_as_af(d0.af_num(), DATA_AF);
|
||||
set_as_af!(clk, CLK_AF);
|
||||
set_as_af!(cmd, CMD_AF);
|
||||
set_as_af!(d0, DATA_AF);
|
||||
});
|
||||
|
||||
Self::new_inner(
|
||||
@ -586,12 +586,12 @@ impl<'d, T: Instance> Sdmmc<'d, T> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
critical_section::with(|_| {
|
||||
clk.set_as_af(clk.af_num(), CLK_AF);
|
||||
cmd.set_as_af(cmd.af_num(), CMD_AF);
|
||||
d0.set_as_af(d0.af_num(), DATA_AF);
|
||||
d1.set_as_af(d1.af_num(), DATA_AF);
|
||||
d2.set_as_af(d2.af_num(), DATA_AF);
|
||||
d3.set_as_af(d3.af_num(), DATA_AF);
|
||||
set_as_af!(clk, CLK_AF);
|
||||
set_as_af!(cmd, CMD_AF);
|
||||
set_as_af!(d0, DATA_AF);
|
||||
set_as_af!(d1, DATA_AF);
|
||||
set_as_af!(d2, DATA_AF);
|
||||
set_as_af!(d3, DATA_AF);
|
||||
});
|
||||
|
||||
Self::new_inner(
|
||||
@ -630,16 +630,16 @@ impl<'d, T: Instance> Sdmmc<'d, T> {
|
||||
config: Config,
|
||||
) -> Self {
|
||||
critical_section::with(|_| {
|
||||
clk.set_as_af(clk.af_num(), CLK_AF);
|
||||
cmd.set_as_af(cmd.af_num(), CMD_AF);
|
||||
d0.set_as_af(d0.af_num(), DATA_AF);
|
||||
d1.set_as_af(d1.af_num(), DATA_AF);
|
||||
d2.set_as_af(d2.af_num(), DATA_AF);
|
||||
d3.set_as_af(d3.af_num(), DATA_AF);
|
||||
d4.set_as_af(d4.af_num(), DATA_AF);
|
||||
d5.set_as_af(d5.af_num(), DATA_AF);
|
||||
d6.set_as_af(d6.af_num(), DATA_AF);
|
||||
d7.set_as_af(d7.af_num(), DATA_AF);
|
||||
set_as_af!(clk, CLK_AF);
|
||||
set_as_af!(cmd, CMD_AF);
|
||||
set_as_af!(d0, DATA_AF);
|
||||
set_as_af!(d1, DATA_AF);
|
||||
set_as_af!(d2, DATA_AF);
|
||||
set_as_af!(d3, DATA_AF);
|
||||
set_as_af!(d4, DATA_AF);
|
||||
set_as_af!(d5, DATA_AF);
|
||||
set_as_af!(d6, DATA_AF);
|
||||
set_as_af!(d7, DATA_AF);
|
||||
});
|
||||
|
||||
Self::new_inner(
|
||||
|
@ -35,7 +35,7 @@ macro_rules! new_spdifrx_pin {
|
||||
($name:ident, $af_type:expr) => {{
|
||||
let pin = $name;
|
||||
let input_sel = pin.input_sel();
|
||||
pin.set_as_af(pin.af_num(), $af_type);
|
||||
set_as_af!(pin, $af_type);
|
||||
(Some(pin.into()), input_sel)
|
||||
}};
|
||||
}
|
||||
|
@ -27,12 +27,10 @@ impl<'d, T: AdvancedInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(
|
||||
pub fn new(pin: Peri<'d, if_afio!(impl TimerComplementaryPin<T, C, A>)>, output_type: OutputType) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh),
|
||||
set_as_af!(
|
||||
pin,
|
||||
crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh)
|
||||
);
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
});
|
||||
ComplementaryPwmPin {
|
||||
pin: pin.into(),
|
||||
|
@ -25,7 +25,7 @@ pub struct CapturePin<'d, T, C, #[cfg(afio)] A> {
|
||||
impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(CapturePin<'d, T, C, A>) {
|
||||
/// Create a new capture pin instance.
|
||||
pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
set_as_af!(pin, AfType::input(pull));
|
||||
CapturePin {
|
||||
pin: pin.into(),
|
||||
phantom: PhantomData,
|
||||
|
@ -65,9 +65,7 @@ impl SealedTriggerSource for Ext {}
|
||||
impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin<'d, T, C> {
|
||||
/// Create a new Channel trigger pin instance.
|
||||
pub fn new<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pull: Pull) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
set_as_af!(pin, AfType::input(pull));
|
||||
TriggerPin {
|
||||
pin: pin.into(),
|
||||
phantom: PhantomData,
|
||||
@ -78,9 +76,7 @@ impl<'d, T: GeneralInstance4Channel, C: TriggerSource + TimerChannel> TriggerPin
|
||||
impl<'d, T: GeneralInstance4Channel> TriggerPin<'d, T, Ext> {
|
||||
/// Create a new external trigger pin instance.
|
||||
pub fn new_external<#[cfg(afio)] A>(pin: Peri<'d, if_afio!(impl ExternalTriggerPin<T, A>)>, pull: Pull) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
set_as_af!(pin, AfType::input(pull));
|
||||
TriggerPin {
|
||||
pin: pin.into(),
|
||||
phantom: PhantomData,
|
||||
|
@ -24,9 +24,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
|
||||
pull: Pull,
|
||||
freq: Hertz,
|
||||
) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
set_as_af!(pin, AfType::input(pull));
|
||||
|
||||
Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2)
|
||||
}
|
||||
@ -38,9 +36,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
|
||||
pull: Pull,
|
||||
freq: Hertz,
|
||||
) -> Self {
|
||||
pin.set_as_af(pin.af_num(), AfType::input(pull));
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
set_as_af!(pin, AfType::input(pull));
|
||||
|
||||
Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1)
|
||||
}
|
||||
|
@ -31,9 +31,7 @@ impl<'d, T: GeneralInstance4Channel, C: QeiChannel, #[cfg(afio)] A> if_afio!(Qei
|
||||
pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(pin.af_num(), AfType::input(Pull::None));
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
set_as_af!(pin, AfType::input(Pull::None));
|
||||
});
|
||||
QeiPin {
|
||||
pin: pin.into(),
|
||||
|
@ -40,9 +40,7 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(P
|
||||
pub fn new(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, output_type: OutputType) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh));
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
set_as_af!(pin, AfType::output(output_type, Speed::VeryHigh));
|
||||
});
|
||||
PwmPin {
|
||||
pin: pin.into(),
|
||||
@ -54,15 +52,13 @@ impl<'d, T: GeneralInstance4Channel, C: TimerChannel, #[cfg(afio)] A> if_afio!(P
|
||||
pub fn new_with_config(pin: Peri<'d, if_afio!(impl TimerPin<T, C, A>)>, pin_config: PwmPinConfig) -> Self {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(
|
||||
pin.af_num(),
|
||||
#[cfg(gpio_v1)]
|
||||
AfType::output(pin_config.output_type, pin_config.speed),
|
||||
#[cfg(gpio_v2)]
|
||||
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
|
||||
#[cfg(gpio_v1)]
|
||||
set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed));
|
||||
#[cfg(gpio_v2)]
|
||||
set_as_af!(
|
||||
pin,
|
||||
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull)
|
||||
);
|
||||
#[cfg(afio)]
|
||||
pin.afio_remap();
|
||||
});
|
||||
PwmPin {
|
||||
pin: pin.into(),
|
||||
|
@ -427,7 +427,7 @@ macro_rules! impl_set_io {
|
||||
pub fn $method<Role: pin_roles::Role>(&mut self, pin: Peri<'d, impl $trait<T>>) -> IOPinWithRole<$group, Role> {
|
||||
critical_section::with(|_| {
|
||||
pin.set_low();
|
||||
pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh));
|
||||
set_as_af!(pin, AfType::output(Role::output_type(), Speed::VeryHigh));
|
||||
let tsc_io_pin = trait_to_io_pin!($trait);
|
||||
let new_pin = Pin {
|
||||
_pin: pin.into(),
|
||||
|
@ -34,7 +34,7 @@ macro_rules! config_ulpi_pins {
|
||||
($($pin:ident),*) => {
|
||||
critical_section::with(|_| {
|
||||
$(
|
||||
$pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!($pin, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
)*
|
||||
})
|
||||
};
|
||||
@ -68,8 +68,8 @@ impl<'d, T: Instance> Driver<'d, T> {
|
||||
ep_out_buffer: &'d mut [u8],
|
||||
config: Config,
|
||||
) -> Self {
|
||||
dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(dp, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(dm, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
|
||||
let regs = T::regs();
|
||||
|
||||
@ -107,8 +107,8 @@ impl<'d, T: Instance> Driver<'d, T> {
|
||||
// For STM32U5 High speed pins need to be left in analog mode
|
||||
#[cfg(not(any(all(stm32u5, peri_usb_otg_hs), all(stm32wba, peri_usb_otg_hs))))]
|
||||
{
|
||||
_dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
_dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(_dp, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(_dm, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
}
|
||||
|
||||
let instance = OtgInstance {
|
||||
|
@ -298,7 +298,7 @@ impl<'d, T: Instance> Driver<'d, T> {
|
||||
) -> Self {
|
||||
{
|
||||
use crate::gpio::{AfType, OutputType, Speed};
|
||||
sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(sof, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
}
|
||||
|
||||
Self::new(_usb, _irq, dp, dm)
|
||||
@ -329,8 +329,8 @@ impl<'d, T: Instance> Driver<'d, T> {
|
||||
#[cfg(not(stm32l1))]
|
||||
{
|
||||
use crate::gpio::{AfType, OutputType, Speed};
|
||||
dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(dp, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
set_as_af!(dm, AfType::output(OutputType::PushPull, Speed::VeryHigh));
|
||||
}
|
||||
#[cfg(stm32l1)]
|
||||
let _ = (dp, dm); // suppress "unused" warnings.
|
||||
|
Loading…
x
Reference in New Issue
Block a user