mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-02-16 08:53:17 +00:00
Merge pull request #3286 from trnila/stm32_usart_break
stm32/usart: sending break character
This commit is contained in:
commit
609b1b0355
@ -12,8 +12,8 @@ use embassy_sync::waitqueue::AtomicWaker;
|
||||
#[cfg(not(any(usart_v1, usart_v2)))]
|
||||
use super::DePin;
|
||||
use super::{
|
||||
clear_interrupt_flags, configure, rdr, reconfigure, sr, tdr, Config, ConfigError, CtsPin, Error, Info, Instance,
|
||||
Regs, RtsPin, RxPin, TxPin,
|
||||
clear_interrupt_flags, configure, rdr, reconfigure, send_break, sr, tdr, Config, ConfigError, CtsPin, Error, Info,
|
||||
Instance, Regs, RtsPin, RxPin, TxPin,
|
||||
};
|
||||
use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
|
||||
use crate::interrupt::{self, InterruptExt};
|
||||
@ -359,6 +359,11 @@ impl<'d> BufferedUart<'d> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Send break character
|
||||
pub fn send_break(&self) {
|
||||
self.tx.send_break()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d> BufferedUartRx<'d> {
|
||||
@ -538,6 +543,11 @@ impl<'d> BufferedUartTx<'d> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Send break character
|
||||
pub fn send_break(&self) {
|
||||
send_break(&self.info.regs);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d> Drop for BufferedUartRx<'d> {
|
||||
|
@ -520,6 +520,11 @@ impl<'d, M: Mode> UartTx<'d, M> {
|
||||
pub fn blocking_flush(&mut self) -> Result<(), Error> {
|
||||
blocking_flush(self.info)
|
||||
}
|
||||
|
||||
/// Send break character
|
||||
pub fn send_break(&self) {
|
||||
send_break(&self.info.regs);
|
||||
}
|
||||
}
|
||||
|
||||
fn blocking_flush(info: &Info) -> Result<(), Error> {
|
||||
@ -534,6 +539,21 @@ fn blocking_flush(info: &Info) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Send break character
|
||||
pub fn send_break(regs: &Regs) {
|
||||
// Busy wait until previous break has been sent
|
||||
#[cfg(any(usart_v1, usart_v2))]
|
||||
while regs.cr1().read().sbk() {}
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
while regs.isr().read().sbkf() {}
|
||||
|
||||
// Send break right after completing the current character transmission
|
||||
#[cfg(any(usart_v1, usart_v2))]
|
||||
regs.cr1().modify(|w| w.set_sbk(true));
|
||||
#[cfg(any(usart_v3, usart_v4))]
|
||||
regs.rqr().write(|w| w.set_sbkrq(true));
|
||||
}
|
||||
|
||||
impl<'d> UartRx<'d, Async> {
|
||||
/// Create a new rx-only UART with no hardware flow control.
|
||||
///
|
||||
@ -1365,6 +1385,11 @@ impl<'d, M: Mode> Uart<'d, M> {
|
||||
pub fn split(self) -> (UartTx<'d, M>, UartRx<'d, M>) {
|
||||
(self.tx, self.rx)
|
||||
}
|
||||
|
||||
/// Send break character
|
||||
pub fn send_break(&self) {
|
||||
self.tx.send_break();
|
||||
}
|
||||
}
|
||||
|
||||
fn reconfigure(info: &Info, kernel_clock: Hertz, config: &Config) -> Result<(), ConfigError> {
|
||||
|
Loading…
Reference in New Issue
Block a user