This commit is contained in:
2024-06-16 11:28:20 +03:00
parent f6bafc6fe3
commit c2aa5f5eeb
3 changed files with 128 additions and 97 deletions

View File

@ -2,12 +2,19 @@
#include "esp_err.h"
#include "esp_log.h"
#ifdef CONFIG_IDF_TARGET_ESP8266
#include "driver/i2c.h"
#else
#include "driver/i2c_master.h"
// #include "driver/i2c.h"
// #ifdef CONFIG_IDF_TARGET_ESP8266
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// #endif
#ifdef CONFIG_IDF_TARGET_ESP8266
typedef struct
{
} i2c_master_bus_handle_t;
#endif
/**
* @brief Default values for zh_bh1750_init_config_t structure for initial initialization of the sensor.
@ -18,7 +25,8 @@
.i2c_address = I2C_ADDRESS_LOW, \
.operation_mode = HIGH_RESOLUTION, \
.work_mode = ONE_TIME, \
.i2c_port = 0 \
.i2c_port = 0, \
.i2c_handle = 0 \
}
#ifdef __cplusplus
@ -51,8 +59,8 @@ extern "C"
CONTINUOUSLY, // Continuously measurement.
ONE_TIME // One time measurement. Sensor is power down after measurement.
} work_mode;
bool i2c_port; // I2C port.
i2c_master_bus_handle_t i2c_handle;
bool i2c_port; // I2C port.
i2c_master_bus_handle_t i2c_handle; // Unique I2C bus handle.
} zh_bh1750_init_config_t;
/**
@ -69,8 +77,9 @@ extern "C"
* @return
* - ESP_OK if initialization was success
* - ESP_ERR_INVALID_ARG if parameter error
* - ESP_ERR_NOT_FOUND if sensor not connected or not responded
*/
esp_err_t zh_bh1750_init(zh_bh1750_init_config_t *config);
esp_err_t zh_bh1750_init(const zh_bh1750_init_config_t *config);
/**
* @brief Read BH1750 sensor.
@ -102,7 +111,7 @@ extern "C"
* - ESP_ERR_INVALID_STATE if I2C driver not installed or not in master mode
* - ESP_ERR_TIMEOUT if operation timeout because the bus is busy
*/
esp_err_t zh_bh1750_adjust(uint8_t value);
esp_err_t zh_bh1750_adjust(const uint8_t value);
#ifdef __cplusplus
}