Skip to content
Merged
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
2 changes: 1 addition & 1 deletion components/gui/include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ class Gui {
.callback = std::bind(&Gui::update, this),
}};
espp::Logger logger_;
mutable std::recursive_mutex mutex_;
std::recursive_mutex &mutex_{Tab5Emu::lvgl_mutex()}; // shared: LVGL is not thread-safe
};
2 changes: 2 additions & 0 deletions components/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Gui::~Gui() {
void Gui::pause() {
paused_ = true;
task_.stop();
// wait out a timer callback already in lv_timer_handler() (stop() does not)
std::lock_guard<std::recursive_mutex> lk(mutex_);
}

void Gui::resume() {
Expand Down
2 changes: 1 addition & 1 deletion components/menu/include/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ class Menu {
.callback = std::bind(&Menu::update, this),
}};
espp::Logger logger_;
std::recursive_mutex mutex_;
std::recursive_mutex &mutex_{Tab5Emu::lvgl_mutex()}; // shared: LVGL is not thread-safe
};
2 changes: 2 additions & 0 deletions components/menu/src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ void Menu::select_slot(int slot) {
void Menu::pause() {
paused_ = true;
task_.stop();
// wait out a timer callback already in lv_timer_handler() (stop() does not)
std::lock_guard<std::recursive_mutex> lk(mutex_);
}

void Menu::resume() {
Expand Down
7 changes: 7 additions & 0 deletions components/tab5-emu/include/tab5-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ class Tab5Emu : public espp::BaseComponent {
/// focused slider / dropdown), A = enter, B = escape. Menus attach their
/// lv_group to it (lv_indev_set_group) when shown.
lv_indev_t *keypad_indev() const { return keypad_indev_; }
/// The one lock for LVGL (built without LV_USE_OS, so it is not
/// thread-safe): the launcher's and the pause menu's timers and their
/// event-manager callbacks (volume) all touch it from different tasks.
static std::recursive_mutex &lvgl_mutex() {
static std::recursive_mutex m;
return m;
}
/// Stop the USB host library (keyboard / mouse stop working). The USB
/// controller is shared with device mode (see initialize_usb_msc()).
void deinitialize_usb_host();
Expand Down
Loading