Skip to content

update compontent button to v4.1.2 #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ add_compile_options(-Wno-missing-field-initializers)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(xiaozhi)

# 项目根目录的 CMakeLists.txt
set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "项目根目录: ${PROJECT_ROOT_DIR}")


# 添加 ESP-IDF 组件路径
set(EXTRA_COMPONENT_DIRS ${CMAKE_SOURCE_DIR}/components)
list(APPEND EXTRA_COMPONENT_DIRS ${CMAKE_SOURCE_DIR}/managed_components)
45 changes: 45 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ elseif(CONFIG_BOARD_TYPE_DOIT_S3_AIBOX)
set(BOARD_TYPE "doit-s3-aibox")
elseif(CONFIG_BOARD_TYPE_ESP32_CGC)
set(BOARD_TYPE "esp32-cgc")
elseif(CONFIG_BOARD_TYPE_Freenove_Media_Kit)
set(BOARD_TYPE "freenove-media-kit")
endif()
file(GLOB BOARD_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc
Expand Down Expand Up @@ -214,3 +216,46 @@ add_custom_command(
add_custom_target(lang_header ALL
DEPENDS ${LANG_HEADER}
)



message(STATUS "PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
message(STATUS "IDF_PATH: ${IDF_PATH}")
message(STATUS "PROJECT_NAME: ${PROJECT_NAME}")

# main/CMakeLists.txt

# 定义按钮组件的路径
set(BUTTON_COMPONENT_DIR "${CMAKE_SOURCE_DIR}/managed_components/espressif__button")

# 检查组件是否存在
if(NOT EXISTS "${BUTTON_COMPONENT_DIR}/idf_component.yml")
message(FATAL_ERROR "Button component missing! Path: ${BUTTON_COMPONENT_DIR}")
endif()

# 读取版本信息
file(READ "${BUTTON_COMPONENT_DIR}/idf_component.yml" BUTTON_YML_CONTENT)
string(REGEX MATCH "version:[ \t]*v?([0-9]+\\.[0-9]+\\.[0-9]+)"
BUTTON_VERSION_MATCH "${BUTTON_YML_CONTENT}")

if(BUTTON_VERSION_MATCH)
set(BUTTON_VERSION "${CMAKE_MATCH_1}") # 提取 4.1.2
string(REPLACE "." ";" BUTTON_VERSION_LIST "${BUTTON_VERSION}")
list(GET BUTTON_VERSION_LIST 0 BUTTON_VERSION_MAJOR)
list(GET BUTTON_VERSION_LIST 1 BUTTON_VERSION_MINOR)
list(GET BUTTON_VERSION_LIST 2 BUTTON_VERSION_PATCH)

# 传递宏到代码
target_compile_definitions(${COMPONENT_LIB} PUBLIC
BUTTON_VERSION_MAJOR=${BUTTON_VERSION_MAJOR}
BUTTON_VERSION_MINOR=${BUTTON_VERSION_MINOR}
BUTTON_VERSION_PATCH=${BUTTON_VERSION_PATCH}
BUTTON_VERSION_STR="\"v${BUTTON_VERSION}\""
)
message(STATUS "Button 组件版本: v${BUTTON_VERSION}")
else()
message(WARNING "Button 组件版本解析失败!")
endif()


2 changes: 2 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ choice BOARD_TYPE
bool "无名科技星智1.54(ML307)"
config BOARD_TYPE_SENSECAP_WATCHER
bool "SenseCAP Watcher"
config BOARD_TYPE_Freenove_Media_Kit
bool "Freenove Media Kit for ESP32-S3"
config BOARD_TYPE_DOIT_S3_AIBOX
bool "四博智联AI陪伴盒子"
endchoice
Expand Down
107 changes: 107 additions & 0 deletions main/boards/common/button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <esp_log.h>

static const char* TAG = "Button";
#if BUTTON_VERSION_MAJOR == 3
#if CONFIG_SOC_ADC_SUPPORTED
Button::Button(const button_adc_config_t& adc_cfg) {
button_config_t button_config = {
Expand Down Expand Up @@ -109,3 +110,109 @@ void Button::OnDoubleClick(std::function<void()> callback) {
}
}, this);
}

#elif BUTTON_VERSION_MAJOR >= 4

#if CONFIG_SOC_ADC_SUPPORTED
Button::Button(const button_adc_config_t& adc_cfg) {
button_config_t button_config = {
.long_press_time = 1000,
.short_press_time = 50,
};
esp_err_t err = iot_button_new_adc_device(&button_config, &adc_cfg, &button_handle_);
if (err != ESP_OK) {
ESP_LOGE(TAG, "ADC Button create failed");
return;
}
}
#endif
Button::Button(gpio_num_t gpio_num, bool active_high) : gpio_num_(gpio_num) {
if (gpio_num == GPIO_NUM_NC) {
return;
}
button_gpio_config_t btn_gpio_cfg = {
.gpio_num = gpio_num,
.active_level = static_cast<uint8_t>(active_high ? 1 : 0)
};
button_config_t button_config = {
.long_press_time = 1000,
.short_press_time = 50,
};
esp_err_t ret = iot_button_new_gpio_device(&button_config, &btn_gpio_cfg, &button_handle_);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "GPIO Button create failed");
return;
}
}

Button::~Button() {
if (button_handle_ != NULL) {
iot_button_delete(button_handle_);
}
}

void Button::OnPressDown(std::function<void()> callback) {
if (button_handle_ == nullptr) {
return;
}
on_press_down_ = callback;
iot_button_register_cb(button_handle_, BUTTON_PRESS_DOWN, NULL, [](void* handle, void* usr_data) {
Button* button = static_cast<Button*>(usr_data);
if (button->on_press_down_) {
button->on_press_down_();
}
}, this);
}

void Button::OnPressUp(std::function<void()> callback) {
if (button_handle_ == nullptr) {
return;
}
on_press_up_ = callback;
iot_button_register_cb(button_handle_, BUTTON_PRESS_UP, NULL, [](void* handle, void* usr_data) {
Button* button = static_cast<Button*>(usr_data);
if (button->on_press_up_) {
button->on_press_up_();
}
}, this);
}

void Button::OnLongPress(std::function<void()> callback) {
if (button_handle_ == nullptr) {
return;
}
on_long_press_ = callback;
iot_button_register_cb(button_handle_, BUTTON_LONG_PRESS_START, NULL, [](void* handle, void* usr_data) {
Button* button = static_cast<Button*>(usr_data);
if (button->on_long_press_) {
button->on_long_press_();
}
}, this);
}

void Button::OnClick(std::function<void()> callback) {
if (button_handle_ == nullptr) {
return;
}
on_click_ = callback;
iot_button_register_cb(button_handle_, BUTTON_SINGLE_CLICK, NULL, [](void* handle, void* usr_data) {
Button* button = static_cast<Button*>(usr_data);
if (button->on_click_) {
button->on_click_();
}
}, this);
}

void Button::OnDoubleClick(std::function<void()> callback) {
if (button_handle_ == nullptr) {
return;
}
on_double_click_ = callback;
iot_button_register_cb(button_handle_, BUTTON_DOUBLE_CLICK, NULL, [](void* handle, void* usr_data) {
Button* button = static_cast<Button*>(usr_data);
if (button->on_double_click_) {
button->on_double_click_();
}
}, this);
}
#endif
2 changes: 2 additions & 0 deletions main/boards/common/button.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef BUTTON_H_
#define BUTTON_H_

#include <button_adc.h>
#include <button_gpio.h>
#include <driver/gpio.h>
#include <iot_button.h>
#include <functional>
Expand Down
59 changes: 59 additions & 0 deletions main/boards/freenove-media-kit/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Freenove Media Kit for ESP32-S3

> 一基于ESP32-S3的多媒体开发设备

<img src="./_static/ReadMe/media-kit-mini-top.jpg" alt="media-kit-mini-top" width='30%' />

<img src="./_static/ReadMe/media-kit-mini-sideview.jpg" alt="media-kit-mini-sideview" width='30%'/>

Freenove Media Kit 是一个传统的多媒体设备,用于ESP32-S3的开发学习。具有以下外设:

- 摄像头

- TF卡槽

- WS2812B彩灯

- I2S接口的硅麦

- I2S接口的音频解码器+功放

- 4Ω 1W扬声器

- 3.5mm耳机插座

- PH2.0接口的3.7V锂电池插座,带有充电功能

- 1.14英寸TFT屏幕

- 采用ADC输入的五向按键。



目前基础示例:

- Sketch_01_LedPixel_RGBW
- Sketch_02_1_Button_Value
- Sketch_02_2_Button
- Sketch_03_SDMMC_Test
- Sketch_04_Simple_Tone
- Sketch_05_Play_MP3
- Sketch_06_Video_Web_Server
- Sketch_07_TFT_Clock
- Sketch_08_1_Camera_TFT_Show
- Sketch_08_2_Take_A_Photo
- Sketch_09_1_Record_To_WAV
- Sketch_09_2_Record_And_Play
- Sketch_09_3_Record_And_Play
- Sketch_10_ESP32_SR
- Sketch_11_LVGL
- Sketch_12_LVGL_LedPixel
- Sketch_13_LVGL_Camera
- Sketch_14_Lvgl_Picture
- Sketch_15_Lvgl_Music
- Sketch_16_Lvgl_Sound_Recorder
- Sketch_17_Lvgl_Multifunctionality
- Sketch_18_Lvgl_Multifunctionality

[xiaozhi-esp32](https://github.com/78/xiaozhi-esp32) 是一个非常优秀的开源项目,因此为Freenove Media Kit进行了适配,在未来的开发中,也许会将自身的项目与小智项目进行合并。

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions main/boards/freenove-media-kit/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_

#include <driver/gpio.h>

#define AUDIO_INPUT_SAMPLE_RATE 16000
#define AUDIO_OUTPUT_SAMPLE_RATE 24000

#define AUDIO_I2S_MIC_GPIO_WS GPIO_NUM_14
#define AUDIO_I2S_MIC_GPIO_SCK GPIO_NUM_3
#define AUDIO_I2S_MIC_GPIO_DIN GPIO_NUM_46
#define AUDIO_I2S_SPK_GPIO_DOUT GPIO_NUM_1
#define AUDIO_I2S_SPK_GPIO_BCLK GPIO_NUM_42
#define AUDIO_I2S_SPK_GPIO_LRCK GPIO_NUM_41

#define BUILTIN_LED_GPIO GPIO_NUM_48
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define TOUCH_BUTTON_GPIO GPIO_NUM_NC
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC

#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_2
#define DISPLAY_MOSI_PIN GPIO_NUM_21
#define DISPLAY_CLK_PIN GPIO_NUM_47
#define DISPLAY_DC_PIN GPIO_NUM_45
#define DISPLAY_RST_PIN GPIO_NUM_NC
#define DISPLAY_CS_PIN GPIO_NUM_NC

#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 135
#define DISPLAY_MIRROR_X true
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY true
#define DISPLAY_INVERT_COLOR true
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
#define DISPLAY_OFFSET_X 40
#define DISPLAY_OFFSET_Y 53
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false

#endif // _BOARD_CONFIG_H_
9 changes: 9 additions & 0 deletions main/boards/freenove-media-kit/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"target": "esp32s3",
"builds": [
{
"name": "freenove-media-kit",
"sdkconfig_append": []
}
]
}
Loading