Skip to content

Commit acc2fdf

Browse files
authored
Merge pull request #718 from espressif/feat/ICM42607_sensor_hub_api
Sensor hub API
2 parents de01849 + 627ce5c commit acc2fdf

36 files changed

+1105
-48
lines changed

.github/ci/update_readme_dependencies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
# 'AUDIO_MIC' : r'',
4949
'SDCARD': r'(^idf$)', # SD card driver is native to ESP-IDF
5050
'IMU': r'(icm42670$|mpu6050$|qma6100p$)',
51+
'HUMITURE': r'(aht30$)',
5152
'LED': r'(led_indicator$|^idf$)', # Provided by led_indicator or idf
5253
'BAT': r'(^idf$)', # Battery (ADC driver) is native to ESP-IDF
5354
'CAMERA': r'(esp32-camera$)', # esp32-camera component
@@ -68,6 +69,7 @@
6869
"AUDIO_SPEAKER": ":speaker:",
6970
"SDCARD": ":floppy_disk:",
7071
"IMU": ":video_game:",
72+
"HUMITURE": ":thermometer:",
7173
"USB": ":electric_plug:",
7274
"BUTTONS": ":radio_button:",
7375
"LED": ":bulb:",

.github/ci/update_supported_boards.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def extract_board_info(board_path):
141141
"AUDIO_SPEAKER": ":speaker:",
142142
"SDCARD": ":floppy_disk:",
143143
"IMU": ":video_game:",
144+
"HUMITURE": ":thermometer:",
144145
"USB": ":electric_plug:",
145146
"BUTTONS": ":radio_button:",
146147
"LED": ":bulb:",
@@ -158,6 +159,7 @@ def extract_board_info(board_path):
158159
"AUDIO_SPEAKER": "Audio Speaker",
159160
"SDCARD": "uSD Card",
160161
"IMU": "IMU",
162+
"HUMITURE": "Temperature and Humidity",
161163
"USB": "USB-OTG",
162164
"BUTTONS": "Button",
163165
"LED": "LED",

.github/workflows/upload_component.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ on:
44
push:
55
branches:
66
- master
7-
paths:
7+
paths:
88
- '.github/**'
99
- 'bsp/**'
1010
- 'components/**'
1111
pull_request:
1212
types: [opened, reopened, synchronize]
13-
paths:
13+
paths:
1414
- '.github/**'
1515
- 'bsp/**'
1616
- 'components/**'
@@ -79,7 +79,6 @@ jobs:
7979
components/mag3110
8080
components/mpu6050
8181
components/esp_lvgl_port
82-
components/icm42670
8382
components/qma6100p
8483
components/lcd_touch/esp_lcd_touch
8584
components/lcd_touch/esp_lcd_touch_ft5x06
@@ -103,6 +102,8 @@ jobs:
103102
components/io_expander/esp_io_expander_tca95xx_16bit
104103
components/io_expander/esp_io_expander_ht8574
105104
components/io_expander/esp_io_expander_pi4ioe5v6408
105+
components/sensors/icm42670
106+
components/sensors/aht30
106107
namespace: "espressif"
107108
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
108109
dry_run: ${{ github.ref_name != 'master' || github.repository_owner != 'espressif' }}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following table shows the compatibility of this BSP with different ESP-IDF v
2727

2828
| Board name | SoC | Supported Features | Photo |
2929
|:----------:|:---:|:-------------------|:-----:|
30-
| [ESP-BOX-3](bsp/esp-box-3) | esp32s3 | :musical_note: Audio <br/>:microphone: Audio Microphone (es7210)<br/>:speaker: Audio Speaker (es8311)<br/>:radio_button: Button <br/>:pager: LCD Display (st7789, ili9341)<br/>:video_game: IMU <br/>:floppy_disk: uSD Card <br/>:point_up: Display Touch (tt21100, gt911)<br/> | <img src="bsp/esp-box-3/doc/esp-box-3.webp" width="150"> |
30+
| [ESP-BOX-3](bsp/esp-box-3) | esp32s3 | :musical_note: Audio <br/>:microphone: Audio Microphone (es7210)<br/>:speaker: Audio Speaker (es8311)<br/>:radio_button: Button <br/>:pager: LCD Display (st7789, ili9341)<br/>:thermometer: Temperature and Humidity <br/>:video_game: IMU <br/>:floppy_disk: uSD Card <br/>:point_up: Display Touch (tt21100, gt911)<br/> | <img src="bsp/esp-box-3/doc/esp-box-3.webp" width="150"> |
3131
| [ESP32-C3-LCDKit](bsp/esp32_c3_lcdkit) | esp32c3 | :musical_note: Audio <br/>:speaker: Audio Speaker <br/>:pager: LCD Display (gc9a01)<br/>:white_circle: Knob <br/>:bulb: LED <br/> | <img src="bsp/esp32_c3_lcdkit/doc/esp32_c3_lcdkit.webp" width="150"> |
3232
| [ESP32-LyraT](bsp/esp32_lyrat) | esp32 | :musical_note: Audio <br/>:microphone: Audio Microphone (es8388)<br/>:speaker: Audio Speaker (es8388)<br/>:radio_button: Button <br/>:bulb: LED <br/>:floppy_disk: uSD Card <br/> | <img src="bsp/esp32_lyrat/doc/esp32_lyrat.webp" width="150"> |
3333
| [ESP32-P4-EYE](bsp/esp32_p4_eye) | esp32p4 | :musical_note: Audio <br/>:microphone: Audio Microphone <br/>:battery: Battery <br/>:radio_button: Button <br/>:camera: Camera (OV2710)<br/>:pager: LCD Display (st7789)<br/>:white_circle: Knob <br/>:bulb: LED <br/>:floppy_disk: uSD Card <br/> | <img src="bsp/esp32_p4_eye/doc/esp32_p4_eye.webp" width="150"> |
@@ -82,6 +82,7 @@ Here is a summary of the available examples:
8282
| [USB HID Example](examples/display_usb_hid) | USB HID demo (keyboard, mouse, or gamepad visualization using LVGL) | <details><summary>3 boards</summary>[esp32_p4_function_ev_board](bsp/esp32_p4_function_ev_board)<br/>[esp32_s3_usb_otg](bsp/esp32_s3_usb_otg)<br/>[m5stack_tab5](bsp/m5stack_tab5)</details> | - |
8383
| [Generic Button and LED Example](examples/generic_button_led) | Minimal example using the Generic BSP: button and LED control | <details><summary>2 boards</summary>[esp_bsp_devkit](bsp/esp_bsp_devkit)<br/>[esp_bsp_generic](bsp/esp_bsp_generic)</details> | - |
8484
| [MQTT Example](examples/mqtt_example) | Collect sensor data and publish to an MQTT server | <details><summary>1 board</summary>[esp32_azure_iot_kit](bsp/esp32_azure_iot_kit)</details> | - |
85+
| [Sensors Example](examples/sensors) | Acquire sensor data using the sensor hub component | <details><summary>1 board</summary>[esp-box-3](bsp/esp-box-3)</details> | [Flash Example](https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-bsp/config.toml&app=sensors) |
8586

8687
<!-- EXAMPLES_TABLE_END -->
8788

@@ -123,4 +124,4 @@ idf.py -B build/wrover_kit -D SDKCONFIG_DEFAULTS=sdkconfig.bsp.esp_wrover_kit bu
123124
124125
## Copyrights and License
125126

126-
All original source code in this repository is Copyright (c) Espressif Systems (Shanghai) Co. Ltd., and is licensed under the Apache 2.0 license.
127+
All original source code in this repository is Copyright (c) Espressif Systems (Shanghai) Co. Ltd., and is licensed under the Apache 2.0 license.

bsp/esp-box-3/API.md

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77

8-
| :1234: [CAPABILITIES](#1234-capabilities) | :floppy_disk: [SD CARD AND SPIFFS](#floppy_disk-sd-card-and-spiffs) | :musical_note: [AUDIO](#musical_note-audio) | :pager: [DISPLAY AND TOUCH](#pager-display-and-touch) | :radio_button: [BUTTONS](#radio_button-buttons) | :electric_plug: [USB](#electric_plug-usb) |
9-
| :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: |
8+
| :1234: [CAPABILITIES](#1234-capabilities) | :floppy_disk: [SD CARD AND SPIFFS](#floppy_disk-sd-card-and-spiffs) | :musical_note: [AUDIO](#musical_note-audio) | :pager: [DISPLAY AND TOUCH](#pager-display-and-touch) | :radio_button: [BUTTONS](#radio_button-buttons) | :electric_plug: [USB](#electric_plug-usb) | :video_game: [SENSORS](#video_game-sensors) |
9+
| :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: | :-------------------------: |
1010

1111
</div>
1212

@@ -149,6 +149,7 @@ You can use these macros to conditionally compile code depending on feature avai
149149
| define | [**BSP\_CAPS\_AUDIO\_SPEAKER**](#define-bsp_caps_audio_speaker) 1<br> |
150150
| define | [**BSP\_CAPS\_BUTTONS**](#define-bsp_caps_buttons) 1<br> |
151151
| define | [**BSP\_CAPS\_DISPLAY**](#define-bsp_caps_display) 1<br> |
152+
| define | [**BSP\_CAPS\_HUMITURE**](#define-bsp_caps_humiture) 1<br> |
152153
| define | [**BSP\_CAPS\_IMU**](#define-bsp_caps_imu) 1<br> |
153154
| define | [**BSP\_CAPS\_SDCARD**](#define-bsp_caps_sdcard) 1<br> |
154155
| define | [**BSP\_CAPS\_TOUCH**](#define-bsp_caps_touch) 1<br> |
@@ -213,6 +214,8 @@ You can use these macros to conditionally compile code depending on feature avai
213214

214215
| Type | Name |
215216
| ---: | :--- |
217+
| define | [**BSP\_I2C\_DOCK\_SCL**](#define-bsp_i2c_dock_scl) (GPIO\_NUM\_40)<br> |
218+
| define | [**BSP\_I2C\_DOCK\_SDA**](#define-bsp_i2c_dock_sda) (GPIO\_NUM\_41)<br> |
216219
| define | [**BSP\_I2C\_NUM**](#define-bsp_i2c_num) CONFIG\_BSP\_I2C\_NUM<br> |
217220
| define | [**BSP\_I2C\_SCL**](#define-bsp_i2c_scl) (GPIO\_NUM\_18)<br> |
218221
| define | [**BSP\_I2C\_SDA**](#define-bsp_i2c_sda) (GPIO\_NUM\_8)<br> |
@@ -1467,3 +1470,107 @@ For more USB-related APIs and configuration options, check the corresponding BSP
14671470
14681471
14691472
1473+
1474+
1475+
1476+
## :video_game: Sensors
1477+
1478+
Boards with integrated sensors (e.g., IMUs, environmental sensors) are abstracted using the sensor hub component.
1479+
The BSP project provides APIs for initializing each sensor and it is up to the integrating platform to provide configuration of the data acquisition and callback handlers.
1480+
1481+
For practical usage examples and supported sensors on your board, refer to the relevant examples in the BSP repository, such as:
1482+
- `sensors` (for reading sensor data)
1483+
- TODO: `display_rotation` (for IMU setup and orientation control)
1484+
1485+
### Usage
1486+
1487+
Create a handler function for sensor hub events
1488+
``` c
1489+
void sensor_event_handler(void *handler_args, esp_event_base_t base, int32_t id, void *event_data)
1490+
{
1491+
...
1492+
}
1493+
```
1494+
1495+
Set up a sensor configuration and initialize it
1496+
``` c
1497+
bsp_sensor_config_t imu_config = {
1498+
.type = IMU_ID,
1499+
.mode = MODE_POLLING,
1500+
.period = 1000
1501+
};
1502+
ESP_ERROR_CHECK(bsp_sensor_init(&imu_config, &imu_sensor_handle));
1503+
```
1504+
1505+
Associate an event handler with the configured sensor
1506+
``` c
1507+
iot_sensor_handler_register(imu_sensor_handle, sensor_event_handler, NULL);
1508+
```
1509+
1510+
Start the sensor data acquisition
1511+
``` c
1512+
iot_sensor_start(imu_sensor_handle);
1513+
```
1514+
1515+
**Notes:**
1516+
- More information can be found in [sensor hub documentation page](https://docs.espressif.com/projects/esp-iot-solution/en/latest/sensors/sensor_hub.html).
1517+
1518+
### Sensors API Reference
1519+
1520+
## Structures and Types
1521+
1522+
| Type | Name |
1523+
| ---: | :--- |
1524+
| struct | [**bsp\_sensor\_config\_t**](#struct-bsp_sensor_config_t) <br>_BSP sensor configuration structure._ |
1525+
1526+
## Functions
1527+
1528+
| Type | Name |
1529+
| ---: | :--- |
1530+
| esp\_err\_t | [**bsp\_sensor\_init**](#function-bsp_sensor_init) (const [**bsp\_sensor\_config\_t**](#struct-bsp_sensor_config_t) \*cfg, sensor\_handle\_t \*sensor\_handle) <br>_Initialize a sensor._ |
1531+
1532+
1533+
1534+
## Structures and Types Documentation
1535+
1536+
### struct `bsp_sensor_config_t`
1537+
1538+
_BSP sensor configuration structure._
1539+
1540+
Variables:
1541+
1542+
- sensor\_mode\_t mode
1543+
1544+
- uint16\_t period
1545+
1546+
- sensor\_type\_t type
1547+
1548+
1549+
## Functions Documentation
1550+
1551+
### function `bsp_sensor_init`
1552+
1553+
_Initialize a sensor._
1554+
```c
1555+
esp_err_t bsp_sensor_init (
1556+
const bsp_sensor_config_t *cfg,
1557+
sensor_handle_t *sensor_handle
1558+
)
1559+
```
1560+
1561+
1562+
**Parameters:**
1563+
1564+
1565+
* `cfg` Pointer to the sensor configuration
1566+
* `sensor_handle` Pointer to the outgoing sensor handle
1567+
1568+
1569+
**Returns:**
1570+
1571+
1572+
1573+
* ESP\_OK on success, otherwise returns ESP\_ERR\_xxx
1574+
1575+
1576+

bsp/esp-box-3/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input
3737
|:heavy_check_mark:| :microphone: AUDIO_MIC | es7210 | | |
3838
|:heavy_check_mark:| :floppy_disk: SDCARD | | idf | >=5.3 |
3939
|:heavy_check_mark:| :video_game: IMU | | [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.2 |
40+
|:heavy_check_mark:| :thermometer: HUMITURE | | [espressif/aht30](https://components.espressif.com/components/espressif/aht30) | ^1.0.0 |
4041

4142
<!-- END_DEPENDENCIES -->
4243
</div>
@@ -54,6 +55,7 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input
5455
| [LVGL Demos Example](https://github.com/espressif/esp-bsp/tree/master/examples/display_lvgl_demos) | Run the LVGL demo player - all LVGL examples are included (LVGL) | [Flash Example](https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-bsp/config.toml&app=display_lvgl_demos-) |
5556
| [Display Rotation Example](https://github.com/espressif/esp-bsp/tree/master/examples/display_rotation) | Rotate screen using buttons or an accelerometer (`BSP_CAPS_IMU`, if available) | [Flash Example](https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-bsp/config.toml&app=display_rotation-) |
5657
| [Display SD card Example](https://github.com/espressif/esp-bsp/tree/master/examples/display_sdcard) | Example of mounting an SD card using SD-MMC/SPI with display interaction. This example is also supported on boards without a display. | [Flash Example](https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-bsp/config.toml&app=display_sdcard) |
58+
| [Sensors Example](https://github.com/espressif/esp-bsp/tree/master/examples/sensors) | Acquire sensor data using the sensor hub component | [Flash Example](https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-bsp/config.toml&app=sensors) |
5759

5860
<!-- END_EXAMPLES -->
5961
</div>

bsp/esp-box-3/esp-box-3.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828
#include "bsp_err_check.h"
2929
#include "esp_codec_dev_defaults.h"
3030

31+
#include "icm42670.h"
32+
#include "aht30.h"
33+
3134
static const char *TAG = "ESP-BOX-3";
3235

36+
#define I2C_CLK_SPEED 400000
37+
3338
/** @cond */
3439
_Static_assert(CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0, "Touch buttons must be supported for this BSP");
3540
/** @endcond */
@@ -73,6 +78,7 @@ static bool spi_sd_initialized = false;
7378
* For IDF 5.2 and 5.3 you must call bsp_i2c_get_handle()
7479
*/
7580
static i2c_master_bus_handle_t i2c_handle = NULL;
81+
static i2c_master_bus_handle_t i2c_dock_handle = NULL;
7682
static bool i2c_initialized = false;
7783

7884
// This is just a wrapper to get function signature for espressif/button API callback
@@ -132,13 +138,32 @@ esp_err_t bsp_i2c_init(void)
132138
};
133139
BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_config, &i2c_handle));
134140

141+
const i2c_master_bus_config_t i2c_dock_config = {
142+
#if BSP_I2C_NUM == 1
143+
.i2c_port = 0,
144+
#else
145+
.i2c_port = 1,
146+
#endif
147+
.sda_io_num = BSP_I2C_DOCK_SDA,
148+
.scl_io_num = BSP_I2C_DOCK_SCL,
149+
.clk_source = I2C_CLK_SRC_DEFAULT,
150+
};
151+
152+
esp_err_t ret = i2c_new_master_bus(&i2c_dock_config, &i2c_dock_handle);
153+
if (ret != ESP_OK) {
154+
i2c_del_master_bus(i2c_handle);
155+
i2c_handle = NULL;
156+
return ret;
157+
}
158+
135159
i2c_initialized = true;
136160
return ESP_OK;
137161
}
138162

139163
esp_err_t bsp_i2c_deinit(void)
140164
{
141165
BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_handle));
166+
BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_dock_handle));
142167
i2c_initialized = false;
143168
return ESP_OK;
144169
}
@@ -842,3 +867,36 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
842867
}
843868
return ret;
844869
}
870+
871+
esp_err_t bsp_sensor_init(const bsp_sensor_config_t *cfg, sensor_handle_t *sensor_handle)
872+
{
873+
ESP_RETURN_ON_FALSE(cfg != NULL, ESP_ERR_INVALID_ARG, TAG, "Pointer to the sensor config can't be NULL");
874+
ESP_RETURN_ON_FALSE(sensor_handle != NULL, ESP_ERR_INVALID_ARG, TAG, "Pointer to the sensor handle can't be NULL");
875+
876+
esp_err_t err = ESP_OK;
877+
878+
BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());
879+
880+
sensor_config_t config = {
881+
.type = cfg->type,
882+
.mode = cfg->mode,
883+
.min_delay = cfg->period
884+
};
885+
886+
switch (cfg->type) {
887+
case IMU_ID:
888+
config.bus = i2c_handle;
889+
config.addr = ICM42670_I2C_ADDRESS;
890+
err = iot_sensor_create("sensor_hub_icm42670", &config, sensor_handle);
891+
break;
892+
case HUMITURE_ID:
893+
config.bus = i2c_dock_handle;
894+
config.addr = AHT30_I2C_ADDRESS;
895+
err = iot_sensor_create("sensor_hub_aht30", &config, sensor_handle);
896+
break;
897+
default:
898+
return ESP_FAIL;
899+
}
900+
901+
return err;
902+
}

0 commit comments

Comments
 (0)