Skip to content
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

feat(esp_bsp_generic): Support I2C Driver-NG #430

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
espzav marked this conversation as resolved.
Show resolved Hide resolved
- 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:
Expand Down
4 changes: 2 additions & 2 deletions bsp/esp_bsp_devkit/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

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

tags:
- bsp

dependencies:
idf: ">=4.4.2"
idf: ">=5.2"

button:
version: ">=2.5,<4.0"
Expand Down
11 changes: 10 additions & 1 deletion bsp/esp_bsp_devkit/include/bsp/esp_bsp_devkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
31 changes: 22 additions & 9 deletions bsp/esp_bsp_devkit/src/esp_bsp_devkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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;

Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions bsp/esp_bsp_generic/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

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

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"
Expand Down
10 changes: 9 additions & 1 deletion bsp/esp_bsp_generic/include/bsp/esp_bsp_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
55 changes: 36 additions & 19 deletions bsp/esp_bsp_generic/src/esp_bsp_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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;

Expand All @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down
Loading