WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
frc::I2C Class Reference

I2C bus interface class. More...

#include <I2C.h>

Inheritance diagram for frc::I2C:
frc::ErrorBase

Public Types

enum  Port { kOnboard = 0, kMXP }
 

Public Member Functions

 I2C (Port port, int deviceAddress)
 Constructor. More...
 
 I2C (I2C &&rhs)
 
I2Coperator= (I2C &&rhs)
 
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...
 
bool VerifySensor (int registerAddress, int count, const uint8_t *expected)
 Verify that a device's registers contain expected values. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static const ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

Detailed Description

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.

Constructor & Destructor Documentation

frc::I2C::I2C ( Port  port,
int  deviceAddress 
)

Constructor.

Parameters
portThe I2C port to which the device is connected.
deviceAddressThe address of the device on the I2C bus.

Member Function Documentation

bool frc::I2C::AddressOnly ( )

Attempt to address a device on the I2C bus.

This allows you to figure out if there is a device on the I2C bus that responds to the address specified in the constructor.

Returns
Transfer Aborted... false for success, true for aborted.
bool frc::I2C::Read ( int  registerAddress,
int  count,
uint8_t *  data 
)

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.

Parameters
registerAddressThe register to read first in the transaction.
countThe number of bytes to read in the transaction.
bufferA pointer to the array of bytes to store the data read from the device.
Returns
Transfer Aborted... false for success, true for aborted.
bool frc::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.

Parameters
bufferA pointer to the array of bytes to store the data read from the device.
countThe number of bytes to read in the transaction.
Returns
Transfer Aborted... false for success, true for aborted.
bool frc::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.

Parameters
dataToSendBuffer of data to send as part of the transaction.
sendSizeNumber of bytes to send as part of the transaction.
dataReceivedBuffer to read data into.
receiveSizeNumber of bytes to read from the device.
Returns
Transfer Aborted... false for success, true for aborted.
bool frc::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.

Precondition
The device must support and be configured to use register auto-increment.
Parameters
registerAddressThe base register to start reading from the device.
countThe size of the field to be verified.
expectedA buffer containing the values expected from the device.
bool frc::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.

Parameters
registerAddressThe address of the register on the device to be written.
dataThe byte to write to the register on the device.
Returns
Transfer Aborted... false for success, true for aborted.
bool frc::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.

Parameters
dataThe data to write to the register on the device.
countThe number of bytes to be written.
Returns
Transfer Aborted... false for success, true for aborted.

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