diff options
| author | Grant Miller <[email protected]> | 2021-12-06 16:47:08 -0600 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2021-12-06 16:47:08 -0600 |
| commit | bd9e730024fc74b1c382c571a07a3b3551bb1110 (patch) | |
| tree | 0d473754fb01c3ae6cc3ec371a6688bb1e6b300e | |
| parent | a35b7d90bc3792d226aa54b74fef18c192946d5c (diff) | |
Move set_word_size to mod
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 49 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v1.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v2.rs | 19 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v3.rs | 23 |
4 files changed, 49 insertions, 58 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 5420ba365..db8ce15fd 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -288,6 +288,55 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 288 | _ => 0b111, | 288 | _ => 0b111, |
| 289 | } | 289 | } |
| 290 | } | 290 | } |
| 291 | |||
| 292 | fn set_word_size(&mut self, word_size: WordSize) { | ||
| 293 | if self.current_word_size == word_size { | ||
| 294 | return; | ||
| 295 | } | ||
| 296 | |||
| 297 | #[cfg(any(spi_v1, spi_f1))] | ||
| 298 | unsafe { | ||
| 299 | T::regs().cr1().modify(|reg| { | ||
| 300 | reg.set_spe(false); | ||
| 301 | reg.set_dff(word_size.dff()) | ||
| 302 | }); | ||
| 303 | T::regs().cr1().modify(|reg| { | ||
| 304 | reg.set_spe(true); | ||
| 305 | }); | ||
| 306 | } | ||
| 307 | #[cfg(spi_v2)] | ||
| 308 | unsafe { | ||
| 309 | T::regs().cr1().modify(|w| { | ||
| 310 | w.set_spe(false); | ||
| 311 | }); | ||
| 312 | T::regs().cr2().modify(|w| { | ||
| 313 | w.set_frxth(word_size.frxth()); | ||
| 314 | w.set_ds(word_size.ds()); | ||
| 315 | }); | ||
| 316 | T::regs().cr1().modify(|w| { | ||
| 317 | w.set_spe(true); | ||
| 318 | }); | ||
| 319 | } | ||
| 320 | #[cfg(spi_v3)] | ||
| 321 | unsafe { | ||
| 322 | T::regs().cr1().modify(|w| { | ||
| 323 | w.set_csusp(true); | ||
| 324 | }); | ||
| 325 | while T::regs().sr().read().eot() {} | ||
| 326 | T::regs().cr1().modify(|w| { | ||
| 327 | w.set_spe(false); | ||
| 328 | }); | ||
| 329 | T::regs().cfg1().modify(|w| { | ||
| 330 | w.set_dsize(word_size.dsize()); | ||
| 331 | }); | ||
| 332 | T::regs().cr1().modify(|w| { | ||
| 333 | w.set_csusp(false); | ||
| 334 | w.set_spe(true); | ||
| 335 | }); | ||
| 336 | } | ||
| 337 | |||
| 338 | self.current_word_size = word_size; | ||
| 339 | } | ||
| 291 | } | 340 | } |
| 292 | 341 | ||
| 293 | trait RegsExt { | 342 | trait RegsExt { |
diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index b98a78343..cd9383d14 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs | |||
| @@ -13,22 +13,6 @@ use futures::future::join3; | |||
| 13 | use super::Spi; | 13 | use super::Spi; |
| 14 | 14 | ||
| 15 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | 15 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { |
| 16 | fn set_word_size(&mut self, word_size: WordSize) { | ||
| 17 | if self.current_word_size == word_size { | ||
| 18 | return; | ||
| 19 | } | ||
| 20 | unsafe { | ||
| 21 | T::regs().cr1().modify(|reg| { | ||
| 22 | reg.set_spe(false); | ||
| 23 | reg.set_dff(word_size.dff()) | ||
| 24 | }); | ||
| 25 | T::regs().cr1().modify(|reg| { | ||
| 26 | reg.set_spe(true); | ||
| 27 | }); | ||
| 28 | } | ||
| 29 | self.current_word_size = word_size; | ||
| 30 | } | ||
| 31 | |||
| 32 | #[allow(unused)] | 16 | #[allow(unused)] |
| 33 | async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> | 17 | async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> |
| 34 | where | 18 | where |
diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 5c62400eb..9817311fa 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs | |||
| @@ -12,25 +12,6 @@ use futures::future::{join, join3}; | |||
| 12 | use super::Spi; | 12 | use super::Spi; |
| 13 | 13 | ||
| 14 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | 14 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { |
| 15 | fn set_word_size(&mut self, word_size: WordSize) { | ||
| 16 | if self.current_word_size == word_size { | ||
| 17 | return; | ||
| 18 | } | ||
| 19 | unsafe { | ||
| 20 | T::regs().cr1().modify(|w| { | ||
| 21 | w.set_spe(false); | ||
| 22 | }); | ||
| 23 | T::regs().cr2().modify(|w| { | ||
| 24 | w.set_frxth(word_size.frxth()); | ||
| 25 | w.set_ds(word_size.ds()); | ||
| 26 | }); | ||
| 27 | T::regs().cr1().modify(|w| { | ||
| 28 | w.set_spe(true); | ||
| 29 | }); | ||
| 30 | } | ||
| 31 | self.current_word_size = word_size; | ||
| 32 | } | ||
| 33 | |||
| 34 | #[allow(unused)] | 15 | #[allow(unused)] |
| 35 | async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> | 16 | async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> |
| 36 | where | 17 | where |
diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index a23a6dd02..af39d3a06 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs | |||
| @@ -13,29 +13,6 @@ use futures::future::join3; | |||
| 13 | use super::Spi; | 13 | use super::Spi; |
| 14 | 14 | ||
| 15 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | 15 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { |
| 16 | fn set_word_size(&mut self, word_size: WordSize) { | ||
| 17 | if self.current_word_size == word_size { | ||
| 18 | return; | ||
| 19 | } | ||
| 20 | unsafe { | ||
| 21 | T::regs().cr1().modify(|w| { | ||
| 22 | w.set_csusp(true); | ||
| 23 | }); | ||
| 24 | while T::regs().sr().read().eot() {} | ||
| 25 | T::regs().cr1().modify(|w| { | ||
| 26 | w.set_spe(false); | ||
| 27 | }); | ||
| 28 | T::regs().cfg1().modify(|w| { | ||
| 29 | w.set_dsize(word_size.dsize()); | ||
| 30 | }); | ||
| 31 | T::regs().cr1().modify(|w| { | ||
| 32 | w.set_csusp(false); | ||
| 33 | w.set_spe(true); | ||
| 34 | }); | ||
| 35 | } | ||
| 36 | self.current_word_size = word_size; | ||
| 37 | } | ||
| 38 | |||
| 39 | #[allow(unused)] | 16 | #[allow(unused)] |
| 40 | async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> | 17 | async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error> |
| 41 | where | 18 | where |
