C++ refactoring (#91)
This commit is contained in:
committed by
GitHub
parent
d06137ba76
commit
ca5d4b8226
@@ -1,6 +1,6 @@
|
||||
#include "Ui/Toolbar.h"
|
||||
#include "ui/Toolbar.h"
|
||||
|
||||
static void app_show(tt::App app, lv_obj_t* parent) {
|
||||
static void app_show(tt::app::App app, lv_obj_t* parent) {
|
||||
lv_obj_t* toolbar = tt::lvgl::toolbar_create(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
@@ -9,9 +9,9 @@ static void app_show(tt::App app, lv_obj_t* parent) {
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
|
||||
extern const tt::AppManifest hello_world_app = {
|
||||
extern const tt::app::Manifest hello_world_app = {
|
||||
.id = "HelloWorld",
|
||||
.name = "Hello World",
|
||||
.type = tt::AppTypeUser,
|
||||
.type = tt::app::TypeUser,
|
||||
.on_show = &app_show
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Hal/Configuration.h"
|
||||
#include "hal/Configuration.h"
|
||||
#include "lvgl_task.h"
|
||||
#include "src/lv_init.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "lvgl.h"
|
||||
#include "Ui/LvglKeypad.h"
|
||||
#include "ui/LvglKeypad.h"
|
||||
|
||||
lv_display_t* lvgl_hal_init() {
|
||||
static lv_display_t* display = NULL;
|
||||
|
||||
+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();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Tactility.h"
|
||||
|
||||
extern const tt::hal::Configuration sim_hardware;
|
||||
extern const tt::AppManifest hello_world_app;
|
||||
extern const tt::app::Manifest hello_world_app;
|
||||
|
||||
void app_main() {
|
||||
static const tt::Configuration config = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Hal/Power.h"
|
||||
#include "hal/Power.h"
|
||||
|
||||
static bool is_charging_enabled = false;
|
||||
|
||||
@@ -23,9 +23,9 @@ static int32_t power_get_current() {
|
||||
}
|
||||
|
||||
extern const tt::hal::Power power = {
|
||||
.is_charging = &power_is_charging,
|
||||
.is_charging_enabled = &power_is_charging_enabled,
|
||||
.set_charging_enabled = &power_set_charging_enabled,
|
||||
.get_charge_level = &power_get_charge_level,
|
||||
.get_current = &power_get_current
|
||||
.isCharging = &power_is_charging,
|
||||
.isChargingEnabled = &power_is_charging_enabled,
|
||||
.setChargingEnabled = &power_set_charging_enabled,
|
||||
.getChargeLevel = &power_get_charge_level,
|
||||
.getCurrent = &power_get_current
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user