diff --git a/.build-test-rules.yml b/.build-test-rules.yml index f1cdf35f..6bf667c2 100644 --- a/.build-test-rules.yml +++ b/.build-test-rules.yml @@ -3,11 +3,18 @@ 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 in ["esp_bsp_generic", "esp_bsp_devkit"] + 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 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 +examples/generic_button_led: + disable: + - if: IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 2 + reason: Requires I2C Driver-NG which was introduced in v5.2 + # Noglib test_app: Build only in CI, where ENV_BUILD_NOGLIB is set test_apps/noglib: disable: diff --git a/bsp/esp_bsp_devkit/idf_component.yml b/bsp/esp_bsp_devkit/idf_component.yml index 82871c5b..20774463 100644 --- a/bsp/esp_bsp_devkit/idf_component.yml +++ b/bsp/esp_bsp_devkit/idf_component.yml @@ -1,5 +1,5 @@ -version: "1.0.1" +version: "2.0.0" description: DevKit Board Support Package (BSP) url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp_bsp_devkit @@ -7,7 +7,7 @@ tags: - bsp dependencies: - idf: ">=4.4.2" + idf: ">=5.2" button: version: ">=2.5,<4.0" diff --git a/bsp/esp_bsp_devkit/include/bsp/esp_bsp_devkit.h b/bsp/esp_bsp_devkit/include/bsp/esp_bsp_devkit.h index 73d7df4b..10972b47 100644 --- a/bsp/esp_bsp_devkit/include/bsp/esp_bsp_devkit.h +++ b/bsp/esp_bsp_devkit/include/bsp/esp_bsp_devkit.h @@ -13,7 +13,7 @@ #include "sdkconfig.h" #include "driver/gpio.h" -#include "driver/i2c.h" +#include "driver/i2c_master.h" #include "driver/sdmmc_host.h" #include "iot_button.h" #include "led_indicator.h" @@ -146,6 +146,15 @@ 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_bsp_devkit/src/esp_bsp_devkit.c b/bsp/esp_bsp_devkit/src/esp_bsp_devkit.c index 6f3d0332..82272cd2 100644 --- a/bsp/esp_bsp_devkit/src/esp_bsp_devkit.c +++ b/bsp/esp_bsp_devkit/src/esp_bsp_devkit.c @@ -16,8 +16,18 @@ static const char *TAG = "BSP-devkit"; -sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler + +/** + * @brief I2C handle for BSP usage + * + * 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; +sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler extern blink_step_t const *bsp_led_blink_defaults_lists[]; static const button_config_t bsp_button_config[] = { @@ -271,16 +281,13 @@ esp_err_t bsp_i2c_init(void) return ESP_OK; } - const i2c_config_t i2c_conf = { - .mode = I2C_MODE_MASTER, + const i2c_master_bus_config_t i2c_config = { + .i2c_port = BSP_I2C_NUM, .sda_io_num = BSP_I2C_SDA, - .sda_pullup_en = GPIO_PULLUP_DISABLE, .scl_io_num = BSP_I2C_SCL, - .scl_pullup_en = GPIO_PULLUP_DISABLE, - .master.clk_speed = CONFIG_BSP_I2C_CLK_SPEED_HZ + .clk_source = I2C_CLK_SRC_DEFAULT, }; - BSP_ERROR_CHECK_RETURN_ERR(i2c_param_config(BSP_I2C_NUM, &i2c_conf)); - BSP_ERROR_CHECK_RETURN_ERR(i2c_driver_install(BSP_I2C_NUM, i2c_conf.mode, 0, 0, 0)); + BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_config, &i2c_handle)); i2c_initialized = true; @@ -289,11 +296,17 @@ esp_err_t bsp_i2c_init(void) esp_err_t bsp_i2c_deinit(void) { - BSP_ERROR_CHECK_RETURN_ERR(i2c_driver_delete(BSP_I2C_NUM)); + BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_handle)); i2c_initialized = false; return ESP_OK; } +i2c_master_bus_handle_t bsp_i2c_get_handle(void) +{ + bsp_i2c_init(); + return i2c_handle; +} + esp_err_t bsp_spiffs_mount(void) { esp_vfs_spiffs_conf_t conf = { diff --git a/bsp/esp_bsp_generic/idf_component.yml b/bsp/esp_bsp_generic/idf_component.yml index d7ed9946..03e17c6b 100644 --- a/bsp/esp_bsp_generic/idf_component.yml +++ b/bsp/esp_bsp_generic/idf_component.yml @@ -1,5 +1,5 @@ -version: "1.2.1" +version: "2.0.0" description: Generic Board Support Package (BSP) url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp_bsp_generic @@ -7,7 +7,7 @@ tags: - bsp dependencies: - idf: ">=4.4.2" + idf: ">=5.2" esp_lcd_touch_tt21100: "^1" esp_lcd_touch_gt1151: "^1" esp_lcd_touch_gt911: "^1" diff --git a/bsp/esp_bsp_generic/include/bsp/esp_bsp_generic.h b/bsp/esp_bsp_generic/include/bsp/esp_bsp_generic.h index dfd162a1..c213333a 100644 --- a/bsp/esp_bsp_generic/include/bsp/esp_bsp_generic.h +++ b/bsp/esp_bsp_generic/include/bsp/esp_bsp_generic.h @@ -13,7 +13,7 @@ #include "sdkconfig.h" #include "driver/gpio.h" -#include "driver/i2c.h" +#include "driver/i2c_master.h" #include "driver/sdmmc_host.h" #include "iot_button.h" #include "led_indicator.h" @@ -176,6 +176,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_bsp_generic/src/esp_bsp_generic.c b/bsp/esp_bsp_generic/src/esp_bsp_generic.c index a835a041..50d464a8 100644 --- a/bsp/esp_bsp_generic/src/esp_bsp_generic.c +++ b/bsp/esp_bsp_generic/src/esp_bsp_generic.c @@ -55,8 +55,17 @@ static lv_indev_t *disp_indev = NULL; static esp_lcd_touch_handle_t tp; // LCD touch handle #endif -sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler +/** + * @brief I2C handle for BSP usage + * + * 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; +sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler extern blink_step_t const *bsp_led_blink_defaults_lists[]; static const button_config_t bsp_button_config[] = { @@ -310,16 +319,13 @@ esp_err_t bsp_i2c_init(void) return ESP_OK; } - const i2c_config_t i2c_conf = { - .mode = I2C_MODE_MASTER, + const i2c_master_bus_config_t i2c_config = { + .i2c_port = BSP_I2C_NUM, .sda_io_num = BSP_I2C_SDA, - .sda_pullup_en = GPIO_PULLUP_DISABLE, .scl_io_num = BSP_I2C_SCL, - .scl_pullup_en = GPIO_PULLUP_DISABLE, - .master.clk_speed = CONFIG_BSP_I2C_CLK_SPEED_HZ + .clk_source = I2C_CLK_SRC_DEFAULT, }; - BSP_ERROR_CHECK_RETURN_ERR(i2c_param_config(BSP_I2C_NUM, &i2c_conf)); - BSP_ERROR_CHECK_RETURN_ERR(i2c_driver_install(BSP_I2C_NUM, i2c_conf.mode, 0, 0, 0)); + BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_config, &i2c_handle)); i2c_initialized = true; @@ -328,11 +334,17 @@ esp_err_t bsp_i2c_init(void) esp_err_t bsp_i2c_deinit(void) { - BSP_ERROR_CHECK_RETURN_ERR(i2c_driver_delete(BSP_I2C_NUM)); + BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_handle)); i2c_initialized = false; return ESP_OK; } +i2c_master_bus_handle_t bsp_i2c_get_handle(void) +{ + bsp_i2c_init(); + return i2c_handle; +} + esp_err_t bsp_spiffs_mount(void) { esp_vfs_spiffs_conf_t conf = { @@ -639,28 +651,33 @@ 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; #if CONFIG_BSP_TOUCH_DRIVER_TT21100 ESP_LOGI(TAG, "Initialize LCD Touch: TT21100"); - const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG(); - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, ""); + esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG(); + 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_tt21100(tp_io_handle, &tp_cfg, ret_touch); #elif CONFIG_BSP_TOUCH_DRIVER_GT1151 ESP_LOGI(TAG, "Initialize LCD Touch: GT1151"); - const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT1151_CONFIG(); - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, ""); + esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT1151_CONFIG(); + 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_gt1151(tp_io_handle, &tp_cfg, ret_touch); #elif CONFIG_BSP_TOUCH_DRIVER_GT911 ESP_LOGI(TAG, "Initialize LCD Touch: GT911"); - const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, ""); + esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); + 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_gt911(tp_io_handle, &tp_cfg, ret_touch); #elif CONFIG_BSP_TOUCH_DRIVER_CST816S ESP_LOGI(TAG, "Initialize LCD Touch: CST816S"); - const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG(); - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, ""); + esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG(); + 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_cst816s(tp_io_handle, &tp_cfg, ret_touch); #elif CONFIG_BSP_TOUCH_DRIVER_FT5X06 ESP_LOGI(TAG, "Initialize LCD Touch: FT5X06"); - const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5X06_CONFIG(); - ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, ""); + esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5X06_CONFIG(); + 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); #endif }