WPILibC++  2018.4.1-20180729181730-1145-g898076f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
I2C.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-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 #pragma once
9 
10 #include <stdint.h>
11 
12 #include "hal/Types.h"
13 
20 // clang-format off
21 HAL_ENUM(HAL_I2CPort) { HAL_I2C_kOnboard = 0, HAL_I2C_kMXP };
22 // clang-format on
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
36 void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status);
37 
51 int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
52  const uint8_t* dataToSend, int32_t sendSize,
53  uint8_t* dataReceived, int32_t receiveSize);
54 
67 int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
68  const uint8_t* dataToSend, int32_t sendSize);
69 
84 int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
85  int32_t count);
86 
92 void HAL_CloseI2C(HAL_I2CPort port);
93 #ifdef __cplusplus
94 } // extern "C"
95 #endif
96 
int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress, const uint8_t *dataToSend, int32_t sendSize, uint8_t *dataReceived, int32_t receiveSize)
Generic I2C read/write transaction.
void HAL_CloseI2C(HAL_I2CPort port)
Closes an I2C port.
int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress, const uint8_t *dataToSend, int32_t sendSize)
Executes a write transaction with the device.
void HAL_InitializeI2C(HAL_I2CPort port, int32_t *status)
Initializes the I2C port.
int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t *buffer, int32_t count)
Executes a read transaction with the device.