Various improvements (#21)
* T-Deck stability and naming improvements * allow main task to clean itself up * remove unused includes * various lvgl improvements * added docs
This commit is contained in:
committed by
GitHub
parent
a2f0399c9f
commit
7a7b31e426
+13
-27
@@ -1,45 +1,31 @@
|
||||
#include "tactility.h"
|
||||
#include "thread.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#define TAG "freertos"
|
||||
|
||||
#define mainQUEUE_RECEIVE_TASK_PRIORITY (tskIDLE_PRIORITY + 2)
|
||||
|
||||
_Noreturn void app_main();
|
||||
|
||||
bool lvgl_is_ready();
|
||||
void lvgl_task(void*);
|
||||
|
||||
void app_main_task(TT_UNUSED void* parameter) {
|
||||
while (!lvgl_is_ready()) {
|
||||
TT_LOG_I(TAG, "waiting for lvgl task");
|
||||
vTaskDelay(50);
|
||||
}
|
||||
void app_main();
|
||||
|
||||
static void main_task(TT_UNUSED void* parameter) {
|
||||
TT_LOG_I(TAG, "starting app_main()");
|
||||
app_main();
|
||||
TT_LOG_I(TAG, "returned from app_main()");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Create the main app loop, like ESP-IDF
|
||||
xTaskCreate(
|
||||
lvgl_task,
|
||||
"lvgl",
|
||||
BaseType_t task_result = xTaskCreate(
|
||||
main_task,
|
||||
"main",
|
||||
8192,
|
||||
NULL,
|
||||
mainQUEUE_RECEIVE_TASK_PRIORITY + 2,
|
||||
ThreadPriorityNormal,
|
||||
NULL
|
||||
);
|
||||
|
||||
xTaskCreate(
|
||||
app_main_task,
|
||||
"app_main",
|
||||
8192,
|
||||
NULL,
|
||||
mainQUEUE_RECEIVE_TASK_PRIORITY + 1,
|
||||
NULL
|
||||
);
|
||||
tt_assert(task_result == pdTRUE);
|
||||
|
||||
// Blocks forever
|
||||
vTaskStartScheduler();
|
||||
@@ -49,11 +35,11 @@ int main() {
|
||||
* Assert implementation as defined in the FreeRTOSConfig.h
|
||||
* It allows you to set breakpoints and debug asserts.
|
||||
*/
|
||||
void vAssertCalled(TT_UNUSED unsigned long line, TT_UNUSED const char* const file) {
|
||||
void vAssertCalled(unsigned long line, const char* const file) {
|
||||
static portBASE_TYPE xPrinted = pdFALSE;
|
||||
volatile uint32_t set_to_nonzero_in_debugger_to_continue = 0;
|
||||
|
||||
TT_LOG_E(TAG, "assert triggered");
|
||||
TT_LOG_E(TAG, "assert triggered at %s:%d", file, line);
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
// Step out by attaching a debugger and setting set_to_nonzero_in_debugger_to_continue
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
/**
|
||||
* Placeholder hardware config.
|
||||
* The real one happens during FreeRTOS startup. See freertos.c and lvgl_*.c
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include "hardware_config.h"
|
||||
#include "lvgl_task.h"
|
||||
#include <src/core/lv_obj.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TAG "hardware"
|
||||
|
||||
// TODO: See if we can move the init from FreeRTOS to app_main()?
|
||||
static bool init_lvgl() { return true; }
|
||||
static bool lvgl_init() {
|
||||
lv_init();
|
||||
lvgl_task_start();
|
||||
return true;
|
||||
}
|
||||
|
||||
TT_UNUSED static void lvgl_deinit() {
|
||||
lvgl_task_interrupt();
|
||||
while (lvgl_task_is_running()) {
|
||||
tt_delay_ms(10);
|
||||
}
|
||||
|
||||
#if LV_ENABLE_GC || !LV_MEM_CUSTOM
|
||||
lv_deinit();
|
||||
#endif
|
||||
}
|
||||
|
||||
HardwareConfig sim_hardware = {
|
||||
.bootstrap = NULL,
|
||||
.init_lvgl = &init_lvgl,
|
||||
.init_lvgl = &lvgl_init,
|
||||
};
|
||||
|
||||
|
||||
+14
-21
@@ -1,5 +1,3 @@
|
||||
#include "lvgl_hal.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "tactility_core.h"
|
||||
#include <sdl/sdl.h>
|
||||
@@ -8,16 +6,17 @@
|
||||
|
||||
#define BUFFER_SIZE (SDL_HOR_RES * SDL_VER_RES * 3)
|
||||
|
||||
static lv_disp_t* hal_init() {
|
||||
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
|
||||
lv_disp_t* lvgl_hal_init() {
|
||||
// Use the 'monitor' driver to simulate a display on PC
|
||||
// Note: this is part of lv_drivers and not SDL!
|
||||
sdl_init();
|
||||
|
||||
/*Create a display buffer*/
|
||||
// Create display buffer
|
||||
static lv_disp_draw_buf_t disp_buf1;
|
||||
static lv_color_t buf1_1[BUFFER_SIZE];
|
||||
lv_disp_draw_buf_init(&disp_buf1, buf1_1, NULL, BUFFER_SIZE);
|
||||
|
||||
/*Create a display*/
|
||||
// Create display
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
disp_drv.draw_buf = &disp_buf1;
|
||||
@@ -25,20 +24,20 @@ static lv_disp_t* hal_init() {
|
||||
disp_drv.hor_res = SDL_HOR_RES;
|
||||
disp_drv.ver_res = SDL_VER_RES;
|
||||
|
||||
lv_disp_t* disp = lv_disp_drv_register(&disp_drv);
|
||||
lv_disp_t* display = lv_disp_drv_register(&disp_drv);
|
||||
|
||||
lv_theme_t* th = lv_theme_default_init(
|
||||
disp,
|
||||
lv_theme_t* theme = lv_theme_default_init(
|
||||
display,
|
||||
lv_palette_main(LV_PALETTE_BLUE),
|
||||
lv_palette_main(LV_PALETTE_RED),
|
||||
LV_THEME_DEFAULT_DARK,
|
||||
LV_FONT_DEFAULT
|
||||
);
|
||||
|
||||
lv_disp_set_theme(disp, th);
|
||||
lv_disp_set_theme(display, theme);
|
||||
|
||||
lv_group_t* g = lv_group_create();
|
||||
lv_group_set_default(g);
|
||||
lv_group_t* group = lv_group_create();
|
||||
lv_group_set_default(group);
|
||||
|
||||
/* Add the mouse as input device
|
||||
* Use the 'mouse' driver which reads the PC's mouse*/
|
||||
@@ -55,21 +54,15 @@ static lv_disp_t* hal_init() {
|
||||
indev_drv_2.type = LV_INDEV_TYPE_KEYPAD;
|
||||
indev_drv_2.read_cb = sdl_keyboard_read;
|
||||
lv_indev_t* kb_indev = lv_indev_drv_register(&indev_drv_2);
|
||||
lv_indev_set_group(kb_indev, g);
|
||||
lv_indev_set_group(kb_indev, group);
|
||||
|
||||
static lv_indev_drv_t indev_drv_3;
|
||||
lv_indev_drv_init(&indev_drv_3); /*Basic initialization*/
|
||||
indev_drv_3.type = LV_INDEV_TYPE_ENCODER;
|
||||
indev_drv_3.read_cb = sdl_mousewheel_read;
|
||||
lv_indev_t* enc_indev = lv_indev_drv_register(&indev_drv_3);
|
||||
lv_indev_set_group(enc_indev, g);
|
||||
lv_indev_set_group(enc_indev, group);
|
||||
|
||||
return disp;
|
||||
return display;
|
||||
}
|
||||
|
||||
void lvgl_hal_init() {
|
||||
TT_LOG_I(TAG, "init: started");
|
||||
lv_init();
|
||||
hal_init();
|
||||
TT_LOG_I(TAG, "init: complete");
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void lvgl_hal_init();
|
||||
lv_disp_t* lvgl_hal_init();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+32
-30
@@ -1,5 +1,6 @@
|
||||
#include "lvgl_task.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "lvgl_hal.h"
|
||||
#include "tactility_core.h"
|
||||
#include "thread.h"
|
||||
@@ -18,6 +19,8 @@ static uint32_t task_max_sleep_ms = 10;
|
||||
static QueueHandle_t task_mutex = NULL;
|
||||
static bool task_running = false;
|
||||
|
||||
static void lvgl_task(TT_UNUSED void* arg);
|
||||
|
||||
static bool task_lock(int timeout_ticks) {
|
||||
assert(task_mutex != NULL);
|
||||
return xSemaphoreTakeRecursive(task_mutex, timeout_ticks) == pdTRUE;
|
||||
@@ -34,14 +37,14 @@ static void task_set_running(bool running) {
|
||||
task_unlock();
|
||||
}
|
||||
|
||||
static bool task_is_running() {
|
||||
bool lvgl_task_is_running() {
|
||||
assert(task_lock(configTICK_RATE_HZ / 100));
|
||||
bool result = task_running;
|
||||
task_unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool lvgl_lock(int timeout_ticks) {
|
||||
static bool lvgl_lock(uint32_t timeout_ticks) {
|
||||
assert(lvgl_mutex != NULL);
|
||||
return xSemaphoreTakeRecursive(lvgl_mutex, timeout_ticks) == pdTRUE;
|
||||
}
|
||||
@@ -51,7 +54,15 @@ static void lvgl_unlock() {
|
||||
xSemaphoreGiveRecursive(lvgl_mutex);
|
||||
}
|
||||
|
||||
static void lvgl_task_init() {
|
||||
void lvgl_task_interrupt() {
|
||||
tt_check(lvgl_lock(TtWaitForever));
|
||||
task_set_running(false); // interrupt task with boolean as flag
|
||||
lvgl_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();
|
||||
@@ -63,31 +74,30 @@ static void lvgl_task_init() {
|
||||
}
|
||||
|
||||
tt_lvgl_sync_set(&lvgl_lock, &lvgl_unlock);
|
||||
|
||||
// Create the main app loop, like ESP-IDF
|
||||
BaseType_t task_result = xTaskCreate(
|
||||
lvgl_task,
|
||||
"lvgl",
|
||||
8192,
|
||||
NULL,
|
||||
ThreadPriorityHigh, // Should be higher than main app task
|
||||
NULL
|
||||
);
|
||||
|
||||
tt_assert(task_result == pdTRUE);
|
||||
}
|
||||
|
||||
static void lvgl_task_deinit() {
|
||||
if (lvgl_mutex) {
|
||||
vSemaphoreDelete(lvgl_mutex);
|
||||
lvgl_mutex = NULL;
|
||||
}
|
||||
if (task_mutex) {
|
||||
vSemaphoreDelete(task_mutex);
|
||||
task_mutex = NULL;
|
||||
}
|
||||
#if LV_ENABLE_GC || !LV_MEM_CUSTOM
|
||||
lv_deinit();
|
||||
#endif
|
||||
}
|
||||
static void lvgl_task(TT_UNUSED void* arg) {
|
||||
TT_LOG_I(TAG, "lvgl task started");
|
||||
|
||||
void lvgl_task(TT_UNUSED void* arg) {
|
||||
lvgl_hal_init();
|
||||
lvgl_task_init();
|
||||
lv_disp_t* display = lvgl_hal_init();
|
||||
|
||||
uint32_t task_delay_ms = task_max_sleep_ms;
|
||||
|
||||
task_set_running(true);
|
||||
|
||||
while (task_is_running()) {
|
||||
while (lvgl_task_is_running()) {
|
||||
if (lvgl_lock(0)) {
|
||||
task_delay_ms = lv_timer_handler();
|
||||
lvgl_unlock();
|
||||
@@ -100,16 +110,8 @@ void lvgl_task(TT_UNUSED void* arg) {
|
||||
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
|
||||
}
|
||||
|
||||
lvgl_task_deinit();
|
||||
lv_disp_remove(display);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
bool lvgl_is_ready() {
|
||||
return task_running;
|
||||
}
|
||||
|
||||
void lvgl_interrupt() {
|
||||
tt_check(lvgl_lock(TtWaitForever));
|
||||
task_set_running(false); // interrupt task with boolean as flag
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool lvgl_is_ready();
|
||||
void lvgl_interrupt();
|
||||
void lvgl_task_start();
|
||||
bool lvgl_task_is_running();
|
||||
void lvgl_task_interrupt();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+1
-10
@@ -1,16 +1,13 @@
|
||||
#include "hello_world/hello_world.h"
|
||||
#include "lvgl_hal.h"
|
||||
#include "tactility.h"
|
||||
#include "ui/lvgl_sync.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#define TAG "main"
|
||||
|
||||
extern HardwareConfig sim_hardware;
|
||||
|
||||
_Noreturn void app_main() {
|
||||
void app_main() {
|
||||
static const Config config = {
|
||||
.hardware = &sim_hardware,
|
||||
.apps = {
|
||||
@@ -20,11 +17,5 @@ _Noreturn void app_main() {
|
||||
.auto_start_app_id = NULL
|
||||
};
|
||||
|
||||
TT_LOG_I("app", "Hello, world!");
|
||||
|
||||
tt_init(&config);
|
||||
|
||||
while (true) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user