Merge pull request #3965 from toon23/stm32_usart-pin_config
Stm32 usart: implement pin config for cts, tx, rts and de
This commit is contained in:
commit
3ffee5e22b
@ -13,10 +13,10 @@ use embassy_sync::waitqueue::AtomicWaker;
|
|||||||
use super::DePin;
|
use super::DePin;
|
||||||
use super::{
|
use super::{
|
||||||
clear_interrupt_flags, configure, half_duplex_set_rx_tx_before_write, rdr, reconfigure, send_break, set_baudrate,
|
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,
|
||||||
RtsPin, RxPin, TxPin,
|
TxPin,
|
||||||
};
|
};
|
||||||
use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
|
use crate::gpio::{AfType, AnyPin, Pull, SealedPin as _};
|
||||||
use crate::interrupt::{self, InterruptExt};
|
use crate::interrupt::{self, InterruptExt};
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
|
|
||||||
@ -217,8 +217,8 @@ impl<'d> BufferedUart<'d> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(config.rx_pull)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@ -242,10 +242,10 @@ impl<'d> BufferedUart<'d> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(Pull::None)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
new_pin!(rts, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(rts, config.rts_config.af_type()),
|
||||||
new_pin!(cts, AfType::input(Pull::None)),
|
new_pin!(cts, AfType::input(config.cts_pull)),
|
||||||
None,
|
None,
|
||||||
tx_buffer,
|
tx_buffer,
|
||||||
rx_buffer,
|
rx_buffer,
|
||||||
@ -266,8 +266,8 @@ impl<'d> BufferedUart<'d> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(Pull::None)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_pin!(rts, AfType::input(Pull::None)), // RTS mapped used as DE
|
new_pin!(rts, AfType::input(Pull::None)), // RTS mapped used as DE
|
||||||
@ -290,8 +290,8 @@ impl<'d> BufferedUart<'d> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(Pull::None)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
new_pin!(rts, AfType::input(Pull::None)),
|
new_pin!(rts, AfType::input(Pull::None)),
|
||||||
None, // no CTS
|
None, // no CTS
|
||||||
None, // no DE
|
None, // no DE
|
||||||
@ -315,11 +315,11 @@ impl<'d> BufferedUart<'d> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(config.rx_pull)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_pin!(de, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(de, config.de_config.af_type()),
|
||||||
tx_buffer,
|
tx_buffer,
|
||||||
rx_buffer,
|
rx_buffer,
|
||||||
config,
|
config,
|
||||||
@ -346,7 +346,6 @@ impl<'d> BufferedUart<'d> {
|
|||||||
rx_buffer: &'d mut [u8],
|
rx_buffer: &'d mut [u8],
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
readback: HalfDuplexReadback,
|
readback: HalfDuplexReadback,
|
||||||
half_duplex: HalfDuplexConfig,
|
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
#[cfg(not(any(usart_v1, usart_v2)))]
|
#[cfg(not(any(usart_v1, usart_v2)))]
|
||||||
{
|
{
|
||||||
@ -357,7 +356,7 @@ impl<'d> BufferedUart<'d> {
|
|||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
None,
|
None,
|
||||||
new_pin!(tx, half_duplex.af_type()),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@ -386,14 +385,13 @@ impl<'d> BufferedUart<'d> {
|
|||||||
rx_buffer: &'d mut [u8],
|
rx_buffer: &'d mut [u8],
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
readback: HalfDuplexReadback,
|
readback: HalfDuplexReadback,
|
||||||
half_duplex: HalfDuplexConfig,
|
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
config.swap_rx_tx = true;
|
config.swap_rx_tx = true;
|
||||||
config.duplex = Duplex::Half(readback);
|
config.duplex = Duplex::Half(readback);
|
||||||
|
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, half_duplex.af_type()),
|
new_pin!(rx, config.rx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use embassy_sync::waitqueue::AtomicWaker;
|
|||||||
use futures_util::future::{select, Either};
|
use futures_util::future::{select, Either};
|
||||||
|
|
||||||
use crate::dma::ChannelAndRequest;
|
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::typelevel::Interrupt as _;
|
||||||
use crate::interrupt::{self, Interrupt, InterruptExt};
|
use crate::interrupt::{self, Interrupt, InterruptExt};
|
||||||
use crate::mode::{Async, Blocking, Mode};
|
use crate::mode::{Async, Blocking, Mode};
|
||||||
@ -131,6 +131,30 @@ pub enum HalfDuplexReadback {
|
|||||||
Readback,
|
Readback,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
|
/// Half duplex IO mode
|
||||||
|
pub enum OutputConfig {
|
||||||
|
/// Push pull allows for faster baudrates, no internal pullup
|
||||||
|
PushPull,
|
||||||
|
/// Open drain output (external pull up needed)
|
||||||
|
OpenDrain,
|
||||||
|
#[cfg(not(gpio_v1))]
|
||||||
|
/// Open drain output with internal pull up resistor
|
||||||
|
OpenDrainPullUp,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OutputConfig {
|
||||||
|
const fn af_type(self) -> AfType {
|
||||||
|
match self {
|
||||||
|
OutputConfig::PushPull => AfType::output(OutputType::PushPull, Speed::Medium),
|
||||||
|
OutputConfig::OpenDrain => AfType::output(OutputType::OpenDrain, Speed::Medium),
|
||||||
|
#[cfg(not(gpio_v1))]
|
||||||
|
OutputConfig::OpenDrainPullUp => AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
/// Duplex mode
|
/// Duplex mode
|
||||||
@ -203,6 +227,18 @@ pub struct Config {
|
|||||||
/// Set the pull configuration for the RX pin.
|
/// Set the pull configuration for the RX pin.
|
||||||
pub rx_pull: Pull,
|
pub rx_pull: Pull,
|
||||||
|
|
||||||
|
/// Set the pull configuration for the CTS pin.
|
||||||
|
pub cts_pull: Pull,
|
||||||
|
|
||||||
|
/// Set the pin configuration for the TX pin.
|
||||||
|
pub tx_config: OutputConfig,
|
||||||
|
|
||||||
|
/// Set the pin configuration for the RTS pin.
|
||||||
|
pub rts_config: OutputConfig,
|
||||||
|
|
||||||
|
/// Set the pin configuration for the DE pin.
|
||||||
|
pub de_config: OutputConfig,
|
||||||
|
|
||||||
// private: set by new_half_duplex, not by the user.
|
// private: set by new_half_duplex, not by the user.
|
||||||
duplex: Duplex,
|
duplex: Duplex,
|
||||||
}
|
}
|
||||||
@ -213,13 +249,13 @@ impl Config {
|
|||||||
if self.swap_rx_tx {
|
if self.swap_rx_tx {
|
||||||
return AfType::input(self.rx_pull);
|
return AfType::input(self.rx_pull);
|
||||||
};
|
};
|
||||||
AfType::output(OutputType::PushPull, Speed::Medium)
|
self.tx_config.af_type()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rx_af(&self) -> AfType {
|
fn rx_af(&self) -> AfType {
|
||||||
#[cfg(any(usart_v3, usart_v4))]
|
#[cfg(any(usart_v3, usart_v4))]
|
||||||
if self.swap_rx_tx {
|
if self.swap_rx_tx {
|
||||||
return AfType::output(OutputType::PushPull, Speed::Medium);
|
return self.tx_config.af_type();
|
||||||
};
|
};
|
||||||
AfType::input(self.rx_pull)
|
AfType::input(self.rx_pull)
|
||||||
}
|
}
|
||||||
@ -243,35 +279,15 @@ impl Default for Config {
|
|||||||
#[cfg(any(usart_v3, usart_v4))]
|
#[cfg(any(usart_v3, usart_v4))]
|
||||||
invert_rx: false,
|
invert_rx: false,
|
||||||
rx_pull: Pull::None,
|
rx_pull: Pull::None,
|
||||||
|
cts_pull: Pull::None,
|
||||||
|
tx_config: OutputConfig::PushPull,
|
||||||
|
rts_config: OutputConfig::PushPull,
|
||||||
|
de_config: OutputConfig::PushPull,
|
||||||
duplex: Duplex::Full,
|
duplex: Duplex::Full,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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
|
/// Serial error
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
@ -419,13 +435,7 @@ impl<'d> UartTx<'d, Async> {
|
|||||||
tx_dma: Peri<'d, impl TxDma<T>>,
|
tx_dma: Peri<'d, impl TxDma<T>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(peri, new_pin!(tx, config.tx_af()), None, new_dma!(tx_dma), config)
|
||||||
peri,
|
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
|
||||||
None,
|
|
||||||
new_dma!(tx_dma),
|
|
||||||
config,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new tx-only UART with a clear-to-send pin
|
/// Create a new tx-only UART with a clear-to-send pin
|
||||||
@ -438,8 +448,8 @@ impl<'d> UartTx<'d, Async> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
new_pin!(cts, AfType::input(Pull::None)),
|
new_pin!(cts, AfType::input(config.cts_pull)),
|
||||||
new_dma!(tx_dma),
|
new_dma!(tx_dma),
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
@ -477,13 +487,7 @@ impl<'d> UartTx<'d, Blocking> {
|
|||||||
tx: Peri<'d, impl TxPin<T>>,
|
tx: Peri<'d, impl TxPin<T>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(peri, new_pin!(tx, config.tx_af()), None, None, config)
|
||||||
peri,
|
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
config,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new blocking tx-only UART with a clear-to-send pin
|
/// Create a new blocking tx-only UART with a clear-to-send pin
|
||||||
@ -495,8 +499,8 @@ impl<'d> UartTx<'d, Blocking> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(tx, config.tx_af()),
|
||||||
new_pin!(cts, AfType::input(config.rx_pull)),
|
new_pin!(cts, AfType::input(config.cts_pull)),
|
||||||
None,
|
None,
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
@ -651,13 +655,7 @@ impl<'d> UartRx<'d, Async> {
|
|||||||
rx_dma: Peri<'d, impl RxDma<T>>,
|
rx_dma: Peri<'d, impl RxDma<T>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(peri, new_pin!(rx, config.rx_af()), None, new_dma!(rx_dma), config)
|
||||||
peri,
|
|
||||||
new_pin!(rx, AfType::input(config.rx_pull)),
|
|
||||||
None,
|
|
||||||
new_dma!(rx_dma),
|
|
||||||
config,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new rx-only UART with a request-to-send pin
|
/// Create a new rx-only UART with a request-to-send pin
|
||||||
@ -671,8 +669,8 @@ impl<'d> UartRx<'d, Async> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(config.rx_pull)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(rts, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(rts, config.rts_config.af_type()),
|
||||||
new_dma!(rx_dma),
|
new_dma!(rx_dma),
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
@ -906,7 +904,7 @@ impl<'d> UartRx<'d, Blocking> {
|
|||||||
rx: Peri<'d, impl RxPin<T>>,
|
rx: Peri<'d, impl RxPin<T>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(peri, new_pin!(rx, AfType::input(config.rx_pull)), None, None, config)
|
Self::new_inner(peri, new_pin!(rx, config.rx_af()), None, None, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new rx-only UART with a request-to-send pin
|
/// Create a new rx-only UART with a request-to-send pin
|
||||||
@ -918,8 +916,8 @@ impl<'d> UartRx<'d, Blocking> {
|
|||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
new_pin!(rx, AfType::input(config.rx_pull)),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(rts, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(rts, config.rts_config.af_type()),
|
||||||
None,
|
None,
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
@ -1135,8 +1133,8 @@ impl<'d> Uart<'d, Async> {
|
|||||||
peri,
|
peri,
|
||||||
new_pin!(rx, config.rx_af()),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, config.tx_af()),
|
new_pin!(tx, config.tx_af()),
|
||||||
new_pin!(rts, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(rts, config.rts_config.af_type()),
|
||||||
new_pin!(cts, AfType::input(Pull::None)),
|
new_pin!(cts, AfType::input(config.cts_pull)),
|
||||||
None,
|
None,
|
||||||
new_dma!(tx_dma),
|
new_dma!(tx_dma),
|
||||||
new_dma!(rx_dma),
|
new_dma!(rx_dma),
|
||||||
@ -1162,7 +1160,7 @@ impl<'d> Uart<'d, Async> {
|
|||||||
new_pin!(tx, config.tx_af()),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_pin!(de, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(de, config.de_config.af_type()),
|
||||||
new_dma!(tx_dma),
|
new_dma!(tx_dma),
|
||||||
new_dma!(rx_dma),
|
new_dma!(rx_dma),
|
||||||
config,
|
config,
|
||||||
@ -1189,7 +1187,6 @@ impl<'d> Uart<'d, Async> {
|
|||||||
rx_dma: Peri<'d, impl RxDma<T>>,
|
rx_dma: Peri<'d, impl RxDma<T>>,
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
readback: HalfDuplexReadback,
|
readback: HalfDuplexReadback,
|
||||||
half_duplex: HalfDuplexConfig,
|
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
#[cfg(not(any(usart_v1, usart_v2)))]
|
#[cfg(not(any(usart_v1, usart_v2)))]
|
||||||
{
|
{
|
||||||
@ -1200,7 +1197,7 @@ impl<'d> Uart<'d, Async> {
|
|||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
None,
|
None,
|
||||||
new_pin!(tx, half_duplex.af_type()),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@ -1229,7 +1226,6 @@ impl<'d> Uart<'d, Async> {
|
|||||||
rx_dma: Peri<'d, impl RxDma<T>>,
|
rx_dma: Peri<'d, impl RxDma<T>>,
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
readback: HalfDuplexReadback,
|
readback: HalfDuplexReadback,
|
||||||
half_duplex: HalfDuplexConfig,
|
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
config.swap_rx_tx = true;
|
config.swap_rx_tx = true;
|
||||||
config.duplex = Duplex::Half(readback);
|
config.duplex = Duplex::Half(readback);
|
||||||
@ -1238,7 +1234,7 @@ impl<'d> Uart<'d, Async> {
|
|||||||
peri,
|
peri,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_pin!(rx, half_duplex.af_type()),
|
new_pin!(rx, config.rx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_dma!(tx_dma),
|
new_dma!(tx_dma),
|
||||||
@ -1302,8 +1298,8 @@ impl<'d> Uart<'d, Blocking> {
|
|||||||
peri,
|
peri,
|
||||||
new_pin!(rx, config.rx_af()),
|
new_pin!(rx, config.rx_af()),
|
||||||
new_pin!(tx, config.tx_af()),
|
new_pin!(tx, config.tx_af()),
|
||||||
new_pin!(rts, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(rts, config.rts_config.af_type()),
|
||||||
new_pin!(cts, AfType::input(Pull::None)),
|
new_pin!(cts, AfType::input(config.cts_pull)),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@ -1326,7 +1322,7 @@ impl<'d> Uart<'d, Blocking> {
|
|||||||
new_pin!(tx, config.tx_af()),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_pin!(de, AfType::output(OutputType::PushPull, Speed::Medium)),
|
new_pin!(de, config.de_config.af_type()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
config,
|
config,
|
||||||
@ -1349,7 +1345,6 @@ impl<'d> Uart<'d, Blocking> {
|
|||||||
tx: Peri<'d, impl TxPin<T>>,
|
tx: Peri<'d, impl TxPin<T>>,
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
readback: HalfDuplexReadback,
|
readback: HalfDuplexReadback,
|
||||||
half_duplex: HalfDuplexConfig,
|
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
#[cfg(not(any(usart_v1, usart_v2)))]
|
#[cfg(not(any(usart_v1, usart_v2)))]
|
||||||
{
|
{
|
||||||
@ -1360,7 +1355,7 @@ impl<'d> Uart<'d, Blocking> {
|
|||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
peri,
|
peri,
|
||||||
None,
|
None,
|
||||||
new_pin!(tx, half_duplex.af_type()),
|
new_pin!(tx, config.tx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@ -1386,7 +1381,6 @@ impl<'d> Uart<'d, Blocking> {
|
|||||||
rx: Peri<'d, impl RxPin<T>>,
|
rx: Peri<'d, impl RxPin<T>>,
|
||||||
mut config: Config,
|
mut config: Config,
|
||||||
readback: HalfDuplexReadback,
|
readback: HalfDuplexReadback,
|
||||||
half_duplex: HalfDuplexConfig,
|
|
||||||
) -> Result<Self, ConfigError> {
|
) -> Result<Self, ConfigError> {
|
||||||
config.swap_rx_tx = true;
|
config.swap_rx_tx = true;
|
||||||
config.duplex = Duplex::Half(readback);
|
config.duplex = Duplex::Half(readback);
|
||||||
@ -1395,7 +1389,7 @@ impl<'d> Uart<'d, Blocking> {
|
|||||||
peri,
|
peri,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
new_pin!(rx, half_duplex.af_type()),
|
new_pin!(rx, config.rx_af()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use defmt::*;
|
|||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::mode::Async;
|
use embassy_stm32::mode::Async;
|
||||||
use embassy_stm32::usart::{
|
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_stm32::{bind_interrupts, peripherals, usart};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
@ -21,16 +21,18 @@ fn create_onewire(p: embassy_stm32::Peripherals) -> OneWire<UartTx<'static, Asyn
|
|||||||
USART1 => usart::InterruptHandler<peripherals::USART1>;
|
USART1 => usart::InterruptHandler<peripherals::USART1>;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut config = Config::default();
|
||||||
|
config.tx_config = OutputConfig::OpenDrain;
|
||||||
|
|
||||||
let usart = Uart::new_half_duplex(
|
let usart = Uart::new_half_duplex(
|
||||||
p.USART1,
|
p.USART1,
|
||||||
p.PA9,
|
p.PA9,
|
||||||
Irqs,
|
Irqs,
|
||||||
p.DMA1_CH1,
|
p.DMA1_CH1,
|
||||||
p.DMA1_CH2,
|
p.DMA1_CH2,
|
||||||
Config::default(),
|
config,
|
||||||
// Enable readback so we can read sensor pulling data low while transmission is in progress
|
// Enable readback so we can read sensor pulling data low while transmission is in progress
|
||||||
usart::HalfDuplexReadback::Readback,
|
usart::HalfDuplexReadback::Readback,
|
||||||
HalfDuplexConfig::OpenDrainExternal,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -50,6 +52,8 @@ fn create_onewire(p: embassy_stm32::Peripherals) -> OneWire<BufferedUartTx<'stat
|
|||||||
});
|
});
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 16;
|
const BUFFER_SIZE: usize = 16;
|
||||||
|
let mut config = Confi::default();
|
||||||
|
config.tx_config = OutputConfig::OpenDrain;
|
||||||
let tx_buf: &mut [u8; BUFFER_SIZE] = singleton!(TX_BUF: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE]).unwrap();
|
let tx_buf: &mut [u8; BUFFER_SIZE] = singleton!(TX_BUF: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE]).unwrap();
|
||||||
let rx_buf: &mut [u8; BUFFER_SIZE] = singleton!(RX_BUF: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE]).unwrap();
|
let rx_buf: &mut [u8; BUFFER_SIZE] = singleton!(RX_BUF: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE]).unwrap();
|
||||||
let usart = BufferedUart::new_half_duplex(
|
let usart = BufferedUart::new_half_duplex(
|
||||||
@ -58,10 +62,9 @@ fn create_onewire(p: embassy_stm32::Peripherals) -> OneWire<BufferedUartTx<'stat
|
|||||||
Irqs,
|
Irqs,
|
||||||
tx_buf,
|
tx_buf,
|
||||||
rx_buf,
|
rx_buf,
|
||||||
Config::default(),
|
config,
|
||||||
// Enable readback so we can read sensor pulling data low while transmission is in progress
|
// Enable readback so we can read sensor pulling data low while transmission is in progress
|
||||||
usart::HalfDuplexReadback::Readback,
|
usart::HalfDuplexReadback::Readback,
|
||||||
HalfDuplexConfig::OpenDrainExternal,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (tx, rx) = usart.split();
|
let (tx, rx) = usart.split();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user