Merge develop into main (#353)

## TactilityC
- Add `tt_lvgl_lock()` and `tt_lvgl_unlock()`
- Add `tt_thread_set_affinity()`
- Add support for STL symbols

## Other
- Add `Thread::setAffinity()`
- `GuiService`: replace `#define` with `constexpr`
- Remove log storage and log app for now
- Split up ELF symbols into more groups
This commit is contained in:
Ken Van Hoeylandt 2025-10-01 23:07:47 +02:00 committed by GitHub
parent c7621b5e4c
commit b214a3358e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 198 additions and 344 deletions

View File

@ -49,7 +49,6 @@ if (DEFINED ENV{ESP_IDF_VERSION})
set(EXCLUDE_COMPONENTS "Simulator")
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_log_write" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_button_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_dropdown_create" APPEND)
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_list_create" APPEND)

View File

@ -1,4 +1,6 @@
#include "ChargeFromVoltage.h"
#include <algorithm>
#include <Tactility/Log.h>
constexpr auto* TAG = "ChargeFromVoltage";

View File

@ -12,10 +12,10 @@
namespace tt::service::gui {
#define GUI_THREAD_FLAG_DRAW (1 << 0)
#define GUI_THREAD_FLAG_INPUT (1 << 1)
#define GUI_THREAD_FLAG_EXIT (1 << 2)
#define GUI_THREAD_FLAG_ALL (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT | GUI_THREAD_FLAG_EXIT)
constexpr auto GUI_THREAD_FLAG_DRAW = (1 << 0);
constexpr auto GUI_THREAD_FLAG_INPUT = (1 << 1);
constexpr auto GUI_THREAD_FLAG_EXIT = (1 << 2);
constexpr auto GUI_THREAD_FLAG_ALL = (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT | GUI_THREAD_FLAG_EXIT);
class GuiService final : public Service {

View File

@ -72,7 +72,6 @@ namespace app {
namespace inputdialog { extern const AppManifest manifest; }
namespace launcher { extern const AppManifest manifest; }
namespace localesettings { extern const AppManifest manifest; }
namespace log { extern const AppManifest manifest; }
namespace notes { extern const AppManifest manifest; }
namespace power { extern const AppManifest manifest; }
namespace selectiondialog { extern const AppManifest manifest; }
@ -111,7 +110,6 @@ static void registerSystemApps() {
addApp(app::inputdialog::manifest);
addApp(app::launcher::manifest);
addApp(app::localesettings::manifest);
addApp(app::log::manifest);
addApp(app::notes::manifest);
addApp(app::settings::manifest);
addApp(app::selectiondialog::manifest);

View File

@ -1,130 +0,0 @@
#include <Tactility/app/selectiondialog/SelectionDialog.h>
#include <Tactility/lvgl/Style.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/service/loader/Loader.h>
#include <sstream>
#include <vector>
#include <ranges>
#include <lvgl.h>
namespace tt::app::log {
class LogApp : public App {
static constexpr auto* TAG = "LogApp";
LogLevel filterLevel = LogLevel::Info;
lv_obj_t* labelWidget = nullptr;
static bool shouldShowLog(LogLevel filterLevel, LogLevel logLevel) {
return filterLevel >= logLevel;
}
void updateLogEntries() {
std::size_t next_log_index;
auto entries = copyLogEntries(next_log_index);
std::stringstream buffer;
if (next_log_index != 0) {
long to_drop = TT_LOG_ENTRY_COUNT - next_log_index;
for (auto entry : std::views::drop(*entries, (long)next_log_index)) {
if (shouldShowLog(filterLevel, entry.level) && entry.message[0] != 0x00) {
buffer << entry.message;
}
}
}
for (auto entry : std::views::take(*entries, (long)next_log_index)) {
if (shouldShowLog(filterLevel, entry.level) && entry.message[0] != 0x00) {
buffer << entry.message;
}
}
if (!buffer.str().empty()) {
lv_label_set_text(labelWidget, buffer.str().c_str());
} else {
lv_label_set_text(labelWidget, "No logs for the selected log level");
}
}
void updateViews() {
if (lvgl::lock(100 / portTICK_PERIOD_MS)) {
updateLogEntries();
lvgl::unlock();
}
}
static void onLevelFilterPressedCallback(TT_UNUSED lv_event_t* event) {
std::vector<std::string> items = {
"Verbose",
"Debug",
"Info",
"Warning",
"Error",
};
selectiondialog::start("Log Level", items);
}
public:
void onShow(AppContext& app, lv_obj_t* parent) override {
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
auto* toolbar = lvgl::toolbar_create(parent, app);
lvgl::toolbar_add_button_action(toolbar, LV_SYMBOL_EDIT, onLevelFilterPressedCallback, this);
auto* wrapper = lv_obj_create(parent);
lv_obj_set_width(wrapper, LV_PCT(100));
lv_obj_set_flex_grow(wrapper, 1);
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_all(wrapper, 0, 0);
lv_obj_set_style_pad_gap(wrapper, 0, 0);
lvgl::obj_set_style_bg_invisible(wrapper);
labelWidget = lv_label_create(wrapper);
lv_obj_align(labelWidget, LV_ALIGN_CENTER, 0, 0);
updateLogEntries();
}
void onResult(AppContext& app, TT_UNUSED LaunchId launchId, Result result, std::unique_ptr<Bundle> bundle) override {
if (result == Result::Ok && bundle != nullptr) {
switch (selectiondialog::getResultIndex(*bundle)) {
case 0:
filterLevel = LogLevel::Verbose;
break;
case 1:
filterLevel = LogLevel::Debug;
break;
case 2:
filterLevel = LogLevel::Info;
break;
case 3:
filterLevel = LogLevel::Warning;
break;
case 4:
filterLevel = LogLevel::Error;
break;
default:
break;
}
updateViews();
}
}
};
extern const AppManifest manifest = {
.appId = "Log",
.appName = "Log",
.appIcon = LV_SYMBOL_LIST,
.appCategory = Category::System,
.createApp = create<LogApp>
};
} // namespace

View File

@ -13,6 +13,12 @@ void tt_lvgl_start();
/** Stop LVGL and related background services */
void tt_lvgl_stop();
/** Lock the LVGL context. Call this before doing LVGL-related operations from a non-LVLG thread */
void tt_lvgl_lock();
/** Unlock the LVGL context */
void tt_lvgl_unlock();
#ifdef __cplusplus
}
#endif

View File

@ -88,6 +88,12 @@ void tt_thread_set_name(ThreadHandle handle, const char* name);
*/
void tt_thread_set_stack_size(ThreadHandle handle, size_t size);
/** Set CPu core affinity for this thread
* @param[in] handle the thread instance handle
* @param[in] affinity -1 means not pinned, otherwise it's the core id (e.g. 0 or 1 on ESP32)
*/
void tt_thread_set_affinity(ThreadHandle handle, int affinity);
/**
* Set the callback for a thread. This method is executed when the thread is started.
* @param[in] handle the thread instance handle

View File

@ -0,0 +1,5 @@
#pragma once
#include <private/elf_symbol.h>
extern const esp_elfsym esp_event_symbols[];

View File

@ -0,0 +1,5 @@
#pragma once
#include <private/elf_symbol.h>
extern const esp_elfsym esp_http_client_symbols[];

View File

@ -2,12 +2,4 @@
#include <private/elf_symbol.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const esp_elfsym gcc_soft_float_symbols[];
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,5 @@
#pragma once
#include <private/elf_symbol.h>
extern const esp_elfsym pthread_symbols[];

View File

@ -0,0 +1,5 @@
#pragma once
#include <private/elf_symbol.h>
extern const esp_elfsym stl_symbols[];

View File

@ -0,0 +1,22 @@
#include <symbols/esp_event.h>
#include <esp_event.h>
const esp_elfsym esp_event_symbols[] = {
ESP_ELFSYM_EXPORT(esp_event_loop_create),
ESP_ELFSYM_EXPORT(esp_event_loop_delete),
ESP_ELFSYM_EXPORT(esp_event_loop_create_default),
ESP_ELFSYM_EXPORT(esp_event_loop_delete_default),
ESP_ELFSYM_EXPORT(esp_event_loop_run),
ESP_ELFSYM_EXPORT(esp_event_handler_register),
ESP_ELFSYM_EXPORT(esp_event_handler_register_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_register_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_register),
ESP_ELFSYM_EXPORT(esp_event_handler_unregister),
ESP_ELFSYM_EXPORT(esp_event_handler_unregister_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_unregister_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_unregister),
ESP_ELFSYM_EXPORT(esp_event_post),
ESP_ELFSYM_EXPORT(esp_event_post_to),
ESP_ELFSYM_EXPORT(esp_event_isr_post),
ESP_ELFSYM_EXPORT(esp_event_isr_post_to),
};

View File

@ -0,0 +1,46 @@
#include <symbols/esp_http_client.h>
#include <esp_http_client.h>
const esp_elfsym esp_http_client_symbols[] = {
ESP_ELFSYM_EXPORT(esp_http_client_init),
ESP_ELFSYM_EXPORT(esp_http_client_perform),
ESP_ELFSYM_EXPORT(esp_http_client_cancel_request),
ESP_ELFSYM_EXPORT(esp_http_client_set_url),
ESP_ELFSYM_EXPORT(esp_http_client_set_post_field),
ESP_ELFSYM_EXPORT(esp_http_client_get_post_field),
ESP_ELFSYM_EXPORT(esp_http_client_set_header),
ESP_ELFSYM_EXPORT(esp_http_client_get_header),
ESP_ELFSYM_EXPORT(esp_http_client_get_username),
ESP_ELFSYM_EXPORT(esp_http_client_set_username),
ESP_ELFSYM_EXPORT(esp_http_client_get_password),
ESP_ELFSYM_EXPORT(esp_http_client_set_password),
ESP_ELFSYM_EXPORT(esp_http_client_cancel_request),
ESP_ELFSYM_EXPORT(esp_http_client_set_authtype),
ESP_ELFSYM_EXPORT(esp_http_client_get_user_data),
ESP_ELFSYM_EXPORT(esp_http_client_set_user_data),
ESP_ELFSYM_EXPORT(esp_http_client_get_errno),
ESP_ELFSYM_EXPORT(esp_http_client_get_and_clear_last_tls_error),
ESP_ELFSYM_EXPORT(esp_http_client_set_method),
ESP_ELFSYM_EXPORT(esp_http_client_set_timeout_ms),
ESP_ELFSYM_EXPORT(esp_http_client_delete_header),
ESP_ELFSYM_EXPORT(esp_http_client_delete_all_headers),
ESP_ELFSYM_EXPORT(esp_http_client_open),
ESP_ELFSYM_EXPORT(esp_http_client_write),
ESP_ELFSYM_EXPORT(esp_http_client_fetch_headers),
ESP_ELFSYM_EXPORT(esp_http_client_is_chunked_response),
ESP_ELFSYM_EXPORT(esp_http_client_read),
ESP_ELFSYM_EXPORT(esp_http_client_get_status_code),
ESP_ELFSYM_EXPORT(esp_http_client_get_content_length),
ESP_ELFSYM_EXPORT(esp_http_client_close),
ESP_ELFSYM_EXPORT(esp_http_client_cleanup),
ESP_ELFSYM_EXPORT(esp_http_client_get_transport_type),
ESP_ELFSYM_EXPORT(esp_http_client_set_redirection),
ESP_ELFSYM_EXPORT(esp_http_client_reset_redirect_counter),
ESP_ELFSYM_EXPORT(esp_http_client_set_auth_data),
ESP_ELFSYM_EXPORT(esp_http_client_add_auth),
ESP_ELFSYM_EXPORT(esp_http_client_is_complete_data_received),
ESP_ELFSYM_EXPORT(esp_http_client_read_response),
ESP_ELFSYM_EXPORT(esp_http_client_flush_response),
ESP_ELFSYM_EXPORT(esp_http_client_get_url),
ESP_ELFSYM_EXPORT(esp_http_client_get_chunk_length),
};

View File

@ -1,10 +1,10 @@
#include <cstdlib>
#include <symbols/gcc_soft_float.h>
extern "C" {
// Reference: https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html
extern "C" {
extern float __addsf3(float a, float b);
extern double __adddf3(double a, double b);
// extern long double __addtf3(long double a, long double b);
@ -139,6 +139,8 @@ int __gtsf2(float a, float b);
int __gtdf2(double a, double b);
// int __gttf2(long double a, long double b);
}
const esp_elfsym gcc_soft_float_symbols[] = {
ESP_ELFSYM_EXPORT(__addsf3),
ESP_ELFSYM_EXPORT(__adddf3),
@ -276,5 +278,3 @@ const esp_elfsym gcc_soft_float_symbols[] = {
ESP_ELFSYM_END
};
}

View File

@ -0,0 +1,11 @@
#include <symbols/pthread.h>
#include <pthread.h>
const esp_elfsym pthread_symbols[] = {
ESP_ELFSYM_EXPORT(pthread_create),
ESP_ELFSYM_EXPORT(pthread_attr_init),
ESP_ELFSYM_EXPORT(pthread_attr_setstacksize),
ESP_ELFSYM_EXPORT(pthread_detach),
ESP_ELFSYM_EXPORT(pthread_join),
ESP_ELFSYM_EXPORT(pthread_exit),
};

View File

@ -0,0 +1,18 @@
#include <symbols/stl.h>
#include <bits/functexcept.h>
extern "C" {
extern void* _Znwj(uint32_t size); // operator new(unsigned int)
extern void _ZdlPvj(void* p, uint64_t size); // operator delete(void*, unsigned int)
}
const esp_elfsym stl_symbols[] = {
ESP_ELFSYM_EXPORT(_Znwj), // operator new(unsigned int)
ESP_ELFSYM_EXPORT(_ZdlPvj), // operator delete(void*, unsigned int)
// Note: You have to use the mangled names here
{ "_ZSt20__throw_length_errorPKc", (void*)&(std::__throw_length_error) },
{ "_ZSt28__throw_bad_array_new_lengthv", (void*)&(std::__throw_bad_array_new_length) },
{ "_ZSt17__throw_bad_allocv", (void*)&(std::__throw_bad_alloc) }
// { "", (void*)&(std::) },
};

View File

@ -5,6 +5,7 @@
#include "tt_app_manifest.h"
#include "tt_app_selectiondialog.h"
#include "tt_bundle.h"
#include "tt_file.h"
#include "tt_gps.h"
#include "tt_hal_device.h"
#include "tt_hal_display.h"
@ -25,31 +26,28 @@
#include "tt_timer.h"
#include "tt_wifi.h"
#include <private/elf_symbol.h>
#include "symbols/esp_event.h"
#include "symbols/esp_http_client.h"
#include "symbols/gcc_soft_float.h"
#include "symbols/pthread.h"
#include "symbols/stl.h"
#include <cstring>
#include <ctype.h>
#include <esp_log.h>
#include <esp_http_client.h>
#include <cassert>
#include <getopt.h>
#include <time.h>
#include <setjmp.h>
#include <sys/errno.h>
#include <sys/unistd.h>
#include <lvgl.h>
#include <pthread.h>
#include <setjmp.h>
#include <tt_file.h>
#include <vector>
extern "C" {
// GCC internal new and delete
extern void* _Znwj(uint32_t size);
extern void _ZdlPvj(void* p, uint64_t size);
const esp_elfsym elf_symbols[] {
// GCC internal
ESP_ELFSYM_EXPORT(_Znwj), // new
ESP_ELFSYM_EXPORT(_ZdlPvj), // delete
const esp_elfsym main_symbols[] {
// stdlib.h
ESP_ELFSYM_EXPORT(malloc),
ESP_ELFSYM_EXPORT(calloc),
@ -66,13 +64,6 @@ const esp_elfsym elf_symbols[] {
// time.h
ESP_ELFSYM_EXPORT(clock_gettime),
ESP_ELFSYM_EXPORT(strftime),
// pthread
ESP_ELFSYM_EXPORT(pthread_create),
ESP_ELFSYM_EXPORT(pthread_attr_init),
ESP_ELFSYM_EXPORT(pthread_attr_setstacksize),
ESP_ELFSYM_EXPORT(pthread_detach),
ESP_ELFSYM_EXPORT(pthread_join),
ESP_ELFSYM_EXPORT(pthread_exit),
// sys/errno.h
ESP_ELFSYM_EXPORT(__errno),
// freertos_tasks_c_additions.h
@ -158,66 +149,6 @@ const esp_elfsym elf_symbols[] {
ESP_ELFSYM_EXPORT(esp_log),
ESP_ELFSYM_EXPORT(esp_log_write),
ESP_ELFSYM_EXPORT(esp_log_timestamp),
// esp_http_client
ESP_ELFSYM_EXPORT(esp_http_client_init),
ESP_ELFSYM_EXPORT(esp_http_client_perform),
ESP_ELFSYM_EXPORT(esp_http_client_cancel_request),
ESP_ELFSYM_EXPORT(esp_http_client_set_url),
ESP_ELFSYM_EXPORT(esp_http_client_set_post_field),
ESP_ELFSYM_EXPORT(esp_http_client_get_post_field),
ESP_ELFSYM_EXPORT(esp_http_client_set_header),
ESP_ELFSYM_EXPORT(esp_http_client_get_header),
ESP_ELFSYM_EXPORT(esp_http_client_get_username),
ESP_ELFSYM_EXPORT(esp_http_client_set_username),
ESP_ELFSYM_EXPORT(esp_http_client_get_password),
ESP_ELFSYM_EXPORT(esp_http_client_set_password),
ESP_ELFSYM_EXPORT(esp_http_client_cancel_request),
ESP_ELFSYM_EXPORT(esp_http_client_set_authtype),
ESP_ELFSYM_EXPORT(esp_http_client_get_user_data),
ESP_ELFSYM_EXPORT(esp_http_client_set_user_data),
ESP_ELFSYM_EXPORT(esp_http_client_get_errno),
ESP_ELFSYM_EXPORT(esp_http_client_get_and_clear_last_tls_error),
ESP_ELFSYM_EXPORT(esp_http_client_set_method),
ESP_ELFSYM_EXPORT(esp_http_client_set_timeout_ms),
ESP_ELFSYM_EXPORT(esp_http_client_delete_header),
ESP_ELFSYM_EXPORT(esp_http_client_delete_all_headers),
ESP_ELFSYM_EXPORT(esp_http_client_open),
ESP_ELFSYM_EXPORT(esp_http_client_write),
ESP_ELFSYM_EXPORT(esp_http_client_fetch_headers),
ESP_ELFSYM_EXPORT(esp_http_client_is_chunked_response),
ESP_ELFSYM_EXPORT(esp_http_client_read),
ESP_ELFSYM_EXPORT(esp_http_client_get_status_code),
ESP_ELFSYM_EXPORT(esp_http_client_get_content_length),
ESP_ELFSYM_EXPORT(esp_http_client_close),
ESP_ELFSYM_EXPORT(esp_http_client_cleanup),
ESP_ELFSYM_EXPORT(esp_http_client_get_transport_type),
ESP_ELFSYM_EXPORT(esp_http_client_set_redirection),
ESP_ELFSYM_EXPORT(esp_http_client_reset_redirect_counter),
ESP_ELFSYM_EXPORT(esp_http_client_set_auth_data),
ESP_ELFSYM_EXPORT(esp_http_client_add_auth),
ESP_ELFSYM_EXPORT(esp_http_client_is_complete_data_received),
ESP_ELFSYM_EXPORT(esp_http_client_read_response),
ESP_ELFSYM_EXPORT(esp_http_client_flush_response),
ESP_ELFSYM_EXPORT(esp_http_client_get_url),
ESP_ELFSYM_EXPORT(esp_http_client_get_chunk_length),
// esp_event
ESP_ELFSYM_EXPORT(esp_event_loop_create),
ESP_ELFSYM_EXPORT(esp_event_loop_delete),
ESP_ELFSYM_EXPORT(esp_event_loop_create_default),
ESP_ELFSYM_EXPORT(esp_event_loop_delete_default),
ESP_ELFSYM_EXPORT(esp_event_loop_run),
ESP_ELFSYM_EXPORT(esp_event_handler_register),
ESP_ELFSYM_EXPORT(esp_event_handler_register_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_register_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_register),
ESP_ELFSYM_EXPORT(esp_event_handler_unregister),
ESP_ELFSYM_EXPORT(esp_event_handler_unregister_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_unregister_with),
ESP_ELFSYM_EXPORT(esp_event_handler_instance_unregister),
ESP_ELFSYM_EXPORT(esp_event_post),
ESP_ELFSYM_EXPORT(esp_event_post_to),
ESP_ELFSYM_EXPORT(esp_event_isr_post),
ESP_ELFSYM_EXPORT(esp_event_isr_post_to),
// Tactility
ESP_ELFSYM_EXPORT(tt_app_start),
ESP_ELFSYM_EXPORT(tt_app_start_with_bundle),
@ -289,6 +220,8 @@ const esp_elfsym elf_symbols[] {
ESP_ELFSYM_EXPORT(tt_kernel_get_millis),
ESP_ELFSYM_EXPORT(tt_kernel_get_micros),
ESP_ELFSYM_EXPORT(tt_lvgl_is_started),
ESP_ELFSYM_EXPORT(tt_lvgl_lock),
ESP_ELFSYM_EXPORT(tt_lvgl_unlock),
ESP_ELFSYM_EXPORT(tt_lvgl_start),
ESP_ELFSYM_EXPORT(tt_lvgl_stop),
ESP_ELFSYM_EXPORT(tt_lvgl_software_keyboard_show),
@ -330,6 +263,7 @@ const esp_elfsym elf_symbols[] {
ESP_ELFSYM_EXPORT(tt_thread_free),
ESP_ELFSYM_EXPORT(tt_thread_set_name),
ESP_ELFSYM_EXPORT(tt_thread_set_stack_size),
ESP_ELFSYM_EXPORT(tt_thread_set_affinity),
ESP_ELFSYM_EXPORT(tt_thread_set_callback),
ESP_ELFSYM_EXPORT(tt_thread_set_priority),
ESP_ELFSYM_EXPORT(tt_thread_set_state_callback),
@ -560,8 +494,8 @@ const esp_elfsym elf_symbols[] {
uintptr_t resolve_symbol(const esp_elfsym* source, const char* symbolName) {
const esp_elfsym* symbol_iterator = source;
while (symbol_iterator->name) {
if (!strcmp(symbol_iterator->name, symbolName)) {
while (symbol_iterator->name != nullptr) {
if (strcmp(symbol_iterator->name, symbolName) == 0) {
return reinterpret_cast<uintptr_t>(symbol_iterator->sym);
}
symbol_iterator++;
@ -570,11 +504,23 @@ uintptr_t resolve_symbol(const esp_elfsym* source, const char* symbolName) {
}
uintptr_t tt_symbol_resolver(const char* symbolName) {
uintptr_t address = resolve_symbol(elf_symbols, symbolName);
if (address != 0) {
return address;
static const std::vector all_symbols = {
main_symbols,
gcc_soft_float_symbols,
stl_symbols,
esp_event_symbols,
esp_http_client_symbols,
pthread_symbols
};
for (const auto* symbols : all_symbols) {
const uintptr_t address = resolve_symbol(symbols, symbolName);
if (address != 0) {
return address;
}
}
return resolve_symbol(gcc_soft_float_symbols, symbolName);
return 0;
}
void tt_init_tactility_c() {

View File

@ -1,4 +1,5 @@
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
extern "C" {
@ -14,4 +15,12 @@ void tt_lvgl_stop() {
tt::lvgl::stop();
}
void tt_lvgl_lock() {
tt::lvgl::getSyncLock()->lock();
}
void tt_lvgl_unlock() {
tt::lvgl::getSyncLock()->unlock();
}
}

View File

@ -18,7 +18,7 @@ ThreadHandle tt_thread_alloc_ext(
return new tt::Thread(
name,
stackSize,
[callback, callbackContext]() {
[callback, callbackContext] {
return callback(callbackContext);
}
);
@ -36,6 +36,10 @@ void tt_thread_set_stack_size(ThreadHandle handle, size_t size) {
HANDLE_AS_THREAD(handle)->setStackSize(size);
}
void tt_thread_set_affinity(ThreadHandle handle, int affinity) {
HANDLE_AS_THREAD(handle)->setAffinity(affinity);
}
void tt_thread_set_callback(ThreadHandle handle, ThreadCallback callback, void* _Nullable callbackContext) {
HANDLE_AS_THREAD(handle)->setMainFunction([callback, callbackContext]() {
return callback(callbackContext);

View File

@ -1,36 +1,10 @@
#pragma once
#include "LogMessages.h"
#include <array>
#include <memory>
#if not defined(ESP_PLATFORM) or (defined(CONFIG_SPIRAM_USE_MALLOC) && CONFIG_SPIRAM_USE_MALLOC == 1)
#define TT_LOG_ENTRY_COUNT 200
#define TT_LOG_MESSAGE_SIZE 128
#else
#define TT_LOG_ENTRY_COUNT 50
#define TT_LOG_MESSAGE_SIZE 50
#endif
#ifdef ESP_PLATFORM
#include "LogEsp.h"
#else
#include "LogSimulator.h"
#endif
#include "LogMessages.h"
#include "LogCommon.h"
namespace tt {
struct LogEntry {
LogLevel level = LogLevel::Verbose;
char message[TT_LOG_MESSAGE_SIZE] = { 0 };
};
/** Make a copy of the currently stored entries.
* The array size is TT_LOG_ENTRY_COUNT
* @param[out] outIndex the write index for the next log entry.
*/
std::unique_ptr<std::array<LogEntry, TT_LOG_ENTRY_COUNT>> copyLogEntries(std::size_t& outIndex);
} // namespace tt

View File

@ -3,6 +3,7 @@
#ifdef ESP_PLATFORM
#include <esp_log.h>
#include "Tactility/LogCommon.h"
#define TT_LOG_E(tag, format, ...) \
ESP_LOGE(tag, format, ##__VA_ARGS__)

View File

@ -97,6 +97,11 @@ public:
*/
void setStackSize(size_t stackSize);
/** Set CPU core pinning for this thread.
* @param[in] affinity -1 means not pinned, otherwise it's the core id (e.g. 0 or 1 on ESP32)
*/
void setAffinity(portBASE_TYPE affinity);
/** Set Thread callback
* @param[in] callback ThreadCallback, called upon thread run
* @param[in] callbackContext what to pass to the callback

View File

@ -1,50 +0,0 @@
#include "Tactility/Mutex.h"
#include <cstring>
#include <sstream>
namespace tt {
static std::array<LogEntry, TT_LOG_ENTRY_COUNT> logEntries;
static size_t nextLogEntryIndex;
/**
* This used to be a simple static value, but that crashes on device boot where early logging happens.
* For some unknown reason, the static Mutex instance wouldn't have their constructor called before
* the mutex is used.
*/
Mutex& getLogMutex() {
static Mutex* logMutex = nullptr;
if (logMutex == nullptr) {
logMutex = new Mutex();
}
return *logMutex;
}
void storeLog(LogLevel level, const char* format, va_list args) {
if (getLogMutex().lock(5 / portTICK_PERIOD_MS)) {
logEntries[nextLogEntryIndex].level = level;
vsnprintf(logEntries[nextLogEntryIndex].message, TT_LOG_MESSAGE_SIZE, format, args);
nextLogEntryIndex++;
if (nextLogEntryIndex == TT_LOG_ENTRY_COUNT) {
nextLogEntryIndex = 0;
}
getLogMutex().unlock();
}
}
std::unique_ptr<std::array<LogEntry, TT_LOG_ENTRY_COUNT>> copyLogEntries(std::size_t& outIndex) {
if (getLogMutex().lock(5 / portTICK_PERIOD_MS)) {
auto copy = std::make_unique<std::array<LogEntry, TT_LOG_ENTRY_COUNT>>(logEntries);
getLogMutex().unlock();
outIndex = nextLogEntryIndex;
return copy;
} else {
return nullptr;
}
}
} // namespace tt

View File

@ -1,24 +0,0 @@
#ifdef ESP_PLATFORM
#include "Tactility/LogCommon.h"
#include <esp_log.h>
namespace tt {
void storeLog(LogLevel level, const char* format, va_list args);
}
extern "C" {
extern void __real_esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...);
void __wrap_esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) {
va_list args;
va_start(args, format);
tt::storeLog((tt::LogLevel)level, format, args);
esp_log_writev(level, tag, format, args);
va_end(args);
}
}
#endif

View File

@ -9,8 +9,6 @@
namespace tt {
void storeLog(LogLevel level, const char* format, va_list args);
static char toPrefix(LogLevel level) {
using enum LogLevel;
switch (level) {
@ -81,10 +79,6 @@ void log(LogLevel level, const char* tag, const char* format, ...) {
va_start(args, format);
vprintf(buffer.str().c_str(), args);
va_end(args);
va_start(args, format);
tt::storeLog(level, buffer.str().c_str(), args);
va_end(args);
}
} // namespace tt

View File

@ -95,9 +95,14 @@ void Thread::setStackSize(size_t newStackSize) {
stackSize = newStackSize;
}
void Thread::setAffinity(portBASE_TYPE newAffinity) {
assert(state == State::Stopped);
affinity = newAffinity;
}
void Thread::setCallback(Callback callback, _Nullable void* callbackContext) {
assert(state == State::Stopped);
mainFunction = [callback, callbackContext]() {
mainFunction = [callback, callbackContext] {
return callback(callbackContext);
};
}