Skyward boardcore
|
High level driver for the I2C peripherals. More...
#include <I2C.h>
Public Member Functions | |
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. | |
Protected Attributes | |
I2CDriver | i2c |
Instance of I2C low-level driver. | |
High level driver for the I2C peripherals.
This driver is NOT thread safe. It implements high level functionalities such as:
Boardcore::I2C::I2C | ( | I2C_TypeDef * | i2c, |
const miosix::GpioPin & | scl, | ||
const miosix::GpioPin & | sda ) |
Constructor for the I2C high-level driver.
It uses the low-level I2C constructor that internally initializes the pins so that they are always set to ALTERNATE_OD mode with Alternate Function 4 (the usual AF of I2C pins). Thanks to this we avoid the possibility of short circuits between master and slaves when they both drive the same bus on two different logical values.
|
delete |
|
delete |
uint16_t Boardcore::I2C::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::I2C::probe | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig | ) |
bool Boardcore::I2C::read | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig, |
void * | buffer, | ||
const size_t | nBytes ) |
Non blocking read operation to read nBytes.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::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.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::readRegister | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig, |
const uint8_t | registerAddress, | ||
uint8_t & | registerContent ) |
Non blocking operation to read an 8-bit register from a slave.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::readRegister16 | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig, |
const uint8_t | registerAddress, | ||
uint16_t & | registerContent ) |
Non blocking operation to read a 16-bit register from a slave.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::readRegister24 | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig, |
const uint8_t | registerAddress, | ||
uint32_t & | registerContent ) |
Non blocking operation to read a 24-bit register from a slave.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::readRegister32 | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig, |
const uint8_t | registerAddress, | ||
uint32_t & | registerContent ) |
Non blocking operation to read a 32-bit register from a slave.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::write | ( | const I2CDriver::I2CSlaveConfig & | slaveConfig, |
const void * | buffer, | ||
const size_t | nBytes ) |
Non blocking write operation to write nBytes.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::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.
This method, if necessary, flushes the bus before the write operation is performed. 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::I2C::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.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::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.
This method, if necessary, flushes the bus before the read operation is performed. 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::I2C::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.
This method, if necessary, flushes the bus before the read operation is performed. 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. |
|
protected |