Skip to content

Commit eb29eb0

Browse files
Support for sending UART break conditions (#535)
* Add functions to send over UART with a break * Fix format * Update CHANGELOG * Fixed missing argument
1 parent a371755 commit eb29eb0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- `Send` for `AsyncCanDriver`
1515
- `DB_12` ADC attenuation
1616
- `fade_with_time`, `fade_with_step`, `fade_stop` for `LedcDriver`
17+
- `write_with_break` for `UartDriver` and `UartTxDriver`
1718

1819
### Fixed
1920
- Fix pcnt_rotary_encoder example for esp32

src/uart.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,11 @@ impl<'d> UartDriver<'d> {
884884
self.tx().write(bytes)
885885
}
886886

887+
/// Write multiple bytes from a slice, then send a break condition.
888+
pub fn write_with_break(&self, bytes: &[u8], brk_len: i32) -> Result<usize, EspError> {
889+
self.tx().write_with_break(bytes, brk_len)
890+
}
891+
887892
/// Write multiple bytes from a slice directly to the TX FIFO hardware.
888893
/// Returns the number of bytes written, where 0 would mean that the TX FIFO is full.
889894
///
@@ -1366,6 +1371,20 @@ impl<'d> UartTxDriver<'d> {
13661371
}
13671372
}
13681373

1374+
/// Write multiple bytes from a slice, then send a break condition.
1375+
pub fn write_with_break(&mut self, bytes: &[u8], brk_len: i32) -> Result<usize, EspError> {
1376+
// `uart_write_bytes_with_break()` returns error (-1) or how many bytes were written
1377+
let len = unsafe {
1378+
uart_write_bytes_with_break(self.port(), bytes.as_ptr().cast(), bytes.len(), brk_len)
1379+
};
1380+
1381+
if len >= 0 {
1382+
Ok(len as usize)
1383+
} else {
1384+
Err(EspError::from_infallible::<ESP_ERR_INVALID_STATE>())
1385+
}
1386+
}
1387+
13691388
/// Write multiple bytes from a slice directly to the TX FIFO hardware.
13701389
/// Returns the number of bytes written, where 0 would mean that the TX FIFO is full.
13711390
///

0 commit comments

Comments
 (0)