面包板增加触摸对话按钮,使用GPIO45

This commit is contained in:
Terrence
2024-12-03 09:43:41 +08:00
parent 436ff2b906
commit 064341c5ef
7 changed files with 21 additions and 10 deletions

View File

@@ -52,10 +52,4 @@ choice BOARD_TYPE
bool "立创开发板"
endchoice
config USE_AFE_SR
bool "Use Espressif AFE SR"
default y
help
Use AFE SR for wake word detection.
endmenu

View File

@@ -16,6 +16,7 @@ class CompactMl307Board : public Ml307Board {
private:
i2c_master_bus_handle_t display_i2c_bus_;
Button boot_button_;
Button touch_button_;
Button volume_up_button_;
Button volume_down_button_;
SystemReset system_reset_;
@@ -40,6 +41,12 @@ private:
boot_button_.OnClick([this]() {
Application::GetInstance().ToggleChatState();
});
touch_button_.OnPressDown([this]() {
Application::GetInstance().StartListening();
});
touch_button_.OnPressUp([this]() {
Application::GetInstance().StopListening();
});
volume_up_button_.OnClick([this]() {
auto codec = GetAudioCodec();
@@ -77,6 +84,7 @@ private:
public:
CompactMl307Board() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
boot_button_(BOOT_BUTTON_GPIO),
touch_button_(TOUCH_BUTTON_GPIO, 1),
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO),
system_reset_(RESET_NVS_BUTTON_GPIO, RESET_FACTORY_BUTTON_GPIO) {

View File

@@ -29,6 +29,7 @@
#define BUILTIN_LED_GPIO GPIO_NUM_48
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define TOUCH_BUTTON_GPIO GPIO_NUM_45
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_40
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_39
#define RESET_NVS_BUTTON_GPIO GPIO_NUM_1

View File

@@ -17,6 +17,7 @@ class CompactWifiBoard : public WifiBoard {
private:
i2c_master_bus_handle_t display_i2c_bus_;
Button boot_button_;
Button touch_button_;
Button volume_up_button_;
Button volume_down_button_;
SystemReset system_reset_;
@@ -43,7 +44,12 @@ private:
if (app.GetChatState() == kChatStateUnknown && !WifiStation::GetInstance().IsConnected()) {
ResetWifiConfiguration();
}
app.ToggleChatState();
});
touch_button_.OnPressDown([this]() {
Application::GetInstance().StartListening();
});
touch_button_.OnPressUp([this]() {
Application::GetInstance().StopListening();
});
volume_up_button_.OnClick([this]() {
@@ -82,6 +88,7 @@ private:
public:
CompactWifiBoard() :
boot_button_(BOOT_BUTTON_GPIO),
touch_button_(TOUCH_BUTTON_GPIO, 1),
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO),
system_reset_(RESET_NVS_BUTTON_GPIO, RESET_FACTORY_BUTTON_GPIO) {

View File

@@ -30,6 +30,7 @@
#define BUILTIN_LED_GPIO GPIO_NUM_48
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define TOUCH_BUTTON_GPIO GPIO_NUM_45
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_40
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_39
#define RESET_NVS_BUTTON_GPIO GPIO_NUM_1

View File

@@ -4,7 +4,7 @@
static const char* TAG = "Button";
Button::Button(gpio_num_t gpio_num) : gpio_num_(gpio_num) {
Button::Button(gpio_num_t gpio_num, bool active_high) : gpio_num_(gpio_num) {
if (gpio_num == GPIO_NUM_NC) {
return;
}
@@ -14,7 +14,7 @@ Button::Button(gpio_num_t gpio_num) : gpio_num_(gpio_num) {
.short_press_time = 50,
.gpio_button_config = {
.gpio_num = gpio_num,
.active_level = 0
.active_level = static_cast<uint8_t>(active_high ? 1 : 0)
}
};
button_handle_ = iot_button_create(&button_config);

View File

@@ -7,7 +7,7 @@
class Button {
public:
Button(gpio_num_t gpio_num);
Button(gpio_num_t gpio_num, bool active_high = false);
~Button();
void OnPressDown(std::function<void()> callback);