WPILibC++  unspecified
I2C.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 FIRST. 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 <stdint.h>
11 
12 #include "SensorBase.h"
13 
14 enum HAL_I2CPort : int32_t;
15 
16 namespace frc {
17 
25 class I2C : SensorBase {
26  public:
27  enum Port { kOnboard = 0, kMXP };
28 
29  I2C(Port port, int deviceAddress);
30  virtual ~I2C();
31 
32  I2C(const I2C&) = delete;
33  I2C& operator=(const I2C&) = delete;
34 
35  bool Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
36  int receiveSize);
37  bool AddressOnly();
38  bool Write(int registerAddress, uint8_t data);
39  bool WriteBulk(uint8_t* data, int count);
40  bool Read(int registerAddress, int count, uint8_t* data);
41  bool ReadOnly(int count, uint8_t* buffer);
42  // void Broadcast(int registerAddress, uint8_t data);
43  bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
44 
45  private:
46  HAL_I2CPort m_port;
47  int m_deviceAddress;
48 };
49 
50 } // namespace frc
Definition: Timer.cpp:18
I2C(Port port, int deviceAddress)
Constructor.
Definition: I2C.cpp:23
Base class for all sensors.
Definition: SensorBase.h:20
bool Transaction(uint8_t *dataToSend, int sendSize, uint8_t *dataReceived, int receiveSize)
Generic transaction.
Definition: I2C.cpp:49
bool ReadOnly(int count, uint8_t *buffer)
Execute a read only transaction with the device.
Definition: I2C.cpp:141
bool Read(int registerAddress, int count, uint8_t *data)
Execute a read transaction with the device.
Definition: I2C.cpp:117
bool VerifySensor(int registerAddress, int count, const uint8_t *expected)
Send a broadcast write to all devices on the I2C bus.
Definition: I2C.cpp:179
bool WriteBulk(uint8_t *data, int count)
Execute a bulk write transaction with the device.
Definition: I2C.cpp:98
bool Write(int registerAddress, uint8_t data)
Execute a write transaction with the device.
Definition: I2C.cpp:79
virtual ~I2C()
Destructor.
Definition: I2C.cpp:35
bool AddressOnly()
Attempt to address a device on the I2C bus.
Definition: I2C.cpp:66
I2C bus interface class.
Definition: I2C.h:25