Skip to content

Commit d41c657

Browse files
feat(m5stack_core_s3): Support I2C Driver-NG
With this change we also must upgrade to IDF v5.4, because esp32-camera supports Driver-NG only from v5.4 onwards. Relates to #391
1 parent 0a83a89 commit d41c657

File tree

11 files changed

+56
-45
lines changed

11 files changed

+56
-45
lines changed

.build-test-rules.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ examples:
55
reason: Do not build examples for deprecated BSPs
66
- if: IDF_VERSION_MAJOR < 5 and IDF_VERSION_MINOR < 3 and CONFIG_NAME == "esp32_p4_function_ev_board"
77
reason: Example depends on BSP, which is supported only for IDF >= 5.3
8+
- if: IDF_VERSION_MAJOR < 5 and IDF_VERSION_MINOR < 4 and CONFIG_NAME == "m5stack_core_s3"
9+
reason: Example depends on BSP, which is supported only for IDF >= 5.4
810

911
# Noglib test_app: Build only in CI, where ENV_BUILD_NOGLIB is set
1012
test_apps/noglib:

bsp/m5stack_core_s3/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ idf_component_register(
22
SRCS "m5stack_core_s3.c" "m5stack_core_s3_idf5.c"
33
INCLUDE_DIRS "include"
44
PRIV_INCLUDE_DIRS "priv_include"
5-
REQUIRES driver spiffs
6-
PRIV_REQUIRES fatfs esp_lcd
5+
REQUIRES esp_driver_i2c esp_driver_i2s esp_driver_gpio esp_driver_sdmmc spiffs
6+
PRIV_REQUIRES fatfs esp_lcd esp_driver_spi
77
)

bsp/m5stack_core_s3/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Sound output on CoreS3 is optimized with the high-fidelity 16-bit I2S power ampl
2424
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
2525
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_ft5x06](https://components.espressif.com/components/espressif/esp_lcd_touch_ft5x06)| ^1 |
2626
| BUTTONS | :x: | | |
27-
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.1 |
27+
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.3.1|
2828
|AUDIO_SPEAKER|:heavy_check_mark:| | |
2929
| AUDIO_MIC |:heavy_check_mark:| | |
30-
| SDCARD |:heavy_check_mark:| idf | >=5.0 |
30+
| SDCARD |:heavy_check_mark:| idf | >=5.4 |
3131
| IMU | :x: | | |
32-
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.2|
32+
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) |^2.0.11|
3333
<!-- Autogenerated end: Dependencies -->
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.1~1"
1+
version: "2.0.0"
22
description: Board Support Package (BSP) for M5Stack CoreS3
33
url: https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_s3
44

@@ -9,7 +9,7 @@ tags:
99
- bsp
1010

1111
dependencies:
12-
idf: ">=5.0"
12+
idf: ">=5.4" # I2C Driver-NG is supported in esp32-camera only from IDFv5.4
1313
esp_lcd_ili9341: "^1"
1414
esp_lcd_touch_ft5x06: "^1"
1515

@@ -18,9 +18,9 @@ dependencies:
1818
public: true
1919

2020
esp_codec_dev:
21-
version: "~1.1"
21+
version: "~1.3.1"
2222
public: true
2323

2424
esp32-camera:
25-
version: "^2.0.2"
25+
version: "^2.0.11"
2626
public: true

bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
1313

1414
#include "sdkconfig.h"
1515
#include "driver/gpio.h"
16-
#include "driver/i2c.h"
16+
#include "driver/i2c_master.h"
17+
#include "driver/i2s_std.h"
1718
#include "driver/sdmmc_host.h"
1819
#include "soc/usb_pins.h"
1920
#include "esp_codec_dev.h"
2021
#include "bsp/config.h"
2122
#include "bsp/display.h"
2223

23-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
24-
#include "driver/i2s.h"
25-
#else
26-
#include "driver/i2s_std.h"
27-
#endif
28-
2924
#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
3025
#include "lvgl.h"
3126
#include "esp_lvgl_port.h"
@@ -134,11 +129,7 @@ extern "C" {
134129
* - ESP_ERR_NO_MEM No memory for storing the channel information
135130
* - ESP_ERR_INVALID_STATE This channel has not initialized or already started
136131
*/
137-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
138-
esp_err_t bsp_audio_init(const i2s_config_t *i2s_config);
139-
#else
140132
esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config);
141-
#endif
142133

143134
/**
144135
* @brief Get codec I2S interface (initialized in bsp_audio_init)

bsp/m5stack_core_s3/m5stack_core_s3.c

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
#include "esp_lcd_panel_vendor.h"
1515
#include "esp_lcd_panel_ops.h"
1616
#include "esp_vfs_fat.h"
17-
#include "driver/sdmmc_host.h"
1817
#include "driver/sdspi_host.h"
19-
#include "driver/i2c.h"
2018

2119
#include "bsp/m5stack_core_s3.h"
2220
#include "bsp/display.h"
@@ -47,6 +45,9 @@ static lv_indev_t *disp_indev = NULL;
4745
static esp_lcd_touch_handle_t tp; // LCD touch handle
4846
sdmmc_card_t *bsp_sdcard = NULL; // Global SD card handler
4947
static bool i2c_initialized = false;
48+
static i2c_master_bus_handle_t i2c_handle = NULL; // I2C Handle
49+
static i2c_master_dev_handle_t axp2101_h = NULL;
50+
static i2c_master_dev_handle_t aw9523_h = NULL;
5051
static bool spi_initialized = false;
5152

5253
esp_err_t bsp_i2c_init(void)
@@ -56,25 +57,35 @@ esp_err_t bsp_i2c_init(void)
5657
return ESP_OK;
5758
}
5859

59-
const i2c_config_t i2c_conf = {
60-
.mode = I2C_MODE_MASTER,
60+
const i2c_master_bus_config_t i2c_config = {
61+
.i2c_port = BSP_I2C_NUM,
6162
.sda_io_num = BSP_I2C_SDA,
62-
.sda_pullup_en = GPIO_PULLUP_DISABLE,
6363
.scl_io_num = BSP_I2C_SCL,
64-
.scl_pullup_en = GPIO_PULLUP_DISABLE,
65-
.master.clk_speed = CONFIG_BSP_I2C_CLK_SPEED_HZ
64+
.clk_source = 1,
6665
};
67-
BSP_ERROR_CHECK_RETURN_ERR(i2c_param_config(BSP_I2C_NUM, &i2c_conf));
68-
BSP_ERROR_CHECK_RETURN_ERR(i2c_driver_install(BSP_I2C_NUM, i2c_conf.mode, 0, 0, 0));
66+
BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_config, &i2c_handle));
6967

70-
i2c_initialized = true;
68+
// AXP2101 and AW9523 are managed by this BSP
69+
const i2c_device_config_t axp2101_config = {
70+
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
71+
.device_address = BSP_AXP2101_ADDR,
72+
.scl_speed_hz = 400000,
73+
};
74+
BSP_ERROR_CHECK_RETURN_ERR(i2c_master_bus_add_device(i2c_handle, &axp2101_config, &axp2101_h));
75+
const i2c_device_config_t aw9523_config = {
76+
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
77+
.device_address = BSP_AW9523_ADDR,
78+
.scl_speed_hz = 400000,
79+
};
80+
BSP_ERROR_CHECK_RETURN_ERR(i2c_master_bus_add_device(i2c_handle, &aw9523_config, &aw9523_h));
7181

82+
i2c_initialized = true;
7283
return ESP_OK;
7384
}
7485

7586
esp_err_t bsp_i2c_deinit(void)
7687
{
77-
BSP_ERROR_CHECK_RETURN_ERR(i2c_driver_delete(BSP_I2C_NUM));
88+
BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_handle));
7889
i2c_initialized = false;
7990
return ESP_OK;
8091
}
@@ -102,27 +113,27 @@ static esp_err_t bsp_enable_feature(bsp_feature_t feature)
102113
/* AXP ALDO4 voltage / SD Card / 3V3 */
103114
data[0] = 0x95;
104115
data[1] = 0b00011100; //3V3
105-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
116+
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
106117
/* Enable SD */
107118
aw9523_P0 |= (1 << 4);
108119
break;
109120
case BSP_FEATURE_SPEAKER:
110121
/* AXP ALDO1 voltage / PA PVDD / 1V8 */
111122
data[0] = 0x92;
112123
data[1] = 0b00001101; //1V8
113-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
124+
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
114125
/* AXP ALDO2 voltage / Codec / 3V3 */
115126
data[0] = 0x93;
116127
data[1] = 0b00011100; //3V3
117-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
128+
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
118129
/* AXP ALDO3 voltage / Codec+Mic / 3V3 */
119130
data[0] = 0x94;
120131
data[1] = 0b00011100; //3V3
121-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
132+
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
122133
/* AW9523 P0 is in push-pull mode */
123134
data[0] = 0x11;
124135
data[1] = 0x10;
125-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
136+
err |= i2c_master_transmit(aw9523_h, data, sizeof(data), 1000);
126137
/* Enable Codec AW88298 */
127138
aw9523_P0 |= (1 << 2);
128139
break;
@@ -134,11 +145,11 @@ static esp_err_t bsp_enable_feature(bsp_feature_t feature)
134145

135146
data[0] = 0x02;
136147
data[1] = aw9523_P0;
137-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
148+
err |= i2c_master_transmit(aw9523_h, data, sizeof(data), 1000);
138149

139150
data[0] = 0x03;
140151
data[1] = aw9523_P1;
141-
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
152+
err |= i2c_master_transmit(aw9523_h, data, sizeof(data), 1000);
142153

143154
return err;
144155
}
@@ -246,6 +257,7 @@ esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
246257
audio_codec_i2c_cfg_t i2c_cfg = {
247258
.port = BSP_I2C_NUM,
248259
.addr = AW88298_CODEC_DEFAULT_ADDR,
260+
.bus_handle = i2c_handle,
249261
};
250262
const audio_codec_ctrl_if_t *out_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
251263

@@ -272,7 +284,7 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
272284
{
273285
const audio_codec_data_if_t *i2s_data_if = bsp_audio_get_codec_itf();
274286
if (i2s_data_if == NULL) {
275-
/* Initilize I2C */
287+
/* Initialize I2C */
276288
BSP_ERROR_CHECK_RETURN_NULL(bsp_i2c_init());
277289
/* Configure I2S peripheral and Power Amplifier */
278290
BSP_ERROR_CHECK_RETURN_NULL(bsp_audio_init(NULL));
@@ -283,6 +295,7 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void)
283295
audio_codec_i2c_cfg_t i2c_cfg = {
284296
.port = BSP_I2C_NUM,
285297
.addr = ES7210_CODEC_DEFAULT_ADDR,
298+
.bus_handle = i2c_handle,
286299
};
287300
const audio_codec_ctrl_if_t *i2c_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
288301
BSP_NULL_CHECK(i2c_ctrl_if, NULL);
@@ -312,9 +325,9 @@ esp_err_t bsp_display_brightness_init(void)
312325
BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());
313326

314327
const uint8_t lcd_bl_en[] = { 0x90, 0xBF }; // AXP DLDO1 Enable
315-
ESP_RETURN_ON_ERROR(i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, lcd_bl_en, sizeof(lcd_bl_en), 1000 / portTICK_PERIOD_MS), TAG, "I2C write failed");
328+
ESP_RETURN_ON_ERROR(i2c_master_transmit(axp2101_h, lcd_bl_en, sizeof(lcd_bl_en), 1000), TAG, "I2C write failed");
316329
const uint8_t lcd_bl_val[] = { 0x99, 0b00011000 }; // AXP DLDO1 voltage
317-
ESP_RETURN_ON_ERROR(i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, lcd_bl_val, sizeof(lcd_bl_val), 1000 / portTICK_PERIOD_MS), TAG, "I2C write failed");
330+
ESP_RETURN_ON_ERROR(i2c_master_transmit(axp2101_h, lcd_bl_val, sizeof(lcd_bl_val), 1000), TAG, "I2C write failed");
318331

319332
return ESP_OK;
320333
}
@@ -331,7 +344,7 @@ esp_err_t bsp_display_brightness_set(int brightness_percent)
331344
ESP_LOGI(TAG, "Setting LCD backlight: %d%%", brightness_percent);
332345
const uint8_t reg_val = 20 + ((8 * brightness_percent) / 100); // 0b00000 ~ 0b11100; under 20, it is too dark
333346
const uint8_t lcd_bl_val[] = { 0x99, reg_val }; // AXP DLDO1 voltage
334-
ESP_RETURN_ON_ERROR(i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, lcd_bl_val, sizeof(lcd_bl_val), 1000 / portTICK_PERIOD_MS), TAG, "I2C write failed");
347+
ESP_RETURN_ON_ERROR(i2c_master_transmit(axp2101_h, lcd_bl_val, sizeof(lcd_bl_val), 1000), TAG, "I2C write failed");
335348

336349
return ESP_OK;
337350
}
@@ -414,8 +427,9 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
414427
},
415428
};
416429
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
417-
const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
418-
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, "");
430+
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
431+
tp_io_config.scl_speed_hz = 400000; // This parameter was introduce together with I2C Driver-NG in IDF v5.2
432+
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, "");
419433
return esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, ret_touch);
420434
}
421435

examples/display/sdkconfig.bsp.m5stack_core_s3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
CONFIG_IDF_TARGET="esp32s3"
55
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
66
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
7+
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
78

89
## LVGL8 ##
910
CONFIG_LV_USE_PERF_MONITOR=y

examples/display_audio_photo/sdkconfig.bsp.m5stack_core_s3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CONFIG_SPIRAM_SPEED_80M=y
1010
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
1111
CONFIG_SPIFFS_PAGE_SIZE=1024
1212
CONFIG_LV_SPRINTF_CUSTOM=y
13-
CONFIG_JD_USE_ROM=n
13+
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
1414
# CONFIG_LV_BUILD_EXAMPLES is not set
1515

1616
## LVGL8 ##

examples/display_camera/sdkconfig.bsp.m5stack_core_s3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192
1414
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
1515
CONFIG_LV_SPRINTF_CUSTOM=y
1616
CAMERA_TASK_STACK_SIZE=4096
17+
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
1718

1819
# CONFIG_LV_BUILD_EXAMPLES is not set
1920

examples/display_lvgl_demos/sdkconfig.bsp.m5stack_core_s3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CONFIG_LV_USE_DEMO_STRESS=y
2222
CONFIG_LV_USE_DEMO_MUSIC=y
2323
CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y
2424
CONFIG_LV_DEMO_MUSIC_SQUARE=y
25+
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
2526

2627
## LVGL8 ##
2728
CONFIG_LV_USE_PERF_MONITOR=y

0 commit comments

Comments
 (0)