2025-09-24 09:50:50 +00:00
|
|
|
///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
|
|
|
|
|
2025-09-26 10:17:39 +00:00
|
|
|
#include "gd32f4xx.h"
|
|
|
|
#include "delay.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #define SOFTWARE_I2C
|
|
|
|
#define HARDWARE_I2C
|
2025-09-24 09:50:50 +00:00
|
|
|
|
|
|
|
#define I2C_SCL_PIN GPIO_PIN_6
|
|
|
|
#define I2C_SDA_PIN GPIO_PIN_7
|
|
|
|
|
2025-09-25 10:05:11 +00:00
|
|
|
#define TMP75_ADDRESS 0x48 //1001000
|
2025-09-29 09:41:58 +00:00
|
|
|
#define TEMP_REGISTER_ADDRESS 0x00 //tmp75寄存器温度数据地址
|
2025-09-25 10:05:11 +00:00
|
|
|
|
2025-09-26 10:17:39 +00:00
|
|
|
#ifdef HARDWARE_I2C
|
|
|
|
#define I2C_PERIPH I2C0
|
|
|
|
#define I2C_SPEED 100000
|
|
|
|
#endif
|
2025-09-25 10:05:11 +00:00
|
|
|
|
2025-09-26 10:17:39 +00:00
|
|
|
#define I2C_SCL_HIGH gpio_bit_set(GPIOB, I2C_SCL_PIN)
|
|
|
|
#define I2C_SCL_LOW gpio_bit_reset(GPIOB, I2C_SCL_PIN)
|
2025-09-24 09:50:50 +00:00
|
|
|
|
2025-09-26 10:17:39 +00:00
|
|
|
#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)
|
2025-09-24 09:50:50 +00:00
|
|
|
|
|
|
|
void i2c_init(void);
|
|
|
|
void i2c_gpio_config(void);
|
|
|
|
|
2025-09-26 10:17:39 +00:00
|
|
|
#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
|
2025-09-24 09:50:50 +00:00
|
|
|
|
|
|
|
#endif
|