aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-10-01 14:41:52 +0000
committerGitHub <[email protected]>2023-10-01 14:41:52 +0000
commit480328d07e73f64856f46c5670460c97a7383fdd (patch)
tree1fa2f7cdb3be185e04b171481ebc00071a7ddc2e
parenta7b1e516504bb0df9f7af42361e4280adcc30417 (diff)
parent05218a52e60537a591932b53328087f5f8976728 (diff)
Merge pull request #1984 from xoviat/set-config
stm32: require use of setconfig to set config
-rw-r--r--embassy-embedded-hal/src/lib.rs14
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/i2c.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/spi.rs2
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/i2c.rs6
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/spi.rs2
-rw-r--r--embassy-embedded-hal/src/shared_bus/mod.rs6
-rw-r--r--embassy-nrf/src/spim.rs7
-rw-r--r--embassy-nrf/src/spis.rs7
-rw-r--r--embassy-nrf/src/twim.rs7
-rw-r--r--embassy-rp/src/spi.rs5
-rw-r--r--embassy-stm32/build.rs1
-rw-r--r--embassy-stm32/src/i2c/v1.rs5
-rw-r--r--embassy-stm32/src/i2c/v2.rs5
-rw-r--r--embassy-stm32/src/sai/mod.rs8
-rw-r--r--embassy-stm32/src/spi/mod.rs7
-rw-r--r--embassy-stm32/src/usart/buffered.rs21
-rw-r--r--embassy-stm32/src/usart/mod.rs25
-rw-r--r--embassy-stm32/src/usart/ringbuffered.rs7
18 files changed, 95 insertions, 48 deletions
diff --git a/embassy-embedded-hal/src/lib.rs b/embassy-embedded-hal/src/lib.rs
index 3aad838bd..8872b3d61 100644
--- a/embassy-embedded-hal/src/lib.rs
+++ b/embassy-embedded-hal/src/lib.rs
@@ -26,6 +26,18 @@ pub trait SetConfig {
26 /// The configuration type used by this driver. 26 /// The configuration type used by this driver.
27 type Config; 27 type Config;
28 28
29 /// The error type that can occur if `set_config` fails.
30 type ConfigError;
31
29 /// Set the configuration of the driver. 32 /// Set the configuration of the driver.
30 fn set_config(&mut self, config: &Self::Config); 33 fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>;
34}
35
36/// Get the configuration of a peripheral driver.
37pub trait GetConfig {
38 /// The configuration type used by this driver.
39 type Config;
40
41 /// Get the configuration of the driver.
42 fn get_config(&self) -> Self::Config;
31} 43}
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
index 87e8a4304..1053d3849 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
@@ -125,14 +125,14 @@ where
125{ 125{
126 async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> { 126 async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> {
127 let mut bus = self.bus.lock().await; 127 let mut bus = self.bus.lock().await;
128 bus.set_config(&self.config); 128 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
129 bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; 129 bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?;
130 Ok(()) 130 Ok(())
131 } 131 }
132 132
133 async fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), I2cDeviceError<BUS::Error>> { 133 async fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), I2cDeviceError<BUS::Error>> {
134 let mut bus = self.bus.lock().await; 134 let mut bus = self.bus.lock().await;
135 bus.set_config(&self.config); 135 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
136 bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; 136 bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?;
137 Ok(()) 137 Ok(())
138 } 138 }
@@ -144,7 +144,7 @@ where
144 rd_buffer: &mut [u8], 144 rd_buffer: &mut [u8],
145 ) -> Result<(), I2cDeviceError<BUS::Error>> { 145 ) -> Result<(), I2cDeviceError<BUS::Error>> {
146 let mut bus = self.bus.lock().await; 146 let mut bus = self.bus.lock().await;
147 bus.set_config(&self.config); 147 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
148 bus.write_read(address, wr_buffer, rd_buffer) 148 bus.write_read(address, wr_buffer, rd_buffer)
149 .await 149 .await
150 .map_err(I2cDeviceError::I2c)?; 150 .map_err(I2cDeviceError::I2c)?;
@@ -153,7 +153,7 @@ where
153 153
154 async fn transaction(&mut self, address: u8, operations: &mut [i2c::Operation<'_>]) -> Result<(), Self::Error> { 154 async fn transaction(&mut self, address: u8, operations: &mut [i2c::Operation<'_>]) -> Result<(), Self::Error> {
155 let mut bus = self.bus.lock().await; 155 let mut bus = self.bus.lock().await;
156 bus.set_config(&self.config); 156 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
157 bus.transaction(address, operations) 157 bus.transaction(address, operations)
158 .await 158 .await
159 .map_err(I2cDeviceError::I2c)?; 159 .map_err(I2cDeviceError::I2c)?;
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
index 030392183..b2a9f1e33 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
@@ -130,7 +130,7 @@ where
130{ 130{
131 async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { 131 async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> {
132 let mut bus = self.bus.lock().await; 132 let mut bus = self.bus.lock().await;
133 bus.set_config(&self.config); 133 bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?;
134 self.cs.set_low().map_err(SpiDeviceError::Cs)?; 134 self.cs.set_low().map_err(SpiDeviceError::Cs)?;
135 135
136 let op_res: Result<(), BUS::Error> = try { 136 let op_res: Result<(), BUS::Error> = try {
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
index af73df059..233c9e1fd 100644
--- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
+++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
@@ -148,7 +148,7 @@ where
148 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { 148 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
149 self.bus.lock(|bus| { 149 self.bus.lock(|bus| {
150 let mut bus = bus.borrow_mut(); 150 let mut bus = bus.borrow_mut();
151 bus.set_config(&self.config); 151 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
152 bus.read(address, buffer).map_err(I2cDeviceError::I2c) 152 bus.read(address, buffer).map_err(I2cDeviceError::I2c)
153 }) 153 })
154 } 154 }
@@ -156,7 +156,7 @@ where
156 fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> { 156 fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
157 self.bus.lock(|bus| { 157 self.bus.lock(|bus| {
158 let mut bus = bus.borrow_mut(); 158 let mut bus = bus.borrow_mut();
159 bus.set_config(&self.config); 159 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
160 bus.write(address, bytes).map_err(I2cDeviceError::I2c) 160 bus.write(address, bytes).map_err(I2cDeviceError::I2c)
161 }) 161 })
162 } 162 }
@@ -164,7 +164,7 @@ where
164 fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { 164 fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> {
165 self.bus.lock(|bus| { 165 self.bus.lock(|bus| {
166 let mut bus = bus.borrow_mut(); 166 let mut bus = bus.borrow_mut();
167 bus.set_config(&self.config); 167 bus.set_config(&self.config).map_err(|_| I2cDeviceError::Config)?;
168 bus.write_read(address, wr_buffer, rd_buffer) 168 bus.write_read(address, wr_buffer, rd_buffer)
169 .map_err(I2cDeviceError::I2c) 169 .map_err(I2cDeviceError::I2c)
170 }) 170 })
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
index 6d03d6263..feb0f5b7d 100644
--- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
@@ -163,7 +163,7 @@ where
163 fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { 163 fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> {
164 self.bus.lock(|bus| { 164 self.bus.lock(|bus| {
165 let mut bus = bus.borrow_mut(); 165 let mut bus = bus.borrow_mut();
166 bus.set_config(&self.config); 166 bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?;
167 self.cs.set_low().map_err(SpiDeviceError::Cs)?; 167 self.cs.set_low().map_err(SpiDeviceError::Cs)?;
168 168
169 let op_res = operations.iter_mut().try_for_each(|op| match op { 169 let op_res = operations.iter_mut().try_for_each(|op| match op {
diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs
index 79a90bd52..b0159ac09 100644
--- a/embassy-embedded-hal/src/shared_bus/mod.rs
+++ b/embassy-embedded-hal/src/shared_bus/mod.rs
@@ -14,6 +14,8 @@ pub mod blocking;
14pub enum I2cDeviceError<BUS> { 14pub enum I2cDeviceError<BUS> {
15 /// An operation on the inner I2C bus failed. 15 /// An operation on the inner I2C bus failed.
16 I2c(BUS), 16 I2c(BUS),
17 /// Configuration of the inner I2C bus failed.
18 Config,
17} 19}
18 20
19impl<BUS> i2c::Error for I2cDeviceError<BUS> 21impl<BUS> i2c::Error for I2cDeviceError<BUS>
@@ -23,6 +25,7 @@ where
23 fn kind(&self) -> i2c::ErrorKind { 25 fn kind(&self) -> i2c::ErrorKind {
24 match self { 26 match self {
25 Self::I2c(e) => e.kind(), 27 Self::I2c(e) => e.kind(),
28 Self::Config => i2c::ErrorKind::Other,
26 } 29 }
27 } 30 }
28} 31}
@@ -38,6 +41,8 @@ pub enum SpiDeviceError<BUS, CS> {
38 Cs(CS), 41 Cs(CS),
39 /// DelayUs operations are not supported when the `time` Cargo feature is not enabled. 42 /// DelayUs operations are not supported when the `time` Cargo feature is not enabled.
40 DelayUsNotSupported, 43 DelayUsNotSupported,
44 /// The SPI bus could not be configured.
45 Config,
41} 46}
42 47
43impl<BUS, CS> spi::Error for SpiDeviceError<BUS, CS> 48impl<BUS, CS> spi::Error for SpiDeviceError<BUS, CS>
@@ -50,6 +55,7 @@ where
50 Self::Spi(e) => e.kind(), 55 Self::Spi(e) => e.kind(),
51 Self::Cs(_) => spi::ErrorKind::Other, 56 Self::Cs(_) => spi::ErrorKind::Other,
52 Self::DelayUsNotSupported => spi::ErrorKind::Other, 57 Self::DelayUsNotSupported => spi::ErrorKind::Other,
58 Self::Config => spi::ErrorKind::Other,
53 } 59 }
54 } 60 }
55} 61}
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index 4828af43e..caf681d99 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -176,7 +176,7 @@ impl<'d, T: Instance> Spim<'d, T> {
176 let mut spim = Self { _p: spim }; 176 let mut spim = Self { _p: spim };
177 177
178 // Apply runtime peripheral configuration 178 // Apply runtime peripheral configuration
179 Self::set_config(&mut spim, &config); 179 Self::set_config(&mut spim, &config).unwrap();
180 180
181 // Disable all events interrupts 181 // Disable all events interrupts
182 r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); 182 r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) });
@@ -566,7 +566,8 @@ mod eha {
566 566
567impl<'d, T: Instance> SetConfig for Spim<'d, T> { 567impl<'d, T: Instance> SetConfig for Spim<'d, T> {
568 type Config = Config; 568 type Config = Config;
569 fn set_config(&mut self, config: &Self::Config) { 569 type ConfigError = ();
570 fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError> {
570 let r = T::regs(); 571 let r = T::regs();
571 // Configure mode. 572 // Configure mode.
572 let mode = config.mode; 573 let mode = config.mode;
@@ -604,5 +605,7 @@ impl<'d, T: Instance> SetConfig for Spim<'d, T> {
604 // Set over-read character 605 // Set over-read character
605 let orc = config.orc; 606 let orc = config.orc;
606 r.orc.write(|w| unsafe { w.orc().bits(orc) }); 607 r.orc.write(|w| unsafe { w.orc().bits(orc) });
608
609 Ok(())
607 } 610 }
608} 611}
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs
index e695ba6b7..e202c6c27 100644
--- a/embassy-nrf/src/spis.rs
+++ b/embassy-nrf/src/spis.rs
@@ -172,7 +172,7 @@ impl<'d, T: Instance> Spis<'d, T> {
172 let mut spis = Self { _p: spis }; 172 let mut spis = Self { _p: spis };
173 173
174 // Apply runtime peripheral configuration 174 // Apply runtime peripheral configuration
175 Self::set_config(&mut spis, &config); 175 Self::set_config(&mut spis, &config).unwrap();
176 176
177 // Disable all events interrupts. 177 // Disable all events interrupts.
178 r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); 178 r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) });
@@ -467,7 +467,8 @@ macro_rules! impl_spis {
467 467
468impl<'d, T: Instance> SetConfig for Spis<'d, T> { 468impl<'d, T: Instance> SetConfig for Spis<'d, T> {
469 type Config = Config; 469 type Config = Config;
470 fn set_config(&mut self, config: &Self::Config) { 470 type ConfigError = ();
471 fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError> {
471 let r = T::regs(); 472 let r = T::regs();
472 // Configure mode. 473 // Configure mode.
473 let mode = config.mode; 474 let mode = config.mode;
@@ -509,5 +510,7 @@ impl<'d, T: Instance> SetConfig for Spis<'d, T> {
509 // Configure auto-acquire on 'transfer end' event. 510 // Configure auto-acquire on 'transfer end' event.
510 let auto_acquire = config.auto_acquire; 511 let auto_acquire = config.auto_acquire;
511 r.shorts.write(|w| w.end_acquire().bit(auto_acquire)); 512 r.shorts.write(|w| w.end_acquire().bit(auto_acquire));
513
514 Ok(())
512 } 515 }
513} 516}
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index fe38fb102..919bb4ab2 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -170,7 +170,7 @@ impl<'d, T: Instance> Twim<'d, T> {
170 let mut twim = Self { _p: twim }; 170 let mut twim = Self { _p: twim };
171 171
172 // Apply runtime peripheral configuration 172 // Apply runtime peripheral configuration
173 Self::set_config(&mut twim, &config); 173 Self::set_config(&mut twim, &config).unwrap();
174 174
175 // Disable all events interrupts 175 // Disable all events interrupts
176 r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); 176 r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) });
@@ -890,9 +890,12 @@ mod eha {
890 890
891impl<'d, T: Instance> SetConfig for Twim<'d, T> { 891impl<'d, T: Instance> SetConfig for Twim<'d, T> {
892 type Config = Config; 892 type Config = Config;
893 fn set_config(&mut self, config: &Self::Config) { 893 type ConfigError = ();
894 fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError> {
894 let r = T::regs(); 895 let r = T::regs();
895 r.frequency 896 r.frequency
896 .write(|w| unsafe { w.frequency().bits(config.frequency as u32) }); 897 .write(|w| unsafe { w.frequency().bits(config.frequency as u32) });
898
899 Ok(())
897 } 900 }
898} 901}
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index 46c440b84..a59ce8419 100644
--- a/embassy-rp/src/spi.rs
+++ b/embassy-rp/src/spi.rs
@@ -597,7 +597,8 @@ mod eha {
597 597
598impl<'d, T: Instance, M: Mode> SetConfig for Spi<'d, T, M> { 598impl<'d, T: Instance, M: Mode> SetConfig for Spi<'d, T, M> {
599 type Config = Config; 599 type Config = Config;
600 fn set_config(&mut self, config: &Self::Config) { 600 type ConfigError = ();
601 fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
601 let p = self.inner.regs(); 602 let p = self.inner.regs();
602 let (presc, postdiv) = calc_prescs(config.frequency); 603 let (presc, postdiv) = calc_prescs(config.frequency);
603 p.cpsr().write(|w| w.set_cpsdvsr(presc)); 604 p.cpsr().write(|w| w.set_cpsdvsr(presc));
@@ -607,5 +608,7 @@ impl<'d, T: Instance, M: Mode> SetConfig for Spi<'d, T, M> {
607 w.set_sph(config.phase == Phase::CaptureOnSecondTransition); 608 w.set_sph(config.phase == Phase::CaptureOnSecondTransition);
608 w.set_scr(postdiv); 609 w.set_scr(postdiv);
609 }); 610 });
611
612 Ok(())
610 } 613 }
611} 614}
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
519impl<'d, T: Instance> SetConfig for I2c<'d, T> { 519impl<'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
1076impl<'d, T: Instance> SetConfig for I2c<'d, T> { 1076impl<'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
1057impl<'d, T: Instance> SetConfig for Sai<'d, T> { 1058impl<'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
1062impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx> { 1062impl<'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
117impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> { 117impl<'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
125impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> { 126impl<'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
133impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> { 135impl<'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
182impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> { 182impl<'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
196impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> { 197impl<'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
212impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> { 214impl<'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
19impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUartRx<'d, T, RxDma> { 19impl<'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 }