Extend set_baudrate implementation to Buffered and RingBuffered structs

This commit is contained in:
Enmanuel Parache 2024-11-09 12:38:02 -04:00
parent 3c1c1d6b93
commit eac8653c00
2 changed files with 27 additions and 3 deletions

View File

@ -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, send_break, sr, tdr, Config, ConfigError, CtsPin, Error, Info,
Instance, Regs, RtsPin, RxPin, TxPin,
clear_interrupt_flags, configure, rdr, reconfigure, send_break, set_baudrate, 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};
@ -441,6 +441,13 @@ impl<'d> BufferedUart<'d> {
pub fn send_break(&self) {
self.tx.send_break()
}
/// Set baudrate
pub fn set_baudrate(&self, baudrate: u32) -> Result<(), ConfigError> {
self.tx.set_baudrate(baudrate)?;
self.rx.set_baudrate(baudrate)?;
Ok(())
}
}
impl<'d> BufferedUartRx<'d> {
@ -535,6 +542,11 @@ impl<'d> BufferedUartRx<'d> {
Ok(())
}
/// Set baudrate
pub fn set_baudrate(&self, baudrate: u32) -> Result<(), ConfigError> {
set_baudrate(self.info, self.kernel_clock, baudrate)
}
}
impl<'d> BufferedUartTx<'d> {
@ -625,6 +637,11 @@ impl<'d> BufferedUartTx<'d> {
pub fn send_break(&self) {
send_break(&self.info.regs);
}
/// Set baudrate
pub fn set_baudrate(&self, baudrate: u32) -> Result<(), ConfigError> {
set_baudrate(self.info, self.kernel_clock, baudrate)
}
}
impl<'d> Drop for BufferedUartRx<'d> {

View File

@ -8,7 +8,9 @@ use embassy_hal_internal::PeripheralRef;
use embedded_io_async::ReadReady;
use futures_util::future::{select, Either};
use super::{clear_interrupt_flags, rdr, reconfigure, sr, Config, ConfigError, Error, Info, State, UartRx};
use super::{
clear_interrupt_flags, rdr, reconfigure, set_baudrate, sr, Config, ConfigError, Error, Info, State, UartRx,
};
use crate::dma::ReadableRingBuffer;
use crate::gpio::{AnyPin, SealedPin as _};
use crate::mode::Async;
@ -213,6 +215,11 @@ impl<'d> RingBufferedUartRx<'d> {
Either::Right(((), _)) => Ok(()),
}
}
/// Set baudrate
pub fn set_baudrate(&self, baudrate: u32) -> Result<(), ConfigError> {
set_baudrate(self.info, self.kernel_clock, baudrate)
}
}
impl Drop for RingBufferedUartRx<'_> {