diff options
| author | Grant Miller <[email protected]> | 2021-12-06 16:51:10 -0600 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2021-12-06 17:19:55 -0600 |
| commit | d76bc45e3029718e954ce7e2ffd950211ce962c3 (patch) | |
| tree | 19c5e08467caa31fbcb00f4f2fb726eb6ec6d5ec | |
| parent | bd9e730024fc74b1c382c571a07a3b3551bb1110 (diff) | |
Move Spi drop impl to mod
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v1.rs | 11 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v2.rs | 11 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/v3.rs | 11 |
4 files changed, 10 insertions, 33 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index db8ce15fd..410e16ee2 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -339,6 +339,16 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 339 | } | 339 | } |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { | ||
| 343 | fn drop(&mut self) { | ||
| 344 | unsafe { | ||
| 345 | self.sck.as_ref().map(|x| x.set_as_analog()); | ||
| 346 | self.mosi.as_ref().map(|x| x.set_as_analog()); | ||
| 347 | self.miso.as_ref().map(|x| x.set_as_analog()); | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 342 | trait RegsExt { | 352 | trait RegsExt { |
| 343 | fn tx_ptr<W>(&self) -> *mut W; | 353 | fn tx_ptr<W>(&self) -> *mut W; |
| 344 | fn rx_ptr<W>(&self) -> *mut W; | 354 | fn rx_ptr<W>(&self) -> *mut W; |
diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index cd9383d14..255bd950a 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::dma::NoDma; | 3 | use crate::dma::NoDma; |
| 4 | use crate::gpio::sealed::Pin; | ||
| 5 | use crate::spi::{Error, Instance, RegsExt, RxDmaChannel, TxDmaChannel, WordSize}; | 4 | use crate::spi::{Error, Instance, RegsExt, RxDmaChannel, TxDmaChannel, WordSize}; |
| 6 | use core::future::Future; | 5 | use core::future::Future; |
| 7 | use core::ptr; | 6 | use core::ptr; |
| @@ -156,16 +155,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 156 | } | 155 | } |
| 157 | } | 156 | } |
| 158 | 157 | ||
| 159 | impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { | ||
| 160 | fn drop(&mut self) { | ||
| 161 | unsafe { | ||
| 162 | self.sck.as_ref().map(|x| x.set_as_analog()); | ||
| 163 | self.mosi.as_ref().map(|x| x.set_as_analog()); | ||
| 164 | self.miso.as_ref().map(|x| x.set_as_analog()); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> for Spi<'d, T, NoDma, NoDma> { | 158 | impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> for Spi<'d, T, NoDma, NoDma> { |
| 170 | type Error = Error; | 159 | type Error = Error; |
| 171 | 160 | ||
diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 9817311fa..b1fae4bdc 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::dma::NoDma; | 3 | use crate::dma::NoDma; |
| 4 | use crate::gpio::sealed::Pin; | ||
| 5 | use crate::spi::{Error, Instance, RegsExt, RxDmaChannel, TxDmaChannel, WordSize}; | 4 | use crate::spi::{Error, Instance, RegsExt, RxDmaChannel, TxDmaChannel, WordSize}; |
| 6 | use core::future::Future; | 5 | use core::future::Future; |
| 7 | use core::ptr; | 6 | use core::ptr; |
| @@ -175,16 +174,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 175 | } | 174 | } |
| 176 | } | 175 | } |
| 177 | 176 | ||
| 178 | impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { | ||
| 179 | fn drop(&mut self) { | ||
| 180 | unsafe { | ||
| 181 | self.sck.as_ref().map(|x| x.set_as_analog()); | ||
| 182 | self.mosi.as_ref().map(|x| x.set_as_analog()); | ||
| 183 | self.miso.as_ref().map(|x| x.set_as_analog()); | ||
| 184 | } | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | trait Word {} | 177 | trait Word {} |
| 189 | 178 | ||
| 190 | impl Word for u8 {} | 179 | impl Word for u8 {} |
diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index af39d3a06..052924db0 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::dma::NoDma; | 3 | use crate::dma::NoDma; |
| 4 | use crate::gpio::sealed::Pin; | ||
| 5 | use crate::spi::{Error, Instance, RegsExt, RxDmaChannel, TxDmaChannel, WordSize}; | 4 | use crate::spi::{Error, Instance, RegsExt, RxDmaChannel, TxDmaChannel, WordSize}; |
| 6 | use core::future::Future; | 5 | use core::future::Future; |
| 7 | use core::ptr; | 6 | use core::ptr; |
| @@ -178,16 +177,6 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 178 | } | 177 | } |
| 179 | } | 178 | } |
| 180 | 179 | ||
| 181 | impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { | ||
| 182 | fn drop(&mut self) { | ||
| 183 | unsafe { | ||
| 184 | self.sck.as_ref().map(|x| x.set_as_analog()); | ||
| 185 | self.mosi.as_ref().map(|x| x.set_as_analog()); | ||
| 186 | self.miso.as_ref().map(|x| x.set_as_analog()); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> for Spi<'d, T, NoDma, NoDma> { | 180 | impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> for Spi<'d, T, NoDma, NoDma> { |
| 192 | type Error = Error; | 181 | type Error = Error; |
| 193 | 182 | ||
