From d431386a82570b8b65757f6da7f15951befc78c6 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Tue, 22 Oct 2024 14:20:38 +0200 Subject: [PATCH 1/2] fix(icm42670): Fix incorrect conversion functions --- components/icm42670/README.md | 5 ++--- components/icm42670/icm42670.c | 8 ++++---- components/icm42670/idf_component.yml | 2 +- components/icm42670/test_apps/main/test_app_icm42670.c | 2 +- components/icm42670/test_apps/sdkconfig.defaults | 10 ++++------ 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/components/icm42670/README.md b/components/icm42670/README.md index d7ecd68f..0f03fd4e 100644 --- a/components/icm42670/README.md +++ b/components/icm42670/README.md @@ -1,6 +1,7 @@ # ICM42607/ICM42670 6-Axis MotionTracking (Accelerometer and Gyroscope) [![Component Registry](https://components.espressif.com/components/espressif/icm42670/badge.svg)](https://components.espressif.com/components/espressif/icm42670) +![maintenance-status](https://img.shields.io/badge/maintenance-passively--maintained-yellowgreen.svg) C driver for Invensense ICM42607/ICM42670 6-axis gyroscope and accelerometer based on I2C communication. @@ -27,6 +28,4 @@ This driver, along with many other components from this repository, can be used Another option is to manually create a `idf_component.yml` file. You can find more about using .yml files for components from [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html). ## See Also -* [MPU6050 datasheet](https://invensense.tdk.com/products/motion-tracking/6-axis/icm-42670-p/) - - +* [ICM42670 datasheet](https://invensense.tdk.com/products/motion-tracking/6-axis/icm-42670-p/) diff --git a/components/icm42670/icm42670.c b/components/icm42670/icm42670.c index ab00dafd..f95ae0da 100644 --- a/components/icm42670/icm42670.c +++ b/components/icm42670/icm42670.c @@ -186,7 +186,7 @@ esp_err_t icm42670_get_acce_sensitivity(icm42670_handle_t sensor, float *sensiti ret = icm42670_read(sensor, ICM42670_ACCEL_CONFIG0, &acce_fs, 1); if (ret == ESP_OK) { - acce_fs = (acce_fs >> 3) & 0x03; + acce_fs = (acce_fs >> 5) & 0x03; switch (acce_fs) { case ACCE_FS_16G: *sensitivity = ACCE_FS_16G_SENSITIVITY; @@ -215,9 +215,9 @@ esp_err_t icm42670_get_gyro_sensitivity(icm42670_handle_t sensor, float *sensiti *sensitivity = 0; - ret = icm42670_read(sensor, ICM42670_ACCEL_CONFIG0, &gyro_fs, 1); + ret = icm42670_read(sensor, ICM42670_GYRO_CONFIG0, &gyro_fs, 1); if (ret == ESP_OK) { - gyro_fs = (gyro_fs >> 3) & 0x03; + gyro_fs = (gyro_fs >> 5) & 0x03; switch (gyro_fs) { case GYRO_FS_2000DPS: *sensitivity = GYRO_FS_2000_SENSITIVITY; @@ -326,7 +326,7 @@ esp_err_t icm42670_get_temp_value(icm42670_handle_t sensor, float *value) ret = icm42670_get_temp_raw_value(sensor, &raw_value); ESP_RETURN_ON_ERROR(ret, TAG, "Get raw value error!"); - *value = (raw_value / 128) + 25; + *value = ((float)raw_value / 128.0) + 25.0; return ESP_OK; } diff --git a/components/icm42670/idf_component.yml b/components/icm42670/idf_component.yml index 1499f793..c3317f90 100644 --- a/components/icm42670/idf_component.yml +++ b/components/icm42670/idf_component.yml @@ -1,4 +1,4 @@ -version: "2.0.0" +version: "2.0.1" description: I2C driver for ICM 42670 6-Axis MotionTracking url: https://github.com/espressif/esp-bsp/tree/master/components/icm42670 dependencies: diff --git a/components/icm42670/test_apps/main/test_app_icm42670.c b/components/icm42670/test_apps/main/test_app_icm42670.c index 0333f8a6..8622fd06 100644 --- a/components/icm42670/test_apps/main/test_app_icm42670.c +++ b/components/icm42670/test_apps/main/test_app_icm42670.c @@ -91,7 +91,7 @@ TEST_CASE("Sensor icm42670 test", "[icm42670]") vTaskDelay(10); // Give FreeRTOS some time to free its resources } -#define TEST_MEMORY_LEAK_THRESHOLD (400) +#define TEST_MEMORY_LEAK_THRESHOLD (500) void setUp(void) { diff --git a/components/icm42670/test_apps/sdkconfig.defaults b/components/icm42670/test_apps/sdkconfig.defaults index b5b36e5c..414ce50c 100644 --- a/components/icm42670/test_apps/sdkconfig.defaults +++ b/components/icm42670/test_apps/sdkconfig.defaults @@ -1,12 +1,10 @@ +# This file was generated using idf.py save-defconfig. It can be edited manually. +# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration +# CONFIG_IDF_TARGET="esp32s3" -CONFIG_ESPTOOLPY_FLASHFREQ_80M=y CONFIG_COMPILER_OPTIMIZATION_PERF=y -CONFIG_SPIRAM=y -CONFIG_SPIRAM_MODE_OCT=y -CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y -CONFIG_SPIRAM_RODATA=y -CONFIG_SPIRAM_SPEED_80M=y CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y CONFIG_ESP_TASK_WDT_EN=n CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 From dcd944c752f1bc7084ba583422bfa284d7172713 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Tue, 22 Oct 2024 14:21:11 +0200 Subject: [PATCH 2/2] fix(m5stack_core_s3): Make I2C dependency private --- bsp/m5stack_core_s3/CMakeLists.txt | 4 ++-- bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h | 1 - bsp/m5stack_core_s3/m5stack_core_s3.c | 13 +++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bsp/m5stack_core_s3/CMakeLists.txt b/bsp/m5stack_core_s3/CMakeLists.txt index 8bbafa4a..df8b67ce 100644 --- a/bsp/m5stack_core_s3/CMakeLists.txt +++ b/bsp/m5stack_core_s3/CMakeLists.txt @@ -2,6 +2,6 @@ idf_component_register( SRCS "m5stack_core_s3.c" "m5stack_core_s3_idf5.c" INCLUDE_DIRS "include" PRIV_INCLUDE_DIRS "priv_include" - REQUIRES esp_driver_i2c esp_driver_i2s esp_driver_gpio esp_driver_sdmmc spiffs - PRIV_REQUIRES fatfs esp_lcd esp_driver_spi + REQUIRES esp_driver_i2s esp_driver_gpio esp_driver_sdmmc spiffs + PRIV_REQUIRES fatfs esp_lcd esp_driver_spi esp_driver_i2c ) diff --git a/bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h b/bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h index da7c4891..86b5fba1 100644 --- a/bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h +++ b/bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h @@ -13,7 +13,6 @@ #include "sdkconfig.h" #include "driver/gpio.h" -#include "driver/i2c_master.h" #include "driver/i2s_std.h" #include "driver/sdmmc_host.h" #include "soc/usb_pins.h" diff --git a/bsp/m5stack_core_s3/m5stack_core_s3.c b/bsp/m5stack_core_s3/m5stack_core_s3.c index f2fd53c7..3ad63626 100644 --- a/bsp/m5stack_core_s3/m5stack_core_s3.c +++ b/bsp/m5stack_core_s3/m5stack_core_s3.c @@ -5,7 +5,9 @@ */ #include "driver/gpio.h" +#include "driver/i2c_master.h" #include "driver/spi_master.h" +#include "driver/sdspi_host.h" #include "esp_err.h" #include "esp_log.h" #include "esp_check.h" @@ -14,7 +16,6 @@ #include "esp_lcd_panel_vendor.h" #include "esp_lcd_panel_ops.h" #include "esp_vfs_fat.h" -#include "driver/sdspi_host.h" #include "bsp/m5stack_core_s3.h" #include "bsp/display.h" @@ -49,7 +50,7 @@ sdmmc_card_t *bsp_sdcard = NULL; // Global SD card handler * @brief I2C handle for BSP usage * * You can call i2c_master_get_bus_handle(BSP_I2C_NUM, i2c_master_bus_handle_t *ret_handle) - * from #include "esp_private/i2c_platforma.h" + * from #include "esp_private/i2c_platform.h" */ static i2c_master_bus_handle_t i2c_handle = NULL; static bool i2c_initialized = false; @@ -68,7 +69,7 @@ esp_err_t bsp_i2c_init(void) .i2c_port = BSP_I2C_NUM, .sda_io_num = BSP_I2C_SDA, .scl_io_num = BSP_I2C_SCL, - .clk_source = 1, + .clk_source = I2C_CLK_SRC_DEFAULT, }; BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_config, &i2c_handle)); @@ -76,13 +77,13 @@ esp_err_t bsp_i2c_init(void) const i2c_device_config_t axp2101_config = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = BSP_AXP2101_ADDR, - .scl_speed_hz = 400000, + .scl_speed_hz = CONFIG_BSP_I2C_CLK_SPEED_HZ, }; BSP_ERROR_CHECK_RETURN_ERR(i2c_master_bus_add_device(i2c_handle, &axp2101_config, &axp2101_h)); const i2c_device_config_t aw9523_config = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = BSP_AW9523_ADDR, - .scl_speed_hz = 400000, + .scl_speed_hz = CONFIG_BSP_I2C_CLK_SPEED_HZ, }; BSP_ERROR_CHECK_RETURN_ERR(i2c_master_bus_add_device(i2c_handle, &aw9523_config, &aw9523_h)); @@ -435,7 +436,7 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t }; esp_lcd_panel_io_handle_t tp_io_handle = NULL; esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG(); - tp_io_config.scl_speed_hz = 400000; // This parameter was introduce together with I2C Driver-NG in IDF v5.2 + tp_io_config.scl_speed_hz = CONFIG_BSP_I2C_CLK_SPEED_HZ; // This parameter was introduced together with I2C Driver-NG in IDF v5.2 ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, ""); return esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, ret_touch); }