This commit is contained in:
Zach Grimaldi 2025-01-08 11:43:06 +08:00 committed by GitHub
commit 3893caf773
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `gpio::{Event, WakeEvent, GpioRegisterAccess}` now implement `Debug`, `Eq`, `PartialEq` and `Hash` (#2842) - `gpio::{Event, WakeEvent, GpioRegisterAccess}` now implement `Debug`, `Eq`, `PartialEq` and `Hash` (#2842)
- `gpio::{Level, Pull, AlternateFunction, RtcFunction}` now implement `Hash` (#2842) - `gpio::{Level, Pull, AlternateFunction, RtcFunction}` now implement `Hash` (#2842)
- `gpio::{GpioPin, AnyPin, Io, Output, OutputOpenDrain, Input, Flex}` now implement `Debug`, `defmt::Format` (#2842) - `gpio::{GpioPin, AnyPin, Io, Output, OutputOpenDrain, Input, Flex}` now implement `Debug`, `defmt::Format` (#2842)
- Add `tx_idle_num` to `uart::Config` with documentation of the expected transmission behavior (#2859)
- More interrupts are available in `esp_hal::spi::master::SpiInterrupt`, add `enable_listen`,`interrupts` and `clear_interrupts` for ESP32/ESP32-S2 (#2833) - More interrupts are available in `esp_hal::spi::master::SpiInterrupt`, add `enable_listen`,`interrupts` and `clear_interrupts` for ESP32/ESP32-S2 (#2833)
- The `ExtU64` and `RateExtU32` traits have been added to `esp_hal::time` (#2845) - The `ExtU64` and `RateExtU32` traits have been added to `esp_hal::time` (#2845)
- Added `AnyPin::steal(pin_number)` (#2854) - Added `AnyPin::steal(pin_number)` (#2854)

View File

@ -410,6 +410,11 @@ pub struct Config {
pub rx_fifo_full_threshold: u16, pub rx_fifo_full_threshold: u16,
/// Optional timeout value for RX operations. /// Optional timeout value for RX operations.
pub rx_timeout: Option<u8>, pub rx_timeout: Option<u8>,
/// Duration between transfers in the unit of bit time, i.e. the time it
/// takes to transfer one bit. If you are expecting bytes written to
/// be sent immediately, set this to 0. Default value is 256,
/// maximum value is 1023.
pub tx_idle_num: u16,
} }
impl Config { impl Config {
@ -445,6 +450,7 @@ impl Default for Config {
clock_source: Default::default(), clock_source: Default::default(),
rx_fifo_full_threshold: UART_FULL_THRESH_DEFAULT, rx_fifo_full_threshold: UART_FULL_THRESH_DEFAULT,
rx_timeout: Some(UART_TOUT_THRESH_DEFAULT), rx_timeout: Some(UART_TOUT_THRESH_DEFAULT),
tx_idle_num: 256,
} }
} }
} }
@ -568,6 +574,10 @@ pub enum ConfigError {
UnsupportedTimeout, UnsupportedTimeout,
/// The requested FIFO threshold is not supported. /// The requested FIFO threshold is not supported.
UnsupportedFifoThreshold, UnsupportedFifoThreshold,
/// The requested idle number is not supported.
/// Valid range is 0..=1023 in the unit of bit time,
/// i.e. the time it takes to transfer one bit.
UnsupportedIdleNum,
} }
impl core::error::Error for ConfigError {} impl core::error::Error for ConfigError {}
@ -579,6 +589,9 @@ impl core::fmt::Display for ConfigError {
ConfigError::UnsupportedFifoThreshold => { ConfigError::UnsupportedFifoThreshold => {
write!(f, "The requested FIFO threshold is not supported") write!(f, "The requested FIFO threshold is not supported")
} }
ConfigError::UnsupportedIdleNum => {
write!(f, "The requested tx_idle_num is not supported.")
}
} }
} }
} }
@ -2278,6 +2291,7 @@ impl Info {
self.change_data_bits(config.data_bits); self.change_data_bits(config.data_bits);
self.change_parity(config.parity); self.change_parity(config.parity);
self.change_stop_bits(config.stop_bits); self.change_stop_bits(config.stop_bits);
self.change_tx_idle(config.tx_idle_num)?;
// Reset Tx/Rx FIFOs // Reset Tx/Rx FIFOs
self.rxfifo_reset(); self.rxfifo_reset();
@ -2541,6 +2555,18 @@ impl Info {
.modify(|_, w| unsafe { w.stop_bit_num().bits(stop_bits as u8) }); .modify(|_, w| unsafe { w.stop_bit_num().bits(stop_bits as u8) });
} }
fn change_tx_idle(&self, idle_num: u16) -> Result<(), ConfigError> {
// Bits 10:19 => 10-bit register has max value of 1023.
if idle_num > 0x3FF {
return Err(ConfigError::UnsupportedIdleNum);
}
self.register_block()
.idle_conf()
.modify(|_, w| unsafe { w.tx_idle_num().bits(idle_num) });
Ok(())
}
fn rxfifo_reset(&self) { fn rxfifo_reset(&self) {
fn rxfifo_rst(reg_block: &RegisterBlock, enable: bool) { fn rxfifo_rst(reg_block: &RegisterBlock, enable: bool) {
reg_block.conf0().modify(|_, w| w.rxfifo_rst().bit(enable)); reg_block.conf0().modify(|_, w| w.rxfifo_rst().bit(enable));