pub struct I2C<const N: usize> { /* private fields */ }
Expand description
This struct represents a configured I2C peripheral.
Implementations§
Source§impl<const N: usize> I2C<N>
impl<const N: usize> I2C<N>
Sourcepub fn new(
core: u8,
scl_pin: (char, u8),
sda_pin: (char, u8),
pullup: bool,
) -> Result<Self, ProgError>
pub fn new( core: u8, scl_pin: (char, u8), sda_pin: (char, u8), pullup: bool, ) -> Result<Self, ProgError>
Configure a I2C connection with one of the internal I2C peripherals.
This Method expects the used I2C core, two pin identifiers for the scl and sda-pins and if the internal pullup-resistors should be used as parameters and returns the I2C Struct. Specitfy the buffer capapcity with the turbofish operator. Panics if the core or pins are already used or invalid.
Sourcepub fn end(self)
pub fn end(self)
Deacitivates the I2C peripheral and destroys the struct, freeing the core and pins.
Sourcepub fn begin_transmission(&mut self, addr: u8)
pub fn begin_transmission(&mut self, addr: u8)
Initiate transmission to a slave with entered address.
Sourcepub fn write(&mut self, data: u8) -> Result<(), ProgError>
pub fn write(&mut self, data: u8) -> Result<(), ProgError>
Add a byte that is send to the slave. Returns an error-enum if transmittion is not initiated or the tx buffer is full.
Sourcepub fn end_transmission(&mut self, stop: bool) -> Result<(), I2cError>
pub fn end_transmission(&mut self, stop: bool) -> Result<(), I2cError>
Burst tranfers the bytes in the tx buffer to the slave. Specify if a stop bit should be send. Normally this should be true. It can be false if you want to communicate with multiple slaves simultaniously. Returns an error-enum if problems with the connection are detected.
Sourcepub fn request_bytes(
&mut self,
addr: u8,
nbytes: u8,
stop: bool,
) -> Result<usize, I2cError>
pub fn request_bytes( &mut self, addr: u8, nbytes: u8, stop: bool, ) -> Result<usize, I2cError>
Request a number of bytes from a slave with the specified address. Recieved bytes are stored in the rx buffer. Specify if a stop bit should be send. Normally this should be true. It can be false if you want to communicate with multiple slaves simultaniously. Returns an error-enum if the buffer cannot hold the number of bytes or a problem with the connection is detected.