Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 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 | |
| 14 | /** |
| 15 | * I2C bus interface class. |
| 16 | * |
| 17 | * This class is intended to be used by sensor (and other I2C device) drivers. |
| 18 | * It probably should not be used directly. |
| 19 | * |
| 20 | */ |
| 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 |