Skyward boardcore
|
Thread safe version of the I2C high-level driver. More...
#include <I2C.h>
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 | |
SyncedI2C & | operator= (const SyncedI2C &)=delete |
SyncedI2C (SyncedI2C &&)=delete | |
SyncedI2C & | operator= (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 ®isterContent) |
Read an 8-bit register from the device. | |
bool | readRegister16 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint16_t ®isterContent) |
Read a 16-bit register from the device. | |
bool | readRegister24 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t ®isterContent) |
Read a 24-bit register from the device. | |
bool | readRegister32 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t ®isterContent) |
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. | |
![]() | |
I2C (I2C_TypeDef *i2c, const miosix::GpioPin &scl, const miosix::GpioPin &sda) | |
Constructor for the I2C high-level driver. | |
I2C (const I2C &)=delete | |
I2C & | operator= (const I2C &)=delete |
I2C (I2C &&)=delete | |
I2C & | operator= (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 ®isterContent) |
Non blocking operation to read an 8-bit register from a slave. | |
bool | readRegister16 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint16_t ®isterContent) |
Non blocking operation to read a 16-bit register from a slave. | |
bool | readRegister24 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t ®isterContent) |
Non blocking operation to read a 24-bit register from a slave. | |
bool | readRegister32 (const I2CDriver::I2CSlaveConfig &slaveConfig, const uint8_t registerAddress, uint32_t ®isterContent) |
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 | |
![]() | |
I2CDriver | i2c |
Instance of I2C low-level driver. | |
Boardcore::SyncedI2C::SyncedI2C | ( | I2C_TypeDef * | i2c, |
const miosix::GpioPin & | scl, | ||
const miosix::GpioPin & | sda ) |
|
delete |
|
delete |
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())
I2CDriver::Errors
enum to get the correspondence between bit position and error reported). 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.
slaveConfig | The configuration struct of the slave device. |
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.
slaveConfig | The configuration struct of the slave device. |
buffer | Data buffer where to store the data read. |
nBytes | Number of bytes to read. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
buffer | Data buffer where to store the data read. |
nBytes | Number of bytes to read. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | Where to store the content of the register. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | Where to store the content of the register. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | Where to store the content of the register. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | Where to store the content of the register. |
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.
slaveConfig | The configuration struct of the slave device. |
buffer | Data buffer where to read the data to send. |
nBytes | Number of bytes to send. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | The content to write on the register. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | The content to write on the register. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | The content to write on the register. |
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.
slaveConfig | The configuration struct of the slave device. |
registerAddress | Byte that represents the address of the register. |
registerContent | The content to write on the register. |