#ifndef _GW3323_IIC_H
#define _GW3323_IIC_H

#include "include.h"

//---------------- IIC Flag Definition ----------------//
#define IIC_FLAG_DONE           ((uint32_t)0x80000000)
#define IIC_FLAG_ACK            ((uint32_t)0x40000000)

//----------------- IIC IT Definition ----------------//
#define IIC_IT_DONE             ((uint32_t)0x00000002)

// iic clock source select enum.
typedef enum {
    IIC_CLK_RC2M                 = 0x00000000,
    IIC_CLK_XOSC24M_DIV8         = 0x00800000,
} IIC_CLK_SOURCE_TYPEDEF;

// iic transmit direction select enum.
typedef enum {
    IIC_SEND_MODE           = 0x01,
    IIC_RECEIVE_MODE        = 0x02,
} IIC_TRANSMIT_MODE;

// iic init struct.
typedef struct {
    unsigned char           scl_pose_div;
    unsigned char           sda_hold_cnt;
    IIC_CLK_SOURCE_TYPEDEF  clk_source;
} iic_init_typedef;

//--------------- Function used to configure iic or transmit data ---------------//
void iic_init(iic_init_typedef *iic_init_struct);
void iic_cmd(FUNCTIONAL_STATE state);
void iic_transmit_config(uint8_t transmit_mode, uint8_t dev_addr0, uint16_t reg_addr, uint8_t len, uint8_t dev_addr1);
void iic_start_transmit(void);
void iic_send_data(uint8_t dev_addr, uint16_t reg_addr, uint32_t data, uint8_t len);
uint32_t iic_receive_data(uint8_t dev_addr0, uint16_t reg_addr, uint8_t len, uint8_t dev_addr1);
//------------------- Function used to configure interrupt -------------------//
void iic_pic_config(isr_t isr, int pr, uint16_t iic_ie_bit, FUNCTIONAL_STATE state);
FLAG_STATE iic_get_flag(uint32_t iic_flag);
void iic_clear_flag(uint32_t iic_flag);

#endif // _GW3323_IIC_H
