Files
Smart-flower-system/components/i2c_master_messager/include/i2c_master_messager.h
Wang Beihong fcc2d0825d first commit
2026-03-14 14:19:32 +08:00

58 lines
1.2 KiB
C

#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "bh1750.h"
#include "driver/gpio.h"
#include "driver/i2c_types.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
i2c_port_num_t i2c_port;
gpio_num_t scl_io_num;
gpio_num_t sda_io_num;
bool i2c_enable_internal_pullup;
bool bh1750_enable;
bool aht30_enable;
uint16_t bh1750_read_period_ms;
uint16_t aht30_read_period_ms;
bh1750_measure_mode_t bh1750_mode;
} i2c_master_messager_config_t;
typedef struct {
float lux;
bool valid;
int64_t last_update_ms;
esp_err_t last_error;
} i2c_bh1750_data_t;
typedef struct {
float temperature_c;
float humidity_rh;
bool valid;
int64_t last_update_ms;
esp_err_t last_error;
} i2c_aht30_data_t;
typedef struct {
i2c_bh1750_data_t bh1750;
i2c_aht30_data_t aht30;
} i2c_master_messager_data_t;
#define I2C_MASTER_MESSAGER_MIN_PERIOD_MS (100)
esp_err_t i2c_master_messager_init(const i2c_master_messager_config_t *config);
esp_err_t i2c_master_messager_start(void);
esp_err_t i2c_master_messager_stop(void);
esp_err_t i2c_master_messager_get_data(i2c_master_messager_data_t *out_data);
esp_err_t i2c_master_messager_deinit(void);
#ifdef __cplusplus
}
#endif