WPILibC++
unspecified
|
I2C bus interface class. More...
#include <I2C.h>
Public Types | |
enum | Port { kOnboard, kMXP } |
Public Member Functions | |
I2C (Port port, int deviceAddress) | |
Constructor. More... | |
virtual | ~I2C () |
Destructor. | |
I2C (const I2C &)=delete | |
I2C & | operator= (const I2C &)=delete |
bool | Transaction (uint8_t *dataToSend, int sendSize, uint8_t *dataReceived, int receiveSize) |
Generic transaction. More... | |
bool | AddressOnly () |
Attempt to address a device on the I2C bus. More... | |
bool | Write (int registerAddress, uint8_t data) |
Execute a write transaction with the device. More... | |
bool | WriteBulk (uint8_t *data, int count) |
Execute a bulk write transaction with the device. More... | |
bool | Read (int registerAddress, int count, uint8_t *data) |
Execute a read transaction with the device. More... | |
bool | ReadOnly (int count, uint8_t *buffer) |
Execute a read only transaction with the device. More... | |
void | Broadcast (int registerAddress, uint8_t data) |
Send a broadcast write to all devices on the I2C bus. More... | |
bool | VerifySensor (int registerAddress, int count, const uint8_t *expected) |
Verify that a device's registers contain expected values. More... | |
I2C bus interface class.
This class is intended to be used by sensor (and other I2C device) drivers. It probably should not be used directly.
I2C::I2C | ( | Port | port, |
int | deviceAddress | ||
) |
bool I2C::AddressOnly | ( | ) |
void I2C::Broadcast | ( | int | registerAddress, |
uint8_t | data | ||
) |
Send a broadcast write to all devices on the I2C bus.
This is not currently implemented!
registerAddress | The register to write on all devices on the bus. |
data | The value to write to the devices. |
bool I2C::Read | ( | int | registerAddress, |
int | count, | ||
uint8_t * | buffer | ||
) |
Execute a read transaction with the device.
Read bytes from a device. Most I2C devices will auto-increment the register pointer internally allowing you to read consecutive registers on a device in a single transaction.
registerAddress | The register to read first in the transaction. |
count | The number of bytes to read in the transaction. |
buffer | A pointer to the array of bytes to store the data read from the device. |
bool I2C::ReadOnly | ( | int | count, |
uint8_t * | buffer | ||
) |
Execute a read only transaction with the device.
Read bytes from a device. This method does not write any data to prompt the device.
buffer | A pointer to the array of bytes to store the data read from the device. |
count | The number of bytes to read in the transaction. |
bool I2C::Transaction | ( | uint8_t * | dataToSend, |
int | sendSize, | ||
uint8_t * | dataReceived, | ||
int | receiveSize | ||
) |
Generic transaction.
This is a lower-level interface to the I2C hardware giving you more control over each transaction.
dataToSend | Buffer of data to send as part of the transaction. |
sendSize | Number of bytes to send as part of the transaction. |
dataReceived | Buffer to read data into. |
receiveSize | Number of bytes to read from the device. |
bool I2C::VerifySensor | ( | int | registerAddress, |
int | count, | ||
const uint8_t * | expected | ||
) |
Verify that a device's registers contain expected values.
Most devices will have a set of registers that contain a known value that can be used to identify them. This allows an I2C device driver to easily verify that the device contains the expected value.
registerAddress | The base register to start reading from the device. |
count | The size of the field to be verified. |
expected | A buffer containing the values expected from the device. |
bool I2C::Write | ( | int | registerAddress, |
uint8_t | data | ||
) |
Execute a write transaction with the device.
Write a single byte to a register on a device and wait until the transaction is complete.
registerAddress | The address of the register on the device to be written. |
data | The byte to write to the register on the device. |
bool I2C::WriteBulk | ( | uint8_t * | data, |
int | count | ||
) |
Execute a bulk write transaction with the device.
Write multiple bytes to a device and wait until the transaction is complete.
data | The data to write to the register on the device. |
count | The number of bytes to be written. |