diff options
| author | Ragarnoy <[email protected]> | 2024-04-30 02:19:28 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-05-20 10:56:43 +0200 |
| commit | 02ee59fa1e720e9fd6a1a15b4f46af4eac2b890f (patch) | |
| tree | 4ae4592e26e5e113484231a82843a94b05b0e7db /embassy-embedded-hal/src | |
| parent | 6df737a48c35c582ed31387ddf7ebedb86a814b5 (diff) | |
Add Copy and 'static constraint to Word type in SPI structs
Diffstat (limited to 'embassy-embedded-hal/src')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/blocking/spi.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index e7e112b0a..7d383980d 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs | |||
| @@ -28,13 +28,13 @@ use crate::shared_bus::SpiDeviceError; | |||
| 28 | use crate::SetConfig; | 28 | use crate::SetConfig; |
| 29 | 29 | ||
| 30 | /// SPI device on a shared bus. | 30 | /// SPI device on a shared bus. |
| 31 | pub struct SpiDevice<'a, M: RawMutex, BUS, CS, Word> { | 31 | pub struct SpiDevice<'a, M: RawMutex, BUS, CS, Word: Copy + 'static = u8> { |
| 32 | bus: &'a Mutex<M, RefCell<BUS>>, | 32 | bus: &'a Mutex<M, RefCell<BUS>>, |
| 33 | cs: CS, | 33 | cs: CS, |
| 34 | _word: core::marker::PhantomData<Word>, | 34 | _word: core::marker::PhantomData<Word>, |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | impl<'a, M: RawMutex, BUS, CS, Word> SpiDevice<'a, M, BUS, CS, Word> { | 37 | impl<'a, M: RawMutex, BUS, CS, Word: Copy + 'static> SpiDevice<'a, M, BUS, CS, Word> { |
| 38 | /// Create a new `SpiDevice`. | 38 | /// Create a new `SpiDevice`. |
| 39 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS) -> Self { | 39 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS) -> Self { |
| 40 | Self { | 40 | Self { |
| @@ -49,6 +49,7 @@ impl<'a, M: RawMutex, BUS, CS, Word> spi::ErrorType for SpiDevice<'a, M, BUS, CS | |||
| 49 | where | 49 | where |
| 50 | BUS: spi::ErrorType, | 50 | BUS: spi::ErrorType, |
| 51 | CS: OutputPin, | 51 | CS: OutputPin, |
| 52 | Word: Copy + 'static, | ||
| 52 | { | 53 | { |
| 53 | type Error = SpiDeviceError<BUS::Error, CS::Error>; | 54 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 54 | } | 55 | } |
| @@ -102,6 +103,7 @@ where | |||
| 102 | M: RawMutex, | 103 | M: RawMutex, |
| 103 | BUS: embedded_hal_02::blocking::spi::Transfer<u8, Error = BusErr>, | 104 | BUS: embedded_hal_02::blocking::spi::Transfer<u8, Error = BusErr>, |
| 104 | CS: OutputPin<Error = CsErr>, | 105 | CS: OutputPin<Error = CsErr>, |
| 106 | Word: Copy + 'static, | ||
| 105 | { | 107 | { |
| 106 | type Error = SpiDeviceError<BusErr, CsErr>; | 108 | type Error = SpiDeviceError<BusErr, CsErr>; |
| 107 | fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { | 109 | fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { |
| @@ -122,6 +124,7 @@ where | |||
| 122 | M: RawMutex, | 124 | M: RawMutex, |
| 123 | BUS: embedded_hal_02::blocking::spi::Write<u8, Error = BusErr>, | 125 | BUS: embedded_hal_02::blocking::spi::Write<u8, Error = BusErr>, |
| 124 | CS: OutputPin<Error = CsErr>, | 126 | CS: OutputPin<Error = CsErr>, |
| 127 | Word: Copy + 'static, | ||
| 125 | { | 128 | { |
| 126 | type Error = SpiDeviceError<BusErr, CsErr>; | 129 | type Error = SpiDeviceError<BusErr, CsErr>; |
| 127 | 130 | ||
| @@ -144,6 +147,7 @@ where | |||
| 144 | M: RawMutex, | 147 | M: RawMutex, |
| 145 | BUS: embedded_hal_02::blocking::spi::Transfer<u16, Error = BusErr>, | 148 | BUS: embedded_hal_02::blocking::spi::Transfer<u16, Error = BusErr>, |
| 146 | CS: OutputPin<Error = CsErr>, | 149 | CS: OutputPin<Error = CsErr>, |
| 150 | Word: Copy + 'static, | ||
| 147 | { | 151 | { |
| 148 | type Error = SpiDeviceError<BusErr, CsErr>; | 152 | type Error = SpiDeviceError<BusErr, CsErr>; |
| 149 | fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> { | 153 | fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> { |
| @@ -164,6 +168,7 @@ where | |||
| 164 | M: RawMutex, | 168 | M: RawMutex, |
| 165 | BUS: embedded_hal_02::blocking::spi::Write<u16, Error = BusErr>, | 169 | BUS: embedded_hal_02::blocking::spi::Write<u16, Error = BusErr>, |
| 166 | CS: OutputPin<Error = CsErr>, | 170 | CS: OutputPin<Error = CsErr>, |
| 171 | Word: Copy + 'static, | ||
| 167 | { | 172 | { |
| 168 | type Error = SpiDeviceError<BusErr, CsErr>; | 173 | type Error = SpiDeviceError<BusErr, CsErr>; |
| 169 | 174 | ||
| @@ -185,14 +190,14 @@ where | |||
| 185 | /// This is like [`SpiDevice`], with an additional bus configuration that's applied | 190 | /// This is like [`SpiDevice`], with an additional bus configuration that's applied |
| 186 | /// to the bus before each use using [`SetConfig`]. This allows different | 191 | /// to the bus before each use using [`SetConfig`]. This allows different |
| 187 | /// devices on the same bus to use different communication settings. | 192 | /// devices on the same bus to use different communication settings. |
| 188 | pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS, Word> { | 193 | pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS, Word: Copy + 'static = u8> { |
| 189 | bus: &'a Mutex<M, RefCell<BUS>>, | 194 | bus: &'a Mutex<M, RefCell<BUS>>, |
| 190 | cs: CS, | 195 | cs: CS, |
| 191 | config: BUS::Config, | 196 | config: BUS::Config, |
| 192 | _word: core::marker::PhantomData<Word>, | 197 | _word: core::marker::PhantomData<Word>, |
| 193 | } | 198 | } |
| 194 | 199 | ||
| 195 | impl<'a, M: RawMutex, BUS: SetConfig, CS, Word> SpiDeviceWithConfig<'a, M, BUS, CS, Word> { | 200 | impl<'a, M: RawMutex, BUS: SetConfig, CS, Word: Copy + 'static> SpiDeviceWithConfig<'a, M, BUS, CS, Word> { |
| 196 | /// Create a new `SpiDeviceWithConfig`. | 201 | /// Create a new `SpiDeviceWithConfig`. |
| 197 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self { | 202 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self { |
| 198 | Self { | 203 | Self { |
