I2c

Struct I2c 

Source
pub struct I2c<I2C, SDA, SCL> { /* private fields */ }
Expand description

I2C abstraction

Implementations§

Source§

impl<SDA, SCL> I2c<I2C1, SDA, SCL>
where SDA: SDAPin<I2C1>, SCL: SCLPin<I2C1>,

Source

pub fn i2c1( i2c: I2C1, sda: SDA, scl: SCL, config: impl Into<Config>, rcc: &mut Rcc, ) -> Self
where SDA: SDAPin<I2C1>, SCL: SCLPin<I2C1>,

Source

pub fn listen(&mut self, ev: Event)

Source

pub fn unlisten(&mut self, ev: Event)

Source

pub fn clear_irq(&mut self, ev: Event)

Source

pub fn release(self) -> (I2C1, SDA, SCL)

Source§

impl<SDA, SCL> I2c<I2C2, SDA, SCL>
where SDA: SDAPin<I2C2>, SCL: SCLPin<I2C2>,

Source

pub fn i2c2( i2c: I2C2, sda: SDA, scl: SCL, config: impl Into<Config>, rcc: &mut Rcc, ) -> Self
where SDA: SDAPin<I2C2>, SCL: SCLPin<I2C2>,

Source

pub fn listen(&mut self, ev: Event)

Source

pub fn unlisten(&mut self, ev: Event)

Source

pub fn clear_irq(&mut self, ev: Event)

Source

pub fn release(self) -> (I2C2, SDA, SCL)

Trait Implementations§

Source§

impl<SDA, SCL> I2cSlave for I2c<I2C1, SDA, SCL>

Source§

fn slave_sbc(&mut self, sbc_enabled: bool)

Enable/Disable Slave Byte Control. Default SBC is switched on. For master write/read the transaction should start with sbc disabled. So ACK will be send on the last received byte. Before the send phase SBC should be enabled again.
Source§

fn slave_addressed(&mut self) -> Result<Option<(u16, I2cDirection)>, Error>

An optional tuple is returned with the address as sent by the master. The address is for 7 bit in range of 0..127
Source§

fn slave_wait_addressed(&mut self) -> Result<(u16, I2cDirection), Error>

Wait until this slave is addressed by the master. A tuple is returned with the address as sent by the master. The address is for 7 bit in range of 0..127
Source§

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

Start writing the bytes, the master want to receive. If OK returned, all bytes are transferred If the master wants more data than bytes.len() the master will run into a timeout, This function will return Ok(()) If the master wants less data than bytes.len(), the function will return IncorrectFrameSize(bytes.len() + 1)
Source§

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

Start reading the bytes, send by the master . If OK returned, all bytes are transferred If the master want to send more bytes than the slave can recieve the slave will NACK the n+1 byte In this case the function will return IncorrectFrameSize(bytes.len() + 1) If the master did send a STOP before all bytes are recieve, the slave will return IncorrectFrameSize(actual nr of bytes send)
Source§

impl<SDA, SCL> I2cSlave for I2c<I2C2, SDA, SCL>

Source§

fn slave_sbc(&mut self, sbc_enabled: bool)

Enable/Disable Slave Byte Control. Default SBC is switched on. For master write/read the transaction should start with sbc disabled. So ACK will be send on the last received byte. Before the send phase SBC should be enabled again.
Source§

fn slave_addressed(&mut self) -> Result<Option<(u16, I2cDirection)>, Error>

An optional tuple is returned with the address as sent by the master. The address is for 7 bit in range of 0..127
Source§

fn slave_wait_addressed(&mut self) -> Result<(u16, I2cDirection), Error>

Wait until this slave is addressed by the master. A tuple is returned with the address as sent by the master. The address is for 7 bit in range of 0..127
Source§

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

Start writing the bytes, the master want to receive. If OK returned, all bytes are transferred If the master wants more data than bytes.len() the master will run into a timeout, This function will return Ok(()) If the master wants less data than bytes.len(), the function will return IncorrectFrameSize(bytes.len() + 1)
Source§

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

Start reading the bytes, send by the master . If OK returned, all bytes are transferred If the master want to send more bytes than the slave can recieve the slave will NACK the n+1 byte In this case the function will return IncorrectFrameSize(bytes.len() + 1) If the master did send a STOP before all bytes are recieve, the slave will return IncorrectFrameSize(actual nr of bytes send)
Source§

impl<SDA, SCL> Read for I2c<I2C1, SDA, SCL>

Source§

type Error = Error

Error type
Source§

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

Reads enough bytes from slave with address to fill buffer Read more
Source§

impl<SDA, SCL> Read for I2c<I2C2, SDA, SCL>

Source§

type Error = Error

Error type
Source§

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

Reads enough bytes from slave with address to fill buffer Read more
Source§

impl<SDA, SCL> Write for I2c<I2C1, SDA, SCL>

Source§

type Error = Error

Error type
Source§

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

Writes bytes to slave with address address Read more
Source§

impl<SDA, SCL> Write for I2c<I2C2, SDA, SCL>

Source§

type Error = Error

Error type
Source§

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

Writes bytes to slave with address address Read more
Source§

impl<SDA, SCL> WriteRead for I2c<I2C1, SDA, SCL>

Source§

type Error = Error

Error type
Source§

fn write_read( &mut self, addr: u8, snd_buffer: &[u8], rcv_buffer: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more
Source§

impl<SDA, SCL> WriteRead for I2c<I2C2, SDA, SCL>

Source§

type Error = Error

Error type
Source§

fn write_read( &mut self, addr: u8, snd_buffer: &[u8], rcv_buffer: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more

Auto Trait Implementations§

§

impl<I2C, SDA, SCL> Freeze for I2c<I2C, SDA, SCL>
where I2C: Freeze, SDA: Freeze, SCL: Freeze,

§

impl<I2C, SDA, SCL> RefUnwindSafe for I2c<I2C, SDA, SCL>
where I2C: RefUnwindSafe, SDA: RefUnwindSafe, SCL: RefUnwindSafe,

§

impl<I2C, SDA, SCL> Send for I2c<I2C, SDA, SCL>
where I2C: Send, SDA: Send, SCL: Send,

§

impl<I2C, SDA, SCL> Sync for I2c<I2C, SDA, SCL>
where I2C: Sync, SDA: Sync, SCL: Sync,

§

impl<I2C, SDA, SCL> Unpin for I2c<I2C, SDA, SCL>
where I2C: Unpin, SDA: Unpin, SCL: Unpin,

§

impl<I2C, SDA, SCL> UnwindSafe for I2c<I2C, SDA, SCL>
where I2C: UnwindSafe, SDA: UnwindSafe, SCL: 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.