diff options
| author | xoviat <[email protected]> | 2023-10-01 09:39:10 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-10-01 09:39:10 -0500 |
| commit | 05218a52e60537a591932b53328087f5f8976728 (patch) | |
| tree | 1fa2f7cdb3be185e04b171481ebc00071a7ddc2e | |
| parent | d2a2734752ed276123a15b58fd8f50c3b531f62d (diff) | |
stm32: update set_config
| -rw-r--r-- | embassy-stm32/build.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v1.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v2.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/sai/mod.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/buffered.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 25 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/ringbuffered.rs | 7 |
8 files changed, 48 insertions, 31 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 2c349e55e..76db0a762 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -91,6 +91,7 @@ fn main() { | |||
| 91 | struct SplitFeature { | 91 | struct SplitFeature { |
| 92 | feature_name: String, | 92 | feature_name: String, |
| 93 | pin_name_with_c: String, | 93 | pin_name_with_c: String, |
| 94 | #[cfg(feature = "_split-pins-enabled")] | ||
| 94 | pin_name_without_c: String, | 95 | pin_name_without_c: String, |
| 95 | } | 96 | } |
| 96 | 97 | ||
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index f32dd0f0c..0d2bfc068 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -518,7 +518,8 @@ impl Timings { | |||
| 518 | 518 | ||
| 519 | impl<'d, T: Instance> SetConfig for I2c<'d, T> { | 519 | impl<'d, T: Instance> SetConfig for I2c<'d, T> { |
| 520 | type Config = Hertz; | 520 | type Config = Hertz; |
| 521 | fn set_config(&mut self, config: &Self::Config) { | 521 | type ConfigError = (); |
| 522 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { | ||
| 522 | let timings = Timings::new(T::frequency(), *config); | 523 | let timings = Timings::new(T::frequency(), *config); |
| 523 | T::regs().cr2().modify(|reg| { | 524 | T::regs().cr2().modify(|reg| { |
| 524 | reg.set_freq(timings.freq); | 525 | reg.set_freq(timings.freq); |
| @@ -531,5 +532,7 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> { | |||
| 531 | T::regs().trise().modify(|reg| { | 532 | T::regs().trise().modify(|reg| { |
| 532 | reg.set_trise(timings.trise); | 533 | reg.set_trise(timings.trise); |
| 533 | }); | 534 | }); |
| 535 | |||
| 536 | Ok(()) | ||
| 534 | } | 537 | } |
| 535 | } | 538 | } |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 36f70e32e..543d8f1b4 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -1075,7 +1075,8 @@ mod eha { | |||
| 1075 | 1075 | ||
| 1076 | impl<'d, T: Instance> SetConfig for I2c<'d, T> { | 1076 | impl<'d, T: Instance> SetConfig for I2c<'d, T> { |
| 1077 | type Config = Hertz; | 1077 | type Config = Hertz; |
| 1078 | fn set_config(&mut self, config: &Self::Config) { | 1078 | type ConfigError = (); |
| 1079 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { | ||
| 1079 | let timings = Timings::new(T::frequency(), *config); | 1080 | let timings = Timings::new(T::frequency(), *config); |
| 1080 | T::regs().timingr().write(|reg| { | 1081 | T::regs().timingr().write(|reg| { |
| 1081 | reg.set_presc(timings.prescale); | 1082 | reg.set_presc(timings.prescale); |
| @@ -1084,5 +1085,7 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> { | |||
| 1084 | reg.set_sdadel(timings.sdadel); | 1085 | reg.set_sdadel(timings.sdadel); |
| 1085 | reg.set_scldel(timings.scldel); | 1086 | reg.set_scldel(timings.scldel); |
| 1086 | }); | 1087 | }); |
| 1088 | |||
| 1089 | Ok(()) | ||
| 1087 | } | 1090 | } |
| 1088 | } | 1091 | } |
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 2741b790b..5eecb637b 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> { | |||
| 982 | ch.cr2().modify(|w| w.set_mute(value)); | 982 | ch.cr2().modify(|w| w.set_mute(value)); |
| 983 | } | 983 | } |
| 984 | 984 | ||
| 985 | #[allow(dead_code)] | ||
| 985 | /// Reconfigures it with the supplied config. | 986 | /// Reconfigures it with the supplied config. |
| 986 | pub fn reconfigure(&mut self, _config: Config) {} | 987 | fn reconfigure(&mut self, _config: Config) {} |
| 987 | 988 | ||
| 988 | pub fn get_current_config(&self) -> Config { | 989 | pub fn get_current_config(&self) -> Config { |
| 989 | Config::default() | 990 | Config::default() |
| @@ -1056,7 +1057,10 @@ foreach_peripheral!( | |||
| 1056 | 1057 | ||
| 1057 | impl<'d, T: Instance> SetConfig for Sai<'d, T> { | 1058 | impl<'d, T: Instance> SetConfig for Sai<'d, T> { |
| 1058 | type Config = Config; | 1059 | type Config = Config; |
| 1059 | fn set_config(&mut self, _config: &Self::Config) { | 1060 | type ConfigError = (); |
| 1061 | fn set_config(&mut self, _config: &Self::Config) -> Result<(), ()> { | ||
| 1060 | // self.reconfigure(*config); | 1062 | // self.reconfigure(*config); |
| 1063 | |||
| 1064 | Ok(()) | ||
| 1061 | } | 1065 | } |
| 1062 | } | 1066 | } |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index f40bce784..14333ba26 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> { | |||
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | /// Reconfigures it with the supplied config. | 325 | /// Reconfigures it with the supplied config. |
| 326 | pub fn set_config(&mut self, config: Config) { | 326 | fn set_config(&mut self, config: Config) { |
| 327 | let cpha = config.raw_phase(); | 327 | let cpha = config.raw_phase(); |
| 328 | let cpol = config.raw_polarity(); | 328 | let cpol = config.raw_polarity(); |
| 329 | 329 | ||
| @@ -1061,7 +1061,10 @@ foreach_peripheral!( | |||
| 1061 | 1061 | ||
| 1062 | impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx> { | 1062 | impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx> { |
| 1063 | type Config = Config; | 1063 | type Config = Config; |
| 1064 | fn set_config(&mut self, config: &Self::Config) { | 1064 | type ConfigError = (); |
| 1065 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { | ||
| 1065 | self.set_config(*config); | 1066 | self.set_config(*config); |
| 1067 | |||
| 1068 | Ok(()) | ||
| 1066 | } | 1069 | } |
| 1067 | } | 1070 | } |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index e2d6e42af..445ca0edc 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> { | |||
| 116 | 116 | ||
| 117 | impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> { | 117 | impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> { |
| 118 | type Config = Config; | 118 | type Config = Config; |
| 119 | type ConfigError = (); | ||
| 119 | 120 | ||
| 120 | fn set_config(&mut self, config: &Self::Config) { | 121 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 121 | unwrap!(self.set_config(config)) | 122 | self.set_config(config).map_err(|_| ()) |
| 122 | } | 123 | } |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 125 | impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> { | 126 | impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> { |
| 126 | type Config = Config; | 127 | type Config = Config; |
| 128 | type ConfigError = (); | ||
| 127 | 129 | ||
| 128 | fn set_config(&mut self, config: &Self::Config) { | 130 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 129 | unwrap!(self.set_config(config)) | 131 | self.set_config(config).map_err(|_| ()) |
| 130 | } | 132 | } |
| 131 | } | 133 | } |
| 132 | 134 | ||
| 133 | impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> { | 135 | impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> { |
| 134 | type Config = Config; | 136 | type Config = Config; |
| 137 | type ConfigError = (); | ||
| 135 | 138 | ||
| 136 | fn set_config(&mut self, config: &Self::Config) { | 139 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 137 | unwrap!(self.set_config(config)) | 140 | self.set_config(config).map_err(|_| ()) |
| 138 | } | 141 | } |
| 139 | } | 142 | } |
| 140 | 143 | ||
| @@ -253,7 +256,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { | |||
| 253 | (self.tx, self.rx) | 256 | (self.tx, self.rx) |
| 254 | } | 257 | } |
| 255 | 258 | ||
| 256 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 259 | fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 257 | reconfigure::<T>(config) | 260 | reconfigure::<T>(config) |
| 258 | } | 261 | } |
| 259 | } | 262 | } |
| @@ -333,7 +336,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> { | |||
| 333 | } | 336 | } |
| 334 | } | 337 | } |
| 335 | 338 | ||
| 336 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 339 | fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 337 | reconfigure::<T>(config) | 340 | reconfigure::<T>(config) |
| 338 | } | 341 | } |
| 339 | } | 342 | } |
| @@ -407,7 +410,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> { | |||
| 407 | } | 410 | } |
| 408 | } | 411 | } |
| 409 | 412 | ||
| 410 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 413 | fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 411 | reconfigure::<T>(config) | 414 | reconfigure::<T>(config) |
| 412 | } | 415 | } |
| 413 | } | 416 | } |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 9835f1ace..2eb2e4e88 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> { | |||
| 181 | 181 | ||
| 182 | impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> { | 182 | impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> { |
| 183 | type Config = Config; | 183 | type Config = Config; |
| 184 | type ConfigError = (); | ||
| 184 | 185 | ||
| 185 | fn set_config(&mut self, config: &Self::Config) { | 186 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 186 | unwrap!(self.tx.set_config(config)); | 187 | self.tx.set_config(config).map_err(|_| ())?; |
| 187 | unwrap!(self.rx.set_config(config)); | 188 | self.rx.set_config(config).map_err(|_| ()) |
| 188 | } | 189 | } |
| 189 | } | 190 | } |
| 190 | 191 | ||
| @@ -195,9 +196,10 @@ pub struct UartTx<'d, T: BasicInstance, TxDma = NoDma> { | |||
| 195 | 196 | ||
| 196 | impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> { | 197 | impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> { |
| 197 | type Config = Config; | 198 | type Config = Config; |
| 199 | type ConfigError = (); | ||
| 198 | 200 | ||
| 199 | fn set_config(&mut self, config: &Self::Config) { | 201 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 200 | unwrap!(self.set_config(config)); | 202 | self.set_config(config).map_err(|_| ()) |
| 201 | } | 203 | } |
| 202 | } | 204 | } |
| 203 | 205 | ||
| @@ -211,9 +213,10 @@ pub struct UartRx<'d, T: BasicInstance, RxDma = NoDma> { | |||
| 211 | 213 | ||
| 212 | impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> { | 214 | impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> { |
| 213 | type Config = Config; | 215 | type Config = Config; |
| 216 | type ConfigError = (); | ||
| 214 | 217 | ||
| 215 | fn set_config(&mut self, config: &Self::Config) { | 218 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 216 | unwrap!(self.set_config(config)); | 219 | self.set_config(config).map_err(|_| ()) |
| 217 | } | 220 | } |
| 218 | } | 221 | } |
| 219 | 222 | ||
| @@ -273,7 +276,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> { | |||
| 273 | }) | 276 | }) |
| 274 | } | 277 | } |
| 275 | 278 | ||
| 276 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 279 | fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 277 | reconfigure::<T>(config) | 280 | reconfigure::<T>(config) |
| 278 | } | 281 | } |
| 279 | 282 | ||
| @@ -374,7 +377,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { | |||
| 374 | }) | 377 | }) |
| 375 | } | 378 | } |
| 376 | 379 | ||
| 377 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 380 | fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 378 | reconfigure::<T>(config) | 381 | reconfigure::<T>(config) |
| 379 | } | 382 | } |
| 380 | 383 | ||
| @@ -803,10 +806,6 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 803 | }) | 806 | }) |
| 804 | } | 807 | } |
| 805 | 808 | ||
| 806 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | ||
| 807 | reconfigure::<T>(config) | ||
| 808 | } | ||
| 809 | |||
| 810 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> | 809 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> |
| 811 | where | 810 | where |
| 812 | TxDma: crate::usart::TxDma<T>, | 811 | TxDma: crate::usart::TxDma<T>, |
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index 347aae7c9..535d1b1fd 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<T>> { | |||
| 18 | 18 | ||
| 19 | impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUartRx<'d, T, RxDma> { | 19 | impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUartRx<'d, T, RxDma> { |
| 20 | type Config = Config; | 20 | type Config = Config; |
| 21 | type ConfigError = (); | ||
| 21 | 22 | ||
| 22 | fn set_config(&mut self, config: &Self::Config) { | 23 | fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> { |
| 23 | unwrap!(self.set_config(config)); | 24 | self.set_config(config).map_err(|_| ()) |
| 24 | } | 25 | } |
| 25 | } | 26 | } |
| 26 | 27 | ||
| @@ -63,7 +64,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> RingBufferedUartRx<'d, T, RxD | |||
| 63 | Err(err) | 64 | Err(err) |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 67 | fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 67 | self.teardown_uart(); | 68 | self.teardown_uart(); |
| 68 | reconfigure::<T>(config) | 69 | reconfigure::<T>(config) |
| 69 | } | 70 | } |
