Struct Spy

Source
pub struct Spy<T, F>
where F: Fn(DataWord),
{ /* private fields */ }
Expand description

embedded hal spy implemnets call backs for used traits

Intended use is chaining over an existing embedded_hal implementation sniffing all the data. Useful when preparing for a refacforing and want to collect actual data for unit test case.

Blocking SPI API hal::blocking::spi::Transfer will return DataWord::First at start of transfer, all data sent in DataWord::Byte(u8) DataWord::Response to indicate where transmit ends and response begins all recived bytes in DataWord::Byte(u8) ending with DataWord::Last

Usage:

   extern crate embedded_hal_spy;
   use embedded_hal_spy::DataWord;

   let mut spix = embedded_hal_spy::new(spi,
            |w|{
                match w {
                    DataWord::First => {
                        print!("data = [");
                    },
                    DataWord::Last =>  {println!("],"); },
                    DataWord::Response =>  { print!("],\r\n       ["); },

                    DataWord::Byte(num) => {
                        print!("{:x},",num);
                        },
                    _other => {},
                }
            }
     );

Trait Implementations§

Source§

impl<T, F> InputPin for Spy<T, F>
where T: InputPin, F: Fn(DataWord),

Digital InputPin

Source§

type Error = <T as InputPin>::Error

Error type
Source§

fn is_high(&self) -> Result<bool, Self::Error>

Is the input pin high?
Source§

fn is_low(&self) -> Result<bool, Self::Error>

Is the input pin low?
Source§

impl<T, F> OutputPin for Spy<T, F>
where T: OutputPin, F: Fn(DataWord),

Digital OutputPin

Source§

type Error = <T as OutputPin>::Error

Error type
Source§

fn set_high(&mut self) -> Result<(), T::Error>

Drives the pin high Read more
Source§

fn set_low(&mut self) -> Result<(), T::Error>

Drives the pin low Read more
Source§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value Read more
Source§

impl<T, F> StatefulOutputPin for Spy<T, F>

Source§

fn is_set_high(&self) -> Result<bool, T::Error>

Is the pin in drive high mode? Read more
Source§

fn is_set_low(&self) -> Result<bool, T::Error>

Is the pin in drive low mode? Read more
Source§

impl<T, F> ToggleableOutputPin for Spy<T, F>

Source§

type Error = <T as ToggleableOutputPin>::Error

Error type
Source§

fn toggle(&mut self) -> Result<(), T::Error>

Toggle pin output.
Source§

impl<T, F> Transfer<u8> for Spy<T, F>
where T: Transfer<u8>, F: Fn(DataWord),

Source§

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error>

Sends Word to the slave. Returns the Word received from the slave

Source§

type Error = <T as Transfer<u8>>::Error

Error type
Source§

impl<T, F> Write<u8> for Spy<T, F>
where T: Write<u8>, F: Fn(DataWord),

Blocking write

Source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words

Source§

type Error = <T as Write<u8>>::Error

Error type
Source§

impl<T, F> FullDuplex<u8> for Spy<T, F>
where T: FullDuplex<u8>, F: Fn(DataWord),

FullDuplex will return every data sent and read in DataWord::Byte(u8)

Source§

type Error = <T as FullDuplex<u8>>::Error

An enumeration of SPI errors
Source§

fn read(&mut self) -> Result<u8, Error<Self::Error>>

Reads the word stored in the shift register Read more
Source§

fn send(&mut self, w: u8) -> Result<(), Error<Self::Error>>

Sends a word to the slave

Auto Trait Implementations§

§

impl<T, F> !Freeze for Spy<T, F>

§

impl<T, F> !RefUnwindSafe for Spy<T, F>

§

impl<T, F> Send for Spy<T, F>
where T: Send, F: Send,

§

impl<T, F> !Sync for Spy<T, F>

§

impl<T, F> Unpin for Spy<T, F>
where T: Unpin, F: Unpin,

§

impl<T, F> UnwindSafe for Spy<T, F>
where T: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.