WPILibC++  2019.4.1-3-g655763a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <hal/I2CTypes.h>
13 
14 #include "frc/ErrorBase.h"
15 
16 namespace frc {
17 
24 class I2C : public ErrorBase {
25  public:
26  enum Port { kOnboard = 0, kMXP };
27 
34  I2C(Port port, int deviceAddress);
35 
36  ~I2C() override;
37 
38  I2C(I2C&& rhs);
39  I2C& operator=(I2C&& rhs);
40 
53  bool Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
54  int receiveSize);
55 
64  bool AddressOnly();
65 
77  bool Write(int registerAddress, uint8_t data);
78 
89  bool WriteBulk(uint8_t* data, int count);
90 
105  bool Read(int registerAddress, int count, uint8_t* data);
106 
118  bool ReadOnly(int count, uint8_t* buffer);
119 
135  bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
136 
137  private:
138  HAL_I2CPort m_port = HAL_I2C_kInvalid;
139  int m_deviceAddress;
140 };
141 
142 } // namespace frc
I2C(Port port, int deviceAddress)
Constructor.
bool Read(int registerAddress, int count, uint8_t *data)
Execute a read transaction with the device.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
bool AddressOnly()
Attempt to address a device on the I2C bus.
bool VerifySensor(int registerAddress, int count, const uint8_t *expected)
Verify that a device's registers contain expected values.
bool WriteBulk(uint8_t *data, int count)
Execute a bulk write transaction with the device.
I2C bus interface class.
Definition: I2C.h:24
bool Write(int registerAddress, uint8_t data)
Execute a write transaction with the device.
bool Transaction(uint8_t *dataToSend, int sendSize, uint8_t *dataReceived, int receiveSize)
Generic transaction.
Base class for most objects.
Definition: ErrorBase.h:74
bool ReadOnly(int count, uint8_t *buffer)
Execute a read only transaction with the device.