-
Notifications
You must be signed in to change notification settings - Fork 177
ICM42670: I2C Driver-NG #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| version: "1.0.0" | ||
| version: "2.0.0" | ||
| description: I2C driver for ICM 42670 6-Axis MotionTracking | ||
| url: https://github.com/espressif/esp-bsp/tree/master/components/icm42670 | ||
| dependencies: | ||
| idf: ">=4.4" | ||
| idf: ">=5.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # 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") | ||
| set(COMPONENTS main) | ||
| include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
| project(test_app_icm42670) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| idf_component_register( | ||
| SRCS "test_app_icm42670.c" | ||
| REQUIRES unity | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ## IDF Component Manager Manifest File | ||
| dependencies: | ||
| idf: ">=5.2" | ||
| icm42670: | ||
| version: "*" | ||
| override_path: "../../" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include "unity.h" | ||
| #include "driver/i2c_master.h" | ||
| #include "icm42670.h" | ||
| #include "esp_system.h" | ||
| #include "esp_log.h" | ||
| #include "unity.h" | ||
| #include "unity_test_runner.h" | ||
| #include "unity_test_utils_memory.h" | ||
|
|
||
| #include "freertos/FreeRTOS.h" | ||
| #include "freertos/task.h" | ||
|
|
||
| // Pinout for ESP32-S3-BOX | ||
| #define I2C_MASTER_SCL_IO 18 /*!< gpio number for I2C master clock */ | ||
| #define I2C_MASTER_SDA_IO 8 /*!< gpio number for I2C master data */ | ||
| #define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */ | ||
|
|
||
| static const char *TAG = "icm42670 test"; | ||
| static icm42670_handle_t icm42670 = NULL; | ||
| static i2c_master_bus_handle_t i2c_handle = NULL; | ||
|
|
||
| static void i2c_bus_init(void) | ||
| { | ||
| const i2c_master_bus_config_t bus_config = { | ||
| .i2c_port = I2C_MASTER_NUM, | ||
| .sda_io_num = I2C_MASTER_SDA_IO, | ||
| .scl_io_num = I2C_MASTER_SCL_IO, | ||
| .clk_source = I2C_CLK_SRC_DEFAULT, | ||
| }; | ||
|
|
||
| esp_err_t ret = i2c_new_master_bus(&bus_config, &i2c_handle); | ||
| TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "I2C install returned error"); | ||
| } | ||
|
|
||
| static void i2c_sensor_icm42670_init(void) | ||
| { | ||
| esp_err_t ret; | ||
|
|
||
| i2c_bus_init(); | ||
| ret = icm42670_create(i2c_handle, ICM42670_I2C_ADDRESS, &icm42670); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| TEST_ASSERT_NOT_NULL_MESSAGE(icm42670, "icm42670 create returned NULL"); | ||
|
|
||
| /* Configuration of the accelerometer and gyroscope */ | ||
| const icm42670_cfg_t imu_cfg = { | ||
| .acce_fs = ACCE_FS_2G, | ||
| .acce_odr = ACCE_ODR_400HZ, | ||
| .gyro_fs = GYRO_FS_2000DPS, | ||
| .gyro_odr = GYRO_ODR_400HZ, | ||
| }; | ||
| ret = icm42670_config(icm42670, &imu_cfg); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| } | ||
|
|
||
| TEST_CASE("Sensor icm42670 test", "[icm42670]") | ||
| { | ||
| esp_err_t ret; | ||
| icm42670_value_t acc, gyro; | ||
| float temperature; | ||
|
|
||
| i2c_sensor_icm42670_init(); | ||
|
|
||
| /* Set accelerometer and gyroscope to ON */ | ||
| ret = icm42670_acce_set_pwr(icm42670, ACCE_PWR_LOWNOISE); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| ret = icm42670_gyro_set_pwr(icm42670, GYRO_PWR_LOWNOISE); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
|
|
||
| for (int i = 0; i < 100; i++) { | ||
| vTaskDelay(pdMS_TO_TICKS(50)); | ||
| ret = icm42670_get_acce_value(icm42670, &acc); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| ret = icm42670_get_gyro_value(icm42670, &gyro); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| ret = icm42670_get_temp_value(icm42670, &temperature); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| ESP_LOGI(TAG, "acc_x:%.2f, acc_y:%.2f, acc_z:%.2f, gyro_x:%.2f, gyro_y:%.2f, gyro_z:%.2f temp: %.1f", | ||
| acc.x, acc.y, acc.z, gyro.x, gyro.y, gyro.z, temperature); | ||
| } | ||
|
|
||
| icm42670_delete(icm42670); | ||
| ret = i2c_del_master_bus(i2c_handle); | ||
| TEST_ASSERT_EQUAL(ESP_OK, ret); | ||
| vTaskDelay(10); // Give FreeRTOS some time to free its resources | ||
| } | ||
|
|
||
| #define TEST_MEMORY_LEAK_THRESHOLD (400) | ||
|
|
||
| void setUp(void) | ||
| { | ||
| unity_utils_set_leak_level(TEST_MEMORY_LEAK_THRESHOLD); | ||
| unity_utils_record_free_mem(); | ||
| } | ||
|
|
||
| void tearDown(void) | ||
| { | ||
| unity_utils_evaluate_leaks(); | ||
| } | ||
|
|
||
| void app_main(void) | ||
| { | ||
| unity_run_menu(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 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_TASK_WDT_EN=n | ||
| CONFIG_FREERTOS_HZ=1000 | ||
| CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| idf_component_register(SRCS "test_esp_acc_qma6100p.c") | ||
| idf_component_register( | ||
| SRCS "test_esp_acc_qma6100p.c" | ||
| REQUIRES unity | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.