Struct stm32g0xx_hal::i2c::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>,
impl<SDA, SCL> I2c<I2C1, SDA, SCL>where
SDA: SDAPin<I2C1>,
SCL: SCLPin<I2C1>,
pub fn i2c1(
i2c: I2C1,
sda: SDA,
scl: SCL,
config: impl Into<Config>,
rcc: &mut Rcc
) -> Selfwhere
SDA: SDAPin<I2C1>,
SCL: SCLPin<I2C1>,
pub fn listen(&mut self, ev: Event)
pub fn unlisten(&mut self, ev: Event)
pub fn clear_irq(&mut self, ev: Event)
pub fn release(self) -> (I2C1, SDA, SCL)
source§impl<SDA, SCL> I2c<I2C2, SDA, SCL>where
SDA: SDAPin<I2C2>,
SCL: SCLPin<I2C2>,
impl<SDA, SCL> I2c<I2C2, SDA, SCL>where
SDA: SDAPin<I2C2>,
SCL: SCLPin<I2C2>,
pub fn i2c2(
i2c: I2C2,
sda: SDA,
scl: SCL,
config: impl Into<Config>,
rcc: &mut Rcc
) -> Selfwhere
SDA: SDAPin<I2C2>,
SCL: SCLPin<I2C2>,
pub fn listen(&mut self, ev: Event)
pub fn unlisten(&mut self, ev: Event)
pub fn clear_irq(&mut self, ev: Event)
pub fn release(self) -> (I2C2, SDA, SCL)
Trait Implementations§
source§impl<SDA, SCL> I2cSlave for I2c<I2C1, SDA, SCL>
impl<SDA, SCL> I2cSlave for I2c<I2C1, SDA, SCL>
source§fn slave_sbc(&mut self, sbc_enabled: bool)
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>
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>
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>
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>
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>
impl<SDA, SCL> I2cSlave for I2c<I2C2, SDA, SCL>
source§fn slave_sbc(&mut self, sbc_enabled: bool)
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>
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>
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>
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>
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)