I2CTarget driver interface.
To use the I2CTarget driver, ensure that the correct driver library for your device is linked in and include this header file as follows:
The I2CTarget driver operates the I2C peripheral as a target on an I2C bus. The I2CTarget driver is event driven. When an I2CTarget_Event occurs, the I2CTarget driver will call a user-specified callback function (from HWI context). It is the user-specified callback's responsibility to process the I2CTarget_Event events, and to manipulate and interperet the data.
This documentation provides a basic usage summary and a set of examples in the form of commented code fragments. Detailed descriptions of the APIs are provided in subsequent sections.
Opening a I2CTarget requires four steps:
Only one I2CTarget index can be used at a time; calling I2CTarget_open() a second time with the same index previosly passed to I2CTarget_open() will result in an error. You can, though, re-use the index if the instance is closed via I2CTarget_close(). In the previous example code, CONFIG_I2CTARGET_0 is passed to I2CTarget_open(). This macro is defined in the example's ti_drivers_config.h file.
The I2CTarget driver will start operation when calling I2CTarget_start(). It is the application's responsibility to process all incoming I2CTarget_Event events in the I2CTarget_Params::eventCallbackFxn and implement the necessary state machine for the I2C protocol used.
The I2CTarget driver operation is stopped by calling I2CTarget_stop().
This example shows a simplified example on how to transmit and receive data.
Refer to the Driver's Configuration section for driver configuration information.
Go to the source code of this file.
Data Structures | |
struct | I2CTarget_Params |
I2CTarget Parameters. More... | |
struct | I2CTarget_Config_ |
I2CTarget Global configuration. More... | |
Macros | |
#define | I2CTarget_STATUS_SUCCESS (0) |
Successful status code returned by application event callback function. More... | |
#define | I2CTarget_STATUS_ERROR (-1) |
Generic error status code returned by application event callback function. More... | |
Typedefs | |
typedef struct I2CTarget_Config_ * | I2CTarget_Handle |
A handle that is returned from a I2CTarget_open() call. More... | |
typedef int_fast16_t(* | I2CTarget_EventCallbackFxn) (I2CTarget_Handle handle, I2CTarget_Event event, uint8_t *val) |
I2CTarget event callback function. More... | |
typedef struct I2CTarget_Config_ | I2CTarget_Config |
I2CTarget Global configuration. More... | |
Enumerations | |
enum | I2CTarget_Event { I2CTarget_Event_WRITE_REQUESTED, I2CTarget_Event_READ_REQUESTED, I2CTarget_Event_WRITE_RECEIVED, I2CTarget_Event_READ_PROCESSED, I2CTarget_Event_STOP } |
I2CTarget events that the application's I2CTarget_EventCallbackFxn must support. More... | |
Functions | |
void | I2CTarget_init (void) |
Function to initializes the I2CTarget module. More... | |
void | I2CTarget_Params_init (I2CTarget_Params *params) |
Function to initialize the I2CTarget_Params struct to its defaults. More... | |
I2CTarget_Handle | I2CTarget_open (uint_least8_t index, I2CTarget_Params *params) |
Function to initialize a given I2C target peripheral specified by the particular index value. The parameter specifies which mode the I2CTarget will operate. More... | |
void | I2CTarget_start (I2CTarget_Handle handle) |
Start I2CTarget driver listening on I2C bus. More... | |
void | I2CTarget_stop (I2CTarget_Handle handle) |
Stop I2CTarget driver from listening on I2C bus. More... | |
void | I2CTarget_close (I2CTarget_Handle handle) |
Variables | |
const I2CTarget_Config | I2CTarget_config [] |
const uint_least8_t | I2CTarget_count |
#define I2CTarget_STATUS_SUCCESS (0) |
Successful status code returned by application event callback function.
Status code returned from application's I2CTarget_EventCallbackFxn on success.
#define I2CTarget_STATUS_ERROR (-1) |
Generic error status code returned by application event callback function.
Status code returned from I2CTarget_EventCallbackFxn on error.
typedef struct I2CTarget_Config_* I2CTarget_Handle |
A handle that is returned from a I2CTarget_open() call.
typedef int_fast16_t(* I2CTarget_EventCallbackFxn) (I2CTarget_Handle handle, I2CTarget_Event event, uint8_t *val) |
I2CTarget event callback function.
User defined callback function that is called whenever an I2CTarget_Event event occurs. The callback function must handle all the I2CTarget_Event events.
[in] | handle | A I2CTarget_Handle returned from I2CTarget_open |
[in] | event | The I2CTarget_Event event causing the callback |
[in,out] | val | Parameter containing the data byte |
typedef struct I2CTarget_Config_ I2CTarget_Config |
I2CTarget Global configuration.
The I2CTarget_Config structure contains a set of pointers used to characterize the I2CTarget driver implementation.
This structure needs to be defined before calling I2CTarget_init() and it must not be changed thereafter.
enum I2CTarget_Event |
I2CTarget events that the application's I2CTarget_EventCallbackFxn must support.
Enumerator | |
---|---|
I2CTarget_Event_WRITE_REQUESTED | The target has been addressed with a write (target-receiver). The resulting |
I2CTarget_Event_READ_REQUESTED | The target has been addressed with a read (target-transmitter). The callback should fill the |
I2CTarget_Event_WRITE_RECEIVED | The target has received a byte of data (target-receiver). The resulting |
I2CTarget_Event_READ_PROCESSED | The target driver requests the next read byte (target-transmitter). Note that this does not necessarily mean that the previous byte has been ACKed, or that this next byte will actually be sent. This depends entirely on if the controller sends an ACK for the previous byte. The resulting |
I2CTarget_Event_STOP | A stop condition was received. The application should reset its state machine. |
void I2CTarget_init | ( | void | ) |
Function to initializes the I2CTarget module.
void I2CTarget_Params_init | ( | I2CTarget_Params * | params | ) |
Function to initialize the I2CTarget_Params struct to its defaults.
params | An pointer to I2CTarget_Params structure for initialization |
Defaults values are: eventCallbackFxn = NULL targetAddress = 0x42
I2CTarget_Handle I2CTarget_open | ( | uint_least8_t | index, |
I2CTarget_Params * | params | ||
) |
Function to initialize a given I2C target peripheral specified by the particular index value. The parameter specifies which mode the I2CTarget will operate.
index | Logical peripheral number for the I2CTarget indexed into the I2CTarget_config table |
params | Pointer to a parameter block, if NULL it will use default values. All the fields in this structure are RO (read-only). |
void I2CTarget_start | ( | I2CTarget_Handle | handle | ) |
Start I2CTarget driver listening on I2C bus.
handle | A I2CTarget_Handle returned from I2CTarget_open |
void I2CTarget_stop | ( | I2CTarget_Handle | handle | ) |
Stop I2CTarget driver from listening on I2C bus.
handle | A I2CTarget_Handle returned from I2CTarget_open |
void I2CTarget_close | ( | I2CTarget_Handle | handle | ) |
After calling the close function, the I2C is disabled.
handle | A I2CTarget_Handle returned from I2CTarget_open |
const I2CTarget_Config I2CTarget_config[] |
const uint_least8_t I2CTarget_count |