This commit is contained in:
2024-09-27 00:15:24 +08:00
parent 9ce4cd2e44
commit d5814ddd62
2 changed files with 241 additions and 78 deletions

View File

@@ -1,7 +1,10 @@
#ifndef GD32E23X_HW_I2C_H
#define GD32E23X_HW_I2C_H
// #define I2C1_ENABLE
#define I2C0_BUS_RCU RCU_I2C0
#define I2C0_GPIO_RCU RCU_GPIOF
#define I2C0_GPIO_PORT GPIOF
#define I2C0_GPIO_SDA_PIN GPIO_PIN_0
@@ -12,6 +15,24 @@
#define I2C0_DCTY I2C_DTCY_2
#define I2C0_ADDR7 0xA0
#ifdef I2C1_ENABLE
#define I2C1_BUS_RCU RCU_I2C1
#define I2C1_GPIO_RCU RCU_GPIOA
#define I2C1_GPIO_PORT GPIOA
#define I2C1_GPIO_SDA_PIN GPIO_PIN_1
#define I2C1_GPIO_SCL_PIN GPIO_PIN_0
#define I2C1_GPIO_AF GPIO_AF_4
#define I2C1_SPEED 400000U
#define I2C1_DCTY I2C_DTCY_2
#define I2C1_ADDR7 0xA1
#endif
@@ -29,6 +50,19 @@ typedef enum {
I2C_STOP
} i2c_process_enum;
typedef struct
{
uint32_t i2c_gpio_rcu;
uint32_t i2c_gpio_port;
uint32_t i2c_gpio_sda_pin;
uint32_t i2c_gpio_scl_pin;
uint32_t i2c_gpio_af;
uint32_t i2c_speed;
uint32_t i2c_dcty;
uint32_t i2c_addr7;
}i2c_parameter_struct;
/**
@@ -72,4 +106,11 @@ uint8_t i2c_master_write_register3_raw(unsigned char Address, unsigned short len
void i2c0_master_init(void);
int read_ir_mlx90614(void);
void i2c_struct_para_init(i2c_parameter_struct* initpara);
void i2c_init(uint32_t i2c_periph, i2c_parameter_struct* initpara);
void i2c0_config(void);
#endif /* GD32E23X_HW_I2C_H */