diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 791501d8f..4fbe8f26d 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -196,6 +196,11 @@ impl> UartPeripheral { super::reader::read_full_blocking(&self.device, buffer) } + /// Initiates a break + pub fn send_break(&mut self) -> super::writer::Break<'_, D> { + super::writer::Break::new(&mut self.device) + } + /// Join the reader and writer halves together back into the original Uart peripheral. /// /// A reader/writer pair can be obtained by calling [`split`]. diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index 410f4f585..893a34e1b 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -123,6 +123,19 @@ pub(crate) fn disable_tx_interrupt(rb: &RegisterBlock) { }); } +/// A break on the current object +pub struct Break<'a, T>(&'a mut T); +impl<'a, T: UartDevice> Break<'a, T> { + pub(crate) fn new(dev: &'a mut T) -> Self { + dev.uartlcr_h.modify(|_,w| w.brk().set_bit()); + Break(dev) + } + /// Stop the break + pub fn clear(self) { + self.0.uartlcr_h.modify(|_,w| w.brk().clear_bit()); + } +} + /// Half of an [`UartPeripheral`] that is only capable of writing. Obtained by calling [`UartPeripheral::split()`] /// /// [`UartPeripheral`]: struct.UartPeripheral.html @@ -164,6 +177,11 @@ impl> Writer { pub fn disable_tx_interrupt(&mut self) { disable_tx_interrupt(&self.device) } + + /// Initiates a break + pub fn send_break(&mut self) -> Break<'_, D> { + Break::new(&mut self.device) + } } impl> Write for Writer {