diff --git a/components/box-emu/include/box-emu.hpp b/components/box-emu/include/box-emu.hpp index 77f78b9..5c0438a 100644 --- a/components/box-emu/include/box-emu.hpp +++ b/components/box-emu/include/box-emu.hpp @@ -21,6 +21,7 @@ #include "aw9523.hpp" #include "base_component.hpp" +#include "button.hpp" #include "events.hpp" #include "high_resolution_timer.hpp" #include "keypad_input.hpp" @@ -283,6 +284,9 @@ class BoxEmu : public espp::BaseComponent { // memory uint8_t *romdata_{nullptr}; + // audio + std::shared_ptr mute_button_; + // gamepad std::atomic can_read_gamepad_{true}; std::recursive_mutex gamepad_state_mutex_; diff --git a/components/box-emu/src/box-emu.cpp b/components/box-emu/src/box-emu.cpp index 958f63e..e11f8c0 100644 --- a/components/box-emu/src/box-emu.cpp +++ b/components/box-emu/src/box-emu.cpp @@ -59,6 +59,36 @@ bool BoxEmu::initialize_box() { return false; } + // initialize the mute button to broadcast the mute state + logger_.info("Initializing mute button"); + mute_button_ = std::make_shared(espp::Button::Config{ + .name = "mute button", + .interrupt_config = + { + .gpio_num = espp::EspBox::get_mute_pin(), + .callback = + [](const espp::Interrupt::Event &event) { + espp::EspBox::get().mute(event.active); + // simply publish that the mute button was presssed + espp::EventManager::get().publish(mute_button_topic, {}); + }, + .active_level = espp::Interrupt::ActiveLevel::LOW, + .interrupt_type = espp::Interrupt::Type::ANY_EDGE, + .pullup_enabled = true, + .pulldown_enabled = false, + }, + .task_config = + { + .name = "mute button task", + .stack_size_bytes = 4 * 1024, + .priority = 5, + }, + .log_level = espp::Logger::Verbosity::WARN, + }); + + // update the mute state (since it's a flip-flop and may have been set if we + // restarted without power loss) + espp::EspBox::get().mute(mute_button_->is_pressed()); return true; } diff --git a/components/espp b/components/espp index 855975f..0fe56d9 160000 --- a/components/espp +++ b/components/espp @@ -1 +1 @@ -Subproject commit 855975f19e835bc34dc7aea74197168712e79457 +Subproject commit 0fe56d920dd94400724b70e08294b86e32b21709