FreeRTOS:
Common I/O
AWS IoT Common I/O library
|
Return to main page ↑ |
Data Structures | |
struct | IotI2CConfig_t |
I2C bus configuration. More... | |
Macros | |
#define | IOT_I2C_STANDARD_MODE_BPS ( 100000 ) |
#define | IOT_I2C_FAST_MODE_BPS ( 400000 ) |
#define | IOT_I2C_FAST_MODE_PLUS_BPS ( 1000000 ) |
#define | IOT_I2C_HIGH_SPEED_BPS ( 3400000 ) |
#define | IOT_I2C_SUCCESS ( 0 ) |
#define | IOT_I2C_INVALID_VALUE ( 1 ) |
#define | IOT_I2C_BUSY ( 2 ) |
#define | IOT_I2C_WRITE_FAILED ( 3 ) |
#define | IOT_I2C_READ_FAILED ( 4 ) |
#define | IOT_I2C_NACK ( 5 ) |
#define | IOT_I2C_BUS_TIMEOUT ( 6 ) |
#define | IOT_I2C_NOTHING_TO_CANCEL ( 7 ) |
#define | IOT_I2C_FUNCTION_NOT_SUPPORTED ( 8 ) |
#define | IOT_I2C_SLAVE_ADDRESS_NOT_SET ( 9 ) |
Typedefs | |
typedef struct IotI2CDescriptor * | IotI2CHandle_t |
IotI2CHandle_t is the handle type returned by calling iot_i2c_open(). This is initialized in open and returned to caller. The caller must pass this pointer to the rest of APIs. | |
typedef void(* | IotI2CCallback_t) (IotI2COperationStatus_t xOpStatus, void *pvUserContext) |
The callback function for completion of I2C operation. More... | |
Enumerations | |
enum | IotI2CBusStatus_t { eI2CBusIdle = 0, eI2cBusBusy = IOT_I2C_BUSY } |
I2C Bus status. More... | |
enum | IotI2COperationStatus_t { eI2CCompleted = IOT_I2C_SUCCESS, eI2CDriverFailed, eI2CNackFromSlave = IOT_I2C_NACK, eI2CMasterTimeout = IOT_I2C_BUS_TIMEOUT } |
I2C operation status. More... | |
enum | IotI2CIoctlRequest_t { eI2CSendNoStopFlag, eI2CSetSlaveAddr, eI2CSetMasterConfig, eI2CGetMasterConfig, eI2CGetBusState, eI2CBusReset, eI2CGetTxNoOfbytes, eI2CGetRxNoOfbytes } |
Ioctl request types. More... | |
Functions | |
IotI2CHandle_t | iot_i2c_open (int32_t lI2CInstance) |
Initiates and reserves an I2C instance as master. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
int32_t | iot_i2c_ioctl (IotI2CHandle_t const pxI2CPeripheral, IotI2CIoctlRequest_t xI2CRequest, void *const pvBuffer) |
Configures the I2C master with user configuration. More... | |
int32_t | iot_i2c_close (IotI2CHandle_t const pxI2CPeripheral) |
Stops the ongoing operation and de-initializes the I2C peripheral. More... | |
int32_t | iot_i2c_cancel (IotI2CHandle_t const pxI2CPeripheral) |
This function is used to cancel the current operation in progress, if possible. More... | |
#define IOT_I2C_STANDARD_MODE_BPS ( 100000 ) |
The speeds supported by I2C bus.Standard mode bits per second.
#define IOT_I2C_FAST_MODE_BPS ( 400000 ) |
Fast mode bits per second.
#define IOT_I2C_FAST_MODE_PLUS_BPS ( 1000000 ) |
Fast plus mode bits per second.
#define IOT_I2C_HIGH_SPEED_BPS ( 3400000 ) |
High speed mode bits per second.
#define IOT_I2C_SUCCESS ( 0 ) |
The return codes for the functions in I2C.I2C operation completed successfully.
#define IOT_I2C_INVALID_VALUE ( 1 ) |
At least one parameter is invalid.
#define IOT_I2C_BUSY ( 2 ) |
I2C bus is busy at current time.
#define IOT_I2C_WRITE_FAILED ( 3 ) |
I2C driver returns error when performing write operation.
#define IOT_I2C_READ_FAILED ( 4 ) |
I2C driver returns error when performing read operation.
#define IOT_I2C_NACK ( 5 ) |
Unexpected NACK is caught.
#define IOT_I2C_BUS_TIMEOUT ( 6 ) |
I2C operation not completed within specified timeout.
#define IOT_I2C_NOTHING_TO_CANCEL ( 7 ) |
No ongoing transaction when cancel operation is performed.
#define IOT_I2C_FUNCTION_NOT_SUPPORTED ( 8 ) |
I2C operation is not supported.
#define IOT_I2C_SLAVE_ADDRESS_NOT_SET ( 9 ) |
Slave address is not set before calling I2C read or write operation.
typedef void(* IotI2CCallback_t) (IotI2COperationStatus_t xOpStatus, void *pvUserContext) |
The callback function for completion of I2C operation.
[out] | xOpStatus | I2C asynchronous operation status. |
[in] | pvUserContext | User Context passed when setting the callback. This is not used or modified by the driver. The context is provided by the caller when setting the callback, and is passed back to the caller in the callback. |
enum IotI2CBusStatus_t |
enum IotI2CIoctlRequest_t |
Ioctl request types.
Enumerator | |
---|---|
eI2CSendNoStopFlag | ! Set flag to not send stop after transaction ! Default is always stop for every transaction ! Flag will auto reset to stop after one transaction if you set no stop |
eI2CSetSlaveAddr | ! This can be either 7-bit address or 10-bit address. All the operations use this slave address after it is set. |
eI2CSetMasterConfig | ! Sets the I2C bus frequency and timeout using the struct IotI2CConfig_t, default speed is Standard mode. |
eI2CGetMasterConfig | ! Gets the I2C bus frequency and timeout set for the I2C master. |
eI2CGetBusState | ! Get the current I2C bus status. Returns eI2CBusIdle or eI2CBusy |
eI2CBusReset | ! Master resets the bus. |
eI2CGetTxNoOfbytes | ! Get the number of bytes sent in write operation. |
eI2CGetRxNoOfbytes | ! Get the number of bytes received in read operation. |
IotI2CHandle_t iot_i2c_open | ( | int32_t | lI2CInstance | ) |
Initiates and reserves an I2C instance as master.
One instance can communicate with one or more slave devices. Slave addresses need to be changed between actions to different slave devices.
[in] | lI2CInstance | The instance of I2C to initialize. This is between 0 and the number of I2C instances on board - 1. |
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.
The callback is guaranteed to be invoked when the current asynchronous operation completes, either successful or failed. This simply provides a notification mechanism to user's application. It has no impact if the callback is not set.
[in] | pxI2CPeripheral | The I2C peripheral handle returned in the open() call. |
[in] | xCallback | The callback function to be called on completion of transaction. |
[in] | pvUserContext | The user context to be passed back when callback is called. |
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.
This function attempts to read certain number of bytes from slave device to a pre-allocated buffer, in synchronous way. Partial read might happen, e.g. no more data is available. And the number of bytes that have been actually read can be obtained by calling iot_i2c_ioctl.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |
[out] | pucBuffer | The receive buffer to read the data into. It must stay allocated before this function returns. |
[in] | xBytes | The number of bytes to read. |
Example
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.
This function attempts to write certain number of bytes from a pre-allocated buffer to a slave device, in synchronous way. Partial write might happen, e.g. slave device unable to receive more data. And the number of bytes that have been actually written can be obtained by calling iot_i2c_ioctl.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |
[in] | pucBuffer | The transmit buffer containing the data to be written. It must stay allocated before this function returns. |
[in] | xBytes | The number of bytes to write. |
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.
This function attempts to read certain number of bytes from a pre-allocated buffer, in asynchronous way. It returns immediately when the operation is started and the status can be check by calling iot_i2c_ioctl. Once the operation completes, successful or not, the user callback will be invoked.
Partial read might happen, e.g. slave device unable to receive more data. And the number of bytes that have been actually read can be obtained by calling iot_i2c_ioctl.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |
[out] | pucBuffer | The receive buffer to read the data into |
[in] | xBytes | The number of bytes to read. |
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.
This function attempts to write certain number of bytes from a pre-allocated buffer to a slave device, in asynchronous way. It returns immediately when the operation is started and the status can be check by calling iot_i2c_ioctl. Once the operation completes, successful or not, the user callback will be invoked.
Partial write might happen, e.g. slave device unable to receive more data. And the number of bytes that have been actually written can be obtained by calling iot_i2c_ioctl.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |
[in] | pucBuffer | The transmit buffer containing the data to be written. It must stay allocated before this function returns. |
[in] | xBytes | The number of bytes to write. |
int32_t iot_i2c_ioctl | ( | IotI2CHandle_t const | pxI2CPeripheral, |
IotI2CIoctlRequest_t | xI2CRequest, | ||
void *const | pvBuffer | ||
) |
Configures the I2C master with user configuration.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |
[in] | xI2CRequest | Should be one of I2C_Ioctl_Request_t. |
[in,out] | pvBuffer | The configuration values for the IOCTL request. |
int32_t iot_i2c_close | ( | IotI2CHandle_t const | pxI2CPeripheral | ) |
Stops the ongoing operation and de-initializes the I2C peripheral.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |
int32_t iot_i2c_cancel | ( | IotI2CHandle_t const | pxI2CPeripheral | ) |
This function is used to cancel the current operation in progress, if possible.
[in] | pxI2CPeripheral | The I2C handle returned in open() call. |