I2C Class¶
- class I2CClass : public Acroname::BrainStem::EntityClass¶
I2CClass: Interface the I2C buses on BrainStem modules. The class provides a way to send read and write commands to I2C devices on the entities bus.
Public Functions
- I2CClass(void)¶
Constructor.
- virtual ~I2CClass(void)¶
Destructor.
- void init(Module *pModule, const uint8_t index)¶
Initialize the class.
- Parameters:
pModule – The module to which this entity belongs.
index – The index of the digital entity being initialized.
- aErr read(const uint8_t address, const uint8_t readLength, uint8_t *buffer)¶
Read from a device on this I2C bus.
- Parameters:
address – - The I2C address (7bit <XXXX-XXX0>) of the device to read.
readLength – - The length of the data to read in bytes.
buffer – - The array of bytes that will be filled with the result, upon success. This array should be larger or equivalent to aBRAINSTEM_MAXPACKETBYTES - 5
- Returns:
Returns common entity return values
- aErr write(const uint8_t address, const uint8_t bufferLength, const uint8_t *buffer)¶
Write to a device on this I2C bus.
- Parameters:
address – - The I2C address (7bit <XXXX-XXX0>) of the device to write.
bufferLength – - The length of the data to write in bytes.
buffer – - The data to send to the device, This array should be no larger than aBRAINSTEM_MAXPACKETBYTES - 5
- Returns:
Returns common entity return values
- aErr setPullup(const bool bEnable)¶
Set bus pull-up state. This call only works with stems that have software controlled pull-ups. Check the datasheet for more information. This parameter is saved when system.save is called.
- Parameters:
bEnable – - true enables pull-ups false disables them.
- Returns:
Returns common entity return values
- aErr setSpeed(const uint8_t speed)¶
Set I2C bus speed.
This call sets the communication speed for I2C transactions through this API. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz
- Parameters:
speed – - The speed setting value.
- Returns:
Returns common entity return values
- aErr getSpeed(uint8_t *speed)¶
Get I2C bus speed.
This call gets the communication speed for I2C transactions through this API. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz
- Parameters:
speed – - The speed setting value.
- Returns:
Returns common entity return values