Skip to content

Commit

Permalink
feat(kaluga): Support I2C Driver-NG
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-espressif committed Nov 18, 2024
1 parent 8c29a6e commit e259b81
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .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 == "m5stack_core_s3"
- if: (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR < 4) and CONFIG_NAME in ["m5stack_core_s3", "esp32_s2_kaluga_kit"]
reason: Example depends on BSP, which is supported only for IDF >= 5.4

examples/generic_button_led:
Expand Down
13 changes: 3 additions & 10 deletions bsp/esp32_s2_kaluga_kit/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_s2_kaluga_kit_idf4.c")
else()
set(SRC_VER "esp32_s2_kaluga_kit_idf5.c")
endif()

idf_component_register(
SRCS "esp32_s2_kaluga_kit.c" ${SRC_VER}
SRCS "esp32_s2_kaluga_kit.c" "esp32_s2_kaluga_kit_idf5.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES driver
PRIV_REQUIRES esp_lcd spiffs
REQUIRES esp_lcd esp_driver_gpio esp_driver_i2s driver
PRIV_REQUIRES spiffs esp_driver_i2c esp_driver_spi esp_psram
)
26 changes: 13 additions & 13 deletions bsp/esp32_s2_kaluga_kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ The ESP32-S2-Kaluga-1 kit v1.3 is a development kit by Espressif that is mainly

<!-- Autogenerated start: Dependencies -->
### Capabilities and dependencies
| Capability | Available | Component | Version |
|-------------|------------------|----------------------------------------------------------------------------------------------|-----------|
| DISPLAY |:heavy_check_mark:| idf | >=4.4.5 |
| 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.0.3,<1.2|
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC |:heavy_check_mark:| | |
| LED |:heavy_check_mark:| idf | >=4.4.5 |
| SDCARD | :x: | | |
| IMU | :x: | | |
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.2 |
| Capability | Available | Component | Version |
|-------------|------------------|----------------------------------------------------------------------------------------------|----------|
| 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.3.1 |
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC |:heavy_check_mark:| | |
| LED |:heavy_check_mark:| idf | >=5.4 |
| SDCARD | :x: | | |
| IMU | :x: | | |
| CAMERA |:heavy_check_mark:| [espressif/esp32-camera](https://components.espressif.com/components/espressif/esp32-camera) | ^2.0.14 |
<!-- Autogenerated end: Dependencies -->
48 changes: 22 additions & 26 deletions bsp/esp32_s2_kaluga_kit/esp32_s2_kaluga_kit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include "driver/spi_master.h"
#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
Expand All @@ -22,10 +22,17 @@

static const char *TAG = "Kaluga";

/**
* @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

static const touch_pad_t bsp_touch_button[TOUCH_BUTTON_NUM] = {
TOUCH_BUTTON_PHOTO, /*!< 'PHOTO' button */
Expand All @@ -40,59 +47,47 @@ static const touch_pad_t bsp_touch_button[TOUCH_BUTTON_NUM] = {
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_5, // ADC1 channel 5 is GPIO6
.adc_button_config.button_index = BSP_BUTTON_REC,
.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_5, // ADC1 channel 5 is GPIO6
.adc_button_config.button_index = BSP_BUTTON_MODE,
.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_5, // ADC1 channel 5 is GPIO6
.adc_button_config.button_index = BSP_BUTTON_PLAY,
.adc_button_config.min = 1550, // middle is 1650mV
.adc_button_config.max = 1750
},
{
.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_5, // ADC1 channel 5 is GPIO6
.adc_button_config.button_index = BSP_BUTTON_SET,
.adc_button_config.min = 1010, // middle is 1110mV
.adc_button_config.max = 1210
},
{
.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_5, // ADC1 channel 5 is GPIO6
.adc_button_config.button_index = BSP_BUTTON_VOLDOWN,
.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_5, // ADC1 channel 5 is GPIO6
.adc_button_config.button_index = BSP_BUTTON_VOLUP,
.adc_button_config.min = 280, // middle is 380mV
Expand All @@ -108,11 +103,9 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
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 All @@ -137,29 +130,31 @@ 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;
}

/**
* @brief Common codec init
*
Expand Down Expand Up @@ -187,6 +182,7 @@ static esp_codec_dev_handle_t bsp_audio_codec_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
83 changes: 0 additions & 83 deletions bsp/esp32_s2_kaluga_kit/esp32_s2_kaluga_kit_idf4.c

This file was deleted.

10 changes: 5 additions & 5 deletions bsp/esp32_s2_kaluga_kit/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-S2-Kaluga kit
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s2_kaluga_kit

Expand All @@ -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"
Expand All @@ -21,15 +21,15 @@ dependencies:
public: true

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

led_strip:
version: "^2.5"
version: "^3.0"
public: true

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

examples:
Expand Down
22 changes: 9 additions & 13 deletions bsp/esp32_s2_kaluga_kit/include/bsp/esp32_s2_kaluga_kit.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@

#include "sdkconfig.h"
#include "driver/gpio.h"
#include "driver/touch_pad.h"
#include "driver/touch_sensor.h"
#include "driver/i2s_std.h"
#include "iot_button.h"
#include "lvgl.h"
#include "esp_lvgl_port.h"
#include "esp_codec_dev.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 @@ -145,11 +141,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 @@ -204,6 +196,13 @@ 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);

/**************************************************************************************************
*
Expand Down Expand Up @@ -394,8 +393,6 @@ void bsp_display_rotate(lv_display_t *disp, lv_disp_rotation_t rotation);
*/
esp_err_t bsp_adc_initialize(void);


#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
/**
* @brief Get ADC handle
*
Expand All @@ -404,7 +401,6 @@ esp_err_t bsp_adc_initialize(void);
* @return ADC handle
*/
adc_oneshot_unit_handle_t bsp_adc_get_handle(void);
#endif

/**************************************************************************************************
*
Expand Down
3 changes: 3 additions & 0 deletions examples/audio/sdkconfig.bsp.esp32_s2_kaluga_kit
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_LV_USE_PERF_MONITOR=y
CONFIG_LV_SPRINTF_CUSTOM=y
# CONFIG_LV_BUILD_EXAMPLES is not set

CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
CONFIG_TOUCH_SUPPRESS_DEPRECATE_WARN=y
Loading

0 comments on commit e259b81

Please sign in to comment.