Skip to content

Commit

Permalink
feat(esp-box-3): Support I2C Driver-NG
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-espressif committed Oct 22, 2024
1 parent b5091df commit c84532f
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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"
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"
Expand Down
13 changes: 3 additions & 10 deletions bsp/esp-box-3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#IDF version is less than IDF5.0
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "5.0")
set(SRC_VER "esp-box-3_idf4.c")
else()
set(SRC_VER "esp-box-3_idf5.c")
endif()

idf_component_register(
SRCS "esp-box-3.c" ${SRC_VER}
SRCS "esp-box-3.c" "esp-box-3_idf5.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES driver spiffs
PRIV_REQUIRES fatfs esp_lcd
REQUIRES esp_driver_i2s esp_driver_gpio esp_driver_sdmmc spiffs
PRIV_REQUIRES fatfs esp_lcd esp_driver_spi esp_driver_i2c
)
6 changes: 3 additions & 3 deletions bsp/esp-box-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input
| 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_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911)| ^1 |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | >=2.5 |
| 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 |:heavy_check_mark:| idf |>=4.4.5|
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^1 |
| SDCARD |:heavy_check_mark:| idf | >=5.2 |
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1|
<!-- Autogenerated end: Dependencies -->
40 changes: 19 additions & 21 deletions bsp/esp-box-3/esp-box-3.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 Down Expand Up @@ -57,8 +58,15 @@ static lv_display_t *disp;
static lv_indev_t *disp_indev = NULL;
static esp_lcd_touch_handle_t tp; // LCD touch handle
static esp_lcd_panel_handle_t panel_handle = NULL;

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"
*/
static i2c_master_bus_handle_t i2c_handle = NULL;
static bool i2c_initialized = false;

// This is just a wrapper to get function signature for espressif/button API callback
Expand Down Expand Up @@ -93,41 +101,28 @@ 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;

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

static esp_err_t bsp_i2c_device_probe(uint8_t addr)
{
esp_err_t ret = ESP_ERR_NOT_FOUND;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (addr << 1) | I2C_MASTER_WRITE, true);
i2c_master_stop(cmd);
if (i2c_master_cmd_begin(BSP_I2C_NUM, cmd, 1000) == ESP_OK) {
ret = ESP_OK;
}
i2c_cmd_link_delete(cmd);
return ret;
return i2c_master_probe(i2c_handle, addr, 100);
}

esp_err_t bsp_spiffs_mount(void)
Expand Down Expand Up @@ -219,6 +214,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 @@ -267,6 +263,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 @@ -526,8 +523,9 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
ESP_LOGE(TAG, "Touch not found");
return ESP_ERR_NOT_FOUND;
}
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((esp_lcd_i2c_bus_handle_t)BSP_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, "");
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, "");
if (ESP_LCD_TOUCH_IO_I2C_TT21100_ADDRESS == tp_io_config.dev_addr) {
ESP_RETURN_ON_ERROR(esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, ret_touch), TAG, "New tt21100 failed");
} else {
Expand Down
75 changes: 0 additions & 75 deletions bsp/esp-box-3/esp-box-3_idf4.c

This file was deleted.

8 changes: 4 additions & 4 deletions bsp/esp-box-3/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: "1.2.0~2"
version: "2.0.0"
description: Board Support Package (BSP) for ESP32-S3-BOX-3
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp-box-3

Expand All @@ -10,7 +10,7 @@ tags:
- bsp

dependencies:
idf: ">=4.4.5"
idf: ">=5.2" # We use I2C Driver-NG from IDF v5.2
esp_lcd_touch_tt21100: "^1"
esp_lcd_touch_gt911: "^1"
esp_lcd_ili9341: "^1"
Expand All @@ -21,13 +21,13 @@ dependencies:
override_path: "../../components/esp_lvgl_port"

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

button:
version: ">=2.5"
public: true

icm42670:
version: "^1"
version: "^2.0.1"
public: true
11 changes: 1 addition & 10 deletions bsp/esp-box-3/include/bsp/esp-box-3.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/i2s_std.h"
#include "driver/sdmmc_host.h"
#include "soc/usb_pins.h"
#include "lvgl.h"
Expand All @@ -22,11 +22,6 @@
#include "iot_button.h"
#include "bsp/display.h"

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#include "driver/i2s.h"
#else
#include "driver/i2s_std.h"
#endif
/**************************************************************************************************
* BSP Capabilities
**************************************************************************************************/
Expand Down Expand Up @@ -181,11 +176,7 @@ typedef struct {
* - ESP_ERR_NO_MEM No memory for storing the channel information
* - ESP_ERR_INVALID_STATE This channel has not initialized or already started
*/
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
esp_err_t bsp_audio_init(const i2s_config_t *i2s_config);
#else
esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config);
#endif

/**
* @brief Get codec I2S interface (initialized in bsp_audio_init)
Expand Down
1 change: 1 addition & 0 deletions examples/display/sdkconfig.bsp.esp-box-3
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESP_DEFAULT_CPU_FREQ_240=y
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
Expand Down
1 change: 1 addition & 0 deletions examples/display_audio_photo/sdkconfig.bsp.esp-box-3
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/display_lvgl_demos/sdkconfig.bsp.esp-box-3
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CONFIG_LV_USE_DEMO_STRESS=y
CONFIG_LV_USE_DEMO_MUSIC=y
CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y
CONFIG_LV_DEMO_MUSIC_SQUARE=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down
1 change: 1 addition & 0 deletions examples/display_rotation/sdkconfig.bsp.esp-box-3
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c84532f

Please sign in to comment.