Skip to content

Commit

Permalink
Merge pull request #433 from espressif/feature/s3_i2c_ng
Browse files Browse the repository at this point in the history
feat(s3_eye): Support I2C Driver-NG
  • Loading branch information
tore-espressif authored Nov 27, 2024
2 parents 4bbe669 + 8ea02a6 commit 35b7002
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 228 deletions.
6 changes: 4 additions & 2 deletions .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", "esp32_s3_korvo_2"]
- 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

examples/generic_button_led:
Expand All @@ -26,7 +26,6 @@ test_apps/components:
- "components/bh1750/**"
- "components/fbm320/**"
- "components/hts221/**"
- "components/io_expander/**"
- "components/lcd/ra8875/**"
- "components/lcd/sh1107/**"
- "components/lcd_touch/**"
Expand Down Expand Up @@ -91,6 +90,9 @@ components/icm42670:
components/qma6100p:
depends_filepatterns:
- "components/qma6100p/**"
disable:
- if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 2) or IDF_VERSION_MAJOR < 5
reason: Requires I2C Driver-NG which was introduced in v5.2

components/io_expander/esp_io_expander_ht8574:
depends_filepatterns:
Expand Down
13 changes: 3 additions & 10 deletions bsp/esp32_s3_eye/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 "esp32_s3_eye_idf4.c")
else()
set(SRC_VER "esp32_s3_eye_idf5.c")
endif()

idf_component_register(
SRCS "esp32_s3_eye.c" ${SRC_VER}
SRCS "esp32_s3_eye.c" "esp32_s3_eye_idf5.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES driver spiffs
PRIV_REQUIRES fatfs esp_lcd
REQUIRES esp_driver_gpio esp_driver_sdmmc spiffs
PRIV_REQUIRES fatfs esp_lcd esp_driver_i2c esp_driver_ledc esp_driver_spi
)
10 changes: 5 additions & 5 deletions bsp/esp32_s3_eye/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ menu "Board Support Package"
default y
help
Error check assert the application before returning the error code.

menu "I2C"
config BSP_I2C_NUM
int "I2C peripheral index"
default 1
range 0 1
help
ESP32-S2 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 @@ -51,7 +51,7 @@ menu "Board Support Package"
help
Supported max files for SPIFFS in the Virtual File System.
endmenu

menu "uSD card - Virtual File System"
config BSP_SD_FORMAT_ON_MOUNT_FAIL
bool "Format uSD card if mounting fails"
Expand Down Expand Up @@ -79,7 +79,7 @@ menu "Board Support Package"
range 1 100
help
Period of LVGL tick timer.

config BSP_DISPLAY_LVGL_MAX_SLEEP
int "LVGL maximum sleep time in ms"
default 1
Expand All @@ -101,5 +101,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
10 changes: 5 additions & 5 deletions bsp/esp32_s3_eye/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ The ESP32-S3-EYE board consists of two parts: the main board (ESP32-S3-EYE-MB) t
### Capabilities and dependencies
| Capability | Available | Component | Version |
|-------------|------------------|----------------------------------------------------------------------------------------------|----------|
| DISPLAY |:heavy_check_mark:| idf | >=4.4.5 |
| DISPLAY |:heavy_check_mark:| idf | >=5.4 |
| LVGL_PORT |:heavy_check_mark:|[espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port)| ^2 |
| TOUCH | :x: | | |
| 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| :x: | | |
| AUDIO_MIC |:heavy_check_mark:| | |
| SDCARD |:heavy_check_mark:| idf | >=4.4.5 |
| IMU |:heavy_check_mark:| [qma6100p](https://components.espressif.com/components/qma6100p) | 1.* |
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.2 |
| SDCARD |:heavy_check_mark:| idf | >=5.4 |
| IMU |:heavy_check_mark:| [qma6100p](https://components.espressif.com/components/qma6100p) | ^2 |
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.13 |
<!-- Autogenerated end: Dependencies -->
52 changes: 23 additions & 29 deletions bsp/esp32_s3_eye/esp32_s3_eye.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,55 @@

#include "driver/spi_master.h"
#include "driver/ledc.h"
#include "driver/i2c.h"
#include "driver/i2c_master.h"

#include "bsp/esp32_s3_eye.h"
#include "bsp_err_check.h"
#include "bsp/display.h"

static const char *TAG = "S3-EYE";

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;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
static adc_oneshot_unit_handle_t bsp_adc_handle = NULL;
#endif
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler

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_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BSP_BUTTON_MENU,
.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_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BSP_BUTTON_PLAY,
.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_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BSP_BUTTON_DOWN,
.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_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BSP_BUTTON_UP,
.adc_button_config.min = 280, // middle is 380mV
Expand All @@ -88,29 +87,32 @@ 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_ENABLE,
.scl_io_num = BSP_I2C_SCL,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.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_spiffs_mount(void)
{
esp_vfs_spiffs_conf_t conf = {
Expand Down Expand Up @@ -312,11 +314,7 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
};
BSP_ERROR_CHECK_RETURN_NULL(bsp_display_new(&bsp_disp_cfg, &panel_handle, &io_handle));

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
esp_lcd_panel_disp_off(panel_handle, false);
#else
esp_lcd_panel_disp_on_off(panel_handle, true);
#endif

/* Add LCD screen */
ESP_LOGD(TAG, "Add LCD screen");
Expand Down Expand Up @@ -420,8 +418,6 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
{
const audio_codec_data_if_t *i2s_data_if = bsp_audio_get_codec_itf();
if (i2s_data_if == NULL) {
/* Initilize I2C */
BSP_ERROR_CHECK_RETURN_NULL(bsp_i2c_init());
/* Configure I2S peripheral and Power Amplifier */
BSP_ERROR_CHECK_RETURN_NULL(bsp_audio_init(NULL));
i2s_data_if = bsp_audio_get_codec_itf();
Expand All @@ -443,11 +439,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
83 changes: 0 additions & 83 deletions bsp/esp32_s3_eye/esp32_s3_eye_idf4.c

This file was deleted.

10 changes: 5 additions & 5 deletions bsp/esp32_s3_eye/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.1.0~1"
version: "4.0.0"
description: Board Support Package (BSP) for ESP32-S3-EYE
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_eye

Expand All @@ -9,26 +9,26 @@ tags:
- bsp

dependencies:
idf: ">=4.4.5"
idf: ">=5.4" # I2C Driver-NG is supported in esp32-camera only from IDFv5.4

espressif/esp_lvgl_port:
version: "^2"
public: true
override_path: "../../components/esp_lvgl_port"

esp32-camera:
version: "^2.0.2"
version: "^2.0.13"
public: true

button:
version: ">=2.5,<4.0"
public: true

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

qma6100p:
version: "1.*"
version: "^2"
override_path: "../../components/qma6100p"
public: true
Loading

0 comments on commit 35b7002

Please sign in to comment.