C++ refactoring (#91)
This commit is contained in:
committed by
GitHub
parent
d06137ba76
commit
ca5d4b8226
+13
-27
@@ -5,30 +5,28 @@
|
||||
#include "lvgl_hal.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "Thread.h"
|
||||
#include "Ui/LvglSync.h"
|
||||
#include "ui/LvglSync.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
#define TAG "lvgl_task"
|
||||
|
||||
// Mutex for LVGL drawing
|
||||
static QueueHandle_t lvgl_mutex = NULL;
|
||||
static tt::Mutex lvgl_mutex(tt::MutexTypeRecursive);
|
||||
static tt::Mutex task_mutex(tt::MutexTypeRecursive);
|
||||
|
||||
static uint32_t task_max_sleep_ms = 10;
|
||||
// Mutex for LVGL task state (to modify task_running state)
|
||||
static QueueHandle_t task_mutex = NULL;
|
||||
static bool task_running = false;
|
||||
|
||||
static void lvgl_task(void* arg);
|
||||
|
||||
static bool task_lock(int timeout_ticks) {
|
||||
assert(task_mutex != NULL);
|
||||
return xSemaphoreTakeRecursive(task_mutex, timeout_ticks) == pdTRUE;
|
||||
return task_mutex.acquire(timeout_ticks) == tt::TtStatusOk;
|
||||
}
|
||||
|
||||
static void task_unlock() {
|
||||
assert(task_mutex != NULL);
|
||||
xSemaphoreGiveRecursive(task_mutex);
|
||||
task_mutex.release();
|
||||
}
|
||||
|
||||
static void task_set_running(bool running) {
|
||||
@@ -45,35 +43,23 @@ bool lvgl_task_is_running() {
|
||||
}
|
||||
|
||||
static bool lvgl_lock(uint32_t timeout_ticks) {
|
||||
assert(lvgl_mutex != NULL);
|
||||
return xSemaphoreTakeRecursive(lvgl_mutex, timeout_ticks) == pdTRUE;
|
||||
return lvgl_mutex.acquire(timeout_ticks) == tt::TtStatusOk;
|
||||
}
|
||||
|
||||
static void lvgl_unlock() {
|
||||
assert(lvgl_mutex != NULL);
|
||||
xSemaphoreGiveRecursive(lvgl_mutex);
|
||||
lvgl_mutex.release();
|
||||
}
|
||||
|
||||
void lvgl_task_interrupt() {
|
||||
tt_check(lvgl_lock(tt::TtWaitForever));
|
||||
tt_check(task_lock(tt::TtWaitForever));
|
||||
task_set_running(false); // interrupt task with boolean as flag
|
||||
lvgl_unlock();
|
||||
task_unlock();
|
||||
}
|
||||
|
||||
void lvgl_task_start() {
|
||||
TT_LOG_I(TAG, "lvgl task starting");
|
||||
|
||||
if (lvgl_mutex == NULL) {
|
||||
TT_LOG_D(TAG, "init: creating lvgl mutex");
|
||||
lvgl_mutex = xSemaphoreCreateRecursiveMutex();
|
||||
}
|
||||
|
||||
if (task_mutex == NULL) {
|
||||
TT_LOG_D(TAG, "init: creating task mutex");
|
||||
task_mutex = xSemaphoreCreateRecursiveMutex();
|
||||
}
|
||||
|
||||
tt::lvgl::sync_set(&lvgl_lock, &lvgl_unlock);
|
||||
tt::lvgl::syncSet(&lvgl_lock, &lvgl_unlock);
|
||||
|
||||
// Create the main app loop, like ESP-IDF
|
||||
BaseType_t task_result = xTaskCreate(
|
||||
@@ -98,7 +84,7 @@ static void lvgl_task(TT_UNUSED void* arg) {
|
||||
task_set_running(true);
|
||||
|
||||
while (lvgl_task_is_running()) {
|
||||
if (lvgl_lock(0)) {
|
||||
if (lvgl_lock(10)) {
|
||||
task_delay_ms = lv_timer_handler();
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user