/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> 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_MASTER_H #define I2C_MASTER_H #include "sys_platform.h" #include #include #define I2C_CONTROLLER_DRV_VER "v2.0.0" #define INT_MODE 0 // 0, polling mode; 1, INT mode(not support) typedef enum { I2CM_STATE_IDLE = 0, I2CM_STATE_READ, I2CM_STATE_WRITE, I2CM_STATE_TIMEOUT, I2CM_STATE_ERROR = 0xFF } i2cm_state; typedef enum{ I2CM_ADDR_7BIT_MODE = 7, I2CM_ADDR_10BIT_MODE = 10, }I2CM_ADDR_MODE; struct i2cm_instance { const char *instance_name; uint32_t base_address; // i2c master base address assigned uint8_t state; // IDLE, READ, WRITE, uint8_t addr_mode; // 7-bit or 10-bit mode uint16_t interrupts_en; uint8_t *rx_buff; uint8_t rcv_length; }; /* * i2c master register definition */ /* ***************************************************************************** * * uint_8 i2c_master_init(struct i2cm_instance* this_i2cm, * uint32_t base_addr) * * performs i2c master block initialization * * Note: This function initializes the i2c master block * * * Arguments: * struct i2cm_instance* this_i2cm: i2c master instance * uint32_t base_addr : base address of the i2c master * * Return Value: * int: * * ***************************************************************************** */ uint8_t i2c_master_init(struct i2cm_instance *this_i2cm, uint32_t base_addr); /* ***************************************************************************** * * uint8_t i2c_master_config(struct i2cm_instance* this_i2cm, * uint8_t i2c_mode, * uint8_t interrupts_en); * * configure the i2c master controller * * Note: This function configurs the i2c master block * * * Arguments: * struct i2cm_instance* this_i2cm: i2c master instance * uint32_t base_addr : base address of the i2c master * uint8_t i2c_mode : i2c mode: 7 - 7 bit address mode * 10 - 10 bit address mode * uint8_t interrupts_en : enabled interrupt bits * uint16_t pre_scaler : calculate and set the prescaler to tune the clock * * Return Value: * int: * * ***************************************************************************** */ uint8_t i2c_master_config(struct i2cm_instance *this_i2cm, uint8_t i2c_mode, uint16_t interrupts_en, uint16_t pre_scaler); /* ***************************************************************************** * * uint8_t i2c_master_read(struct i2cm_instance* this_i2cm, * uint16_t address, * uint8_t buffer_size, * uint8_t *data_buffer) * * performs i2c master read operation * * Note: This function perform the i2c master read operation * * * Arguments: * struct i2cm_instance* this_i2cm: i2c master instance * uint16_t address : address of the slave device * uint8_t read_length : number of bytes to read * uint8_t *data_buffer : pointer to data buffer storing the dare read back * * Return Value: * int: * * ***************************************************************************** */ uint8_t i2c_master_read(struct i2cm_instance *this_i2cm, uint16_t address, uint8_t read_length, uint8_t * data_buffer); /* ***************************************************************************** * * uint8_t i2c_master_write(struct i2cm_instance* this_i2cm, * uint16_t address, * uint8_t buffer_size, * uint8_t *data_buffer) * * performs i2c master write operation * * Note: This function perform the i2c master write operation * * * Arguments: * struct i2cm_instance* this_i2cm: i2c master instance * uint16_t address : address of the slave device * uint8_t buffer_size : number of bytes to write * uint8_t *data_buffer : pointer to data buffer * * Return Value: * int: * * ***************************************************************************** */ uint8_t i2c_master_write(struct i2cm_instance *this_i2cm, uint16_t address, uint8_t buffer_size, uint8_t * data_buffer); /* ***************************************************************************** * * uint8_t i2c_master_repeated_start(struct i2cm_instance *this_i2cm, * uint16_t address, * uint8_t wr_data_size ,uint8_t * wr_data_buffer , uint8_t rd_data_size , uint8_t * rd_data_buffer); * * performs i2c master repeated start operation * * Note: This function perform the i2c master repeated start operation * * * Arguments: * struct i2cm_instance* this_i2cm: i2c master instance * uint16_t address : address of the slave device * uint8_t wr_data_size : number of bytes to write * uint8_t *wr_data_buffer : pointer to write data buffer * uint8_t rd_data_size : number of bytes to read * uint8_t *rd_data_buffer : pointer to read data buffer * * Return Value: * int: * * ***************************************************************************** */ uint8_t i2c_master_repeated_start(struct i2cm_instance *this_i2cm, uint16_t address, uint8_t wr_data_size ,uint8_t * wr_data_buffer , uint8_t rd_data_size , uint8_t * rd_data_buffer); //void i2c_master_isr(void *ctx); #endif /*I2C Master Header File */