1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef _I2C_H_
18 #define _I2C_H_
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include <stddef.h>
27
28 typedef void (*I2cCallbackF)(void *cookie, size_t tx, size_t rx, int err);
29
30 int i2cMasterRequest(uint32_t busId, uint32_t speedInHz);
31 int i2cMasterRelease(uint32_t busId);
32 int i2cMasterTxRx(uint32_t busId, uint32_t addr, const void *txBuf, size_t txSize,
33 void *rxBuf, size_t rxSize, I2cCallbackF callback, void *cookie);
i2cMasterTx(uint32_t busId,uint32_t addr,const void * txBuf,size_t txSize,I2cCallbackF callback,void * cookie)34 static inline int i2cMasterTx(uint32_t busId, uint32_t addr,
35 const void *txBuf, size_t txSize, I2cCallbackF callback, void *cookie)
36 {
37 return i2cMasterTxRx(busId, addr, txBuf, txSize, NULL, 0, callback, cookie);}
i2cMasterRx(uint32_t busId,uint32_t addr,void * rxBuf,size_t rxSize,I2cCallbackF callback,void * cookie)38 static inline int i2cMasterRx(uint32_t busId, uint32_t addr,
39 void *rxBuf, size_t rxSize, I2cCallbackF callback, void *cookie)
40 {
41 return i2cMasterTxRx(busId, addr, NULL, 0, rxBuf, rxSize, callback, cookie);
42 }
43
44 int i2cSlaveRequest(uint32_t busId, uint32_t addr);
45 int i2cSlaveRelease(uint32_t busId);
46
47 void i2cSlaveEnableRx(uint32_t busId, void *rxBuf, size_t rxSize,
48 I2cCallbackF callback, void *cookie);
49 int i2cSlaveTxPreamble(uint32_t busId, uint8_t byte,
50 I2cCallbackF callback, void *cookie);
51 int i2cSlaveTxPacket(uint32_t busId, const void *txBuf, size_t txSize,
52 I2cCallbackF callback, void *cookie);
53
54 #ifdef __cplusplus
55 }
56 #endif
57
58 #endif /* _I2C_H_ */
59