Common IO - basic v1.0.0
Common IO - basic v1.0.0 Library
 
Loading...
Searching...
No Matches
iot_i2c.h
Go to the documentation of this file.
1/*
2 * Common IO - basic V1.0.0
3 * Copyright (C) 2020 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 )
67typedef enum
68{
72
76typedef enum
77{
83
87typedef struct IotI2CConfig
88{
89 uint32_t ulMasterTimeout;
90 uint32_t ulBusFreq;
92
96typedef enum
97{
109
114struct IotI2CDescriptor;
115
121typedef struct IotI2CDescriptor * IotI2CHandle_t;
122
133typedef void (* IotI2CCallback_t) ( IotI2COperationStatus_t xOpStatus,
134 void * pvUserContext );
135
152IotI2CHandle_t iot_i2c_open( int32_t lI2CInstance );
153
169void iot_i2c_set_callback( IotI2CHandle_t const pxI2CPeripheral,
170 IotI2CCallback_t xCallback,
171 void * pvUserContext );
172
270int32_t iot_i2c_read_sync( IotI2CHandle_t const pxI2CPeripheral,
271 uint8_t * const pucBuffer,
272 size_t xBytes );
273
307int32_t iot_i2c_write_sync( IotI2CHandle_t const pxI2CPeripheral,
308 uint8_t * const pucBuffer,
309 size_t xBytes );
310
347int32_t iot_i2c_read_async( IotI2CHandle_t const pxI2CPeripheral,
348 uint8_t * const pucBuffer,
349 size_t xBytes );
350
388int32_t iot_i2c_write_async( IotI2CHandle_t const pxI2CPeripheral,
389 uint8_t * const pucBuffer,
390 size_t xBytes );
391
441int32_t iot_i2c_ioctl( IotI2CHandle_t const pxI2CPeripheral,
442 IotI2CIoctlRequest_t xI2CRequest,
443 void * const pvBuffer );
444
445
457int32_t iot_i2c_close( IotI2CHandle_t const pxI2CPeripheral );
458
472int32_t iot_i2c_cancel( IotI2CHandle_t const pxI2CPeripheral );
473
477/* end of group iot_i2c */
478
479#endif /* ifndef _IOT_I2C_H_ */
int32_t iot_i2c_cancel(IotI2CHandle_t const pxI2CPeripheral)
This function is used to cancel the current operation in progress, if possible.
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.
void(* IotI2CCallback_t)(IotI2COperationStatus_t xOpStatus, void *pvUserContext)
The callback function for completion of I2C operation.
Definition: iot_i2c.h:133
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.
int32_t iot_i2c_close(IotI2CHandle_t const pxI2CPeripheral)
Stops the ongoing operation and de-initializes the I2C peripheral.
#define IOT_I2C_BUS_TIMEOUT
Definition: iot_i2c.h:59
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.
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
#define IOT_I2C_BUSY
Definition: iot_i2c.h:55
#define IOT_I2C_SUCCESS
Definition: iot_i2c.h:53
#define IOT_I2C_NACK
Definition: iot_i2c.h:58
IotI2COperationStatus_t
I2C operation status.
Definition: iot_i2c.h:77
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.
IotI2CBusStatus_t
I2C Bus status.
Definition: iot_i2c.h:68
int32_t iot_i2c_ioctl(IotI2CHandle_t const pxI2CPeripheral, IotI2CIoctlRequest_t xI2CRequest, void *const pvBuffer)
Configures the I2C master with user configuration.
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.
IotI2CIoctlRequest_t
Ioctl request types.
Definition: iot_i2c.h:97
IotI2CHandle_t iot_i2c_open(int32_t lI2CInstance)
Initiates and reserves an I2C instance as master.
@ eI2CDriverFailed
Definition: iot_i2c.h:79
@ eI2CCompleted
Definition: iot_i2c.h:78
@ eI2CMasterTimeout
Definition: iot_i2c.h:81
@ eI2CNackFromSlave
Definition: iot_i2c.h:80
@ eI2CBusIdle
Definition: iot_i2c.h:69
@ eI2cBusBusy
Definition: iot_i2c.h:70
@ eI2CGetTxNoOfbytes
Definition: iot_i2c.h:106
@ eI2CSetSlaveAddr
Definition: iot_i2c.h:101
@ eI2CSetMasterConfig
Definition: iot_i2c.h:102
@ eI2CGetBusState
Definition: iot_i2c.h:104
@ eI2CBusReset
Definition: iot_i2c.h:105
@ eI2CSendNoStopFlag
Definition: iot_i2c.h:98
@ eI2CGetMasterConfig
Definition: iot_i2c.h:103
@ eI2CGetRxNoOfbytes
Definition: iot_i2c.h:107
I2C bus configuration.
Definition: iot_i2c.h:88
uint32_t ulMasterTimeout
Definition: iot_i2c.h:89
uint32_t ulBusFreq
Definition: iot_i2c.h:90