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(korvo2): Update to I2C Driver-NG #437

Merged
merged 1 commit into from
Nov 19, 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
2 changes: 1 addition & 1 deletion .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ examples:
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 in ["m5stack_core_s3", "esp32_s2_kaluga_kit"]
- 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"]
reason: Example depends on BSP, which is supported only for IDF >= 5.4

examples/generic_button_led:
Expand Down
4 changes: 4 additions & 0 deletions bsp/esp32_s3_korvo_2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## v3.0.0

* Migrated to I2C Driver-NG (https://docs.espressif.com/projects/esp-idf/en/stable/esp32/migration-guides/release-5.x/5.2/peripherals.html#i2c)

## v2.2.1 - 2024-09-20

### Bugfix
Expand Down
15 changes: 3 additions & 12 deletions bsp/esp32_s3_korvo_2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#IDF version is less than IDF5.0
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "5.0")
set(SRC_VER "esp32_s3_korvo_2_idf4.c")
set(REQ driver esp_lcd)
else()
set(SRC_VER "esp32_s3_korvo_2_idf5.c")
set(REQ driver esp_lcd esp_adc)
endif()

idf_component_register(
SRCS "esp32_s3_korvo_2.c" ${SRC_VER}
SRCS "esp32_s3_korvo_2.c" "esp32_s3_korvo_2_idf5.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES ${REQ}
PRIV_REQUIRES spiffs fatfs
REQUIRES esp_driver_gpio esp_driver_i2s esp_driver_sdmmc esp_adc
PRIV_REQUIRES spiffs fatfs esp_lcd esp_driver_i2c esp_driver_spi esp_driver_ledc
)
4 changes: 2 additions & 2 deletions bsp/esp32_s3_korvo_2/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ menu "Board Support Package"
default 1
range 0 1
help
ESP32S3 has two I2C peripherals, pick the one you want to use.
ESP32-S3 has two I2C peripherals, pick the one you want to use.

config BSP_I2C_FAST_MODE
bool "Enable I2C fast mode"
Expand Down Expand Up @@ -72,5 +72,5 @@ menu "Board Support Package"
default 1
range 0 1
help
ESP32S3 has two I2S peripherals, pick the one you want to use.
ESP32-S3 has two I2S peripherals, pick the one you want to use.
endmenu
26 changes: 13 additions & 13 deletions bsp/esp32_s3_korvo_2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ The ESP32-S3-Korvo-2 is a multimedia development board based on the ESP32-S3 chi

<!-- Autogenerated start: Dependencies -->
### Capabilities and dependencies
| Capability | Available | Component | Version |
|-------------|------------------|--------------------------------------------------------------------------------------------------------------|-----------|
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341) | ^1 |
| 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_tt21100](https://components.espressif.com/components/espressif/esp_lcd_touch_tt21100)| ^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.0.2,<1.2|
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC |:heavy_check_mark:| | |
| LED |:heavy_check_mark:| idf | >=4.4.5 |
| SDCARD |:heavy_check_mark:| idf | >=4.4.5 |
| IMU | :x: | | |
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.2 |
| Capability | Available | Component | Version |
|-------------|------------------|--------------------------------------------------------------------------------------------------------------|----------|
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341) | ^1 |
| 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_tt21100](https://components.espressif.com/components/espressif/esp_lcd_touch_tt21100)| ^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.3.1 |
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC |:heavy_check_mark:| | |
| LED |:heavy_check_mark:| idf | >=5.4 |
| SDCARD |:heavy_check_mark:| idf | >=5.4 |
| IMU | :x: | | |
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.13 |
<!-- Autogenerated end: Dependencies -->
71 changes: 35 additions & 36 deletions bsp/esp32_s3_korvo_2/esp32_s3_korvo_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#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"
Expand All @@ -28,14 +29,21 @@

static const char *TAG = "S3-KORVO-2";

/**
* @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 esp_io_expander_handle_t io_expander = NULL; // IO expander tca9554 handle
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
static esp_lcd_touch_handle_t tp; // LCD touch handle
static lv_indev_t *disp_indev = NULL;
static bool i2c_initialized = false;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
static adc_oneshot_unit_handle_t bsp_adc_handle = NULL;
#endif

// This is just a wrapper to get function signature for espressif/button API callback
static uint8_t bsp_get_main_button(void *param);
Expand All @@ -44,59 +52,47 @@ static esp_err_t bsp_init_main_button(void *param);
static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
{
.type = BUTTON_TYPE_ADC,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.adc_button_config.adc_handle = &bsp_adc_handle,
#endif
.adc_button_config.adc_channel = ADC_CHANNEL_4, // ADC1 channel 4 is GPIO5
.adc_button_config.button_index = BSP_BUTTON_REC,
.adc_button_config.min = 2310, // middle is 2410mV
.adc_button_config.max = 2510
},
{
.type = BUTTON_TYPE_ADC,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.adc_button_config.adc_handle = &bsp_adc_handle,
#endif
.adc_button_config.adc_channel = ADC_CHANNEL_4, // ADC1 channel 4 is GPIO5
.adc_button_config.button_index = BSP_BUTTON_MUTE,
.adc_button_config.min = 1880, // middle is 1980mV
.adc_button_config.max = 2080
},
{
.type = BUTTON_TYPE_ADC,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.adc_button_config.adc_handle = &bsp_adc_handle,
#endif
.adc_button_config.adc_channel = ADC_CHANNEL_4, // ADC1 channel 4 is GPIO5
.adc_button_config.button_index = BSP_BUTTON_PLAY,
.adc_button_config.min = 1550, // middle is 1650mV
.adc_button_config.max = 1750
},
{
.type = BUTTON_TYPE_ADC,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.adc_button_config.adc_handle = &bsp_adc_handle,
#endif
.adc_button_config.adc_channel = ADC_CHANNEL_4, // ADC1 channel 4 is GPIO5
.adc_button_config.button_index = BSP_BUTTON_SET,
.adc_button_config.min = 1010, // middle is 1110mV
.adc_button_config.max = 1210
},
{
.type = BUTTON_TYPE_ADC,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.adc_button_config.adc_handle = &bsp_adc_handle,
#endif
.adc_button_config.adc_channel = ADC_CHANNEL_4, // ADC1 channel 4 is GPIO5
.adc_button_config.button_index = BSP_BUTTON_VOLDOWN,
.adc_button_config.min = 720, // middle is 820mV
.adc_button_config.max = 920
},
{
.type = BUTTON_TYPE_ADC,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.adc_button_config.adc_handle = &bsp_adc_handle,
#endif
.adc_button_config.adc_channel = ADC_CHANNEL_4, // ADC1 channel 4 is GPIO5
.adc_button_config.button_index = BSP_BUTTON_VOLUP,
.adc_button_config.min = 280, // middle is 380mV
Expand All @@ -119,29 +115,31 @@ 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,
.flags.enable_internal_pullup = true,
};
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;

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

esp_err_t bsp_sdcard_mount(void)
{
Expand Down Expand Up @@ -198,6 +196,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 @@ -246,6 +245,7 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
audio_codec_i2c_cfg_t i2c_cfg = {
.port = BSP_I2C_NUM,
.addr = ES7210_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 @@ -273,13 +273,11 @@ esp_io_expander_handle_t bsp_io_expander_init(void)
ESP_LOGD(TAG, "io_expander is initialized");
} else {
// Here we try to initialize TCA9554 first, if it fails, we try to initialize TCA9554A
// *INDENT-OFF*
if ((esp_io_expander_new_i2c_tca9554(BSP_I2C_NUM, BSP_IO_EXPANDER_I2C_ADDRESS_TCA9554, &io_expander) != ESP_OK) &&
(esp_io_expander_new_i2c_tca9554(BSP_I2C_NUM, BSP_IO_EXPANDER_I2C_ADDRESS_TCA9554A, &io_expander) != ESP_OK)) {
ESP_LOGE(TAG, "Failed to initialize IO expander");
return NULL;
if (i2c_master_probe(i2c_handle, BSP_IO_EXPANDER_I2C_ADDRESS_TCA9554, 100) == ESP_OK) {
esp_io_expander_new_i2c_tca9554(i2c_handle, BSP_IO_EXPANDER_I2C_ADDRESS_TCA9554, &io_expander);
} else if (i2c_master_probe(i2c_handle, BSP_IO_EXPANDER_I2C_ADDRESS_TCA9554A, 100) == ESP_OK) {
esp_io_expander_new_i2c_tca9554(i2c_handle, BSP_IO_EXPANDER_I2C_ADDRESS_TCA9554A, &io_expander);
}
// *INDENT-OFF*
}

return io_expander;
Expand Down Expand Up @@ -397,6 +395,13 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)

esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t *ret_touch)
{
BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());

esp_lcd_panel_io_handle_t tp_io_handle = NULL;
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, "");

/* Initialize touch */
const esp_lcd_touch_config_t tp_cfg = {
.x_max = BSP_LCD_H_RES,
Expand All @@ -413,10 +418,6 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
.mirror_y = 0,
},
};
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG();
BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());
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, "");
return esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, ret_touch);
}

Expand Down Expand Up @@ -575,11 +576,9 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
(btn_array == NULL)) {
return ESP_ERR_INVALID_ARG;
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
/* Initialize ADC and get ADC handle */
BSP_ERROR_CHECK_RETURN_NULL(bsp_adc_initialize());
bsp_adc_handle = bsp_adc_get_handle();
#endif

if (btn_cnt) {
*btn_cnt = 0;
Expand Down
106 changes: 0 additions & 106 deletions bsp/esp32_s3_korvo_2/esp32_s3_korvo_2_idf4.c

This file was deleted.

Loading
Loading