/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2006-2018 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_SLAVE_BASE_ADDR 0x00008800 #define READ_CMD 0x03 #define I2C_ADDR_7BIT_MODE 0x00 #define I2C_ADDR_10BIT_MODE 0x01 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; }; 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); void i2c_slave_isr(void *ctx); uint8_t i2c_slave_clk_stretch(struct i2c_slave_instance *this_i2cs,uint8_t stretch_enable); uint8_t i2c_slave_data_write(struct i2c_slave_instance *this_i2cs,uint8_t *tx_buf,uint8_t length); uint8_t i2c_slave_data_read(struct i2c_slave_instance *this_i2cs,uint8_t *rx_buf,uint8_t *length); uint8_t i2c_slave_status_get(struct i2c_slave_instance *this_i2cs,uint8_t *status); uint8_t i2c_slave_config(struct i2c_slave_instance *this_i2cs, uint32_t base_addr, uint16_t slave_addr, uint8_t addr_mode); #endif