WPILibC++  unspecified
I2C.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 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 "ErrorBase.h"
13 
14 enum HAL_I2CPort : int32_t;
15 
16 namespace frc {
17 
24 class I2C : public ErrorBase {
25  public:
26  enum Port { kOnboard = 0, kMXP };
27 
28  I2C(Port port, int deviceAddress);
29  ~I2C() override;
30 
31  I2C(const I2C&) = delete;
32  I2C& operator=(const I2C&) = delete;
33 
34  bool Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
35  int receiveSize);
36  bool AddressOnly();
37  bool Write(int registerAddress, uint8_t data);
38  bool WriteBulk(uint8_t* data, int count);
39  bool Read(int registerAddress, int count, uint8_t* data);
40  bool ReadOnly(int count, uint8_t* buffer);
41  bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
42 
43  private:
44  HAL_I2CPort m_port;
45  int m_deviceAddress;
46 };
47 
48 } // namespace frc
Definition: RobotController.cpp:14
I2C(Port port, int deviceAddress)
Constructor.
Definition: I2C.cpp:23
~I2C() override
Destructor.
Definition: I2C.cpp:35
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)
Verify that a device&#39;s registers contain expected values.
Definition: I2C.cpp:168
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
bool AddressOnly()
Attempt to address a device on the I2C bus.
Definition: I2C.cpp:66
I2C bus interface class.
Definition: I2C.h:24
Base class for most objects.
Definition: ErrorBase.h:74