/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2006-2023 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ IMPORTANT: THIS FILE IS AUTO-GENERATED BY LATTICE RADIANT Software. Permission: Lattice grants permission to use this code pursuant to the terms of the Lattice Corporation Open Source License Agreement. Disclaimer: Lattice provides no warranty regarding the use or functionality of this code. It is the user's responsibility to verify the user Software design for consistency and functionality through the use of formal Software validation methods. ------------------------------------------------------------------ Lattice Semiconductor Corporation 111 SW Fifth Avenue, Suite 700 Portland, OR 97204 U.S.A Email: techsupport@latticesemi.com Web: http://www.latticesemi.com/Home/Support/SubmitSupportTicket.aspx ================================================================== */ #ifndef I2C_SLAVE_H #define I2C_SLAVE_H #include #include #define I2C_TARGET_DRV_VER "v2.1.0" #define I2C_ADDR_7BIT_MODE 0x00 #define I2C_ADDR_10BIT_MODE 0x01 /**ERR CODE**/ typedef enum { /* basic errors */ I2C_SLV_SUCCESS = 0, /**< No error condition. */ I2C_SLV_PTR_ERROR = 1, /**< PTR is NULL. */ } I2C_SLAVE_ErrorCode; #define SET_ALL_BITS 0xff #define CLEAR_ALL_BITS 0x00 enum{ I2C_IDLE=0, I2C_BUSY, I2C_READY, I2C_ERROR, I2C_WRITE }; struct i2c_slave_instance { uint32_t base_addr; uint16_t slave_addr; uint8_t addr_mode; uint8_t *rx_buffer; uint8_t rx_size; uint8_t rx_idx; uint8_t status; uint8_t *tx_buffer; uint8_t tx_size; uint8_t tx_idx; }; /* ***************************************************************************** * performs i2c slave block initialization * * Note: This function initializes the i2c slave block * * * Arguments: * struct i2c_slave_instance *this_i2cs: i2c slave instance * uint32_t base_addr : base address of the i2c slave * uint16_t slave_addr : slave address * uint8_t addr_mode : address mode * uint8_t *rx_buffer : buffer for data received * uint8_t rx_size : size of rx buffer * uint8_t *tx_buffer : buffer for data sent * uint8_t tx_size : size of tx buffer * * Return Value: * uint8_t: * * ***************************************************************************** */ uint8_t i2c_slave_init(struct i2c_slave_instance *this_i2cs, uint32_t base_addr, uint16_t slave_addr, uint8_t addr_mode,uint8_t *rx_buffer, uint8_t rx_size, uint8_t *tx_buffer, uint8_t tx_size); /* ***************************************************************************** * I2C slave interrupt service routine * * Note: This function handles I2C slave interrupts * * * Arguments: * void *ctx: context pointer * * Return Value: * void * ***************************************************************************** */ void i2c_slave_isr(void *ctx); /* ***************************************************************************** * Enable or disable I2C slave clock stretching * * Note: This function enables or disables clock stretching for the I2C slave * * * Arguments: * struct i2c_slave_instance *this_i2cs: i2c slave instance * uint8_t stretch_enable : enable or disable clock stretching * * Return Value: * uint8_t: status code * * ***************************************************************************** */ uint8_t i2c_slave_clk_stretch(struct i2c_slave_instance *this_i2cs,uint8_t stretch_enable); /* ***************************************************************************** * Write data to I2C slave transmit buffer * * Note: This function writes data to the I2C slave transmit buffer * * * Arguments: * struct i2c_slave_instance *this_i2cs: i2c slave instance * uint8_t *tx_buf : data to be transmitted * uint8_t length : number of bytes to be transmitted * * Return Value: * uint8_t: status code * * ***************************************************************************** */ uint8_t i2c_slave_data_write(struct i2c_slave_instance *this_i2cs,uint8_t *tx_buf,uint8_t length); /* ***************************************************************************** * Read data from I2C slave receive buffer * * Note: This function reads data from the I2C slave receive buffer * * * Arguments: * struct i2c_slave_instance *this_i2cs: i2c slave instance * uint8_t *rx_buf : buffer to store received data * uint8_t *length : number of bytes received * * Return Value: * uint8_t: status code * * ***************************************************************************** */ uint8_t i2c_slave_data_read(struct i2c_slave_instance *this_i2cs,uint8_t *rx_buf,uint8_t *length); /* ***************************************************************************** * Get I2C slave status * * Note: This function gets the status of the I2C slave * * * Arguments: * struct i2c_slave_instance *this_i2cs: i2c slave instance * uint8_t *status : pointer to store the status value * * Return Value: * uint8_t: status code * * ***************************************************************************** */ uint8_t i2c_slave_status_get(struct i2c_slave_instance *this_i2cs,uint8_t *status); /* ***************************************************************************** * Configure I2C slave block * * Note: This function configures the I2C slave block * * * Arguments: * struct i2c_slave_instance *this_i2cs: i2c slave instance * uint32_t base_addr : base address of the i2c slave * uint16_t slave_addr : slave address * uint8_t addr_mode : address mode * * Return Value: * uint8_t: status code * * ***************************************************************************** */ uint8_t i2c_slave_config(struct i2c_slave_instance *this_i2cs); #endif