2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-06-25 09:05:49 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "SensorBase.h"
|
|
|
|
|
|
2017-05-09 12:12:46 -07:00
|
|
|
enum HAL_I2CPort : int32_t;
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* I2C bus interface class.
|
2014-07-21 16:32:36 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* This class is intended to be used by sensor (and other I2C device) drivers.
|
|
|
|
|
* It probably should not be used directly.
|
2014-07-21 16:32:36 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class I2C : SensorBase {
|
|
|
|
|
public:
|
2017-05-09 12:12:46 -07:00
|
|
|
enum Port { kOnboard = 0, kMXP };
|
2014-06-18 15:38:02 -04:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
I2C(Port port, int deviceAddress);
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual ~I2C();
|
2014-06-18 15:38:02 -04:00
|
|
|
|
2015-07-21 01:23:34 -07:00
|
|
|
I2C(const I2C&) = delete;
|
|
|
|
|
I2C& operator=(const I2C&) = delete;
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
bool Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
|
|
|
|
|
int receiveSize);
|
2015-06-25 15:07:55 -04:00
|
|
|
bool AddressOnly();
|
2016-09-06 00:01:45 -07:00
|
|
|
bool Write(int registerAddress, uint8_t data);
|
|
|
|
|
bool WriteBulk(uint8_t* data, int count);
|
|
|
|
|
bool Read(int registerAddress, int count, uint8_t* data);
|
|
|
|
|
bool ReadOnly(int count, uint8_t* buffer);
|
2016-12-23 11:20:13 -08:00
|
|
|
// void Broadcast(int registerAddress, uint8_t data);
|
2016-09-06 00:01:45 -07:00
|
|
|
bool VerifySensor(int registerAddress, int count, const uint8_t* expected);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2017-05-09 12:12:46 -07:00
|
|
|
HAL_I2CPort m_port;
|
2016-09-06 00:01:45 -07:00
|
|
|
int m_deviceAddress;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|