diff --git a/.github/workflows/upload_component.yml b/.github/workflows/upload_component.yml index 9a2391238..15b470576 100644 --- a/.github/workflows/upload_component.yml +++ b/.github/workflows/upload_component.yml @@ -76,6 +76,7 @@ jobs: components/sensors/power_monitor/ina236; components/sensors/pressure/bme280; components/sensors/radar/at581x; + components/sensors/sensor_hub; components/spi_bus; components/touch/touch_proximity_sensor; components/usb/esp_msc_ota; diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml index dad110616..455044551 100644 --- a/.gitlab/ci/build.yml +++ b/.gitlab/ci/build.yml @@ -1327,6 +1327,14 @@ build_components_sensors_radar_at581x_test_apps: variables: EXAMPLE_DIR: components/sensors/radar/at581x/test_apps +build_components_sensor_hub_test_apps: + extends: + - .build_examples_template + - .rules:build:components_sensors_sensor_hub_test_apps + - .build_idf_active_release_version + variables: + EXAMPLE_DIR: components/sensors/sensor_hub/test_apps + build_components_spi_bus_test_apps: extends: - .build_examples_template diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index 57881dcb2..2d216a911 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -252,6 +252,7 @@ .patterns-components_sensors_sensor_hub: &patterns-components_sensors_sensor_hub - "components/sensors/sensor_hub/**/*" + - "tools/cmake_utilities/package_manager.cmake" .patterns-components_spi_bus: &patterns-components_spi_bus - "components/spi_bus/**/*" @@ -2121,7 +2122,7 @@ - <<: *if-dev-push changes: *patterns-components_sensors_pressure_bme280 -.rules:build:components_sensors_sensor_hub_test: +.rules:build:components_sensors_sensor_hub_test_apps: rules: - <<: *if-protected - <<: *if-label-build diff --git a/README.md b/README.md index 6207cdfce..e5de36e80 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ The registered components in ESP-IoT-Solution are listed below: | [openai](https://components.espressif.com/components/espressif/openai) | [![Component Registry](https://components.espressif.com/components/espressif/openai/badge.svg)](https://components.espressif.com/components/espressif/openai) | | [power_measure](https://components.espressif.com/components/espressif/power_measure) | [![Component Registry](https://components.espressif.com/components/espressif/power_measure/badge.svg)](https://components.espressif.com/components/espressif/power_measure) | | [pwm_audio](https://components.espressif.com/components/espressif/pwm_audio) | [![Component Registry](https://components.espressif.com/components/espressif/pwm_audio/badge.svg)](https://components.espressif.com/components/espressif/pwm_audio) | +| [sensor_hub](https://components.espressif.com/components/espressif/sensor_hub) | [![Component Registry](https://components.espressif.com/components/espressif/sensor_hub/badge.svg)](https://components.espressif.com/components/espressif/sensor_hub) | | [servo](https://components.espressif.com/components/espressif/servo) | [![Component Registry](https://components.espressif.com/components/espressif/servo/badge.svg)](https://components.espressif.com/components/espressif/servo) | | [sht3x](https://components.espressif.com/components/espressif/sht3x) | [![Component Registry](https://components.espressif.com/components/espressif/sht3x/badge.svg)](https://components.espressif.com/components/espressif/sht3x) | | [spi_bus](https://components.espressif.com/components/espressif/spi_bus) | [![Component Registry](https://components.espressif.com/components/espressif/spi_bus/badge.svg)](https://components.espressif.com/components/espressif/spi_bus) | diff --git a/README_CN.md b/README_CN.md index cf5e8f061..2b617c2ae 100644 --- a/README_CN.md +++ b/README_CN.md @@ -118,6 +118,7 @@ ESP-IoT-Solution 中注册的组件如下: | [openai](https://components.espressif.com/components/espressif/openai) | [![Component Registry](https://components.espressif.com/components/espressif/openai/badge.svg)](https://components.espressif.com/components/espressif/openai) | | [power_measure](https://components.espressif.com/components/espressif/power_measure) | [![Component Registry](https://components.espressif.com/components/espressif/power_measure/badge.svg)](https://components.espressif.com/components/espressif/power_measure) | | [pwm_audio](https://components.espressif.com/components/espressif/pwm_audio) | [![Component Registry](https://components.espressif.com/components/espressif/pwm_audio/badge.svg)](https://components.espressif.com/components/espressif/pwm_audio) | +| [sensor_hub](https://components.espressif.com/components/espressif/sensor_hub) | [![Component Registry](https://components.espressif.com/components/espressif/sensor_hub/badge.svg)](https://components.espressif.com/components/espressif/sensor_hub) | | [servo](https://components.espressif.com/components/espressif/servo) | [![Component Registry](https://components.espressif.com/components/espressif/servo/badge.svg)](https://components.espressif.com/components/espressif/servo) | | [sht3x](https://components.espressif.com/components/espressif/sht3x) | [![Component Registry](https://components.espressif.com/components/espressif/sht3x/badge.svg)](https://components.espressif.com/components/espressif/sht3x) | | [spi_bus](https://components.espressif.com/components/espressif/spi_bus) | [![Component Registry](https://components.espressif.com/components/espressif/spi_bus/badge.svg)](https://components.espressif.com/components/espressif/spi_bus) | diff --git a/components/sensors/humiture/hdc2010/CHANGELOG.md b/components/sensors/humiture/hdc2010/CHANGELOG.md index 48a3311bc..efecf715e 100644 --- a/components/sensors/humiture/hdc2010/CHANGELOG.md +++ b/components/sensors/humiture/hdc2010/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.2.0 - 2024-12-19 + +### Enhancements: + +* Update the method of driver registration to the `sensor_hub` + ## v0.1.1 - 2024-12-11 ### Bug Fixes: diff --git a/components/sensors/humiture/hdc2010/CMakeLists.txt b/components/sensors/humiture/hdc2010/CMakeLists.txt index 71c55e347..f4a70369a 100644 --- a/components/sensors/humiture/hdc2010/CMakeLists.txt +++ b/components/sensors/humiture/hdc2010/CMakeLists.txt @@ -1,5 +1,9 @@ idf_component_register(SRCS "hdc2010.c" INCLUDE_DIRS include) +if(CONFIG_SENSOR_INCLUDED_HUMITURE) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u humiture_hdc2010_init") +endif() + include(package_manager) cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) diff --git a/components/sensors/humiture/hdc2010/hdc2010.c b/components/sensors/humiture/hdc2010/hdc2010.c index 5c6dc7f49..e5e4f0b80 100644 --- a/components/sensors/humiture/hdc2010/hdc2010.c +++ b/components/sensors/humiture/hdc2010/hdc2010.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #include "i2c_bus.h" #include "esp_log.h" #include "hdc2010.h" +#include "iot_sensor_hub.h" #define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */ #define READ_BIT I2C_MASTER_READ /*!< I2C master read */ @@ -289,3 +290,81 @@ esp_err_t hdc2010_default_init(hdc2010_handle_t sensor) return ESP_OK; } + +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE + +static hdc2010_handle_t hdc2010 = NULL; +static bool is_init = false; + +esp_err_t humiture_hdc2010_init(i2c_bus_handle_t i2c_bus, uint8_t addr) +{ + if (is_init || !i2c_bus) { + return ESP_FAIL; + } + + hdc2010 = hdc2010_create(i2c_bus, addr); + + if (!hdc2010) { + return ESP_FAIL; + } + + is_init = true; + return ESP_OK; +} + +esp_err_t humiture_hdc2010_deinit(void) +{ + if (!is_init) { + return ESP_FAIL; + } + + esp_err_t ret = hdc2010_delete(&hdc2010); + + if (ret != ESP_OK) { + return ESP_FAIL; + } + + is_init = false; + return ESP_OK; +} + +esp_err_t humiture_hdc2010_test(void) +{ + if (!is_init) { + return ESP_FAIL; + } + + return ESP_OK; +} + +esp_err_t humiture_hdc2010_acquire_humidity(float *h) +{ + if (!is_init) { + return ESP_FAIL; + } + + *h = hdc2010_get_humidity(hdc2010); + return ESP_OK; +} + +esp_err_t humiture_hdc2010_acquire_temperature(float *t) +{ + if (!is_init) { + return ESP_FAIL; + } + + *t = hdc2010_get_temperature(hdc2010); + return ESP_OK; +} + +static humiture_impl_t hdc2010_impl = { + .init = humiture_hdc2010_init, + .deinit = humiture_hdc2010_deinit, + .test = humiture_hdc2010_test, + .acquire_humidity = humiture_hdc2010_acquire_humidity, + .acquire_temperature = humiture_hdc2010_acquire_temperature, +}; + +SENSOR_HUB_DETECT_FN(HUMITURE_ID, hdc2010, &hdc2010_impl); + +#endif diff --git a/components/sensors/humiture/hdc2010/idf_component.yml b/components/sensors/humiture/hdc2010/idf_component.yml index 8d73f8d33..882c1ff9d 100644 --- a/components/sensors/humiture/hdc2010/idf_component.yml +++ b/components/sensors/humiture/hdc2010/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.1" +version: "0.2.0" description: I2C driver for HDC2010 humiture sensor url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/humiture/hdc2010 repository: https://github.com/espressif/esp-iot-solution.git @@ -8,5 +8,8 @@ dependencies: i2c_bus: public: true override_path: "../../../i2c_bus" + sensor_hub: + public: true + override_path: "../../../sensors/sensor_hub" idf: '>=4.4' cmake_utilities: "0.*" diff --git a/components/sensors/humiture/mvh3004d/CHANGELOG.md b/components/sensors/humiture/mvh3004d/CHANGELOG.md index 4b67a9d74..12c363421 100644 --- a/components/sensors/humiture/mvh3004d/CHANGELOG.md +++ b/components/sensors/humiture/mvh3004d/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.2.0 - 2024-12-19 + +### Enhancements: + +* Update the method of driver registration to the `sensor_hub` + ## v0.1.0 - 2024-11-5 ### Enhancements: diff --git a/components/sensors/humiture/mvh3004d/CMakeLists.txt b/components/sensors/humiture/mvh3004d/CMakeLists.txt index 54e0f37ff..e5d19fe18 100644 --- a/components/sensors/humiture/mvh3004d/CMakeLists.txt +++ b/components/sensors/humiture/mvh3004d/CMakeLists.txt @@ -1,5 +1,9 @@ idf_component_register(SRCS "mvh3004d.c" INCLUDE_DIRS include) +if(CONFIG_SENSOR_INCLUDED_HUMITURE) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u humiture_mvh3004d_init") +endif() + include(package_manager) cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) diff --git a/components/sensors/humiture/mvh3004d/idf_component.yml b/components/sensors/humiture/mvh3004d/idf_component.yml index a4f97c2df..9b6e6c69d 100644 --- a/components/sensors/humiture/mvh3004d/idf_component.yml +++ b/components/sensors/humiture/mvh3004d/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.0" +version: "0.2.0" description: I2C driver for MVH3004D humiture sensor url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/humiture/mvh3004d repository: https://github.com/espressif/esp-iot-solution.git @@ -8,5 +8,8 @@ dependencies: i2c_bus: public: true override_path: "../../../i2c_bus" + sensor_hub: + public: true + override_path: "../../../sensors/sensor_hub" idf: '>=4.4' cmake_utilities: "0.*" diff --git a/components/sensors/humiture/mvh3004d/mvh3004d.c b/components/sensors/humiture/mvh3004d/mvh3004d.c index bd42e19a1..d07c79ad6 100644 --- a/components/sensors/humiture/mvh3004d/mvh3004d.c +++ b/components/sensors/humiture/mvh3004d/mvh3004d.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,7 @@ #include #include "esp_log.h" #include "mvh3004d.h" +#include "iot_sensor_hub.h" static const char *TAG = "mvh3004d"; typedef struct { @@ -69,3 +70,97 @@ esp_err_t mvh3004d_get_temperature(mvh3004d_handle_t sensor, float *tp) { return mvh3004d_get_data(sensor, tp, NULL); } + +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE + +static mvh3004d_handle_t mvh3004d = NULL; +static bool is_init = false; + +esp_err_t humiture_mvh3004d_init(i2c_bus_handle_t i2c_bus, uint8_t addr) +{ + if (is_init || !i2c_bus) { + return ESP_FAIL; + } + + mvh3004d = mvh3004d_create(i2c_bus, addr); + + if (!mvh3004d) { + return ESP_FAIL; + } + + is_init = true; + return ESP_OK; +} + +esp_err_t humiture_mvh3004d_deinit(void) +{ + if (!is_init) { + return ESP_FAIL; + } + + esp_err_t ret = mvh3004d_delete(&mvh3004d); + + if (ret != ESP_OK) { + return ESP_FAIL; + } + + is_init = false; + return ESP_OK; +} + +esp_err_t humiture_mvh3004d_test(void) +{ + if (!is_init) { + return ESP_FAIL; + } + + return ESP_OK; +} + +esp_err_t humiture_mvh3004d_acquire_humidity(float *h) +{ + if (!is_init) { + return ESP_FAIL; + } + + float humidity = 0; + esp_err_t ret = mvh3004d_get_huminity(mvh3004d, &humidity); + + if (ret == ESP_OK) { + *h = humidity; + return ESP_OK; + } + + *h = 0; + return ESP_FAIL; +} + +esp_err_t humiture_mvh3004d_acquire_temperature(float *t) +{ + if (!is_init) { + return ESP_FAIL; + } + + float temperature = 0; + esp_err_t ret = mvh3004d_get_temperature(mvh3004d, &temperature); + + if (ret == ESP_OK) { + *t = temperature; + return ESP_OK; + } + + *t = 0; + return ESP_FAIL; +} + +static humiture_impl_t mvh3004d_impl = { + .init = humiture_mvh3004d_init, + .deinit = humiture_mvh3004d_deinit, + .test = humiture_mvh3004d_test, + .acquire_humidity = humiture_mvh3004d_acquire_humidity, + .acquire_temperature = humiture_mvh3004d_acquire_temperature, +}; + +SENSOR_HUB_DETECT_FN(HUMITURE_ID, mvh3004d, &mvh3004d_impl); + +#endif diff --git a/components/sensors/humiture/sht3x/CHANGELOG.md b/components/sensors/humiture/sht3x/CHANGELOG.md index 4b67a9d74..27fd490e2 100644 --- a/components/sensors/humiture/sht3x/CHANGELOG.md +++ b/components/sensors/humiture/sht3x/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.2.0 - 2024-12-9 + +### Enhancements: + +* Update the method of driver registration to the `sensor hub` + ## v0.1.0 - 2024-11-5 ### Enhancements: diff --git a/components/sensors/humiture/sht3x/CMakeLists.txt b/components/sensors/humiture/sht3x/CMakeLists.txt index 961b114d0..5eed48b88 100644 --- a/components/sensors/humiture/sht3x/CMakeLists.txt +++ b/components/sensors/humiture/sht3x/CMakeLists.txt @@ -2,5 +2,9 @@ idf_component_register(SRCS "sht3x.c" INCLUDE_DIRS include REQUIRES esp_timer) +if(CONFIG_SENSOR_INCLUDED_HUMITURE) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u humiture_sht3x_init") +endif() + include(package_manager) cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) diff --git a/components/sensors/humiture/sht3x/idf_component.yml b/components/sensors/humiture/sht3x/idf_component.yml index f98e2860f..56d931a42 100644 --- a/components/sensors/humiture/sht3x/idf_component.yml +++ b/components/sensors/humiture/sht3x/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.0" +version: "0.2.0" description: I2C driver for SHT3X humiture sensor url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/humiture/sht3x repository: https://github.com/espressif/esp-iot-solution.git @@ -8,5 +8,8 @@ dependencies: i2c_bus: public: true override_path: "../../../i2c_bus" + sensor_hub: + public: true + override_path: "../../sensor_hub" idf: '>=4.4' cmake_utilities: "0.*" diff --git a/components/sensors/humiture/sht3x/include/sht3x.h b/components/sensors/humiture/sht3x/include/sht3x.h index 32e7d6c73..518b4aaae 100644 --- a/components/sensors/humiture/sht3x/include/sht3x.h +++ b/components/sensors/humiture/sht3x/include/sht3x.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -164,59 +164,6 @@ esp_err_t sht3x_set_measure_mode(sht3x_handle_t sensor, sht3x_cmd_measure_t sht3 */ esp_err_t sht3x_heater(sht3x_handle_t sensor, sht3x_cmd_measure_t sht3x_heater_condition); -/***implements of humiture hal interface****/ -#ifdef CONFIG_SENSOR_HUMITURE_INCLUDED_SHT3X - -/** - * @brief initialize sht3x with default configurations - * - * @param i2c_bus i2c bus handle the sensor will attached to - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t humiture_sht3x_init(i2c_bus_handle_t handle); - -/** - * @brief de-initialize sht3x - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t humiture_sht3x_deinit(void); - -/** - * @brief test if sht3x is active - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t humiture_sht3x_test(void); - -/** - * @brief acquire relative humidity result one time. - * - * @param h point to result data (unit:percentage) - * @return esp_err_t - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t humiture_sht3x_acquire_humidity(float *h); - -/** - * @brief acquire temperature result one time. - * - * @param t point to result data (unit:dCelsius) - * @return esp_err_t - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t humiture_sht3x_acquire_temperature(float *t); - -#endif - #ifdef __cplusplus } #endif diff --git a/components/sensors/humiture/sht3x/sht3x.c b/components/sensors/humiture/sht3x/sht3x.c index 9324874f8..49a9fd695 100644 --- a/components/sensors/humiture/sht3x/sht3x.c +++ b/components/sensors/humiture/sht3x/sht3x.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,7 @@ #include "esp_log.h" #include "esp_system.h" #include "esp_timer.h" +#include "iot_sensor_hub.h" #include "sht3x.h" typedef struct { @@ -217,18 +218,18 @@ esp_err_t sht3x_heater(sht3x_handle_t sensor, sht3x_cmd_measure_t sht3x_heater_c return ret; } -#ifdef CONFIG_SENSOR_HUMITURE_INCLUDED_SHT3X +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE static sht3x_handle_t sht3x = NULL; static bool is_init = false; -esp_err_t humiture_sht3x_init(i2c_bus_handle_t i2c_bus) +esp_err_t humiture_sht3x_init(i2c_bus_handle_t i2c_bus, uint8_t addr) { if (is_init || !i2c_bus) { return ESP_FAIL; } - sht3x = sht3x_create(i2c_bus, SHT3x_ADDR_PIN_SELECT_VSS); + sht3x = sht3x_create(i2c_bus, addr); if (!sht3x) { return ESP_FAIL; @@ -283,7 +284,6 @@ esp_err_t humiture_sht3x_acquire_humidity(float *h) *h = humidity; return ESP_OK; } - *h = 0; return ESP_FAIL; } @@ -307,4 +307,14 @@ esp_err_t humiture_sht3x_acquire_temperature(float *t) return ESP_FAIL; } +static humiture_impl_t sht3x_impl = { + .init = humiture_sht3x_init, + .deinit = humiture_sht3x_deinit, + .test = humiture_sht3x_test, + .acquire_humidity = humiture_sht3x_acquire_humidity, + .acquire_temperature = humiture_sht3x_acquire_temperature, +}; + +SENSOR_HUB_DETECT_FN(HUMITURE_ID, sht3x, &sht3x_impl); + #endif diff --git a/components/sensors/imu/lis2dh12/CHANGELOG.md b/components/sensors/imu/lis2dh12/CHANGELOG.md index 4b67a9d74..12c363421 100644 --- a/components/sensors/imu/lis2dh12/CHANGELOG.md +++ b/components/sensors/imu/lis2dh12/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.2.0 - 2024-12-19 + +### Enhancements: + +* Update the method of driver registration to the `sensor_hub` + ## v0.1.0 - 2024-11-5 ### Enhancements: diff --git a/components/sensors/imu/lis2dh12/CMakeLists.txt b/components/sensors/imu/lis2dh12/CMakeLists.txt index f7bb0532a..46720d8c9 100644 --- a/components/sensors/imu/lis2dh12/CMakeLists.txt +++ b/components/sensors/imu/lis2dh12/CMakeLists.txt @@ -1,5 +1,9 @@ idf_component_register(SRCS "lis2dh12.c" INCLUDE_DIRS include) +if(CONFIG_SENSOR_INCLUDED_IMU) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u imu_lis2dh12_init") +endif() + include(package_manager) cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) diff --git a/components/sensors/imu/lis2dh12/idf_component.yml b/components/sensors/imu/lis2dh12/idf_component.yml index b3a9ba951..553ac542e 100644 --- a/components/sensors/imu/lis2dh12/idf_component.yml +++ b/components/sensors/imu/lis2dh12/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.0" +version: "0.2.0" description: I2C driver for LIS2DH12 imu sensor url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/imu/lis2dh12 repository: https://github.com/espressif/esp-iot-solution.git @@ -8,5 +8,8 @@ dependencies: i2c_bus: public: true override_path: "../../../i2c_bus" + sensor_hub: + public: true + override_path: "../../../sensors/sensor_hub" idf: '>=4.4' cmake_utilities: "0.*" diff --git a/components/sensors/imu/lis2dh12/include/lis2dh12.h b/components/sensors/imu/lis2dh12/include/lis2dh12.h index d2edf6ad1..88df39961 100644 --- a/components/sensors/imu/lis2dh12/include/lis2dh12.h +++ b/components/sensors/imu/lis2dh12/include/lis2dh12.h @@ -789,48 +789,6 @@ esp_err_t lis2dh12_get_raw_acce(lis2dh12_handle_t sensor, lis2dh12_raw_acce_valu */ esp_err_t lis2dh12_get_acce(lis2dh12_handle_t sensor, lis2dh12_acce_value_t *acce_value); -/***implements of imu hal interface****/ -#ifdef CONFIG_SENSOR_IMU_INCLUDED_LIS2DH12 - -/** - * @brief initialize lis2dh12 with default configurations - * - * @param i2c_bus i2c bus handle the sensor will attached to - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t imu_lis2dh12_init(i2c_bus_handle_t i2c_bus); - -/** - * @brief - * - * @return esp_err_t - */ -esp_err_t imu_lis2dh12_deinit(void); - -/** - * @brief de-initialize lis2dh12 - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t imu_lis2dh12_test(void); - -/** - * @brief acquire lis2dh12 accelerometer result one time. - * - * @param acce_x result data (unit:g) - * @param acce_y result data (unit:g) - * @param acce_z result data (unit:g) - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t imu_lis2dh12_acquire_acce(float *acce_x, float *acce_y, float *acce_z); -#endif - #ifdef __cplusplus } #endif diff --git a/components/sensors/imu/lis2dh12/lis2dh12.c b/components/sensors/imu/lis2dh12/lis2dh12.c index 418eaabf0..a4b464665 100644 --- a/components/sensors/imu/lis2dh12/lis2dh12.c +++ b/components/sensors/imu/lis2dh12/lis2dh12.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,7 @@ #include #include "lis2dh12.h" #include "esp_log.h" +#include "iot_sensor_hub.h" static const char *TAG = "lis2dh12"; #define IOT_CHECK(tag, a, ret) if(!(a)) { \ @@ -273,18 +274,18 @@ esp_err_t lis2dh12_get_acce(lis2dh12_handle_t sensor, lis2dh12_acce_value_t *acc } /***sensors hal interface****/ -#ifdef CONFIG_SENSOR_IMU_INCLUDED_LIS2DH12 +#ifdef CONFIG_SENSOR_INCLUDED_IMU static lis2dh12_handle_t lis2dh12 = NULL; static bool is_init = false; -esp_err_t imu_lis2dh12_init(i2c_bus_handle_t i2c_bus) +esp_err_t imu_lis2dh12_init(i2c_bus_handle_t i2c_bus, uint8_t addr) { if (is_init || !i2c_bus) { return ESP_FAIL; } - lis2dh12 = lis2dh12_create(i2c_bus, LIS2DH12_I2C_ADDRESS); + lis2dh12 = lis2dh12_create(i2c_bus, addr); if (!lis2dh12) { return ESP_FAIL; @@ -356,4 +357,19 @@ esp_err_t imu_lis2dh12_acquire_acce(float *acce_x, float *acce_y, float *acce_z) return ESP_FAIL; } +static esp_err_t imu_lis2dh12_null_acquire_function(float *x, float *y, float *z) +{ + return ESP_ERR_NOT_SUPPORTED; +} + +static imu_impl_t lis2dh12_impl = { + .init = imu_lis2dh12_init, + .deinit = imu_lis2dh12_deinit, + .test = imu_lis2dh12_test, + .acquire_acce = imu_lis2dh12_acquire_acce, + .acquire_gyro = imu_lis2dh12_null_acquire_function, +}; + +SENSOR_HUB_DETECT_FN(IMU_ID, lis2dh12, &lis2dh12_impl); + #endif diff --git a/components/sensors/light_sensor/veml6040/CHANGELOG.md b/components/sensors/light_sensor/veml6040/CHANGELOG.md index 4b67a9d74..12c363421 100644 --- a/components/sensors/light_sensor/veml6040/CHANGELOG.md +++ b/components/sensors/light_sensor/veml6040/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.2.0 - 2024-12-19 + +### Enhancements: + +* Update the method of driver registration to the `sensor_hub` + ## v0.1.0 - 2024-11-5 ### Enhancements: diff --git a/components/sensors/light_sensor/veml6040/CMakeLists.txt b/components/sensors/light_sensor/veml6040/CMakeLists.txt index 9a1304acd..bfe0d0b9f 100644 --- a/components/sensors/light_sensor/veml6040/CMakeLists.txt +++ b/components/sensors/light_sensor/veml6040/CMakeLists.txt @@ -1,5 +1,9 @@ idf_component_register(SRCS "veml6040.c" INCLUDE_DIRS include) +if(CONFIG_SENSOR_INCLUDED_LIGHT) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u light_sensor_veml6040_init") +endif() + include(package_manager) cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) diff --git a/components/sensors/light_sensor/veml6040/idf_component.yml b/components/sensors/light_sensor/veml6040/idf_component.yml index 306eae30f..8c7a8aa30 100644 --- a/components/sensors/light_sensor/veml6040/idf_component.yml +++ b/components/sensors/light_sensor/veml6040/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.0" +version: "0.2.0" description: I2C driver for VEML6040 light sensor url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/light_sensor/veml6040 repository: https://github.com/espressif/esp-iot-solution.git @@ -8,5 +8,8 @@ dependencies: i2c_bus: public: true override_path: "../../../i2c_bus" + sensor_hub: + public: true + override_path: "../../../sensors/sensor_hub" idf: '>=4.4' cmake_utilities: "0.*" diff --git a/components/sensors/light_sensor/veml6040/include/veml6040.h b/components/sensors/light_sensor/veml6040/include/veml6040.h index 753f5411c..4773c4f25 100644 --- a/components/sensors/light_sensor/veml6040/include/veml6040.h +++ b/components/sensors/light_sensor/veml6040/include/veml6040.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -159,52 +159,6 @@ float veml6040_get_lux(veml6040_handle_t sensor); */ float veml6040_get_cct(veml6040_handle_t sensor, float offset); -/**implements of light sensor hal interface**/ -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6040 -/** - * @brief initialize veml6040 with default configurations - * - * @param i2c_bus i2c bus handle the sensor will attached to - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6040_init(i2c_bus_handle_t handle); - -/** - * @brief de-initialize veml6040 - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6040_deinit(void); - -/** - * @brief test if veml6040 is active - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6040_test(void); - -/** - * @brief Acquire light sensor color result result one time. - * light color includes red green blue and white. - * - * @param r red result (unit:lux) - * @param g green result (unit:lux) - * @param b blue result (unit:lux) - * @param w white result (unit:lux) - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6040_acquire_rgbw(float *r, float *g, float *b, float *w); - -#endif - #ifdef __cplusplus } #endif diff --git a/components/sensors/light_sensor/veml6040/veml6040.c b/components/sensors/light_sensor/veml6040/veml6040.c index 0b9395f3c..8e8a448b4 100644 --- a/components/sensors/light_sensor/veml6040/veml6040.c +++ b/components/sensors/light_sensor/veml6040/veml6040.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #include #include #include "veml6040.h" +#include "iot_sensor_hub.h" //CMD #define VEML6040_SET_CMD 0x00 @@ -173,17 +174,17 @@ float veml6040_get_cct(veml6040_handle_t sensor, float offset) return cct; } -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6040 +#ifdef CONFIG_SENSOR_INCLUDED_LIGHT static veml6040_handle_t veml6040 = NULL; static bool is_init = false; -esp_err_t light_sensor_veml6040_init(i2c_bus_handle_t i2c_bus) +esp_err_t light_sensor_veml6040_init(i2c_bus_handle_t i2c_bus, uint8_t addr) { if (is_init || !i2c_bus) { return ESP_FAIL; } - veml6040 = veml6040_create(i2c_bus, VEML6040_I2C_ADDRESS); + veml6040 = veml6040_create(i2c_bus, addr); if (!veml6040) { return ESP_FAIL; } @@ -236,4 +237,25 @@ esp_err_t light_sensor_veml6040_acquire_rgbw(float *r, float *g, float *b, float return ESP_OK; } +static esp_err_t light_sensor_veml6040_null_acquire_light_function(float* l) +{ + return ESP_ERR_NOT_SUPPORTED; +} + +static esp_err_t light_sensor_veml6040_null_acquire_uv_function(float* uv, float* uva, float* uvb) +{ + return ESP_ERR_NOT_SUPPORTED; +} + +static light_impl_t veml6040_impl = { + .init = light_sensor_veml6040_init, + .deinit = light_sensor_veml6040_deinit, + .test = light_sensor_veml6040_test, + .acquire_light = light_sensor_veml6040_null_acquire_light_function, + .acquire_rgbw = light_sensor_veml6040_acquire_rgbw, + .acquire_uv = light_sensor_veml6040_null_acquire_uv_function, +}; + +SENSOR_HUB_DETECT_FN(LIGHT_SENSOR_ID, veml6040, &veml6040_impl); + #endif diff --git a/components/sensors/light_sensor/veml6075/CHANGELOG.md b/components/sensors/light_sensor/veml6075/CHANGELOG.md index 4b67a9d74..12c363421 100644 --- a/components/sensors/light_sensor/veml6075/CHANGELOG.md +++ b/components/sensors/light_sensor/veml6075/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.2.0 - 2024-12-19 + +### Enhancements: + +* Update the method of driver registration to the `sensor_hub` + ## v0.1.0 - 2024-11-5 ### Enhancements: diff --git a/components/sensors/light_sensor/veml6075/CMakeLists.txt b/components/sensors/light_sensor/veml6075/CMakeLists.txt index 952a0cd23..85cebe8c1 100644 --- a/components/sensors/light_sensor/veml6075/CMakeLists.txt +++ b/components/sensors/light_sensor/veml6075/CMakeLists.txt @@ -1,5 +1,9 @@ idf_component_register(SRCS "veml6075.c" INCLUDE_DIRS include) +if(CONFIG_SENSOR_INCLUDED_LIGHT) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u light_sensor_veml6075_init") +endif() + include(package_manager) cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) diff --git a/components/sensors/light_sensor/veml6075/idf_component.yml b/components/sensors/light_sensor/veml6075/idf_component.yml index 43ce15c08..c99d4aff8 100644 --- a/components/sensors/light_sensor/veml6075/idf_component.yml +++ b/components/sensors/light_sensor/veml6075/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.0" +version: "0.2.0" description: I2C driver for VEML6075 light sensor url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/light_sensor/veml6040 repository: https://github.com/espressif/esp-iot-solution.git @@ -8,5 +8,8 @@ dependencies: i2c_bus: public: true override_path: "../../../i2c_bus" + sensor_hub: + public: true + override_path: "../../../sensors/sensor_hub" idf: '>=4.3' cmake_utilities: "0.*" diff --git a/components/sensors/light_sensor/veml6075/include/veml6075.h b/components/sensors/light_sensor/veml6075/include/veml6075.h index 1a715abcc..0d428fd23 100644 --- a/components/sensors/light_sensor/veml6075/include/veml6075.h +++ b/components/sensors/light_sensor/veml6075/include/veml6075.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -224,51 +224,6 @@ uint16_t veml6075_get_raw_vis(veml6075_handle_t sensor); */ uint16_t veml6075_get_raw_ir(veml6075_handle_t sensor); -/**implements of light sensor hal interface**/ -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6075 -/** - * @brief initialize veml6040 with default configurations - * - * @param i2c_bus i2c bus handle the sensor will attached to - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6075_init(i2c_bus_handle_t handle); - -/** - * @brief de-initialize veml6040 - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6075_deinit(void); - -/** - * @brief test if veml6040 is active - * - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6075_test(void); - -/** - * @brief Acquire light sensor ultra violet result one time. - * light Ultraviolet includes UVA UVB and UV - * - * @param uv Ultraviolet result (unit:lux) - * @param uva Ultraviolet A data (unit:lux) - * @param uvb Ultraviolet B data (unit:lux) - * @return - * - ESP_OK Success - * - ESP_FAIL Fail - */ -esp_err_t light_sensor_veml6075_acquire_uv(float* uv, float* uva, float* uvb); - -#endif - #ifdef __cplusplus } #endif diff --git a/components/sensors/light_sensor/veml6075/veml6075.c b/components/sensors/light_sensor/veml6075/veml6075.c index 538085107..8115d76ea 100644 --- a/components/sensors/light_sensor/veml6075/veml6075.c +++ b/components/sensors/light_sensor/veml6075/veml6075.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #include #include #include "veml6075.h" +#include "iot_sensor_hub.h" veml6075_handle_t veml6075_create(i2c_bus_handle_t bus, uint8_t dev_addr) { @@ -191,17 +192,17 @@ uint16_t veml6075_get_raw_ir(veml6075_handle_t sensor) return sens->raw_data.raw_ir; } -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6075 +#ifdef CONFIG_SENSOR_INCLUDED_LIGHT static veml6075_handle_t veml6075 = NULL; static bool is_init = false; -esp_err_t light_sensor_veml6075_init(i2c_bus_handle_t i2c_bus) +esp_err_t light_sensor_veml6075_init(i2c_bus_handle_t i2c_bus, uint8_t addr) { if (is_init || !i2c_bus) { return ESP_FAIL; } - veml6075 = veml6075_create(i2c_bus, VEML6075_I2C_ADDRESS); + veml6075 = veml6075_create(i2c_bus, addr); if (!veml6075) { return ESP_FAIL; } @@ -251,4 +252,25 @@ esp_err_t light_sensor_veml6075_acquire_uv(float *uv, float *uva, float *uvb) return ESP_OK; } +static esp_err_t light_sensor_veml6075_null_acquire_light_function(float* l) +{ + return ESP_ERR_NOT_SUPPORTED; +} + +static esp_err_t light_sensor_veml6075_null_acquire_rgbw_function(float* r, float* g, float* b, float* w) +{ + return ESP_ERR_NOT_SUPPORTED; +} + +static light_impl_t veml6075_impl = { + .init = light_sensor_veml6075_init, + .deinit = light_sensor_veml6075_deinit, + .test = light_sensor_veml6075_test, + .acquire_light = light_sensor_veml6075_null_acquire_light_function, + .acquire_rgbw = light_sensor_veml6075_null_acquire_rgbw_function, + .acquire_uv = light_sensor_veml6075_acquire_uv, +}; + +SENSOR_HUB_DETECT_FN(LIGHT_SENSOR_ID, veml6075, &veml6075_impl); + #endif diff --git a/components/sensors/sensor_hub/CHANGELOG.md b/components/sensors/sensor_hub/CHANGELOG.md new file mode 100644 index 000000000..56dfe2d6c --- /dev/null +++ b/components/sensors/sensor_hub/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## v0.1.0 - 2024-12-6 + +First release version + +### Enhancements: + +- Support user to register sensor driver into `sensor_hub` as a component \ No newline at end of file diff --git a/components/sensors/sensor_hub/CMakeLists.txt b/components/sensors/sensor_hub/CMakeLists.txt index b232d65ff..8d73b9f99 100644 --- a/components/sensors/sensor_hub/CMakeLists.txt +++ b/components/sensors/sensor_hub/CMakeLists.txt @@ -1,12 +1,4 @@ -#common requires -set(requires i2c_bus) -#imu sensor requires -list(APPEND requires mpu6050 lis2dh12) -#humiture sensor requires -list(APPEND requires sht3x hts221) -#light sensor requires -list(APPEND requires bh1750 veml6040 veml6075) - idf_component_register(SRC_DIRS "." "hal" INCLUDE_DIRS "include" - REQUIRES "${requires}" "esp_timer") + REQUIRES "esp_event" "esp_timer" "driver" + LDFRAGMENTS linker.lf) diff --git a/components/sensors/sensor_hub/Kconfig.projbuild b/components/sensors/sensor_hub/Kconfig.projbuild index 1cea9ebe8..7323bc48a 100644 --- a/components/sensors/sensor_hub/Kconfig.projbuild +++ b/components/sensors/sensor_hub/Kconfig.projbuild @@ -1,35 +1,5 @@ menu "Sensor Hub Options" - menu "Sensor Hal Options" - menu "IMU Hal Options" - config SENSOR_IMU_INCLUDED_MPU6050 - bool "include MPU6050 driver" - default y - config SENSOR_IMU_INCLUDED_LIS2DH12 - bool "include LIS2DH12 driver" - default y - endmenu - menu "Humiture Hal Options" - config SENSOR_HUMITURE_INCLUDED_SHT3X - bool "include SHT3X driver" - default y - config SENSOR_HUMITURE_INCLUDED_HTS221 - bool "include HTS221 driver" - default y - endmenu - menu "Light Sensor Hal Options" - config SENSOR_LIGHT_INCLUDED_BH1750 - bool "include BH1750 driver" - default y - config SENSOR_LIGHT_INCLUDED_VEML6040 - bool "include VEML6040 driver" - default y - config SENSOR_LIGHT_INCLUDED_VEML6075 - bool "include VEML6075 driver" - default y - endmenu - endmenu - menu "Sensor Build Options" config SENSOR_INCLUDED_IMU bool "include imu sensor driver in sensor hub" diff --git a/components/sensors/sensor_hub/README.md b/components/sensors/sensor_hub/README.md new file mode 100644 index 000000000..373605302 --- /dev/null +++ b/components/sensors/sensor_hub/README.md @@ -0,0 +1,64 @@ +# SENSOR HUB + +`Sensor hub` is a sensor management component that can realize hardware abstraction, device management and data distribution for sensor devices. From the point of application development, this component has the following features: + +1. Support for registering sensor drivers through component approach, enabling users to focus on usage without concerning themselves with the implementation of the driver layer. +2. Provides a unified sensor management and message notification mechanism, allowing users to simply select sensor operation modes, sampling intervals, ranges, etc., and register callback functions for events of interest. This ensures users are notified when the sensor state changes or data collection is complete. + +`Sensor hub` can be used as a basic component for sensor applications in various intelligent scenarios such as environment monitoring, motion detection, health management and etc. as it simplifies operation and improves operating efficiency by centralized management of sensors. + + +## How to register sensor_hub in other sensor drivers + +To enable the ``sensor_hub`` to locate the sensor component, please refer to the following procedure: + +1. Add a dependency on `sensor_hub` in the `idf_component.yml` file of the sensor driver. +2. Implement specific functions based on the sensor type and register them in the `sensor_hub`. + +```c +static imu_impl_t virtual_mpu6050_impl = { + .name = "virtual_mpu6050", + .sensor_type = IMU_ID, + .init = virtual_imu_init, + .deinit = virtual_imu_deinit, + .test = virtual_imu_test, + .acquire_acce = virtual_imu_acquire_acce, + .acquire_gyro = virtual_imu_acquire_gyro, + .sleep = virtual_imu_null_function, + .wakeup = virtual_imu_null_function, +}; + +void *virtual_mpu6050_detect(sensor_info_t *sensor_info) +{ + sensor_info->snesor_type = IMU_ID; + sensor_info->name = virtual_mpu6050_impl.name; + return (void*)&virtual_mpu6050_impl; +} + +ESP_SENSOR_DETECT_FN(virtual_mpu6050_detect) +{ + return virtual_mpu6050_detect(sensor_info); +} +``` + +3. Modify the CMakeLists of the sensor driver to link the sensor registration function. + +```cmake +target_link_libraries(${COMPONENT_LIB} INTERFACE "-u virtual_mpu6050_detect") +``` + +The `test_apps` of `sensor_hub` provide examples of virtual sensor registration, which you can refer to when registering your own sensor. + +## Add component to your project + +Please use the component manager command `add-dependency` to add the `sensor_hub` to your project's dependency, during the `CMake` step the component will be downloaded automatically + +``` +idf.py add-dependency "espressif/sensor_hub=*" +``` + +Alternatively, you can create `idf_component.yml`. More is in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html). + +## How to use + +[sensor_hub user guide](https://docs.espressif.com/projects/esp-iot-solution/en/latest/sensors/sensor_hub.html) diff --git a/components/sensors/sensor_hub/hal/humiture_hal.c b/components/sensors/sensor_hub/hal/humiture_hal.c index 193fb6a8a..038914cdb 100644 --- a/components/sensors/sensor_hub/hal/humiture_hal.c +++ b/components/sensors/sensor_hub/hal/humiture_hal.c @@ -1,39 +1,20 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "esp_log.h" #include "esp_timer.h" #include "hal/humiture_hal.h" +#include "iot_sensor_hub.h" -#ifdef CONFIG_SENSOR_HUMITURE_INCLUDED_SHT3X -#include "sht3x.h" -#endif -#ifdef CONFIG_SENSOR_HUMITURE_INCLUDED_HTS221 -#include "hts221.h" -#endif - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -static esp_err_t null_function(void) -{ - return ESP_ERR_NOT_SUPPORTED; -} -static esp_err_t null_acquire_humidity_function(float *h) -{ - return ESP_ERR_NOT_SUPPORTED; -} -static esp_err_t null_acquire_temperature_function(float *t) -{ - return ESP_ERR_NOT_SUPPORTED; -} -#pragma GCC diagnostic pop +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE static const char *TAG = "HUMITURE|TEMPERATURE"; @@ -43,94 +24,44 @@ static const char *TAG = "HUMITURE|TEMPERATURE"; } typedef struct { - humiture_id_t id; - esp_err_t (*init)(bus_handle_t); - esp_err_t (*deinit)(void); - esp_err_t (*test)(void); - esp_err_t (*acquire_humidity)(float *); - esp_err_t (*acquire_temperature)(float *); - esp_err_t (*sleep)(void); - esp_err_t (*wakeup)(void); -} humiture_impl_t; - -typedef struct { - humiture_id_t id; bus_handle_t bus; bool is_init; const humiture_impl_t *impl; } sensor_humiture_t; -static const humiture_impl_t humiture_implementations[] = { -#ifdef CONFIG_SENSOR_HUMITURE_INCLUDED_SHT3X - { - .id = SHT3X_ID, - .init = humiture_sht3x_init, - .deinit = humiture_sht3x_deinit, - .test = humiture_sht3x_test, - .acquire_humidity = humiture_sht3x_acquire_humidity, - .acquire_temperature = humiture_sht3x_acquire_temperature, - .sleep = null_function, - .wakeup = null_function, - }, -#endif -#ifdef CONFIG_SENSOR_HUMITURE_INCLUDED_HTS221 - { - .id = HTS221_ID, - .init = humiture_hts221_init, - .deinit = humiture_hts221_deinit, - .test = humiture_hts221_test, - .acquire_humidity = humiture_hts221_acquire_humidity, - .acquire_temperature = humiture_hts221_acquire_temperature, - .sleep = humiture_hts221_sleep, - .wakeup = humiture_hts221_wakeup, - }, -#endif -}; - -/****************************private functions*************************************/ - -static const humiture_impl_t *find_implementation(int id) -{ - const humiture_impl_t *active_driver = NULL; - int count = sizeof(humiture_implementations) / sizeof(humiture_impl_t); - - for (int i = 0; i < count; i++) { - if (humiture_implementations[i].id == id) { - active_driver = &humiture_implementations[i]; - break; - } - } - - return active_driver; -} - /****************************public functions*************************************/ -sensor_humiture_handle_t humiture_create(bus_handle_t bus, int id) +sensor_humiture_handle_t humiture_create(bus_handle_t bus, const char *sensor_name, uint8_t addr) { SENSOR_CHECK(bus != NULL, "i2c bus has not initialized", NULL); - const humiture_impl_t *sensor_impl = find_implementation(id); - - if (sensor_impl == NULL) { - ESP_LOGE(TAG, "no driver founded, HUMITURE ID = %d", id); + if (sensor_name == NULL || addr == 0) { + ESP_LOGE(TAG, "Incorrect Sensor Information"); return NULL; } - sensor_humiture_t *p_sensor = (sensor_humiture_t *)malloc(sizeof(sensor_humiture_t)); - SENSOR_CHECK(p_sensor != NULL, "humiture sensor creat failed", NULL); - p_sensor->id = id; - p_sensor->bus = bus; - p_sensor->impl = sensor_impl; - esp_err_t ret = p_sensor->impl->init(bus); - - if (ret != ESP_OK) { - free(p_sensor); - ESP_LOGE(TAG, "humiture sensor init failed"); - return NULL; + // search the sensor driver from a specific segment + for (sensor_hub_detect_fn_t *p = &__sensor_hub_detect_fn_array_start; p < &__sensor_hub_detect_fn_array_end; ++p) { + sensor_info_t info; + sensor_device_impl_t sensor_device_impl = (*(p->fn))(&info); + + if (sensor_device_impl != NULL && strcmp(sensor_name, info.name) == 0) { + sensor_humiture_t *p_sensor = (sensor_humiture_t *)malloc(sizeof(sensor_humiture_t)); + SENSOR_CHECK(p_sensor != NULL, "humiture sensor creat failed", NULL); + p_sensor->bus = bus; + p_sensor->impl = (humiture_impl_t *)(sensor_device_impl); + + esp_err_t ret = p_sensor->impl->init(bus, addr); + if (ret != ESP_OK) { + free(p_sensor); + ESP_LOGE(TAG, "humiture sensor init failed"); + return NULL; + } + p_sensor->is_init = true; + return (sensor_humiture_handle_t)p_sensor; + } } - p_sensor->is_init = true; - return (sensor_humiture_handle_t)p_sensor; + return NULL; } esp_err_t humiture_delete(sensor_humiture_handle_t *sensor) @@ -160,6 +91,10 @@ esp_err_t humiture_test(sensor_humiture_handle_t sensor) return ESP_FAIL; } + if (p_sensor->impl->test == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + esp_err_t ret = p_sensor->impl->test(); return ret; } @@ -203,9 +138,15 @@ static esp_err_t humiture_set_power(sensor_humiture_handle_t sensor, sensor_powe esp_err_t ret; switch (power_mode) { case POWER_MODE_WAKEUP: + if (p_sensor->impl->wakeup == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } ret = p_sensor->impl->wakeup(); break; case POWER_MODE_SLEEP: + if (p_sensor->impl->sleep == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } ret = p_sensor->impl->sleep(); break; default: @@ -235,16 +176,38 @@ esp_err_t humiture_acquire(sensor_humiture_handle_t sensor, sensor_data_group_t return ESP_OK; } +esp_err_t humiture_set_work_mode(sensor_humiture_handle_t sensor, sensor_mode_t work_mode) +{ + SENSOR_CHECK(sensor != NULL, "pointer can't be NULL ", ESP_ERR_INVALID_ARG); + sensor_humiture_t *p_sensor = (sensor_humiture_t *)(sensor); + + if (p_sensor->impl->set_mode == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + return p_sensor->impl->set_mode(work_mode); +} + +esp_err_t humiture_set_range(sensor_humiture_handle_t sensor, sensor_range_t range) +{ + SENSOR_CHECK(sensor != NULL, "pointer can't be NULL ", ESP_ERR_INVALID_ARG); + sensor_humiture_t *p_sensor = (sensor_humiture_t *)(sensor); + + if (p_sensor->impl->set_range == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + return p_sensor->impl->set_range(range); +} + esp_err_t humiture_control(sensor_humiture_handle_t sensor, sensor_command_t cmd, void *args) { SENSOR_CHECK(sensor != NULL, "sensor handle can't be NULL ", ESP_ERR_INVALID_ARG); esp_err_t ret; switch (cmd) { case COMMAND_SET_MODE: - ret = ESP_ERR_NOT_SUPPORTED; + ret = humiture_set_work_mode(sensor, (sensor_mode_t)args); break; case COMMAND_SET_RANGE: - ret = ESP_ERR_NOT_SUPPORTED; + ret = humiture_set_range(sensor, (sensor_range_t)args); break; case COMMAND_SET_ODR: ret = ESP_ERR_NOT_SUPPORTED; @@ -261,3 +224,4 @@ esp_err_t humiture_control(sensor_humiture_handle_t sensor, sensor_command_t cmd } return ret; } +#endif diff --git a/components/sensors/sensor_hub/hal/imu_hal.c b/components/sensors/sensor_hub/hal/imu_hal.c index 64e5c8e50..4a16c3d36 100644 --- a/components/sensors/sensor_hub/hal/imu_hal.c +++ b/components/sensors/sensor_hub/hal/imu_hal.c @@ -1,35 +1,20 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "esp_log.h" #include "esp_timer.h" #include "hal/imu_hal.h" +#include "iot_sensor_hub.h" -#ifdef CONFIG_SENSOR_IMU_INCLUDED_MPU6050 -#include "mpu6050.h" -#endif -#ifdef CONFIG_SENSOR_IMU_INCLUDED_LIS2DH12 -#include "lis2dh12.h" -#endif - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -static esp_err_t null_function(void) -{ - return ESP_ERR_NOT_SUPPORTED; -} -static esp_err_t null_acquire_function(float *x, float *y, float *z) -{ - return ESP_ERR_NOT_SUPPORTED; -} -#pragma GCC diagnostic pop +#ifdef CONFIG_SENSOR_INCLUDED_IMU static const char *TAG = "IMU"; @@ -39,94 +24,43 @@ static const char *TAG = "IMU"; } typedef struct { - imu_id_t id; - esp_err_t (*init)(bus_handle_t); - esp_err_t (*deinit)(void); - esp_err_t (*test)(void); - esp_err_t (*acquire_acce)(float *acce_x, float *acce_y, float *acce_z); - esp_err_t (*acquire_gyro)(float *gyro_x, float *gyro_y, float *gyro_z); - esp_err_t (*sleep)(void); - esp_err_t (*wakeup)(void); -} imu_impl_t; - -typedef struct { - imu_id_t id; bus_handle_t bus; bool is_init; const imu_impl_t *impl; } sensor_imu_t; -static const imu_impl_t imu_implementations[] = { -#ifdef CONFIG_SENSOR_IMU_INCLUDED_MPU6050 - { - .id = MPU6050_ID, - .init = imu_mpu6050_init, - .deinit = imu_mpu6050_deinit, - .test = imu_mpu6050_test, - .acquire_acce = imu_mpu6050_acquire_acce, - .acquire_gyro = imu_mpu6050_acquire_gyro, - .sleep = imu_mpu6050_sleep, - .wakeup = imu_mpu6050_wakeup, - }, -#endif -#ifdef CONFIG_SENSOR_IMU_INCLUDED_LIS2DH12 - { - .id = LIS2DH12_ID, - .init = imu_lis2dh12_init, - .deinit = imu_lis2dh12_deinit, - .test = imu_lis2dh12_test, - .acquire_acce = imu_lis2dh12_acquire_acce, - .acquire_gyro = null_acquire_function, - .sleep = null_function, - .wakeup = null_function, - }, -#endif -}; - -/****************************private functions*************************************/ - -static const imu_impl_t *find_implementation(imu_id_t id) -{ - const imu_impl_t *active_driver = NULL; - int count = sizeof(imu_implementations) / sizeof(imu_impl_t); - - for (int i = 0; i < count; i++) { - if (imu_implementations[i].id == id) { - active_driver = &imu_implementations[i]; - break; - } - } - - return active_driver; -} - /****************************public functions*************************************/ -sensor_imu_handle_t imu_create(bus_handle_t bus, int imu_id) +sensor_imu_handle_t imu_create(bus_handle_t bus, const char *sensor_name, uint8_t addr) { SENSOR_CHECK(bus != NULL, "i2c bus has not initialized", NULL); - const imu_impl_t *sensor_impl = find_implementation(imu_id); - - if (sensor_impl == NULL) { - ESP_LOGE(TAG, "no driver founded, IMU ID = %d", imu_id); + if (sensor_name == NULL || addr == 0) { + ESP_LOGE(TAG, "Incorrect Sensor Information"); return NULL; } - sensor_imu_t *p_sensor = (sensor_imu_t *)malloc(sizeof(sensor_imu_t)); - SENSOR_CHECK(p_sensor != NULL, "imu sensor creat failed", NULL); - p_sensor->id = imu_id; - p_sensor->bus = bus; - p_sensor->impl = sensor_impl; - esp_err_t ret = p_sensor->impl->init(bus); - - if (ret != ESP_OK) { - free(p_sensor); - ESP_LOGE(TAG, "imu sensor init failed"); - return NULL; + for (sensor_hub_detect_fn_t *p = &__sensor_hub_detect_fn_array_start; p < &__sensor_hub_detect_fn_array_end; ++p) { + sensor_info_t info; + sensor_device_impl_t sensor_device_impl = (*(p->fn))(&info); + + if (sensor_device_impl != NULL && strcmp(sensor_name, info.name) == 0) { + sensor_imu_t *p_sensor = (sensor_imu_t *)malloc(sizeof(sensor_imu_t)); + SENSOR_CHECK(p_sensor != NULL, "imu sensor creat failed", NULL); + p_sensor->bus = bus; + p_sensor->impl = (imu_impl_t *)(sensor_device_impl); + + esp_err_t ret = p_sensor->impl->init(bus, addr); + if (ret != ESP_OK) { + free(p_sensor); + ESP_LOGE(TAG, "imu sensor init failed"); + return NULL; + } + p_sensor->is_init = true; + return (sensor_imu_handle_t)p_sensor; + } } - p_sensor->is_init = true; - return (sensor_imu_handle_t)p_sensor; + return NULL; } esp_err_t imu_delete(sensor_imu_handle_t *sensor) @@ -156,6 +90,10 @@ esp_err_t imu_test(sensor_imu_handle_t sensor) return ESP_FAIL; } + if (p_sensor->impl->test == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + esp_err_t ret = p_sensor->impl->test(); return ret; } @@ -199,9 +137,15 @@ static esp_err_t imu_set_power(sensor_imu_handle_t sensor, sensor_power_mode_t p esp_err_t ret; switch (power_mode) { case POWER_MODE_WAKEUP: + if (p_sensor->impl->wakeup == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } ret = p_sensor->impl->wakeup(); break; case POWER_MODE_SLEEP: + if (p_sensor->impl->sleep == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } ret = p_sensor->impl->sleep(); break; default: @@ -231,16 +175,38 @@ esp_err_t imu_acquire(sensor_imu_handle_t sensor, sensor_data_group_t *data_grou return ESP_OK; } +esp_err_t imu_set_work_mode(sensor_imu_handle_t sensor, sensor_mode_t work_mode) +{ + SENSOR_CHECK(sensor != NULL, "pointer can't be NULL ", ESP_ERR_INVALID_ARG); + sensor_imu_t *p_sensor = (sensor_imu_t *)(sensor); + + if (p_sensor->impl->set_mode == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + return p_sensor->impl->set_mode(work_mode); +} + +esp_err_t imu_set_range(sensor_imu_handle_t sensor, sensor_range_t range) +{ + SENSOR_CHECK(sensor != NULL, "pointer can't be NULL ", ESP_ERR_INVALID_ARG); + sensor_imu_t *p_sensor = (sensor_imu_t *)(sensor); + + if (p_sensor->impl->set_range == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + return p_sensor->impl->set_range(range); +} + esp_err_t imu_control(sensor_imu_handle_t sensor, sensor_command_t cmd, void *args) { SENSOR_CHECK(sensor != NULL, "sensor handle can't be NULL ", ESP_ERR_INVALID_ARG); esp_err_t ret; switch (cmd) { case COMMAND_SET_MODE: - ret = ESP_ERR_NOT_SUPPORTED; + ret = imu_set_work_mode(sensor, (sensor_mode_t)args); break; case COMMAND_SET_RANGE: - ret = ESP_ERR_NOT_SUPPORTED; + ret = imu_set_range(sensor, (sensor_range_t)args); break; case COMMAND_SET_ODR: ret = ESP_ERR_NOT_SUPPORTED; @@ -257,3 +223,4 @@ esp_err_t imu_control(sensor_imu_handle_t sensor, sensor_command_t cmd, void *ar } return ret; } +#endif diff --git a/components/sensors/sensor_hub/hal/light_sensor_hal.c b/components/sensors/sensor_hub/hal/light_sensor_hal.c index 561466234..8763fca89 100644 --- a/components/sensors/sensor_hub/hal/light_sensor_hal.c +++ b/components/sensors/sensor_hub/hal/light_sensor_hal.c @@ -1,46 +1,20 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "esp_log.h" #include "esp_timer.h" #include "hal/light_sensor_hal.h" +#include "iot_sensor_hub.h" -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_BH1750 -#include "bh1750.h" -#endif -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6040 -#include "veml6040.h" -#endif -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6075 -#include "veml6075.h" -#endif - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -static esp_err_t null_function(void) -{ - return ESP_ERR_NOT_SUPPORTED; -} -static esp_err_t null_acquire_light_function(float* l) -{ - return ESP_ERR_NOT_SUPPORTED; -} -static esp_err_t null_acquire_rgbw_function(float* r, float* g, float* b, float* w) -{ - return ESP_ERR_NOT_SUPPORTED; -} -static esp_err_t null_acquire_uv_function(float* uv, float* uva, float* uvb) -{ - return ESP_ERR_NOT_SUPPORTED; -} -#pragma GCC diagnostic pop +#ifdef CONFIG_SENSOR_INCLUDED_LIGHT static const char* TAG = "LIGHT|RGBW|UV"; @@ -50,106 +24,44 @@ static const char* TAG = "LIGHT|RGBW|UV"; } typedef struct { - light_sensor_id_t id; - esp_err_t (*init)(bus_handle_t); - esp_err_t (*deinit)(void); - esp_err_t (*test)(void); - esp_err_t (*acquire_light)(float* l); - esp_err_t (*acquire_rgbw)(float* r, float* g, float* b, float* w); - esp_err_t (*acquire_uv)(float* uv, float* uva, float* uvb); - esp_err_t (*sleep)(void); - esp_err_t (*wakeup)(void); -} light_sensor_impl_t; - -typedef struct { - light_sensor_id_t id; bus_handle_t bus; bool is_init; - const light_sensor_impl_t* impl; + const light_impl_t* impl; } sensor_light_t; -static const light_sensor_impl_t light_sensor_implementations[] = { -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_BH1750 - { - .id = BH1750_ID, - .init = light_sensor_bh1750_init, - .deinit = light_sensor_bh1750_deinit, - .test = light_sensor_bh1750_test, - .acquire_light = light_sensor_bh1750_acquire_light, - .acquire_rgbw = null_acquire_rgbw_function, - .acquire_uv = null_acquire_uv_function, - .sleep = null_function, - .wakeup = null_function, - }, -#endif -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6040 - { - .id = VEML6040_ID, - .init = light_sensor_veml6040_init, - .deinit = light_sensor_veml6040_deinit, - .test = light_sensor_veml6040_test, - .acquire_light = null_acquire_light_function, - .acquire_rgbw = light_sensor_veml6040_acquire_rgbw, - .acquire_uv = null_acquire_uv_function, - .sleep = null_function, - .wakeup = null_function, - }, -#endif -#ifdef CONFIG_SENSOR_LIGHT_INCLUDED_VEML6075 - { - .id = VEML6075_ID, - .init = light_sensor_veml6075_init, - .deinit = light_sensor_veml6075_deinit, - .test = light_sensor_veml6075_test, - .acquire_light = null_acquire_light_function, - .acquire_rgbw = null_acquire_rgbw_function, - .acquire_uv = light_sensor_veml6075_acquire_uv, - .sleep = null_function, - .wakeup = null_function, - }, -#endif -}; - -/****************************private functions*************************************/ - -static const light_sensor_impl_t* find_implementation(int id) -{ - const light_sensor_impl_t* active_driver = NULL; - int count = sizeof(light_sensor_implementations) / sizeof(light_sensor_impl_t); - for (int i = 0; i < count; i++) { - if (light_sensor_implementations[i].id == id) { - active_driver = &light_sensor_implementations[i]; - break; - } - } - return active_driver; -} - /****************************public functions*************************************/ -sensor_light_handle_t light_sensor_create(bus_handle_t bus, int id) +sensor_light_handle_t light_sensor_create(bus_handle_t bus, const char *sensor_name, uint8_t addr) { SENSOR_CHECK(bus != NULL, "i2c bus has not initialized", NULL); - const light_sensor_impl_t *sensor_impl = find_implementation(id); - - if (sensor_impl == NULL) { - ESP_LOGE(TAG, "no driver founded, LIGHT ID = %d", id); + if (sensor_name == NULL || addr == 0) { + ESP_LOGE(TAG, "Incorrect Sensor Information"); return NULL; } - sensor_light_t* p_sensor = (sensor_light_t*)malloc(sizeof(sensor_light_t)); - SENSOR_CHECK(p_sensor != NULL, "light sensor creat failed", NULL); - p_sensor->id = id; - p_sensor->bus = bus; - p_sensor->impl = sensor_impl; - esp_err_t ret = p_sensor->impl->init(bus); - if (ret != ESP_OK) { - free(p_sensor); - ESP_LOGE(TAG, "light sensor init failed"); - return NULL; + // search the sensor driver from a specific segment + for (sensor_hub_detect_fn_t *p = &__sensor_hub_detect_fn_array_start; p < &__sensor_hub_detect_fn_array_end; ++p) { + sensor_info_t info; + sensor_device_impl_t sensor_device_impl = (*(p->fn))(&info); + + if (sensor_device_impl != NULL && strcmp(sensor_name, info.name) == 0) { + sensor_light_t* p_sensor = (sensor_light_t*)malloc(sizeof(sensor_light_t)); + SENSOR_CHECK(p_sensor != NULL, "light sensor creat failed", NULL); + p_sensor->bus = bus; + p_sensor->impl = (light_impl_t *)(sensor_device_impl); + + esp_err_t ret = p_sensor->impl->init(bus, addr); + if (ret != ESP_OK) { + free(p_sensor); + ESP_LOGE(TAG, "light sensor init failed"); + return NULL; + } + p_sensor->is_init = true; + return (sensor_light_handle_t)p_sensor; + } } - p_sensor->is_init = true; - return (sensor_light_handle_t)p_sensor; + + return NULL; } esp_err_t light_sensor_delete(sensor_light_handle_t *sensor) @@ -177,6 +89,11 @@ esp_err_t light_sensor_test(sensor_light_handle_t sensor) if (!p_sensor->is_init) { return ESP_FAIL; } + + if (p_sensor->impl->test == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + esp_err_t ret = p_sensor->impl->test(); return ret; } @@ -228,9 +145,15 @@ static esp_err_t light_sensor_set_power(sensor_light_handle_t sensor, sensor_pow esp_err_t ret; switch (power_mode) { case POWER_MODE_WAKEUP: + if (p_sensor->impl->wakeup == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } ret = p_sensor->impl->wakeup(); break; case POWER_MODE_SLEEP: + if (p_sensor->impl->sleep == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } ret = p_sensor->impl->sleep(); break; default: @@ -267,16 +190,38 @@ esp_err_t light_sensor_acquire(sensor_light_handle_t sensor, sensor_data_group_t return ESP_OK; } +esp_err_t light_sensor_set_work_mode(sensor_light_handle_t sensor, sensor_mode_t work_mode) +{ + SENSOR_CHECK(sensor != NULL, "pointer can't be NULL ", ESP_ERR_INVALID_ARG); + sensor_light_t *p_sensor = (sensor_light_t *)(sensor); + + if (p_sensor->impl->set_mode == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + return p_sensor->impl->set_mode(work_mode); +} + +esp_err_t light_sensor_set_range(sensor_light_handle_t sensor, sensor_range_t range) +{ + SENSOR_CHECK(sensor != NULL, "pointer can't be NULL ", ESP_ERR_INVALID_ARG); + sensor_light_t *p_sensor = (sensor_light_t *)(sensor); + + if (p_sensor->impl->set_range == NULL) { + return ESP_ERR_NOT_SUPPORTED; + } + return p_sensor->impl->set_range(range); +} + esp_err_t light_sensor_control(sensor_light_handle_t sensor, sensor_command_t cmd, void *args) { SENSOR_CHECK(sensor != NULL, "sensor handle can't be NULL ", ESP_ERR_INVALID_ARG); esp_err_t ret; switch (cmd) { case COMMAND_SET_MODE: - ret = ESP_ERR_NOT_SUPPORTED; + ret = light_sensor_set_work_mode(sensor, (sensor_mode_t)args); break; case COMMAND_SET_RANGE: - ret = ESP_ERR_NOT_SUPPORTED; + ret = light_sensor_set_range(sensor, (sensor_range_t)args); break; case COMMAND_SET_ODR: ret = ESP_ERR_NOT_SUPPORTED; @@ -293,3 +238,4 @@ esp_err_t light_sensor_control(sensor_light_handle_t sensor, sensor_command_t cm } return ret; } +#endif diff --git a/components/sensors/sensor_hub/idf_component.yml b/components/sensors/sensor_hub/idf_component.yml new file mode 100644 index 000000000..72c3997ca --- /dev/null +++ b/components/sensors/sensor_hub/idf_component.yml @@ -0,0 +1,12 @@ +version: "0.1.0" +description: Unified Framework for Sensor Management +dependencies: + i2c_bus: + public: true + version: "1.*" + override_path: "../../i2c_bus" + idf: ">=4.4" + cmake_utilities: "0.*" +sbom: + supplier: 'Organization: Espressif Systems (Shanghai) CO LTD' + originator: 'Organization: Espressif Systems (Shanghai) CO LTD' diff --git a/components/sensors/sensor_hub/include/hal/humiture_hal.h b/components/sensors/sensor_hub/include/hal/humiture_hal.h index 74948a93b..adb628027 100644 --- a/components/sensors/sensor_hub/include/hal/humiture_hal.h +++ b/components/sensors/sensor_hub/include/hal/humiture_hal.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,20 +7,85 @@ #ifndef _HUMITURE_HAL_H_ #define _HUMITURE_HAL_H_ +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE + #include "i2c_bus.h" #include "sensor_type.h" typedef void *sensor_humiture_handle_t; /*!< humiture sensor handle*/ /** - * @brief humiture sensor id, used for humiture_create + * @brief Implementation Interface for Humiture Sensors * */ -typedef enum { - SHT3X_ID = 0x01, /*!< sht3x humiture sensor id*/ - HTS221_ID, /*!< hts221 humiture sensor id*/ - HUMITURE_MAX_ID, /*!< max humiture sensor id*/ -} humiture_id_t; +typedef struct { + /** + * @brief Initialize the humiture sensor + * + * @param handle The bus handle + * @param addr The I2C address of the sensor + * @return esp_err_t Result of initialization + */ + esp_err_t (*init)(bus_handle_t handle, uint8_t addr); + + /** + * @brief Deinitialize the humiture sensor + * + * @return esp_err_t Result of deinitialization + */ + esp_err_t (*deinit)(void); + + /** + * @brief Test the humiture sensor + * + * @return esp_err_t Result of the test + */ + esp_err_t (*test)(void); + + /** + * @brief Acquire humidity data from the sensor + * + * @param[out] humidity Pointer to store the humidity data + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_humidity)(float *humidity); + + /** + * @brief Acquire temperature data from the sensor + * + * @param[out] temperature Pointer to store the temperature data + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_temperature)(float *temperature); + + /** + * @brief Put the humiture sensor to sleep + * + * @return esp_err_t Result of the sleep operation + */ + esp_err_t (*sleep)(void); + + /** + * @brief Wake up the humiture sensor + * + * @return esp_err_t Result of the wake-up operation + */ + esp_err_t (*wakeup)(void); + + /** + * @brief Set sensor work mode + * + * @return esp_err_t Result of setting work mode + */ + esp_err_t (*set_mode)(sensor_mode_t work_mode); + + /** + * @brief Set sensor measurement range + * + * @return esp_err_t Result of setting measurement range + */ + esp_err_t (*set_range)(sensor_range_t range); +} humiture_impl_t; #ifdef __cplusplus extern "C" @@ -28,14 +93,14 @@ extern "C" #endif /** - * @brief Create a humiture/temperature/humidity sensor instance. - * Same series' sensor or sensor with same address can only be created once. + * @brief Create a humiture/temperature sensor instance. * - * @param bus i2c bus handle the sensor attached to - * @param id id declared in humiture_id_t + * @param bus i2c/spi bus handle the sensor attached to + * @param sensor_name name of sensor + * @param addr addr of sensor * @return sensor_humiture_handle_t return humiture sensor handle if succeed, return NULL if create failed. */ -sensor_humiture_handle_t humiture_create(bus_handle_t bus, int id); +sensor_humiture_handle_t humiture_create(bus_handle_t bus, const char *sensor_name, uint8_t addr); /** * @brief Delete and release the sensor resource. @@ -132,3 +197,5 @@ extern "C" #endif #endif + +#endif diff --git a/components/sensors/sensor_hub/include/hal/imu_hal.h b/components/sensors/sensor_hub/include/hal/imu_hal.h index 223c28928..2b8128ff5 100644 --- a/components/sensors/sensor_hub/include/hal/imu_hal.h +++ b/components/sensors/sensor_hub/include/hal/imu_hal.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,8 @@ #ifndef _IMU_HAL_H_ #define _IMU_HAL_H_ +#ifdef CONFIG_SENSOR_INCLUDED_IMU + #include "i2c_bus.h" #include "esp_err.h" #include "sensor_type.h" @@ -14,28 +16,96 @@ typedef void *sensor_imu_handle_t; /*!< imu sensor handle*/ /** - * @brief imu sensor id, used for imu_create + * @brief Implementation Interface for IMU Sensors * */ -typedef enum { - MPU6050_ID = 0x01, /*!< MPU6050 imu sensor id*/ - LIS2DH12_ID, /*!< LIS2DH12 imu sensor id*/ - IMU_MAX_ID, /*!< max imu sensor id*/ -} imu_id_t; +typedef struct { + /** + * @brief Initialize the IMU sensor + * + * @param handle The bus handle + * @param addr The I2C address of the sensor + * @return esp_err_t Result of initialization + */ + esp_err_t (*init)(bus_handle_t, uint8_t addr); + + /** + * @brief Deinitialize the IMU sensor + * + * @return esp_err_t Result of deinitialization + */ + esp_err_t (*deinit)(void); + + /** + * @brief Test the IMU sensor + * + * @return esp_err_t Result of the test + */ + esp_err_t (*test)(void); + + /** + * @brief Acquire accelerometer data + * + * @param[out] acce_x Pointer to store the X-axis accelerometer data + * @param[out] acce_y Pointer to store the Y-axis accelerometer data + * @param[out] acce_z Pointer to store the Z-axis accelerometer data + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_acce)(float *acce_x, float *acce_y, float *acce_z); + + /** + * @brief Acquire gyroscope data + * + * @param[out] gyro_x Pointer to store the X-axis gyroscope data + * @param[out] gyro_y Pointer to store the Y-axis gyroscope data + * @param[out] gyro_z Pointer to store the Z-axis gyroscope data + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_gyro)(float *gyro_x, float *gyro_y, float *gyro_z); + + /** + * @brief Put the IMU sensor to sleep + * + * @return esp_err_t Result of the sleep operation + */ + esp_err_t (*sleep)(void); + + /** + * @brief Wake up the IMU sensor + * + * @return esp_err_t Result of the wake-up operation + */ + esp_err_t (*wakeup)(void); + + /** + * @brief Set sensor work mode + * + * @return esp_err_t Result of setting work mode + */ + esp_err_t (*set_mode)(sensor_mode_t work_mode); + + /** + * @brief Set sensor measurement range + * + * @return esp_err_t Result of setting measurement range + */ + esp_err_t (*set_range)(sensor_range_t range); +} imu_impl_t; #ifdef __cplusplus extern "C" { #endif + /** * @brief Create a Inertial Measurement Unit sensor instance. - * Same series' sensor or sensor with same address can only be created once. * - * @param bus i2c bus handle the sensor attached to - * @param imu_id id declared in imu_id_t + * @param bus i2c/spi bus handle the sensor attached to + * @param sensor_name name of sensor + * @param addr addr of sensor * @return sensor_imu_handle_t return imu sensor handle if succeed, NULL is failed. */ -sensor_imu_handle_t imu_create(bus_handle_t bus, int imu_id); +sensor_imu_handle_t imu_create(bus_handle_t bus, const char *sensor_name, uint8_t addr); /** * @brief Delete and release the sensor resource. @@ -132,3 +202,5 @@ extern "C" #endif #endif + +#endif diff --git a/components/sensors/sensor_hub/include/hal/light_sensor_hal.h b/components/sensors/sensor_hub/include/hal/light_sensor_hal.h index 3054ea594..37710a166 100644 --- a/components/sensors/sensor_hub/include/hal/light_sensor_hal.h +++ b/components/sensors/sensor_hub/include/hal/light_sensor_hal.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,8 @@ #ifndef _LIGHT_SENSOR_HAL_H_ #define _LIGHT_SENSOR_HAL_H_ +#ifdef CONFIG_SENSOR_INCLUDED_LIGHT + #include "i2c_bus.h" #include "esp_err.h" #include "sensor_type.h" @@ -14,15 +16,90 @@ typedef void *sensor_light_handle_t; /*!< light sensor handle*/ /** - * @brief light sensor id, used for light_sensor_create + * @brief Implementation Interface for Light Sensors * */ -typedef enum { - BH1750_ID = 0x01, /*!< BH1750 light sensor id*/ - VEML6040_ID, /*!< VEML6040 light sensor id*/ - VEML6075_ID, /*!< VEML6075 light sensor id*/ - LIGHT_MAX_ID, /*!< max light sensor id*/ -} light_sensor_id_t; +typedef struct { + /** + * @brief Initialize the light sensor + * + * @param handle The bus handle + * @param addr The I2C address of the sensor + * @return esp_err_t Result of initialization + */ + esp_err_t (*init)(bus_handle_t handle, uint8_t addr); + + /** + * @brief Deinitialize the light sensor + * + * @return esp_err_t Result of deinitialization + */ + esp_err_t (*deinit)(void); + + /** + * @brief Test the light sensor + * + * @return esp_err_t Result of the test + */ + esp_err_t (*test)(void); + + /** + * @brief Acquire ambient light data + * + * @param[out] l Pointer to store the ambient light intensity + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_light)(float *l); + + /** + * @brief Acquire RGBW (Red, Green, Blue, White) light data + * + * @param[out] r Pointer to store the red light intensity + * @param[out] g Pointer to store the green light intensity + * @param[out] b Pointer to store the blue light intensity + * @param[out] w Pointer to store the white light intensity + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_rgbw)(float *r, float *g, float *b, float *w); + + /** + * @brief Acquire UV (Ultraviolet) light data + * + * @param[out] uv Pointer to store the total UV intensity + * @param[out] uva Pointer to store the UVA light intensity + * @param[out] uvb Pointer to store the UVB light intensity + * @return esp_err_t Result of acquiring data + */ + esp_err_t (*acquire_uv)(float *uv, float *uva, float *uvb); + + /** + * @brief Put the light sensor to sleep + * + * @return esp_err_t Result of the sleep operation + */ + esp_err_t (*sleep)(void); + + /** + * @brief Wake up the light sensor + * + * @return esp_err_t Result of the wake-up operation + */ + esp_err_t (*wakeup)(void); + + /** + * @brief Set sensor work mode + * + * @return esp_err_t Result of setting work mode + */ + esp_err_t (*set_mode)(sensor_mode_t work_mode); + + /** + * @brief Set sensor measurement range + * + * @return esp_err_t Result of setting measurement range + */ + esp_err_t (*set_range)(sensor_range_t range); +} light_impl_t; #ifdef __cplusplus extern "C" @@ -31,13 +108,13 @@ extern "C" /** * @brief Create a light sensor instance. - * same series' sensor or sensor with same address can only be created once. * - * @param bus i2c bus handle the sensor attached to - * @param id id declared in light_sensor_id_t - * @return sensor_light_handle_t return light sensor handle if succeed, return NULL if failed. + * @param bus i2c/spi bus handle the sensor attached to + * @param sensor_name name of sensor + * @param addr addr of sensor + * @return sensor_light_handle_t return humiture sensor handle if succeed, return NULL if create failed. */ -sensor_light_handle_t light_sensor_create(bus_handle_t bus, int id); +sensor_light_handle_t light_sensor_create(bus_handle_t bus, const char *sensor_name, uint8_t addr); /** * @brief Delete and release the sensor resource. @@ -148,3 +225,5 @@ extern "C" #endif #endif + +#endif diff --git a/components/sensors/sensor_hub/include/iot_sensor_hub.h b/components/sensors/sensor_hub/include/iot_sensor_hub.h index a0dfd7c1d..3504d827c 100644 --- a/components/sensors/sensor_hub/include/iot_sensor_hub.h +++ b/components/sensors/sensor_hub/include/iot_sensor_hub.h @@ -24,51 +24,22 @@ #include "sensor_event.h" #include "sensor_type.h" -/** @cond **/ -/* SENSORS IMU EVENTS BASE */ -ESP_EVENT_DECLARE_BASE(SENSOR_IMU_EVENTS); -ESP_EVENT_DECLARE_BASE(SENSOR_HUMITURE_EVENTS); -ESP_EVENT_DECLARE_BASE(SENSOR_LIGHTSENSOR_EVENTS); -/** @endcond **/ +typedef void *sensor_handle_t; /*!< sensor handle*/ +typedef void *sensor_event_handler_instance_t; /*!< sensor event handler handle*/ +typedef const char *sensor_event_base_t; /*!< unique pointer to a subsystem that exposes events */ -typedef void *sensor_handle_t; /*!< sensor handle*/ -typedef void *sensor_event_handler_instance_t; /*!< sensor event handler handle*/ -typedef const char *sensor_event_base_t; /*!< unique pointer to a subsystem that exposes events */ - -typedef void (*sensor_event_handler_t)(void *event_handler_arg, sensor_event_base_t event_base, int32_t event_id, void *event_data); /*!< function called when an event is posted to the queue */ +typedef void (*sensor_event_handler_t)(void *event_handler_arg, sensor_event_base_t event_base, int32_t event_id, void *event_data); /*!< function called when an event is posted to the queue */ extern const char *SENSOR_TYPE_STRING[]; extern const char *SENSOR_MODE_STRING[]; /** - * @brief sensor id, used for iot_sensor_create - * - */ -typedef enum { -#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE - SENSOR_SHT3X_ID = (HUMITURE_ID << SENSOR_ID_OFFSET) | SHT3X_ID, /*!< sht3x sensor id*/ - SENSOR_HTS221_ID = (HUMITURE_ID << SENSOR_ID_OFFSET) | HTS221_ID, /*!< hts221 sensor id*/ -#endif -#ifdef CONFIG_SENSOR_INCLUDED_IMU - SENSOR_MPU6050_ID = ((IMU_ID << SENSOR_ID_OFFSET) | MPU6050_ID), /*!< mpu6050 sensor id*/ - SENSOR_LIS2DH12_ID = ((IMU_ID << SENSOR_ID_OFFSET) | LIS2DH12_ID), /*!< lis2dh12 sensor id*/ -#endif -#ifdef CONFIG_SENSOR_INCLUDED_LIGHT - SENSOR_BH1750_ID = (LIGHT_SENSOR_ID << SENSOR_ID_OFFSET) | BH1750_ID, /*!< bh1750 sensor id*/ - SENSOR_VEML6040_ID = (LIGHT_SENSOR_ID << SENSOR_ID_OFFSET) | VEML6040_ID, /*!< veml6040 sensor id*/ - SENSOR_VEML6075_ID = (LIGHT_SENSOR_ID << SENSOR_ID_OFFSET) | VEML6075_ID, /*!< veml6075 sensor id*/ -#endif -} sensor_id_t; - -/** - * @brief sensor information type + * @brief sensor information, written by the driver developer. * */ typedef struct { - const char* name; /*!< sensor name*/ - const char* desc; /*!< sensor descriptive message*/ - sensor_id_t sensor_id; /*!< sensor id*/ - const uint8_t *addrs; /*!< sensor address list*/ + const char *name; /*!< sensor name */ + sensor_type_t sensor_type; /*!< sensor type */ } sensor_info_t; /** @@ -76,30 +47,84 @@ typedef struct { * */ typedef struct { - bus_handle_t bus; /*!< i2c/spi bus handle*/ - sensor_mode_t mode; /*!< set acquire mode detiled in sensor_mode_t*/ - sensor_range_t range; /*!< set measuring range*/ - uint32_t min_delay; /*!< set minimum acquisition interval*/ - int intr_pin; /*!< set interrupt pin */ - int intr_type; /*!< set interrupt type*/ + bus_handle_t bus; /*!< i2c/spi bus handle*/ + uint8_t addr; /*!< set addr of sensor*/ + sensor_type_t type; /*!< sensor type */ + sensor_mode_t mode; /*!< set acquire mode detiled in sensor_mode_t*/ + sensor_range_t range; /*!< set measuring range*/ + uint32_t min_delay; /*!< set minimum acquisition interval*/ + int intr_pin; /*!< set interrupt pin */ + int intr_type; /*!< set interrupt type*/ } sensor_config_t; +/** + * @brief Detection function interface for sensors + */ +typedef struct { + /** + * @brief Function pointer for sensor detection + * + * This function detects a sensor based on the provided sensor information. + * + * @param sensor_info Pointer to the sensor information structure + * @return void* Pointer to the detected sensor instance, or NULL if detection failed + */ + void* (*fn)(sensor_info_t *sensor_info); +} sensor_hub_detect_fn_t; + +/** + * @brief Defines a sensor detection function to be executed automatically in the application layer. + * + * @param type_id The sensor type identifier. + * @param name_id The unique name identifier for the sensor. + * @param impl The implementation returned on successful detection. + * + * This macro defines a function and its corresponding metadata to facilitate automatic sensor detection + * and initialization. The function must return the implementation (`impl`) on success; otherwise, + * an error is logged, and the automatic detection process in the application layer will be aborted. + * + * To prevent the linker from optimizing out the sensor driver, the driver must include at least one + * undefined symbol that is explicitly referenced during the linking phase. This ensures that the linker + * retains the driver, even if no other files directly depend on its symbols. + * + * For example, in the sensor driver's `CMakeLists.txt`, include the following to force the linker + * to keep the required symbol: + * + * target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ") + * + * Replace `` with an appropriate symbol, such as `sht3x_init`, defined in the driver. + */ +#define SENSOR_HUB_DETECT_FN(type_id, name_id, impl) \ + static void* __sensor_hub_detect_fn_##name_id(sensor_info_t *sensor_info); \ + __attribute__((used)) _SECTION_ATTR_IMPL(".sensor_hub_detect_fn", __COUNTER__) \ + sensor_hub_detect_fn_t sensor_hub_detect_fn_##name_id = { \ + .fn = __sensor_hub_detect_fn_##name_id, \ + }; \ + static void* __sensor_hub_detect_fn_##name_id(sensor_info_t *sensor_info) { \ + sensor_info->name = #name_id; \ + sensor_info->sensor_type = type_id; \ + return impl; \ + } + +extern sensor_hub_detect_fn_t __sensor_hub_detect_fn_array_start; +extern sensor_hub_detect_fn_t __sensor_hub_detect_fn_array_end; + #ifdef __cplusplus extern "C" { #endif /** - * @brief Create a sensor instance with specified sensor_id and desired configurations. + * @brief Create a sensor instance with specified name and desired configurations. * - * @param sensor_id sensor's id detailed in sensor_id_t. + * @param sensor_name sensor's name. Sensor information will be registered by ESP_SENSOR_DETECT_FN * @param config sensor's configurations detailed in sensor_config_t * @param p_sensor_handle return sensor handle if succeed, NULL if failed. * @return esp_err_t * - ESP_OK Success * - ESP_FAIL Fail */ -esp_err_t iot_sensor_create(sensor_id_t sensor_id, const sensor_config_t *config, sensor_handle_t *p_sensor_handle); +esp_err_t iot_sensor_create(const char *sensor_name, const sensor_config_t *config, sensor_handle_t *p_sensor_handle); /** * @brief start sensor acquisition, post data ready events when data acquired. @@ -127,12 +152,12 @@ esp_err_t iot_sensor_stop(sensor_handle_t sensor_handle); /** * @brief delete and release the sensor resource. * - * @param p_sensor_handle point to sensor handle, will set to NULL if delete succeed. + * @param p_sensor_handle sensor handle, will set to NULL if delete succeed. * @return esp_err_t * - ESP_OK Success * - ESP_FAIL Fail */ -esp_err_t iot_sensor_delete(sensor_handle_t *p_sensor_handle); +esp_err_t iot_sensor_delete(sensor_handle_t p_sensor_handle); /** * @brief Scan for valid sensors attached on bus @@ -143,7 +168,13 @@ esp_err_t iot_sensor_delete(sensor_handle_t *p_sensor_handle); * latter sensors will be discarded if num less-than the total number found on the bus. * @return uint8_t total number of valid sensors found on the bus */ -uint8_t iot_sensor_scan(bus_handle_t bus, sensor_info_t* buf[], uint8_t num); + +/** + * @brief Scan for valid sensors registered in the system + * + * @return int number of valid sensors + */ +int iot_sensor_scan(); /** * @brief Register a event handler to a sensor's event with sensor_handle. diff --git a/components/sensors/sensor_hub/include/sensor_type.h b/components/sensors/sensor_hub/include/sensor_type.h index 512a835a6..d4dccda0d 100644 --- a/components/sensors/sensor_hub/include/sensor_type.h +++ b/components/sensors/sensor_hub/include/sensor_type.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,15 +8,14 @@ #define _IOT_SENSOR_TYPE_H_ #include "esp_err.h" +typedef void *sensor_device_impl_t; #define SENSOR_EVENT_ANY_ID ESP_EVENT_ANY_ID /*!< register handler for any event id */ -typedef void *sensor_driver_handle_t; /*!< hal level sensor driver handle */ -typedef void *bus_handle_t; /*!< i2c/spi bus handle */ +typedef void *sensor_driver_handle_t; /*!< hal level sensor driver handle */ +typedef void *bus_handle_t; /*!< i2c/spi bus handle */ /** @cond **/ -#define SENSOR_ID_MASK 0X0F -#define SENSOR_ID_OFFSET 4 -#define SENSOR_DATA_GROUP_MAX_NUM 6 /*default number of sensor_data_t in a group */ +#define SENSOR_DATA_GROUP_MAX_NUM 6 /*!< default number of sensor_data_t in a group */ /** * @brief imu sensor type @@ -54,7 +53,7 @@ typedef struct { */ #ifndef UV_T typedef struct { - float uv; /*!< ultroviolet */ + float uv; /*!< ultroviolet */ float uva; /*!< ultroviolet A */ float uvb; /*!< ultroviolet B */ } uv_t; @@ -67,9 +66,9 @@ typedef struct { * */ typedef enum { - NULL_ID, /*!< NULL */ - HUMITURE_ID, /*!< humidity or temperature sensor */ - IMU_ID, /*!< gyro or acc sensor */ + NULL_ID, /*!< NULL */ + HUMITURE_ID, /*!< humidity or temperature sensor */ + IMU_ID, /*!< gyro or acc sensor */ LIGHT_SENSOR_ID, /*!< light illumination or uv or color sensor */ SENSOR_TYPE_MAX, /*!< max sensor type */ } sensor_type_t; @@ -79,12 +78,12 @@ typedef enum { * */ typedef enum { - COMMAND_SET_MODE, /*!< set measure mode */ + COMMAND_SET_MODE, /*!< set measure mode */ COMMAND_SET_RANGE, /*!< set measure range */ - COMMAND_SET_ODR, /*!< set output rate */ + COMMAND_SET_ODR, /*!< set output rate */ COMMAND_SET_POWER, /*!< set power mode */ COMMAND_SELF_TEST, /*!< sensor self test */ - COMMAND_MAX /*!< max sensor command */ + COMMAND_MAX /*!< max sensor command */ } sensor_command_t; /** @@ -93,8 +92,8 @@ typedef enum { */ typedef enum { POWER_MODE_WAKEUP, /*!< wakeup from sleep */ - POWER_MODE_SLEEP, /*!< set to sleep */ - POWER_MAX /*!< max sensor power mode */ + POWER_MODE_SLEEP, /*!< set to sleep */ + POWER_MAX /*!< max sensor power mode */ } sensor_power_mode_t; /** @@ -102,10 +101,10 @@ typedef enum { * */ typedef enum { - MODE_DEFAULT, /*!< default work mode */ - MODE_POLLING, /*!< polling acquire with a interval time */ + MODE_DEFAULT, /*!< default work mode */ + MODE_POLLING, /*!< polling acquire with a interval time */ MODE_INTERRUPT, /*!< interrupt mode, acquire data when interrupt comes */ - MODE_MAX, /*!< max sensor mode */ + MODE_MAX, /*!< max sensor mode */ } sensor_mode_t; /** @@ -114,9 +113,9 @@ typedef enum { */ typedef enum { RANGE_DEFAULT, /*!< default range */ - RANGE_MIN, /*!< minimum range for high-speed or high-precision*/ - RANGE_MEDIUM, /*!< medium range for general use*/ - RANGE_MAX, /*!< maximum range for full scale*/ + RANGE_MIN, /*!< minimum range for high-speed or high-precision*/ + RANGE_MEDIUM, /*!< medium range for general use*/ + RANGE_MAX, /*!< maximum range for full scale*/ } sensor_range_t; /** @@ -124,9 +123,9 @@ typedef enum { * */ typedef enum { - SENSOR_STARTED, /*!< sensor started, data acquire will be started */ - SENSOR_STOPED, /*!< sensor stopped, data acquire will be stopped */ - SENSOR_EVENT_COMMON_END = 9, /*!< max common events id */ + SENSOR_STARTED, /*!< sensor started, data acquire will be started */ + SENSOR_STOPED, /*!< sensor stopped, data acquire will be stopped */ + SENSOR_EVENT_COMMON_END = 9, /*!< max common events id */ } sensor_event_id_t; /** @@ -159,29 +158,31 @@ typedef enum { * */ typedef struct { - int64_t timestamp; /*!< timestamp */ - uint8_t sensor_id; /*!< sensor id */ - int32_t event_id; /*!< reserved for future use */ - uint32_t min_delay; /*!< minimum delay between two events, unit: ms */ + int64_t timestamp; /*!< timestamp */ + const char* sensor_name; /*!< sensor name */ + sensor_type_t sensor_type; /*!< sensor type */ + uint8_t sensor_addr; /*!< sensor addr */ + int32_t event_id; /*!< reserved for future use */ + uint32_t min_delay; /*!< minimum delay between two events, unit: ms */ union { - axis3_t acce; /*!< Accelerometer. unit: G */ - axis3_t gyro; /*!< Gyroscope. unit: dps */ - axis3_t mag; /*!< Magnetometer. unit: Gauss */ - float temperature; /*!< Temperature. unit: dCelsius */ - float humidity; /*!< Relative humidity. unit: percentage */ - float baro; /*!< Pressure. unit: pascal (Pa) */ - float light; /*!< Light. unit: lux */ - rgbw_t rgbw; /*!< Color. unit: lux */ - uv_t uv; /*!< ultraviole unit: lux */ - float proximity; /*!< Distance. unit: centimeters */ - float hr; /*!< Heat rate. unit: HZ */ - float tvoc; /*!< TVOC. unit: permillage */ - float noise; /*!< Noise Loudness. unit: HZ */ - float step; /*!< Step sensor. unit: 1 */ - float force; /*!< Force sensor. unit: mN */ - float current; /*!< Current sensor unit: mA */ - float voltage; /*!< Voltage sensor unit: mV */ - float data[4]; /*!< for general use */ + axis3_t acce; /*!< Accelerometer. unit: G */ + axis3_t gyro; /*!< Gyroscope. unit: dps */ + axis3_t mag; /*!< Magnetometer. unit: Gauss */ + float temperature; /*!< Temperature. unit: dCelsius */ + float humidity; /*!< Relative humidity. unit: percentage */ + float baro; /*!< Pressure. unit: pascal (Pa) */ + float light; /*!< Light. unit: lux */ + rgbw_t rgbw; /*!< Color. unit: lux */ + uv_t uv; /*!< ultraviole unit: lux */ + float proximity; /*!< Distance. unit: centimeters */ + float hr; /*!< Heat rate. unit: HZ */ + float tvoc; /*!< TVOC. unit: permillage */ + float noise; /*!< Noise Loudness. unit: HZ */ + float step; /*!< Step sensor. unit: 1 */ + float force; /*!< Force sensor. unit: mN */ + float current; /*!< Current sensor unit: mA */ + float voltage; /*!< Voltage sensor unit: mV */ + float data[4]; /*!< for general use */ }; } sensor_data_t; @@ -190,7 +191,7 @@ typedef struct { * */ typedef struct { - uint8_t number; /*!< effective data number */ + uint8_t number; /*!< effective data number */ sensor_data_t sensor_data[SENSOR_DATA_GROUP_MAX_NUM]; /*!< data buffer */ } sensor_data_group_t; @@ -200,11 +201,11 @@ typedef struct { * */ typedef struct { - sensor_type_t type; /*!< sensor type */ - sensor_driver_handle_t (*create)(bus_handle_t, int sensor_id); /*!< create a sensor */ - esp_err_t (*delete)(sensor_driver_handle_t *); /*!< delete a sensor */ - esp_err_t (*acquire)(sensor_driver_handle_t, sensor_data_group_t *); /*!< acquire a group of sensor data */ - esp_err_t (*control)(sensor_driver_handle_t, sensor_command_t cmd, void *args); /*!< modify the sensor configuration */ + sensor_type_t type; /*!< sensor type */ + sensor_driver_handle_t (*create)(bus_handle_t, const char *sensor_name, uint8_t addr); /*!< create a sensor */ + esp_err_t (*delete)(sensor_driver_handle_t *); /*!< delete a sensor */ + esp_err_t (*acquire)(sensor_driver_handle_t, sensor_data_group_t *); /*!< acquire a group of sensor data */ + esp_err_t (*control)(sensor_driver_handle_t, sensor_command_t cmd, void *args); /*!< modify the sensor configuration */ } iot_sensor_impl_t; /** @endcond **/ diff --git a/components/sensors/sensor_hub/iot_sensor_hub.c b/components/sensors/sensor_hub/iot_sensor_hub.c index 8eb466300..887ecaa33 100644 --- a/components/sensors/sensor_hub/iot_sensor_hub.c +++ b/components/sensors/sensor_hub/iot_sensor_hub.c @@ -6,6 +6,7 @@ #include #include +#include #include "esp_log.h" #include "iot_sensor_hub.h" #include "esp_timer.h" @@ -62,6 +63,7 @@ static SemaphoreHandle_t s_sensor_node_mutex = NULL; /* mutex to achieve thre ESP_EVENT_DEFINE_BASE(SENSOR_IMU_EVENTS); ESP_EVENT_DEFINE_BASE(SENSOR_HUMITURE_EVENTS); ESP_EVENT_DEFINE_BASE(SENSOR_LIGHTSENSOR_EVENTS); +#define SENSOR_EVENT_NAME_LENGTH 50 #ifdef CONFIG_SENSOR_DEFAULT_HANDLER static sensor_event_handler_instance_t s_sensor_default_handler_instance = NULL; static void sensor_default_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data); @@ -71,13 +73,14 @@ static void sensor_default_event_handler(void *handler_args, esp_event_base_t ba typedef struct { bus_handle_t bus; sensor_type_t type; - sensor_id_t sensor_id; sensor_mode_t mode; uint32_t min_delay; + const char *name; sensor_driver_handle_t driver_handle; iot_sensor_impl_t *impl; - const char *event_base; + char event_base[SENSOR_EVENT_NAME_LENGTH]; uint32_t event_bit; + uint8_t addr; TaskHandle_t task_handle; int intr_pin; /*!< set interrupt pin */ union { @@ -123,44 +126,7 @@ static iot_sensor_impl_t s_sensor_impls[] = { #endif }; -static sensor_info_t s_sensor_info[] = { -#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE - { "SHT31", "Humi/Temp sensor", SENSOR_SHT3X_ID, (const uint8_t *)"\x44\x45" }, - { "HTS221", "Humi/Temp sensor", SENSOR_HTS221_ID, (const uint8_t *)"\x5f" }, -#endif -#ifdef CONFIG_SENSOR_INCLUDED_IMU - { "MPU6050", "Gyro/Acce sensor", SENSOR_MPU6050_ID, (const uint8_t *)"\x69\x68" }, - { "LIS2DH", "Acce sensor", SENSOR_LIS2DH12_ID, (const uint8_t *)"\x19\x18" }, -#endif -#ifdef CONFIG_SENSOR_INCLUDED_LIGHT - { "BH1750", "Light Intensity sensor", SENSOR_BH1750_ID, (const uint8_t *)"\x23" }, - { "VEML6040", "Light Color sensor", SENSOR_VEML6040_ID, (const uint8_t *)"\x10" }, - { "VEML6075", "Light UV sensor", SENSOR_VEML6075_ID, (const uint8_t *)"\x10" }, -#endif -}; - /******************************************Private Functions*********************************************/ -static sensor_info_t *sensor_find_info(uint8_t i2c_address) -{ - sensor_info_t *last_matched_info = NULL; - int counter = 0; - int length = sizeof(s_sensor_info) / sizeof(sensor_info_t); - - for (int i = 0; i < length; i++) { - for (int j = 0; s_sensor_info[i].addrs[j] != '\0'; j++) { - if (s_sensor_info[i].addrs[j] == i2c_address) { - counter++; - last_matched_info = &s_sensor_info[i]; - ESP_LOGI(TAG, "address 0x%0x might be %s (%s)\n", i2c_address, s_sensor_info[i].name, s_sensor_info[i].desc); - break; - } - } - } - - ESP_LOGI(TAG, "address 0x%0x found %d matched info\n", i2c_address, counter); - return last_matched_info; -} - static iot_sensor_impl_t *sensor_find_impl(int sensor_type) { int count = sizeof(s_sensor_impls) / sizeof(iot_sensor_impl_t); @@ -174,30 +140,6 @@ static iot_sensor_impl_t *sensor_find_impl(int sensor_type) return NULL; } -static const char *sensor_find_event_base(int sensor_type) -{ - const char *event_base = NULL; - - switch (sensor_type) { - case IMU_ID: - event_base = SENSOR_IMU_EVENTS; - break; - - case HUMITURE_ID: - event_base = SENSOR_HUMITURE_EVENTS; - break; - - case LIGHT_SENSOR_ID: - event_base = SENSOR_LIGHTSENSOR_EVENTS; - break; - - default : - break; - } - - return event_base; -} - static inline esp_err_t sensor_take_event_bit(uint32_t *p_bit) { SENSOR_CHECK(p_bit != NULL, "pointer can not be NULL", ESP_ERR_INVALID_ARG); @@ -299,12 +241,13 @@ static void sensor_default_task(void *arg) if ((uxBits >> (node->p_sensor->event_bit)) & 0x01) { node->p_sensor->impl->acquire(node->p_sensor->driver_handle, &sensor_data_group); acquire_time = sensor_get_timestamp_us(); - for (uint8_t i = 0; i < sensor_data_group.number; i++) { /*.event_id and .data assignment during acquire stage*/ sensor_data_group.sensor_data[i].timestamp = acquire_time; - sensor_data_group.sensor_data[i].sensor_id = node->p_sensor->sensor_id; + sensor_data_group.sensor_data[i].sensor_type = node->p_sensor->type; + sensor_data_group.sensor_data[i].sensor_name = node->p_sensor->name; sensor_data_group.sensor_data[i].min_delay = node->p_sensor->min_delay; + sensor_data_group.sensor_data[i].sensor_addr = node->p_sensor->addr; sensors_event_post(node->p_sensor->event_base, sensor_data_group.sensor_data[i].event_id, &(sensor_data_group.sensor_data[i]), sizeof(sensor_data_t), 0); } } @@ -387,30 +330,39 @@ static inline esp_err_t sensor_intr_isr_remove(int pin) } /******************************************Public Functions*********************************************/ -esp_err_t iot_sensor_create(sensor_id_t sensor_id, const sensor_config_t *config, sensor_handle_t *p_sensor_handle) +esp_err_t iot_sensor_create(const char *sensor_name, const sensor_config_t *config, sensor_handle_t *p_sensor_handle) { - SENSOR_CHECK(config != NULL, "config can not be NULL", ESP_ERR_INVALID_ARG); - SENSOR_CHECK(p_sensor_handle != NULL, "p_sensor_handle can not be NULL", ESP_ERR_INVALID_ARG); - esp_err_t ret = ESP_FAIL; - /*copy first for safety operation*/ + if (sensor_name == NULL || config == NULL) { + ESP_LOGE(TAG, "Please validate sensor name or config"); + return ESP_ERR_INVALID_ARG; + } + esp_err_t ret = ESP_OK; + // copy first for safety operation sensor_config_t config_copy = *config; - /*search for driver based on sensor_id*/ + + if (config_copy.type <= NULL_ID || config_copy.type >= SENSOR_TYPE_MAX) { + ESP_LOGE(TAG, "Invalid sensor type"); + return ESP_ERR_NOT_SUPPORTED; + } + + // Set Sensor Abstraction Layer Information _iot_sensor_t *sensor = (_iot_sensor_t *)calloc(1, sizeof(_iot_sensor_t)); SENSOR_CHECK(sensor != NULL, "calloc node failed", ESP_ERR_NO_MEM); - sensor->type = (sensor_type_t)(sensor_id >> 4 & SENSOR_ID_MASK); - sensor->sensor_id = sensor_id; + sensor->type = config_copy.type; sensor->bus = config_copy.bus; - sensor->mode = config_copy.mode; + sensor->name = sensor_name; + sensor->addr = config_copy.addr; sensor->min_delay = config_copy.min_delay; sensor->intr_pin = config_copy.intr_pin; + sensor->mode = config_copy.mode; sensor->impl = sensor_find_impl(sensor->type); - sensor->event_base = sensor_find_event_base(sensor->type); + sprintf(sensor->event_base, "%s_%x", sensor_name, config->addr); SENSOR_CHECK_GOTO(sensor->impl != NULL && sensor->event_base != NULL, "no driver found !!", cleanup_sensor); - /*create a new sensor*/ - sensor->driver_handle = sensor->impl->create(sensor->bus, (sensor->sensor_id & SENSOR_ID_MASK)); + // create a new sensor + sensor->driver_handle = sensor->impl->create(sensor->bus, sensor->name, sensor->addr); SENSOR_CHECK_GOTO(sensor->driver_handle != NULL, "sensor create failed", cleanup_sensor); - /*config sensor work mode, not supported case will be skipped*/ + // config sensor work mode, not supported case will be skipped ret = sensor->impl->control(sensor->driver_handle, COMMAND_SET_MODE, (void *)(config_copy.mode)); SENSOR_CHECK_GOTO(ESP_OK == ret || ESP_ERR_NOT_SUPPORTED == ret, "set sensor mode failed !!", cleanup_sensor); /*config sensor measuring range, not supported case will be skipped*/ @@ -430,16 +382,13 @@ esp_err_t iot_sensor_create(sensor_id_t sensor_id, const sensor_config_t *config SENSOR_CHECK(s_sensor_node_mutex != NULL, "sensor_node xSemaphoreCreateMutex failed", ESP_FAIL); } - /*add sensor to list, event_bit will be set internal*/ + // add sensor to list, event_bit will be set internal ret = sensor_add_node(sensor); SENSOR_CHECK_GOTO(ret == ESP_OK, "add sensor node to list failed !!", cleanup_sensor); - char sensor_timmer_name[16] = {'\0'}; - snprintf(sensor_timmer_name, sizeof(sensor_timmer_name) - 1, "%s%02x", SENSOR_TYPE_STRING[sensor->type], sensor->sensor_id); - switch (sensor->mode) { case MODE_POLLING: - sensor->timer_handle = sensor_polling_mode_init(sensor_timmer_name, sensor->min_delay, (void *)(sensor->event_bit)); + sensor->timer_handle = sensor_polling_mode_init(sensor->name, sensor->min_delay, (void *)(sensor->event_bit)); SENSOR_CHECK_GOTO(sensor->timer_handle != NULL, "sensor timer create failed", cleanup_sensor_node); break; @@ -461,23 +410,23 @@ esp_err_t iot_sensor_create(sensor_id_t sensor_id, const sensor_config_t *config } sensor->task_handle = s_sensor_task_handle; - /*regist default event handler for message print*/ + // regist default event handler for message print #ifdef CONFIG_SENSOR_DEFAULT_HANDLER_DATA if (s_sensor_default_handler_instance == NULL) { - /*print all sensor event includes data*/ + // print all sensor event includes data sensors_event_handler_instance_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, sensor_default_event_handler, (void *)true, &s_sensor_default_handler_instance); } #elif CONFIG_SENSOR_DEFAULT_HANDLER if (s_sensor_default_handler_instance == NULL) { - /*print sensor state message only*/ + // print sensor state message only sensors_event_handler_instance_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, sensor_default_event_handler, (void *)false, &s_sensor_default_handler_instance); } #endif - ESP_LOGI(TAG, "Sensor created, Task name = %s, Type = %s, Sensor ID = %d, Mode = %s, Min Delay = %d ms", + ESP_LOGI(TAG, "Sensor created, Task name = %s, Type = %s, Sensor Name = %s, Mode = %s, Min Delay = %" PRIu32 " ms", SENSOR_DEFAULT_TASK_NAME, SENSOR_TYPE_STRING[sensor->type], - sensor->sensor_id, + sensor->name, SENSOR_MODE_STRING[sensor->mode], sensor->min_delay); @@ -487,12 +436,12 @@ esp_err_t iot_sensor_create(sensor_id_t sensor_id, const sensor_config_t *config cleanup_sensor: free(sensor); *p_sensor_handle = NULL; - return ESP_FAIL; + return ret; cleanup_sensor_node: sensor_remove_node(sensor); free(sensor); *p_sensor_handle = NULL; - return ESP_FAIL; + return ret; } esp_err_t iot_sensor_stop(sensor_handle_t sensor_handle) @@ -519,7 +468,9 @@ esp_err_t iot_sensor_stop(sensor_handle_t sensor_handle) sensor_data_t sensor_data; memset(&sensor_data, 0, sizeof(sensor_data_t)); - sensor_data.sensor_id = sensor->sensor_id; + sensor_data.sensor_type = sensor->type; + sensor_data.sensor_name = sensor->name; + sensor_data.sensor_addr = sensor->addr; sensor_data.timestamp = sensor_get_timestamp_us(); sensor_data.event_id = SENSOR_STOPED; esp_err_t ret = sensors_event_post(sensor->event_base, sensor_data.event_id, &sensor_data, sizeof(sensor_data_t), portMAX_DELAY); @@ -561,7 +512,9 @@ esp_err_t iot_sensor_start(sensor_handle_t sensor_handle) sensor_data_t sensor_data; memset(&sensor_data, 0, sizeof(sensor_data_t)); - sensor_data.sensor_id = sensor->sensor_id; + sensor_data.sensor_type = sensor->type; + sensor_data.sensor_name = sensor->name; + sensor_data.sensor_addr = sensor->addr; sensor_data.timestamp = sensor_get_timestamp_us(); sensor_data.event_id = SENSOR_STARTED; esp_err_t ret = sensors_event_post(sensor->event_base, sensor_data.event_id, &sensor_data, sizeof(sensor_data_t), portMAX_DELAY); @@ -579,10 +532,10 @@ esp_err_t iot_sensor_start(sensor_handle_t sensor_handle) return ESP_OK; } -esp_err_t iot_sensor_delete(sensor_handle_t *p_sensor_handle) +esp_err_t iot_sensor_delete(sensor_handle_t p_sensor_handle) { - SENSOR_CHECK(p_sensor_handle != NULL && *p_sensor_handle != NULL, "sensor handle can not be NULL", ESP_ERR_INVALID_ARG); - _iot_sensor_t *sensor = (_iot_sensor_t *)(*p_sensor_handle); + SENSOR_CHECK(p_sensor_handle != NULL, "sensor handle can not be NULL", ESP_ERR_INVALID_ARG); + _iot_sensor_t *sensor = (_iot_sensor_t *)(p_sensor_handle); SENSOR_CHECK(sensor->timer_handle != NULL, "sensor timmer handle can not be NULL", ESP_ERR_INVALID_ARG); switch (sensor->mode) { @@ -619,7 +572,7 @@ esp_err_t iot_sensor_delete(sensor_handle_t *p_sensor_handle) /*free the resource then set handle to NULL*/ free(sensor); - *p_sensor_handle = NULL; + p_sensor_handle = NULL; /*if no event bits to wait, delete the default sensor task*/ if (s_sensor_wait_bits == BIT23_KILL_WAITING_TASK) { @@ -657,28 +610,19 @@ esp_err_t iot_sensor_delete(sensor_handle_t *p_sensor_handle) return ESP_OK; } -uint8_t iot_sensor_scan(bus_handle_t bus, sensor_info_t *buf[], uint8_t num) +int iot_sensor_scan() { - uint8_t addrs[SENSORS_NUM_MAX] = {0}; - /* second call to get the addresses*/ - uint8_t num_attached = i2c_bus_scan(bus, addrs, SENSORS_NUM_MAX); - uint8_t num_valid = 0; - - for (size_t i = 0; i < num_attached; i++) { - sensor_info_t *matched_info = sensor_find_info(*(addrs + i)); - - if (matched_info == NULL) { - continue; - } - - if (buf != NULL && num_valid < num) { - *(buf + num_valid) = matched_info; + int sensor_count = 0; + // search the sensor driver from a specific segment + for (sensor_hub_detect_fn_t *p = &__sensor_hub_detect_fn_array_start; p < &__sensor_hub_detect_fn_array_end; ++p) { + sensor_info_t info; + sensor_device_impl_t sensor_device_impl = (*(p->fn))(&info); + if (sensor_device_impl != NULL) { + ESP_LOGI(TAG, "Find %s driver, type: %s", info.name, SENSOR_TYPE_STRING[info.sensor_type]); + sensor_count++; } - - num_valid++; } - - return num_valid; + return sensor_count; } esp_err_t iot_sensor_handler_register(sensor_handle_t sensor_handle, sensor_event_handler_t handler, sensor_event_handler_instance_t *context) @@ -764,81 +708,78 @@ esp_err_t iot_sensor_handler_unregister_with_type(sensor_type_t sensor_type, int static void sensor_default_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) { sensor_data_t *sensor_data = (sensor_data_t *)event_data; - sensor_type_t sensor_type = (sensor_type_t)((sensor_data->sensor_id) >> 4 & SENSOR_ID_MASK); - - if (sensor_type >= SENSOR_TYPE_MAX) { - ESP_LOGE(TAG, "sensor_id invalid, id=%d", sensor_data->sensor_id); - return; - } - - if (id >= SENSOR_EVENT_ID_END || (handler_args == false && id >= SENSOR_EVENT_COMMON_END)) { - return; - } switch (id) { case SENSOR_STARTED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STARTED", + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STARTED", sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); + sensor_data->sensor_name, + sensor_data->sensor_addr); break; - case SENSOR_STOPED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STOPED", + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STOPPED", sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); + sensor_data->sensor_name, + sensor_data->sensor_addr); break; - case SENSOR_HUMI_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_HUMI_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x HUMI_DATA_READY - " "humiture=%.2f", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->humidity); break; - case SENSOR_TEMP_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_TEMP_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x TEMP_DATA_READY - " "temperature=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->temperature); break; - case SENSOR_ACCE_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_ACCE_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x ACCE_DATA_READY - " "acce_x=%.2f, acce_y=%.2f, acce_z=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->acce.x, sensor_data->acce.y, sensor_data->acce.z); break; - case SENSOR_GYRO_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_GYRO_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x GYRO_DATA_READY - " "gyro_x=%.2f, gyro_y=%.2f, gyro_z=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->gyro.x, sensor_data->gyro.y, sensor_data->gyro.z); break; - case SENSOR_LIGHT_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_LIGHT_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x LIGHT_DATA_READY - " "light=%.2f", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->light); break; - case SENSOR_RGBW_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_RGBW_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x RGBW_DATA_READY - " "r=%.2f, g=%.2f, b=%.2f, w=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->rgbw.r, sensor_data->rgbw.r, sensor_data->rgbw.b, sensor_data->rgbw.w); break; - case SENSOR_UV_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_UV_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x UV_DATA_READY - " "uv=%.2f, uva=%.2f, uvb=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->uv.uv, sensor_data->uv.uva, sensor_data->uv.uvb); break; - default: - ESP_LOGI(TAG, "Timestamp = %llu - event id = %d", sensor_data->timestamp, id); + ESP_LOGI(TAG, "Timestamp = %" PRIi64 " - event id = %" PRIi32, sensor_data->timestamp, id); break; } } diff --git a/components/sensors/sensor_hub/linker.lf b/components/sensors/sensor_hub/linker.lf new file mode 100644 index 000000000..398e2fc15 --- /dev/null +++ b/components/sensors/sensor_hub/linker.lf @@ -0,0 +1,13 @@ +[sections:sensors_detect] +entries: + .sensor_hub_detect_fn+ + +[scheme:sensors_detect_default] +entries: + sensors_detect -> flash_rodata + +[mapping:sensors_detect] +archive: * +entries: + * (sensors_detect_default); + sensors_detect -> flash_rodata KEEP() SURROUND(_sensor_hub_detect_fn_array) diff --git a/components/sensors/sensor_hub/test/CMakeLists.txt b/components/sensors/sensor_hub/test/CMakeLists.txt deleted file mode 100644 index bfaafadbb..000000000 --- a/components/sensors/sensor_hub/test/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -idf_component_register(SRC_DIRS "." - INCLUDE_DIRS "." - REQUIRES i2c_bus unity sensor_hub) diff --git a/components/sensors/sensor_hub/test/test_humiture_hal.c b/components/sensors/sensor_hub/test/test_humiture_hal.c deleted file mode 100644 index abeefe8ca..000000000 --- a/components/sensors/sensor_hub/test/test_humiture_hal.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "unity.h" -#include "driver/i2c.h" -#include "i2c_bus.h" -#include "hal/humiture_hal.h" -#include "esp_system.h" - -#define I2C_MASTER_SCL_IO 22 /*!< gpio number for I2C master clock */ -#define I2C_MASTER_SDA_IO 21 /*!< gpio number for I2C master data */ -#define I2C_MASTER_NUM I2C_NUM_1 /*!< I2C port number for master dev */ -#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */ - -static i2c_bus_handle_t i2c_bus = NULL; -static sensor_humiture_handle_t humiture_handle = NULL; -static humiture_id_t HUMITURE_ID_TEST = SHT3X_ID; -//static humiture_id_t HUMITURE_ID_TEST = HTS221_ID; - -static void humiture_test_get_data() -{ - int cnt = 10; - i2c_config_t conf = { - .mode = I2C_MODE_MASTER, - .sda_io_num = I2C_MASTER_SDA_IO, - .sda_pullup_en = GPIO_PULLUP_ENABLE, - .scl_io_num = I2C_MASTER_SCL_IO, - .scl_pullup_en = GPIO_PULLUP_ENABLE, - .master.clk_speed = I2C_MASTER_FREQ_HZ, - }; - i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf); - TEST_ASSERT(NULL != i2c_bus); - humiture_handle = humiture_create(i2c_bus, HUMITURE_ID_TEST); - TEST_ASSERT(NULL != humiture_handle); - vTaskDelay(100 / portTICK_RATE_MS); - TEST_ASSERT(ESP_OK == humiture_test(humiture_handle)); - - while (cnt--) { - float humidity = 0.0; - float temperature = 0.0; - printf("\n************* humiture sensor ************\n"); - humiture_acquire_humidity(humiture_handle, &humidity); - printf("humidity:%.2f\n", humidity); - humiture_acquire_temperature(humiture_handle, &temperature); - printf("temperature:%.2f\n", temperature); - printf("**************************************************\n"); - vTaskDelay(1000 / portTICK_RATE_MS); - } - humiture_delete(&humiture_handle); - TEST_ASSERT(NULL == humiture_handle); - i2c_bus_delete(&i2c_bus); - TEST_ASSERT(NULL == i2c_bus); -} - -TEST_CASE("Sensor humidity hal test get data [1000ms]", "[humiture_hal][iot][sensor_hal]") -{ - humiture_test_get_data(); -} diff --git a/components/sensors/sensor_hub/test/test_imu_hal.c b/components/sensors/sensor_hub/test/test_imu_hal.c deleted file mode 100644 index 2971122f6..000000000 --- a/components/sensors/sensor_hub/test/test_imu_hal.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "unity.h" -#include "driver/i2c.h" -#include "i2c_bus.h" -#include "hal/imu_hal.h" -#include "esp_system.h" - -#define I2C_MASTER_SCL_IO 22 /*!< gpio number for I2C master clock */ -#define I2C_MASTER_SDA_IO 21 /*!< gpio number for I2C master data */ -#define I2C_MASTER_NUM I2C_NUM_1 /*!< I2C port number for master dev */ -#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */ - -static i2c_bus_handle_t i2c_bus = NULL; -static sensor_imu_handle_t imu_handle = NULL; -static imu_id_t IMU_ID_TEST = MPU6050_ID; -//static imu_id_t IMU_ID_TEST = LIS2DH12_ID; - -static void imu_test_get_data() -{ - int cnt = 10; - i2c_config_t conf = { - .mode = I2C_MODE_MASTER, - .sda_io_num = I2C_MASTER_SDA_IO, - .sda_pullup_en = GPIO_PULLUP_ENABLE, - .scl_io_num = I2C_MASTER_SCL_IO, - .scl_pullup_en = GPIO_PULLUP_ENABLE, - .master.clk_speed = I2C_MASTER_FREQ_HZ, - }; - i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf); - TEST_ASSERT(NULL != i2c_bus); - imu_handle = imu_create(i2c_bus, IMU_ID_TEST); - TEST_ASSERT(NULL != imu_handle); - vTaskDelay(100 / portTICK_RATE_MS); - TEST_ASSERT(ESP_OK == imu_test(imu_handle)); - - while (cnt--) { - axis3_t acce = {0}; - axis3_t gyro = {0}; - printf("\n************* imu sensor************\n"); - imu_acquire_acce(imu_handle, &acce); - printf("acce_x:%.2f, acce_y:%.2f, acce_z:%.2f\n", acce.x, acce.y, acce.z); - imu_acquire_gyro(imu_handle, &gyro); - printf("gyro_x:%.2f, gyro_y:%.2f, gyro_z:%.2f\n", gyro.x, gyro.y, gyro.z); - printf("**************************************************\n"); - vTaskDelay(1000 / portTICK_RATE_MS); - } - imu_delete(&imu_handle); - TEST_ASSERT(NULL == imu_handle); - i2c_bus_delete(&i2c_bus); - TEST_ASSERT(NULL == i2c_bus); -} - -TEST_CASE("Sensor imu hal test get data [1000ms]", "[imu_hal][iot][sensor_hal]") -{ - imu_test_get_data(); -} diff --git a/components/sensors/sensor_hub/test/test_light_sensor_hal.c b/components/sensors/sensor_hub/test/test_light_sensor_hal.c deleted file mode 100644 index 54bff1d38..000000000 --- a/components/sensors/sensor_hub/test/test_light_sensor_hal.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "unity.h" -#include "driver/i2c.h" -#include "i2c_bus.h" -#include "hal/light_sensor_hal.h" -#include "esp_system.h" - -#define I2C_MASTER_SCL_IO 22 /*!< gpio number for I2C master clock */ -#define I2C_MASTER_SDA_IO 21 /*!< gpio number for I2C master data */ -#define I2C_MASTER_NUM I2C_NUM_1 /*!< I2C port number for master dev */ -#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */ - -static i2c_bus_handle_t i2c_bus = NULL; -static sensor_light_handle_t light_sensor_handle = NULL; -static light_sensor_id_t LIGHT_SENSOR_ID_TEST = BH1750_ID; -//static light_sensor_id_t LIGHT_SENSOR_ID_TEST = VEML6040_ID; -//static light_sensor_id_t LIGHT_SENSOR_ID_TEST = VEML6075_ID; - -static void light_sensor_test_get_data() -{ - int cnt = 10; - i2c_config_t conf = { - .mode = I2C_MODE_MASTER, - .sda_io_num = I2C_MASTER_SDA_IO, - .sda_pullup_en = GPIO_PULLUP_ENABLE, - .scl_io_num = I2C_MASTER_SCL_IO, - .scl_pullup_en = GPIO_PULLUP_ENABLE, - .master.clk_speed = I2C_MASTER_FREQ_HZ, - }; - i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf); - TEST_ASSERT(NULL != i2c_bus); - light_sensor_handle = light_sensor_create(i2c_bus, LIGHT_SENSOR_ID_TEST); - TEST_ASSERT(NULL != light_sensor_handle); - vTaskDelay(100 / portTICK_RATE_MS); - TEST_ASSERT(ESP_OK == light_sensor_test(light_sensor_handle)); - - while (cnt--) { - float light = 0.0; - uv_t uv = {0}; - rgbw_t rgbw = {0}; - printf("\n************* light sensor ************\n"); - if (ESP_OK == light_sensor_acquire_light(light_sensor_handle, &light)) { - printf("light illuminance:%.2f\n", light); - } - if (ESP_OK == light_sensor_acquire_rgbw(light_sensor_handle, &rgbw)) { - printf("red:%.2f green:%.2f blue:%.2f white:%.2f\n", rgbw.r, rgbw.g, rgbw.b, rgbw.w); - } - if (ESP_OK == light_sensor_acquire_uv(light_sensor_handle, &uv)) { - printf("UV:%.2f UVA:%.2f UVB:%.2f\n", uv.uv, uv.uva, uv.uvb); - } - printf("**************************************************\n"); - vTaskDelay(1000 / portTICK_RATE_MS); - } - light_sensor_delete(&light_sensor_handle); - TEST_ASSERT(NULL == light_sensor_handle); - i2c_bus_delete(&i2c_bus); - TEST_ASSERT(NULL == i2c_bus); -} - -TEST_CASE("Sensor light sensor hal test get data [1000ms]", "[light_sensor_hal][iot][sensor_hal]") -{ - light_sensor_test_get_data(); -} diff --git a/components/sensors/sensor_hub/test/test_sensor_hub.c b/components/sensors/sensor_hub/test/test_sensor_hub.c deleted file mode 100644 index a372273ba..000000000 --- a/components/sensors/sensor_hub/test/test_sensor_hub.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "unity.h" -#include "driver/i2c.h" -#include "i2c_bus.h" -#include "iot_sensor_hub.h" -#include "esp_log.h" - -#define I2C_MASTER_SCL_IO 22 /*!< gpio number for I2C master clock */ -#define I2C_MASTER_SDA_IO 21 /*!< gpio number for I2C master data */ -#define I2C_MASTER_NUM I2C_NUM_1 /*!< I2C port number for master dev */ -#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */ - -static i2c_bus_handle_t i2c_bus = NULL; -static sensor_handle_t imu_handle = NULL; -static sensor_handle_t humiture_handle = NULL; -static sensor_handle_t light_handle = NULL; -static sensor_event_handler_instance_t imu_handler_handle = NULL; -static sensor_event_handler_instance_t humiture_handler_handle = NULL; -static sensor_event_handler_instance_t light_handler_handle = NULL; -static sensor_id_t SENSOR_ID_1 = SENSOR_MPU6050_ID; -static sensor_id_t SENSOR_ID_2 = SENSOR_SHT3X_ID; -static sensor_id_t SENSOR_ID_3 = SENSOR_BH1750_ID; - -static const char* TAG = "sensor_hub_test"; - -static void sensor_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) -{ - sensor_data_t *sensor_data = (sensor_data_t *)event_data; - sensor_type_t sensor_type = (sensor_type_t)((sensor_data->sensor_id) >> 4 & SENSOR_ID_MASK); - - if (sensor_type >= SENSOR_TYPE_MAX) { - ESP_LOGE(TAG, "sensor_id invalid, id=%d", sensor_data->sensor_id); - return; - } - switch (id) { - case SENSOR_STARTED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STARTED", - sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); - break; - case SENSOR_STOPED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STOPED", - sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); - break; - case SENSOR_HUMI_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_HUMI_DATA_READY - " - "humiture=%.2f", - sensor_data->timestamp, - sensor_data->humidity); - break; - case SENSOR_TEMP_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_TEMP_DATA_READY - " - "temperature=%.2f\n", - sensor_data->timestamp, - sensor_data->temperature); - break; - case SENSOR_ACCE_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_ACCE_DATA_READY - " - "acce_x=%.2f, acce_y=%.2f, acce_z=%.2f\n", - sensor_data->timestamp, - sensor_data->acce.x, sensor_data->acce.y, sensor_data->acce.z); - break; - case SENSOR_GYRO_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_GYRO_DATA_READY - " - "gyro_x=%.2f, gyro_y=%.2f, gyro_z=%.2f\n", - sensor_data->timestamp, - sensor_data->gyro.x, sensor_data->gyro.y, sensor_data->gyro.z); - break; - case SENSOR_LIGHT_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_LIGHT_DATA_READY - " - "light=%.2f", - sensor_data->timestamp, - sensor_data->light); - break; - case SENSOR_RGBW_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_RGBW_DATA_READY - " - "r=%.2f, g=%.2f, b=%.2f, w=%.2f\n", - sensor_data->timestamp, - sensor_data->rgbw.r, sensor_data->rgbw.r, sensor_data->rgbw.b, sensor_data->rgbw.w); - break; - case SENSOR_UV_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_UV_DATA_READY - " - "uv=%.2f, uva=%.2f, uvb=%.2f\n", - sensor_data->timestamp, - sensor_data->uv.uv, sensor_data->uv.uva, sensor_data->uv.uvb); - break; - default: - ESP_LOGI(TAG, "Timestamp = %llu - event id = %d", sensor_data->timestamp, id); - break; - } -} - -static void imu_test_get_data() -{ - i2c_config_t conf = { - .mode = I2C_MODE_MASTER, - .sda_io_num = I2C_MASTER_SDA_IO, - .sda_pullup_en = GPIO_PULLUP_ENABLE, - .scl_io_num = I2C_MASTER_SCL_IO, - .scl_pullup_en = GPIO_PULLUP_ENABLE, - .master.clk_speed = I2C_MASTER_FREQ_HZ, - }; - i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf); - TEST_ASSERT(i2c_bus != NULL); - - sensor_config_t sensor_conf = { - .bus = i2c_bus, - .mode = MODE_POLLING, - .min_delay = 200, /**< name of the event loop task; if NULL,a dedicated task is not created for sensor*/ - }; - - TEST_ASSERT(ESP_OK == iot_sensor_create(SENSOR_ID_1, &sensor_conf, &imu_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_create(SENSOR_ID_2, &sensor_conf, &humiture_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_create(SENSOR_ID_3, &sensor_conf, &light_handle)); - TEST_ASSERT(NULL != imu_handle); - TEST_ASSERT(NULL != humiture_handle); - TEST_ASSERT(NULL != light_handle); - TEST_ASSERT(ESP_OK == iot_sensor_handler_register(imu_handle, sensor_event_handler, &imu_handler_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_handler_register(humiture_handle, sensor_event_handler, &humiture_handler_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_handler_register(light_handle, sensor_event_handler, &light_handler_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_start(imu_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_start(humiture_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_start(light_handle)); - vTaskDelay(10000 / portTICK_RATE_MS); - TEST_ASSERT(ESP_OK == iot_sensor_stop(imu_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_stop(humiture_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_stop(light_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(imu_handle, imu_handler_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(humiture_handle, humiture_handler_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(light_handle, light_handler_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_delete(&imu_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_delete(&humiture_handle)); - TEST_ASSERT(ESP_OK == iot_sensor_delete(&light_handle)); - TEST_ASSERT(NULL == imu_handle); - TEST_ASSERT(NULL == humiture_handle); - TEST_ASSERT(NULL == light_handle); - TEST_ASSERT(ESP_OK == i2c_bus_delete(&i2c_bus)); - TEST_ASSERT(NULL == i2c_bus); -} - -TEST_CASE("SENSOR_HUB test get data [200ms]", "[imu_handle][iot][sensor]") -{ - imu_test_get_data(); -} diff --git a/components/sensors/sensor_hub/test_apps/CMakeLists.txt b/components/sensors/sensor_hub/test_apps/CMakeLists.txt new file mode 100644 index 000000000..680464edb --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/CMakeLists.txt @@ -0,0 +1,9 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components" + "../../sensor_hub") + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(sensor_hub_test) diff --git a/components/sensors/sensor_hub/test_apps/main/CMakeLists.txt b/components/sensors/sensor_hub/test_apps/main/CMakeLists.txt new file mode 100644 index 000000000..c878c97fd --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/main/CMakeLists.txt @@ -0,0 +1,15 @@ +idf_component_register(SRC_DIRS "." + PRIV_INCLUDE_DIRS "." + PRIV_REQUIRES unity test_utils sensor_hub) + +if(CONFIG_SENSOR_INCLUDED_HUMITURE) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u virtual_humiture_init") +endif() + +if(CONFIG_SENSOR_INCLUDED_IMU) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u virtual_imu_init") +endif() + +if(CONFIG_SENSOR_INCLUDED_LIGHT) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u virtual_light_init") +endif() diff --git a/components/sensors/sensor_hub/test_apps/main/sensor_hub_test.c b/components/sensors/sensor_hub/test_apps/main/sensor_hub_test.c new file mode 100644 index 000000000..feaa8b938 --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/main/sensor_hub_test.c @@ -0,0 +1,227 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "unity.h" +#include "iot_sensor_hub.h" +#include "esp_log.h" + +#define TEST_MEMORY_LEAK_THRESHOLD (-460) + +#define I2C_MASTER_SCL_IO 2 /*!< gpio number for I2C master clock */ +#define I2C_MASTER_SDA_IO 1 /*!< gpio number for I2C master data */ +#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */ +#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */ + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static i2c_bus_handle_t i2c_bus = NULL; +static sensor_handle_t sht3x_handle1 = NULL; +static sensor_handle_t sht3x_handle2 = NULL; +static sensor_handle_t mpu6050_handle = NULL; +static sensor_handle_t bh1750_handle = NULL; +static sensor_event_handler_instance_t sht3x_handler_handle1 = NULL; +static sensor_event_handler_instance_t sht3x_handler_handle2 = NULL; +static sensor_event_handler_instance_t mpu6050_handler_handle = NULL; +static sensor_event_handler_instance_t bh1750_handler_handle = NULL; + +static const char* TAG = "sensor_hub_test"; + +static void sensor_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) +{ + sensor_data_t *sensor_data = (sensor_data_t *)event_data; + + switch (id) { + case SENSOR_STARTED: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STARTED", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr); + break; + case SENSOR_STOPED: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STOPPED", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr); + break; + case SENSOR_HUMI_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x HUMI_DATA_READY - " + "humiture=%.2f", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->humidity); + break; + case SENSOR_TEMP_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x TEMP_DATA_READY - " + "temperature=%.2f\n", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->temperature); + break; + case SENSOR_ACCE_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x ACCE_DATA_READY - " + "acce_x=%.2f, acce_y=%.2f, acce_z=%.2f\n", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->acce.x, sensor_data->acce.y, sensor_data->acce.z); + break; + case SENSOR_GYRO_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x GYRO_DATA_READY - " + "gyro_x=%.2f, gyro_y=%.2f, gyro_z=%.2f\n", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->gyro.x, sensor_data->gyro.y, sensor_data->gyro.z); + break; + case SENSOR_LIGHT_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x LIGHT_DATA_READY - " + "light=%.2f", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->light); + break; + case SENSOR_RGBW_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x RGBW_DATA_READY - " + "r=%.2f, g=%.2f, b=%.2f, w=%.2f\n", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->rgbw.r, sensor_data->rgbw.r, sensor_data->rgbw.b, sensor_data->rgbw.w); + break; + case SENSOR_UV_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x UV_DATA_READY - " + "uv=%.2f, uva=%.2f, uvb=%.2f\n", + sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->uv.uv, sensor_data->uv.uva, sensor_data->uv.uvb); + break; + default: + ESP_LOGI(TAG, "Timestamp = %" PRIi64 " - event id = %" PRIi32, sensor_data->timestamp, id); + break; + } +} + +TEST_CASE("SENSOR_HUB test for virtual sensors", "[virtual sensors][iot]") +{ + i2c_config_t conf = { + .mode = I2C_MODE_MASTER, + .sda_io_num = I2C_MASTER_SDA_IO, + .sda_pullup_en = GPIO_PULLUP_ENABLE, + .scl_io_num = I2C_MASTER_SCL_IO, + .scl_pullup_en = GPIO_PULLUP_ENABLE, + .master.clk_speed = I2C_MASTER_FREQ_HZ, + }; + i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf); + TEST_ASSERT(i2c_bus != NULL); + + sensor_config_t virtual_sht3x_config1 = { + .bus = i2c_bus, + .addr = 0x44, + .type = HUMITURE_ID, + .mode = MODE_POLLING, + .min_delay = 100, + }; + TEST_ASSERT(ESP_OK == iot_sensor_create("virtual_sht3x", &virtual_sht3x_config1, &sht3x_handle1)); + + sensor_config_t virtual_sht3x_config2 = { + .bus = i2c_bus, + .addr = 0x5F, + .type = HUMITURE_ID, + .mode = MODE_POLLING, + .min_delay = 200, + }; + TEST_ASSERT(ESP_OK == iot_sensor_create("virtual_sht3x", &virtual_sht3x_config2, &sht3x_handle2)); + + sensor_config_t virtual_mpu6050_config = { + .bus = i2c_bus, + .addr = 0x68, + .type = IMU_ID, + .mode = MODE_POLLING, + .min_delay = 300, + }; + TEST_ASSERT(ESP_OK == iot_sensor_create("virtual_mpu6050", &virtual_mpu6050_config, &mpu6050_handle)); + + sensor_config_t virtual_bh1750_config = { + .bus = i2c_bus, + .addr = 0x23, + .type = LIGHT_SENSOR_ID, + .mode = MODE_POLLING, + .min_delay = 400, + }; + TEST_ASSERT(ESP_OK == iot_sensor_create("virtual_bh1750", &virtual_bh1750_config, &bh1750_handle)); + + TEST_ASSERT(NULL != sht3x_handle1); + TEST_ASSERT(NULL != sht3x_handle2); + TEST_ASSERT(NULL != mpu6050_handle); + TEST_ASSERT(NULL != bh1750_handle); + + TEST_ASSERT(ESP_OK == iot_sensor_handler_register(sht3x_handle1, sensor_event_handler, &sht3x_handler_handle1)); + TEST_ASSERT(ESP_OK == iot_sensor_handler_register(sht3x_handle2, sensor_event_handler, &sht3x_handler_handle2)); + TEST_ASSERT(ESP_OK == iot_sensor_handler_register(mpu6050_handle, sensor_event_handler, &mpu6050_handler_handle)); + TEST_ASSERT(ESP_OK == iot_sensor_handler_register(bh1750_handle, sensor_event_handler, &bh1750_handler_handle)); + TEST_ASSERT(ESP_OK == iot_sensor_start(sht3x_handle1)); + TEST_ASSERT(ESP_OK == iot_sensor_start(sht3x_handle2)); + TEST_ASSERT(ESP_OK == iot_sensor_start(mpu6050_handle)); + TEST_ASSERT(ESP_OK == iot_sensor_start(bh1750_handle)); + vTaskDelay(2000 / portTICK_RATE_MS); + TEST_ASSERT(ESP_OK == iot_sensor_stop(sht3x_handle1)); + TEST_ASSERT(ESP_OK == iot_sensor_stop(sht3x_handle2)); + TEST_ASSERT(ESP_OK == iot_sensor_stop(mpu6050_handle)); + TEST_ASSERT(ESP_OK == iot_sensor_stop(bh1750_handle)); + vTaskDelay(100 / portTICK_RATE_MS); + TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(sht3x_handle1, sht3x_handler_handle1)); + TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(sht3x_handle2, sht3x_handler_handle2)); + TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(mpu6050_handle, mpu6050_handler_handle)); + TEST_ASSERT(ESP_OK == iot_sensor_handler_unregister(bh1750_handle, bh1750_handler_handle)); + + TEST_ASSERT(ESP_OK == iot_sensor_delete(sht3x_handle1)); + TEST_ASSERT(ESP_OK == iot_sensor_delete(sht3x_handle2)); + TEST_ASSERT(ESP_OK == iot_sensor_delete(mpu6050_handle)); + TEST_ASSERT(ESP_OK == iot_sensor_delete(bh1750_handle)); + TEST_ASSERT(ESP_OK == i2c_bus_delete(&i2c_bus)); + TEST_ASSERT(NULL == i2c_bus); +} + +TEST_CASE("SENSOR_HUB scan driver", "[virtual sensors][drivers][iot]") +{ + iot_sensor_scan(); +} + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + printf("SENSOR HUB TEST \n"); + unity_run_menu(); +} diff --git a/components/sensors/sensor_hub/test_apps/main/virtual_humiture_sensor.c b/components/sensors/sensor_hub/test_apps/main/virtual_humiture_sensor.c new file mode 100644 index 000000000..3ee1ef31c --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/main/virtual_humiture_sensor.c @@ -0,0 +1,49 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "iot_sensor_hub.h" +#include "esp_err.h" +#include "esp_random.h" + +#ifdef CONFIG_SENSOR_INCLUDED_HUMITURE + +esp_err_t virtual_humiture_init(i2c_bus_handle_t i2c_bus, uint8_t addr) +{ + return ESP_OK; +} + +esp_err_t virtual_humiture_deinit(void) +{ + return ESP_OK; +} + +esp_err_t virtual_humiture_test(void) +{ + return ESP_OK; +} + +esp_err_t virtual_humiture_acquire_humidity(float *h) +{ + *h = ((float)esp_random() / UINT32_MAX) * 100.0f; + return ESP_OK; +} + +esp_err_t virtual_humiture_acquire_temperature(float *t) +{ + *t = ((float)esp_random() / UINT32_MAX) * 100.0f; + return ESP_OK; +} + +static humiture_impl_t virtual_sht3x_impl = { + .init = virtual_humiture_init, + .deinit = virtual_humiture_deinit, + .test = virtual_humiture_test, + .acquire_humidity = virtual_humiture_acquire_humidity, + .acquire_temperature = virtual_humiture_acquire_temperature, +}; + +SENSOR_HUB_DETECT_FN(HUMITURE_ID, virtual_sht3x, &virtual_sht3x_impl); + +#endif diff --git a/components/sensors/sensor_hub/test_apps/main/virtual_imu_sensor.c b/components/sensors/sensor_hub/test_apps/main/virtual_imu_sensor.c new file mode 100644 index 000000000..0f8230ab1 --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/main/virtual_imu_sensor.c @@ -0,0 +1,54 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "iot_sensor_hub.h" +#include "esp_err.h" +#include "esp_random.h" + +#ifdef CONFIG_SENSOR_INCLUDED_IMU + +esp_err_t virtual_imu_init(i2c_bus_handle_t i2c_bus, uint8_t addr) +{ + return ESP_OK; +} + +esp_err_t virtual_imu_deinit(void) +{ + return ESP_OK; +} + +esp_err_t virtual_imu_test(void) +{ + return ESP_OK; +} + +esp_err_t virtual_imu_acquire_acce(float *acce_x, float *acce_y, float *acce_z) +{ + *acce_x = ((float)esp_random() / UINT32_MAX) * 100.0f - 50.0f; + *acce_y = ((float)esp_random() / UINT32_MAX) * 100.0f - 50.0f; + *acce_z = ((float)esp_random() / UINT32_MAX) * 100.0f - 50.0f; + + return ESP_OK; +} + +esp_err_t virtual_imu_acquire_gyro(float *gyro_x, float *gyro_y, float *gyro_z) +{ + *gyro_x = ((float)esp_random() / UINT32_MAX) * 5000.0f - 2500.0f; + *gyro_y = ((float)esp_random() / UINT32_MAX) * 5000.0f - 2500.0f; + *gyro_z = ((float)esp_random() / UINT32_MAX) * 5000.0f - 2500.0f; + return ESP_OK; +} + +static imu_impl_t virtual_mpu6050_impl = { + .init = virtual_imu_init, + .deinit = virtual_imu_deinit, + .test = virtual_imu_test, + .acquire_acce = virtual_imu_acquire_acce, + .acquire_gyro = virtual_imu_acquire_gyro, +}; + +SENSOR_HUB_DETECT_FN(IMU_ID, virtual_mpu6050, &virtual_mpu6050_impl); + +#endif diff --git a/components/sensors/sensor_hub/test_apps/main/virtual_light_sensor.c b/components/sensors/sensor_hub/test_apps/main/virtual_light_sensor.c new file mode 100644 index 000000000..c1d55d748 --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/main/virtual_light_sensor.c @@ -0,0 +1,61 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "iot_sensor_hub.h" +#include "esp_err.h" +#include "esp_random.h" + +#ifdef CONFIG_SENSOR_INCLUDED_LIGHT + +esp_err_t virtual_light_init(i2c_bus_handle_t i2c_bus, uint8_t addr) +{ + return ESP_OK; +} + +esp_err_t virtual_light_deinit(void) +{ + return ESP_OK; +} + +esp_err_t virtual_light_test(void) +{ + return ESP_OK; +} + +esp_err_t virtual_light_acquire_light(float* l) +{ + *l = ((float)esp_random() / UINT32_MAX) * 1000.0f; + return ESP_OK; +} + +esp_err_t virtual_light_acquire_rgbw(float* r, float* g, float* b, float* w) +{ + *r = ((float)esp_random() / UINT32_MAX) * 255.0f; + *g = ((float)esp_random() / UINT32_MAX) * 255.0f; + *b = ((float)esp_random() / UINT32_MAX) * 255.0f; + *w = ((float)esp_random() / UINT32_MAX) * 255.0f; + return ESP_OK; +} + +esp_err_t virtual_light_acquire_uv(float* uv, float* uva, float* uvb) +{ + *uv = ((float)esp_random() / UINT32_MAX) * 1000.0f; + *uva = ((float)esp_random() / UINT32_MAX) * 1000.0f; + *uvb = ((float)esp_random() / UINT32_MAX) * 1000.0f; + return ESP_OK; +} + +static light_impl_t virtual_bh1750_impl = { + .init = virtual_light_init, + .deinit = virtual_light_deinit, + .test = virtual_light_test, + .acquire_light = virtual_light_acquire_light, + .acquire_rgbw = virtual_light_acquire_rgbw, + .acquire_uv = virtual_light_acquire_uv, +}; + +SENSOR_HUB_DETECT_FN(LIGHT_SENSOR_ID, virtual_bh1750, &virtual_bh1750_impl); + +#endif diff --git a/components/sensors/sensor_hub/test_apps/sdkconfig.defaults b/components/sensors/sensor_hub/test_apps/sdkconfig.defaults new file mode 100644 index 000000000..50b0b716a --- /dev/null +++ b/components/sensors/sensor_hub/test_apps/sdkconfig.defaults @@ -0,0 +1,14 @@ +# For IDF 5.0 +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT_EN=n + +# For IDF4.4 +CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP_TASK_WDT=n + +# For Sensor hub +CONFIG_SENSOR_INCLUDED_IMU=y +CONFIG_SENSOR_INCLUDED_HUMITURE=y +CONFIG_SENSOR_INCLUDED_LIGHT=y diff --git a/docs/en/sensors/sensor_hub.rst b/docs/en/sensors/sensor_hub.rst index 69511d607..34661ed39 100644 --- a/docs/en/sensors/sensor_hub.rst +++ b/docs/en/sensors/sensor_hub.rst @@ -10,7 +10,7 @@ Sensor Hub is a sensor management component that can realize hardware abstractio Sensor Hub Programming Model -The Sensor Hub provides hardware abstraction for common sensor categories, based on which users can switch sensor models without modifying the upper layer of the application. And it allows adding new sensors to the Sensor Hub by implementing their corresponding sensor interface at hardware abstraction layer. This component can be used as a basic component for sensor applications in various intelligent scenarios such as environment monitoring, motion detection, health management and etc. as it simplifies operation and improves operating efficiency by centralized management of sensors. +Sensor Hub supports loading sensor drivers as components. Users only need to input the name of the sensor registered with the Sensor Hub to directly access the corresponding sensor driver. Additionally, as this component enables centralized management of sensors, it not only simplifies operations but also improves operational efficiency. It can serve as a foundational component for sensor applications and can be applied to various intelligent scenarios such as environmental sensing, motion sensing, health management, and more. .. figure:: ../../_static/sensor_hub.png :align: center @@ -21,23 +21,53 @@ The Sensor Hub provides hardware abstraction for common sensor categories, based Instructions ------------------- -1. Create a sensor instance: use :cpp:func:`iot_sensor_create` to create a sensor instance. The related parameters include the sensor ID defined in ``sensor_id_t``, configuration options for the sensor and its handler pointer. The sensor ID is used to find and load the corresponding driver, and each ID can only be used for one sensor instance. In configuration options, `bus` is used to specify the bus location on which the sensor is mounted; `mode` is used to specify the operating mode of the sensor; `min_delay` is used to specify the acquisition interval of the sensor, while other items inside are all non-required options. After the instance is created, the sensor handler is obtained; +``sensor_hub`` uses the `linker script generation mechanism `_ to register sensor drivers into specific target file sections. For application developers, there is no need to focus on the specific implementation of the sensor drivers; simply adding the corresponding sensor component will load the respective driver. -2. Register callback functions for sensor events: when a sensor event occurs, the callback functions will be called in sequence. There are two ways to register a callback function, and the instance handler of the event callback function will be returned after the registration succeed: +Driver developer: +^^^^^^^^^^^^^^^^^^^ + +Taking the ``ShT3X`` temperature and humidity sensor as an example, driver developers need to populate the ``humiture_impl_t`` structure with operations related to the sensor and create a sensor detection function. ``sensor_hub`` provides a sensor registration interface: ``SENSOR_HUB_DETECT_FN``, where driver developers can directly insert the corresponding functions into the registration interface. + +.. code-block:: c + + static humiture_impl_t sht3x_impl = { + .init = humiture_sht3x_init, + .deinit = humiture_sht3x_deinit, + .test = humiture_sht3x_test, + .acquire_humidity = humiture_sht3x_acquire_humidity, + .acquire_temperature = humiture_sht3x_acquire_temperature, + }; + + SENSOR_HUB_DETECT_FN(HUMITURE_ID, sht3x, &sht3x_impl); + +At the same time, add the interface dependency in the component's ``CMakeLists.txt``: + +.. code-block:: cmake + + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u humiture_sht3x_init") + +Application developer +^^^^^^^^^^^^^^^^^^^^^^^ + +1. Add ``sensor_hub`` and the required sensor components in the project's ``idf_component.yml``. + +2. Create a sensor instance: Use :cpp:func:`iot_sensor_create` to create a sensor instance. The parameters include the sensor name, sensor configuration options, and a pointer to the sensor handle. The sensor name is used to locate and load the driver registered in the ``sensor_hub``. If the sensor supports configurable addresses, multiple instances of the same sensor name can be created. In the configuration options, ``bus`` specifies the bus to which the sensor is mounted; ``addr`` specifies the address corresponding to the sensor; ``type`` specifies the type of the sensor ; ``mode`` specifies the operating mode of the sensor; and ``min_delay`` specifies the sensor's data collection interval. Other options are optional. Upon successful creation, the sensor handle is obtained. + +3. Register callback functions for sensor events: when a sensor event occurs, the callback functions will be called in sequence. There are two ways to register a callback function, and the instance handler of the event callback function will be returned after the registration succeed: - Use :cpp:func:`iot_sensor_handler_register` to register a callback function with the sensor handler - Use :cpp:func:`iot_sensor_handler_register_with_type` to register a callback function with the sensor type -3. Start a sensor: use :cpp:func:`iot_sensor_start` to start a specific sensor. After started, it will trigger a ``SENSOR_STARTED`` event, then it will collect the sensor data continuously with a set of period and trigger ``SENSOR_XXXX_DATA_READY`` event. The event callback function can obtain the specific data of each event via the ``event_data`` parameter; +4. Start a sensor: use :cpp:func:`iot_sensor_start` to start a specific sensor. After started, it will trigger a ``SENSOR_STARTED`` event, then it will collect the sensor data continuously with a set of period and trigger ``SENSOR_XXXX_DATA_READY`` event. The event callback function can obtain the specific data of each event via the ``event_data`` parameter; -4. Stop a sensor: use :cpp:func:`iot_sensor_stop` to stop a specified sensor temporarily. After stopped, the sensor will send out a ``SENSOR_STOPED`` event and then stop the data collecting work. If the driver of this sensor supports power management, the sensor will be set to sleep mode in this stage; +5. Stop a sensor: use :cpp:func:`iot_sensor_stop` to stop a specified sensor temporarily. After stopped, the sensor will send out a ``SENSOR_STOPED`` event and then stop the data collecting work. If the driver of this sensor supports power management, the sensor will be set to sleep mode in this stage; -5. Unregister callback functions for sensor events: the user program can unregister an event at any time using the instance handler of this event callback function, and this callback function will not be called again when this event occurs afterwards. There are also two ways to do so: +6. Unregister callback functions for sensor events: the user program can unregister an event at any time using the instance handler of this event callback function, and this callback function will not be called again when this event occurs afterwards. There are also two ways to do so: - Use :cpp:func:`iot_sensor_handler_unregister` to unregister the callback function with the sensor handler - Use :cpp:func:`iot_sensor_handler_unregister_with_type` to unregister the callback function with the sensor type -6. Delete sensors: use :cpp:func:`iot_sensor_delete` to delete the corresponding sensor to release the allocated memory and other resources. +7. Delete sensors: use :cpp:func:`iot_sensor_delete` to delete the corresponding sensor to release the allocated memory and other resources. Examples -------------- diff --git a/docs/zh_CN/sensors/sensor_hub.rst b/docs/zh_CN/sensors/sensor_hub.rst index 367a28f3b..d036ff09f 100644 --- a/docs/zh_CN/sensors/sensor_hub.rst +++ b/docs/zh_CN/sensors/sensor_hub.rst @@ -10,8 +10,7 @@ Sensor Hub 是一个传感器管理组件,可以实现对传感器设备的硬 Sensor Hub 编程模型 -Sensor Hub 对常见的传感器类别进行了硬件抽象,用户在切换传感器型号时,无需修改上层应用程序, -也可以通过实现硬件抽象层的传感器接口添加新的传感器到 Sensor Hub 中。该组件由于实现了对传感器的集中管理,在简化操作的同时也提高了运行效率,可作为传感器应用的基础组件,应用在环境感知、运动感知、健康管理等更多智能化场景中。 +Sensor Hub 支持以组件方式加载传感器驱动,用户在添加传感器时只需填入注册到 Sensor Hub 的传感器名称即可直接获取对应的传感器驱动。此外,该组件由于实现了对传感器的集中管理,在简化操作的同时也提高了运行效率,可作为传感器应用的基础组件,应用在环境感知、运动感知、健康管理等更多智能化场景中。 .. figure:: ../../_static/sensor_hub.png :align: center @@ -22,28 +21,68 @@ Sensor Hub 对常见的传感器类别进行了硬件抽象,用户在切换传 Sensor Hub 使用方法 ------------------------ -1. 创建一个传感器实例:使用 :cpp:func:`iot_sensor_create` 创建一个传感器实例,参数包括 ``sensor_id_t`` 中定义的传感器 ID、传感器配置项和传感器句柄指针。传感器 ID 用于查找和加载对应的驱动,一个 ID 只能对应创建一个实例。配置项中 `bus` 用于指定传感器挂载到的总线位置;`mode` 用于指定传感器的工作模式;`min_delay` 用于指定传感器的采集间隔,其它均为非必须项。创建成功之后,获得该传感器句柄; +``sensor_hub`` 采用 `链接器脚本生成机制 `_ 将传感器驱动注册到特定的目标文件段中。对于应用开发者而言,无需关注传感器驱动的具体实现,只需添加对应的传感器组件即可加载对应的驱动。 -2. 注册传感器事件回调函数:在传感器事件发生时,回调函数将会被依次调用,注册回调函数的方法有以下两种,注册成功之后将返回事件回调函数实例句柄: +驱动开发者: +^^^^^^^^^^^^^ + +以 ``ShT3X`` 温湿度传感器为例,驱动开发者需要将与传感器相关的操作填入到 ``humiture_impl_t``,并创建传感器检测函数。``sensor_hub`` 提供了用于传感器注册接口:``SENSOR_HUB_DETECT_FN``,驱动开发者可以直接将对应的函数填入到注册接口中。 + +.. code-block:: c + + static humiture_impl_t sht3x_impl = { + .init = humiture_sht3x_init, + .deinit = humiture_sht3x_deinit, + .test = humiture_sht3x_test, + .acquire_humidity = humiture_sht3x_acquire_humidity, + .acquire_temperature = humiture_sht3x_acquire_temperature, + }; + + SENSOR_HUB_DETECT_FN(HUMITURE_ID, sht3x, &sht3x_impl); + +同时,在组件的 ``CMakeLists.txt`` 中添加接口依赖: + +.. code-block:: cmake + + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u humiture_sht3x_init") + +应用开发者: +^^^^^^^^^^^^^ + +1. 在工程的 ``idf_component.yml`` 中添加 ``sensor_hub`` 与所需的传感器组件。 + +2. 创建一个传感器实例:使用 :cpp:func:`iot_sensor_create` 创建一个传感器实例,参数包括传感器名称、传感器配置项和传感器句柄指针。传感器名称用于查找和加载注册到 ``sensor_hub`` 中的传感器的驱动,若传感器支持地址可配置,则可以多次创建该名称的传感器。配置项中 ``bus`` 用于指定传感器挂载到的总线位置;``addr`` 用于指定传感器对应的地址;``type`` 用于指定传感器对应的类型;``mode`` 用于指定传感器的工作模式;``min_delay`` 用于指定传感器的采集间隔,其它均为非必须项。创建成功之后,获得该传感器句柄; + +.. code-block:: c + + sensor_config_t sht3x_config = { + .bus = i2c0_bus_handle, + .addr = 0x44, + .mode = MODE_POLLING, + .min_delay = SENSOR_PERIOD, + }; + iot_sensor_create("sht3x", &sht3x_config, &sht3x_handle) + +3. 注册传感器事件回调函数:在传感器事件发生时,回调函数将会被依次调用,注册回调函数的方法有以下两种,注册成功之后将返回事件回调函数实例句柄: - 使用 :cpp:func:`iot_sensor_handler_register` 通过传感器句柄注册回调函数 - 使用 :cpp:func:`iot_sensor_handler_register_with_type` 通过传感器类型注册回调函数 -3. 启动传感器:使用 :cpp:func:`iot_sensor_start` 启动指定的传感器,传感器启动之后将发出 ``SENSOR_STARTED`` 事件,之后将以设定的周期持续采集传感器数据,并发送 ``SENSOR_XXXX_DATA_READY`` 事件。事件回调函数可通过 ``event_data`` 参数获取每一个事件的具体数据; +4. 启动传感器:使用 :cpp:func:`iot_sensor_start` 启动指定的传感器,传感器启动之后将发出 ``SENSOR_STARTED`` 事件,之后将以设定的周期持续采集传感器数据,并发送 ``SENSOR_XXXX_DATA_READY`` 事件。事件回调函数可通过 ``event_data`` 参数获取每一个事件的具体数据; -4. 停止传感器:使用 :cpp:func:`iot_sensor_stop` 可临时关闭指定的传感器,传感器关闭之后将发出 ``SENSOR_STOPED`` 事件,之后采集工作将停止。如果该传感器驱动支持电源管理,传感器将被设置为睡眠模式; +5. 停止传感器:使用 :cpp:func:`iot_sensor_stop` 可临时关闭指定的传感器,传感器关闭之后将发出 ``SENSOR_STOPED`` 事件,之后采集工作将停止。如果该传感器驱动支持电源管理,传感器将被设置为睡眠模式; -5. 取消注册传感器事件回调函数:用户程序可在任意时刻使用事件回调函数实例句柄取消对事件的注册,之后该事件发生时,该回调函数将不再被调用。取消注册的方法对应也有两种: +6. 取消注册传感器事件回调函数:用户程序可在任意时刻使用事件回调函数实例句柄取消对事件的注册,之后该事件发生时,该回调函数将不再被调用。取消注册的方法对应也有两种: - 使用 :cpp:func:`iot_sensor_handler_unregister` 通过传感器句柄取消已注册的回调函数 - 使用 :cpp:func:`iot_sensor_handler_unregister_with_type` 通过传感器类型取消已经注册的回调函数 -6. 删除传感器:使用 :cpp:func:`iot_sensor_delete` 可删除对应的传感器,释放已分配的内存等资源。 +7. 删除传感器:使用 :cpp:func:`iot_sensor_delete` 可删除对应的传感器,释放已分配的内存等资源。 示例程序 -------- -1. 光照传感器控制 LED 开关示例::example:`sensors/sensor_control_led`。 +1. 温湿度传感器控制 LED 开关示例::example:`sensors/sensor_control_led`。 2. 传感器监测示例::example:`sensors/sensor_hub_monitor`。 API 参考 diff --git a/examples/sensors/sensor_control_led/CMakeLists.txt b/examples/sensors/sensor_control_led/CMakeLists.txt index 0fc16dcd9..3f4b2ecf6 100644 --- a/examples/sensors/sensor_control_led/CMakeLists.txt +++ b/examples/sensors/sensor_control_led/CMakeLists.txt @@ -1,20 +1,6 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) - -#If IOT_SOLUTION_PATH is not defined, use relative path as default value -if(NOT DEFINED ENV{IOT_SOLUTION_PATH}) - get_filename_component(IOT_SOLUTION_PATH "${CMAKE_SOURCE_DIR}/../../.." ABSOLUTE) - set(ENV{IOT_SOLUTION_PATH} ${IOT_SOLUTION_PATH}) - message(WARNING "IOT_SOLUTION_PATH not set, using default $ENV{IOT_SOLUTION_PATH}") -endif() - -set(EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS} - $ENV{IOT_SOLUTION_PATH}/components/sensors/sensor_hub - $ENV{IOT_SOLUTION_PATH}/components/sensors/humiture/hts221 - $ENV{IOT_SOLUTION_PATH}/components/sensors/imu/mpu6050 - ) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(sensors_monitor) diff --git a/examples/sensors/sensor_control_led/README_cn.md b/examples/sensors/sensor_control_led/README_cn.md index ee87cc487..dcfd4f930 100644 --- a/examples/sensors/sensor_control_led/README_cn.md +++ b/examples/sensors/sensor_control_led/README_cn.md @@ -1,18 +1,18 @@ ## 传感器控制 LED -本示例演示了如何在 `esp32-meshkit-sense` 开发板上使用 `sensor_hub` 组件快速开发一个光照传感器控制 LED 灯的应用程序,`sensor_hub` 可以帮助用户处理底层传感器的复杂实现,通过事件消息将数据包发送给应用程序,大大降低了传感器应用的开发难度。 +本示例演示了如何在 `esp32-meshkit-sense` 开发板上使用 `sensor_hub` 组件快速开发一个温湿度传感器控制 LED 灯的应用程序,`sensor_hub` 可以帮助用户处理底层传感器的复杂实现,通过事件消息将数据包发送给应用程序,大大降低了传感器应用的开发难度。 ## 如何使用该示例 ### 硬件需求 1. 本示例默认使用 `common_components/boards` 组件中包含的 `esp32-meshkit-sense` 开发板,您也可根据 `examples/common_components/boards/esp32-meshkit-sense/iot_board.h` 中的开发板引脚定义使用任意 `ESP32` 或 `ESP32S2` 开发板实现; -2. 本示例默认使用 `sensor_hub` 中已支持光线传感器 `BH1750` ( `sensor_id = SENSOR_BH1750_ID` ) 进行实验,您可以直接切换 `sensor_hub` 中支持的其它光线传感器,或按照接口定义自行实现新的光线传感器。 +2. 本示例默认使用 `sensor_hub` 中已支持温湿度传感器 `SHT3X` 进行实验,您可以按照 `SHT3X` 注册 `sensor_hub` 的方式自行注册其他传感器。 3. 传感器接线图: ``` - esp32-meshkit-sense BH1750 + esp32-meshkit-sense SHT3X -- | || VCC [SCL 32] --------> | || SCL @@ -46,37 +46,92 @@ ### 示例输出结果 -以下是挂载了`BH1750` 光照度传感器输出结果: +以下是挂载了`SHT3X` 光照度传感器输出结果: ``` -(0) cpu_start: Starting scheduler on APP CPU. -I (346) gpio: GPIO[2]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (356) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (366) gpio: GPIO[12]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (376) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (386) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (396) gpio: GPIO[27]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (406) i2c_bus: i2c0 bus inited -I (406) Board: Board Info: ESP32-MESHKIT-SENSE_V1_1 -I (416) Board: Init Done ... -I (416) SENSOR_HUB: Sensor created, Task name = SENSOR_HUB, Type = LIGHTSENSOR, Sensor ID = 49, Mode = MODE_POLLING, Min Delay = 200 ms -I (426) SENSOR_HUB: task: sensor_default_task created! -I (436) SENSOR_LOOP: event loop created succeed -I (436) SENSOR_LOOP: register a new handler to event loop succeed -I (446) LIGHT_SENSOR_TRIGGER: Timestamp = 204615 - LIGHTSENSOR SENSOR_STARTED -I (676) LIGHT_SENSOR_TRIGGER: Timestamp = 430814 - SENSOR_LIGHT_DATA_READY - light=440.00 -I (876) LIGHT_SENSOR_TRIGGER: Timestamp = 630671 - SENSOR_LIGHT_DATA_READY - light=440.00 -I (1076) LIGHT_SENSOR_TRIGGER: Timestamp = 830671 - SENSOR_LIGHT_DATA_READY - light=440.00 -I (1276) LIGHT_SENSOR_TRIGGER: Timestamp = 1030667 - SENSOR_LIGHT_DATA_READY - light=440.00 -I (1476) LIGHT_SENSOR_TRIGGER: Timestamp = 1230671 - SENSOR_LIGHT_DATA_READY - light=440.00 -I (1676) LIGHT_SENSOR_TRIGGER: Timestamp = 1430668 - SENSOR_LIGHT_DATA_READY - light=436.67 -I (1876) LIGHT_SENSOR_TRIGGER: Timestamp = 1630671 - SENSOR_LIGHT_DATA_READY - light=300.00 -I (2076) LIGHT_SENSOR_TRIGGER: Timestamp = 1830667 - SENSOR_LIGHT_DATA_READY - light=190.00 -I (2076) LIGHT_SENSOR_TRIGGER: LED turn on -I (2276) LIGHT_SENSOR_TRIGGER: Timestamp = 2030672 - SENSOR_LIGHT_DATA_READY - light=156.67 -I (2476) LIGHT_SENSOR_TRIGGER: Timestamp = 2230668 - SENSOR_LIGHT_DATA_READY - light=63.33 -I (2676) LIGHT_SENSOR_TRIGGER: Timestamp = 2430672 - SENSOR_LIGHT_DATA_READY - light=66.67 -I (2876) LIGHT_SENSOR_TRIGGER: Timestamp = 2630668 - SENSOR_LIGHT_DATA_READY - light=283.33 -I (3076) LIGHT_SENSOR_TRIGGER: Timestamp = 2830672 - SENSOR_LIGHT_DATA_READY - light=426.67 -I (3076) LIGHT_SENSOR_TRIGGER: LED turn off +I (21) boot: ESP-IDF v4.4.8 2nd stage bootloader +I (21) boot: compile time 11:22:06 +I (21) boot: chip revision: v0.0 +I (24) boot.esp32s2: SPI Speed : 80MHz +I (29) boot.esp32s2: SPI Mode : DIO +I (34) boot.esp32s2: SPI Flash Size : 2MB +I (38) boot: Enabling RNG early entropy source... +I (44) boot: Partition Table: +I (47) boot: ## Label Usage Type ST Offset Length +I (55) boot: 0 nvs WiFi data 01 02 00009000 00006000 +I (62) boot: 1 phy_init RF data 01 01 0000f000 00001000 +I (70) boot: 2 factory factory app 00 00 00010000 00100000 +I (77) boot: End of partition table +I (81) esp_image: segment 0: paddr=00010020 vaddr=3f000020 size=0b81ch ( 47132) map +I (99) esp_image: segment 1: paddr=0001b844 vaddr=3ffbf950 size=0162ch ( 5676) load +I (101) esp_image: segment 2: paddr=0001ce78 vaddr=40022000 size=031a0h ( 12704) load +I (110) esp_image: segment 3: paddr=00020020 vaddr=40080020 size=1d108h (119048) map +I (139) esp_image: segment 4: paddr=0003d130 vaddr=400251a0 size=0a7a4h ( 42916) load +I (156) boot: Loaded app from partition at offset 0x10000 +I (156) boot: Disabling RNG early entropy source... +I (167) cpu_start: Unicore app +I (168) cache: Instruction cache : size 8KB, 4Ways, cache line size 32Byte +I (168) cpu_start: Pro cpu up. +I (192) cpu_start: Pro cpu start user code +I (192) cpu_start: cpu freq: 160000000 +I (192) cpu_start: Application information: +I (195) cpu_start: Project name: sensors_monitor +I (200) cpu_start: App version: 6ecfeec7-dirty +I (206) cpu_start: Compile time: Dec 19 2024 11:22:02 +I (212) cpu_start: ELF file SHA256: 4dc3344f3c816cae... +I (218) cpu_start: ESP-IDF: v4.4.8 +I (223) cpu_start: Min chip rev: v0.0 +I (228) cpu_start: Max chip rev: v1.99 +I (232) cpu_start: Chip rev: v0.0 +I (237) heap_init: Initializing. RAM available for dynamic allocation: +I (244) heap_init: At 3FFC19E0 len 0003A620 (233 KiB): DRAM +I (251) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM +I (257) heap_init: At 3FF9E000 len 00002000 (8 KiB): RTCRAM +I (264) spi_flash: detected chip: generic +I (268) spi_flash: flash io: dio +W (272) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. +I (285) cpu_start: Starting scheduler on PRO CPU. +I (291) Board_Common: Board Init ... +W (291) Board_Common: no gpio defined +I (291) Board_Common: BOARD_LED_NUM = 1 +I (301) Board_Common: led(RGB) init succeed io=17 +I (301) i2c_bus: i2c0 bus inited +I (311) i2c_bus: I2C Bus Config Succeed, Version: 1.1.0 +I (311) Board_Common: i2c bus create succeed +I (321) Board_Common: Board Info: + +BOARD_NAME: ESP32-S2-Saola-1 +BOARD_VENDOR: Espressif +BOARD_URL: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/hw-reference/esp32s2/user-guide-saola-1-v1.2.html + +I (341) Board_Common: Board Init Done ! +I (341) SENSOR_HUB: Find sht3x driver, type: HUMITURE +I (351) SENSOR_HUB: Sensor created, Task name = SENSOR_HUB, Type = HUMITURE, Sensor Name = sht3x, Mode = MODE_POLLING, Min Delay = 200 ms +I (361) SENSOR_HUB: task: sensor_default_task created! +I (371) SENSOR_LOOP: event loop created succeed +I (371) SENSOR_LOOP: register a new handler to event loop succeed +I (381) SENSOR_CONTROL: Timestamp = 855805 - sht3x_0x44 STARTED +I (581) SENSOR_CONTROL: Timestamp = 1052607 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (581) SENSOR_CONTROL: LED turn on +I (581) SENSOR_CONTROL: Timestamp = 1052607 - event id = 14 +I (781) SENSOR_CONTROL: Timestamp = 1251619 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (781) SENSOR_CONTROL: Timestamp = 1251619 - event id = 14 +I (981) SENSOR_CONTROL: Timestamp = 1452601 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (981) SENSOR_CONTROL: Timestamp = 1452601 - event id = 14 +I (1181) SENSOR_CONTROL: Timestamp = 1651617 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (1181) SENSOR_CONTROL: Timestamp = 1651617 - event id = 14 +I (1381) SENSOR_CONTROL: Timestamp = 1852597 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (1381) SENSOR_CONTROL: Timestamp = 1852597 - event id = 14 +I (1581) SENSOR_CONTROL: Timestamp = 2051617 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (1581) SENSOR_CONTROL: Timestamp = 2051617 - event id = 14 +I (1781) SENSOR_CONTROL: Timestamp = 2252597 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 + +I (1781) SENSOR_CONTROL: Timestamp = 2252597 - event id = 14 + ``` diff --git a/examples/sensors/sensor_control_led/main/Kconfig.projbuild b/examples/sensors/sensor_control_led/main/Kconfig.projbuild index 45cefa3ce..4571ea793 100644 --- a/examples/sensors/sensor_control_led/main/Kconfig.projbuild +++ b/examples/sensors/sensor_control_led/main/Kconfig.projbuild @@ -5,6 +5,6 @@ menu "Sensor Monitor Example" default 200 config SENSOR_EXAMPLE_THRESHOLD int "led state toggle threshold" - range 150 1000 - default 300 + range 0 100 + default 30 endmenu diff --git a/examples/sensors/sensor_control_led/main/app_main.c b/examples/sensors/sensor_control_led/main/app_main.c index 913ab44a3..d1b19579a 100644 --- a/examples/sensors/sensor_control_led/main/app_main.c +++ b/examples/sensors/sensor_control_led/main/app_main.c @@ -1,27 +1,27 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "esp_log.h" #include "iot_board.h" +#include "sht3x.h" #include "iot_sensor_hub.h" -#define LIGHT_SENSOR_ID SENSOR_BH1750_ID #define SENSOR_PERIOD CONFIG_SENSOR_EXAMPLE_PERIOD -#define LIGHT_SENSOR_THRESHOLD (CONFIG_SENSOR_EXAMPLE_THRESHOLD * 1.0) -#define LIGHT_SENSOR_DEADZONE (LIGHT_SENSOR_THRESHOLD * 0.1) +#define TEMPERATURE_SENSOR_THRESHOLD (CONFIG_SENSOR_EXAMPLE_THRESHOLD * 1.0) +#define TEMPERATURE_SENSOR_DEADZONE (TEMPERATURE_SENSOR_THRESHOLD * 0.1) #define TAG "SENSOR_CONTROL" static void led_control(float value) { static bool led_is_on = false; - if ((!led_is_on) && (value < (LIGHT_SENSOR_THRESHOLD - LIGHT_SENSOR_DEADZONE))) { + if ((!led_is_on) && (value < (TEMPERATURE_SENSOR_THRESHOLD - TEMPERATURE_SENSOR_DEADZONE))) { ESP_LOGI(TAG, "LED turn on"); iot_board_led_all_set_state(true); led_is_on = true; - } else if ((led_is_on) && (value >= (LIGHT_SENSOR_THRESHOLD + LIGHT_SENSOR_DEADZONE))) { + } else if ((led_is_on) && (value >= (TEMPERATURE_SENSOR_THRESHOLD + TEMPERATURE_SENSOR_DEADZONE))) { ESP_LOGI(TAG, "LED turn off"); iot_board_led_all_set_state(false); led_is_on = false; @@ -31,31 +31,31 @@ static void led_control(float value) static void sensor_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) { sensor_data_t *sensor_data = (sensor_data_t *)event_data; - sensor_type_t sensor_type = (sensor_type_t)((sensor_data->sensor_id) >> 4 & SENSOR_ID_MASK); - if (sensor_data->sensor_id != LIGHT_SENSOR_ID) { - return; - } switch (id) { case SENSOR_STARTED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STARTED", + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STARTED", sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); + sensor_data->sensor_name, + sensor_data->sensor_addr); break; case SENSOR_STOPED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STOPED", + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STOPPED", sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); + sensor_data->sensor_name, + sensor_data->sensor_addr); break; - case SENSOR_LIGHT_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_LIGHT_DATA_READY - " - "light=%.2f", + case SENSOR_TEMP_DATA_READY: + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x TEMP_DATA_READY - " + "temperature=%.2f\n", sensor_data->timestamp, - sensor_data->light); - led_control(sensor_data->light); + sensor_data->sensor_name, + sensor_data->sensor_addr, + sensor_data->temperature); + led_control(sensor_data->temperature); break; default: - ESP_LOGI(TAG, "Timestamp = %llu - event id = %d", sensor_data->timestamp, id); + ESP_LOGI(TAG, "Timestamp = %" PRIi64 " - event id = %" PRIi32, sensor_data->timestamp, id); break; } } @@ -78,12 +78,14 @@ void app_main(void) /*create sensor based on sensorID*/ sensor_handle_t sensor_handle = NULL; sensor_config_t sensor_config = { - .bus = i2c0_bus_handle, /*which bus sensors will connect to*/ - .mode = MODE_POLLING, /*data acquire mode*/ - .min_delay = SENSOR_PERIOD /*data acquire period*/ + .bus = i2c0_bus_handle, /*which bus sensors will connect to*/ + .type = HUMITURE_ID, /*sensor type*/ + .addr = SHT3x_ADDR_PIN_SELECT_VSS, /*sensor addr*/ + .mode = MODE_POLLING, /*data acquire mode*/ + .min_delay = SENSOR_PERIOD /*data acquire period*/ }; - if (ESP_OK != iot_sensor_create(LIGHT_SENSOR_ID, &sensor_config, &sensor_handle)) { /*create a sensor with specific sensor_id and configurations*/ + if (ESP_OK != iot_sensor_create("sht3x", &sensor_config, &sensor_handle)) { /*create a sensor with specific sensor_id and configurations*/ goto error_loop; } diff --git a/examples/sensors/sensor_control_led/main/idf_component.yml b/examples/sensors/sensor_control_led/main/idf_component.yml index 6f86ff26e..85bfeb1eb 100644 --- a/examples/sensors/sensor_control_led/main/idf_component.yml +++ b/examples/sensors/sensor_control_led/main/idf_component.yml @@ -2,27 +2,9 @@ dependencies: boards: version: "~0.0.1" override_path: "../../../common_components/boards" - button: - public: true - override_path: "../../../../components/button" - apds9960: - public: true - override_path: "../../../../components/sensors/gesture/apds9960" sht3x: public: true override_path: "../../../../components/sensors/humiture/sht3x" - lis2dh12: - public: true - override_path: "../../../../components/sensors/imu/lis2dh12" - bh1750: - public: true - override_path: "../../../../components/sensors/light_sensor/bh1750" - veml6040: - public: true - override_path: "../../../../components/sensors/light_sensor/veml6040" - veml6075: - public: true - override_path: "../../../../components/sensors/light_sensor/veml6075" - bme280: + sensor_hub: public: true - override_path: "../../../../components/sensors/pressure/bme280" + override_path: "../../../../components/sensors/sensor_hub" diff --git a/examples/sensors/sensor_control_led/sdkconfig.defaults b/examples/sensors/sensor_control_led/sdkconfig.defaults index fa1685b0a..17fabd90a 100644 --- a/examples/sensors/sensor_control_led/sdkconfig.defaults +++ b/examples/sensors/sensor_control_led/sdkconfig.defaults @@ -2,33 +2,6 @@ # Sensor Hub Options # -# -# Sensor Hal Options -# - -# -# IMU Hal Options -# -CONFIG_SENSOR_IMU_INCLUDED_MPU6050=y -CONFIG_SENSOR_IMU_INCLUDED_LIS2DH12=y -# end of IMU Hal Options - -# -# Humiture Hal Options -# -CONFIG_SENSOR_HUMITURE_INCLUDED_SHT3X=y -CONFIG_SENSOR_HUMITURE_INCLUDED_HTS221=y -# end of Humiture Hal Options - -# -# Light Sensor Hal Options -# -CONFIG_SENSOR_LIGHT_INCLUDED_BH1750=y -CONFIG_SENSOR_LIGHT_INCLUDED_VEML6040=y -CONFIG_SENSOR_LIGHT_INCLUDED_VEML6075=y -# end of Light Sensor Hal Options -# end of Sensor Hal Options - # # Sensor Build Options # @@ -78,5 +51,5 @@ CONFIG_BOARD_POWER_SCREEN=y # Sensor Monitor Example # CONFIG_SENSOR_EXAMPLE_PERIOD=200 -CONFIG_SENSOR_EXAMPLE_THRESHOLD=300 +CONFIG_SENSOR_EXAMPLE_THRESHOLD=30 # end of Sensor Monitor Example diff --git a/examples/sensors/sensor_hub_monitor/CMakeLists.txt b/examples/sensors/sensor_hub_monitor/CMakeLists.txt index 0fc16dcd9..3f4b2ecf6 100644 --- a/examples/sensors/sensor_hub_monitor/CMakeLists.txt +++ b/examples/sensors/sensor_hub_monitor/CMakeLists.txt @@ -1,20 +1,6 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) - -#If IOT_SOLUTION_PATH is not defined, use relative path as default value -if(NOT DEFINED ENV{IOT_SOLUTION_PATH}) - get_filename_component(IOT_SOLUTION_PATH "${CMAKE_SOURCE_DIR}/../../.." ABSOLUTE) - set(ENV{IOT_SOLUTION_PATH} ${IOT_SOLUTION_PATH}) - message(WARNING "IOT_SOLUTION_PATH not set, using default $ENV{IOT_SOLUTION_PATH}") -endif() - -set(EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS} - $ENV{IOT_SOLUTION_PATH}/components/sensors/sensor_hub - $ENV{IOT_SOLUTION_PATH}/components/sensors/humiture/hts221 - $ENV{IOT_SOLUTION_PATH}/components/sensors/imu/mpu6050 - ) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(sensors_monitor) diff --git a/examples/sensors/sensor_hub_monitor/README_cn.md b/examples/sensors/sensor_hub_monitor/README_cn.md index 933f675be..2855dbc29 100644 --- a/examples/sensors/sensor_hub_monitor/README_cn.md +++ b/examples/sensors/sensor_hub_monitor/README_cn.md @@ -49,66 +49,34 @@ ### 示例输出结果 -以下是挂载了`BH1750` 光照度传感器、 `SHT31` 温湿度传感器、`MPU6050` 陀螺仪加速度计三个传感器模块的测试输出结果: +以下是挂载了`VEML6040` 光照度传感器、 `SHT31` 温湿度传感器、`LIS2DH12` 陀螺仪加速度计三个传感器模块的测试输出结果: 1. 发现三个 i2c 设备,并根据地址推断出传感器型号: ``` -I (348) i2c_bus: i2c0 bus inited -I (348) Board: Board Info: ESP32-Devkitc -I (358) Board: Board Init Done ... -I (358) SENSOR_LOOP: event loop created succeed -I (368) SENSOR_LOOP: register a new handler to event loop succeed -I (378) i2c_bus: found i2c device address = 0x23 -I (388) i2c_bus: found i2c device address = 0x44 -I (398) i2c_bus: found i2c device address = 0x68 -I (398) SENSOR_HUB: address 0x23 might be BH1750 (Light Intensity sensor) - -I (408) SENSOR_HUB: address 0x23 found 1 matched info - -I (418) SENSOR_HUB: address 0x44 might be SHT31 (Humi/Temp sensor) - -I (428) SENSOR_HUB: address 0x44 found 1 matched info - -I (428) SENSOR_HUB: address 0x68 might be MPU6050 (Gyro/Acce sensor) - -I (438) SENSOR_HUB: address 0x68 found 1 matched info +I (319) Board_Common: Board Init Done ! +I (329) SENSOR_HUB: Find lis2dh12 driver, type: IMU +I (329) SENSOR_HUB: Find sht3x driver, type: HUMITURE +I (339) SENSOR_HUB: Find veml6040 driver, type: LIGHTSENSOR +I (349) SENSOR_HUB: Find sht3x driver, type: HUMITURE ``` -2. 分别创建并启动了这三个传感器: +2. 创建并启动了对应的传感器: ``` -I (448) SENSOR_HUB: Sensor created, Task name = SENSOR_HUB, Type = LIGHTSENSOR, Sensor ID = 49, Mode = MODE_POLLING, Min Delay = 200 ms -I (458) SENSOR_HUB: task: sensor_default_task created! -I (468) Sensors Monitor: Timestamp = 226526 - LIGHTSENSOR SENSOR_STARTED -I (478) Sensors Monitor: BH1750 (Light Intensity sensor) created -I (488) SENSOR_HUB: Sensor created, Task name = SENSOR_HUB, Type = HUMITURE, Sensor ID = 17, Mode = MODE_POLLING, Min Delay = 200 ms -I (498) Sensors Monitor: Timestamp = 253110 - HUMITURE SENSOR_STARTED -I (498) Sensors Monitor: SHT31 (Humi/Temp sensor) created -I (508) MPU6050: mpu6050 device address is: 0x68 - -I (518) SENSOR_HUB: Sensor created, Task name = SENSOR_HUB, Type = IMU, Sensor ID = 33, Mode = MODE_POLLING, Min Delay = 200 ms - -I (528) Sensors Monitor: Timestamp = 283925 - IMU SENSOR_STARTED -I (538) Sensors Monitor: MPU6050 (Gyro/Acce sensor) created +I (349) SENSOR_HUB: Sensor created, Task name = SENSOR_HUB, Type = HUMITURE, Sensor Name = sht3x, Mode = MODE_POLLING, Min Delay = 200 ms +I (359) SENSOR_HUB: task: sensor_default_task created! +I (369) SENSOR_LOOP: event loop created succeed +I (379) SENSOR_LOOP: register a new handler to event loop succeed +I (379) Sensors Monitor: Timestamp = 850604 - sht3x_0x44 STARTED ``` 3. 传感器启动以后,以设定的周期采集数据,并发送事件消息: ``` -I (698) Sensors Monitor: Timestamp = 450729 - SENSOR_LIGHT_DATA_READY - light=353.33 -I (698) Sensors Monitor: Timestamp = 451679 - SENSOR_TEMP_DATA_READY - temperature=24.47 - -I (698) Sensors Monitor: Timestamp = 451679 - SENSOR_HUMI_DATA_READY - humiture=38.58 -I (728) Sensors Monitor: Timestamp = 483688 - SENSOR_GYRO_DATA_READY - gyro_x=0.26, gyro_y=-2.00, gyro_z=-0.92 - -I (728) Sensors Monitor: Timestamp = 483688 - SENSOR_ACCE_DATA_READY - acce_x=0.07, acce_y=0.43, acce_z=0.80 - -I (898) Sensors Monitor: Timestamp = 650686 - SENSOR_LIGHT_DATA_READY - light=353.33 -I (898) Sensors Monitor: Timestamp = 651049 - SENSOR_TEMP_DATA_READY - temperature=24.47 - -I (898) Sensors Monitor: Timestamp = 651049 - SENSOR_HUMI_DATA_READY - humiture=38.58 -I (928) Sensors Monitor: Timestamp = 683593 - SENSOR_GYRO_DATA_READY - gyro_x=0.44, gyro_y=-2.18, gyro_z=-0.93 +I (579) Sensors Monitor: Timestamp = 1044096 - sht3x_0x44 HUMI_DATA_READY - humiture=45.78 +I (779) Sensors Monitor: Timestamp = 1243127 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 -I (928) Sensors Monitor: Timestamp = 683593 - SENSOR_ACCE_DATA_READY - acce_x=0.08, acce_y=0.43, acce_z=0.80 +I (779) Sensors Monitor: Timestamp = 1243127 - sht3x_0x44 HUMI_DATA_READY - humiture=45.78 +I (979) Sensors Monitor: Timestamp = 1444101 - sht3x_0x44 TEMP_DATA_READY - temperature=25.00 ``` \ No newline at end of file diff --git a/examples/sensors/sensor_hub_monitor/main/app_main.c b/examples/sensors/sensor_hub_monitor/main/app_main.c index fa2893f62..dac5be4be 100644 --- a/examples/sensors/sensor_hub_monitor/main/app_main.c +++ b/examples/sensors/sensor_hub_monitor/main/app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,72 +10,98 @@ #define SENSOR_PERIOD CONFIG_SENSOR_EXAMPLE_PERIOD +#if CONFIG_SENSOR_INCLUDED_HUMITURE +static sensor_handle_t sht3x_handle = NULL; +static sensor_event_handler_instance_t sht3x_handler_handle = NULL; +#endif + +#if CONFIG_SENSOR_INCLUDED_IMU +static sensor_handle_t lis2dh12_handle = NULL; +static sensor_event_handler_instance_t lis2dh12_handler_handle = NULL; +#endif + +#if CONFIG_SENSOR_INCLUDED_LIGHT +static sensor_handle_t veml6040_handle = NULL; +static sensor_event_handler_instance_t veml6040_handler_handle = NULL; +#endif + #define TAG "Sensors Monitor" static void sensor_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) { sensor_data_t *sensor_data = (sensor_data_t *)event_data; - sensor_type_t sensor_type = (sensor_type_t)((sensor_data->sensor_id) >> 4 & SENSOR_ID_MASK); - if (sensor_type >= SENSOR_TYPE_MAX) { - ESP_LOGE(TAG, "sensor_id invalid, id=%d", sensor_data->sensor_id); - return; - } switch (id) { case SENSOR_STARTED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STARTED", + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STARTED", sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); + sensor_data->sensor_name, + sensor_data->sensor_addr); break; case SENSOR_STOPED: - ESP_LOGI(TAG, "Timestamp = %llu - %s SENSOR_STOPED", + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x STOPPED", sensor_data->timestamp, - SENSOR_TYPE_STRING[sensor_type]); + sensor_data->sensor_name, + sensor_data->sensor_addr); break; case SENSOR_HUMI_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_HUMI_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x HUMI_DATA_READY - " "humiture=%.2f", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->humidity); break; case SENSOR_TEMP_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_TEMP_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x TEMP_DATA_READY - " "temperature=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->temperature); break; case SENSOR_ACCE_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_ACCE_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x ACCE_DATA_READY - " "acce_x=%.2f, acce_y=%.2f, acce_z=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->acce.x, sensor_data->acce.y, sensor_data->acce.z); break; case SENSOR_GYRO_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_GYRO_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x GYRO_DATA_READY - " "gyro_x=%.2f, gyro_y=%.2f, gyro_z=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->gyro.x, sensor_data->gyro.y, sensor_data->gyro.z); break; case SENSOR_LIGHT_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_LIGHT_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x LIGHT_DATA_READY - " "light=%.2f", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->light); break; case SENSOR_RGBW_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_RGBW_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x RGBW_DATA_READY - " "r=%.2f, g=%.2f, b=%.2f, w=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->rgbw.r, sensor_data->rgbw.r, sensor_data->rgbw.b, sensor_data->rgbw.w); break; case SENSOR_UV_DATA_READY: - ESP_LOGI(TAG, "Timestamp = %llu - SENSOR_UV_DATA_READY - " + ESP_LOGI(TAG, "Timestamp = %llu - %s_0x%x UV_DATA_READY - " "uv=%.2f, uva=%.2f, uvb=%.2f\n", sensor_data->timestamp, + sensor_data->sensor_name, + sensor_data->sensor_addr, sensor_data->uv.uv, sensor_data->uv.uva, sensor_data->uv.uvb); break; default: - ESP_LOGI(TAG, "Timestamp = %llu - event id = %d", sensor_data->timestamp, id); + ESP_LOGI(TAG, "Timestamp = %" PRIi64 " - event id = %" PRIi32, sensor_data->timestamp, id); break; } } @@ -95,27 +121,70 @@ void app_main(void) goto error_loop; } - /*register handler with NULL specific typeID, thus all events posted to sensor_loop will be handled*/ - ESP_ERROR_CHECK(iot_sensor_handler_register_with_type(NULL_ID, NULL_ID, sensor_event_handler, NULL)); + /*scan the sensor drivers already loaded in the current project.*/ + iot_sensor_scan(); - /*create sensors based on sensor scan result*/ - sensor_info_t* sensor_infos[10]; - sensor_handle_t sensor_handle[10] = {NULL}; - sensor_config_t sensor_config = { - .bus = i2c0_bus_handle, /*which bus sensors will connect to*/ - .mode = MODE_POLLING, /*data acquire mode*/ - .min_delay = SENSOR_PERIOD /*data acquire period*/ + /*create sensors*/ +#if CONFIG_SENSOR_INCLUDED_HUMITURE + sensor_config_t sht3x_config = { + .bus = i2c0_bus_handle, + .addr = 0x44, + .type = HUMITURE_ID, + .mode = MODE_POLLING, + .min_delay = SENSOR_PERIOD, }; - int num = iot_sensor_scan(i2c0_bus_handle, sensor_infos, 10); /*scan for valid sensors based on active i2c address*/ - for (size_t i = 0; i < num && i < 10; i++) { + if (ESP_OK != iot_sensor_create("sht3x", &sht3x_config, &sht3x_handle)) { + goto error_loop; + } + if (ESP_OK != iot_sensor_handler_register(sht3x_handle, sensor_event_handler, &sht3x_handler_handle)) { + goto error_loop; + } + if (ESP_OK != iot_sensor_start(sht3x_handle)) { + goto error_loop; + } +#endif - if (ESP_OK != iot_sensor_create(sensor_infos[i]->sensor_id, &sensor_config, &sensor_handle[i])) { /*create a sensor with specific sensor_id and configurations*/ - goto error_loop; - } +#if CONFIG_SENSOR_INCLUDED_IMU + sensor_config_t lis2dh12_config = { + .bus = i2c0_bus_handle, + .addr = 0x19, + .type = IMU_ID, + .mode = MODE_POLLING, + .min_delay = SENSOR_PERIOD, + }; + if (ESP_OK != iot_sensor_create("lis2dh12", &lis2dh12_config, &lis2dh12_handle)) { + goto error_loop; + } - iot_sensor_start(sensor_handle[i]); /*start a sensor, data ready events will be posted once data acquired successfully*/ - ESP_LOGI(TAG, "%s (%s) created", sensor_infos[i]->name, sensor_infos[i]->desc); + if (ESP_OK != iot_sensor_handler_register(lis2dh12_handle, sensor_event_handler, &lis2dh12_handler_handle)) { + goto error_loop; + } + + if (ESP_OK != iot_sensor_start(lis2dh12_handle)) { + goto error_loop; + } +#endif + +#if CONFIG_SENSOR_INCLUDED_LIGHT + sensor_config_t veml6040_config = { + .bus = i2c0_bus_handle, + .addr = 0x10, + .type = LIGHT_SENSOR_ID, + .mode = MODE_POLLING, + .min_delay = SENSOR_PERIOD, + }; + if (ESP_OK != iot_sensor_create("veml6040", &veml6040_config, &veml6040_handle)) { + goto error_loop; + } + + if (ESP_OK != iot_sensor_handler_register(veml6040_handle, sensor_event_handler, &veml6040_handler_handle)) { + goto error_loop; + } + + if (ESP_OK != iot_sensor_start(veml6040_handle)) { + goto error_loop; } +#endif while (1) { vTaskDelay(1000); diff --git a/examples/sensors/sensor_hub_monitor/main/idf_component.yml b/examples/sensors/sensor_hub_monitor/main/idf_component.yml index 6f86ff26e..06220d877 100644 --- a/examples/sensors/sensor_hub_monitor/main/idf_component.yml +++ b/examples/sensors/sensor_hub_monitor/main/idf_component.yml @@ -5,24 +5,15 @@ dependencies: button: public: true override_path: "../../../../components/button" - apds9960: + sensor_hub: public: true - override_path: "../../../../components/sensors/gesture/apds9960" + override_path: "../../../../components/sensors/sensor_hub" sht3x: public: true override_path: "../../../../components/sensors/humiture/sht3x" lis2dh12: public: true override_path: "../../../../components/sensors/imu/lis2dh12" - bh1750: - public: true - override_path: "../../../../components/sensors/light_sensor/bh1750" veml6040: public: true override_path: "../../../../components/sensors/light_sensor/veml6040" - veml6075: - public: true - override_path: "../../../../components/sensors/light_sensor/veml6075" - bme280: - public: true - override_path: "../../../../components/sensors/pressure/bme280" diff --git a/examples/sensors/sensor_hub_monitor/sdkconfig.defaults b/examples/sensors/sensor_hub_monitor/sdkconfig.defaults index e301ed098..a2c9d54e6 100644 --- a/examples/sensors/sensor_hub_monitor/sdkconfig.defaults +++ b/examples/sensors/sensor_hub_monitor/sdkconfig.defaults @@ -1,34 +1,3 @@ -# -# Sensor Hub Options -# - -# -# Sensor Hal Options -# - -# -# IMU Hal Options -# -CONFIG_SENSOR_IMU_INCLUDED_MPU6050=y -CONFIG_SENSOR_IMU_INCLUDED_LIS2DH12=y -# end of IMU Hal Options - -# -# Humiture Hal Options -# -CONFIG_SENSOR_HUMITURE_INCLUDED_SHT3X=y -CONFIG_SENSOR_HUMITURE_INCLUDED_HTS221=y -# end of Humiture Hal Options - -# -# Light Sensor Hal Options -# -CONFIG_SENSOR_LIGHT_INCLUDED_BH1750=y -CONFIG_SENSOR_LIGHT_INCLUDED_VEML6040=y -CONFIG_SENSOR_LIGHT_INCLUDED_VEML6075=y -# end of Light Sensor Hal Options -# end of Sensor Hal Options - # # Sensor Build Options #