46 lines
953 B
C
46 lines
953 B
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;
|
|
uint16_t read_period_ms;
|
|
uint8_t bh1750_addr;
|
|
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 {
|
|
i2c_bh1750_data_t bh1750;
|
|
} 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
|