examples: update new components;add esp-box-lite support.

This commit is contained in:
marcus_xu
2023-07-11 13:09:16 +08:00
parent e129cb58cd
commit 0924e7bc2c
79 changed files with 1004 additions and 689 deletions
+2 -1
View File
@@ -68,7 +68,8 @@ build_example_factory_demo_v5.0:
extends:
- .build_examples_template
- .rules:build:example_factory_demo
image: espressif/idf:release-v5.0
#image: espressif/idf:release-v5.0 don't support release-v5.0 now.
image: espressif/idf:release-v5.1
variables:
IDF_TARGET: esp32s3
EXAMPLE_DIR: examples/factory_demo
+1 -1
View File
@@ -32,7 +32,7 @@ The ESP-BOX is a new generation AIoT development platform released by Espressif
| ESP-BOX | Dependent ESP-IDF | Branch Note | Support State |
| :--------------: | :---------------: | :----------------------------------------------------: | -------------- |
| master | release/v5.0<br/>commit id: ef4b1b7704 | Latest developing firmware <br/>esp-sr version: v1.1.0 | New feature develop, Support ESP32-S3-BOX only |
| master | >= release/v5.0<br/>commit id: 96119acc8b | Latest developing firmware <br/>esp-sr version: v1.3.3 | Compatible with ESP32-S3-BOX and ESP32-S3-BOX-Lite <br/>Use menuconfig to select board |
| Tag 0.3.0 | release/v4.4<br>commit id: 2bdea81b2a | esp-sr version: dev/v2.0<br>commit id: c873a35 | Compatible with ESP32-S3-BOX and ESP32-S3-BOX-Lite |
| Tag 0.2.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.2.1/idf_patch) | esp-sr version: close v1.0<br/>commit id: 3ce34fe | Support ESP32-S3-BOX only |
| Tag 0.1.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.1.1/idf_patch) | esp-sr version: v0.9.6<br/>commit id: 3ce34fe | Support ESP32-S3-BOX only |
+1 -1
View File
@@ -32,7 +32,7 @@ ESP-BOX 是乐鑫信息科技发布的新一代 AIoT 应用开发平台。ESP32-
| ESP-BOX | 依赖的 ESP-IDF | 分支信息 | 支持状态 |
| :-------: | :----------------------------------------------------------: | :----------------------------------------------------------: | ------------------------------------------------------- |
| master | release/v5.0<br/>commit id: ef4b1b7704 | Latest developing firmware <br/>esp-sr version: v1.1.0 | 新功能开发分支,支持 ESP32-S3-BOX |
| master | >= release/v5.0<br/>commit id: 96119acc8b | Latest developing firmware <br/>esp-sr version: v1.3.3 | 兼容 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite<br/>使用 menuconfig 选择开发板 |
| Tag 0.3.0 | release/v4.4<br/>commit id: 2bdea81b2a | esp-sr version: dev/v2.0<br/>commit id: c873a35 | 兼容 ESP32-S3-BOX 和 ESP32-S3-BOX-Lite |
| Tag 0.2.1 | release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.2.1/idf_patch) | esp-sr version: close v1.0<br/>commit id: 3ce34fe | 仅支持 ESP32-S3-BOX |
| Tag 0.1.1 | Release/v4.4 with [patch](https://github.com/espressif/esp-box/tree/v0.1.1/idf_patch) | esp-sr version: v0.9.6<br/>commit id: 3ce34fe | 仅支持 ESP32-S3-BOX |
+21 -6
View File
@@ -1,15 +1,30 @@
set(bsp_src "src/storage/bsp_sdcard.c")
if (CONFIG_BSP_BOARD_ESP32_S3_BOX)
list(APPEND bsp_src "src/boards/esp32_s3_box.c")
elseif (CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite)
list(APPEND bsp_src "src/boards/esp32_s3_box_lite.c")
message(STATUS "PROJECT_DIR: " ${PROJECT_DIR})
if(EXISTS ${PROJECT_DIR}/sdkconfig)
file(READ ${PROJECT_DIR}/sdkconfig SDKCONFIG_RULE)
string(REGEX MATCH "CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y" CMAKE_TARGET_IS_BOX_LITE "${SDKCONFIG_RULE}")
string(REGEX MATCH "CONFIG_BSP_BOARD_ESP32_S3_BOX=y" CMAKE_TARGET_IS_ESP_BOX "${SDKCONFIG_RULE}")
else()
#message(FATAL_ERROR "Platform unknown.")
message(STATUS "sdkconfig not exist")
file(READ ${CMAKE_CURRENT_LIST_DIR}/Kconfig.projbuild SDKCONFIG_RULE)
string(REGEX MATCH "default BSP_BOARD_ESP32_S3_BOX_Lite" CMAKE_TARGET_IS_BOX_LITE "${SDKCONFIG_RULE}")
string(REGEX MATCH "default BSP_BOARD_ESP32_S3_BOX" CMAKE_TARGET_IS_ESP_BOX "${SDKCONFIG_RULE}")
endif()
set(priv_requires "es7210" "esp-box")
if (CMAKE_TARGET_IS_ESP_BOX)
message(STATUS "PLATFORM ESP32_S3_BOX.")
list(APPEND bsp_src "src/boards/esp32_s3_box.c")
elseif (CMAKE_TARGET_IS_BOX_LITE)
message(STATUS "PLATFORM ESP32_S3_BOX_Lite.")
list(APPEND bsp_src "src/boards/esp32_s3_box_lite.c")
set(box_lite "-lite")
else()
message(FATAL_ERROR "PLATFORM unknown.")
endif()
set(priv_requires "esp-box${box_lite}")
set(requires "driver" "fatfs")
idf_component_register(
+8 -2
View File
@@ -6,7 +6,13 @@ menu "HMI Board Config"
config BSP_BOARD_ESP32_S3_BOX
bool "BSP board esp32_s3_box"
config BSP_BOARD_ESP32_S3_BOX_Lite
bool "BSP board esp32_s3_box_lite [Not Supported]"
bool "BSP board esp32_s3_box_lite"
endchoice
config BSP_TOUCH_BUTTON
depends on BSP_BOARD_ESP32_S3_BOX
bool "Enable esp32_s3_box touch button"
default y
help
Whether to enable the touch button.
endmenu
+7 -1
View File
@@ -1,4 +1,10 @@
## IDF Component Manager Manifest File
dependencies:
espressif/button: ^2
espressif/es7210: "~1.0.0"
espressif/esp-box:
version: "2.4.*"
require: "no"
espressif/esp-box-lite:
version: "1.0.*"
require: "no"
+1 -4
View File
@@ -10,8 +10,8 @@
#include "esp_err.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
// #include "bsp/esp-bsp.h"
#include "driver/i2s_std.h"
#include "bsp/esp-bsp.h"
#include "iot_button.h"
#ifdef __cplusplus
@@ -31,9 +31,6 @@ typedef enum {
BOARD_BTN_ID_NUM
#elif CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
BOARD_BTN_ID_BOOT = 0,
BOARD_BTN_ID_PREV,
BOARD_BTN_ID_ENTER,
BOARD_BTN_ID_NEXT,
BOARD_BTN_ID_NUM
#endif
} bsp_button_id_t;
+48 -67
View File
@@ -6,26 +6,20 @@
#include "esp_log.h"
#include "esp_check.h"
#include "hal/i2s_hal.h"
#include "bsp/esp-bsp.h"
#include "bsp_board.h"
#include "iot_button.h"
#include "es7210.h"
#include "es8311.h"
#define ES8311_SAMPLE_RATE (16000)
#define ES8311_DEFAULT_VOLUME (60)
#define ES7210_I2C_ADDR (0x40)
#define ES7210_SAMPLE_RATE (16000)
#define ES7210_I2S_FORMAT ES7210_I2S_FMT_I2S
#define ES7210_MCLK_MULTIPLE (256)
#define ES7210_BIT_WIDTH ES7210_I2S_BITS_16B
#define ES7210_MIC_BIAS ES7210_MIC_BIAS_2V87
#define ES7210_MIC_GAIN ES7210_MIC_GAIN_30DB
#define ES7210_ADC_VOLUME (0)
#define ES7210_BIT_WIDTH (16)
#define ES7210_ADC_VOLUME (24.0)
#define ES7210_CHANNEL (2)
static bool bsp_home_button_get(void *param);
static uint8_t bsp_home_button_get(void *param);
static const pmod_pins_t g_pmod[2] = {
{
@@ -90,6 +84,10 @@ static const button_config_t BOARD_BTN_ID_config[BOARD_BTN_ID_NUM] = {
},
};
static esp_codec_dev_handle_t play_dev_handle;
static esp_codec_dev_handle_t record_dev_handle;
static button_handle_t *g_btn_handle = NULL;
static bsp_codec_config_t g_codec_handle;
@@ -99,17 +97,15 @@ static const boards_info_t g_boards_info = {
.board_desc = &g_board_s3_box_res
};
static i2s_chan_handle_t i2s_tx_chan;
static i2s_chan_handle_t i2s_rx_chan;
static es7210_dev_handle_t es7210_handle = NULL;
static es8311_handle_t es8311_handle = NULL;
static const char *TAG = "board";
static bool bsp_home_button_get(void *param)
static uint8_t bsp_home_button_get(void *param)
{
#if CONFIG_BSP_TOUCH_BUTTON
return bsp_button_get(BSP_BUTTON_MAIN);
#else
return false;
#endif
}
esp_err_t bsp_btn_init(void)
@@ -158,30 +154,34 @@ esp_err_t bsp_btn_rm_all_callback(bsp_button_id_t btn)
static esp_err_t bsp_i2s_read(void *audio_buffer, size_t len, size_t *bytes_read, uint32_t timeout_ms)
{
esp_err_t ret = ESP_OK;
ret = i2s_channel_read(i2s_rx_chan, (char *)audio_buffer, len, bytes_read, timeout_ms);
ret = esp_codec_dev_read(record_dev_handle, audio_buffer, len);
*bytes_read = len;
return ret;
}
static esp_err_t bsp_i2s_write(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms)
{
esp_err_t ret = ESP_OK;
ret = i2s_channel_write(i2s_tx_chan, (char *)audio_buffer, len, bytes_written, timeout_ms);
ret = esp_codec_dev_write(play_dev_handle, audio_buffer, len);
*bytes_written = len;
return ret;
}
static esp_err_t bsp_i2s_reconfig_clk(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch)
static esp_err_t bsp_codec_es8311_set(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch)
{
esp_err_t ret = ESP_OK;
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(rate),
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t)bits_cfg, (i2s_slot_mode_t)ch),
.gpio_cfg = BSP_I2S_GPIO_CFG,
esp_codec_dev_sample_info_t fs = {
.sample_rate = rate,
.channel = ch,
.bits_per_sample = bits_cfg,
};
ret |= i2s_channel_disable(i2s_tx_chan);
ret |= i2s_channel_reconfig_std_clock(i2s_tx_chan, &std_cfg.clk_cfg);
ret |= i2s_channel_reconfig_std_slot(i2s_tx_chan, &std_cfg.slot_cfg);
ret |= i2s_channel_enable(i2s_tx_chan);
ret = esp_codec_dev_close(play_dev_handle);
ret = esp_codec_dev_close(record_dev_handle);
ret = esp_codec_dev_open(play_dev_handle, &fs);
ret = esp_codec_dev_open(record_dev_handle, &fs);
return ret;
}
@@ -191,14 +191,14 @@ static esp_err_t bsp_codec_volume_set(int volume, int *volume_set)
float v = volume;
v *= 0.6f;
v = -0.01f * (v * v) + 2.0f * v;
ret = es8311_voice_volume_set(es8311_handle, (int)v, volume_set);
ret = esp_codec_dev_set_out_vol(play_dev_handle, (int)v);
return ret;
}
static esp_err_t bsp_codec_mute_set(bool enable)
{
esp_err_t ret = ESP_OK;
ret = es8311_voice_mute(es8311_handle, enable);
ret = esp_codec_dev_set_out_mute(play_dev_handle, enable);
return ret;
}
@@ -206,56 +206,37 @@ static esp_err_t bsp_codec_es7210_set()
{
esp_err_t ret = ESP_OK;
es7210_codec_config_t codec_conf = {
.i2s_format = ES7210_I2S_FORMAT,
.mclk_ratio = ES7210_MCLK_MULTIPLE,
.sample_rate_hz = ES7210_SAMPLE_RATE,
.bit_width = ES7210_BIT_WIDTH,
.mic_bias = ES7210_MIC_BIAS,
.mic_gain = ES7210_MIC_GAIN,
.flags.tdm_enable = false
esp_codec_dev_sample_info_t fs = {
.sample_rate = ES7210_SAMPLE_RATE,
.channel = ES7210_CHANNEL,
.bits_per_sample = ES7210_BIT_WIDTH,
};
ret |= es7210_config_codec(es7210_handle, &codec_conf);
ret |= es7210_config_volume(es7210_handle, ES7210_ADC_VOLUME);
assert(record_dev_handle);
ret = esp_codec_dev_open(record_dev_handle, &fs);
esp_codec_dev_set_in_gain(record_dev_handle, ES7210_ADC_VOLUME);
return ret;
}
static void bsp_codec_init()
{
/* Create ES7210 device handle */
es7210_i2c_config_t es7210_i2c_conf = {
.i2c_port = BSP_I2C_NUM,
.i2c_addr = ES7210_I2C_ADDR
};
es7210_new_codec(&es7210_i2c_conf, &es7210_handle);
play_dev_handle = bsp_audio_codec_speaker_init();
assert((play_dev_handle) && "play_dev_handle not initialized");
record_dev_handle = bsp_audio_codec_microphone_init();
assert((record_dev_handle) && "record_dev_handle not initialized");
bsp_audio_poweramp_enable(false);
bsp_codec_es7210_set();
es8311_handle = es8311_create(BSP_I2C_NUM, ES8311_ADDRRES_0);
es8311_clock_config_t clk_cfg = BSP_ES8311_SCLK_CONFIG(ES8311_SAMPLE_RATE);
es8311_init(es8311_handle, &clk_cfg, ES8311_RESOLUTION_32, ES8311_RESOLUTION_32);
es8311_voice_volume_set(es8311_handle, ES8311_DEFAULT_VOLUME, NULL);
/* Microphone settings */
es8311_microphone_config(es8311_handle, false);
es8311_microphone_gain_set(es8311_handle, ES8311_MIC_GAIN_42DB);
/* Configure I2S peripheral and Power Amplifier */
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000),
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
.gpio_cfg = BSP_I2S_GPIO_CFG,
};
bsp_audio_init(&std_cfg, &i2s_tx_chan, &i2s_rx_chan);
bsp_audio_poweramp_enable(true);
bsp_codec_config_t *codec_config = bsp_board_get_codec_handle();
codec_config->volume_set_fn = bsp_codec_volume_set;
codec_config->mute_set_fn = bsp_codec_mute_set;
codec_config->codec_reconfig_fn = bsp_codec_es7210_set;
codec_config->i2s_read_fn = bsp_i2s_read;
codec_config->i2s_write_fn = bsp_i2s_write;
codec_config->i2s_reconfig_clk_fn = bsp_i2s_reconfig_clk;
codec_config->i2s_reconfig_clk_fn = bsp_codec_es8311_set;
}
__attribute__((weak)) void mute_btn_handler(void *handle, void *arg)
+50 -67
View File
@@ -4,27 +4,21 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
#include "esp_log.h"
#include "bsp_board.h"
#include "esp_log.h"
#include "esp_check.h"
#include "hal/i2s_hal.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include "soc/soc_caps.h"
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h"
#else
#include "driver/adc.h"
#include "esp_adc_cal.h"
#endif
#include "bsp/esp-bsp.h"
#include "bsp_board.h"
#include "iot_button.h"
#define es8156_SAMPLE_RATE (16000)
#define es8156_DEFAULT_VOLUME (60)
#define ES7243_SAMPLE_RATE (16000)
#define ES7243_BIT_WIDTH (16)
#define ES7243_ADC_VOLUME (24.0)
#define ES7243_CHANNEL (2)
static const pmod_pins_t g_pmod[2] = {
{
@@ -77,29 +71,11 @@ const button_config_t BOARD_BTN_ID_config[BOARD_BTN_ID_NUM] = {
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = BOARD_BTN_ID_BOOT,
},
{
.type = BUTTON_TYPE_ADC,
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BOARD_BTN_ID_PREV,
.adc_button_config.min = 2286, // middle is 2386mV
.adc_button_config.max = 2486
},
{
.type = BUTTON_TYPE_ADC,
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BOARD_BTN_ID_ENTER,
.adc_button_config.min = 1863, // middle is 1963mV
.adc_button_config.max = 2063
},
{
.type = BUTTON_TYPE_ADC,
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = BOARD_BTN_ID_NEXT,
.adc_button_config.min = 694, // middle is 794mV
.adc_button_config.max = 894
}
};
static esp_codec_dev_handle_t play_dev_handle;
static esp_codec_dev_handle_t record_dev_handle;
static button_handle_t *g_btn_handle = NULL;
static bsp_codec_config_t g_codec_handle;
@@ -109,12 +85,8 @@ static const boards_info_t g_boards_info = {
.board_desc = &g_board_s3_box_lite_res
};
static i2s_chan_handle_t i2s_tx_chan;
static i2s_chan_handle_t i2s_rx_chan;
static const char *TAG = "board";
esp_err_t bsp_btn_init(void)
{
ESP_ERROR_CHECK((NULL != g_btn_handle));
@@ -161,61 +133,79 @@ esp_err_t bsp_btn_rm_all_callback(bsp_button_id_t btn)
static esp_err_t bsp_i2s_read(void *audio_buffer, size_t len, size_t *bytes_read, uint32_t timeout_ms)
{
esp_err_t ret = ESP_OK;
ret = i2s_channel_read(i2s_rx_chan, (char *)audio_buffer, len, bytes_read, timeout_ms);
ret = esp_codec_dev_read(record_dev_handle, audio_buffer, len);
*bytes_read = len;
return ret;
}
static esp_err_t bsp_i2s_write(void *audio_buffer, size_t len, size_t *bytes_written, uint32_t timeout_ms)
{
esp_err_t ret = ESP_OK;
ret = i2s_channel_write(i2s_tx_chan, (char *)audio_buffer, len, bytes_written, timeout_ms);
ret = esp_codec_dev_write(play_dev_handle, audio_buffer, len);
*bytes_written = len;
return ret;
}
static esp_err_t bsp_i2s_reconfig_clk(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch)
static esp_err_t bsp_codec_es8156_set(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch)
{
esp_err_t ret = ESP_OK;
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(rate),
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t)bits_cfg, (i2s_slot_mode_t)ch),
.gpio_cfg = BSP_I2S_GPIO_CFG,
esp_codec_dev_sample_info_t fs = {
.sample_rate = rate,
.channel = ch,
.bits_per_sample = bits_cfg,
};
ret |= i2s_channel_disable(i2s_tx_chan);
ret |= i2s_channel_reconfig_std_clock(i2s_tx_chan, &std_cfg.clk_cfg);
ret |= i2s_channel_reconfig_std_slot(i2s_tx_chan, &std_cfg.slot_cfg);
ret |= i2s_channel_enable(i2s_tx_chan);
ret = esp_codec_dev_close(play_dev_handle);
ret = esp_codec_dev_close(record_dev_handle);
ret = esp_codec_dev_open(play_dev_handle, &fs);
ret = esp_codec_dev_open(record_dev_handle, &fs);
return ret;
}
static esp_err_t bsp_codec_volume_set(int volume, int *volume_set)
{
esp_err_t ret = ESP_OK;
float v = volume;
v *= 0.6f;
v = -0.01f * (v * v) + 2.0f * v;
ret = esp_codec_dev_set_out_vol(play_dev_handle, (int)v);
return ret;
}
static esp_err_t bsp_codec_mute_set(bool enable)
{
esp_err_t ret = ESP_OK;
ret = esp_codec_dev_set_out_mute(play_dev_handle, enable);
return ret;
}
static esp_err_t bsp_codec_es7243_set()
{
esp_err_t ret = ESP_OK;
esp_codec_dev_sample_info_t fs = {
.sample_rate = ES7243_SAMPLE_RATE,
.channel = ES7243_CHANNEL,
.bits_per_sample = ES7243_BIT_WIDTH,
};
assert(record_dev_handle);
ret = esp_codec_dev_open(record_dev_handle, &fs);
esp_codec_dev_set_in_gain(record_dev_handle, ES7243_ADC_VOLUME);
return ret;
}
static void bsp_codec_init()
{
/* Configure I2S peripheral and Power Amplifier */
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(16000),
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
.gpio_cfg = BSP_I2S_GPIO_CFG,
};
bsp_audio_init(&std_cfg, &i2s_tx_chan, &i2s_rx_chan);
bsp_audio_poweramp_enable(true);
play_dev_handle = bsp_audio_codec_speaker_init();
assert((play_dev_handle) && "play_dev_handle not initialized");
record_dev_handle = bsp_audio_codec_microphone_init();
assert((record_dev_handle) && "record_dev_handle not initialized");
bsp_codec_es7243_set();
bsp_codec_config_t *codec_config = bsp_board_get_codec_handle();
codec_config->volume_set_fn = bsp_codec_volume_set;
@@ -223,20 +213,13 @@ static void bsp_codec_init()
codec_config->codec_reconfig_fn = bsp_codec_es7243_set;
codec_config->i2s_read_fn = bsp_i2s_read;
codec_config->i2s_write_fn = bsp_i2s_write;
codec_config->i2s_reconfig_clk_fn = bsp_i2s_reconfig_clk;
codec_config->i2s_reconfig_clk_fn = bsp_codec_es8156_set;
}
esp_err_t bsp_board_s3_box_lite_init(void)
{
/**
* @brief Initialize I2S and audio codec
*
* @note Actually the sampling rate can be reconfigured.
* `MP3GetLastFrameInfo` can fill the `MP3FrameInfo`, which includes `samprate`.
* So theoretically, the sampling rate can be dynamically changed according to the MP3 frame information.
*/
bsp_btn_init();
bsp_codec_init();
return ESP_OK;
}
+7 -4
View File
@@ -29,8 +29,9 @@
static const char *TAG = "app_audio";
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
static bool mute_flag = true;
#endif
bool record_flag = false;
uint32_t record_total_len = 0;
uint32_t file_total_len = 0;
@@ -92,7 +93,7 @@ void audio_record_init()
return; // Return or handle the error condition appropriately
}
file_iterator_instance_t *file_iterator = file_iterator_new(BSP_MOUNT_POINT);
file_iterator_instance_t *file_iterator = file_iterator_new(BSP_SPIFFS_MOUNT_POINT);
assert(file_iterator != NULL);
/* Configure I2S peripheral and Power Amplifier */
@@ -296,9 +297,10 @@ void sr_handler_task(void *pvParam)
{
static bool mute_state = false;
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
mute_flag = bsp_button_get(BSP_BUTTON_MUTE);
printf("sr handle task, mute:%d\n", mute_flag);
#endif
while (true) {
if (NEED_DELETE && xEventGroupGetBits(g_sr_data->event_group)) {
@@ -313,6 +315,7 @@ void sr_handler_task(void *pvParam)
app_sr_get_result(&result, pdMS_TO_TICKS(1 * 1000));
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
if (mute_state != mute_flag) {
mute_state = mute_flag;
if (false == mute_state) {
@@ -321,7 +324,7 @@ void sr_handler_task(void *pvParam)
bsp_codec_config->codec_reconfig_fn();
}
}
#endif
if (ESP_MN_STATE_TIMEOUT == result.state) {
ESP_LOGI(TAG, "ESP_MN_STATE_TIMEOUT");
audio_record_stop();
-1
View File
@@ -30,7 +30,6 @@
#include "app_wifi.h"
static const char *TAG = "app_sr";
extern bool mute_flag;
static esp_afe_sr_iface_t *afe_handle = NULL;
static srmodel_list_t *models = NULL;
+7 -2
View File
@@ -48,9 +48,14 @@ void ui_ctrl_init(void)
static void wifi_check_timer_handler(lv_timer_t *timer)
{
if (WIFI_STATUS_CONNECTED_OK == wifi_connected_already()){
lv_obj_clear_flag(ui_PanelSetupSteps, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ui_PanelSetupWifi, LV_OBJ_FLAG_HIDDEN);
_ui_flag_modify(ui_PanelSetupSteps, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
_ui_flag_modify(ui_PanelSetupWifi, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
lv_timer_del(timer);
if (ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
lv_group_add_obj(ui_get_btn_op_group(), ui_ButtonSetup);
}
} else {
if (strlen(lv_label_get_text(ui_LabelSetupWifi)) >= sizeof(LABEL_WIFI_TEXT) + LABEL_WIFI_DOT_COUNT_MAX + 1) {
lv_label_set_text(ui_LabelSetupWifi, LABEL_WIFI_TEXT);
+1 -2
View File
@@ -1,5 +1,4 @@
## IDF Component Manager Manifest File
dependencies:
chmorgan/esp-file-iterator: "1.0.0"
espressif/esp-box: "~2.2.0"
espressif/esp-sr: "1.3.0"
espressif/esp-sr: "1.3.3"
@@ -33,8 +33,13 @@ esp_err_t settings_factory_reset(void)
memcpy(&g_sys_param, &g_default_sys_param, sizeof(sys_param_t));
ESP_LOGW(TAG, "ssid|password:[%s:%s]", DEFAULT_ESP_WIFI_SSID, DEFAULT_ESP_WIFI_PASS);
memcpy(&g_sys_param.ssid[0], DEFAULT_ESP_WIFI_SSID, strlen(DEFAULT_ESP_WIFI_SSID));
memcpy(&g_sys_param.password[0], DEFAULT_ESP_WIFI_PASS, strlen(DEFAULT_ESP_WIFI_PASS));
if((0 == strlen(DEFAULT_ESP_WIFI_SSID)) || ( 0 == strlen(DEFAULT_ESP_WIFI_PASS))){
memcpy(&g_sys_param.ssid[0], "DEFAULT_ESP_WIFI_SSID", strlen("DEFAULT_ESP_WIFI_SSID"));
memcpy(&g_sys_param.password[0], "DEFAULT_ESP_WIFI_PASS", strlen("DEFAULT_ESP_WIFI_PASS"));
} else {
memcpy(&g_sys_param.ssid[0], DEFAULT_ESP_WIFI_SSID, strlen(DEFAULT_ESP_WIFI_SSID));
memcpy(&g_sys_param.password[0], DEFAULT_ESP_WIFI_PASS, strlen(DEFAULT_ESP_WIFI_PASS));
}
g_sys_param.password_len = strlen(g_sys_param.password);
g_sys_param.ssid_len = strlen(g_sys_param.ssid);
@@ -408,5 +408,4 @@ void ui_ScreenListen_screen_init(void)
lv_obj_add_event_cb(ui_PanelSleep, ui_event_PanelSleep, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_ImageListenSettings, ui_event_ImageListenSettings, LV_EVENT_ALL, NULL);
}
@@ -141,6 +141,10 @@ void ui_ScreenSettings_screen_init(void)
lv_obj_set_y(ui_DropdownSettingsRegion, -9);
lv_obj_set_align(ui_DropdownSettingsRegion, LV_ALIGN_BOTTOM_RIGHT);
lv_obj_add_flag(ui_DropdownSettingsRegion, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_set_style_outline_width(ui_DropdownSettingsRegion, 0, LV_STATE_FOCUSED);
lv_obj_set_style_outline_pad(ui_DropdownSettingsRegion, 0, LV_STATE_FOCUSED);
lv_obj_set_style_outline_width(ui_DropdownSettingsRegion, 0, LV_STATE_FOCUS_KEY);
lv_obj_set_style_outline_pad(ui_DropdownSettingsRegion, 0, LV_STATE_FOCUS_KEY);
lv_obj_set_style_text_align(ui_DropdownSettingsRegion, LV_TEXT_ALIGN_CENTER, LV_PART_INDICATOR | LV_STATE_DEFAULT);
@@ -83,16 +83,22 @@ void ui_ScreenSetup_screen_init(void)
ui_LabelSetupStepContent = lv_label_create(ui_PanelSetupSteps);
lv_obj_set_width(ui_LabelSetupStepContent, lv_pct(88));
lv_obj_set_height(ui_LabelSetupStepContent, lv_pct(61));
lv_obj_set_height(ui_LabelSetupStepContent, lv_pct(73));
lv_obj_set_x(ui_LabelSetupStepContent, lv_pct(0));
lv_obj_set_y(ui_LabelSetupStepContent, lv_pct(20));
lv_obj_set_align(ui_LabelSetupStepContent, LV_ALIGN_TOP_MID);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
lv_label_set_text(ui_LabelSetupStepContent,
"1. Wake up the device using \"Hi ESP\".\n2. Ask a question within 10 seconds and wait for a reply.\n3. In sleep mode, click screen can wake up the device. ");
lv_obj_set_style_text_line_space(ui_LabelSetupStepContent, 10, LV_PART_MAIN | LV_STATE_DEFAULT);
#else
lv_label_set_text(ui_LabelSetupStepContent,
"1. Wake up the device using \"Hi ESP\".\n2. Ask a question within 10 seconds and wait for a reply.\n3. In sleep mode, click \"Enter\" button can wake up the device.\n4. Long press \"Enter\" button to enter/exit Settings.");
lv_obj_set_style_text_line_space(ui_LabelSetupStepContent, 7, LV_PART_MAIN | LV_STATE_DEFAULT);
#endif
lv_obj_set_style_text_color(ui_LabelSetupStepContent, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(ui_LabelSetupStepContent, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_letter_space(ui_LabelSetupStepContent, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_line_space(ui_LabelSetupStepContent, 10, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_LabelSetupStepContent, &ui_font_PingFangEN14, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_LabelSetupStepTile = lv_label_create(ui_PanelSetupSteps);
@@ -129,5 +135,4 @@ void ui_ScreenSetup_screen_init(void)
lv_obj_set_style_text_font(ui_LabelSetupBtn, &ui_font_PingFangEN16, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_add_event_cb(ui_ButtonSetup, ui_event_ButtonSetup, LV_EVENT_ALL, NULL);
}
+43 -1
View File
@@ -76,6 +76,9 @@ void ui_event____initial_actions0(lv_event_t * e);
lv_obj_t * ui____initial_actions0;
const lv_img_dsc_t * ui_imgset_listen_body_eyes_[2] = {&ui_img_listen_body_eyes_1_png, &ui_img_listen_body_eyes_2_png};
static lv_group_t *g_btn_op_group = NULL;
///////////////////// TEST LVGL SETTINGS ////////////////////
#if LV_COLOR_DEPTH != 16
#error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings"
@@ -84,6 +87,11 @@ const lv_img_dsc_t * ui_imgset_listen_body_eyes_[2] = {&ui_img_listen_body_eyes_
#error "LV_COLOR_16_SWAP should be 1 to match SquareLine Studio's settings"
#endif
lv_group_t *ui_get_btn_op_group(void)
{
return g_btn_op_group;
}
///////////////////// ANIMATIONS ////////////////////
void sleep_body_up_down_Animation(lv_obj_t * TargetObject, int delay)
{
@@ -185,6 +193,10 @@ void ui_event_ButtonSetup(lv_event_t * e)
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(ui_ScreenListen, LV_SCR_LOAD_ANIM_NONE, 0, 0);
if(ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
lv_group_add_obj(ui_get_btn_op_group(), ui_PanelSleep);
}
sleep_body_up_down_Animation(ui_ImageSleepBody, 0);
listen_eye_blink_Animation(ui_ImageListenEye, 0);
listen_eye_screen_move_Animation(ui_ImageListenEyeScreen, 0);
@@ -200,10 +212,19 @@ void ui_event_PanelSleep(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
if(true == lv_obj_has_flag(ui_PanelSleep, LV_OBJ_FLAG_HIDDEN)) {
return;
}
if(event_code == LV_EVENT_SHORT_CLICKED) {
_ui_flag_modify(ui_PanelListen, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
_ui_flag_modify(ui_PanelSleep, LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
EventPanelSleepClickCb(e);
} else if(event_code == LV_EVENT_LONG_PRESSED) {
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
lv_event_send(ui_ImageListenSettings, LV_EVENT_CLICKED, NULL);
#endif
}
}
void ui_event_ImageListenSettings(lv_event_t * e)
@@ -212,14 +233,24 @@ void ui_event_ImageListenSettings(lv_event_t * e)
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(ui_ScreenSettings, LV_SCR_LOAD_ANIM_NONE, 0, 0);
if(ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
lv_group_add_obj(ui_get_btn_op_group(), ui_DropdownSettingsRegion);
}
}
}
void ui_event_DropdownSettingsRegion(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_VALUE_CHANGED) {
EventSettingsRegionValueChange(e);
} else if(event_code == LV_EVENT_LONG_PRESSED_REPEAT) {
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
lv_event_send(ui_ImageSettingsBack, LV_EVENT_CLICKED, NULL);
#endif
}
}
void ui_event_ImageSettingsBack(lv_event_t * e)
@@ -228,6 +259,10 @@ void ui_event_ImageSettingsBack(lv_event_t * e)
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(ui_ScreenListen, LV_SCR_LOAD_ANIM_NONE, 0, 0);
if(ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
lv_group_add_obj(ui_get_btn_op_group(), ui_PanelSleep);
}
}
}
void ui_event____initial_actions0(lv_event_t * e)
@@ -247,6 +282,13 @@ void ui_init(void)
lv_disp_t * dispp = lv_disp_get_default();
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
false, LV_FONT_DEFAULT);
lv_indev_t *indev = lv_indev_get_next(NULL);
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
g_btn_op_group = lv_group_create();
lv_indev_set_group(indev, g_btn_op_group);
}
lv_disp_set_theme(dispp, theme);
ui_ScreenSetup_screen_init();
ui_ScreenListen_screen_init();
+3
View File
@@ -79,6 +79,9 @@ extern lv_obj_t * ui_ImageSettingsBack;
void ui_event____initial_actions0(lv_event_t * e);
extern lv_obj_t * ui____initial_actions0;
// EVENT: event for ESP32_S3_BOX_Lite
lv_group_t *ui_get_btn_op_group(void);
LV_IMG_DECLARE(ui_img_setup_bg_png); // assets\setup_bg.png
LV_IMG_DECLARE(ui_img_setup_text_bg_png); // assets\setup_text_bg.png
LV_IMG_DECLARE(ui_img_body_shadow_png); // assets\body_shadow.png
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+3 -1
View File
@@ -58,7 +58,6 @@ CONFIG_ESP_WIFI_RX_BA_WIN=6
CONFIG_FREERTOS_HZ=1000
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
CONFIG_AUDIO_PLAYER_LOG_LEVEL=1
CONFIG_LV_COLOR_16_SWAP=y
CONFIG_LV_MEM_CUSTOM=y
CONFIG_LV_MEMCPY_MEMSET_STD=y
@@ -68,3 +67,6 @@ CONFIG_SPIRAM_SPEED_80M=y
CONFIG_SPIRAM_SPEED=80
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
+2
View File
@@ -9,6 +9,8 @@ The factory_demo is a built-in firmware of ESP-BOX series products, which integr
## How to use example
<font color="red">[Note]: </font>This example requires ESP-IDF release/v5.1 or later.
Please check the [User-Guide](../../docs/getting_started.md).
### Hardware Required
+5 -5
View File
@@ -123,13 +123,13 @@ static void obtain_time(void)
static void initialize_sntp(void)
{
ESP_LOGI(TAG, "Initializing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "ntp.aliyun.com");
sntp_setservername(1, "time.asia.apple.com");
sntp_setservername(2, "pool.ntp.org");
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
esp_sntp_setservername(0, "ntp.aliyun.com");
esp_sntp_setservername(1, "time.asia.apple.com");
esp_sntp_setservername(2, "pool.ntp.org");
sntp_set_time_sync_notification_cb(time_sync_notification_cb);
#ifdef CONFIG_SNTP_TIME_SYNC_METHOD_SMOOTH
sntp_set_sync_mode(SNTP_SYNC_MODE_SMOOTH);
#endif
sntp_init();
esp_sntp_init();
}
+5 -6
View File
@@ -353,11 +353,6 @@ esp_err_t app_sr_set_language(sr_language_t new_lang)
g_sr_data->multinet->destroy(g_sr_data->model_data);
}
// remove all command
app_sr_remove_all_cmd();
esp_mn_commands_free();
esp_mn_commands_alloc();
g_sr_data->cmd_num = 0;
char *wn_name = esp_srmodel_filter(models, ESP_WN_PREFIX, (SR_LANG_EN == g_sr_data->lang ? "hiesp" : "hilexin"));
@@ -371,6 +366,9 @@ esp_err_t app_sr_set_language(sr_language_t new_lang)
g_sr_data->model_data = model_data;
ESP_LOGI(TAG, "load multinet:%s,%d,%d", mn_name, sizeof(esp_mn_iface_t), sizeof(esp_mn_iface_t));
// remove all command
app_sr_remove_all_cmd();
uint8_t cmd_number = 0;
// count command number
for (size_t i = 0; i < sizeof(g_default_cmd_info) / sizeof(sr_cmd_t); i++) {
@@ -380,6 +378,7 @@ esp_err_t app_sr_set_language(sr_language_t new_lang)
}
}
ESP_LOGI(TAG, "cmd_number=%d", cmd_number);
return app_sr_update_cmds();/* Reset command list */
}
@@ -605,7 +604,7 @@ esp_err_t app_sr_update_cmds(void)
esp_mn_error_t *err_id = esp_mn_commands_update(g_sr_data->multinet, g_sr_data->model_data);
if(err_id){
for (int i = 0; i < err_id->num; i++) {
ESP_LOGE(TAG, "err cmd id:%d", err_id->phrase_idx[i]);
ESP_LOGE(TAG, "err cmd id:%d", err_id->phrases[i]);
}
}
esp_mn_commands_print();
@@ -70,6 +70,7 @@ static esp_err_t sr_echo_play(audio_segment_t audio)
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
uint8_t *p = g_audio_data[audio].audio_buffer;
wav_header_t *wav_head = (wav_header_t *)p;
if (NULL == strstr((char *)wav_head->Subchunk1ID, "fmt") &&
NULL == strstr((char *)wav_head->Subchunk2ID, "data")) {
ESP_LOGE(TAG, "Header of wav format error");
@@ -81,7 +82,10 @@ static esp_err_t sr_echo_play(audio_segment_t audio)
ESP_LOGD(TAG, "frame_rate=%d, ch=%d, width=%d", wav_head->SampleRate, wav_head->NumChannels, wav_head->BitsPerSample);
codec_handle->i2s_reconfig_clk_fn(wav_head->SampleRate, wav_head->BitsPerSample, I2S_SLOT_MODE_STEREO);
//i2s_zero_dma_buffer(I2S_NUM_0);
vTaskDelay(pdMS_TO_TICKS(500));
codec_handle->mute_set_fn(false);
codec_handle->volume_set_fn(85, NULL);
sys_param_t *param = settings_get_parameter();
codec_handle->volume_set_fn(param->volume, NULL);
codec_handle->mute_set_fn(false);
@@ -36,6 +36,7 @@ static void ui_about_us_page_return_click_cb(lv_event_t *e)
}
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
static void btn_return_down_cb(void *handle, void *arg)
{
lv_obj_t *obj = (lv_obj_t *) arg;
@@ -43,6 +44,7 @@ static void btn_return_down_cb(void *handle, void *arg)
lv_event_send(obj, LV_EVENT_CLICKED, NULL);
ui_release();
}
#endif
static void factory_end_cb(void)
{
@@ -100,6 +100,7 @@ static void ui_dev_ctrl_page_return_click_cb(lv_event_t *e)
}
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
static void btn_return_down_cb(void *handle, void *arg)
{
lv_obj_t *obj = (lv_obj_t *) arg;
@@ -107,6 +108,7 @@ static void btn_return_down_cb(void *handle, void *arg)
lv_event_send(obj, LV_EVENT_CLICKED, NULL);
ui_release();
}
#endif
void ui_device_ctrl_start(void (*fn)(void))
{
-24
View File
@@ -20,24 +20,6 @@ static void (*g_hint_end_cb)(void) = NULL;
LV_FONT_DECLARE(font_en_16);
LV_FONT_DECLARE(font_cn_gb1_16);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
static void hint_page_btn_prev_cb(void *arg, void *data)
{
lv_obj_t *obj = (lv_obj_t *) data;
uint16_t tab_index = lv_tabview_get_tab_act(obj);
if (tab_index > 0) {
tab_index --;
ESP_LOGI(TAG, "hint previous");
lv_tabview_set_act(obj, tab_index, LV_ANIM_ON);
if (ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
lv_group_add_obj(ui_get_btn_op_group(), g_hint_page_btn[tab_index]);
}
}
}
#endif
static void hint_page_btn_next_cb(void *arg, void *data)
{
lv_obj_t *obj = (lv_obj_t *) data;
@@ -303,10 +285,4 @@ void ui_hint_start(void (*fn)(void))
lv_obj_set_style_text_color(label, lv_color_make(255, 0, 0), LV_PART_MAIN);
lv_obj_center(label);
lv_obj_add_event_cb(btn_next, ui_hint_page_next_click_cb, LV_EVENT_RELEASED, tabview);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
bsp_btn_register_callback(BOARD_BTN_ID_PREV, BUTTON_PRESS_DOWN, hint_page_btn_prev_cb, (void *)tabview);
bsp_btn_register_callback(BOARD_BTN_ID_NEXT, BUTTON_PRESS_DOWN, hint_page_btn_next_cb, (void *)tabview);
#endif
}
+216 -118
View File
@@ -202,87 +202,178 @@ static item_desc_t item[] = {
{ .name = "About Us", .img_src = (void *) &icon_about_us},
};
static lv_obj_t *g_img_item = NULL;
static lv_obj_t *g_img_btn, *g_img_item = NULL;
static lv_obj_t *g_lab_item = NULL;
static lv_obj_t *g_led_item[5];
static size_t g_item_size = sizeof(item) / sizeof(item[0]);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
static void btn_press_prev_cb(void *arg, void *data)
{
lv_obj_t *obj = (lv_obj_t *) data;
ui_acquire();
lv_event_send(obj, LV_EVENT_PRESSED, lv_indev_get_act());
ui_release();
}
static lv_obj_t *g_focus_last_obj = NULL;
static lv_obj_t *g_group_list[3] = {0};
static void btn_press_next_cb(void *arg, void *data)
static uint32_t menu_get_num_offset(uint32_t focus, int32_t max, int32_t offset)
{
lv_obj_t *obj = (lv_obj_t *) data;
ui_acquire();
lv_event_send(obj, LV_EVENT_RELEASED, lv_indev_get_act());
ui_release();
}
#endif
static void menu_prev_cb(lv_event_t *e)
{
lv_led_off(g_led_item[g_item_index]);
if (0 == g_item_index) {
g_item_index = g_item_size;
if (focus >= max) {
ESP_LOGI(TAG, "[ERROR] focus should less than max");
return focus;
}
g_item_index--;
uint32_t i;
if (offset >= 0) {
i = (focus + offset) % max;
} else {
offset = max + (offset % max);
i = (focus + offset) % max;
}
return i;
}
static int8_t menu_direct_probe(lv_obj_t *focus_obj)
{
int8_t direct;
uint32_t index_max_sz, index_focus, index_prev;
index_focus = 0;
index_prev = 0;
index_max_sz = sizeof(g_group_list)/ sizeof(g_group_list[0]);
for(int i = 0; i< index_max_sz; i++){
if(focus_obj == g_group_list[i]){
index_focus = i;
}
if(g_focus_last_obj == g_group_list[i]){
index_prev = i;
}
}
if(NULL == g_focus_last_obj){
direct = 0;
} else if(index_focus == menu_get_num_offset(index_prev, index_max_sz, 1)){
direct = 1;
} else if(index_focus == menu_get_num_offset(index_prev, index_max_sz, -1)){
direct = -1;
} else {
direct = 0;
}
g_focus_last_obj = focus_obj;
return direct;
}
void menu_new_item_select(lv_obj_t *obj)
{
int8_t direct = menu_direct_probe(obj);
g_item_index = menu_get_num_offset(g_item_index, g_item_size, direct);
ESP_LOGI(TAG, "slected:%d, direct:%d", g_item_index, direct);
lv_led_on(g_led_item[g_item_index]);
lv_img_set_src(g_img_item, item[g_item_index].img_src);
lv_label_set_text_static(g_lab_item, item[g_item_index].name);
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
static void menu_prev_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_user_data(e);
if (LV_EVENT_FOCUSED == code) {
lv_led_off(g_led_item[g_item_index]);
menu_new_item_select(obj);
} else if (LV_EVENT_CLICKED == code) {
lv_event_send(g_img_btn, LV_EVENT_CLICKED, g_img_btn);
}
}
static void menu_next_cb(lv_event_t *e)
{
lv_led_off(g_led_item[g_item_index]);
g_item_index++;
if (g_item_index >= g_item_size) {
g_item_index = 0;
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_user_data(e);
if (LV_EVENT_FOCUSED == code) {
lv_led_off(g_led_item[g_item_index]);
menu_new_item_select(obj);
} else if (LV_EVENT_CLICKED == code) {
lv_event_send(g_img_btn, LV_EVENT_CLICKED, g_img_btn);
}
lv_led_on(g_led_item[g_item_index]);
lv_img_set_src(g_img_item, item[g_item_index].img_src);
lv_label_set_text_static(g_lab_item, item[g_item_index].name);
}
#else
static void menu_prev_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
if (LV_EVENT_RELEASED == code) {
lv_led_off(g_led_item[g_item_index]);
if (0 == g_item_index) {
g_item_index = g_item_size;
}
g_item_index--;
lv_led_on(g_led_item[g_item_index]);
lv_img_set_src(g_img_item, item[g_item_index].img_src);
lv_label_set_text_static(g_lab_item, item[g_item_index].name);
}
}
static void menu_next_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
if (LV_EVENT_RELEASED == code) {
lv_led_off(g_led_item[g_item_index]);
g_item_index++;
if (g_item_index >= g_item_size) {
g_item_index = 0;
}
lv_led_on(g_led_item[g_item_index]);
lv_img_set_src(g_img_item, item[g_item_index].img_src);
lv_label_set_text_static(g_lab_item, item[g_item_index].name);
}
}
#endif
static void menu_enter_cb(lv_event_t *e)
{
ESP_LOGI(TAG, "menu item index=%d", g_item_index);
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_user_data(e);
if (ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
}
ui_btn_rm_all_cb();
ui_led_set_visible(false);
lv_obj_del(obj);
switch (g_item_index) {
case 0:
ui_status_bar_set_visible(true);
ui_device_ctrl_start(dev_ctrl_end_cb);
break;
case 1:
ui_status_bar_set_visible(true);
ui_net_config_start(net_end_cb);
break;
case 2:
ui_status_bar_set_visible(true);
ui_media_player(player_end_cb);
break;
case 3:
ui_status_bar_set_visible(false);
ui_help();
break;
case 4:
ui_status_bar_set_visible(true);
ui_about_us_start(about_us_end_cb);
break;
default:
break;
if (LV_EVENT_FOCUSED == code) {
lv_led_off(g_led_item[g_item_index]);
menu_new_item_select(obj);
} else if (LV_EVENT_CLICKED == code) {
lv_obj_t * menu_btn_parent = lv_obj_get_parent(obj);
ESP_LOGI(TAG, "menu click, item index = %d", g_item_index);
if (ui_get_btn_op_group()) {
lv_group_remove_all_objs(ui_get_btn_op_group());
}
ui_btn_rm_all_cb();
ui_led_set_visible(false);
lv_obj_del(menu_btn_parent);
g_focus_last_obj = NULL;
switch (g_item_index) {
case 0:
ui_status_bar_set_visible(true);
ui_device_ctrl_start(dev_ctrl_end_cb);
break;
case 1:
ui_status_bar_set_visible(true);
ui_net_config_start(net_end_cb);
break;
case 2:
ui_status_bar_set_visible(true);
ui_media_player(player_end_cb);
break;
case 3:
ui_status_bar_set_visible(false);
ui_help();
break;
case 4:
ui_status_bar_set_visible(true);
ui_about_us_start(about_us_end_cb);
break;
default:
break;
}
}
}
@@ -307,23 +398,22 @@ static void ui_main_menu(int32_t index_id)
lv_obj_set_style_shadow_opa(obj, LV_OPA_30, LV_PART_MAIN);
lv_obj_align(obj, LV_ALIGN_TOP_MID, 0, -10);
lv_obj_t *img_btn = lv_btn_create(obj);
lv_obj_set_size(img_btn, 80, 80);
lv_obj_add_style(img_btn, &ui_button_styles()->style_pr, LV_STATE_PRESSED);
lv_obj_add_style(img_btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(img_btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_set_style_bg_color(img_btn, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_shadow_color(img_btn, lv_color_make(0, 0, 0), LV_PART_MAIN);
lv_obj_set_style_shadow_width(img_btn, 15, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_x(img_btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_y(img_btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_opa(img_btn, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_radius(img_btn, 40, LV_PART_MAIN);
lv_obj_align(img_btn, LV_ALIGN_CENTER, 0, -20);
lv_group_add_obj(ui_get_btn_op_group(), img_btn);
lv_obj_add_event_cb(img_btn, menu_enter_cb, LV_EVENT_CLICKED, obj);
g_img_btn = lv_btn_create(obj);
lv_obj_set_size(g_img_btn, 80, 80);
lv_obj_add_style(g_img_btn, &ui_button_styles()->style_pr, LV_STATE_PRESSED);
lv_obj_add_style(g_img_btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(g_img_btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_set_style_bg_color(g_img_btn, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_shadow_color(g_img_btn, lv_color_make(0, 0, 0), LV_PART_MAIN);
lv_obj_set_style_shadow_width(g_img_btn, 15, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_x(g_img_btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_y(g_img_btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_opa(g_img_btn, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_radius(g_img_btn, 40, LV_PART_MAIN);
lv_obj_align(g_img_btn, LV_ALIGN_CENTER, 0, -20);
lv_obj_add_event_cb(g_img_btn, menu_enter_cb, LV_EVENT_ALL, g_img_btn);
g_img_item = lv_img_create(img_btn);
g_img_item = lv_img_create(g_img_btn);
lv_img_set_src(g_img_item, item[index_id].img_src);
lv_obj_center(g_img_item);
@@ -345,46 +435,63 @@ static void ui_main_menu(int32_t index_id)
}
lv_led_on(g_led_item[index_id]);
lv_obj_t *btn = lv_btn_create(obj);
lv_obj_add_style(btn, &ui_button_styles()->style_pr, LV_STATE_PRESSED);
lv_obj_set_size(btn, 40, 40);
lv_obj_set_style_bg_color(btn, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_shadow_color(btn, lv_color_make(0, 0, 0), LV_PART_MAIN);
lv_obj_set_style_shadow_width(btn, 15, LV_PART_MAIN);
lv_obj_set_style_shadow_opa(btn, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_x(btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_y(btn, 0, LV_PART_MAIN);
lv_obj_set_style_radius(btn, 20, LV_PART_MAIN);
lv_obj_align_to(btn, obj, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_t *label = lv_label_create(btn);
lv_obj_t *btn_prev = lv_btn_create(obj);
lv_obj_add_style(btn_prev, &ui_button_styles()->style_pr, LV_STATE_PRESSED);
lv_obj_add_style(btn_prev, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_prev, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_set_size(btn_prev, 40, 40);
lv_obj_set_style_bg_color(btn_prev, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_shadow_color(btn_prev, lv_color_make(0, 0, 0), LV_PART_MAIN);
lv_obj_set_style_shadow_width(btn_prev, 15, LV_PART_MAIN);
lv_obj_set_style_shadow_opa(btn_prev, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_x(btn_prev, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_y(btn_prev, 0, LV_PART_MAIN);
lv_obj_set_style_radius(btn_prev, 20, LV_PART_MAIN);
lv_obj_align_to(btn_prev, obj, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_t *label = lv_label_create(btn_prev);
lv_label_set_text_static(label, LV_SYMBOL_LEFT);
lv_obj_set_style_text_color(label, lv_color_make(5, 5, 5), LV_PART_MAIN);
lv_obj_center(label);
lv_obj_add_event_cb(btn, menu_prev_cb, LV_EVENT_RELEASED, NULL);
lv_obj_add_event_cb(btn_prev, menu_prev_cb, LV_EVENT_ALL, btn_prev);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
bsp_btn_register_callback(BOARD_BTN_ID_PREV, BUTTON_PRESS_DOWN, btn_press_prev_cb, (void *)btn);
bsp_btn_register_callback(BOARD_BTN_ID_PREV, BUTTON_PRESS_UP, btn_press_prev_cb, (void *)btn);
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), btn_prev);
}
g_group_list[0] = btn_prev;
#endif
btn = lv_btn_create(obj);
lv_obj_add_style(btn, &ui_button_styles()->style_pr, LV_STATE_PRESSED);
lv_obj_set_size(btn, 40, 40);
lv_obj_set_style_bg_color(btn, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_shadow_color(btn, lv_color_make(0, 0, 0), LV_PART_MAIN);
lv_obj_set_style_shadow_width(btn, 15, LV_PART_MAIN);
lv_obj_set_style_shadow_opa(btn, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_x(btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_y(btn, 0, LV_PART_MAIN);
lv_obj_set_style_radius(btn, 20, LV_PART_MAIN);
lv_obj_align_to(btn, obj, LV_ALIGN_RIGHT_MID, 0, 0);
label = lv_label_create(btn);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), g_img_btn);
}
g_group_list[1] = g_img_btn;
#endif
lv_obj_t *btn_next = lv_btn_create(obj);
lv_obj_add_style(btn_next, &ui_button_styles()->style_pr, LV_STATE_PRESSED);
lv_obj_add_style(btn_next, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_next, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_set_size(btn_next, 40, 40);
lv_obj_set_style_bg_color(btn_next, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_shadow_color(btn_next, lv_color_make(0, 0, 0), LV_PART_MAIN);
lv_obj_set_style_shadow_width(btn_next, 15, LV_PART_MAIN);
lv_obj_set_style_shadow_opa(btn_next, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_x(btn_next, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_ofs_y(btn_next, 0, LV_PART_MAIN);
lv_obj_set_style_radius(btn_next, 20, LV_PART_MAIN);
lv_obj_align_to(btn_next, obj, LV_ALIGN_RIGHT_MID, 0, 0);
label = lv_label_create(btn_next);
lv_label_set_text_static(label, LV_SYMBOL_RIGHT);
lv_obj_set_style_text_color(label, lv_color_make(5, 5, 5), LV_PART_MAIN);
lv_obj_center(label);
lv_obj_add_event_cb(btn, menu_next_cb, LV_EVENT_RELEASED, NULL);
lv_obj_add_event_cb(btn_next, menu_next_cb, LV_EVENT_ALL, btn_next);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
bsp_btn_register_callback(BOARD_BTN_ID_NEXT, BUTTON_PRESS_DOWN, btn_press_next_cb, (void *)btn);
bsp_btn_register_callback(BOARD_BTN_ID_NEXT, BUTTON_PRESS_UP, btn_press_next_cb, (void *)btn);
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), btn_next);
}
g_group_list[2] = btn_next;
#endif
}
@@ -419,7 +526,8 @@ esp_err_t ui_main_start(void)
lv_indev_t *indev = lv_indev_get_next(NULL);
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) {
if ((lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) || \
lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
ESP_LOGI(TAG, "Input device type is keypad");
g_btn_op_group = lv_group_create();
lv_indev_set_group(indev, g_btn_op_group);
@@ -481,17 +589,7 @@ static void ui_led_set_visible(bool visible)
void ui_btn_rm_all_cb(void)
{
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
for (size_t i = 0; i < BOARD_BTN_ID_NUM; i++) {
if (BOARD_BTN_ID_NEXT == i) {
bsp_btn_rm_all_callback(BOARD_BTN_ID_NEXT);
} else if (BOARD_BTN_ID_PREV == i) {
bsp_btn_rm_all_callback(BOARD_BTN_ID_PREV);
} else if (BOARD_BTN_ID_ENTER == i) {
bsp_btn_rm_all_callback(BOARD_BTN_ID_ENTER);
}
}
#elif CONFIG_BSP_BOARD_ESP32_S3_BOX
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
for (size_t i = 0; i < BOARD_BTN_ID_NUM; i++) {
if (BOARD_BTN_ID_HOME == i) {
bsp_btn_rm_all_callback(BOARD_BTN_ID_HOME);
+2
View File
@@ -77,11 +77,13 @@ void ui_mute_init(void)
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
static void ui_mute_set_state(bool mute)
{
mute_state = mute;
mute_disp_count = 0;
}
#endif
/**
* @brief Mute button handler.
@@ -36,6 +36,7 @@ static void ui_app_page_return_click_cb(lv_event_t *e)
lv_obj_del(obj);
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
static void btn_return_down_cb(void *handle, void *arg)
{
lv_obj_t *obj = (lv_obj_t *) arg;
@@ -43,6 +44,7 @@ static void btn_return_down_cb(void *handle, void *arg)
lv_event_send(obj, LV_EVENT_CLICKED, NULL);
ui_release();
}
#endif
static void ui_net_config_page_app_click_cb(lv_event_t *e)
{
@@ -118,6 +118,7 @@ static void ui_player_page_return_click_cb(lv_event_t *e)
}
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX
static void btn_return_down_cb(void *handle, void *arg)
{
lv_obj_t *obj = (lv_obj_t *) arg;
@@ -125,6 +126,7 @@ static void btn_return_down_cb(void *handle, void *arg)
lv_event_send(obj, LV_EVENT_CLICKED, NULL);
ui_release();
}
#endif
static void audio_cb(audio_player_cb_ctx_t *ctx)
{
+5 -11
View File
@@ -1,12 +1,10 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.0"
idf: ">=5.1"
chmorgan/esp-audio-player: "1.0.4"
chmorgan/esp-audio-player: "1.0.5"
chmorgan/esp-file-iterator: "1.0.0"
chmorgan/esp-libhelix-mp3: "1.0.3"
espressif/esp-box: "2.3.*"
espressif/esp_rainmaker:
path: components/esp_rainmaker
git: https://github.com/espressif/esp-rainmaker.git
@@ -15,12 +13,8 @@ dependencies:
path: components/esp_schedule
git: https://github.com/espressif/esp-rainmaker.git
version: "cc861bffc818c607e799f66c79923fd4e2d00447"
espressif/rmaker_common:
path: ./
git: https://github.com/espressif/esp-rainmaker-common.git
version: "b5c21128fb9b37316cb38c8edf2facb63013cc74"
#espressif/rmaker_common: "1.3.0"
espressif/esp-sr: "1.1.0"
espressif/rmaker_common: "1.4.2"
espressif/esp-sr: "1.3.*"
espressif/led_strip: "~2.0.0"
espressif/json_generator: ^1
espressif/json_parser: =1.0.0
+1 -1
View File
@@ -9,7 +9,7 @@
/** Major version number (X.x.x) */
#define BOX_DEMO_VERSION_MAJOR 0
/** Minor version number (x.X.x) */
#define BOX_DEMO_VERSION_MINOR 4
#define BOX_DEMO_VERSION_MINOR 5
/** Patch version number (x.x.X) */
#define BOX_DEMO_VERSION_PATCH 0
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+6
View File
@@ -151,3 +151,9 @@ CONFIG_MQTT_TRANSPORT_WEBSOCKET=n
# Temporary Fix for Timer Overflows
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
# rainmaker
CONFIG_ESP_RMAKER_ASSISTED_CLAIM=y
+4 -3
View File
@@ -2,9 +2,10 @@ cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(EXTRA_COMPONENT_DIRS
../../components
)
add_compile_options(-fdiagnostics-color=always)
# The following line can be removed after LVGL update to v8.3.5.
add_compile_options(-Wno-format)
project(image_display)
@@ -1,4 +1,3 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.0"
espressif/esp-box: "2.3.*"
+2 -1
View File
@@ -61,7 +61,8 @@ static void image_display(void)
{
lv_indev_t *indev = lv_indev_get_next(NULL);
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) {
if ((lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) || \
lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
ESP_LOGI(TAG, "Input device type is keypad");
g_btn_op_group = lv_group_create();
lv_indev_set_group(indev, g_btn_op_group);
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+4 -1
View File
@@ -25,4 +25,7 @@ CONFIG_LV_USE_SJPG=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_SPEED_80M=y
CONFIG_SPIRAM_SPEED_80M=y
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
+4 -3
View File
@@ -4,9 +4,10 @@ cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(EXTRA_COMPONENT_DIRS
../../components
)
add_compile_options(-fdiagnostics-color=always)
# The following line can be removed after LVGL update to v8.3.5.
add_compile_options(-Wno-format)
project(lv_demos)
+1 -11
View File
@@ -1,12 +1,2 @@
set(LV_DEMO_DIR ../managed_components/lvgl__lvgl/demos)
file(GLOB_RECURSE LV_DEMOS_SOURCES ${LV_DEMO_DIR}/*.c ./*.c)
idf_component_register(
SRCS
"lv_demos.c"
${LV_DEMOS_SOURCES})
set_source_files_properties(
${LV_DEMOS_SOURCES}
PROPERTIES COMPILE_OPTIONS
-DLV_LVGL_H_INCLUDE_SIMPLE)
SRCS "lv_demos.c")
-1
View File
@@ -1,4 +1,3 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.0"
espressif/esp-box: "2.3.*"
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+4 -1
View File
@@ -15,4 +15,7 @@ CONFIG_LV_COLOR_16_SWAP=y
CONFIG_LV_FONT_MONTSERRAT_12=y
CONFIG_LV_FONT_MONTSERRAT_16=y
CONFIG_LV_MEM_SIZE_KILOBYTES=48
CONFIG_LV_USE_DEMO_WIDGETS=y
CONFIG_LV_USE_DEMO_WIDGETS=y
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
-3
View File
@@ -8,8 +8,5 @@ set(EXTRA_COMPONENT_DIRS
add_compile_options(-fdiagnostics-color=always)
# The following line can be removed after LVGL update to v8.3.5.
add_compile_options(-Wno-format)
project(mp3_demo)
+3 -4
View File
@@ -1,7 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.0"
chmorgan/esp-libhelix-mp3: "1.0.3"
chmorgan/esp-file-iterator: "1.0.0"
chmorgan/esp-audio-player: "1.0.4"
espressif/esp-box: "2.3.*"
chmorgan/esp-audio-player: "1.0.5"
chmorgan/esp-file-iterator: "1.0.0"
+1 -7
View File
@@ -18,13 +18,8 @@ static esp_err_t audio_mute_function(AUDIO_PLAYER_MUTE_SETTING setting)
{
// Volume saved when muting and restored when unmuting. Restoring volume is necessary
// as es8311_set_voice_mute(true) results in voice volume (REG32) being set to zero.
static uint8_t last_volume;
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
uint8_t volume = get_sys_volume();
if (volume != 0) {
last_volume = volume;
}
codec_handle->mute_set_fn(setting == AUDIO_PLAYER_MUTE ? true : false);
@@ -32,7 +27,6 @@ static esp_err_t audio_mute_function(AUDIO_PLAYER_MUTE_SETTING setting)
if (setting == AUDIO_PLAYER_UNMUTE) {
codec_handle->volume_set_fn(volume, NULL);
}
ESP_LOGI(TAG, "mute setting %d, volume:%d", setting, last_volume);
return ESP_OK;
}
@@ -50,7 +44,7 @@ void app_main(void)
bsp_spiffs_mount();
file_iterator_instance_t *file_iterator = file_iterator_new(BSP_MOUNT_POINT);
file_iterator_instance_t *file_iterator = file_iterator_new(BSP_SPIFFS_MOUNT_POINT);
assert(file_iterator != NULL);
/* Configure I2S peripheral and Power Amplifier */
+253 -90
View File
@@ -13,26 +13,45 @@
static const char *TAG = "ui_audio";
typedef struct {
lv_style_t style_bg;
lv_style_t style_focus_no_outline;
} button_style_t;
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
static lv_obj_t *g_group_list[3] = {0};
static lv_obj_t *g_focus_last_obj = NULL;
#endif
static lv_group_t *g_btn_op_group = NULL;
static file_iterator_instance_t *file_iterator;
static uint8_t g_sys_volume;
static button_style_t g_btn_styles;
#if CONFIG_ESP32_S3_BOX_LITE_BOARD
static void register_button_callback(lv_obj_t *btn_list[]);
#endif
static void btn_play_pause_cb(lv_event_t *event)
uint8_t get_sys_volume()
{
lv_obj_t *btn = (lv_obj_t *) event->target;
lv_obj_t *lab = (lv_obj_t *) btn->user_data;
return g_sys_volume;
}
audio_player_state_t state = audio_player_get_state();
if (state == AUDIO_PLAYER_STATE_PAUSE) {
lv_label_set_text_static(lab, LV_SYMBOL_PAUSE);
audio_player_resume();
} else if (state == AUDIO_PLAYER_STATE_PLAYING) {
lv_label_set_text_static(lab, LV_SYMBOL_PLAY);
audio_player_pause();
}
button_style_t *ui_button_styles(void)
{
return &g_btn_styles;
}
lv_group_t *ui_get_btn_op_group(void)
{
return g_btn_op_group;
}
static void ui_button_style_init(void)
{
/*Init the style for the default state*/
lv_style_init(&g_btn_styles.style_focus_no_outline);
lv_style_set_outline_width(&g_btn_styles.style_focus_no_outline, 0);
lv_style_init(&g_btn_styles.style_bg);
lv_style_set_bg_opa(&g_btn_styles.style_bg, LV_OPA_100);
lv_style_set_bg_color(&g_btn_styles.style_bg, lv_color_make(255, 255, 255));
lv_style_set_shadow_width(&g_btn_styles.style_bg, 0);
}
static void play_index(int index)
@@ -46,8 +65,6 @@ static void play_index(int index)
return;
}
ESP_LOGI(TAG, "opening file '%s'", filename);
FILE *fp = fopen(filename, "rb");
if (fp) {
ESP_LOGI(TAG, "Playing '%s'", filename);
@@ -57,6 +74,148 @@ static void play_index(int index)
}
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
static uint32_t music_list_get_num_offset(uint32_t focus, int32_t max, int32_t offset)
{
if (focus >= max) {
ESP_LOGI(TAG, "[ERROR] focus should less than max");
return focus;
}
uint32_t i;
if (offset >= 0) {
i = (focus + offset) % max;
} else {
offset = max + (offset % max);
i = (focus + offset) % max;
}
return i;
}
static int8_t music_list_direct_probe(lv_obj_t *focus_obj)
{
int8_t direct;
uint32_t index_max_sz, index_focus, index_prev;
index_focus = 0;
index_prev = 0;
index_max_sz = sizeof(g_group_list) / sizeof(g_group_list[0]);
for (int i = 0; i < index_max_sz; i++) {
if (focus_obj == g_group_list[i]) {
index_focus = i;
}
if (g_focus_last_obj == g_group_list[i]) {
index_prev = i;
}
}
if (NULL == g_focus_last_obj) {
direct = 0;
} else if (index_focus == music_list_get_num_offset(index_prev, index_max_sz, 1)) {
direct = 1;
} else if (index_focus == music_list_get_num_offset(index_prev, index_max_sz, -1)) {
direct = -1;
} else {
direct = 0;
}
g_focus_last_obj = focus_obj;
return direct;
}
void music_list_new_item_select(lv_obj_t *obj)
{
int8_t direct = music_list_direct_probe(obj);
int item_size = file_iterator_get_count(file_iterator);
int item_index = file_iterator_get_index(file_iterator);
item_index = music_list_get_num_offset(item_index, item_size, direct);
ESP_LOGI(TAG, "slected:[%d/%d], direct:%d", item_index, item_size, direct);
if (1 == direct) {
file_iterator_next(file_iterator);
} else if (-1 == direct) {
file_iterator_prev(file_iterator);
} else {
return;
}
audio_player_state_t state = audio_player_get_state();
if (state == AUDIO_PLAYER_STATE_IDLE) {
// nothing to do, changing songs while not playing
// doesn't start or stop playback
ESP_LOGI(TAG, "idle, nothing to do");
} else if (state == AUDIO_PLAYER_STATE_PLAYING) {
int index = file_iterator_get_index(file_iterator);
play_index(index);
}
}
static void music_list_prev_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_user_data(e);
if (LV_EVENT_FOCUSED == code) {
music_list_new_item_select(obj);
} else if (LV_EVENT_CLICKED == code) {
lv_event_send(g_group_list[1], LV_EVENT_CLICKED, g_group_list[1]);
}
}
static void music_list_next_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_user_data(e);
if (LV_EVENT_FOCUSED == code) {
music_list_new_item_select(obj);
} else if (LV_EVENT_CLICKED == code) {
lv_event_send(g_group_list[1], LV_EVENT_CLICKED, g_group_list[1]);
}
}
static void music_play_pause_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = lv_event_get_user_data(e);
if (LV_EVENT_FOCUSED == code) {
ESP_LOGI(TAG, "##play focus, %02X,%02X,%02X", g_group_list[0]->state, g_group_list[1]->state, g_group_list[2]->state);
music_list_new_item_select(obj);
} else if (LV_EVENT_CLICKED == code) {
ESP_LOGI(TAG, "##play click, %02X,%02X,%02X", g_group_list[0]->state, g_group_list[1]->state, g_group_list[2]->state);
lv_obj_t *lab = lv_obj_get_child(obj, 0);
ESP_LOGI(TAG, "[play/pause] = %d", file_iterator_get_index(file_iterator));
audio_player_state_t state = audio_player_get_state();
if (state == AUDIO_PLAYER_STATE_PAUSE) {
lv_label_set_text_static(lab, LV_SYMBOL_PAUSE);
audio_player_resume();
} else if (state == AUDIO_PLAYER_STATE_PLAYING) {
lv_label_set_text_static(lab, LV_SYMBOL_PLAY);
audio_player_pause();
}
}
}
#else
static void btn_play_pause_cb(lv_event_t *event)
{
lv_obj_t *btn = (lv_obj_t *) event->target;
lv_obj_t *lab = (lv_obj_t *) btn->user_data;
audio_player_state_t state = audio_player_get_state();
if (state == AUDIO_PLAYER_STATE_PAUSE) {
lv_label_set_text_static(lab, LV_SYMBOL_PAUSE);
audio_player_resume();
} else if (state == AUDIO_PLAYER_STATE_PLAYING) {
lv_label_set_text_static(lab, LV_SYMBOL_PLAY);
audio_player_pause();
}
}
static void btn_prev_next_cb(lv_event_t *event)
{
bool is_next = (bool) event->user_data;
@@ -80,6 +239,7 @@ static void btn_prev_next_cb(lv_event_t *event)
play_index(index);
}
}
#endif
static void volume_slider_cb(lv_event_t *event)
{
@@ -155,16 +315,21 @@ static void music_list_cb(lv_event_t *event)
}
}
uint8_t get_sys_volume()
{
return g_sys_volume;
}
void ui_audio_start(file_iterator_instance_t *i)
{
file_iterator = i;
g_sys_volume = 80;
ui_button_style_init();
lv_indev_t *indev = lv_indev_get_next(NULL);
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
ESP_LOGI(TAG, "Input device type is encoder");
g_btn_op_group = lv_group_create();
lv_indev_set_group(indev, g_btn_op_group);
}
/* Create audio control button */
lv_obj_t *btn_play_pause = lv_btn_create(lv_scr_act());
lv_obj_align(btn_play_pause, LV_ALIGN_CENTER, 0, 40);
@@ -172,29 +337,83 @@ void ui_audio_start(file_iterator_instance_t *i)
lv_obj_set_style_radius(btn_play_pause, 25, LV_STATE_DEFAULT);
lv_obj_add_flag(btn_play_pause, LV_OBJ_FLAG_CHECKABLE);
lv_obj_add_style(btn_play_pause, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_play_pause, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_t *label_play_pause = lv_label_create(btn_play_pause);
lv_label_set_text_static(label_play_pause, LV_SYMBOL_PAUSE);
lv_obj_center(label_play_pause);
lv_obj_set_user_data(btn_play_pause, (void *) label_play_pause);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
lv_obj_add_event_cb(btn_play_pause, music_play_pause_cb, LV_EVENT_ALL, (void *) btn_play_pause);
#else
lv_obj_add_event_cb(btn_play_pause, btn_play_pause_cb, LV_EVENT_VALUE_CHANGED, NULL);
#endif
lv_obj_t *label_prev = lv_label_create(lv_scr_act());
lv_obj_set_user_data(label_prev, btn_play_pause);
lv_obj_add_flag(label_prev, LV_OBJ_FLAG_CLICKABLE);
lv_obj_t *btn_play_prev = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn_play_prev, 50, 50);
lv_obj_set_style_radius(btn_play_prev, 25, LV_STATE_DEFAULT);
lv_obj_clear_flag(btn_play_prev, LV_OBJ_FLAG_CHECKABLE);
lv_obj_align_to(btn_play_prev, btn_play_pause, LV_ALIGN_OUT_LEFT_MID, -40, 0);
lv_obj_add_style(btn_play_prev, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_play_prev, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_add_style(btn_play_prev, &ui_button_styles()->style_bg, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_play_prev, &ui_button_styles()->style_bg, LV_STATE_FOCUSED);
lv_obj_add_style(btn_play_prev, &ui_button_styles()->style_bg, LV_STATE_DEFAULT);
lv_obj_t *label_prev = lv_label_create(btn_play_prev);
lv_label_set_text_static(label_prev, LV_SYMBOL_PREV);
lv_obj_set_style_text_font(label_prev, &lv_font_montserrat_24, LV_STATE_DEFAULT);
lv_obj_set_style_text_color(label_prev, lv_color_make(255, 0, 0), LV_STATE_PRESSED);
lv_obj_align_to(label_prev, btn_play_pause, LV_ALIGN_OUT_LEFT_MID, -40, 0);
lv_obj_add_event_cb(label_prev, btn_prev_next_cb, LV_EVENT_CLICKED, (void *) false);
lv_obj_set_style_text_color(label_prev, lv_color_make(0, 0, 0), LV_STATE_DEFAULT);
lv_obj_center(label_prev);
lv_obj_set_user_data(btn_play_prev, (void *) label_prev);
lv_obj_t *label_next = lv_label_create(lv_scr_act());
lv_obj_set_user_data(label_next, btn_play_pause);
lv_obj_add_flag(label_next, LV_OBJ_FLAG_CLICKABLE);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
g_group_list[0] = btn_play_prev;
lv_obj_add_event_cb(btn_play_prev, music_list_prev_cb, LV_EVENT_ALL, (void *) btn_play_prev);
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), btn_play_prev);
}
#else
lv_obj_add_event_cb(btn_play_prev, btn_prev_next_cb, LV_EVENT_CLICKED, (void *) false);
#endif
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
g_group_list[1] = btn_play_pause;
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), btn_play_pause);
}
#endif
lv_obj_t *btn_play_next = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn_play_next, 50, 50);
lv_obj_set_style_radius(btn_play_next, 25, LV_STATE_DEFAULT);
lv_obj_clear_flag(btn_play_next, LV_OBJ_FLAG_CHECKABLE);
lv_obj_align_to(btn_play_next, btn_play_pause, LV_ALIGN_OUT_RIGHT_MID, 40, 0);
lv_obj_add_style(btn_play_next, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_play_next, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_add_style(btn_play_next, &ui_button_styles()->style_bg, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn_play_next, &ui_button_styles()->style_bg, LV_STATE_FOCUSED);
lv_obj_add_style(btn_play_next, &ui_button_styles()->style_bg, LV_STATE_DEFAULT);
lv_obj_t *label_next = lv_label_create(btn_play_next);
lv_label_set_text_static(label_next, LV_SYMBOL_NEXT);
lv_obj_set_style_text_font(label_next, &lv_font_montserrat_24, LV_STATE_DEFAULT);
lv_obj_set_style_text_color(label_next, lv_color_make(255, 0, 0), LV_STATE_PRESSED);
lv_obj_align_to(label_next, btn_play_pause, LV_ALIGN_OUT_RIGHT_MID, 40, 0);
lv_obj_add_event_cb(label_next, btn_prev_next_cb, LV_EVENT_CLICKED, (void *) true);
lv_obj_set_style_text_color(label_next, lv_color_make(0, 0, 0), LV_STATE_DEFAULT);
lv_obj_center(label_next);
lv_obj_set_user_data(btn_play_next, (void *) label_next);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
g_group_list[2] = btn_play_next;
lv_obj_add_event_cb(btn_play_next, music_list_next_cb, LV_EVENT_ALL, (void *) btn_play_next);
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), btn_play_next);
}
#else
lv_obj_add_event_cb(btn_play_next, btn_prev_next_cb, LV_EVENT_CLICKED, (void *) true);
#endif
/* Create volume slider */
lv_obj_t *volume_slider = lv_slider_create(lv_scr_act());
@@ -230,64 +449,8 @@ void ui_audio_start(file_iterator_instance_t *i)
lv_obj_add_event_cb(music_list, music_list_cb, LV_EVENT_VALUE_CHANGED, NULL);
build_file_list(music_list);
audio_player_callback_register(audio_callback, (void *) music_list);
#if CONFIG_ESP32_S3_BOX_LITE_BOARD
register_button_callback((lv_obj_t *[]) {
label_prev, label_next, btn_play_pause
});
#endif
// initiate playback
play_index(file_iterator_get_index(file_iterator));
}
#if CONFIG_ESP32_S3_BOX_LITE_BOARD
#include "bsp_btn.h"
static void prev_click_cb(void *arg)
{
button_dev_t *event = (button_dev_t *) arg;
lv_obj_t *obj = (lv_obj_t *) event->cb_user_data;
lv_event_send(obj, LV_EVENT_CLICKED, NULL);
}
static void next_click_cb(void *arg)
{
button_dev_t *event = (button_dev_t *) arg;
lv_obj_t *obj = (lv_obj_t *) event->cb_user_data;
lv_event_send(obj, LV_EVENT_CLICKED, NULL);
}
static void play_pause_click_cb(void *arg)
{
button_dev_t *event = (button_dev_t *) arg;
lv_obj_t *obj = (lv_obj_t *) event->cb_user_data;
if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
lv_obj_clear_state(obj, LV_STATE_CHECKED);
} else {
lv_obj_add_state(obj, LV_STATE_CHECKED);
}
lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
}
static void register_button_callback(lv_obj_t *btn_list[])
{
lv_obj_t *btn_prev = btn_list[0];
lv_obj_t *btn_next = btn_list[1];
lv_obj_t *btn_play_pause = btn_list[2];
bsp_btn_set_user_data(0, (void *) btn_prev);
bsp_btn_set_user_data(1, (void *) btn_play_pause);
bsp_btn_set_user_data(2, (void *) btn_next);
bsp_btn_register_callback(0, BUTTON_SINGLE_CLICK, prev_click_cb);
bsp_btn_register_callback(1, BUTTON_SINGLE_CLICK, play_pause_click_cb);
bsp_btn_register_callback(2, BUTTON_SINGLE_CLICK, next_click_cb);
}
#endif
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+4 -1
View File
@@ -34,4 +34,7 @@ CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_SPEED_80M=y
CONFIG_SPIFFS_OBJ_NAME_LEN=128
CONFIG_SPIFFS_OBJ_NAME_LEN=128
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
+2 -2
View File
@@ -5,8 +5,8 @@ cmake_minimum_required(VERSION 3.5)
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# set(EXTRA_COMPONENT_DIRS
# ../../components)
set(EXTRA_COMPONENT_DIRS
../../components)
add_compile_options(-fdiagnostics-color=always)
+1 -1
View File
@@ -3,7 +3,7 @@
| Board | Support Status |
| ----------------- | -------------- |
| ESP32-S3-BOX | YES |
| ESP32-S3-BOX-Lite | NO |
| ESP32-S3-BOX-Lite | YES |
This demo makes ESP32-S3-BOX work as a USB headset that can play music and record voice. Default uses 48k single mic and single channel audio data, and it uses FFT to display the music spectrum on the screen and supports multiple animations.
+1 -2
View File
@@ -1,7 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.0"
espressif/es7210: "^1.0.1"
#espressif/es7210: "^1.0.1"
espressif/esp-dsp: "^1.2.1"
espressif/esp-box: "2.3.*"
espressif/tinyusb: "^0.14.2"
+8 -61
View File
@@ -3,52 +3,13 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "bsp_board.h"
#include "bsp/esp-bsp.h"
#include "display.h"
#include "es7210.h"
#include "es8311.h"
#include "fft_convert.h"
#include "usb_headset.h"
#define ES7210_ADDR 0x40
#define ES7210_ADC_VOLUME 0
i2s_chan_handle_t i2s_tx_chan;
i2s_chan_handle_t i2s_rx_chan;
static es8311_handle_t es8311_dev = NULL;
static es7210_dev_handle_t es7210_handle = NULL;
static void _es8311_init()
{
/* Create and configure ES8311 I2C driver */
es8311_dev = es8311_create(BSP_I2C_NUM, ES8311_ADDRRES_0);
const es8311_clock_config_t clk_cfg = BSP_ES8311_SCLK_CONFIG(SAMPLE_RATE);
es8311_init(es8311_dev, &clk_cfg, ES8311_RESOLUTION_16, ES8311_RESOLUTION_16);
es8311_voice_volume_set(es8311_dev, DEFAULT_VOLUME, NULL);
}
static void _es7210_init()
{
const es7210_i2c_config_t es7210_cfg = {
.i2c_addr = ES7210_ADDR,
.i2c_port = BSP_I2C_NUM,
};
es7210_new_codec(&es7210_cfg, &es7210_handle);
es7210_codec_config_t codec_conf = {
.i2s_format = ES7210_I2S_FMT_I2S,
.mclk_ratio = 256,
.sample_rate_hz = SAMPLE_RATE,
.bit_width = WIDTH,
.mic_bias = ES7210_MIC_BIAS_2V87,
.mic_gain = ES7210_MIC_GAIN_30DB,
.flags.tdm_enable = false,
};
es7210_config_codec(es7210_handle, &codec_conf);
es7210_config_volume(es7210_handle, ES7210_ADC_VOLUME);
}
void app_main(void)
{
/* Initialize I2C (for touch and audio) */
@@ -57,30 +18,16 @@ void app_main(void)
/* Initialize display */
display_lcd_init();
/* Set display brightness to 100% */
bsp_display_backlight_on();
/* Init fft */
fft_convert_init();
/* Init es8311 */
_es8311_init();
bsp_board_init();
/* Init es7210 */
_es7210_init();
/* Configure I2S peripheral and Power Amplifier */
i2s_std_config_t i2s_config = {
.clk_cfg = {
.sample_rate_hz = SAMPLE_RATE,
.clk_src = I2S_CLK_SRC_DEFAULT,
.mclk_multiple = I2S_MCLK_MULTIPLE_384,
},
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t)WIDTH, (i2s_slot_mode_t)CHANNEL),
.gpio_cfg = BSP_I2S_GPIO_CFG,
};
bsp_audio_init(&i2s_config, &i2s_tx_chan, &i2s_rx_chan);
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
codec_handle->i2s_reconfig_clk_fn(SAMPLE_RATE, WIDTH, CHANNEL);
codec_handle->volume_set_fn(80, NULL);
codec_handle->mute_set_fn(false);
bsp_audio_poweramp_enable(true);
usb_headset_init();
}
+19 -80
View File
@@ -4,8 +4,10 @@
*/
#include <math.h>
#include "bsp/esp-bsp.h"
#include "bsp/display.h"
#include "display.h"
#include "driver/ledc.h"
#include "hal/spi_ll.h"
#include "driver/spi_master.h"
#include "esp_log.h"
#include "esp_lcd_panel_io.h"
@@ -15,13 +17,9 @@
static const char *TAG = "display";
/****************** LCD Configuration ************************************************/
#define LCD_LEDC_CH CONFIG_BSP_DISPLAY_BRIGHTNESS_LEDC_CH
#define LCD_WIDTH BSP_LCD_H_RES
#define LCD_HEIGHT BSP_LCD_V_RES
#define LCD_CMD_BITS 8
#define LCD_PARAM_BITS 8
#define LCD_BUFFER_SIZE 320*240*2
#define LCD_BUFFER_LINE 320*2
/****************** configure the example working mode *******************************/
#define BASIC_HIGH 40 /* Subtract the height of the column height */
@@ -49,49 +47,24 @@ static const char *TAG = "display";
#define STRIP_NUM 320 / GROUP_WIDTH
#define INTERVAL_WIDTH GROUP_WIDTH - STRIP_WIDTH
#define BDISPLAY_ERROR_CHECK_RETURN_ERR(x) do { \
esp_err_t err_rc_ = (x); \
if (unlikely(err_rc_ != ESP_OK)) { \
return err_rc_; \
} \
} while(0)
#define DISPLAY_ERROR_CHECK_RETURN_NULL(x) do { \
if (unlikely((x) != ESP_OK)) { \
return NULL; \
} \
} while(0)
#ifndef SPI_LL_DATA_MAX_BIT_LEN
#define SPI_LL_DATA_MAX_BIT_LEN (1 << 18)
#define LCD_SPI_MAX_DATA_SIZE (SPI_LL_DATA_MAX_BIT_LEN / 8)
#else
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
#define LCD_SPI_MAX_DATA_SIZE (SPI_LL_DATA_MAX_BIT_LEN / 8)
#else
/**
* @brief release5.0 align = 4092(4096 -4)
*/
#define LCD_SPI_MAX_DATA_SIZE ((SPI_LL_DATA_MAX_BIT_LEN / 8)/4092*4092)
#endif
#endif
static esp_lcd_panel_handle_t panel_handle = NULL;
static int16_t fre_point[STRIP_NUM] = {0};
static uint16_t *display_buffer = NULL;
static esp_err_t display_brightness_init(void)
{
// Setup LEDC peripheral for PWM backlight control
const ledc_channel_config_t LCD_backlight_channel = {
.gpio_num = BSP_LCD_BACKLIGHT,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LCD_LEDC_CH,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = 1,
.duty = 0,
.hpoint = 0
};
const ledc_timer_config_t LCD_backlight_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_10_BIT,
.timer_num = 1,
.freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK
};
BDISPLAY_ERROR_CHECK_RETURN_ERR(ledc_timer_config(&LCD_backlight_timer));
BDISPLAY_ERROR_CHECK_RETURN_ERR(ledc_channel_config(&LCD_backlight_channel));
return ESP_OK;
}
typedef struct {
float speed[STRIP_NUM];
int16_t square_high[STRIP_NUM];
@@ -222,48 +195,14 @@ esp_err_t display_draw(float *data)
esp_err_t display_lcd_init(void)
{
display_brightness_init();
ESP_LOGD(TAG, "Initialize SPI bus");
const spi_bus_config_t buscfg = {
.sclk_io_num = BSP_LCD_PCLK,
.mosi_io_num = BSP_LCD_DATA0,
.miso_io_num = GPIO_NUM_NC,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.max_transfer_sz = BSP_LCD_H_RES * BSP_LCD_V_RES * sizeof(uint16_t),
};
BDISPLAY_ERROR_CHECK_RETURN_ERR(spi_bus_initialize(BSP_LCD_SPI_NUM, &buscfg, SPI_DMA_CH_AUTO));
ESP_LOGD(TAG, "Install panel IO");
esp_lcd_panel_io_handle_t io_handle = NULL;
const esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = BSP_LCD_DC,
.cs_gpio_num = BSP_LCD_CS,
.pclk_hz = BSP_LCD_PIXEL_CLOCK_HZ,
.lcd_cmd_bits = LCD_CMD_BITS,
.lcd_param_bits = LCD_PARAM_BITS,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = NULL,
.user_ctx = NULL,
const bsp_display_config_t bsp_disp_cfg = {
.max_transfer_sz = (LCD_SPI_MAX_DATA_SIZE),
};
bsp_display_new(&bsp_disp_cfg, &panel_handle, &io_handle);
// Attach the LCD to the SPI bus
BDISPLAY_ERROR_CHECK_RETURN_ERR(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)BSP_LCD_SPI_NUM, &io_config, &io_handle));
ESP_LOGD(TAG, "Install LCD driver of st7789");
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = BSP_LCD_RST, // Shared with Touch reset
.color_space = ESP_LCD_COLOR_SPACE_BGR,
.bits_per_pixel = 16,
};
BDISPLAY_ERROR_CHECK_RETURN_ERR(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
esp_lcd_panel_reset(panel_handle);
esp_lcd_panel_init(panel_handle);
esp_lcd_panel_mirror(panel_handle, true, true);
esp_lcd_panel_disp_on_off(panel_handle, true);
bsp_display_backlight_on();
for (int i = 0; i < STRIP_NUM; i++) {
display_square.square_high[i] = 1;
+6 -5
View File
@@ -3,7 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "bsp_board.h"
#include "bsp/esp-bsp.h"
#include "esp_private/usb_phy.h"
#include "fft_convert.h"
#include "tusb.h"
@@ -21,9 +23,6 @@ const uint32_t sample_rates[] = {44100, 48000, 88200, 96000};
uint32_t current_sample_rate = 48000;
extern i2s_chan_handle_t i2s_tx_chan;
extern i2s_chan_handle_t i2s_rx_chan;
#define N_SAMPLE_RATES TU_ARRAY_SIZE(sample_rates)
#define AUDIO_LENGTH 96
@@ -353,7 +352,8 @@ bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_bytes_received, u
size_t bytes_written = 0;
esp_err_t ret = i2s_channel_write(i2s_tx_chan, &spk_buf, spk_data_size, &bytes_written, 0);
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
esp_err_t ret = codec_handle->i2s_write_fn(&spk_buf, spk_data_size, &bytes_written, 0);
for (int i = 0; i < AUDIO_LENGTH ; i += 2) {
rb_write(spk_buf + i, 2);
@@ -384,7 +384,8 @@ bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uin
/*** Here to fill audio buffer, only use in audio transmission begin ***/
size_t bytes_read = 0;
esp_err_t ret = i2s_channel_read(i2s_rx_chan, &mic_buf, AUDIO_LENGTH * 2, &bytes_read, 0);
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
esp_err_t ret = codec_handle->i2s_read_fn(&mic_buf, AUDIO_LENGTH * 2, &bytes_read, 0);
for (int i = 0; i < AUDIO_LENGTH / 2 ; i++) {
mic_buf[i + 1] = mic_buf[2 * (i + 1)];
}
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+5 -1
View File
@@ -6,6 +6,7 @@ CONFIG_IDF_TARGET="esp32s3"
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=240
# CONFIG_BSP_TOUCH_BUTTON is not set
#
# LVGL
@@ -38,4 +39,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
#
CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB=y
CONFIG_ESP32S3_DATA_CACHE_64KB=y
CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y
CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
+1 -1
View File
@@ -56,7 +56,7 @@ The following photo shows the connection of the modules. For detailed connection
| ESP-BOX GPIO |Sensor | Relay | Description of GPIO Pin Functionality |
|--------------|-----------|-----------|---------------------------------------|
|GPIO9 |AUOT |- | Acquire ADC channel |
|GPIO11 |AUOT |- | Acquire ADC channel |
|GPIO41 |- |IN1 | Relay control |
## Build Project
+87 -30
View File
@@ -3,33 +3,109 @@
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdbool.h>
#include <stdio.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_vfs.h"
#include "esp_heap_caps.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "bsp_board.h"
#include "bsp/esp-bsp.h"
typedef struct {
// The "RIFF" chunk descriptor
uint8_t ChunkID[4];// Indicates the file as "RIFF" file
int32_t ChunkSize;// The total size of the entire file, excluding the "RIFF" and the header itself, which is the file size minus 8 bytes.
uint8_t Format[4];// File format header indicating a "WAVE" file.
// The "fmt" sub-chunk
uint8_t Subchunk1ID[4];// Format identifier for the "fmt" sub-chunk.
int32_t Subchunk1Size;// The length of the fmt sub-chunk (subchunk1) excluding the Subchunk1 ID and Subchunk1 Size fields. It is typically 16, but a value greater than 16 indicates the presence of an extended area. Optional values for the length include 16, 18, 20, 40, etc.
int16_t AudioFormat;// Audio encoding format, which represents the compression format. A value of 0x01 indicates PCM format, which is uncompressed. Please refer to table 3 for more details.
int16_t NumChannels;// Number of audio channels
int32_t SampleRate;// Sample rate, for example, "44100" represents a sampling rate of 44100 Hz.
int32_t ByteRate;// Bit rate: Sample rate x bit depth x number of channels / 8. For example, the bit rate for a stereo (2 channels) audio with a sample rate of 44.1 kHz and 16-bit depth would be 176400 bits per second.
int16_t BlockAlign;// Memory size occupied by one sample: Bit depth x number of channels / 8.
int16_t BitsPerSample;//Sample depth, also known as bit depth.
// The "data" sub-chunk
uint8_t Subchunk2ID[4];// Total length of the audio data, which is the file size minus the length of the WAV file header.
int32_t Subchunk2Size;// Length of the data section, referring to the size of the audio data excluding the header.
} wav_header_t;
static const char *TAG = "app_audio";
static bool b_audio_playing = false;
static SemaphoreHandle_t audio_sem = NULL;
esp_err_t sr_echo_play(void *filepath)
{
FILE *fp = NULL;
struct stat file_stat;
esp_err_t ret = ESP_OK;
const size_t chunk_size = 4096;
uint8_t *buffer = malloc(chunk_size);
ESP_GOTO_ON_FALSE(NULL != buffer, ESP_FAIL, EXIT, TAG, "buffer malloc failed");
ESP_GOTO_ON_FALSE(-1 != stat(filepath, &file_stat), ESP_FAIL, EXIT, TAG, "Failed to stat file");
fp = fopen(filepath, "r");
ESP_GOTO_ON_FALSE(NULL != fp, ESP_FAIL, EXIT, TAG, "Failed create record file");
wav_header_t wav_head;
int len = fread(&wav_head, 1, sizeof(wav_header_t), fp);
ESP_GOTO_ON_FALSE(len > 0, ESP_FAIL, EXIT, TAG, "Read wav header failed");
if (NULL == strstr((char *)wav_head.Subchunk1ID, "fmt") &&
NULL == strstr((char *)wav_head.Subchunk2ID, "data")) {
ESP_LOGI(TAG, "PCM format");
fseek(fp, 0, SEEK_SET);
wav_head.SampleRate = 16000;
wav_head.NumChannels = 2;
wav_head.BitsPerSample = 16;
}
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
ESP_LOGE(TAG, "frame_rate= %" PRIi32 ", ch=%d, width=%d", wav_head.SampleRate, wav_head.NumChannels, wav_head.BitsPerSample);
codec_handle->i2s_reconfig_clk_fn(wav_head.SampleRate, wav_head.BitsPerSample, I2S_SLOT_MODE_STEREO);
vTaskDelay(pdMS_TO_TICKS(500));
codec_handle->mute_set_fn(false);
codec_handle->volume_set_fn(85, NULL);
size_t cnt, total_cnt = 0;
do {
/* Read file in chunks into the scratch buffer */
len = fread(buffer, 1, chunk_size, fp);
if (len <= 0) {
break;
} else if (len > 0) {
codec_handle->i2s_write_fn(buffer, len, &cnt, portMAX_DELAY);
total_cnt += cnt;
}
} while (1);
ESP_LOGI(TAG, "play end, %d K", total_cnt / 1024);
EXIT:
if (fp) {
fclose(fp);
}
if (buffer) {
free(buffer);
}
return ret;
}
static void audio_beep_task(void *pvParam)
{
void *audio_buffer = pvParam;
size_t bytes_written = 0;
size_t bytes_to_write = heap_caps_get_allocated_size(audio_buffer);
bsp_codec_config_t *codec_handle = bsp_board_get_codec_handle();
bsp_audio_poweramp_enable(true);
while (true) {
xSemaphoreTake(audio_sem, portMAX_DELAY);
b_audio_playing = true;
codec_handle->i2s_write_fn((char *)audio_buffer, bytes_to_write, &bytes_written, portMAX_DELAY);
sr_echo_play("/spiffs/echo_en_wake.wav");
b_audio_playing = false;
/* It's useful if wake audio didn't finish playing when next wake word detetced */
@@ -39,25 +115,6 @@ static void audio_beep_task(void *pvParam)
esp_err_t app_audio_beep_init(void)
{
FILE *fp = fopen("/spiffs/wake.pcm", "rb");
if (NULL == fp) {
ESP_LOGE(TAG, "Audio file does't exist");
return ESP_ERR_NOT_FOUND;
}
fseek(fp, 0, SEEK_END);
size_t file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
void *audio_buffer = heap_caps_malloc(file_size, MALLOC_CAP_SPIRAM);
if (NULL == audio_buffer) {
ESP_LOGE(TAG, "No mem for audio buffer");
return ESP_ERR_NO_MEM;
}
fread(audio_buffer, 1, file_size, fp);
fclose(fp);
audio_sem = xSemaphoreCreateBinary();
if (NULL == audio_sem) {
ESP_LOGE(TAG, "Failed create audio semaphore");
@@ -67,9 +124,9 @@ esp_err_t app_audio_beep_init(void)
BaseType_t ret_val = xTaskCreatePinnedToCore(
(TaskFunction_t) audio_beep_task,
(const char *const) "beep Task",
(const uint32_t) 2 * 1024,
(void *const) audio_buffer,
(UBaseType_t) 1,
(const uint32_t) 4 * 1024,
NULL,
(UBaseType_t) 5,
(TaskHandle_t *const) NULL,
(const BaseType_t) 0);
if (pdPASS != ret_val) {
@@ -84,7 +84,7 @@ static esp_err_t adc_calibration_init(app_humidity_t *ref)
if (!calibrated) {
ESP_LOGI(TAG, "calibration scheme version is %s", "Curve Fitting");
adc_cali_curve_fitting_config_t cali_config = {
.unit_id = ADC_UNIT_1,
.unit_id = ADC_UNIT_2,
.atten = ref->adc_atten,
.bitwidth = ref->adc_width,
};
@@ -127,15 +127,15 @@ static esp_err_t app_humidity_drive_init(app_humidity_t *ref)
{
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
if (NULL == ref->adc1_handle) {
//ADC1 Init
//ADC2 Init
adc_oneshot_unit_init_cfg_t init_config = {
.unit_id = ADC_UNIT_1,
.unit_id = ADC_UNIT_2,
};
if (adc_oneshot_new_unit(&init_config, &ref->adc1_handle) != ESP_OK) {
ESP_LOGW(TAG, "adc oneshot new unit fail!");
}
//ADC1 Config
//ADC2 Config
adc_oneshot_chan_cfg_t oneshot_config = {
.bitwidth = ref->adc_width,
.atten = ref->adc_atten,
@@ -143,9 +143,9 @@ static esp_err_t app_humidity_drive_init(app_humidity_t *ref)
if (adc_oneshot_config_channel(ref->adc1_handle, ref->adc_channel, &oneshot_config) != ESP_OK) {
ESP_LOGW(TAG, "adc oneshot config channel fail!");
}
//-------------ADC1 Calibration Init---------------//
//-------------ADC2 Calibration Init---------------//
if (adc_calibration_init(ref) != ESP_OK) {
ESP_LOGW(TAG, "ADC1 Calibration Init False");
ESP_LOGW(TAG, "ADC2 Calibration Init False");
}
}
#else
@@ -230,11 +230,11 @@ static void humidity_task(void *pvParam)
app_humidity_t *ref = pvParam;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
ref->adc_channel = ADC_CHANNEL_8;
ref->adc_channel = ADC_CHANNEL_0;
ref->adc_atten = ADC_ATTEN_DB_11;//for box s3
ref->adc_width = SOC_ADC_RTC_MAX_BITWIDTH;
#else
ref->adc_channel = ADC1_CHANNEL_8;
ref->adc_channel = ADC2_CHANNEL_0;
ref->adc_atten = ADC_ATTEN_DB_11;//for box s3
ref->adc_width = ADC_WIDTH_BIT_DEFAULT;
ref->adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
+22 -7
View File
@@ -41,6 +41,13 @@ static srmodel_list_t *models = NULL;
static FILE *fp = NULL;
static bool b_record_en = false;
const char *cmd_phoneme[4] = {
"ting zhi jiao hua",
"ting zhi jiao shui",
"kai shi jiao hua",
"kai shi jiao shui"
};
static void audio_feed_task(void *pvParam)
{
size_t bytes_read = 0;
@@ -97,7 +104,7 @@ static void audio_detect_task(void *pvParam)
afe_fetch_result_t *res = afe_handle->fetch(afe_data);
if (!res || res->ret_value == ESP_FAIL) {
ESP_LOGE(TAG, "fetch error!");
//break;
continue;
}
if (res->wakeup_state == WAKENET_DETECTED) {
@@ -170,7 +177,6 @@ static void audio_detect_task(void *pvParam)
}
continue;
}
ESP_LOGE(TAG, "Exception unhandled");
}
}
@@ -215,20 +221,29 @@ esp_err_t app_sr_start(bool record_en)
afe_handle = &ESP_AFE_SR_HANDLE;
afe_config_t afe_config = AFE_CONFIG_DEFAULT();
afe_config.wakenet_model_name = esp_srmodel_filter(models, ESP_WN_PREFIX, NULL);
afe_config.aec_init = false;
// afe_config.vad_init = false;
ESP_LOGI(TAG, "load wakenet:%s", afe_config.wakenet_model_name);
esp_afe_sr_data_t *afe_data = afe_handle->create_from_config(&afe_config);
ESP_LOGI(TAG, "load wakenet:%s", afe_config.wakenet_model_name);
char *mn_name = esp_srmodel_filter(models, ESP_MN_PREFIX, NULL);
multinet = esp_mn_handle_from_name(mn_name);
ESP_LOGI(TAG, "load multinet:%s", mn_name);
model_data = multinet->create(mn_name, 5760);
ESP_LOGI(TAG, "load multinet:%s", mn_name);
esp_mn_commands_update_from_sdkconfig(multinet, model_data);
// esp_mn_commands_update_from_sdkconfig(multinet, model_data);
BaseType_t ret_val = xTaskCreatePinnedToCore(audio_feed_task, "Feed Task", 4 * 1024, afe_data, 5, NULL, 1);
esp_mn_commands_clear();
for (int i = 0; i < sizeof(cmd_phoneme) / sizeof(cmd_phoneme[0]); i++) {
esp_mn_commands_add(i, (char *)cmd_phoneme[i]);
}
esp_mn_commands_update();
esp_mn_commands_print();
multinet->print_active_speech_commands(model_data);
BaseType_t ret_val = xTaskCreatePinnedToCore(audio_feed_task, "Feed Task", 4 * 1024, afe_data, 5, NULL, 0);
ESP_RETURN_ON_FALSE(pdPASS == ret_val, ESP_FAIL, TAG, "Failed create audio feed task");
ret_val = xTaskCreatePinnedToCore(audio_detect_task, "Detect Task", 6 * 1024, afe_data, 5, NULL, 1);
@@ -38,8 +38,8 @@ void sr_handler_task(void *pvParam)
if (WAKENET_DETECTED == result.wakenet_mode) {
sr_anim_start();
app_audio_beep_play_start();
sr_anim_set_text("Say command");
app_audio_beep_play_start();
continue;
}
@@ -58,7 +58,6 @@ void sr_handler_task(void *pvParam)
default:
break;
}
/* **************** REGISTER COMMAND CALLBACK HERE **************** */
}
}
+53 -2
View File
@@ -9,7 +9,6 @@
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_check.h"
#include "bsp_board.h"
#include "lvgl.h"
#include "app_wifi.h"
#include "nvs_flash.h"
@@ -22,6 +21,9 @@
#include "ui_net_config.h"
#include "ui_boot_animate.h"
#include "bsp_board.h"
#include "bsp/esp-bsp.h"
static const char *TAG = "ui_main";
LV_FONT_DECLARE(font_en_16)
@@ -41,6 +43,40 @@ static lv_obj_t *g_status_bar = NULL;
static void ui_arc_animation_ctrl(int start);
static void ui_button_style_init(void)
{
/*Init the style for the default state*/
lv_style_init(&g_btn_styles.style);
lv_style_set_radius(&g_btn_styles.style, 5);
lv_style_set_bg_color(&g_btn_styles.style, lv_color_make(255, 255, 255));
lv_style_set_border_opa(&g_btn_styles.style, LV_OPA_30);
lv_style_set_border_width(&g_btn_styles.style, 2);
lv_style_set_border_color(&g_btn_styles.style, lv_palette_main(LV_PALETTE_GREY));
lv_style_set_shadow_width(&g_btn_styles.style, 7);
lv_style_set_shadow_color(&g_btn_styles.style, lv_color_make(0, 0, 0));
lv_style_set_shadow_ofs_x(&g_btn_styles.style, 0);
lv_style_set_shadow_ofs_y(&g_btn_styles.style, 0);
/*Init the pressed style*/
lv_style_init(&g_btn_styles.style_pr);
lv_style_set_border_opa(&g_btn_styles.style_pr, LV_OPA_40);
lv_style_set_border_width(&g_btn_styles.style_pr, 2);
lv_style_set_border_color(&g_btn_styles.style_pr, lv_palette_main(LV_PALETTE_GREY));
lv_style_init(&g_btn_styles.style_focus);
lv_style_set_outline_color(&g_btn_styles.style_focus, lv_color_make(255, 0, 0));
lv_style_init(&g_btn_styles.style_focus_no_outline);
lv_style_set_outline_width(&g_btn_styles.style_focus_no_outline, 0);
}
button_style_t *ui_button_styles(void)
{
return &g_btn_styles;
@@ -183,6 +219,8 @@ static void ui_watering_btn(lv_obj_t *parent)
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_border_width(obj, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_width(obj, 0, LV_PART_MAIN);
lv_obj_add_style(obj, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(obj, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_align(obj, LV_ALIGN_RIGHT_MID, 0, 0);
g_btn_item = lv_btn_create(obj);
@@ -190,6 +228,8 @@ static void ui_watering_btn(lv_obj_t *parent)
lv_obj_set_size(btn, 120, 120);
lv_obj_set_style_border_width(btn, 0, LV_PART_MAIN);
lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN);
lv_obj_add_style(btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUS_KEY);
lv_obj_add_style(btn, &ui_button_styles()->style_focus_no_outline, LV_STATE_FOCUSED);
lv_obj_center(btn);
lv_obj_set_style_radius(btn, LV_STYLE_RADIUS, LV_STATE_DEFAULT);
@@ -202,6 +242,11 @@ static void ui_watering_btn(lv_obj_t *parent)
lv_obj_add_event_cb(btn, btn_watering_handler, LV_EVENT_RELEASED, label_btn);
lv_obj_add_event_cb(btn, btn_watering_handler, LV_EVENT_VALUE_CHANGED, label_btn);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
if (ui_get_btn_op_group()) {
lv_group_add_obj(ui_get_btn_op_group(), btn);
}
#endif
app_pump_add_cb_before_watering(ui_main_watering_before, NULL);
app_pump_add_cb_during_watering(ui_main_watering_during, NULL);
app_pump_add_cb_after_watering(ui_main_watering_after, NULL);
@@ -315,11 +360,15 @@ static void ui_after_boot(void)
void ui_main(void)
{
bsp_display_lock(0);
ui_button_style_init();
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(237, 238, 239), LV_STATE_DEFAULT);
lv_indev_t *indev = lv_indev_get_next(NULL);
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) {
if ((lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) || \
lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
ESP_LOGI(TAG, "Input device type is keypad");
g_btn_op_group = lv_group_create();
lv_indev_set_group(indev, g_btn_op_group);
@@ -355,4 +404,6 @@ void ui_main(void)
ui_sr_anim_init();
boot_animate_start(ui_after_boot);
bsp_display_unlock();
}
@@ -1,6 +1,7 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=5.0"
espressif/esp_rainmaker:
path: components/esp_rainmaker
git: https://github.com/espressif/esp-rainmaker.git
@@ -9,13 +10,8 @@ dependencies:
path: components/esp_schedule
git: https://github.com/espressif/esp-rainmaker.git
version: "cc861bffc818c607e799f66c79923fd4e2d00447"
espressif/rmaker_common:
path: ./
git: https://github.com/espressif/esp-rainmaker-common.git
version: "b5c21128fb9b37316cb38c8edf2facb63013cc74"
#espressif/rmaker_common: "1.3.0"
espressif/esp-sr: "1.1.0"
espressif/rmaker_common: "1.4.2"
espressif/esp-sr: "1.3.3"
espressif/json_generator: ^1
espressif/json_parser: =1.0.0
espressif/qrcode: ^0.1.0
espressif/esp-box: "2.3.*"
+5 -2
View File
@@ -13,13 +13,16 @@
#include "esp_log.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "bsp_board.h"
#include "bsp_storage.h"
#include "app_audio.h"
#include "app_sr.h"
#include "app_pump.h"
#include "app_humidity.h"
#include "app_rmaker.h"
#include "bsp_board.h"
#include "bsp/esp-bsp.h"
#include "lvgl.h"
#include "gui/ui_main.h"
static const char *TAG = "main";
@@ -299,23 +299,10 @@ static void wifi_credential_reset(void *handle, void *arg)
esp_rmaker_factory_reset(0, 2);
}
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
static void esp_watering_btn_click(void *handle, void *arg)
{
if (app_pump_is_watering()) {
app_pump_watering_stop();
} else {
app_pump_watering_start();
}
}
#endif
esp_err_t app_watering_rmaker_start(void)
{
bsp_btn_register_callback(BOARD_BTN_ID_BOOT, BUTTON_LONG_PRESS_START, wifi_credential_reset, NULL);
#if CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite
bsp_btn_register_callback(BOARD_BTN_ID_ENTER, BUTTON_SINGLE_CLICK, esp_watering_btn_click, NULL);
#endif
BaseType_t ret_val = xTaskCreatePinnedToCore(rmaker_task, "RMaker Task", 6 * 1024, NULL, 1, NULL, 0);
ESP_ERROR_CHECK_WITHOUT_ABORT((pdPASS == ret_val) ? ESP_OK : ESP_FAIL);
return ESP_OK;
+1
View File
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX=y
@@ -0,0 +1 @@
CONFIG_BSP_BOARD_ESP32_S3_BOX_Lite=y
+10 -4
View File
@@ -4,10 +4,10 @@ CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_DETECT is not set
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_SR_MN_CN_MULTINET5_RECOGNITION_QUANT8=y
CONFIG_CN_SPEECH_COMMAND_ID0="ting zhi jiao hua"
CONFIG_CN_SPEECH_COMMAND_ID1="ting zhi jiao shui"
CONFIG_CN_SPEECH_COMMAND_ID2="kai shi jiao hua"
CONFIG_CN_SPEECH_COMMAND_ID3="kai shi jiao shui"
CONFIG_CN_SPEECH_COMMAND_ID0=""
CONFIG_CN_SPEECH_COMMAND_ID1=""
CONFIG_CN_SPEECH_COMMAND_ID2=""
CONFIG_CN_SPEECH_COMMAND_ID3=""
CONFIG_CN_SPEECH_COMMAND_ID4=""
CONFIG_CN_SPEECH_COMMAND_ID5=""
CONFIG_CN_SPEECH_COMMAND_ID6=""
@@ -77,3 +77,9 @@ CONFIG_BUTTON_SHORT_PRESS_TIME_MS=100
CONFIG_BUTTON_LONG_PRESS_TIME_MS=500
CONFIG_ADC_BUTTON_MAX_BUTTON_PER_CHANNEL=4
CONFIG_IO_GLITCH_FILTER_TIME_MS=20
# BSP
CONFIG_BSP_LCD_DRAW_BUF_HEIGHT=10
# rainmaker
CONFIG_ESP_RMAKER_ASSISTED_CLAIM=y