mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 11:02:40 +00:00
5001b7081b
* add firmware source code
135 lines
3.0 KiB
C++
135 lines
3.0 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
#include "hal_bridge.h"
|
|
#include "stackchan_display.h"
|
|
#include <esp_log.h>
|
|
#include <esp_err.h>
|
|
#include <nvs.h>
|
|
#include <nvs_flash.h>
|
|
#include <driver/gpio.h>
|
|
#include <esp_event.h>
|
|
#include <application.h>
|
|
#include <board.h>
|
|
#include <display.h>
|
|
#include <mutex>
|
|
#include <assets.h>
|
|
|
|
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<std::mutex> lock(_mutex);
|
|
_data.touchPoint.num = num;
|
|
_data.touchPoint.x = x;
|
|
_data.touchPoint.y = y;
|
|
}
|
|
|
|
TouchPoint_t get_touch_point()
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
return _data.touchPoint;
|
|
}
|
|
|
|
bool is_xiaozhi_mode()
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
return _data.isXiaozhiMode;
|
|
}
|
|
|
|
void set_xiaozhi_mode(bool mode)
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
_data.isXiaozhiMode = mode;
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* Display */
|
|
/* -------------------------------------------------------------------------- */
|
|
#define DISPLAY_TYPE StackChanAvatarDisplay
|
|
|
|
lv_disp_t* display_get_lvgl_display()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(Board::GetInstance().GetDisplay());
|
|
return display->GetLvglDisplay();
|
|
}
|
|
|
|
void disply_lvgl_lock()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(Board::GetInstance().GetDisplay());
|
|
display->LvglLock();
|
|
}
|
|
|
|
void disply_lvgl_unlock()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(Board::GetInstance().GetDisplay());
|
|
display->LvglUnlock();
|
|
}
|
|
|
|
void display_setup_xiaozhi_ui()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(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
|