I2CPeripheral

Struct I2CPeripheral 

Source
pub struct I2CPeripheral<'a, I2C, E, const ADDRESS: u8> { /* private fields */ }
Expand description

The I2C Implementation of the Interface trait

This seems to work and has been tested a bit.

Note the lifetimes. This struct takes ownership of the mutable borrow until it is dropped out of scope

Implementations§

Source§

impl<'a, I2C, E, const ADDRESS: u8> I2CPeripheral<'a, I2C, E, ADDRESS>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,

Source

pub fn new(bus: &'a mut I2C) -> I2CPeripheral<'a, I2C, E, ADDRESS>

This makes a peripheral struct that implements the Interface trait

The peripheral takes ownership of the mut borrow for the life Of the struct so the struct is only ever expected to live breifely but it might be nice to make a parent thing that know the chip id etc that can have long life and then spawns on of these periodically

Trait Implementations§

Source§

impl<'a, I2C, E, const ADDRESS: u8> Interface for I2CPeripheral<'a, I2C, E, ADDRESS>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,

Source§

fn read_register( &mut self, register: u8, buffer: &mut [u8], ) -> Result<(), Self::Error>

Read buffer.len() bytes starting at the reg at register This is the i2c implementation for the interface trait

Source§

fn write_register( &mut self, register: u8, bytes: &[u8], ) -> Result<(), Self::Error>

Write buffer.len() bytes starting at the reg at register This is the i2c implementation for the interface trait NOTE: The current implementation only works for 10 bytes And will panic if more are given.

Source§

type Error = InterfaceError<E>

Auto Trait Implementations§

§

impl<'a, I2C, E, const ADDRESS: u8> Freeze for I2CPeripheral<'a, I2C, E, ADDRESS>

§

impl<'a, I2C, E, const ADDRESS: u8> RefUnwindSafe for I2CPeripheral<'a, I2C, E, ADDRESS>

§

impl<'a, I2C, E, const ADDRESS: u8> Send for I2CPeripheral<'a, I2C, E, ADDRESS>
where I2C: Send, E: Send,

§

impl<'a, I2C, E, const ADDRESS: u8> Sync for I2CPeripheral<'a, I2C, E, ADDRESS>
where I2C: Sync, E: Sync,

§

impl<'a, I2C, E, const ADDRESS: u8> Unpin for I2CPeripheral<'a, I2C, E, ADDRESS>
where E: Unpin,

§

impl<'a, I2C, E, const ADDRESS: u8> !UnwindSafe for I2CPeripheral<'a, I2C, E, ADDRESS>

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.