blob: fe4952fdeb999596d15c094af357c73867b37c23 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
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
13using namespace hal;
14
15namespace hal {
16namespace init {
17void InitializeI2C() {}
18} // namespace init
19} // namespace hal
20
21extern "C" {
22void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
23 hal::init::CheckInit();
24 SimI2CData[port].initialized = true;
25}
26int32_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}
33int32_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}
38int32_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}
43void HAL_CloseI2C(HAL_I2CPort port) { SimI2CData[port].initialized = false; }
44} // extern "C"