diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 2c349e55..76db0a76 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -91,6 +91,7 @@ fn main() { struct SplitFeature { feature_name: String, pin_name_with_c: String, + #[cfg(feature = "_split-pins-enabled")] pin_name_without_c: String, } diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index f32dd0f0..0d2bfc06 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -518,7 +518,8 @@ impl Timings { impl<'d, T: Instance> SetConfig for I2c<'d, T> { type Config = Hertz; - fn set_config(&mut self, config: &Self::Config) { + type ConfigError = (); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { let timings = Timings::new(T::frequency(), *config); T::regs().cr2().modify(|reg| { reg.set_freq(timings.freq); @@ -531,5 +532,7 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> { T::regs().trise().modify(|reg| { reg.set_trise(timings.trise); }); + + Ok(()) } } diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 36f70e32..543d8f1b 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -1075,7 +1075,8 @@ mod eha { impl<'d, T: Instance> SetConfig for I2c<'d, T> { type Config = Hertz; - fn set_config(&mut self, config: &Self::Config) { + type ConfigError = (); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { let timings = Timings::new(T::frequency(), *config); T::regs().timingr().write(|reg| { reg.set_presc(timings.prescale); @@ -1084,5 +1085,7 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> { reg.set_sdadel(timings.sdadel); reg.set_scldel(timings.scldel); }); + + Ok(()) } } diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 2741b790..5eecb637 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs @@ -982,8 +982,9 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> { ch.cr2().modify(|w| w.set_mute(value)); } + #[allow(dead_code)] /// Reconfigures it with the supplied config. - pub fn reconfigure(&mut self, _config: Config) {} + fn reconfigure(&mut self, _config: Config) {} pub fn get_current_config(&self) -> Config { Config::default() @@ -1056,7 +1057,10 @@ foreach_peripheral!( impl<'d, T: Instance> SetConfig for Sai<'d, T> { type Config = Config; - fn set_config(&mut self, _config: &Self::Config) { + type ConfigError = (); + fn set_config(&mut self, _config: &Self::Config) -> Result<(), ()> { // self.reconfigure(*config); + + Ok(()) } } diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index f40bce78..14333ba2 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -323,7 +323,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { } /// Reconfigures it with the supplied config. - pub fn set_config(&mut self, config: Config) { + fn set_config(&mut self, config: Config) { let cpha = config.raw_phase(); let cpol = config.raw_polarity(); @@ -1061,7 +1061,10 @@ foreach_peripheral!( impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx> { type Config = Config; - fn set_config(&mut self, config: &Self::Config) { + type ConfigError = (); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { self.set_config(*config); + + Ok(()) } } diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index e2d6e42a..445ca0ed 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -116,25 +116,28 @@ pub struct BufferedUartRx<'d, T: BasicInstance> { impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.set_config(config)) + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.set_config(config).map_err(|_| ()) } } impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.set_config(config)) + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.set_config(config).map_err(|_| ()) } } impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.set_config(config)) + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.set_config(config).map_err(|_| ()) } } @@ -253,7 +256,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { (self.tx, self.rx) } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { + fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } } @@ -333,7 +336,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> { } } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { + fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } } @@ -407,7 +410,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> { } } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { + fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } } diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 9835f1ac..2eb2e4e8 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -181,10 +181,11 @@ pub struct Uart<'d, T: BasicInstance, TxDma = NoDma, RxDma = NoDma> { impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.tx.set_config(config)); - unwrap!(self.rx.set_config(config)); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.tx.set_config(config).map_err(|_| ())?; + self.rx.set_config(config).map_err(|_| ()) } } @@ -195,9 +196,10 @@ pub struct UartTx<'d, T: BasicInstance, TxDma = NoDma> { impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.set_config(config)); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.set_config(config).map_err(|_| ()) } } @@ -211,9 +213,10 @@ pub struct UartRx<'d, T: BasicInstance, RxDma = NoDma> { impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.set_config(config)); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.set_config(config).map_err(|_| ()) } } @@ -273,7 +276,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { }) } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { + fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } @@ -374,7 +377,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { }) } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { + fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { reconfigure::(config) } @@ -803,10 +806,6 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { }) } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { - reconfigure::(config) - } - pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> where TxDma: crate::usart::TxDma, diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index 347aae7c..535d1b1f 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs @@ -18,9 +18,10 @@ pub struct RingBufferedUartRx<'d, T: BasicInstance, RxDma: super::RxDma> { impl<'d, T: BasicInstance, RxDma: super::RxDma> SetConfig for RingBufferedUartRx<'d, T, RxDma> { type Config = Config; + type ConfigError = (); - fn set_config(&mut self, config: &Self::Config) { - unwrap!(self.set_config(config)); + fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { + self.set_config(config).map_err(|_| ()) } } @@ -63,7 +64,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma> RingBufferedUartRx<'d, T, RxD Err(err) } - pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { + fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { self.teardown_uart(); reconfigure::(config) }