From 02ee59fa1e720e9fd6a1a15b4f46af4eac2b890f Mon Sep 17 00:00:00 2001 From: Ragarnoy Date: Tue, 30 Apr 2024 02:19:28 +0200 Subject: [PATCH] Add Copy and 'static constraint to Word type in SPI structs --- embassy-embedded-hal/src/shared_bus/blocking/spi.rs | 13 +++++++++---- 1 file 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; use crate::SetConfig; /// SPI device on a shared bus. -pub struct SpiDevice<'a, M: RawMutex, BUS, CS, Word> { +pub struct SpiDevice<'a, M: RawMutex, BUS, CS, Word: Copy + 'static = u8> { bus: &'a Mutex>, cs: CS, _word: core::marker::PhantomData, } -impl<'a, M: RawMutex, BUS, CS, Word> SpiDevice<'a, M, BUS, CS, Word> { +impl<'a, M: RawMutex, BUS, CS, Word: Copy + 'static> SpiDevice<'a, M, BUS, CS, Word> { /// Create a new `SpiDevice`. pub fn new(bus: &'a Mutex>, cs: CS) -> Self { Self { @@ -49,6 +49,7 @@ impl<'a, M: RawMutex, BUS, CS, Word> spi::ErrorType for SpiDevice<'a, M, BUS, CS where BUS: spi::ErrorType, CS: OutputPin, + Word: Copy + 'static, { type Error = SpiDeviceError; } @@ -102,6 +103,7 @@ where M: RawMutex, BUS: embedded_hal_02::blocking::spi::Transfer, CS: OutputPin, + Word: Copy + 'static, { type Error = SpiDeviceError; fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { @@ -122,6 +124,7 @@ where M: RawMutex, BUS: embedded_hal_02::blocking::spi::Write, CS: OutputPin, + Word: Copy + 'static, { type Error = SpiDeviceError; @@ -144,6 +147,7 @@ where M: RawMutex, BUS: embedded_hal_02::blocking::spi::Transfer, CS: OutputPin, + Word: Copy + 'static, { type Error = SpiDeviceError; fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> { @@ -164,6 +168,7 @@ where M: RawMutex, BUS: embedded_hal_02::blocking::spi::Write, CS: OutputPin, + Word: Copy + 'static, { type Error = SpiDeviceError; @@ -185,14 +190,14 @@ where /// This is like [`SpiDevice`], with an additional bus configuration that's applied /// to the bus before each use using [`SetConfig`]. This allows different /// devices on the same bus to use different communication settings. -pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS, Word> { +pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS, Word: Copy + 'static = u8> { bus: &'a Mutex>, cs: CS, config: BUS::Config, _word: core::marker::PhantomData, } -impl<'a, M: RawMutex, BUS: SetConfig, CS, Word> SpiDeviceWithConfig<'a, M, BUS, CS, Word> { +impl<'a, M: RawMutex, BUS: SetConfig, CS, Word: Copy + 'static> SpiDeviceWithConfig<'a, M, BUS, CS, Word> { /// Create a new `SpiDeviceWithConfig`. pub fn new(bus: &'a Mutex>, cs: CS, config: BUS::Config) -> Self { Self {