stm32/uart: optimize swap_rx_tx

This commit is contained in:
Alessandro Pezzato 2023-07-19 10:50:40 +02:00
parent 3df2c71e6c
commit 36ff688fab

View file

@ -694,19 +694,21 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
let r = T::regs(); let r = T::regs();
#[allow(unused_variables)] // Some chips do not have swap_rx_tx bit
let swap_rx_tx = false; cfg_if::cfg_if! {
if #[cfg(any(usart_v3, usart_v4))] {
#[cfg(any(usart_v3, usart_v4))] if config.swap_rx_tx {
let swap_rx_tx = config.swap_rx_tx; let (rx, tx) = (tx, rx);
rx.set_as_af(rx.af_num(), AFType::Input);
if swap_rx_tx { tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
let (rx, tx) = (tx, rx); } else {
rx.set_as_af(rx.af_num(), AFType::Input); rx.set_as_af(rx.af_num(), AFType::Input);
tx.set_as_af(tx.af_num(), AFType::OutputPushPull); tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
} else { }
rx.set_as_af(rx.af_num(), AFType::Input); } else {
tx.set_as_af(tx.af_num(), AFType::OutputPushPull); rx.set_as_af(rx.af_num(), AFType::Input);
tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
}
} }
configure(r, &config, T::frequency(), T::KIND, true, true); configure(r, &config, T::frequency(), T::KIND, true, true);