jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #ifndef I2C_H
|
| 8 | #define I2C_H
|
| 9 |
|
| 10 | #include "SensorBase.h"
|
| 11 |
|
| 12 | class DigitalModule;
|
| 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 | * It is constructed by calling DigitalModule::GetI2C() on a DigitalModule object.
|
| 21 | */
|
| 22 | class I2C : SensorBase
|
| 23 | {
|
| 24 | friend class DigitalModule;
|
| 25 | public:
|
| 26 | virtual ~I2C();
|
| 27 | bool Transaction(UINT8 *dataToSend, UINT8 sendSize, UINT8 *dataReceived, UINT8 receiveSize);
|
| 28 | bool AddressOnly();
|
| 29 | bool Write(UINT8 registerAddress, UINT8 data);
|
| 30 | bool Read(UINT8 registerAddress, UINT8 count, UINT8 *data);
|
| 31 | void Broadcast(UINT8 registerAddress, UINT8 data);
|
| 32 | void SetCompatibilityMode(bool enable);
|
| 33 |
|
| 34 | bool VerifySensor(UINT8 registerAddress, UINT8 count, const UINT8 *expected);
|
| 35 | private:
|
| 36 | static SEM_ID m_semaphore;
|
| 37 | static UINT32 m_objCount;
|
| 38 |
|
| 39 | I2C(DigitalModule *module, UINT8 deviceAddress);
|
| 40 |
|
| 41 | DigitalModule *m_module;
|
| 42 | UINT8 m_deviceAddress;
|
| 43 | bool m_compatibilityMode;
|
| 44 | };
|
| 45 |
|
| 46 | #endif
|
| 47 |
|