mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-07-21 02:05:52 +00:00
* feat: migrate firmware to xiaozhi-fonts 2.0.0 * fix: restart scrolling subtitles on text change * docs: add AGENTS.md for project overview, architecture, rules, and commands - Introduced AGENTS.md to document the XiaoZhi voice-assistant firmware architecture, required rules for development, board configuration process, and validation steps. - Included detailed sections on project structure, commands for building and testing, and authoritative documentation references. * feat: finalize glyph push protocol * fix: remove stale emoji font include * build: use xiaozhi-fonts 2.0.0 * fix: decouple custom fonts from glyph push * refactor: improve wake word invocation handling - Introduced BeginWakeWordInvoke method to streamline the wake word processing flow. - Updated HandleWakeWordDetectedEvent to utilize the new method, ensuring proper state transitions and scheduling. - Enhanced error handling to prevent the device from getting stuck in the connecting state. - Refactored audio channel management to improve responsiveness during wake word detection. --------- Co-authored-by: Xiaoxia <terrence.huang@tenclass.com>
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <esp_heap_caps.h>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
#include <vector>
|
|
|
|
bool TextGlyphStorageUsesPsram();
|
|
|
|
template <typename T>
|
|
class TextGlyphAllocator {
|
|
public:
|
|
using value_type = T;
|
|
using is_always_equal = std::true_type;
|
|
|
|
TextGlyphAllocator() noexcept = default;
|
|
|
|
template <typename U>
|
|
TextGlyphAllocator(const TextGlyphAllocator<U>&) noexcept {}
|
|
|
|
T* allocate(size_t count) {
|
|
if (count == 0) {
|
|
return nullptr;
|
|
}
|
|
if (count > std::numeric_limits<size_t>::max() / sizeof(T)) {
|
|
std::abort();
|
|
}
|
|
uint32_t caps = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT;
|
|
if (TextGlyphStorageUsesPsram()) {
|
|
caps = MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT;
|
|
}
|
|
auto ptr = static_cast<T*>(heap_caps_malloc(count * sizeof(T), caps));
|
|
if (ptr == nullptr) {
|
|
std::abort();
|
|
}
|
|
return ptr;
|
|
}
|
|
|
|
void deallocate(T* ptr, size_t) noexcept { heap_caps_free(ptr); }
|
|
};
|
|
|
|
template <typename T, typename U>
|
|
bool operator==(const TextGlyphAllocator<T>&, const TextGlyphAllocator<U>&) {
|
|
return true;
|
|
}
|
|
|
|
template <typename T, typename U>
|
|
bool operator!=(const TextGlyphAllocator<T>&, const TextGlyphAllocator<U>&) {
|
|
return false;
|
|
}
|
|
|
|
template <typename T>
|
|
using TextGlyphVector = std::vector<T, TextGlyphAllocator<T>>;
|
|
|
|
struct TextGlyph {
|
|
uint32_t codepoint = 0;
|
|
uint32_t adv_w = 0;
|
|
uint16_t box_w = 0;
|
|
uint16_t box_h = 0;
|
|
int16_t ofs_x = 0;
|
|
int16_t ofs_y = 0;
|
|
TextGlyphVector<uint8_t> bitmap;
|
|
};
|