Skip to content

Commit

Permalink
Properly update the Uart config in examples (#1759)
Browse files Browse the repository at this point in the history
* fix: Properly update the config

* feat: Make rx_timeout optional

* docs: Update changelog
  • Loading branch information
SergioGasquez committed Jul 8, 2024
1 parent 967c478 commit ea34196
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for GPIO wake-up source (#1724)
- dma: add Mem2Mem to support memory to memory transfer (#1738)
- Add `uart` wake source (#1727)
- uart: Make `rx_timeout` optional in Config struct (#1759)

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub mod config {
pub stop_bits: StopBits,
pub clock_source: super::ClockSource,
pub rx_fifo_full_threshold: u16,
pub rx_timeout: u8,
pub rx_timeout: Option<u8>,
}

impl Config {
Expand Down Expand Up @@ -337,7 +337,7 @@ pub mod config {
self
}

pub fn rx_timeout(mut self, timeout: u8) -> Self {
pub fn rx_timeout(mut self, timeout: Option<u8>) -> Self {
self.rx_timeout = timeout;
self
}
Expand All @@ -355,7 +355,7 @@ pub mod config {
#[cfg(not(any(esp32c6, esp32h2, lp_uart)))]
clock_source: super::ClockSource::Apb,
rx_fifo_full_threshold: UART_FULL_THRESH_DEFAULT,
rx_timeout: UART_TOUT_THRESH_DEFAULT,
rx_timeout: Some(UART_TOUT_THRESH_DEFAULT),
}
}
}
Expand Down Expand Up @@ -764,7 +764,7 @@ where
serial
.rx
.set_rx_fifo_full_threshold(config.rx_fifo_full_threshold)?;
serial.rx.set_rx_timeout(Some(config.rx_timeout))?;
serial.rx.set_rx_timeout(config.rx_timeout)?;
serial.change_baud_internal(config.baudrate, config.clock_source, clocks);
serial.change_data_bits(config.data_bits);
serial.change_parity(config.parity);
Expand Down
3 changes: 1 addition & 2 deletions examples/src/bin/embassy_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ async fn main(spawner: Spawner) {
#[cfg(feature = "esp32s3")]
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44);

let config = Config::default();
config.rx_fifo_full_threshold(READ_BUF_SIZE as u16);
let config = Config::default().rx_fifo_full_threshold(READ_BUF_SIZE as u16);

let mut uart0 =
Uart::new_async_with_config(peripherals.UART0, config, &clocks, tx_pin, rx_pin).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions examples/src/bin/serial_interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ fn main() -> ! {
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44);
#[cfg(feature = "esp32s3")]
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44);
let config = Config::default();
config.rx_fifo_full_threshold(30);
let config = Config::default().rx_fifo_full_threshold(30);

let mut uart0 = Uart::new_with_config(
peripherals.UART0,
Expand Down

0 comments on commit ea34196

Please sign in to comment.