Skip to content

Commit 3936e75

Browse files
committed
feat(sensors): Move ICM42670 to the sensors folder and add sensor hub functionality
1 parent fda65f6 commit 3936e75

15 files changed

Lines changed: 89 additions & 10 deletions

File tree

.github/workflows/upload_component.yml

Lines changed: 3 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,7 @@ 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
106106
namespace: "espressif"
107107
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
108108
dry_run: ${{ github.ref_name != 'master' || github.repository_owner != 'espressif' }}

bsp/esp-box-3/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies:
3636
icm42670:
3737
version: ^2.0.2
3838
public: true
39-
override_path: "../../components/icm42670"
39+
override_path: ../../components/sensors/icm42670
4040

4141
examples:
4242
- path: ../../examples/display

bsp/esp-box/idf_component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags:
1111

1212
dependencies:
1313
idf: ">=4.4.5,<6.0"
14-
esp_lcd_touch_tt21100:
14+
esp_lcd_touch_tt21100:
1515
version: "^1"
1616
override_path: "../../components/lcd_touch/esp_lcd_touch_tt21100"
1717

@@ -31,4 +31,4 @@ dependencies:
3131
icm42670:
3232
version: "^1"
3333
public: true
34-
override_path: "../../components/icm42670"
34+
override_path: "../../components/sensors/icm42670"

components/.build-test-rules.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ components/ds18b20:
3434
- if: SOC_RMT_SUPPORTED != 1
3535
reason: Onewire component depends on RMT peripheral
3636

37-
components/icm42670:
37+
components/sensors/icm42670:
3838
depends_filepatterns:
39-
- "components/icm42670/**"
39+
- "components/sensors/icm42670/**"
4040
disable:
4141
- if: IDF_VERSION < "5.2.0"
4242
reason: Requires I2C Driver-NG which was introduced in v5.2

components/icm42670/CMakeLists.txt renamed to components/sensors/icm42670/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ else()
55
endif()
66

77
idf_component_register(SRCS "icm42670.c" INCLUDE_DIRS "include" REQUIRES ${REQ} esp_timer)
8+
9+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u icm42670_impl_init")
File renamed without changes.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "esp_check.h"
1414
#include "esp_rom_sys.h"
1515
#include "esp_timer.h"
16+
#include "iot_sensor_hub.h"
1617
#include "icm42670.h"
1718

1819
#define I2C_CLK_SPEED 400000
@@ -482,3 +483,76 @@ esp_err_t icm42670_write_mreg_register(icm42670_handle_t sensor, uint8_t mreg, u
482483

483484
return ESP_OK;
484485
}
486+
487+
static icm42670_handle_t sensor_hub_icm42670_handle;
488+
489+
esp_err_t icm42670_impl_init(bus_handle_t bus_handle, uint8_t addr)
490+
{
491+
ESP_RETURN_ON_ERROR(icm42670_create(bus_handle, addr, &sensor_hub_icm42670_handle), TAG,
492+
"Failed to initialize ICM42670");
493+
if (sensor_hub_icm42670_handle) {
494+
/* Configuration of the accelerometer and gyroscope */
495+
const icm42670_cfg_t icm42670_cfg = {
496+
.acce_fs = ACCE_FS_2G,
497+
.acce_odr = ACCE_ODR_400HZ,
498+
.gyro_fs = GYRO_FS_2000DPS,
499+
.gyro_odr = GYRO_ODR_400HZ,
500+
};
501+
ESP_RETURN_ON_ERROR(icm42670_config(sensor_hub_icm42670_handle, &icm42670_cfg), TAG, "Failed to initialize ICM42670");
502+
503+
/* Set accelerometer and gyroscope to ON */
504+
ESP_RETURN_ON_ERROR(icm42670_acce_set_pwr(sensor_hub_icm42670_handle, ACCE_PWR_LOWNOISE), TAG,
505+
"Failed to set ICM42670 accelerometer power setting");
506+
ESP_RETURN_ON_ERROR(icm42670_gyro_set_pwr(sensor_hub_icm42670_handle, GYRO_PWR_LOWNOISE), TAG,
507+
"Failed to set ICM42670 gyroscope power setting");
508+
return ESP_OK;
509+
}
510+
return ESP_FAIL;
511+
}
512+
513+
esp_err_t icm42670_impl_deinit(void)
514+
{
515+
ESP_RETURN_ON_FALSE(sensor_hub_icm42670_handle != NULL, ESP_ERR_INVALID_STATE, TAG,
516+
"Failed to delete uninitialized ICM42670");
517+
icm42670_delete(sensor_hub_icm42670_handle);
518+
sensor_hub_icm42670_handle = NULL;
519+
return ESP_OK;
520+
}
521+
522+
esp_err_t icm42670_impl_test (void)
523+
{
524+
uint8_t device_id;
525+
return icm42670_get_deviceid(sensor_hub_icm42670_handle, &device_id);
526+
}
527+
528+
esp_err_t icm42670_impl_acquire_acce (float *acce_x, float *acce_y, float *acce_z)
529+
{
530+
icm42670_value_t value;
531+
ESP_RETURN_ON_ERROR(icm42670_get_acce_value(sensor_hub_icm42670_handle, &value), TAG,
532+
"Failed to read acceleration data");
533+
*acce_x = value.x;
534+
*acce_y = value.y;
535+
*acce_z = value.z;
536+
return ESP_OK;
537+
}
538+
539+
esp_err_t icm42670_impl_acquire_gyro(float *gyro_x, float *gyro_y, float *gyro_z)
540+
{
541+
icm42670_value_t value;
542+
ESP_RETURN_ON_ERROR(icm42670_get_gyro_value(sensor_hub_icm42670_handle, &value), TAG,
543+
"Failed to read acceleration data");
544+
*gyro_x = value.x;
545+
*gyro_y = value.y;
546+
*gyro_z = value.z;
547+
return ESP_OK;
548+
}
549+
550+
static imu_impl_t icm42670_impl = {
551+
.init = icm42670_impl_init,
552+
.deinit = icm42670_impl_deinit,
553+
.test = icm42670_impl_test,
554+
.acquire_acce = icm42670_impl_acquire_acce,
555+
.acquire_gyro = icm42670_impl_acquire_gyro,
556+
};
557+
558+
SENSOR_HUB_DETECT_FN(IMU_ID, sensor_hub_icm42670, &icm42670_impl);
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
version: "2.0.4"
1+
version: 2.1.0
22
description: I2C driver for ICM 42670 6-Axis MotionTracking
3-
url: https://github.com/espressif/esp-bsp/tree/master/components/icm42670
3+
url: https://github.com/espressif/esp-bsp/tree/master/components/sensors/icm42670
44
dependencies:
55
idf: ">=5.2"
6+
sensor_hub:
7+
version: ^0.1.4
8+
public: true
File renamed without changes.

0 commit comments

Comments
 (0)