TactilityC improvements (#359)

- Expose HAL Configuration's `UiScale`
- Updated docs
- Fix for `tt_timer_alloc()`
- Changed `enum class` to regular C `enum`
- Renamed enums (add prefix)
- Include `<stdbool.h>` where needed
This commit is contained in:
Ken Van Hoeylandt
2025-10-05 18:31:54 +02:00
committed by GitHub
parent 3802679de4
commit 15de4e20b8
16 changed files with 117 additions and 26 deletions
+13
View File
@@ -0,0 +1,13 @@
#include "tt_hal.h"
#include <Tactility/Tactility.h>
#include <Tactility/hal/Configuration.h>
extern "C" {
UiScale tt_hal_configuration_get_ui_scale() {
auto scale = tt::hal::getConfiguration()->uiScale;
return static_cast<UiScale>(scale);
}
}
+2
View File
@@ -7,6 +7,7 @@
#include "tt_bundle.h"
#include "tt_file.h"
#include "tt_gps.h"
#include "tt_hal.h"
#include "tt_hal_device.h"
#include "tt_hal_display.h"
#include "tt_hal_gpio.h"
@@ -183,6 +184,7 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_bundle_put_string),
ESP_ELFSYM_EXPORT(tt_gps_has_coordinates),
ESP_ELFSYM_EXPORT(tt_gps_get_coordinates),
ESP_ELFSYM_EXPORT(tt_hal_configuration_get_ui_scale),
ESP_ELFSYM_EXPORT(tt_hal_device_find),
ESP_ELFSYM_EXPORT(tt_hal_display_driver_alloc),
ESP_ELFSYM_EXPORT(tt_hal_display_driver_draw_bitmap),
+13 -11
View File
@@ -5,42 +5,44 @@ struct TimerWrapper {
std::unique_ptr<tt::Timer> timer;
};
#define HANDLE_TO_WRAPPER(handle) static_cast<TimerWrapper*>(handle)
extern "C" {
TimerHandle tt_timer_alloc(TimerType type, TimerCallback callback, void* callbackContext) {
auto wrapper = std::make_shared<TimerWrapper>();
wrapper->timer = std::make_unique<tt::Timer>((tt::Timer::Type)type, [callback, callbackContext](){ callback(callbackContext); });
return wrapper.get();
auto wrapper = new TimerWrapper;
wrapper->timer = std::make_unique<tt::Timer>(static_cast<tt::Timer::Type>(type), [callback, callbackContext](){ callback(callbackContext); });
return wrapper;
}
void tt_timer_free(TimerHandle handle) {
auto* wrapper = (TimerWrapper*)handle;
auto* wrapper = static_cast<TimerWrapper*>(handle);
wrapper->timer = nullptr;
delete wrapper;
}
bool tt_timer_start(TimerHandle handle, TickType_t intervalTicks) {
return ((TimerWrapper*)handle)->timer->start(intervalTicks);
return HANDLE_TO_WRAPPER(handle)->timer->start(intervalTicks);
}
bool tt_timer_restart(TimerHandle handle, TickType_t intervalTicks) {
return ((TimerWrapper*)handle)->timer->restart(intervalTicks);
return HANDLE_TO_WRAPPER(handle)->timer->restart(intervalTicks);
}
bool tt_timer_stop(TimerHandle handle) {
return ((TimerWrapper*)handle)->timer->stop();
return HANDLE_TO_WRAPPER(handle)->timer->stop();
}
bool tt_timer_is_running(TimerHandle handle) {
return ((TimerWrapper*)handle)->timer->isRunning();
return HANDLE_TO_WRAPPER(handle)->timer->isRunning();
}
uint32_t tt_timer_get_expire_time(TimerHandle handle) {
return ((TimerWrapper*)handle)->timer->getExpireTime();
return HANDLE_TO_WRAPPER(handle)->timer->getExpireTime();
}
bool tt_timer_set_pending_callback(TimerHandle handle, TimerPendingCallback callback, void* callbackContext, uint32_t callbackArg, TickType_t timeoutTicks) {
return ((TimerWrapper*)handle)->timer->setPendingCallback(
return HANDLE_TO_WRAPPER(handle)->timer->setPendingCallback(
callback,
callbackContext,
callbackArg,
@@ -49,7 +51,7 @@ bool tt_timer_set_pending_callback(TimerHandle handle, TimerPendingCallback call
}
void tt_timer_set_thread_priority(TimerHandle handle, ThreadPriority priority) {
((TimerWrapper*)handle)->timer->setThreadPriority((tt::Thread::Priority)priority);
HANDLE_TO_WRAPPER(handle)->timer->setThreadPriority(static_cast<tt::Thread::Priority>(priority));
}
}