/* * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD * * SPDX-License-Identifier: MIT */ #include "hal_bridge.h" #include "stackchan_display.h" #include #include #include #include #include #include #include #include #include #include #include static const char* _tag = "HAL_BRIDGE"; namespace hal_bridge { /* -------------------------------------------------------------------------- */ /* State and touch point */ /* -------------------------------------------------------------------------- */ static std::mutex _mutex; static Data_t _data; void lock() { _mutex.lock(); } void unlock() { _mutex.unlock(); } Data_t& get_data() { return _data; } void set_touch_point(int num, int x, int y) { std::lock_guard lock(_mutex); _data.touchPoint.num = num; _data.touchPoint.x = x; _data.touchPoint.y = y; } TouchPoint_t get_touch_point() { std::lock_guard lock(_mutex); return _data.touchPoint; } bool is_xiaozhi_mode() { std::lock_guard lock(_mutex); return _data.isXiaozhiMode; } void set_xiaozhi_mode(bool mode) { std::lock_guard lock(_mutex); _data.isXiaozhiMode = mode; } /* -------------------------------------------------------------------------- */ /* Display */ /* -------------------------------------------------------------------------- */ #define DISPLAY_TYPE StackChanAvatarDisplay lv_disp_t* display_get_lvgl_display() { auto display = static_cast(Board::GetInstance().GetDisplay()); return display->GetLvglDisplay(); } void disply_lvgl_lock() { auto display = static_cast(Board::GetInstance().GetDisplay()); display->LvglLock(); } void disply_lvgl_unlock() { auto display = static_cast(Board::GetInstance().GetDisplay()); display->LvglUnlock(); } void display_setup_xiaozhi_ui() { auto display = static_cast(Board::GetInstance().GetDisplay()); display->SetupXiaoZhiUI(); } /* -------------------------------------------------------------------------- */ /* Application */ /* -------------------------------------------------------------------------- */ void xiaozhi_board_init() { // Initialize the default event loop ESP_ERROR_CHECK(esp_event_loop_create_default()); // Init board auto& board = Board::GetInstance(); // test board.GetBacklight()->SetBrightness(100); } void start_xiaozhi_app() { display_setup_xiaozhi_ui(); set_xiaozhi_mode(true); // Launch the application auto& app = Application::GetInstance(); app.Start(); } void app_play_sound(const std::string_view& sound) { auto& app = Application::GetInstance(); app.PlaySound(sound); } } // namespace hal_bridge