Skip to content

Commit

Permalink
Implement send_break support
Browse files Browse the repository at this point in the history
  • Loading branch information
ithinuel committed Oct 18, 2023
1 parent 9bde6b5 commit 1d80e9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rp2040-hal/src/uart/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Enabled, D, P> {
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`].
Expand Down
18 changes: 18 additions & 0 deletions rp2040-hal/src/uart/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -164,6 +177,11 @@ impl<D: UartDevice, P: ValidUartPinout<D>> Writer<D, P> {
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<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for Writer<D, P> {
Expand Down

0 comments on commit 1d80e9b

Please sign in to comment.