High level interface for interacting with the Cypress EZ Inter-Integrated Circuit (EZI2C).
The EZI2C driver implements an I2C slave device that emulates a common I2C EEPROM interface between the external master and your application code. EZI2C Slave buffers can be set up as any variable, array, or structure in your code without worrying about the I2C protocol. I2C related transactions and processing of data from the I2C master are handled by the driver through internal interrupt routine, reducing application involvement to maintain the I2C buffer.
Initialize EZI2C by using cyhal_ezi2c_init and selecting the sda and scl pins. Setup one or two memory buffers and read/write boundaries using the EZI2C configuration structure cyhal_ezi2c_cfg_t. See Snippet 1: EZI2C Initialization and Configuration
The following snippet shows how to initialize and configure an EZI2C and assign the pins to the sda and scl lines. The clk need not be provided (NULL), in which case a clock resource is assigned.
The following snippet shows how to use the cyhal_ezi2c_register_callback function. The callback parameter refers to the handler which will be invoked when an event triggers.
API Reference | |
EZI2C HAL Results | |
EZI2C specific return codes. | |
Data Structures | |
struct | cyhal_ezi2c_slave_cfg_t |
Initial EZI2C sub configuration. More... | |
struct | cyhal_ezi2c_cfg_t |
Initial EZI2C configuration. More... | |
Macros | |
#define | CYHAL_EZI2C_EVENT_NONE CYHAL_EZI2C_STATUS_OK |
CYHAL_EZI2C_EVENT_NONE event is deprecated and that CYHAL_EZI2C_STATUS_OK should be used instead. | |
Typedefs | |
typedef cyhal_ezi2c_status_t | cyhal_ezi2c_event_t |
This type is deprecated and that cyhal_ezi2c_status_t should be used instead. | |
typedef void(* | cyhal_ezi2c_event_callback_t) (void *callback_arg, cyhal_ezi2c_status_t event) |
Handler for I2C events. | |
Enumerations | |
enum | cyhal_ezi2c_sub_addr_size_t { CYHAL_EZI2C_SUB_ADDR8_BITS , CYHAL_EZI2C_SUB_ADDR16_BITS } |
Size of Sub-Address. More... | |
enum | cyhal_ezi2c_data_rate_t { CYHAL_EZI2C_DATA_RATE_100KHZ = 100000 , CYHAL_EZI2C_DATA_RATE_400KHZ = 400000 , CYHAL_EZI2C_DATA_RATE_1MHZ = 1000000 } |
Data rate of the slave. | |
enum | cyhal_ezi2c_status_t { CYHAL_EZI2C_STATUS_OK = 0x1UL , CYHAL_EZI2C_STATUS_READ1 = 0x2UL , CYHAL_EZI2C_STATUS_WRITE1 = 0x4UL , CYHAL_EZI2C_STATUS_READ2 = 0x8UL , CYHAL_EZI2C_STATUS_WRITE2 = 0x10UL , CYHAL_EZI2C_STATUS_BUSY = 0x20UL , CYHAL_EZI2C_STATUS_ERR = 0x40UL } |
Return codes of ezi2c. More... | |
Functions | |
cy_rslt_t | cyhal_ezi2c_init (cyhal_ezi2c_t *obj, cyhal_gpio_t sda, cyhal_gpio_t scl, const cyhal_clock_t *clk, const cyhal_ezi2c_cfg_t *cfg) |
Initialize the EZI2C (slave), and configures its specified pins and clock. More... | |
void | cyhal_ezi2c_free (cyhal_ezi2c_t *obj) |
Deinitialize the ezi2c object. More... | |
cyhal_ezi2c_status_t | cyhal_ezi2c_get_activity_status (cyhal_ezi2c_t *obj) |
EZI2C slave get activity status This function returns a non-zero value ( cyhal_ezi2c_status_t) if an I2C Read or Write cycle has occurred since the last time this function was called. More... | |
void | cyhal_ezi2c_register_callback (cyhal_ezi2c_t *obj, cyhal_ezi2c_event_callback_t callback, void *callback_arg) |
Register a EZI2C event callback handler. More... | |
void | cyhal_ezi2c_enable_event (cyhal_ezi2c_t *obj, cyhal_ezi2c_status_t event, uint8_t intr_priority, bool enable) |
Configure and Enable or Disable EZI2C Interrupt. More... | |
cy_rslt_t | cyhal_ezi2c_init_cfg (cyhal_ezi2c_t *obj, const cyhal_ezi2c_configurator_t *cfg, const cyhal_ezi2c_slave_cfg_t *slave1_cfg, const cyhal_ezi2c_slave_cfg_t *slave2_cfg) |
Initialize the EZI2C peripheral using a configurator generated configuration struct and set up slave address(es) data. More... | |
struct cyhal_ezi2c_slave_cfg_t |
struct cyhal_ezi2c_cfg_t |
Data Fields | ||
---|---|---|
bool | two_addresses |
Number of addresses (one or two). If set "true" - use two addresses otherwise ("false") one |
bool | enable_wake_from_sleep | When set, the slave will wake the device from Deep Sleep on an address match. |
cyhal_ezi2c_data_rate_t | data_rate |
Maximum frequency that the I2C Slave bus runs at. Supports standard data rates of 100/400/1000 kbps |
cyhal_ezi2c_slave_cfg_t | slave1_cfg |
Refer to cyhal_ezi2c_slave_cfg_t for details. This config structure is mandatory. |
cyhal_ezi2c_slave_cfg_t | slave2_cfg |
Refer to cyhal_ezi2c_slave_cfg_t for details. This config structure is optional. Set it if user want to use dual-port addressing otherwise leave blank |
cyhal_ezi2c_sub_addr_size_t | sub_address_size | The size of the sub-address, can either be 8 or 16 bits. |
enum cyhal_ezi2c_status_t |
Return codes of ezi2c.
cy_rslt_t cyhal_ezi2c_init | ( | cyhal_ezi2c_t * | obj, |
cyhal_gpio_t | sda, | ||
cyhal_gpio_t | scl, | ||
const cyhal_clock_t * | clk, | ||
const cyhal_ezi2c_cfg_t * | cfg | ||
) |
Initialize the EZI2C (slave), and configures its specified pins and clock.
See Snippet 1: EZI2C Initialization and Configuration
[out] | obj | Pointer to an EZI2C object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | sda | The sda pin |
[in] | scl | The scl pin |
[in] | clk | The clock to use can be shared, if NULL a new clock will be allocated |
[in] | cfg | The ezi2c configuration (refer to cyhal_ezi2c_cfg_t for details) |
void cyhal_ezi2c_free | ( | cyhal_ezi2c_t * | obj | ) |
Deinitialize the ezi2c object.
[in,out] | obj | The ezi2c object |
cyhal_ezi2c_status_t cyhal_ezi2c_get_activity_status | ( | cyhal_ezi2c_t * | obj | ) |
EZI2C slave get activity status This function returns a non-zero value ( cyhal_ezi2c_status_t) if an I2C Read or Write cycle has occurred since the last time this function was called.
See Snippet 2: Register Callback function
[in] | obj | The EZI2C object |
void cyhal_ezi2c_register_callback | ( | cyhal_ezi2c_t * | obj, |
cyhal_ezi2c_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
Register a EZI2C event callback handler.
See Snippet 2: Register Callback function
[in] | obj | The EZI2C object |
[in] | callback | The callback handler which will be invoked when an event triggers |
[in] | callback_arg | Generic argument that will be provided to the callback when called |
void cyhal_ezi2c_enable_event | ( | cyhal_ezi2c_t * | obj, |
cyhal_ezi2c_status_t | event, | ||
uint8_t | intr_priority, | ||
bool | enable | ||
) |
Configure and Enable or Disable EZI2C Interrupt.
[in] | obj | The EZI2C object |
[in] | event | The EZI2C event type |
[in] | intr_priority | The priority for NVIC interrupt events |
[in] | enable | True to turn on interrupts, False to turn off |
cy_rslt_t cyhal_ezi2c_init_cfg | ( | cyhal_ezi2c_t * | obj, |
const cyhal_ezi2c_configurator_t * | cfg, | ||
const cyhal_ezi2c_slave_cfg_t * | slave1_cfg, | ||
const cyhal_ezi2c_slave_cfg_t * | slave2_cfg | ||
) |
Initialize the EZI2C peripheral using a configurator generated configuration struct and set up slave address(es) data.
[in] | obj | The EZI2C peripheral to configure |
[in] | cfg | Configuration structure generated by a configurator. |
[in] | slave1_cfg | Primary slave address configuration |
[in] | slave2_cfg | Secondary slave address configuration (can be NULL) |