Skip to content

Commit

Permalink
Merge pull request #444 from espressif/feat/lcd_ev_i2c_ng
Browse files Browse the repository at this point in the history
feat(lcd_ev): Upgrade to I2C Driver-NG
  • Loading branch information
tore-espressif authored Nov 29, 2024
2 parents cfe9845 + 03088c6 commit c817af2
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ examples:
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"]
- if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 3) and CONFIG_NAME in ["esp32_p4_function_ev_board", "esp-box-3", "esp32_s3_lcd_ev_board"]
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 in ["m5stack_core_s3", "esp32_s2_kaluga_kit", "esp32_s3_korvo_2", "esp32_s3_eye"]
reason: Example depends on BSP, which is supported only for IDF >= 5.4
Expand Down
6 changes: 6 additions & 0 deletions bsp/esp32_s3_lcd_ev_board/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@
### Bugfix

* Fixed LVGL8 compatibility in esp32_s3_lcd_ev_board

## v3.0.0 - 2024-28-11

### Features

* Upgrade to I2C Driver-NG
2 changes: 1 addition & 1 deletion bsp/esp32_s3_lcd_ev_board/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ idf_component_register(
SRCS ${SRCS}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES driver esp_lcd esp_adc
REQUIRES esp_driver_i2c esp_driver_i2s esp_driver_gpio esp_lcd esp_adc
PRIV_REQUIRES esp_timer spiffs esp_psram
)
2 changes: 1 addition & 1 deletion bsp/esp32_s3_lcd_ev_board/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Based on the above configurations, there are three different anti-tearing modes
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_ft5x06](https://components.espressif.com/components/espressif/esp_lcd_touch_ft5x06)| ^1 |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=2.5,<4.0|
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ^1,<1.2 |
| 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 | :x: | | |
Expand Down
29 changes: 8 additions & 21 deletions bsp/esp32_s3_lcd_ev_board/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.2.3"
version: "3.0.0"
description: Board Support Package (BSP) for ESP32-S3-LCD-EV-Board
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_lcd_ev_board

Expand All @@ -9,34 +9,21 @@ tags:
- bsp

dependencies:
idf: ">=5.0.1"

esp_lcd_touch_gt1151:
version: "^1"
public: true

esp_lcd_touch_ft5x06:
version: "^1"
public: true
idf: ">=5.3" # We use I2C Driver-NG from IDF v5.2 but esp-codec-dev supports from v5.3
esp_lcd_touch_gt1151: "^1"
esp_lcd_touch_ft5x06: "^1"
esp_lcd_panel_io_additions: "^1"

esp_io_expander_tca9554:
version: "^1"
public: true

esp_lcd_panel_io_additions:
version: "^1"
version: "^2"
public: true

esp_lcd_gc9503:
matches:
- if: "idf_version <5.1.2"
version: "^1"
- if: "idf_version >=5.1.2"
version: "^3"
version: "^3"
public: true

esp_codec_dev:
version: "^1,<1.2"
version: "~1.3.1"
public: true

button:
Expand Down
9 changes: 9 additions & 0 deletions bsp/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include "driver/i2s_std.h"
#include "driver/i2c_master.h"
#include "driver/gpio.h"
#include "soc/usb_pins.h"
#include "esp_adc/adc_cali_scheme.h"
Expand Down Expand Up @@ -147,6 +148,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
23 changes: 8 additions & 15 deletions bsp/esp32_s3_lcd_ev_board/src/bsp_probe.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "esp_check.h"
#include "esp_psram.h"

Expand Down Expand Up @@ -44,33 +44,26 @@ bsp_sub_board_type_t bsp_probe_sub_board_type(void)
}

BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());
i2c_master_bus_handle_t i2c_handle = bsp_i2c_get_handle();

uint8_t tp_address[] = {
ESP_LCD_TOUCH_IO_I2C_FT5x06_ADDRESS,
ESP_LCD_TOUCH_IO_I2C_GT1151_ADDRESS,
};
uint8_t i = 0;
i2c_cmd_handle_t cmd;
bsp_sub_board_type_t detect_type = SUB_BOARD_TYPE_UNKNOW;
while (i < sizeof(tp_address)) {
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (tp_address[i] << 1) | I2C_MASTER_WRITE, true);
i2c_master_stop(cmd);
if (i2c_master_cmd_begin(BSP_I2C_NUM, cmd, pdMS_TO_TICKS(20)) == ESP_OK) {

for (int i = 0; i < sizeof(tp_address); i++) {
if (i2c_master_probe(i2c_handle, tp_address[i], 100) == ESP_OK) {
if (tp_address[i] == ESP_LCD_TOUCH_IO_I2C_FT5x06_ADDRESS) {
ESP_LOGI(TAG, "Detect sub_board2 with 480x480 LCD (GC9503), Touch (FT5x06)");
detect_type = SUB_BOARD_TYPE_2_480_480;
break;
} else if (tp_address[i] == ESP_LCD_TOUCH_IO_I2C_GT1151_ADDRESS) {
ESP_LOGI(TAG, "Detect sub_board3 with 800x480 LCD (ST7262), Touch (GT1151)");
detect_type = SUB_BOARD_TYPE_3_800_480;
break;
}
}
i2c_cmd_link_delete(cmd);
if (detect_type != SUB_BOARD_TYPE_UNKNOW) {
break;
}
i++;
}

ESP_RETURN_ON_FALSE(detect_type != SUB_BOARD_TYPE_UNKNOW, ESP_ERR_INVALID_STATE, TAG,
Expand Down
13 changes: 9 additions & 4 deletions bsp/esp32_s3_lcd_ev_board/src/bsp_sub_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
return ESP_FAIL;
}

BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());
i2c_master_bus_handle_t i2c_handle = bsp_i2c_get_handle();

switch (sub_board_type) {
case SUB_BOARD_TYPE_2_480_480: {
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
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
const esp_lcd_touch_config_t tp_cfg = {
.x_max = BSP_LCD_SUB_BOARD_2_H_RES,
.y_max = BSP_LCD_SUB_BOARD_2_V_RES,
Expand All @@ -256,12 +260,13 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
.mirror_y = 0,
},
};
BSP_ERROR_CHECK_RETURN_ERR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle));
BSP_ERROR_CHECK_RETURN_ERR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle));
BSP_ERROR_CHECK_RETURN_ERR(esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, &tp_handle));
break;
}
case SUB_BOARD_TYPE_3_800_480: {
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT1151_CONFIG();
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
const esp_lcd_touch_config_t tp_cfg = {
.x_max = BSP_LCD_SUB_BOARD_3_H_RES,
.y_max = BSP_LCD_SUB_BOARD_3_V_RES,
Expand All @@ -278,7 +283,7 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
},
};

BSP_ERROR_CHECK_RETURN_ERR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle));
BSP_ERROR_CHECK_RETURN_ERR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle));
BSP_ERROR_CHECK_RETURN_ERR(esp_lcd_touch_new_i2c_gt1151(tp_io_handle, &tp_cfg, &tp_handle));
break;
}
Expand Down
43 changes: 29 additions & 14 deletions bsp/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "driver/i2s_std.h"
#include "driver/gpio.h"
#include "esp_codec_dev_defaults.h"
Expand Down Expand Up @@ -54,6 +54,15 @@

static const char *TAG = "S3-LCD-EV-BOARD";

/**
* @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;
static const audio_codec_data_if_t *i2s_data_if = NULL; /* Codec data interface */
static i2s_chan_handle_t i2s_tx_chan = NULL;
Expand Down Expand Up @@ -89,34 +98,38 @@ esp_err_t bsp_i2c_init(void)
ESP_LOGE(TAG, "Unknow module type");
return ESP_FAIL;
}

i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
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,
};

// To compatible with ESP32-S3-WROOM-N16R16V module
if (module_type == MODULE_TYPE_R16) {
i2c_conf.sda_io_num = BSP_I2C_SDA_R16;
i2c_conf.scl_io_num = BSP_I2C_SCL_R16;
i2c_config.sda_io_num = BSP_I2C_SDA_R16;
i2c_config.scl_io_num = BSP_I2C_SCL_R16;
}
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));

i2c_initialized = true;
BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_config, &i2c_handle));

i2c_initialized = true;
return ESP_OK;
}

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;
}

/**************************************************************************************************
*
* SPIFFS Function
Expand Down Expand Up @@ -163,7 +176,7 @@ esp_err_t bsp_spiffs_unmount(void)
esp_io_expander_handle_t bsp_io_expander_init(void)
{
if (!io_expander) {
BSP_ERROR_CHECK_RETURN_NULL(esp_io_expander_new_i2c_tca9554(BSP_I2C_NUM, BSP_IO_EXPANDER_I2C_ADDRESS, &io_expander));
BSP_ERROR_CHECK_RETURN_NULL(esp_io_expander_new_i2c_tca9554(i2c_handle, BSP_IO_EXPANDER_I2C_ADDRESS, &io_expander));
}

return io_expander;
Expand Down Expand Up @@ -244,6 +257,7 @@ esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
audio_codec_i2c_cfg_t i2c_cfg = {
.port = BSP_I2C_NUM,
.addr = ES8311_CODEC_DEFAULT_ADDR,
.bus_handle = i2c_handle,
};
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
BSP_NULL_CHECK(i2c_ctrl_if, NULL);
Expand Down Expand Up @@ -290,6 +304,7 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
audio_codec_i2c_cfg_t i2c_cfg = {
.port = BSP_I2C_NUM,
.addr = BSP_ES7210_CODEC_ADDR,
.bus_handle = i2c_handle,
};
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
BSP_NULL_CHECK(i2c_ctrl_if, NULL);
Expand Down
1 change: 1 addition & 0 deletions examples/display/sdkconfig.bsp.esp32_s3_lcd_ev_board
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y
CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y
CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y
CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CONFIG_BSP_DISPLAY_LVGL_TASK_STACK_SIZE=8
CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR=y
CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y
CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CONFIG_LV_USE_DEMO_BENCHMARK=y
CONFIG_LV_USE_DEMO_STRESS=y
CONFIG_LV_USE_DEMO_MUSIC=y
CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down
1 change: 1 addition & 0 deletions examples/display_lvgl_demos/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ CONFIG_LV_USE_DEMO_BENCHMARK=y
CONFIG_LV_USE_DEMO_STRESS=y
CONFIG_LV_USE_DEMO_MUSIC=y
CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2
CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y
CONFIG_BSP_DISPLAY_LVGL_DIRECT_MODE=y
CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down

0 comments on commit c817af2

Please sign in to comment.