mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
Add Copy and 'static constraint to Word type in SPI structs
This commit is contained in:
parent
6df737a48c
commit
02ee59fa1e
@ -28,13 +28,13 @@ use crate::shared_bus::SpiDeviceError;
|
|||||||
use crate::SetConfig;
|
use crate::SetConfig;
|
||||||
|
|
||||||
/// SPI device on a shared bus.
|
/// 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<M, RefCell<BUS>>,
|
bus: &'a Mutex<M, RefCell<BUS>>,
|
||||||
cs: CS,
|
cs: CS,
|
||||||
_word: core::marker::PhantomData<Word>,
|
_word: core::marker::PhantomData<Word>,
|
||||||
}
|
}
|
||||||
|
|
||||||
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`.
|
/// Create a new `SpiDevice`.
|
||||||
pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS) -> Self {
|
pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -49,6 +49,7 @@ impl<'a, M: RawMutex, BUS, CS, Word> spi::ErrorType for SpiDevice<'a, M, BUS, CS
|
|||||||
where
|
where
|
||||||
BUS: spi::ErrorType,
|
BUS: spi::ErrorType,
|
||||||
CS: OutputPin,
|
CS: OutputPin,
|
||||||
|
Word: Copy + 'static,
|
||||||
{
|
{
|
||||||
type Error = SpiDeviceError<BUS::Error, CS::Error>;
|
type Error = SpiDeviceError<BUS::Error, CS::Error>;
|
||||||
}
|
}
|
||||||
@ -102,6 +103,7 @@ where
|
|||||||
M: RawMutex,
|
M: RawMutex,
|
||||||
BUS: embedded_hal_02::blocking::spi::Transfer<u8, Error = BusErr>,
|
BUS: embedded_hal_02::blocking::spi::Transfer<u8, Error = BusErr>,
|
||||||
CS: OutputPin<Error = CsErr>,
|
CS: OutputPin<Error = CsErr>,
|
||||||
|
Word: Copy + 'static,
|
||||||
{
|
{
|
||||||
type Error = SpiDeviceError<BusErr, CsErr>;
|
type Error = SpiDeviceError<BusErr, CsErr>;
|
||||||
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
|
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
|
||||||
@ -122,6 +124,7 @@ where
|
|||||||
M: RawMutex,
|
M: RawMutex,
|
||||||
BUS: embedded_hal_02::blocking::spi::Write<u8, Error = BusErr>,
|
BUS: embedded_hal_02::blocking::spi::Write<u8, Error = BusErr>,
|
||||||
CS: OutputPin<Error = CsErr>,
|
CS: OutputPin<Error = CsErr>,
|
||||||
|
Word: Copy + 'static,
|
||||||
{
|
{
|
||||||
type Error = SpiDeviceError<BusErr, CsErr>;
|
type Error = SpiDeviceError<BusErr, CsErr>;
|
||||||
|
|
||||||
@ -144,6 +147,7 @@ where
|
|||||||
M: RawMutex,
|
M: RawMutex,
|
||||||
BUS: embedded_hal_02::blocking::spi::Transfer<u16, Error = BusErr>,
|
BUS: embedded_hal_02::blocking::spi::Transfer<u16, Error = BusErr>,
|
||||||
CS: OutputPin<Error = CsErr>,
|
CS: OutputPin<Error = CsErr>,
|
||||||
|
Word: Copy + 'static,
|
||||||
{
|
{
|
||||||
type Error = SpiDeviceError<BusErr, CsErr>;
|
type Error = SpiDeviceError<BusErr, CsErr>;
|
||||||
fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {
|
fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {
|
||||||
@ -164,6 +168,7 @@ where
|
|||||||
M: RawMutex,
|
M: RawMutex,
|
||||||
BUS: embedded_hal_02::blocking::spi::Write<u16, Error = BusErr>,
|
BUS: embedded_hal_02::blocking::spi::Write<u16, Error = BusErr>,
|
||||||
CS: OutputPin<Error = CsErr>,
|
CS: OutputPin<Error = CsErr>,
|
||||||
|
Word: Copy + 'static,
|
||||||
{
|
{
|
||||||
type Error = SpiDeviceError<BusErr, CsErr>;
|
type Error = SpiDeviceError<BusErr, CsErr>;
|
||||||
|
|
||||||
@ -185,14 +190,14 @@ where
|
|||||||
/// This is like [`SpiDevice`], with an additional bus configuration that's applied
|
/// This is like [`SpiDevice`], with an additional bus configuration that's applied
|
||||||
/// to the bus before each use using [`SetConfig`]. This allows different
|
/// to the bus before each use using [`SetConfig`]. This allows different
|
||||||
/// devices on the same bus to use different communication settings.
|
/// 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<M, RefCell<BUS>>,
|
bus: &'a Mutex<M, RefCell<BUS>>,
|
||||||
cs: CS,
|
cs: CS,
|
||||||
config: BUS::Config,
|
config: BUS::Config,
|
||||||
_word: core::marker::PhantomData<Word>,
|
_word: core::marker::PhantomData<Word>,
|
||||||
}
|
}
|
||||||
|
|
||||||
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`.
|
/// Create a new `SpiDeviceWithConfig`.
|
||||||
pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self {
|
pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user