Skip to content

Commit

Permalink
Remove redundant config setters
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Dec 20, 2024
1 parent f83ab23 commit 6029c90
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 58 deletions.
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `parl_io::{no_clk_pin(), NoClkPin}` (#2531)
- Removed `get_core` function in favour of `Cpu::current` (#2533)

- Removed `uart::Config` setters and `symbol_length`. (#2847)

## [0.21.1]

### Fixed
Expand Down
14 changes: 13 additions & 1 deletion esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ is enabled. To retrieve the address and size of the initialized external memory,

The usage of `esp_alloc::psram_allocator!` remains unchanged.


## embedded-hal 0.2.* is not supported anymore.

As per https://github.com/rust-embedded/embedded-hal/pull/640, our driver no longer implements traits from `embedded-hal 0.2.x`.
Expand Down Expand Up @@ -317,3 +316,16 @@ To avoid abbreviations and contractions (as per the esp-hal guidelines), some er
- Error::InvalidZeroLength
+ Error::ZeroLengthInvalid
```

## UART changes

The `Config` struct's setters are now prefixed with `with_`. `parity_none`, `parity_even`,
`parity_odd` have been replaced by `with_parity` that takes a `Parity` parameter.

```diff
let config = Config::default()
- .rx_fifo_full_threshold(30)
+ .with_rx_fifo_full_threshold(30)
- .parity_even();
+ .with_parity(Parity::Even);
```
58 changes: 2 additions & 56 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
any(esp32s2, esp32s3),
doc = "let (tx_pin, rx_pin) = (peripherals.GPIO43, peripherals.GPIO44);"
)]
//! let config = Config::default().rx_fifo_full_threshold(30);
//! let config = Config::default().with_rx_fifo_full_threshold(30);
//!
//! let mut uart0 = Uart::new(
//! peripherals.UART0,
Expand Down Expand Up @@ -421,51 +421,9 @@ pub struct Config {
}

impl Config {
/// Sets the baud rate for the UART configuration.
pub fn baudrate(mut self, baudrate: u32) -> Self {
self.baudrate = baudrate;
self
}

/// Configures the UART to use no parity check.
pub fn parity_none(mut self) -> Self {
self.parity = Parity::ParityNone;
self
}

/// Configures the UART to use even parity check.
pub fn parity_even(mut self) -> Self {
self.parity = Parity::ParityEven;
self
}

/// Configures the UART to use odd parity check.
pub fn parity_odd(mut self) -> Self {
self.parity = Parity::ParityOdd;
self
}

/// Sets the number of data bits for the UART configuration.
pub fn data_bits(mut self, data_bits: DataBits) -> Self {
self.data_bits = data_bits;
self
}

/// Sets the number of stop bits for the UART configuration.
pub fn stop_bits(mut self, stop_bits: StopBits) -> Self {
self.stop_bits = stop_bits;
self
}

/// Sets the clock source for the UART configuration.
pub fn clock_source(mut self, source: ClockSource) -> Self {
self.clock_source = source;
self
}

/// Calculates the total symbol length in bits based on the configured
/// data bits, parity, and stop bits.
pub fn symbol_length(&self) -> u8 {
fn symbol_length(&self) -> u8 {
let mut length: u8 = 1; // start bit
length += match self.data_bits {
DataBits::DataBits5 => 5,
Expand All @@ -483,18 +441,6 @@ impl Config {
};
length
}

/// Sets the RX FIFO full threshold for the UART configuration.
pub fn rx_fifo_full_threshold(mut self, threshold: u16) -> Self {
self.rx_fifo_full_threshold = threshold;
self
}

/// Sets the RX timeout for the UART configuration.
pub fn rx_timeout(mut self, timeout: Option<u8>) -> Self {
self.rx_timeout = timeout;
self
}
}

impl Default for Config {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/embassy_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async fn main(spawner: Spawner) {
}
}

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

let mut uart0 = Uart::new(peripherals.UART0, config, rx_pin, tx_pin)
.unwrap()
Expand Down

0 comments on commit 6029c90

Please sign in to comment.