FreeRTOS: Common I/O
AWS IoT Common I/O library
Return to main page ↑
iot_i2c.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS Common IO V1.0.0
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
30 #ifndef _IOT_I2C_H_
31 #define _IOT_I2C_H_
32 
33 /* Standard includes. */
34 #include <stdint.h>
35 #include <stddef.h>
36 
45 #define IOT_I2C_STANDARD_MODE_BPS ( 100000 )
46 #define IOT_I2C_FAST_MODE_BPS ( 400000 )
47 #define IOT_I2C_FAST_MODE_PLUS_BPS ( 1000000 )
48 #define IOT_I2C_HIGH_SPEED_BPS ( 3400000 )
53 #define IOT_I2C_SUCCESS ( 0 )
54 #define IOT_I2C_INVALID_VALUE ( 1 )
55 #define IOT_I2C_BUSY ( 2 )
56 #define IOT_I2C_WRITE_FAILED ( 3 )
57 #define IOT_I2C_READ_FAILED ( 4 )
58 #define IOT_I2C_NACK ( 5 )
59 #define IOT_I2C_BUS_TIMEOUT ( 6 )
60 #define IOT_I2C_NOTHING_TO_CANCEL ( 7 )
61 #define IOT_I2C_FUNCTION_NOT_SUPPORTED ( 8 )
62 #define IOT_I2C_SLAVE_ADDRESS_NOT_SET ( 9 )
67 typedef enum
68 {
72 
76 typedef enum
77 {
83 
87 typedef struct IotI2CConfig
88 {
89  uint32_t ulMasterTimeout;
90  uint32_t ulBusFreq;
92 
96 typedef enum
97 {
109 
114 struct IotI2CDescriptor;
115 
121 typedef struct IotI2CDescriptor * IotI2CHandle_t;
122 
133 typedef void (* IotI2CCallback_t) ( IotI2COperationStatus_t xOpStatus,
134  void * pvUserContext );
135 
152 IotI2CHandle_t iot_i2c_open( int32_t lI2CInstance );
153 
169 void iot_i2c_set_callback( IotI2CHandle_t const pxI2CPeripheral,
170  IotI2CCallback_t xCallback,
171  void * pvUserContext );
172 
270 int32_t iot_i2c_read_sync( IotI2CHandle_t const pxI2CPeripheral,
271  uint8_t * const pucBuffer,
272  size_t xBytes );
273 
307 int32_t iot_i2c_write_sync( IotI2CHandle_t const pxI2CPeripheral,
308  uint8_t * const pucBuffer,
309  size_t xBytes );
310 
347 int32_t iot_i2c_read_async( IotI2CHandle_t const pxI2CPeripheral,
348  uint8_t * const pucBuffer,
349  size_t xBytes );
350 
388 int32_t iot_i2c_write_async( IotI2CHandle_t const pxI2CPeripheral,
389  uint8_t * const pucBuffer,
390  size_t xBytes );
391 
441 int32_t iot_i2c_ioctl( IotI2CHandle_t const pxI2CPeripheral,
442  IotI2CIoctlRequest_t xI2CRequest,
443  void * const pvBuffer );
444 
445 
457 int32_t iot_i2c_close( IotI2CHandle_t const pxI2CPeripheral );
458 
472 int32_t iot_i2c_cancel( IotI2CHandle_t const pxI2CPeripheral );
473 
477 /* end of group iot_i2c */
478 
479 #endif /* ifndef _IOT_I2C_H_ */
IotI2CHandle_t iot_i2c_open(int32_t lI2CInstance)
Initiates and reserves an I2C instance as master.
Definition: iot_i2c.h:104
int32_t iot_i2c_read_sync(IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pucBuffer, size_t xBytes)
Starts the I2C master read operation in synchronous mode.
Definition: iot_i2c.h:81
#define IOT_I2C_BUSY
Definition: iot_i2c.h:55
Definition: iot_i2c.h:106
IotI2COperationStatus_t
I2C operation status.
Definition: iot_i2c.h:76
int32_t iot_i2c_write_sync(IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pucBuffer, size_t xBytes)
Starts the I2C master write operation in synchronous mode.
Definition: iot_i2c.h:101
Definition: iot_i2c.h:69
Definition: iot_i2c.h:103
struct IotI2CDescriptor * IotI2CHandle_t
IotI2CHandle_t is the handle type returned by calling iot_i2c_open(). This is initialized in open and...
Definition: iot_i2c.h:121
int32_t iot_i2c_close(IotI2CHandle_t const pxI2CPeripheral)
Stops the ongoing operation and de-initializes the I2C peripheral.
int32_t iot_i2c_read_async(IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pucBuffer, size_t xBytes)
Starts the I2C master read operation in asynchronous mode.
Definition: iot_i2c.h:78
uint32_t ulBusFreq
Definition: iot_i2c.h:90
void iot_i2c_set_callback(IotI2CHandle_t const pxI2CPeripheral, IotI2CCallback_t xCallback, void *pvUserContext)
Sets the application callback to be called on completion of an operation.
Definition: iot_i2c.h:79
Definition: iot_i2c.h:105
Definition: iot_i2c.h:98
Definition: iot_i2c.h:102
int32_t iot_i2c_write_async(IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pucBuffer, size_t xBytes)
Starts the I2C master write operation in asynchronous mode.
Definition: iot_i2c.h:70
I2C bus configuration.
Definition: iot_i2c.h:87
int32_t iot_i2c_ioctl(IotI2CHandle_t const pxI2CPeripheral, IotI2CIoctlRequest_t xI2CRequest, void *const pvBuffer)
Configures the I2C master with user configuration.
void(* IotI2CCallback_t)(IotI2COperationStatus_t xOpStatus, void *pvUserContext)
The callback function for completion of I2C operation.
Definition: iot_i2c.h:133
#define IOT_I2C_BUS_TIMEOUT
Definition: iot_i2c.h:59
Definition: iot_i2c.h:80
uint32_t ulMasterTimeout
Definition: iot_i2c.h:89
int32_t iot_i2c_cancel(IotI2CHandle_t const pxI2CPeripheral)
This function is used to cancel the current operation in progress, if possible.
IotI2CBusStatus_t
I2C Bus status.
Definition: iot_i2c.h:67
Definition: iot_i2c.h:107
#define IOT_I2C_NACK
Definition: iot_i2c.h:58
#define IOT_I2C_SUCCESS
Definition: iot_i2c.h:53
IotI2CIoctlRequest_t
Ioctl request types.
Definition: iot_i2c.h:96