Skip to content

Commit

Permalink
Merge pull request #406 from espressif/refactor/core_s3_driver_ng
Browse files Browse the repository at this point in the history
feat(m5stack_core_s3): Support I2C Driver-NG
  • Loading branch information
tore-espressif authored Oct 17, 2024
2 parents f580175 + 63b9959 commit b5091df
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ 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 == "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"
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
test_apps/noglib:
Expand Down
4 changes: 2 additions & 2 deletions bsp/m5stack_core_s3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ idf_component_register(
SRCS "m5stack_core_s3.c" "m5stack_core_s3_idf5.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES driver spiffs
PRIV_REQUIRES fatfs esp_lcd
REQUIRES esp_driver_i2c esp_driver_i2s esp_driver_gpio esp_driver_sdmmc spiffs
PRIV_REQUIRES fatfs esp_lcd esp_driver_spi
)
6 changes: 3 additions & 3 deletions bsp/m5stack_core_s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Sound output on CoreS3 is optimized with the high-fidelity 16-bit I2S power ampl
| 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_ft5x06](https://components.espressif.com/components/espressif/esp_lcd_touch_ft5x06)| ^1 |
| BUTTONS | :x: | | |
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.1 |
| 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 | >=5.0 |
| 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.2|
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) |^2.0.11|
<!-- Autogenerated end: Dependencies -->
8 changes: 4 additions & 4 deletions bsp/m5stack_core_s3/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.1.1~1"
version: "2.0.0"
description: Board Support Package (BSP) for M5Stack CoreS3
url: https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_s3

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

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

Expand All @@ -18,9 +18,9 @@ dependencies:
public: true

esp_codec_dev:
version: "~1.1"
version: "~1.3.1"
public: true

esp32-camera:
version: "^2.0.2"
version: "^2.0.11"
public: true
13 changes: 2 additions & 11 deletions bsp/m5stack_core_s3/include/bsp/m5stack_core_s3.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@

#include "sdkconfig.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "driver/i2s_std.h"
#include "driver/sdmmc_host.h"
#include "soc/usb_pins.h"
#include "esp_codec_dev.h"
#include "bsp/config.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

#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
#include "lvgl.h"
#include "esp_lvgl_port.h"
Expand Down Expand Up @@ -134,11 +129,7 @@ extern "C" {
* - 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
69 changes: 45 additions & 24 deletions bsp/m5stack_core_s3/m5stack_core_s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "driver/i2c.h"

#include "bsp/m5stack_core_s3.h"
#include "bsp/display.h"
Expand Down Expand Up @@ -46,7 +44,17 @@ static lv_indev_t *disp_indev = NULL;
#endif // (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
static esp_lcd_touch_handle_t tp; // LCD touch handle
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_platforma.h"
*/
static i2c_master_bus_handle_t i2c_handle = NULL;
static bool i2c_initialized = false;
static i2c_master_dev_handle_t axp2101_h = NULL;
static i2c_master_dev_handle_t aw9523_h = NULL;
static bool spi_initialized = false;

esp_err_t bsp_i2c_init(void)
Expand All @@ -56,25 +64,35 @@ 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 = 1,
};
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;
// AXP2101 and AW9523 are managed by this BSP
const i2c_device_config_t axp2101_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = BSP_AXP2101_ADDR,
.scl_speed_hz = 400000,
};
BSP_ERROR_CHECK_RETURN_ERR(i2c_master_bus_add_device(i2c_handle, &axp2101_config, &axp2101_h));
const i2c_device_config_t aw9523_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = BSP_AW9523_ADDR,
.scl_speed_hz = 400000,
};
BSP_ERROR_CHECK_RETURN_ERR(i2c_master_bus_add_device(i2c_handle, &aw9523_config, &aw9523_h));

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;
}
Expand Down Expand Up @@ -102,27 +120,27 @@ static esp_err_t bsp_enable_feature(bsp_feature_t feature)
/* AXP ALDO4 voltage / SD Card / 3V3 */
data[0] = 0x95;
data[1] = 0b00011100; //3V3
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
/* Enable SD */
aw9523_P0 |= (1 << 4);
break;
case BSP_FEATURE_SPEAKER:
/* AXP ALDO1 voltage / PA PVDD / 1V8 */
data[0] = 0x92;
data[1] = 0b00001101; //1V8
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
/* AXP ALDO2 voltage / Codec / 3V3 */
data[0] = 0x93;
data[1] = 0b00011100; //3V3
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
/* AXP ALDO3 voltage / Codec+Mic / 3V3 */
data[0] = 0x94;
data[1] = 0b00011100; //3V3
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AXP2101_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(axp2101_h, data, sizeof(data), 1000);
/* AW9523 P0 is in push-pull mode */
data[0] = 0x11;
data[1] = 0x10;
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(aw9523_h, data, sizeof(data), 1000);
/* Enable Codec AW88298 */
aw9523_P0 |= (1 << 2);
break;
Expand All @@ -134,11 +152,11 @@ static esp_err_t bsp_enable_feature(bsp_feature_t feature)

data[0] = 0x02;
data[1] = aw9523_P0;
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(aw9523_h, data, sizeof(data), 1000);

data[0] = 0x03;
data[1] = aw9523_P1;
err |= i2c_master_write_to_device(BSP_I2C_NUM, BSP_AW9523_ADDR, data, sizeof(data), 1000 / portTICK_PERIOD_MS);
err |= i2c_master_transmit(aw9523_h, data, sizeof(data), 1000);

return err;
}
Expand Down Expand Up @@ -246,6 +264,7 @@ esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
audio_codec_i2c_cfg_t i2c_cfg = {
.port = BSP_I2C_NUM,
.addr = AW88298_CODEC_DEFAULT_ADDR,
.bus_handle = i2c_handle,
};
const audio_codec_ctrl_if_t *out_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);

Expand All @@ -272,7 +291,7 @@ 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 */
/* Initialize I2C */
BSP_ERROR_CHECK_RETURN_NULL(bsp_i2c_init());
/* Configure I2S peripheral and Power Amplifier */
BSP_ERROR_CHECK_RETURN_NULL(bsp_audio_init(NULL));
Expand All @@ -283,6 +302,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 @@ -312,9 +332,9 @@ esp_err_t bsp_display_brightness_init(void)
BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init());

const uint8_t lcd_bl_en[] = { 0x90, 0xBF }; // AXP DLDO1 Enable
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");
ESP_RETURN_ON_ERROR(i2c_master_transmit(axp2101_h, lcd_bl_en, sizeof(lcd_bl_en), 1000), TAG, "I2C write failed");
const uint8_t lcd_bl_val[] = { 0x99, 0b00011000 }; // AXP DLDO1 voltage
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");
ESP_RETURN_ON_ERROR(i2c_master_transmit(axp2101_h, lcd_bl_val, sizeof(lcd_bl_val), 1000), TAG, "I2C write failed");

return ESP_OK;
}
Expand All @@ -331,7 +351,7 @@ esp_err_t bsp_display_brightness_set(int brightness_percent)
ESP_LOGI(TAG, "Setting LCD backlight: %d%%", brightness_percent);
const uint8_t reg_val = 20 + ((8 * brightness_percent) / 100); // 0b00000 ~ 0b11100; under 20, it is too dark
const uint8_t lcd_bl_val[] = { 0x99, reg_val }; // AXP DLDO1 voltage
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");
ESP_RETURN_ON_ERROR(i2c_master_transmit(axp2101_h, lcd_bl_val, sizeof(lcd_bl_val), 1000), TAG, "I2C write failed");

return ESP_OK;
}
Expand Down Expand Up @@ -414,8 +434,9 @@ esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t
},
};
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_FT5x06_CONFIG();
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_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
tp_io_config.scl_speed_hz = 400000; // This parameter was introduce 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, "");
return esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, ret_touch);
}

Expand Down
1 change: 1 addition & 0 deletions examples/display/sdkconfig.bsp.m5stack_core_s3
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CONFIG_IDF_TARGET="esp32s3"
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down
2 changes: 1 addition & 1 deletion examples/display_audio_photo/sdkconfig.bsp.m5stack_core_s3
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CONFIG_SPIRAM_SPEED_80M=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_SPIFFS_PAGE_SIZE=1024
CONFIG_LV_SPRINTF_CUSTOM=y
CONFIG_JD_USE_ROM=n
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
# CONFIG_LV_BUILD_EXAMPLES is not set

## LVGL8 ##
Expand Down
1 change: 1 addition & 0 deletions examples/display_camera/sdkconfig.bsp.m5stack_core_s3
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_LV_SPRINTF_CUSTOM=y
CAMERA_TASK_STACK_SIZE=4096
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

# CONFIG_LV_BUILD_EXAMPLES is not set

Expand Down
1 change: 1 addition & 0 deletions examples/display_lvgl_demos/sdkconfig.bsp.m5stack_core_s3
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.m5stack_core_s3
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CONFIG_IDF_TARGET="esp32s3"
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_LV_MEMCPY_MEMSET_STD=y
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n

## LVGL8 ##
CONFIG_LV_USE_PERF_MONITOR=y
Expand Down

0 comments on commit b5091df

Please sign in to comment.