Skip to content

Commit

Permalink
Merge pull request #700 from ithinuel/add-send-break
Browse files Browse the repository at this point in the history
Implement `send_break` support
  • Loading branch information
jannic authored Apr 13, 2024
2 parents 9306210 + 8e15127 commit 840e90b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions rp2040-hal/src/uart/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,40 @@ impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Enabled, D, P> {
super::reader::read_full_blocking(&self.device, buffer)
}

/// Initiates a break
///
/// If transmitting, this takes effect immediately after the current byte has completed.
/// For proper execution of the break command, this must be held for at least 2 complete frames
/// worth of time.
///
/// <div class="warning">The device won’t be able to send anything while breaking.</div>
///
/// # Example
///
/// ```no_run
/// # use rp2040_hal::uart::{Pins, ValidUartPinout, Enabled, UartPeripheral};
/// # use rp2040_hal::pac::UART0;
/// # use rp2040_hal::typelevel::OptionTNone;
/// # use embedded_hal_0_2::blocking::delay::DelayUs;
/// # type PINS = Pins<OptionTNone, OptionTNone, OptionTNone, OptionTNone>;
/// # let mut serial: UartPeripheral<Enabled, UART0, PINS> = unsafe { core::mem::zeroed() };
/// # let mut timer: rp2040_hal::Timer = unsafe { core::mem::zeroed() };
/// serial.lowlevel_break_start();
/// // at 115_200Bps on 8N1 configuration, 20bits takes (20*10⁶)/115200 = 173.611…μs.
/// timer.delay_us(175);
/// serial.lowlevel_break_stop();
/// ```
pub fn lowlevel_break_start(&mut self) {
self.device.uartlcr_h().modify(|_, w| w.brk().set_bit());
}

/// Terminates a break condition.
///
/// See `lowlevel_break_start` for more details.
pub fn lowlevel_break_stop(&mut self) {
self.device.uartlcr_h().modify(|_, w| w.brk().clear_bit());
}

/// 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
34 changes: 34 additions & 0 deletions rp2040-hal/src/uart/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,40 @@ impl<D: UartDevice, P: ValidUartPinout<D>> Writer<D, P> {
pub fn disable_tx_interrupt(&mut self) {
disable_tx_interrupt(&self.device)
}

/// Initiates a break
///
/// If transmitting, this takes effect immediately after the current byte has completed.
/// For proper execution of the break command, this must be held for at least 2 complete frames
/// worth of time.
///
/// <div class="warning">The device won’t be able to send anything while breaking.</div>
///
/// # Example
///
/// ```no_run
/// # use rp2040_hal::uart::{Pins, ValidUartPinout, Enabled, UartPeripheral};
/// # use rp2040_hal::pac::UART0;
/// # use rp2040_hal::typelevel::OptionTNone;
/// # use embedded_hal_0_2::blocking::delay::DelayUs;
/// # type PINS = Pins<OptionTNone, OptionTNone, OptionTNone, OptionTNone>;
/// # let mut serial: UartPeripheral<Enabled, UART0, PINS> = unsafe { core::mem::zeroed() };
/// # let mut timer: rp2040_hal::Timer = unsafe { core::mem::zeroed() };
/// serial.lowlevel_break_start();
/// // at 115_200Bps on 8N1 configuration, 20bits takes (20*10⁶)/115200 = 173.611…μs.
/// timer.delay_us(175);
/// serial.lowlevel_break_stop();
/// ```
pub fn lowlevel_break_start(&mut self) {
self.device.uartlcr_h().modify(|_, w| w.brk().set_bit());
}

/// Terminates a break condition.
///
/// See `lowlevel_break_start` for more details.
pub fn lowlevel_break_stop(&mut self) {
self.device.uartlcr_h().modify(|_, w| w.brk().clear_bit());
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ErrorType for Writer<D, P> {
Expand Down

0 comments on commit 840e90b

Please sign in to comment.