From b1e8a42fe6b0450c1a6b9aae990f45b4a25f97bc Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Tue, 22 Oct 2024 17:57:51 +0200 Subject: [PATCH] feat(esp-box-3): Add default examples --- .build-test-rules.yml | 4 +--- bsp/esp-box-3/CMakeLists.txt | 4 ++-- bsp/esp-box-3/README.md | 2 +- bsp/esp-box-3/esp-box-3.c | 13 ++++++++++--- bsp/esp-box-3/idf_component.yml | 6 +++++- bsp/esp-box-3/include/bsp/esp-box-3.h | 14 +++++++++----- bsp/esp-box/idf_component.yml | 4 ---- .../display_audio_photo/main/idf_component.yml | 4 ++-- examples/display_audio_photo/sdkconfig.defaults | 1 + examples/display_rotation/main/CMakeLists.txt | 1 + examples/display_rotation/main/idf_component.yml | 4 ++-- examples/display_rotation/main/main.c | 13 +++++++------ examples/display_rotation/sdkconfig.defaults | 1 + 13 files changed, 42 insertions(+), 29 deletions(-) diff --git a/.build-test-rules.yml b/.build-test-rules.yml index 3c2bd955..f1cdf35f 100644 --- a/.build-test-rules.yml +++ b/.build-test-rules.yml @@ -3,9 +3,7 @@ examples: disable: - if: CONFIG_NAME in ["esp-box", "esp-box-lite"] reason: Do not build examples for deprecated BSPs - - if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 2) and CONFIG_NAME == "esp-box-3" - reason: Example depends on BSP, which is supported only for IDF >= 5.2 - - if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 3) and CONFIG_NAME == "esp32_p4_function_ev_board" + - if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 3) and CONFIG_NAME in ["esp32_p4_function_ev_board", "esp-box-3"] reason: Example depends on BSP, which is supported only for IDF >= 5.3 - if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 4) and CONFIG_NAME == "m5stack_core_s3" reason: Example depends on BSP, which is supported only for IDF >= 5.4 diff --git a/bsp/esp-box-3/CMakeLists.txt b/bsp/esp-box-3/CMakeLists.txt index f58e73ad..623999b7 100644 --- a/bsp/esp-box-3/CMakeLists.txt +++ b/bsp/esp-box-3/CMakeLists.txt @@ -2,6 +2,6 @@ idf_component_register( SRCS "esp-box-3.c" "esp-box-3_idf5.c" INCLUDE_DIRS "include" PRIV_INCLUDE_DIRS "priv_include" - REQUIRES esp_driver_i2s esp_driver_gpio esp_driver_sdmmc spiffs - PRIV_REQUIRES fatfs esp_lcd esp_driver_spi esp_driver_i2c + REQUIRES driver spiffs + PRIV_REQUIRES fatfs esp_lcd ) diff --git a/bsp/esp-box-3/README.md b/bsp/esp-box-3/README.md index 6a35c50c..ad3b126a 100644 --- a/bsp/esp-box-3/README.md +++ b/bsp/esp-box-3/README.md @@ -25,6 +25,6 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input | AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.3.1| |AUDIO_SPEAKER|:heavy_check_mark:| | | | AUDIO_MIC |:heavy_check_mark:| | | -| SDCARD |:heavy_check_mark:| idf | >=5.2 | +| SDCARD |:heavy_check_mark:| idf | >=5.3 | | IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1| diff --git a/bsp/esp-box-3/esp-box-3.c b/bsp/esp-box-3/esp-box-3.c index 092cf526..50c0ceae 100644 --- a/bsp/esp-box-3/esp-box-3.c +++ b/bsp/esp-box-3/esp-box-3.c @@ -7,7 +7,6 @@ #include "driver/gpio.h" #include "driver/ledc.h" #include "driver/spi_master.h" -#include "driver/i2c_master.h" #include "esp_err.h" #include "esp_log.h" #include "esp_check.h" @@ -63,8 +62,10 @@ 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_platform.h" + * In IDF v5.4 you can call i2c_master_get_bus_handle(BSP_I2C_NUM, i2c_master_bus_handle_t *ret_handle) + * from #include "esp_private/i2c_platform.h" to get this handle + * + * For IDF 5.2 and 5.3 you must call bsp_i2c_get_handle() */ static i2c_master_bus_handle_t i2c_handle = NULL; static bool i2c_initialized = false; @@ -120,6 +121,12 @@ esp_err_t bsp_i2c_deinit(void) return ESP_OK; } +i2c_master_bus_handle_t bsp_i2c_get_handle(void) +{ + bsp_i2c_init(); + return i2c_handle; +} + static esp_err_t bsp_i2c_device_probe(uint8_t addr) { return i2c_master_probe(i2c_handle, addr, 100); diff --git a/bsp/esp-box-3/idf_component.yml b/bsp/esp-box-3/idf_component.yml index f47d2ad4..731f1ac5 100644 --- a/bsp/esp-box-3/idf_component.yml +++ b/bsp/esp-box-3/idf_component.yml @@ -10,7 +10,7 @@ tags: - bsp dependencies: - idf: ">=5.2" # We use I2C Driver-NG from IDF v5.2 + idf: ">=5.3" # We use I2C Driver-NG from IDF v5.2 but esp-codec-dev supports from v5.3 esp_lcd_touch_tt21100: "^1" esp_lcd_touch_gt911: "^1" esp_lcd_ili9341: "^1" @@ -31,3 +31,7 @@ dependencies: icm42670: version: "^2.0.1" public: true + +examples: + - path: ../../examples/display_audio_photo + - path: ../../examples/display_rotation diff --git a/bsp/esp-box-3/include/bsp/esp-box-3.h b/bsp/esp-box-3/include/bsp/esp-box-3.h index 7f1c2506..5d17a499 100644 --- a/bsp/esp-box-3/include/bsp/esp-box-3.h +++ b/bsp/esp-box-3/include/bsp/esp-box-3.h @@ -14,6 +14,7 @@ #include "sdkconfig.h" #include "driver/gpio.h" #include "driver/i2s_std.h" +#include "driver/i2c_master.h" #include "driver/sdmmc_host.h" #include "soc/usb_pins.h" #include "lvgl.h" @@ -210,11 +211,6 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void); * - Encryption chip ATECC608A (NOT populated on most boards) * - LCD Touch controller * - Inertial Measurement Unit ICM-42607-P - * - * After initialization of I2C, use BSP_I2C_NUM macro when creating I2C devices drivers ie.: - * \code{.c} - * icm42670_handle_t imu = icm42670_create(BSP_I2C_NUM, ICM42670_I2C_ADDRESS); - * \endcode **************************************************************************************************/ #define BSP_I2C_NUM CONFIG_BSP_I2C_NUM @@ -239,6 +235,14 @@ esp_err_t bsp_i2c_init(void); */ esp_err_t bsp_i2c_deinit(void); +/** + * @brief Get I2C driver handle + * + * @return + * - I2C handle + */ +i2c_master_bus_handle_t bsp_i2c_get_handle(void); + /************************************************************************************************** * * SPIFFS diff --git a/bsp/esp-box/idf_component.yml b/bsp/esp-box/idf_component.yml index b4b4e97d..999b4b0e 100644 --- a/bsp/esp-box/idf_component.yml +++ b/bsp/esp-box/idf_component.yml @@ -29,7 +29,3 @@ dependencies: icm42670: version: "^1" public: true - -examples: - - path: ../../examples/display_audio_photo - - path: ../../examples/display_rotation diff --git a/examples/display_audio_photo/main/idf_component.yml b/examples/display_audio_photo/main/idf_component.yml index fc28d292..19518415 100644 --- a/examples/display_audio_photo/main/idf_component.yml +++ b/examples/display_audio_photo/main/idf_component.yml @@ -1,6 +1,6 @@ description: BSP Display Audio Photo Example dependencies: esp_jpeg: "*" - esp-box: + esp-box-3: version: "*" - override_path: "../../../bsp/esp-box" + override_path: "../../../bsp/esp-box-3" diff --git a/examples/display_audio_photo/sdkconfig.defaults b/examples/display_audio_photo/sdkconfig.defaults index 9f4a5db4..59e852cb 100644 --- a/examples/display_audio_photo/sdkconfig.defaults +++ b/examples/display_audio_photo/sdkconfig.defaults @@ -12,6 +12,7 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_SPIFFS_PAGE_SIZE=1024 CONFIG_LV_SPRINTF_CUSTOM=y # CONFIG_LV_BUILD_EXAMPLES is not set +CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n ## LVGL8 ## CONFIG_LV_USE_PERF_MONITOR=y diff --git a/examples/display_rotation/main/CMakeLists.txt b/examples/display_rotation/main/CMakeLists.txt index 914c3a10..418ff41a 100644 --- a/examples/display_rotation/main/CMakeLists.txt +++ b/examples/display_rotation/main/CMakeLists.txt @@ -1,4 +1,5 @@ idf_component_register(SRCS "main.c" + REQUIRES driver INCLUDE_DIRS ".") lvgl_port_create_c_image("images/esp_logo.png" "images/gen/" "ARGB8888" "NONE") diff --git a/examples/display_rotation/main/idf_component.yml b/examples/display_rotation/main/idf_component.yml index 621521bc..81d49c90 100644 --- a/examples/display_rotation/main/idf_component.yml +++ b/examples/display_rotation/main/idf_component.yml @@ -1,5 +1,5 @@ description: BSP Display rotation example dependencies: - esp-box: + esp-box-3: version: "*" - override_path: "../../../bsp/esp-box" + override_path: "../../../bsp/esp-box-3" diff --git a/examples/display_rotation/main/main.c b/examples/display_rotation/main/main.c index 51e41047..483e99a7 100644 --- a/examples/display_rotation/main/main.c +++ b/examples/display_rotation/main/main.c @@ -140,9 +140,10 @@ static void app_lvgl_display(void) #if BSP_CAPS_IMU static void app_imu_init(void) { - imu = icm42670_create(BSP_I2C_NUM, ICM42670_I2C_ADDRESS); + i2c_master_bus_handle_t i2c_handle = bsp_i2c_get_handle(); + ESP_ERROR_CHECK(icm42670_create(i2c_handle, ICM42670_I2C_ADDRESS, &imu)); if (imu) { - /* Configuration of the acceleremeter and gyroscope */ + /* Configuration of the accelerometer and gyroscope */ const icm42670_cfg_t imu_cfg = { .acce_fs = ACCE_FS_2G, .acce_odr = ACCE_ODR_400HZ, @@ -175,7 +176,7 @@ static void app_imu_read(void) icm42670_complimentory_filter(imu, &acce_val, &gyro_val, &angle); ESP_LOGI(TAG, "Angle roll: %.2f pitch: %.2f ", angle.roll, angle.pitch); - if (acce_val.x > 5) { + if (acce_val.y < -0.6) { if (rotation != LV_DISPLAY_ROTATION_0) { rotation = LV_DISPLAY_ROTATION_0; bsp_display_lock(0); @@ -183,7 +184,7 @@ static void app_imu_read(void) lv_label_set_text_fmt(lbl_rotation, "Rotation %d°", app_lvgl_get_rotation_degrees(rotation)); bsp_display_unlock(); } - } else if (acce_val.x < -5) { + } else if (acce_val.y > 0.6) { if (rotation != LV_DISPLAY_ROTATION_180) { rotation = LV_DISPLAY_ROTATION_180; bsp_display_lock(0); @@ -191,7 +192,7 @@ static void app_imu_read(void) lv_label_set_text_fmt(lbl_rotation, "Rotation %d°", app_lvgl_get_rotation_degrees(rotation)); bsp_display_unlock(); } - } else if (acce_val.y > 5) { + } else if (acce_val.x > 0.6) { if (rotation != LV_DISPLAY_ROTATION_270) { rotation = LV_DISPLAY_ROTATION_270; bsp_display_lock(0); @@ -199,7 +200,7 @@ static void app_imu_read(void) lv_label_set_text_fmt(lbl_rotation, "Rotation %d°", app_lvgl_get_rotation_degrees(rotation)); bsp_display_unlock(); } - } else if (acce_val.y < -5) { + } else if (acce_val.x < -0.6) { if (rotation != LV_DISPLAY_ROTATION_90) { rotation = LV_DISPLAY_ROTATION_90; bsp_display_lock(0); diff --git a/examples/display_rotation/sdkconfig.defaults b/examples/display_rotation/sdkconfig.defaults index c862604d..20785c31 100644 --- a/examples/display_rotation/sdkconfig.defaults +++ b/examples/display_rotation/sdkconfig.defaults @@ -3,6 +3,7 @@ # CONFIG_IDF_TARGET="esp32s3" # CONFIG_LV_BUILD_EXAMPLES is not set +CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n ## LVGL8 ## CONFIG_LV_USE_PERF_MONITOR=y