49 lines
1.0 KiB
C
49 lines
1.0 KiB
C
/**
|
|
* @file sht30.h
|
|
* @brief SHT30 温湿度传感器驱动 (I2C)
|
|
*
|
|
* 硬件接口: I2C (复用 hw_init 中已初始化的 I2C_PORT)
|
|
* I2C 地址: 0x44 (ADDR 接地) 或 0x45 (ADDR 接 VDD)
|
|
* 框架: ESP-IDF 5.1.x
|
|
*/
|
|
|
|
#ifndef SHT30_H
|
|
#define SHT30_H
|
|
|
|
#include <stdint.h>
|
|
#include "esp_err.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** 单次测量结果 */
|
|
typedef struct {
|
|
float temperature; /* 摄氏度 */
|
|
float humidity; /* 相对湿度 % */
|
|
} sht30_data_t;
|
|
|
|
/**
|
|
* @brief 初始化 SHT30 传感器 (验证 I2C 通信)
|
|
* @return ESP_OK 成功, 否则失败
|
|
*
|
|
* 注意: 调用前需确保 I2C 总线已初始化 (hw_i2c_init)。
|
|
*/
|
|
esp_err_t sht30_init(void);
|
|
|
|
/**
|
|
* @brief 执行单次测量 (高重复性、时钟拉伸模式)
|
|
* @param data [输出] 温湿度结果
|
|
* @return ESP_OK 成功, 否则失败
|
|
*
|
|
* 内部等待约 15 ms 后读取 6 字节原始数据,
|
|
* 经 CRC-8 校验后转换为物理量。
|
|
*/
|
|
esp_err_t sht30_read(sht30_data_t *data);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* SHT30_H */
|