Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::SyncedI2C Class Reference

Thread safe version of the I2C high-level driver. More...

#include <I2C.h>

Inheritance diagram for Boardcore::SyncedI2C:
Collaboration diagram for Boardcore::SyncedI2C:

Public Member Functions

 SyncedI2C (I2C_TypeDef *i2c, const miosix::GpioPin &scl, const miosix::GpioPin &sda)
 Constructor for the synced I2C high-level driver.
 
 SyncedI2C (const SyncedI2C &)=delete
 
SyncedI2Coperator= (const SyncedI2C &)=delete
 
 SyncedI2C (SyncedI2C &&)=delete
 
SyncedI2Coperator= (SyncedI2C &&)=delete
 
bool read (const I2CDriver::I2CSlaveConfig &slaveConfig, void *buffer, const size_t nBytes)
 Read operation to read nBytes.
 
bool write (const I2CDriver::I2CSlaveConfig &slaveConfig, const void *buffer, const size_t nBytes)
 Write operation to write nBytes.
 
bool readRegister (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint8_t &registerContent)
 Read an 8-bit register from the device.
 
bool readRegister16 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint16_t &registerContent)
 Read a 16-bit register from the device.
 
bool readRegister24 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t &registerContent)
 Read a 24-bit register from the device.
 
bool readRegister32 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t &registerContent)
 Read a 32-bit register from the device.
 
bool writeRegister (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint8_t registerContent)
 Write an 8-bit register from the device.
 
bool writeRegister16 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint16_t registerContent)
 Write a 16-bit register from the device.
 
bool writeRegister24 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint32_t registerContent)
 Write a 24-bit register from the device.
 
bool writeRegister32 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint32_t registerContent)
 Write a 32-bit register from the device.
 
bool readFromRegister (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, void *buffer, const size_t nBytes)
 Read n-bytes from register from a slave.
 
bool probe (const I2CDriver::I2CSlaveConfig &slaveConfig)
 Check if a slave is available.
 
uint16_t getLastError ()
 Returns the last errors happened in the communication.
 
- Public Member Functions inherited from Boardcore::I2C
 I2C (I2C_TypeDef *i2c, const miosix::GpioPin &scl, const miosix::GpioPin &sda)
 Constructor for the I2C high-level driver.
 
 I2C (const I2C &)=delete
 
I2Coperator= (const I2C &)=delete
 
 I2C (I2C &&)=delete
 
I2Coperator= (I2C &&)=delete
 
bool read (const I2CDriver::I2CSlaveConfig &slaveConfig, void *buffer, const size_t nBytes)
 Non blocking read operation to read nBytes.
 
bool write (const I2CDriver::I2CSlaveConfig &slaveConfig, const void *buffer, const size_t nBytes)
 Non blocking write operation to write nBytes.
 
bool readRegister (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint8_t &registerContent)
 Non blocking operation to read an 8-bit register from a slave.
 
bool readRegister16 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint16_t &registerContent)
 Non blocking operation to read a 16-bit register from a slave.
 
bool readRegister24 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t &registerContent)
 Non blocking operation to read a 24-bit register from a slave.
 
bool readRegister32 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t &registerContent)
 Non blocking operation to read a 32-bit register from a slave.
 
bool writeRegister (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint8_t registerContent)
 Non blocking operation to write an 8-bit register from a slave.
 
bool writeRegister16 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint16_t registerContent)
 Non blocking operation to write a 16-bit register from a slave.
 
bool writeRegister24 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint32_t registerContent)
 Non blocking operation to write a 24-bit register from a slave.
 
bool writeRegister32 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, const uint32_t registerContent)
 Non blocking operation to write a 32-bit register from a slave.
 
bool readFromRegister (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, void *buffer, const size_t nBytes)
 Non blocking operation to read n-bytes from register from a slave.
 
bool probe (const I2CDriver::I2CSlaveConfig &slaveConfig)
 Non blocking operation to check if a slave is available.
 
uint16_t getLastError ()
 Returns the last errors happened in the communication.
 

Additional Inherited Members

- Protected Attributes inherited from Boardcore::I2C
I2CDriver i2c
 Instance of I2C low-level driver.
 

Detailed Description

Thread safe version of the I2C high-level driver.

Definition at line 270 of file I2C.h.

Constructor & Destructor Documentation

◆ SyncedI2C() [1/3]

Boardcore::SyncedI2C::SyncedI2C ( I2C_TypeDef * i2c,
const miosix::GpioPin & scl,
const miosix::GpioPin & sda )

Constructor for the synced I2C high-level driver.

Parameters
i2cStructure that represents the I2C peripheral.
sclSerial clock GpioPin of the relative I2C peripheral.
sdaSerial data GpioPin of the relative I2C peripheral. Delete copy/move constructors/operators.

Definition at line 206 of file I2C.cpp.

◆ SyncedI2C() [2/3]

Boardcore::SyncedI2C::SyncedI2C ( const SyncedI2C & )
delete

◆ SyncedI2C() [3/3]

Boardcore::SyncedI2C::SyncedI2C ( SyncedI2C && )
delete

Member Function Documentation

◆ getLastError()

uint16_t Boardcore::SyncedI2C::getLastError ( )

Returns the last errors happened in the communication.

For checking if a specific error occurred in the last transaction you can do if(getLastError() &Errors::<error-to-check>). Do not use == to check for errors because there could be more errors at once. To check if no errors occurred use if(getLastError() == Errors::NO_ERROR) or simply if(!getLastError())

Returns
A bit sequence where the bits set correspond to the last errors occurred in the peripheral (see the I2CDriver::Errors enum to get the correspondence between bit position and error reported).

Definition at line 304 of file I2C.cpp.

◆ operator=() [1/2]

SyncedI2C & Boardcore::SyncedI2C::operator= ( const SyncedI2C & )
delete

◆ operator=() [2/2]

SyncedI2C & Boardcore::SyncedI2C::operator= ( SyncedI2C && )
delete

◆ probe()

bool Boardcore::SyncedI2C::probe ( const I2CDriver::I2CSlaveConfig & slaveConfig)

Check if a slave is available.

This method could have to wait that no other thread is trying to do some operation on the bus.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
Returns
true if the device is available, false otherwise.

Definition at line 298 of file I2C.cpp.

◆ read()

bool Boardcore::SyncedI2C::read ( const I2CDriver::I2CSlaveConfig & slaveConfig,
void * buffer,
const size_t nBytes )

Read operation to read nBytes.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
bufferData buffer where to store the data read.
nBytesNumber of bytes to read.
Returns
True if the read is successful, false otherwise.

Definition at line 212 of file I2C.cpp.

◆ readFromRegister()

bool Boardcore::SyncedI2C::readFromRegister ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
void * buffer,
const size_t nBytes )

Read n-bytes from register from a slave.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
bufferData buffer where to store the data read.
nBytesNumber of bytes to read.
Returns
True if the read is successful, false otherwise.

Definition at line 290 of file I2C.cpp.

◆ readRegister()

bool Boardcore::SyncedI2C::readRegister ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
uint8_t & registerContent )

Read an 8-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentWhere to store the content of the register.
Returns
True if the read is successful, false otherwise.

Definition at line 226 of file I2C.cpp.

◆ readRegister16()

bool Boardcore::SyncedI2C::readRegister16 ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
uint16_t & registerContent )

Read a 16-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentWhere to store the content of the register.
Returns
True if the read is successful, false otherwise.

Definition at line 234 of file I2C.cpp.

◆ readRegister24()

bool Boardcore::SyncedI2C::readRegister24 ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
uint32_t & registerContent )

Read a 24-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentWhere to store the content of the register.
Returns
True if the read is successful, false otherwise.

Definition at line 242 of file I2C.cpp.

◆ readRegister32()

bool Boardcore::SyncedI2C::readRegister32 ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
uint32_t & registerContent )

Read a 32-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentWhere to store the content of the register.
Returns
True if the read is successful, false otherwise.

Definition at line 250 of file I2C.cpp.

◆ write()

bool Boardcore::SyncedI2C::write ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const void * buffer,
const size_t nBytes )

Write operation to write nBytes.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
bufferData buffer where to read the data to send.
nBytesNumber of bytes to send.
Returns
True if the write is successful, false otherwise.

Definition at line 219 of file I2C.cpp.

◆ writeRegister()

bool Boardcore::SyncedI2C::writeRegister ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
const uint8_t registerContent )

Write an 8-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentThe content to write on the register.
Returns
True if the write is successful, false otherwise.

Definition at line 258 of file I2C.cpp.

◆ writeRegister16()

bool Boardcore::SyncedI2C::writeRegister16 ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
const uint16_t registerContent )

Write a 16-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentThe content to write on the register.
Returns
True if the write is successful, false otherwise.

Definition at line 266 of file I2C.cpp.

◆ writeRegister24()

bool Boardcore::SyncedI2C::writeRegister24 ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
const uint32_t registerContent )

Write a 24-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentThe content to write on the register.
Returns
True if the write is successful, false otherwise.

Definition at line 274 of file I2C.cpp.

◆ writeRegister32()

bool Boardcore::SyncedI2C::writeRegister32 ( const I2CDriver::I2CSlaveConfig & slaveConfig,
const uint8_t registerAddress,
const uint32_t registerContent )

Write a 32-bit register from the device.

This method could have to wait that no other thread is trying to do some operation on the bus. In case of an error during the communication, this method returns false immediately.

Warning
Check always if the operation succeeded or not!
Parameters
slaveConfigThe configuration struct of the slave device.
registerAddressByte that represents the address of the register.
registerContentThe content to write on the register.
Returns
True if the write is successful, false otherwise.

Definition at line 282 of file I2C.cpp.


The documentation for this class was generated from the following files: