TI-RTOS Drivers  tidrivers_full_2_20_00_08
I2C.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
124 #ifndef ti_drivers_I2C__include
125 #define ti_drivers_I2C__include
126 
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
130 
131 #include <stdint.h>
132 #include <stdbool.h>
133 #include <stddef.h>
134 
152 #define I2C_CMD_RESERVED 32
153 
166 #define I2C_STATUS_RESERVED -32
167 
181 #define I2C_STATUS_SUCCESS 0
182 
189 #define I2C_STATUS_ERROR -1
190 
198 #define I2C_STATUS_UNDEFINEDCMD -2
199 
209 /* Add I2C_CMD_<commands> here */
210 
218 typedef struct I2C_Config *I2C_Handle;
219 
230 typedef struct I2C_Transaction {
231  void *writeBuf;
232  size_t writeCount;
234  void *readBuf;
235  size_t readCount;
237  unsigned char slaveAddress;
239  void *arg;
240  void *nextPtr;
242 
250 typedef enum I2C_TransferMode {
254 
268 typedef void (*I2C_CallbackFxn)(I2C_Handle, I2C_Transaction *, bool);
269 
276 typedef enum I2C_BitRate {
279 } I2C_BitRate;
280 
301 typedef struct I2C_Params {
305  uintptr_t custom;
307 } I2C_Params;
308 
313 typedef void (*I2C_CancelFxn) (I2C_Handle handle);
314 
319 typedef void (*I2C_CloseFxn) (I2C_Handle handle);
320 
325 typedef int (*I2C_ControlFxn) (I2C_Handle handle,
326  unsigned int cmd,
327  void *arg);
328 
333 typedef void (*I2C_InitFxn) (I2C_Handle handle);
334 
339 typedef I2C_Handle (*I2C_OpenFxn) (I2C_Handle handle,
340  I2C_Params *params);
341 
346 typedef bool (*I2C_TransferFxn) (I2C_Handle handle,
347  I2C_Transaction *transaction);
348 
354 typedef struct I2C_FxnTable {
357 
360 
363 
366 
369 
372 } I2C_FxnTable;
373 
385 typedef struct I2C_Config {
388 
390  void *object;
391 
393  void const *hwAttrs;
394 } I2C_Config;
395 
396 
416 extern void I2C_cancel(I2C_Handle handle);
417 
427 extern void I2C_close(I2C_Handle handle);
428 
466 extern int I2C_control(I2C_Handle handle, unsigned int cmd, void *arg);
467 
476 extern void I2C_init(void);
477 
498 extern I2C_Handle I2C_open(unsigned int index, I2C_Params *params);
499 
511 extern void I2C_Params_init(I2C_Params *params);
512 
556 extern bool I2C_transfer(I2C_Handle handle, I2C_Transaction *transaction);
557 
558 #ifdef __cplusplus
559 }
560 #endif
561 
562 #endif /* ti_drivers_I2C__include */
void * writeBuf
Definition: I2C.h:231
void * arg
Definition: I2C.h:239
struct I2C_Config I2C_Config
I2C global configuration.
I2C_TransferMode transferMode
Definition: I2C.h:302
void * object
Definition: I2C.h:390
void * readBuf
Definition: I2C.h:234
void * nextPtr
Definition: I2C.h:240
I2C global configuration.
Definition: I2C.h:385
void I2C_Params_init(I2C_Params *params)
Initialize an I2C_Params struct to its defaults.
struct I2C_Config * I2C_Handle
A handle that is returned from a I2C_open() call.
Definition: I2C.h:218
void(* I2C_CloseFxn)(I2C_Handle handle)
A function pointer to a driver-specific implementation of I2C_close().
Definition: I2C.h:319
int I2C_control(I2C_Handle handle, unsigned int cmd, void *arg)
Perform implementation specific features on a given I2C_Handle.
void(* I2C_CallbackFxn)(I2C_Handle, I2C_Transaction *, bool)
I2C callback function.
Definition: I2C.h:268
void(* I2C_InitFxn)(I2C_Handle handle)
A function pointer to a driver-specific implementation of I2C_init().
Definition: I2C.h:333
I2C_BitRate
I2C bitRate.
Definition: I2C.h:276
void(* I2C_CancelFxn)(I2C_Handle handle)
A function pointer to a driver-specific implementation of I2C_cancel().
Definition: I2C.h:313
Definition: I2C.h:251
I2C_CancelFxn cancelFxn
Definition: I2C.h:356
I2C_TransferMode
I2C transfer mode.
Definition: I2C.h:250
I2C_CallbackFxn transferCallbackFxn
Definition: I2C.h:303
I2C_CloseFxn closeFxn
Definition: I2C.h:359
I2C_InitFxn initFxn
Definition: I2C.h:365
bool(* I2C_TransferFxn)(I2C_Handle handle, I2C_Transaction *transaction)
A function pointer to a driver-specific implementation of I2C_transfer().
Definition: I2C.h:346
The definition of an I2C function table that contains the required set of functions to control a spec...
Definition: I2C.h:354
uintptr_t custom
Definition: I2C.h:305
I2C_FxnTable const * fxnTablePtr
Definition: I2C.h:387
I2C_OpenFxn openFxn
Definition: I2C.h:368
Definition: I2C.h:278
struct I2C_FxnTable I2C_FxnTable
The definition of an I2C function table that contains the required set of functions to control a spec...
I2C_TransferFxn transferFxn
Definition: I2C.h:371
I2C_BitRate bitRate
Definition: I2C.h:304
void I2C_close(I2C_Handle handle)
Close an I2C peripheral specified by an I2C handle.
I2C Parameters.
Definition: I2C.h:301
int(* I2C_ControlFxn)(I2C_Handle handle, unsigned int cmd, void *arg)
A function pointer to a driver-specific implementation of I2C_control().
Definition: I2C.h:325
I2C_ControlFxn controlFxn
Definition: I2C.h:362
struct I2C_Transaction I2C_Transaction
I2C transaction.
I2C_Handle I2C_open(unsigned int index, I2C_Params *params)
Initialize a given I2C peripheral specified by the particular index value. The parameter specifies wh...
void I2C_cancel(I2C_Handle handle)
Cancel all I2C transfers.
struct I2C_Params I2C_Params
I2C Parameters.
Definition: I2C.h:252
void I2C_init(void)
Initializes the I2C module.
unsigned char slaveAddress
Definition: I2C.h:237
void const * hwAttrs
Definition: I2C.h:393
I2C transaction.
Definition: I2C.h:230
bool I2C_transfer(I2C_Handle handle, I2C_Transaction *transaction)
Perform an I2C transaction with an I2C slave peripheral.
size_t writeCount
Definition: I2C.h:232
I2C_Handle(* I2C_OpenFxn)(I2C_Handle handle, I2C_Params *params)
A function pointer to a driver-specific implementation of I2C_open().
Definition: I2C.h:339
Definition: I2C.h:277
size_t readCount
Definition: I2C.h:235
Copyright 2016, Texas Instruments Incorporated