///Copyright (c) 2022, 四川汇源光通信有限公司 
///All rights reserved. 
///@file        drv_i2c.h 
///@brief       drv_i2c驱动程序
///
///@details     
///@note        
///@author      dufresne
///@date        2025/09/24 
///
///@version		v1.0 2025/09/24 初始版本

#ifndef DRV_I2C_H
#define DRV_I2C_H

#include "gd32f4xx.h"
#include "delay.h"



// #define SOFTWARE_I2C
#define HARDWARE_I2C

#define I2C_SCL_PIN     GPIO_PIN_6
#define I2C_SDA_PIN     GPIO_PIN_7

#define TMP75_ADDRESS   0x48        //1001000
#define TEMP_REGISTER_ADDRESS  0x00  //tmp75寄存器温度数据地址

#ifdef  HARDWARE_I2C
#define I2C_PERIPH      I2C0
#define I2C_SPEED       100000
#endif

#define I2C_SCL_HIGH  gpio_bit_set(GPIOB, I2C_SCL_PIN)
#define I2C_SCL_LOW   gpio_bit_reset(GPIOB, I2C_SCL_PIN)

#define I2C_SDA_HIGH  gpio_bit_set(GPIOB, I2C_SDA_PIN)
#define I2C_SDA_LOW   gpio_bit_reset(GPIOB, I2C_SDA_PIN)
#define I2C_SDA_GET   gpio_input_bit_get(GPIOB, I2C_SDA_PIN)

void i2c_init(void);
void i2c_gpio_config(void);

#ifdef  HARDWARE_I2C
void i2c_config(void);
void i2c_write(uint8_t *buff, int len, uint8_t device_address);
void i2c_read(uint8_t *buff, uint16_t len, uint8_t device_address);
#endif

#endif