Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5aa0565

Browse files
committedJan 31, 2025
updates
1 parent 9081406 commit 5aa0565

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed
 

‎esp-hal/src/lcd_cam/cam.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ impl<'d> Camera<'d> {
168168
}
169169

170170
/// Applies the configuration to the camera interface.
171-
///
171+
///
172172
/// # Errors
173173
///
174-
/// A [`ConfigError`] variant will be returned if the frequency passed in `Config` is too low.
174+
/// A [`ConfigError`] variant will be returned if the frequency passed in
175+
/// `Config` is too low.
175176
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
176177
let clocks = Clocks::get();
177178
let (i, divider) = calculate_clkm(

‎esp-hal/src/lcd_cam/lcd/dpi.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ where
170170
}
171171

172172
/// Applies the configuration to the peripheral.
173-
///
173+
///
174174
/// # Errors
175175
///
176-
/// A [`ConfigError`] variant will be returned if the frequency passed in `Config` is too low.
176+
/// A [`ConfigError`] variant will be returned if the frequency passed in
177+
/// `Config` is too low.
177178
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
178179
let clocks = Clocks::get();
179180
// Due to https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf

‎esp-hal/src/lcd_cam/lcd/i8080.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ where
135135
}
136136

137137
/// Applies configuration.
138-
///
138+
///
139139
/// # Errors
140140
///
141-
/// A [`ConfigError`] variant will be returned if the frequency passed in `Config` is too low.
141+
/// A [`ConfigError`] variant will be returned if the frequency passed in
142+
/// `Config` is too low.
142143
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
143144
let clocks = Clocks::get();
144145
// Due to https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf

‎esp-hal/src/spi/master.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,14 @@ impl Config {
596596
fn raw_clock_reg_value(&self) -> Result<u32, ConfigError> {
597597
self.reg
598598
}
599+
600+
fn validate(&self) -> Result<(), ConfigError> {
601+
// Max supported frequency is 80Mhz
602+
if self.frequency > HertzU32::MHz(80) {
603+
return Err(ConfigError::UnsupportedFrequency);
604+
}
605+
Ok(())
606+
}
599607
}
600608

601609
#[derive(Debug)]
@@ -613,7 +621,22 @@ struct SpiPinGuard {
613621
#[non_exhaustive]
614622
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
615623
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
616-
pub enum ConfigError {}
624+
pub enum ConfigError {
625+
/// The requested frequency is not supported.
626+
UnsupportedFrequency,
627+
}
628+
629+
impl core::error::Error for ConfigError {}
630+
631+
impl core::fmt::Display for ConfigError {
632+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
633+
match self {
634+
ConfigError::UnsupportedFrequency => {
635+
write!(f, " The requested frequency is not supported")
636+
}
637+
}
638+
}
639+
}
617640

618641
/// SPI peripheral driver
619642
///
@@ -994,6 +1017,10 @@ where
9941017
}
9951018

9961019
/// Change the bus configuration.
1020+
///
1021+
/// # Errors.
1022+
/// If frequency passed in config exceeds 80Mhz, a corresponding
1023+
/// [`ConfigError`] variant will be returned.
9971024
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
9981025
self.driver().apply_config(config)
9991026
}
@@ -1565,6 +1592,10 @@ mod dma {
15651592
}
15661593

15671594
/// Change the bus configuration.
1595+
///
1596+
/// # Errors.
1597+
/// If frequency passed in config exceeds 80Mhz, a corresponding
1598+
/// [`ConfigError`] variant will be returned.
15681599
#[instability::unstable]
15691600
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
15701601
self.driver().apply_config(config)
@@ -2027,6 +2058,10 @@ mod dma {
20272058
}
20282059

20292060
/// Change the bus configuration.
2061+
///
2062+
/// # Errors.
2063+
/// If frequency passed in config exceeds 80Mhz, a corresponding
2064+
/// [`ConfigError`] variant will be returned.
20302065
#[instability::unstable]
20312066
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
20322067
self.spi_dma.apply_config(config)
@@ -3073,6 +3108,7 @@ impl Driver {
30733108
}
30743109

30753110
fn apply_config(&self, config: &Config) -> Result<(), ConfigError> {
3111+
config.validate()?;
30763112
self.ch_bus_freq(config)?;
30773113
self.set_bit_order(config.read_bit_order, config.write_bit_order);
30783114
self.set_data_mode(config.mode);

‎esp-hal/src/uart.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ impl Config {
349349
};
350350
length
351351
}
352+
353+
fn validate(&self) -> Result<(), ConfigError> {
354+
// Max supported baud rate is 5Mbaud
355+
if self.baudrate == 0 || self.baudrate > 5_000_000 {
356+
return Err(ConfigError::UnsupportedBaudrate);
357+
}
358+
Ok(())
359+
}
352360
}
353361

354362
/// Configuration for the AT-CMD detection functionality
@@ -455,6 +463,8 @@ pub struct UartRx<'d, Dm> {
455463
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
456464
#[non_exhaustive]
457465
pub enum ConfigError {
466+
/// The requested baud rate is not supported.
467+
UnsupportedBaudrate,
458468
/// The requested timeout is not supported.
459469
UnsupportedTimeout,
460470
/// The requested FIFO threshold is not supported.
@@ -466,6 +476,9 @@ impl core::error::Error for ConfigError {}
466476
impl core::fmt::Display for ConfigError {
467477
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
468478
match self {
479+
ConfigError::UnsupportedBaudrate => {
480+
write!(f, "The requested baud rate is not supported")
481+
}
469482
ConfigError::UnsupportedTimeout => write!(f, "The requested timeout is not supported"),
470483
ConfigError::UnsupportedFifoThreshold => {
471484
write!(f, "The requested FIFO threshold is not supported")
@@ -1178,7 +1191,8 @@ where
11781191
///
11791192
/// # Errors.
11801193
/// Errors will be returned in the cases described in
1181-
/// [`UartRx::apply_config`].
1194+
/// [`UartRx::apply_config`] and if baud rate passed in config exceeds
1195+
/// 5MBaud or is equal to zero.
11821196
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
11831197
self.rx.apply_config(config)?;
11841198
self.tx.apply_config(config)?;
@@ -2190,6 +2204,7 @@ impl Info {
21902204
}
21912205

21922206
fn apply_config(&self, config: &Config) -> Result<(), ConfigError> {
2207+
config.validate()?;
21932208
self.change_baud(config);
21942209
self.change_data_bits(config.data_bits);
21952210
self.change_parity(config.parity);

0 commit comments

Comments
 (0)
Please sign in to comment.