diff --git a/.build-test-rules.yml b/.build-test-rules.yml index bea7e367..4a50410b 100644 --- a/.build-test-rules.yml +++ b/.build-test-rules.yml @@ -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: @@ -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/**" @@ -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: diff --git a/bsp/esp32_s3_eye/CMakeLists.txt b/bsp/esp32_s3_eye/CMakeLists.txt index 165e540f..9db765ad 100644 --- a/bsp/esp32_s3_eye/CMakeLists.txt +++ b/bsp/esp32_s3_eye/CMakeLists.txt @@ -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 ) diff --git a/bsp/esp32_s3_eye/Kconfig b/bsp/esp32_s3_eye/Kconfig index 9306c9c9..22097031 100644 --- a/bsp/esp32_s3_eye/Kconfig +++ b/bsp/esp32_s3_eye/Kconfig @@ -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" @@ -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" @@ -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 @@ -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 diff --git a/bsp/esp32_s3_eye/README.md b/bsp/esp32_s3_eye/README.md index df2a13da..1e2837ab 100644 --- a/bsp/esp32_s3_eye/README.md +++ b/bsp/esp32_s3_eye/README.md @@ -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 | diff --git a/bsp/esp32_s3_eye/esp32_s3_eye.c b/bsp/esp32_s3_eye/esp32_s3_eye.c index a82bc3e8..a6353767 100644 --- a/bsp/esp32_s3_eye/esp32_s3_eye.c +++ b/bsp/esp32_s3_eye/esp32_s3_eye.c @@ -19,7 +19,7 @@ #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" @@ -27,18 +27,23 @@ 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 @@ -46,9 +51,7 @@ 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_PLAY, .adc_button_config.min = 1880, // middle is 1980mV @@ -56,9 +59,7 @@ 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_DOWN, .adc_button_config.min = 720, // middle is 820mV @@ -66,9 +67,7 @@ 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_UP, .adc_button_config.min = 280, // middle is 380mV @@ -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 = { @@ -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"); @@ -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(); @@ -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; diff --git a/bsp/esp32_s3_eye/esp32_s3_eye_idf4.c b/bsp/esp32_s3_eye/esp32_s3_eye_idf4.c deleted file mode 100644 index 45c7a48a..00000000 --- a/bsp/esp32_s3_eye/esp32_s3_eye_idf4.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "esp_err.h" -#include "bsp/esp32_s3_eye.h" -#include "bsp_err_check.h" -#include "esp_codec_dev_defaults.h" - -static const char *TAG = "S3-EYE"; - -/* Sample rate of MSM261S4030H0 */ -#define BSP_MIC_SAMPLE_RATE (48000u) - -/* This configuration is used by default in bsp_audio_init() */ -#define BSP_I2S_SIMPLEX_MONO_CFG(_sample_rate) \ - { \ - .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX, \ - .sample_rate = _sample_rate, \ - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, \ - .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, \ - .communication_format = I2S_COMM_FORMAT_STAND_I2S, \ - .dma_buf_count = 3, \ - .dma_buf_len = 1024, \ - .use_apll = true, \ - .tx_desc_auto_clear = true, \ - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM \ - } - -static const audio_codec_data_if_t *i2s_data_if = NULL; /* Codec data interface */ - -esp_err_t bsp_audio_init(const i2s_config_t *i2s_config) -{ - esp_err_t ret = ESP_FAIL; - - if (i2s_data_if != NULL) { - /* Audio was initialized before */ - return ESP_OK; - } - - /* Setup I2S peripheral */ - const i2s_pin_config_t i2s_pin_config = { - .mck_io_num = GPIO_NUM_NC, - .bck_io_num = BSP_I2S_SCLK, - .ws_io_num = BSP_I2S_LCLK, - .data_out_num = GPIO_NUM_NC, - .data_in_num = BSP_I2S_DIN - }; - - /* Setup I2S channels */ - const i2s_config_t std_cfg_default = BSP_I2S_SIMPLEX_MONO_CFG(BSP_MIC_SAMPLE_RATE); - const i2s_config_t *p_i2s_cfg = &std_cfg_default; - if (i2s_config != NULL) { - p_i2s_cfg = i2s_config; - } - - ESP_ERROR_CHECK(i2s_driver_install(CONFIG_BSP_I2S_NUM, p_i2s_cfg, 0, NULL)); - ESP_GOTO_ON_ERROR(i2s_set_pin(CONFIG_BSP_I2S_NUM, &i2s_pin_config), err, TAG, "I2S set pin failed"); - - audio_codec_i2s_cfg_t i2s_cfg = { - .port = CONFIG_BSP_I2S_NUM, - }; - i2s_data_if = audio_codec_new_i2s_data(&i2s_cfg); - BSP_NULL_CHECK_GOTO(i2s_data_if, err); - - return ESP_OK; - -err: - i2s_driver_uninstall(CONFIG_BSP_I2S_NUM); - return ret; -} - -const audio_codec_data_if_t *bsp_audio_get_codec_itf(void) -{ - return i2s_data_if; -} - -esp_err_t bsp_adc_initialize(void) -{ - return ESP_OK; -} diff --git a/bsp/esp32_s3_eye/idf_component.yml b/bsp/esp32_s3_eye/idf_component.yml index efea657b..82dae467 100644 --- a/bsp/esp32_s3_eye/idf_component.yml +++ b/bsp/esp32_s3_eye/idf_component.yml @@ -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 @@ -9,7 +9,7 @@ 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" @@ -17,7 +17,7 @@ dependencies: override_path: "../../components/esp_lvgl_port" esp32-camera: - version: "^2.0.2" + version: "^2.0.13" public: true button: @@ -25,10 +25,10 @@ dependencies: 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 diff --git a/bsp/esp32_s3_eye/include/bsp/esp32_s3_eye.h b/bsp/esp32_s3_eye/include/bsp/esp32_s3_eye.h index df4e55ea..ba05da01 100644 --- a/bsp/esp32_s3_eye/include/bsp/esp32_s3_eye.h +++ b/bsp/esp32_s3_eye/include/bsp/esp32_s3_eye.h @@ -18,12 +18,7 @@ #include "iot_button.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" @@ -138,7 +133,7 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b * I2C interface * * There are two devices connected to I2C peripheral: - * - QMA7981 Inertial measurement unit + * - QMA7981 or QMA6100P Inertial measurement unit * - OV2640 Camera module **************************************************************************************************/ #define BSP_I2C_NUM CONFIG_BSP_I2C_NUM @@ -164,6 +159,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); + /************************************************************************************************** * * Camera interface @@ -441,11 +444,7 @@ esp_err_t bsp_led_set(const bsp_led_t led_io, const bool on); * - 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) @@ -483,17 +482,12 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void); */ esp_err_t bsp_adc_initialize(void); - -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) /** * @brief Get ADC handle * - * @note This function is available only in IDF5 and higher - * * @return ADC handle */ adc_oneshot_unit_handle_t bsp_adc_get_handle(void); -#endif #ifdef __cplusplus } diff --git a/components/qma6100p/idf_component.yml b/components/qma6100p/idf_component.yml index c2949f95..5c0914ad 100644 --- a/components/qma6100p/idf_component.yml +++ b/components/qma6100p/idf_component.yml @@ -1,6 +1,6 @@ -version: "1.0.0" +version: "2.0.0" description: I2C driver for QMA6100P accelerometer url: https://github.com/espressif/esp-bsp/tree/master/components/qma6100p dependencies: - idf : ">=4.0" + idf : ">=5.2" cmake_utilities: "0.*" diff --git a/components/qma6100p/include/qma6100p.h b/components/qma6100p/include/qma6100p.h index 5d18b642..9fc54e2b 100644 --- a/components/qma6100p/include/qma6100p.h +++ b/components/qma6100p/include/qma6100p.h @@ -15,7 +15,7 @@ extern "C" { #endif -#include "driver/i2c.h" +#include "driver/i2c_master.h" #include "driver/gpio.h" #define QMA6100P_I2C_ADDRESS 0x12u /*!< I2C address with AD0 pin low */ @@ -89,16 +89,18 @@ typedef struct { typedef void *qma6100p_handle_t; /** - * @brief Create and init sensor object and return a sensor handle - * - * @param port I2C port number - * @param dev_addr I2C device address of sensor + * @brief Create and init sensor object * + * @param[in] i2c_bus I2C bus handle. Obtained from i2c_new_master_bus() + * @param[in] dev_addr I2C device address of sensor. Can be QMA6100P_I2C_ADDRESS or QMA6100P_I2C_ADDRESS_1 + * @param[out] handle_ret Handle to created QMA6100P driver object* * @return - * - NULL Fail - * - Others Success + * - ESP_OK Success + * - ESP_ERR_NO_MEM Not enough memory for the driver + * - ESP_ERR_NOT_FOUND Sensor not found on the I2C bus + * - Others Error from underlying I2C driver */ -qma6100p_handle_t qma6100p_create(i2c_port_t port, const uint16_t dev_addr); +esp_err_t qma6100p_create(i2c_master_bus_handle_t i2c_bus, const uint8_t dev_addr, qma6100p_handle_t *handle_ret); /** * @brief Delete and release a sensor object diff --git a/components/qma6100p/qma6100p.c b/components/qma6100p/qma6100p.c index 7cd5d607..7269e4fe 100644 --- a/components/qma6100p/qma6100p.c +++ b/components/qma6100p/qma6100p.c @@ -8,8 +8,12 @@ #include #include #include "esp_system.h" -#include "driver/i2c.h" +#include "driver/i2c_master.h" #include "qma6100p.h" +#include "esp_err.h" +#include "esp_check.h" + +#define I2C_CLK_SPEED 400000 #define QMA6100P_WHO_AM_I 0x00u #define QMA6100P_ACCEL_CONFIG 0x0Fu @@ -38,7 +42,6 @@ #define QMA6100P_FIFO_DATA 0x3Fu #define QMA6100P_FIFO_MODE 0x3Eu - const uint8_t QMA6100P_DATA_RDY_INT_BIT = (uint8_t) BIT4; // FIFO full interrupt const uint8_t QMA6100P_FIFO_FULL_INT_BIT = (uint8_t) BIT5; @@ -47,11 +50,11 @@ const uint8_t QMA6100P_FIFO_WM_INT_BIT = (uint8_t) BIT6; const uint8_t QMA6100P_FIFO_OF_INT_BIT = (uint8_t) BIT7; const uint8_t QMA6100P_ALL_INTERRUPTS = (QMA6100P_DATA_RDY_INT_BIT | QMA6100P_FIFO_FULL_INT_BIT | QMA6100P_FIFO_WM_INT_BIT | QMA6100P_FIFO_OF_INT_BIT); +static const char *TAG = "QMA6100P"; typedef struct { - i2c_port_t bus; + i2c_master_dev_handle_t i2c_handle; gpio_num_t int_pin; - uint16_t dev_addr; uint32_t counter; float dt; /*!< delay time between two measurements, dt should be small (ms level) */ struct timeval *timer; @@ -60,65 +63,55 @@ typedef struct { static esp_err_t qma6100p_write(qma6100p_handle_t sensor, const uint8_t reg_start_addr, const uint8_t data_buf) { qma6100p_dev_t *sens = (qma6100p_dev_t *) sensor; - esp_err_t ret; - - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - ret = i2c_master_start(cmd); - assert(ESP_OK == ret); - ret = i2c_master_write_byte(cmd, sens->dev_addr | I2C_MASTER_WRITE, true); - assert(ESP_OK == ret); - ret = i2c_master_write_byte(cmd, reg_start_addr, true); - assert(ESP_OK == ret); - ret = i2c_master_write_byte(cmd, data_buf, true); - assert(ESP_OK == ret); - ret = i2c_master_stop(cmd); - assert(ESP_OK == ret); - ret = i2c_master_cmd_begin(sens->bus, cmd, 1000 / portTICK_PERIOD_MS); - i2c_cmd_link_delete(cmd); - return ret; + uint8_t write_buff[2] = {reg_start_addr, data_buf}; + return i2c_master_transmit(sens->i2c_handle, write_buff, 2, -1); } static esp_err_t qma6100p_read(qma6100p_handle_t sensor, const uint8_t reg_start_addr, uint8_t *const data_buf, const uint8_t data_len) { qma6100p_dev_t *sens = (qma6100p_dev_t *) sensor; - esp_err_t ret; - - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - ret = i2c_master_start(cmd); - assert(ESP_OK == ret); - ret = i2c_master_write_byte(cmd, sens->dev_addr | I2C_MASTER_WRITE, true); - assert(ESP_OK == ret); - ret = i2c_master_write_byte(cmd, reg_start_addr, true); - assert(ESP_OK == ret); - ret = i2c_master_start(cmd); - assert(ESP_OK == ret); - ret = i2c_master_write_byte(cmd, sens->dev_addr | I2C_MASTER_READ, true); - assert(ESP_OK == ret); - ret = i2c_master_read(cmd, data_buf, data_len, I2C_MASTER_LAST_NACK); - assert(ESP_OK == ret); - ret = i2c_master_stop(cmd); - assert(ESP_OK == ret); - ret = i2c_master_cmd_begin(sens->bus, cmd, 1000 / portTICK_PERIOD_MS); - i2c_cmd_link_delete(cmd); - return ret; + uint8_t reg_buff[] = {reg_start_addr}; + assert(sens); + + return i2c_master_transmit_receive(sens->i2c_handle, reg_buff, sizeof(reg_buff), data_buf, data_len, -1); } -qma6100p_handle_t qma6100p_create(i2c_port_t port, const uint16_t dev_addr) +esp_err_t qma6100p_create(i2c_master_bus_handle_t i2c_bus, const uint8_t dev_addr, qma6100p_handle_t *handle_ret) { + esp_err_t ret = ESP_OK; + qma6100p_dev_t *sensor = (qma6100p_dev_t *) calloc(1, sizeof(qma6100p_dev_t)); - sensor->bus = port; - sensor->dev_addr = dev_addr << 1; - sensor->counter = 0; - sensor->dt = 0; - sensor->timer = (struct timeval *) calloc(1, sizeof(struct timeval)); - return (qma6100p_handle_t) sensor; + struct timeval *timer = (struct timeval *) calloc(1, sizeof(struct timeval)); + ESP_RETURN_ON_FALSE(sensor != NULL && timer != NULL, ESP_ERR_NO_MEM, TAG, "Not enough memory"); + sensor->timer = timer; + + // Add new I2C device + const i2c_device_config_t i2c_dev_cfg = { + .device_address = dev_addr, + .scl_speed_hz = I2C_CLK_SPEED, + }; + ESP_GOTO_ON_ERROR(i2c_master_bus_add_device(i2c_bus, &i2c_dev_cfg, &sensor->i2c_handle), err, TAG, "Failed to add new I2C device"); + assert(sensor->i2c_handle); + + *handle_ret = sensor; + return ret; + +err: + qma6100p_delete(sensor); + return ret; } void qma6100p_delete(qma6100p_handle_t sensor) { qma6100p_dev_t *sens = (qma6100p_dev_t *) sensor; + if (sens->i2c_handle) { + i2c_master_bus_rm_device(sens->i2c_handle); + } + if (sens->timer) { + free(sens->timer); + } free(sens); } diff --git a/components/qma6100p/test_apps/main/idf_component.yml b/components/qma6100p/test_apps/main/idf_component.yml index 2502e5c0..0f217d14 100644 --- a/components/qma6100p/test_apps/main/idf_component.yml +++ b/components/qma6100p/test_apps/main/idf_component.yml @@ -1,6 +1,6 @@ ## IDF Component Manager Manifest File dependencies: - idf: ">=4.0" + idf: ">=5.2" qma6100p: version: "*" override_path: "../../../qma6100p" diff --git a/components/qma6100p/test_apps/main/test_esp_acc_qma6100p.c b/components/qma6100p/test_apps/main/test_esp_acc_qma6100p.c index b6b57d6d..22f53aec 100644 --- a/components/qma6100p/test_apps/main/test_esp_acc_qma6100p.c +++ b/components/qma6100p/test_apps/main/test_esp_acc_qma6100p.c @@ -6,7 +6,7 @@ #include #include "unity.h" -#include "driver/i2c.h" +#include "driver/i2c_master.h" #include "qma6100p.h" #include "esp_system.h" #include "esp_log.h" @@ -21,25 +21,21 @@ static const char *TAG = "qma6100p test"; static qma6100p_handle_t qma6100p = NULL; +static i2c_master_bus_handle_t i2c_handle = NULL; /** * @brief i2c master initialization */ static void i2c_bus_init(void) { - i2c_config_t conf; - conf.mode = I2C_MODE_MASTER; - conf.sda_io_num = (gpio_num_t)I2C_MASTER_SDA_IO; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - conf.scl_io_num = (gpio_num_t)I2C_MASTER_SCL_IO; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - conf.master.clk_speed = I2C_MASTER_FREQ_HZ; - conf.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL; - - esp_err_t ret = i2c_param_config(I2C_MASTER_NUM, &conf); - TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "I2C config returned error"); - - ret = i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0); + const i2c_master_bus_config_t bus_config = { + .i2c_port = I2C_MASTER_NUM, + .sda_io_num = I2C_MASTER_SDA_IO, + .scl_io_num = I2C_MASTER_SCL_IO, + .clk_source = I2C_CLK_SRC_DEFAULT, + }; + + esp_err_t ret = i2c_new_master_bus(&bus_config, &i2c_handle); TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, ret, "I2C install returned error"); } @@ -51,7 +47,8 @@ static void i2c_sensor_qma6100p_init(void) esp_err_t ret; i2c_bus_init(); - qma6100p = qma6100p_create(I2C_MASTER_NUM, QMA6100P_I2C_ADDRESS); + ret = qma6100p_create(i2c_handle, QMA6100P_I2C_ADDRESS, &qma6100p); + TEST_ASSERT_EQUAL(ESP_OK, ret); TEST_ASSERT_NOT_NULL_MESSAGE(qma6100p, "QMA6100P create returned NULL"); ret = qma6100p_wake_up(qma6100p); @@ -75,7 +72,7 @@ TEST_CASE("Sensor qma6100p test", "[qma6100p][iot][sensor]") ESP_LOGI(TAG, "acce_x:%.2f, acce_y:%.2f, acce_z:%.2f\n", acce.acce_x, acce.acce_y, acce.acce_z); qma6100p_delete(qma6100p); - ret = i2c_driver_delete(I2C_MASTER_NUM); + ret = i2c_del_master_bus(i2c_handle); TEST_ASSERT_EQUAL(ESP_OK, ret); } diff --git a/examples/display/sdkconfig.bsp.esp32_s3_eye b/examples/display/sdkconfig.bsp.esp32_s3_eye index 8d117a9c..a9692de5 100644 --- a/examples/display/sdkconfig.bsp.esp32_s3_eye +++ b/examples/display/sdkconfig.bsp.esp32_s3_eye @@ -8,6 +8,7 @@ CONFIG_LV_SPRINTF_CUSTOM=y CONFIG_BSP_DISPLAY_LVGL_TICK=5 CONFIG_BSP_DISPLAY_LVGL_MAX_SLEEP=500 # CONFIG_LV_BUILD_EXAMPLES is not set +CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n ## LVGL8 ## CONFIG_LV_USE_PERF_MONITOR=y diff --git a/examples/display_camera/sdkconfig.bsp.esp32_s3_eye b/examples/display_camera/sdkconfig.bsp.esp32_s3_eye index 8774be6f..b58c50b0 100644 --- a/examples/display_camera/sdkconfig.bsp.esp32_s3_eye +++ b/examples/display_camera/sdkconfig.bsp.esp32_s3_eye @@ -18,6 +18,7 @@ CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y CONFIG_LV_SPRINTF_CUSTOM=y CAMERA_TASK_STACK_SIZE=4096 # CONFIG_LV_BUILD_EXAMPLES is not set +CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n ## LVGL8 ## CONFIG_LV_USE_PERF_MONITOR=y diff --git a/examples/display_lvgl_demos/sdkconfig.bsp.esp32_s3_eye b/examples/display_lvgl_demos/sdkconfig.bsp.esp32_s3_eye index a177bdc6..d321aabf 100644 --- a/examples/display_lvgl_demos/sdkconfig.bsp.esp32_s3_eye +++ b/examples/display_lvgl_demos/sdkconfig.bsp.esp32_s3_eye @@ -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