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-box-3): Support I2C Driver-NG #414

Merged
merged 2 commits into from
Nov 5, 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
4 changes: 2 additions & 2 deletions .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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 < 3 and CONFIG_NAME == "esp32_p4_function_ev_board"
- 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"
- 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

# Noglib test_app: Build only in CI, where ENV_BUILD_NOGLIB is set
Expand Down
9 changes: 1 addition & 8 deletions bsp/esp-box-3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#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
Expand Down
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.3 |
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1|
<!-- Autogenerated end: Dependencies -->
47 changes: 26 additions & 21 deletions bsp/esp-box-3/esp-box-3.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ 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
*
* 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;

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

i2c_master_bus_handle_t bsp_i2c_get_handle(void)
{
bsp_i2c_init();
return i2c_handle;
}

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 +221,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 +270,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 +530,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.

12 changes: 8 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.3" # We use I2C Driver-NG from IDF v5.2 but esp-codec-dev supports from v5.3
esp_lcd_touch_tt21100: "^1"
esp_lcd_touch_gt911: "^1"
esp_lcd_ili9341: "^1"
Expand All @@ -21,13 +21,17 @@ 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

examples:
- path: ../../examples/display_audio_photo
- path: ../../examples/display_rotation
25 changes: 10 additions & 15 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,8 @@

#include "sdkconfig.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/i2s_std.h"
#include "driver/i2c_master.h"
#include "driver/sdmmc_host.h"
#include "soc/usb_pins.h"
#include "lvgl.h"
Expand All @@ -22,11 +23,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 +177,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 Expand Up @@ -219,11 +211,6 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void);
* - Encryption chip ATECC608A (NOT populated on most boards)
* - LCD Touch controller
* - Inertial Measurement Unit ICM-42607-P
*
* After initialization of I2C, use BSP_I2C_NUM macro when creating I2C devices drivers ie.:
* \code{.c}
* icm42670_handle_t imu = icm42670_create(BSP_I2C_NUM, ICM42670_I2C_ADDRESS);
* \endcode
**************************************************************************************************/
#define BSP_I2C_NUM CONFIG_BSP_I2C_NUM

Expand All @@ -248,6 +235,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
4 changes: 0 additions & 4 deletions bsp/esp-box/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,3 @@ dependencies:
icm42670:
version: "^1"
public: true

examples:
- path: ../../examples/display_audio_photo
- path: ../../examples/display_rotation
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
4 changes: 2 additions & 2 deletions examples/display_audio_photo/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: BSP Display Audio Photo Example
dependencies:
esp_jpeg: "*"
esp-box:
esp-box-3:
version: "*"
override_path: "../../../bsp/esp-box"
override_path: "../../../bsp/esp-box-3"
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_audio_photo/sdkconfig.defaults
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/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
idf_component_register(SRCS "main.c"
REQUIRES driver
INCLUDE_DIRS ".")

lvgl_port_create_c_image("images/esp_logo.png" "images/gen/" "ARGB8888" "NONE")
Expand Down
4 changes: 2 additions & 2 deletions examples/display_rotation/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: BSP Display rotation example
dependencies:
esp-box:
esp-box-3:
version: "*"
override_path: "../../../bsp/esp-box"
override_path: "../../../bsp/esp-box-3"
Loading
Loading