Inter-Integrated Circuit (I2C) Slave Driver.
The I2C Slave driver allows you to send and recieve I2C transfers. This driver complements the I2C.h driver which operates as an I2C master.
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.
Refer to the Driver's Configuration section for driver configuration information.
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | I2CSlave_Params |
I2CSlave parameters used with I2CSlave_open(). More... | |
struct | I2CSlave_FxnTable |
The definition of a I2CSlave function table that contains the required set of functions to control a specific I2CSlave driver implementation. More... | |
struct | I2CSlave_Config_ |
I2C Slave driver's custom configuration structure. More... | |
Macros | |
#define | I2CSLAVE_CMD_RESERVED (32) |
#define | I2CSLAVE_STATUS_RESERVED (-32) |
#define | I2CSLAVE_STATUS_SUCCESS (0) |
Successful status code returned by I2CSlave_control(). More... | |
#define | I2CSLAVE_STATUS_ERROR (-1) |
Generic error status code returned by I2CSlave_control(). More... | |
#define | I2CSLAVE_STATUS_UNDEFINEDCMD (-2) |
An error status code returned by I2CSlave_control() for undefined command codes. More... | |
Typedefs | |
typedef struct I2CSlave_Config_ * | I2CSlave_Handle |
A handle that is returned from a I2CSlave_open() call. More... | |
typedef void(* | I2CSlave_CallbackFxn) (I2CSlave_Handle handle, bool status) |
The definition of a callback function. More... | |
typedef struct I2CSlave_Config_ | I2CSlave_Config |
I2C Slave driver's custom configuration structure. More... | |
Enumerations | |
enum | I2CSlave_TransferMode { I2CSLAVE_MODE_BLOCKING, I2CSLAVE_MODE_CALLBACK } |
Return behavior of I2CSlave_write() and I2CSlave_read() specified in the I2CSlave_Params. More... | |
Functions | |
void | I2CSlave_close (I2CSlave_Handle handle) |
Function to close an I2CSlave driver instance. More... | |
int_fast16_t | I2CSlave_control (I2CSlave_Handle handle, uint_fast16_t cmd, void *arg) |
Function performs implementation specific features on a driver instance. More... | |
void | I2CSlave_init (void) |
Function to initialize the I2C Slave driver. More... | |
I2CSlave_Handle | I2CSlave_open (uint_least8_t index, I2CSlave_Params *params) |
Function to initialize the I2CSlave peripheral. More... | |
void | I2CSlave_Params_init (I2CSlave_Params *params) |
Initialize an I2CSlave_Params structure to its default values. More... | |
bool | I2CSlave_read (I2CSlave_Handle handle, void *buffer, size_t size) |
Perform an I2C read from an I2C master. More... | |
bool | I2CSlave_write (I2CSlave_Handle handle, const void *buffer, size_t size) |
Perform an I2C write to an I2C master. More... | |
typedef struct I2CSlave_Config_* I2CSlave_Handle |
A handle that is returned from a I2CSlave_open() call.
typedef void(* I2CSlave_CallbackFxn) (I2CSlave_Handle handle, bool status) |
The definition of a callback function.
When operating in I2CSLAVE_MODE_CALLBACK, the callback function is called when a transfer completes. The application is responsible for declaring an I2CSlave_CallbackFxn function and providing a pointer in I2CSlave_Params.transferCallbackFxn.
[out] | handle | I2CSlave_Handle used with the initial call to I2CSlave_read() or I2CSlave_write() |
[out] | status | Boolean indicating if the I2C transfer was successful. If true , the transfer was successful. If false , the transfer failed. |
typedef struct I2CSlave_Config_ I2CSlave_Config |
I2C Slave driver's custom configuration structure.
Return behavior of I2CSlave_write() and I2CSlave_read() specified in the I2CSlave_Params.
Enumerator | |
---|---|
I2CSLAVE_MODE_BLOCKING | |
I2CSLAVE_MODE_CALLBACK |
void I2CSlave_close | ( | I2CSlave_Handle | handle | ) |
Function to close an I2CSlave driver instance.
[in] | handle | An I2CSlave_Handle returned from I2CSlave_open() |
int_fast16_t I2CSlave_control | ( | I2CSlave_Handle | handle, |
uint_fast16_t | cmd, | ||
void * | arg | ||
) |
Function performs implementation specific features on a driver instance.
[in] | handle | An I2CSlave_Handle returned from I2CSlave_open() |
[in] | cmd | A command value defined by the device specific implementation |
[in] | arg | An optional R/W (read/write) argument that is accompanied with cmd |
I2CSLAVE_STATUS_UNDEFINEDCMD | The cmd value is not supported by the device specific implementation. |
void I2CSlave_init | ( | void | ) |
Function to initialize the I2C Slave driver.
This function must also be called before any other I2CSlave driver APIs.
I2CSlave_Handle I2CSlave_open | ( | uint_least8_t | index, |
I2CSlave_Params * | params | ||
) |
Function to initialize the I2CSlave peripheral.
Function to initialize the I2CSlave peripheral specified by the particular index value.
[in] | index | Index in the I2CSlave_Config [] array. |
[in] | params | Pointer to an initialized I2CSlave_Params structure. If NULL, the default I2CSlave_Params values are used. |
void I2CSlave_Params_init | ( | I2CSlave_Params * | params | ) |
Initialize an I2CSlave_Params structure to its default values.
[in] | params | A pointer to an I2CSlave_Params structure. |
Defaults values are:
bool I2CSlave_read | ( | I2CSlave_Handle | handle, |
void * | buffer, | ||
size_t | size | ||
) |
Perform an I2C read from an I2C master.
This function will perform an I2C read transfer.
The data written by the I2CSlave is synchronized with the START and STOP condition from an I2C master.
[in] | handle | An I2CSlave_Handle returned from I2CSlave_open() |
[in,out] | buffer | A pointer to buffer to store data read |
[in] | size | The number of bytes to read into buffer |
true | on successful read |
false | on an error |
bool I2CSlave_write | ( | I2CSlave_Handle | handle, |
const void * | buffer, | ||
size_t | size | ||
) |
Perform an I2C write to an I2C master.
This function will perform an I2C write transfer.
The data written by the I2CSlave is synchronized with the START and STOP conditions from an I2C master.
[in] | handle | An I2CSlave_Handle |
[in] | buffer | A pointer to buffer containing data to write |
[in] | size | The number of bytes in buffer to write. If the I2C master requests more than size bytes, this driver will transmit 0xFF until a STOP condition is recieved. |
true | on successful write |
false | on an error |