Skip to content

Commit

Permalink
Return ConfigError
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 5, 2024
1 parent da32819 commit b9762e8
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions esp-hal/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//! [`embedded-hal-bus`]: https://docs.rs/embedded-hal-bus/latest/embedded_hal_bus/spi/index.html
//! [`embassy-embedded-hal`]: https://docs.embassy.dev/embassy-embedded-hal/git/default/shared_bus/index.html
use core::{convert::Infallible, marker::PhantomData};
use core::marker::PhantomData;

pub use dma::*;
use embassy_embedded_hal::SetConfig;
Expand Down Expand Up @@ -469,6 +469,11 @@ impl Default for Config {
}
}

/// Configuration errors.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConfigError {}

/// SPI peripheral driver
pub struct Spi<'d, M, T = AnySpi> {
spi: PeripheralRef<'d, T>,
Expand Down Expand Up @@ -677,8 +682,8 @@ where
}

/// Change the bus configuration.
pub fn apply_config(&mut self, config: &Config) {
self.driver().apply_config(config);
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
self.driver().apply_config(config)
}
}

Expand All @@ -688,11 +693,10 @@ where
M: Mode,
{
type Config = Config;
type ConfigError = Infallible;
type ConfigError = ConfigError;

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError> {
self.apply_config(config);
Ok(())
self.apply_config(config)
}
}

Expand Down Expand Up @@ -1205,8 +1209,8 @@ mod dma {
}

/// Change the bus configuration.
pub fn apply_config(&mut self, config: &Config) {
self.driver().apply_config(config);
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
self.driver().apply_config(config)
}

/// Configures the DMA buffers for the SPI instance.
Expand All @@ -1229,11 +1233,10 @@ mod dma {
M: Mode,
{
type Config = Config;
type ConfigError = Infallible;
type ConfigError = ConfigError;

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError> {
self.apply_config(config);
Ok(())
self.apply_config(config)
}
}

Expand Down Expand Up @@ -1638,8 +1641,8 @@ mod dma {
}

/// Change the bus configuration.
pub fn apply_config(&mut self, config: &Config) {
self.spi_dma.apply_config(config);
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError> {
self.spi_dma.apply_config(config)
}

/// Reads data from the SPI bus using DMA.
Expand Down Expand Up @@ -1806,11 +1809,10 @@ mod dma {
M: Mode,
{
type Config = Config;
type ConfigError = Infallible;
type ConfigError = ConfigError;

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError> {
self.apply_config(config);
Ok(())
self.apply_config(config)
}
}

Expand Down Expand Up @@ -2620,10 +2622,11 @@ impl Info {
});
}

fn apply_config(&self, config: &Config) {
fn apply_config(&self, config: &Config) -> Result<(), ConfigError> {
self.ch_bus_freq(config.frequency);
self.set_bit_order(config.read_bit_order, config.write_bit_order);
self.set_data_mode(config.mode);
Ok(())
}

fn set_data_mode(&self, data_mode: SpiMode) {
Expand Down

0 comments on commit b9762e8

Please sign in to comment.