WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
I2C.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "SensorBase.h"
11 
19 class I2C : SensorBase {
20  public:
21  enum Port { kOnboard, kMXP };
22 
23  I2C(Port port, uint8_t deviceAddress);
24  virtual ~I2C();
25 
26  I2C(const I2C&) = delete;
27  I2C& operator=(const I2C&) = delete;
28 
29  bool Transaction(uint8_t *dataToSend, uint8_t sendSize, uint8_t *dataReceived,
30  uint8_t receiveSize);
31  bool AddressOnly();
32  bool Write(uint8_t registerAddress, uint8_t data);
33  bool WriteBulk(uint8_t *data, uint8_t count);
34  bool Read(uint8_t registerAddress, uint8_t count, uint8_t *data);
35  bool ReadOnly(uint8_t count, uint8_t *buffer);
36  void Broadcast(uint8_t registerAddress, uint8_t data);
37  bool VerifySensor(uint8_t registerAddress, uint8_t count,
38  const uint8_t *expected);
39 
40  private:
41  Port m_port;
42  uint8_t m_deviceAddress;
43 };
bool Write(uint8_t registerAddress, uint8_t data)
Execute a write transaction with the device.
Definition: I2C.cpp:79
I2C(Port port, uint8_t deviceAddress)
Constructor.
Definition: I2C.cpp:19
virtual ~I2C()
Destructor.
Definition: I2C.cpp:31
bool Transaction(uint8_t *dataToSend, uint8_t sendSize, uint8_t *dataReceived, uint8_t receiveSize)
Generic transaction.
Definition: I2C.cpp:45
bool ReadOnly(uint8_t count, uint8_t *buffer)
Execute a read only transaction with the device.
Definition: I2C.cpp:145
Base class for all sensors.
Definition: SensorBase.h:20
bool VerifySensor(uint8_t registerAddress, uint8_t count, const uint8_t *expected)
Verify that a device's registers contain expected values.
Definition: I2C.cpp:184
bool AddressOnly()
Attempt to address a device on the I2C bus.
Definition: I2C.cpp:62
void Broadcast(uint8_t registerAddress, uint8_t data)
Send a broadcast write to all devices on the I2C bus.
Definition: I2C.cpp:168
bool Read(uint8_t registerAddress, uint8_t count, uint8_t *data)
Execute a read transaction with the device.
Definition: I2C.cpp:117
I2C bus interface class.
Definition: I2C.h:19
bool WriteBulk(uint8_t *data, uint8_t count)
Execute a bulk write transaction with the device.
Definition: I2C.cpp:98