Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-embedded/embedded-hal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 68cd1beb0ba8f80bea77624eca513fb6d4419421
Choose a base ref
..
head repository: rust-embedded/embedded-hal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6013187cc217d1190dfa10a735d039e66f77305e
Choose a head ref
Showing with 34 additions and 20 deletions.
  1. +34 −20 embedded-hal-async/src/spi.rs
54 changes: 34 additions & 20 deletions embedded-hal-async/src/spi.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ pub use embedded_hal::spi::{
};

/// Read-only SPI
pub trait Read<W: 'static + Copy = u8>: ErrorType {
pub trait Read<Word: 'static + Copy = u8>: ErrorType {
/// Future returned by the `read` method.
type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
where
@@ -18,7 +18,7 @@ pub trait Read<W: 'static + Copy = u8>: ErrorType {
///
/// The word value sent on MOSI during reading is implementation-defined,
/// typically `0x00`, `0xFF`, or configurable.
fn read<'a>(&'a mut self, words: &'a mut [W]) -> Self::ReadFuture<'a>;
fn read<'a>(&'a mut self, words: &'a mut [Word]) -> Self::ReadFuture<'a>;

/// Future returned by the `read_transaction` method.
type ReadTransactionFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
@@ -31,17 +31,17 @@ pub trait Read<W: 'static + Copy = u8>: ErrorType {
/// typically `0x00`, `0xFF`, or configurable.
fn read_transaction<'a>(
&'a mut self,
words: &'a mut [&'a mut [W]],
words: &'a mut [&'a mut [Word]],
) -> Self::ReadTransactionFuture<'a>;
}

impl<T: Read<W>, W: 'static + Copy> Read<W> for &mut T {
impl<T: Read<Word>, Word: 'static + Copy> Read<Word> for &mut T {
type ReadFuture<'a>
where
Self: 'a,
= T::ReadFuture<'a>;

fn read<'a>(&'a mut self, words: &'a mut [W]) -> Self::ReadFuture<'a> {
fn read<'a>(&'a mut self, words: &'a mut [Word]) -> Self::ReadFuture<'a> {
T::read(self, words)
}

@@ -52,21 +52,21 @@ impl<T: Read<W>, W: 'static + Copy> Read<W> for &mut T {

fn read_transaction<'a>(
&'a mut self,
words: &'a mut [&'a mut [W]],
words: &'a mut [&'a mut [Word]],
) -> Self::ReadTransactionFuture<'a> {
T::read_transaction(self, words)
}
}

/// Write-only SPI
pub trait Write<W: 'static + Copy = u8>: ErrorType {
pub trait Write<Word: 'static + Copy = u8>: ErrorType {
/// Future returned by the `write` method.
type WriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
where
Self: 'a;

/// Write `words` to the slave, ignoring all the incoming words
fn write<'a>(&'a mut self, words: &'a [W]) -> Self::WriteFuture<'a>;
fn write<'a>(&'a mut self, words: &'a [Word]) -> Self::WriteFuture<'a>;

/// Future returned by the `write_transaction` method.
type WriteTransactionFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
@@ -76,17 +76,17 @@ pub trait Write<W: 'static + Copy = u8>: ErrorType {
/// Write all slices in `words` to the slave as part of a single SPI transaction, ignoring all the incoming words
fn write_transaction<'a>(
&'a mut self,
words: &'a [&'a [W]],
words: &'a [&'a [Word]],
) -> Self::WriteTransactionFuture<'a>;
}

impl<T: Write<W>, W: 'static + Copy> Write<W> for &mut T {
impl<T: Write<Word>, Word: 'static + Copy> Write<Word> for &mut T {
type WriteFuture<'a>
where
Self: 'a,
= T::WriteFuture<'a>;

fn write<'a>(&'a mut self, words: &'a [W]) -> Self::WriteFuture<'a> {
fn write<'a>(&'a mut self, words: &'a [Word]) -> Self::WriteFuture<'a> {
T::write(self, words)
}

@@ -97,14 +97,14 @@ impl<T: Write<W>, W: 'static + Copy> Write<W> for &mut T {

fn write_transaction<'a>(
&'a mut self,
words: &'a [&'a [W]],
words: &'a [&'a [Word]],
) -> Self::WriteTransactionFuture<'a> {
T::write_transaction(self, words)
}
}

/// Read-write SPI
pub trait ReadWrite<W: 'static + Copy = u8>: Read<W> + Write<W> {
pub trait ReadWrite<Word: 'static + Copy = u8>: Read<Word> + Write<Word> {
/// Future returned by the `transfer` method.
type TransferFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
where
@@ -118,7 +118,11 @@ pub trait ReadWrite<W: 'static + Copy = u8>: Read<W> + Write<W> {
/// incoming words after `read` has been filled will be discarded. If `write` is shorter,
/// the value of words sent in MOSI after all `write` has been sent is implementation-defined,
/// typically `0x00`, `0xFF`, or configurable.
fn transfer<'a>(&'a mut self, read: &'a mut [W], write: &'a [W]) -> Self::TransferFuture<'a>;
fn transfer<'a>(
&'a mut self,
read: &'a mut [Word],
write: &'a [Word],
) -> Self::TransferFuture<'a>;

/// Future returned by the `transfer_in_place` method.
type TransferInPlaceFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
@@ -128,7 +132,10 @@ pub trait ReadWrite<W: 'static + Copy = u8>: Read<W> + Write<W> {
/// Write and read simultaneously. The contents of `words` are
/// written to the slave, and the received words are stored into the same
/// `words` buffer, overwriting it.
fn transfer_in_place<'a>(&'a mut self, words: &'a mut [W]) -> Self::TransferInPlaceFuture<'a>;
fn transfer_in_place<'a>(
&'a mut self,
words: &'a mut [Word],
) -> Self::TransferInPlaceFuture<'a>;

/// Future returned by the `transaction` method.
type TransactionFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
@@ -138,17 +145,21 @@ pub trait ReadWrite<W: 'static + Copy = u8>: Read<W> + Write<W> {
/// Execute multiple operations as part of a single SPI transaction
fn transaction<'a>(
&'a mut self,
operations: &'a mut [Operation<'a, W>],
operations: &'a mut [Operation<'a, Word>],
) -> Self::TransactionFuture<'a>;
}

impl<T: ReadWrite<W>, W: 'static + Copy> ReadWrite<W> for &mut T {
impl<T: ReadWrite<Word>, Word: 'static + Copy> ReadWrite<Word> for &mut T {
type TransferFuture<'a>
where
Self: 'a,
= T::TransferFuture<'a>;

fn transfer<'a>(&'a mut self, read: &'a mut [W], write: &'a [W]) -> Self::TransferFuture<'a> {
fn transfer<'a>(
&'a mut self,
read: &'a mut [Word],
write: &'a [Word],
) -> Self::TransferFuture<'a> {
T::transfer(self, read, write)
}

@@ -157,7 +168,10 @@ impl<T: ReadWrite<W>, W: 'static + Copy> ReadWrite<W> for &mut T {
Self: 'a,
= T::TransferInPlaceFuture<'a>;

fn transfer_in_place<'a>(&'a mut self, words: &'a mut [W]) -> Self::TransferInPlaceFuture<'a> {
fn transfer_in_place<'a>(
&'a mut self,
words: &'a mut [Word],
) -> Self::TransferInPlaceFuture<'a> {
T::transfer_in_place(self, words)
}

@@ -168,7 +182,7 @@ impl<T: ReadWrite<W>, W: 'static + Copy> ReadWrite<W> for &mut T {

fn transaction<'a>(
&'a mut self,
operations: &'a mut [Operation<'a, W>],
operations: &'a mut [Operation<'a, Word>],
) -> Self::TransactionFuture<'a> {
T::transaction(self, operations)
}