Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement send_break support #700

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ithinuel marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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>> Write02<u8> for Writer<D, P> {
Expand Down
Loading