WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
I2C.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 
12 namespace frc {
13 
21 class I2C : SensorBase {
22  public:
23  enum Port { kOnboard, kMXP };
24 
25  I2C(Port port, int deviceAddress);
26  virtual ~I2C();
27 
28  I2C(const I2C&) = delete;
29  I2C& operator=(const I2C&) = delete;
30 
31  bool Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
32  int receiveSize);
33  bool AddressOnly();
34  bool Write(int registerAddress, uint8_t data);
35  bool WriteBulk(uint8_t* data, int count);
36  bool Read(int registerAddress, int count, uint8_t* data);
37  bool ReadOnly(int count, uint8_t* buffer);
38  // void Broadcast(int registerAddress, uint8_t data);
39  bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
40 
41  private:
42  Port m_port;
43  int m_deviceAddress;
44 };
45 
46 } // namespace frc
I2C(Port port, int deviceAddress)
Constructor.
Definition: I2C.cpp:22
Base class for all sensors.
Definition: SensorBase.h:22
bool Transaction(uint8_t *dataToSend, int sendSize, uint8_t *dataReceived, int receiveSize)
Generic transaction.
Definition: I2C.cpp:48
bool ReadOnly(int count, uint8_t *buffer)
Execute a read only transaction with the device.
Definition: I2C.cpp:140
bool Read(int registerAddress, int count, uint8_t *data)
Execute a read transaction with the device.
Definition: I2C.cpp:116
bool VerifySensor(int registerAddress, int count, const uint8_t *expected)
Send a broadcast write to all devices on the I2C bus.
Definition: I2C.cpp:178
bool WriteBulk(uint8_t *data, int count)
Execute a bulk write transaction with the device.
Definition: I2C.cpp:97
bool Write(int registerAddress, uint8_t data)
Execute a write transaction with the device.
Definition: I2C.cpp:78
virtual ~I2C()
Destructor.
Definition: I2C.cpp:34
bool AddressOnly()
Attempt to address a device on the I2C bus.
Definition: I2C.cpp:65
I2C bus interface class.
Definition: I2C.h:21