Added support new I2C driver for ESP32
This commit is contained in:
15
README.md
15
README.md
@@ -35,13 +35,13 @@ void app_main(void)
|
|||||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||||
i2c_config_t i2c_config = {
|
i2c_config_t i2c_config = {
|
||||||
.mode = I2C_MODE_MASTER,
|
.mode = I2C_MODE_MASTER,
|
||||||
.sda_io_num = GPIO_NUM_04, // In accordance with used chip.
|
.sda_io_num = GPIO_NUM_4, // In accordance with used chip.
|
||||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
.scl_io_num = GPIO_NUM_05, // In accordance with used chip.
|
.scl_io_num = GPIO_NUM_5, // In accordance with used chip.
|
||||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
};
|
};
|
||||||
i2c_param_config(I2C_PORT, &i2c_config);
|
|
||||||
i2c_driver_install(I2C_PORT, i2c_config.mode);
|
i2c_driver_install(I2C_PORT, i2c_config.mode);
|
||||||
|
i2c_param_config(I2C_PORT, &i2c_config);
|
||||||
#else
|
#else
|
||||||
i2c_master_bus_config_t i2c_bus_config = {
|
i2c_master_bus_config_t i2c_bus_config = {
|
||||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||||
@@ -55,15 +55,18 @@ void app_main(void)
|
|||||||
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
|
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
|
||||||
#endif
|
#endif
|
||||||
zh_bh1750_init_config_t zh_bh1750_init_config = ZH_BH1750_INIT_CONFIG_DEFAULT();
|
zh_bh1750_init_config_t zh_bh1750_init_config = ZH_BH1750_INIT_CONFIG_DEFAULT();
|
||||||
zh_bh1750_init_config.i2c_port = I2C_PORT; // Required only for ESP8266.
|
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||||
zh_bh1750_init_config.i2c_handle = i2c_bus_handle; // Required only for ESP32.
|
zh_bh1750_init_config.i2c_port = I2C_PORT;
|
||||||
|
#else
|
||||||
|
zh_bh1750_init_config.i2c_handle = i2c_bus_handle;
|
||||||
|
#endif
|
||||||
zh_bh1750_init(&zh_bh1750_init_config);
|
zh_bh1750_init(&zh_bh1750_init_config);
|
||||||
zh_bh1750_adjust(69); // Just for an example of how to change the sensor sensitivity.
|
zh_bh1750_adjust(69); // Just for an example of how to change the sensor sensitivity.
|
||||||
float lux = 0.0;
|
float lux = 0.0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
zh_bh1750_read(&lux);
|
zh_bh1750_read(&lux);
|
||||||
printf("Lux %0.2f\n", lux);
|
printf("Lux %d\n", (uint32_t)lux);
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,12 +10,6 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
#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.
|
* @brief Default values for zh_bh1750_init_config_t structure for initial initialization of the sensor.
|
||||||
*
|
*
|
||||||
@@ -25,8 +19,7 @@ typedef struct
|
|||||||
.i2c_address = I2C_ADDRESS_LOW, \
|
.i2c_address = I2C_ADDRESS_LOW, \
|
||||||
.operation_mode = HIGH_RESOLUTION, \
|
.operation_mode = HIGH_RESOLUTION, \
|
||||||
.work_mode = ONE_TIME, \
|
.work_mode = ONE_TIME, \
|
||||||
.i2c_port = 0, \
|
.i2c_port = 0 \
|
||||||
.i2c_handle = 0 \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -59,8 +52,11 @@ extern "C"
|
|||||||
CONTINUOUSLY, // Continuously measurement.
|
CONTINUOUSLY, // Continuously measurement.
|
||||||
ONE_TIME // One time measurement. Sensor is power down after measurement.
|
ONE_TIME // One time measurement. Sensor is power down after measurement.
|
||||||
} work_mode;
|
} work_mode;
|
||||||
bool i2c_port; // I2C port.
|
bool i2c_port; // I2C port.
|
||||||
|
#ifndef CONFIG_IDF_TARGET_ESP8266
|
||||||
i2c_master_bus_handle_t i2c_handle; // Unique I2C bus handle.
|
i2c_master_bus_handle_t i2c_handle; // Unique I2C bus handle.
|
||||||
|
#endif
|
||||||
|
|
||||||
} zh_bh1750_init_config_t;
|
} zh_bh1750_init_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user