diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 2dfb99dbc..57551ff56 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -13,7 +13,7 @@ use embassy_sync::waitqueue::AtomicWaker; use super::DePin; use super::{ clear_interrupt_flags, configure, half_duplex_set_rx_tx_before_write, rdr, reconfigure, send_break, set_baudrate, - sr, tdr, Config, ConfigError, CtsPin, Duplex, Error, HalfDuplexConfig, HalfDuplexReadback, Info, Instance, Regs, + sr, tdr, Config, ConfigError, CtsPin, Duplex, Error, HalfDuplexReadback, Info, Instance, Regs, RtsPin, RxPin, TxPin, }; use crate::gpio::{AfType, AnyPin, Pull, SealedPin as _}; @@ -346,7 +346,6 @@ impl<'d> BufferedUart<'d> { rx_buffer: &'d mut [u8], mut config: Config, readback: HalfDuplexReadback, - half_duplex: HalfDuplexConfig, ) -> Result { #[cfg(not(any(usart_v1, usart_v2)))] { @@ -357,7 +356,7 @@ impl<'d> BufferedUart<'d> { Self::new_inner( peri, None, - new_pin!(tx, half_duplex.af_type()), + new_pin!(tx, config.tx_af()), None, None, None, @@ -386,14 +385,13 @@ impl<'d> BufferedUart<'d> { rx_buffer: &'d mut [u8], mut config: Config, readback: HalfDuplexReadback, - half_duplex: HalfDuplexConfig, ) -> Result { config.swap_rx_tx = true; config.duplex = Duplex::Half(readback); Self::new_inner( peri, - new_pin!(rx, half_duplex.af_type()), + new_pin!(rx, config.rx_af()), None, None, None, diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 80a391d41..a6bafc5a7 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -14,7 +14,7 @@ use embassy_sync::waitqueue::AtomicWaker; use futures_util::future::{select, Either}; use crate::dma::ChannelAndRequest; -use crate::gpio::{self, AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; +use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; use crate::interrupt::typelevel::Interrupt as _; use crate::interrupt::{self, Interrupt, InterruptExt}; use crate::mode::{Async, Blocking, Mode}; @@ -303,30 +303,6 @@ impl Default for Config { } } -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -/// Half duplex IO mode -pub enum HalfDuplexConfig { - /// Push pull allows for faster baudrates, may require series resistor - PushPull, - /// Open drain output using external pull up resistor - OpenDrainExternal, - #[cfg(not(gpio_v1))] - /// Open drain output using internal pull up resistor - OpenDrainInternal, -} - -impl HalfDuplexConfig { - fn af_type(self) -> gpio::AfType { - match self { - HalfDuplexConfig::PushPull => AfType::output(OutputType::PushPull, Speed::Medium), - HalfDuplexConfig::OpenDrainExternal => AfType::output(OutputType::OpenDrain, Speed::Medium), - #[cfg(not(gpio_v1))] - HalfDuplexConfig::OpenDrainInternal => AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up), - } - } -} - /// Serial error #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -1245,7 +1221,6 @@ impl<'d> Uart<'d, Async> { rx_dma: Peri<'d, impl RxDma>, mut config: Config, readback: HalfDuplexReadback, - half_duplex: HalfDuplexConfig, ) -> Result { #[cfg(not(any(usart_v1, usart_v2)))] { @@ -1256,7 +1231,7 @@ impl<'d> Uart<'d, Async> { Self::new_inner( peri, None, - new_pin!(tx, half_duplex.af_type()), + new_pin!(tx, config.tx_af()), None, None, None, @@ -1285,7 +1260,6 @@ impl<'d> Uart<'d, Async> { rx_dma: Peri<'d, impl RxDma>, mut config: Config, readback: HalfDuplexReadback, - half_duplex: HalfDuplexConfig, ) -> Result { config.swap_rx_tx = true; config.duplex = Duplex::Half(readback); @@ -1294,7 +1268,7 @@ impl<'d> Uart<'d, Async> { peri, None, None, - new_pin!(rx, half_duplex.af_type()), + new_pin!(rx, config.rx_af()), None, None, new_dma!(tx_dma), @@ -1405,7 +1379,6 @@ impl<'d> Uart<'d, Blocking> { tx: Peri<'d, impl TxPin>, mut config: Config, readback: HalfDuplexReadback, - half_duplex: HalfDuplexConfig, ) -> Result { #[cfg(not(any(usart_v1, usart_v2)))] { @@ -1416,7 +1389,7 @@ impl<'d> Uart<'d, Blocking> { Self::new_inner( peri, None, - new_pin!(tx, half_duplex.af_type()), + new_pin!(tx, config.tx_af()), None, None, None, @@ -1442,7 +1415,6 @@ impl<'d> Uart<'d, Blocking> { rx: Peri<'d, impl RxPin>, mut config: Config, readback: HalfDuplexReadback, - half_duplex: HalfDuplexConfig, ) -> Result { config.swap_rx_tx = true; config.duplex = Duplex::Half(readback); @@ -1451,7 +1423,7 @@ impl<'d> Uart<'d, Blocking> { peri, None, None, - new_pin!(rx, half_duplex.af_type()), + new_pin!(rx, config.rx_af()), None, None, None, diff --git a/examples/stm32g0/src/bin/onewire_ds18b20.rs b/examples/stm32g0/src/bin/onewire_ds18b20.rs index f85cc4ff8..75519bbf2 100644 --- a/examples/stm32g0/src/bin/onewire_ds18b20.rs +++ b/examples/stm32g0/src/bin/onewire_ds18b20.rs @@ -8,7 +8,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_stm32::mode::Async; use embassy_stm32::usart::{ - BufferedUartRx, BufferedUartTx, Config, ConfigError, HalfDuplexConfig, RingBufferedUartRx, UartTx, + BufferedUartRx, BufferedUartTx, Config, ConfigError, OutputConfig, RingBufferedUartRx, UartTx, }; use embassy_stm32::{bind_interrupts, peripherals, usart}; use embassy_time::{Duration, Timer}; @@ -21,16 +21,18 @@ fn create_onewire(p: embassy_stm32::Peripherals) -> OneWire usart::InterruptHandler; }); + let mut config = Config::default(); + config.tx_config = OutputConfig::OpenDrainExternal; + let usart = Uart::new_half_duplex( p.USART1, p.PA9, Irqs, p.DMA1_CH1, p.DMA1_CH2, - Config::default(), + config, // Enable readback so we can read sensor pulling data low while transmission is in progress usart::HalfDuplexReadback::Readback, - HalfDuplexConfig::OpenDrainExternal, ) .unwrap(); @@ -50,6 +52,8 @@ fn create_onewire(p: embassy_stm32::Peripherals) -> OneWire OneWire