Merge develop into main (#365)

### TactilityC
- Create UART HAL
- Refactor locking APIs
- Bind new C++ functionality
- Bind new LVGL functionality

### Apps
- Remove Serial Console as it has been ported as an external app
This commit is contained in:
Ken Van Hoeylandt
2025-10-08 23:16:45 +02:00
committed by GitHub
parent 17b4fc6a47
commit d25603166a
26 changed files with 391 additions and 702 deletions
+18
View File
@@ -0,0 +1,18 @@
#include <private/elf_symbol.h>
#include <cstddef>
#include <symbols/cplusplus.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)
extern void __cxa_pure_virtual();
}
const esp_elfsym cplusplus_symbols[] = {
ESP_ELFSYM_EXPORT(_Znwj), // operator new(unsigned int)
ESP_ELFSYM_EXPORT(_ZdlPvj), // operator delete(void*, unsigned int)
ESP_ELFSYM_EXPORT(__cxa_pure_virtual), // class-related, see https://arobenko.github.io/bare_metal_cpp/
// delimiter
ESP_ELFSYM_END
};
+6
View File
@@ -1,4 +1,8 @@
#include <private/elf_symbol.h>
#include <cstddef>
#include <symbols/esp_event.h>
#include <esp_event.h>
const esp_elfsym esp_event_symbols[] = {
@@ -19,4 +23,6 @@ const esp_elfsym esp_event_symbols[] = {
ESP_ELFSYM_EXPORT(esp_event_post_to),
ESP_ELFSYM_EXPORT(esp_event_isr_post),
ESP_ELFSYM_EXPORT(esp_event_isr_post_to),
// delimiter
ESP_ELFSYM_END
};
@@ -1,4 +1,8 @@
#include <private/elf_symbol.h>
#include <cstddef>
#include <symbols/esp_http_client.h>
#include <esp_http_client.h>
const esp_elfsym esp_http_client_symbols[] = {
@@ -43,4 +47,6 @@ const esp_elfsym esp_http_client_symbols[] = {
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),
// delimiter
ESP_ELFSYM_END
};
+6 -2
View File
@@ -1,6 +1,10 @@
#include <cstdlib>
#include <private/elf_symbol.h>
#include <cstddef>
#include <symbols/gcc_soft_float.h>
#include <cstdlib>
// Reference: https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html
extern "C" {
@@ -139,7 +143,7 @@ int __gtsf2(float a, float b);
int __gtdf2(double a, double b);
// int __gttf2(long double a, long double b);
}
} // extern "C"
const esp_elfsym gcc_soft_float_symbols[] = {
ESP_ELFSYM_EXPORT(__addsf3),
+6
View File
@@ -1,4 +1,8 @@
#include <private/elf_symbol.h>
#include <cstddef>
#include <symbols/pthread.h>
#include <pthread.h>
const esp_elfsym pthread_symbols[] = {
@@ -8,4 +12,6 @@ const esp_elfsym pthread_symbols[] = {
ESP_ELFSYM_EXPORT(pthread_detach),
ESP_ELFSYM_EXPORT(pthread_join),
ESP_ELFSYM_EXPORT(pthread_exit),
// delimiter
ESP_ELFSYM_END
};
+8 -9
View File
@@ -1,18 +1,17 @@
#include <private/elf_symbol.h>
#include <cstddef>
#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) },
{ "_ZSt17__throw_bad_allocv", (void*)&(std::__throw_bad_alloc) },
{ "_ZSt28__throw_bad_array_new_lengthv", (void*)&(std::__throw_bad_array_new_length) },
{ "_ZSt17__throw_bad_allocv", (void*)&(std::__throw_bad_alloc) }
{ "_ZSt25__throw_bad_function_callv", (void*)&(std::__throw_bad_function_call) },
{ "_ZSt20__throw_length_errorPKc", (void*)&(std::__throw_length_error) },
// { "", (void*)&(std::) },
// delimiter
ESP_ELFSYM_END
};
-13
View File
@@ -1,13 +0,0 @@
#include <tt_file.h>
#include <tt_lock_private.h>
#include <Tactility/file/File.h>
extern "C" {
LockHandle tt_lock_alloc_for_file(const char* path) {
auto lock = tt::file::getLock(path);
auto holder = new LockHolder(lock);
return holder;
}
}
+82
View File
@@ -0,0 +1,82 @@
#include "tt_hal_uart.h"
#include <Tactility/hal/uart/Uart.h>
using namespace tt::hal;
struct UartWrapper {
std::shared_ptr<uart::Uart> uart;
};
#define HANDLE_AS_UART(handle) static_cast<UartWrapper*>(handle)->uart
extern "C" {
size_t tt_hal_uart_get_count() {
return uart::getNames().size();
}
bool tt_hal_uart_get_name(size_t index, char* name, size_t nameSizeLimit) {
assert(index < uart::getNames().size());
auto source_name = uart::getNames()[index];
return strncpy(name, source_name.c_str(), nameSizeLimit) != nullptr;
}
UartHandle tt_hal_uart_alloc(size_t index) {
assert(index < uart::getNames().size());
auto* wrapper = new UartWrapper();
auto name = uart::getNames()[index];
wrapper->uart = uart::open(name);
assert(wrapper->uart != nullptr);
return wrapper;
}
void tt_hal_uart_free(UartHandle handle) {
auto* wrapper = static_cast<UartWrapper*>(handle);
assert(wrapper->uart != nullptr);
if (wrapper->uart->isStarted()) {
wrapper->uart->stop();
}
delete wrapper;
}
bool tt_hal_uart_start(UartHandle handle) {
return HANDLE_AS_UART(handle)->start();
}
bool tt_hal_uart_is_started(UartHandle handle) {
return HANDLE_AS_UART(handle)->isStarted();
}
bool tt_hal_uart_stop(UartHandle handle) {
return HANDLE_AS_UART(handle)->stop();
}
size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize, TickType timeout) {
return HANDLE_AS_UART(handle)->readBytes(reinterpret_cast<std::byte*>(buffer), bufferSize, timeout);
}
bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType timeout) {
return HANDLE_AS_UART(handle)->readByte(reinterpret_cast<std::byte*>(output), timeout);
}
size_t tt_hal_uart_write_bytes(UartHandle handle, const char* buffer, size_t bufferSize, TickType timeout) {
return HANDLE_AS_UART(handle)->writeBytes(reinterpret_cast<const std::byte*>(buffer), bufferSize, timeout);
}
size_t tt_hal_uart_available(UartHandle handle) {
return HANDLE_AS_UART(handle)->available();
}
bool tt_hal_uart_set_baud_rate(UartHandle handle, size_t baud_rate) {
return HANDLE_AS_UART(handle)->setBaudRate(baud_rate);
}
uint32_t tt_hal_uart_get_baud_rate(UartHandle handle) {
return HANDLE_AS_UART(handle)->getBaudRate();
}
void tt_hal_uart_flush_input(UartHandle handle) {
HANDLE_AS_UART(handle)->flushInput();
}
}
+34 -11
View File
@@ -4,7 +4,6 @@
#include "tt_app_alertdialog.h"
#include "tt_app_selectiondialog.h"
#include "tt_bundle.h"
#include "tt_file.h"
#include "tt_gps.h"
#include "tt_hal.h"
#include "tt_hal_device.h"
@@ -12,13 +11,14 @@
#include "tt_hal_gpio.h"
#include "tt_hal_i2c.h"
#include "tt_hal_touch.h"
#include "tt_hal_uart.h"
#include "tt_kernel.h"
#include <tt_lock.h>
#include "tt_lvgl.h"
#include "tt_lvgl_keyboard.h"
#include "tt_lvgl_spinner.h"
#include "tt_lvgl_toolbar.h"
#include "tt_message_queue.h"
#include "tt_mutex.h"
#include "tt_preferences.h"
#include "tt_semaphore.h"
#include "tt_thread.h"
@@ -31,6 +31,7 @@
#include "symbols/gcc_soft_float.h"
#include "symbols/pthread.h"
#include "symbols/stl.h"
#include "symbols/cplusplus.h"
#include <cstring>
#include <ctype.h>
@@ -57,6 +58,8 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(rand),
ESP_ELFSYM_EXPORT(srand),
ESP_ELFSYM_EXPORT(rand_r),
ESP_ELFSYM_EXPORT(atoi),
ESP_ELFSYM_EXPORT(atol),
// esp random
ESP_ELFSYM_EXPORT(esp_random),
ESP_ELFSYM_EXPORT(esp_fill_random),
@@ -169,7 +172,8 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_app_get_user_data_child_path),
ESP_ELFSYM_EXPORT(tt_app_get_assets_path),
ESP_ELFSYM_EXPORT(tt_app_get_assets_child_path),
ESP_ELFSYM_EXPORT(tt_lock_alloc_for_file),
ESP_ELFSYM_EXPORT(tt_lock_alloc_mutex),
ESP_ELFSYM_EXPORT(tt_lock_alloc_for_path),
ESP_ELFSYM_EXPORT(tt_lock_acquire),
ESP_ELFSYM_EXPORT(tt_lock_release),
ESP_ELFSYM_EXPORT(tt_lock_free),
@@ -215,6 +219,20 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_alloc),
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_free),
ESP_ELFSYM_EXPORT(tt_hal_touch_driver_get_touched_points),
ESP_ELFSYM_EXPORT(tt_hal_uart_get_count),
ESP_ELFSYM_EXPORT(tt_hal_uart_get_name),
ESP_ELFSYM_EXPORT(tt_hal_uart_alloc),
ESP_ELFSYM_EXPORT(tt_hal_uart_free),
ESP_ELFSYM_EXPORT(tt_hal_uart_start),
ESP_ELFSYM_EXPORT(tt_hal_uart_is_started),
ESP_ELFSYM_EXPORT(tt_hal_uart_stop),
ESP_ELFSYM_EXPORT(tt_hal_uart_read_bytes),
ESP_ELFSYM_EXPORT(tt_hal_uart_read_byte),
ESP_ELFSYM_EXPORT(tt_hal_uart_write_bytes),
ESP_ELFSYM_EXPORT(tt_hal_uart_available),
ESP_ELFSYM_EXPORT(tt_hal_uart_set_baud_rate),
ESP_ELFSYM_EXPORT(tt_hal_uart_get_baud_rate),
ESP_ELFSYM_EXPORT(tt_hal_uart_flush_input),
ESP_ELFSYM_EXPORT(tt_kernel_delay_millis),
ESP_ELFSYM_EXPORT(tt_kernel_delay_micros),
ESP_ELFSYM_EXPORT(tt_kernel_delay_ticks),
@@ -252,10 +270,6 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_message_queue_get_message_size),
ESP_ELFSYM_EXPORT(tt_message_queue_get_count),
ESP_ELFSYM_EXPORT(tt_message_queue_reset),
ESP_ELFSYM_EXPORT(tt_mutex_alloc),
ESP_ELFSYM_EXPORT(tt_mutex_free),
ESP_ELFSYM_EXPORT(tt_mutex_lock),
ESP_ELFSYM_EXPORT(tt_mutex_unlock),
ESP_ELFSYM_EXPORT(tt_preferences_alloc),
ESP_ELFSYM_EXPORT(tt_preferences_free),
ESP_ELFSYM_EXPORT(tt_preferences_opt_bool),
@@ -322,9 +336,12 @@ const esp_elfsym main_symbols[] {
// lv_obj
ESP_ELFSYM_EXPORT(lv_color_hex),
ESP_ELFSYM_EXPORT(lv_color_make),
ESP_ELFSYM_EXPORT(lv_obj_clean),
ESP_ELFSYM_EXPORT(lv_obj_create),
ESP_ELFSYM_EXPORT(lv_obj_delete),
ESP_ELFSYM_EXPORT(lv_obj_add_event_cb),
ESP_ELFSYM_EXPORT(lv_obj_add_flag),
ESP_ELFSYM_EXPORT(lv_obj_add_state),
ESP_ELFSYM_EXPORT(lv_obj_align),
ESP_ELFSYM_EXPORT(lv_obj_align_to),
ESP_ELFSYM_EXPORT(lv_obj_get_parent),
@@ -337,11 +354,11 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(lv_obj_get_content_width),
ESP_ELFSYM_EXPORT(lv_obj_get_content_height),
ESP_ELFSYM_EXPORT(lv_obj_center),
ESP_ELFSYM_EXPORT(lv_obj_remove_event_cb),
ESP_ELFSYM_EXPORT(lv_obj_get_user_data),
ESP_ELFSYM_EXPORT(lv_obj_set_user_data),
ESP_ELFSYM_EXPORT(lv_obj_remove_event_cb),
ESP_ELFSYM_EXPORT(lv_obj_remove_flag),
ESP_ELFSYM_EXPORT(lv_obj_add_flag),
ESP_ELFSYM_EXPORT(lv_obj_remove_state),
ESP_ELFSYM_EXPORT(lv_obj_set_pos),
ESP_ELFSYM_EXPORT(lv_obj_set_flex_align),
ESP_ELFSYM_EXPORT(lv_obj_set_flex_flow),
@@ -442,6 +459,9 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(lv_dropdown_get_option_count),
ESP_ELFSYM_EXPORT(lv_dropdown_get_option_index),
ESP_ELFSYM_EXPORT(lv_dropdown_get_options),
ESP_ELFSYM_EXPORT(lv_dropdown_get_selected),
ESP_ELFSYM_EXPORT(lv_dropdown_get_selected_str),
ESP_ELFSYM_EXPORT(lv_dropdown_get_selected_highlight),
ESP_ELFSYM_EXPORT(lv_dropdown_set_dir),
ESP_ELFSYM_EXPORT(lv_dropdown_set_options),
ESP_ELFSYM_EXPORT(lv_dropdown_set_options_static),
@@ -462,6 +482,8 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(lv_textarea_get_label),
ESP_ELFSYM_EXPORT(lv_textarea_get_max_length),
ESP_ELFSYM_EXPORT(lv_textarea_get_one_line),
ESP_ELFSYM_EXPORT(lv_textarea_get_text),
ESP_ELFSYM_EXPORT(lv_textarea_get_text_selection),
ESP_ELFSYM_EXPORT(lv_textarea_set_one_line),
ESP_ELFSYM_EXPORT(lv_textarea_set_accepted_chars),
ESP_ELFSYM_EXPORT(lv_textarea_set_align),
@@ -526,9 +548,10 @@ uintptr_t tt_symbol_resolver(const char* symbolName) {
main_symbols,
gcc_soft_float_symbols,
stl_symbols,
cplusplus_symbols,
esp_event_symbols,
esp_http_client_symbols,
pthread_symbols
pthread_symbols,
};
for (const auto* symbols : all_symbols) {
@@ -545,7 +568,7 @@ void tt_init_tactility_c() {
elf_set_symbol_resolver(tt_symbol_resolver);
}
}
} // extern "C"
#else // Simulator
+27 -5
View File
@@ -1,20 +1,42 @@
#include <tt_lock.h>
#include <tt_lock_private.h>
#include <Tactility/Mutex.h>
#include <Tactility/file/File.h>
#define HANDLE_AS_LOCK(handle) (static_cast<LockHolder*>(handle)->lock)
extern "C" {
LockHandle tt_lock_alloc_mutex(TtMutexType type) {
auto* lock_holder = new LockHolder();
switch (type) {
case MutexTypeNormal:
lock_holder->lock = std::make_shared<tt::Mutex>(tt::Mutex::Type::Normal);
break;
case MutexTypeRecursive:
lock_holder->lock = std::make_shared<tt::Mutex>(tt::Mutex::Type::Recursive);
break;
default:
tt_crash("Type not supported");
}
return lock_holder;
}
LockHandle tt_lock_alloc_for_path(const char* path) {
const auto lock = tt::file::getLock(path);
return new LockHolder(lock);
}
bool tt_lock_acquire(LockHandle handle, TickType timeout) {
auto holder = static_cast<LockHolder*>(handle);
return holder->lock->lock(timeout);
return HANDLE_AS_LOCK(handle)->lock(timeout);
}
bool tt_lock_release(LockHandle handle) {
auto holder = static_cast<LockHolder*>(handle);
return holder->lock->unlock();
return HANDLE_AS_LOCK(handle)->unlock();
}
void tt_lock_free(LockHandle handle) {
auto holder = static_cast<LockHolder*>(handle);
const auto holder = static_cast<LockHolder*>(handle);
delete holder;
}
+3 -2
View File
@@ -1,3 +1,4 @@
#include <tt_kernel.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
@@ -15,8 +16,8 @@ void tt_lvgl_stop() {
tt::lvgl::stop();
}
void tt_lvgl_lock() {
tt::lvgl::getSyncLock()->lock();
void tt_lvgl_lock(TickType timeout) {
tt::lvgl::getSyncLock()->lock(timeout);
}
void tt_lvgl_unlock() {
-31
View File
@@ -1,31 +0,0 @@
#include "tt_mutex.h"
#include <Tactility/Mutex.h>
extern "C" {
#define HANDLE_AS_MUTEX(handle) ((tt::Mutex*)(handle))
MutexHandle tt_mutex_alloc(TtMutexType type) {
switch (type) {
case MUTEX_TYPE_NORMAL:
return new tt::Mutex(tt::Mutex::Type::Normal);
case MUTEX_TYPE_RECURSIVE:
return new tt::Mutex(tt::Mutex::Type::Recursive);
default:
tt_crash("Type not supported");
}
}
void tt_mutex_free(MutexHandle handle) {
delete HANDLE_AS_MUTEX(handle);
}
bool tt_mutex_lock(MutexHandle handle, TickType timeout) {
return HANDLE_AS_MUTEX(handle)->lock(timeout);
}
bool tt_mutex_unlock(MutexHandle handle) {
return HANDLE_AS_MUTEX(handle)->unlock();
}
}