Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2017-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 | #include "hal/I2C.h" |
| 9 | |
| 10 | #include "HALInitializer.h" |
| 11 | #include "mockdata/I2CDataInternal.h" |
| 12 | |
| 13 | using namespace hal; |
| 14 | |
| 15 | namespace hal { |
| 16 | namespace init { |
| 17 | void InitializeI2C() {} |
| 18 | } // namespace init |
| 19 | } // namespace hal |
| 20 | |
| 21 | extern "C" { |
| 22 | void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) { |
| 23 | hal::init::CheckInit(); |
| 24 | SimI2CData[port].initialized = true; |
| 25 | } |
| 26 | int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress, |
| 27 | const uint8_t* dataToSend, int32_t sendSize, |
| 28 | uint8_t* dataReceived, int32_t receiveSize) { |
| 29 | SimI2CData[port].Write(deviceAddress, dataToSend, sendSize); |
| 30 | SimI2CData[port].Read(deviceAddress, dataReceived, receiveSize); |
| 31 | return 0; |
| 32 | } |
| 33 | int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress, |
| 34 | const uint8_t* dataToSend, int32_t sendSize) { |
| 35 | SimI2CData[port].Write(deviceAddress, dataToSend, sendSize); |
| 36 | return 0; |
| 37 | } |
| 38 | int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer, |
| 39 | int32_t count) { |
| 40 | SimI2CData[port].Read(deviceAddress, buffer, count); |
| 41 | return 0; |
| 42 | } |
| 43 | void HAL_CloseI2C(HAL_I2CPort port) { SimI2CData[port].initialized = false; } |
| 44 | } // extern "C" |