cleanup and improvements

improved driver creation
fixed compile warnings in check.h
hello_world example is now working again with lvgl
This commit is contained in:
Ken Van Hoeylandt
2023-12-26 23:04:40 +01:00
parent 25b0aa09e2
commit 88c5c55be3
20 changed files with 138 additions and 108 deletions
@@ -22,7 +22,7 @@ const nb_app_t* const FLIPPER_SYSTEM_APPS[] = {
const size_t FLIPPER_SYSTEM_APPS_COUNT = sizeof(FLIPPER_SYSTEM_APPS) / sizeof(nb_app_t*);
const FlipperInternalOnStartHook FLIPPER_ON_SYSTEM_START[] = {
const nb_on_system_start_ FLIPPER_ON_SYSTEM_START[] = {
};
const size_t FLIPPER_ON_SYSTEM_START_COUNT = sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(FlipperInternalOnStartHook);
const size_t FLIPPER_ON_SYSTEM_START_COUNT = sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(nb_on_system_start_);
@@ -6,7 +6,10 @@
extern "C" {
#endif
typedef void (*FlipperInternalOnStartHook)(void);
// Forward declaration
typedef struct nb_hardware nb_hardware_t;
typedef void (*nb_on_system_start_)(nb_hardware_t* hardware);
extern const nb_app_t* const FLIPPER_SERVICES[];
extern const size_t FLIPPER_SERVICES_COUNT;
@@ -14,7 +17,7 @@ extern const size_t FLIPPER_SERVICES_COUNT;
extern const nb_app_t* const FLIPPER_SYSTEM_APPS[];
extern const size_t FLIPPER_SYSTEM_APPS_COUNT;
extern const FlipperInternalOnStartHook FLIPPER_ON_SYSTEM_START[];
extern const nb_on_system_start_ FLIPPER_ON_SYSTEM_START[];
extern const size_t FLIPPER_ON_SYSTEM_START_COUNT;
#ifdef __cplusplus
@@ -16,7 +16,7 @@ static int32_t prv_desktop_main(void* param) {
//
// lv_obj_t* label = lv_label_create(lv_parent);
// lv_label_set_recolor(label, true);
// lv_obj_set_width(label, (lv_coord_t)platform->display->horizontal_resolution);
// lv_obj_set_width(label, (lv_coord_t)hardware->display->horizontal_resolution);
// lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_LEFT, 0);
// lv_label_set_text(label, "Desktop app");
// lv_obj_align(label, LV_ALIGN_TOP_LEFT, 0, 0);
+25 -26
View File
@@ -1,6 +1,6 @@
#include "nanobake.h"
#include "nb_hardware.h"
#include "nb_lvgl.h"
#include "nb_hardwarei.h"
#include "nb_lvgli.h"
#include "applications/nb_applications.h"
#include <esp_log.h>
#include <m-list.h>
@@ -10,10 +10,11 @@
#include <record.h>
#include <check.h>
static const char* TAG = "nanobake";
M_LIST_DEF(thread_ids, FuriThreadId);
static const char* TAG = "nanobake";
thread_ids_t prv_thread_ids;
static void prv_furi_init() {
// TODO: can we remove the suspend-resume logic?
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
@@ -25,8 +26,6 @@ static void prv_furi_init() {
xTaskResumeAll();
}
thread_ids_t prv_thread_ids;
FuriThreadId nanobake_get_app_thread_id(size_t index) {
return *thread_ids_get(prv_thread_ids, index);
}
@@ -38,8 +37,8 @@ size_t nanobake_get_app_thread_count() {
extern void nanobake_start(nb_config_t _Nonnull* config) {
prv_furi_init();
nb_hardware_t _Nonnull* hardware = nb_hardware_alloc(config);
nb_lvgl_init(hardware);
nb_hardware_t hardware = nb_hardware_create(config);
nb_lvgl_t lvgl = nb_lvgl_init(&hardware);
thread_ids_init(prv_thread_ids);
@@ -81,24 +80,24 @@ extern void nanobake_start(nb_config_t _Nonnull* config) {
thread_ids_push_back(prv_thread_ids, thread_id);
}
// ESP_LOGI(TAG, "Starting external apps");
//
// size_t external_apps_count = sizeof(*config->apps);
// for(size_t i = 0; i < FLIPPER_SERVICES_COUNT; i++) {
// ESP_LOGI(TAG, "Starting external app \"%s\"", FLIPPER_[i]->name);
//
// FuriThread* thread = furi_thread_alloc_ex(
// FLIPPER_SERVICES[i]->name,
// FLIPPER_SERVICES[i]->stack_size,
// FLIPPER_SERVICES[i]->entry_point,
// NULL
// );
// furi_thread_set_appid(thread, FLIPPER_SERVICES[i]->id);
// furi_thread_start(thread);
//
// FuriThreadId thread_id = furi_thread_get_id(thread);
// thread_ids_push_back(prv_thread_ids, thread_id);
// }
ESP_LOGI(TAG, "Starting external apps");
for(size_t i = 0; i < config->apps_count; i++) {
const nb_app_t* app = config->apps[i];
ESP_LOGI(TAG, "Starting external app \"%s\"", app->name);
FuriThread* thread = furi_thread_alloc_ex(
app->name,
app->stack_size,
app->entry_point,
NULL
);
furi_thread_set_appid(thread, app->id);
furi_thread_start(thread);
FuriThreadId thread_id = furi_thread_get_id(thread);
thread_ids_push_back(prv_thread_ids, thread_id);
}
ESP_LOGI(TAG, "Startup complete");
}
+10 -13
View File
@@ -1,32 +1,29 @@
#include "nb_hardware.h"
#include "nb_display.h"
#include "nb_touch.h"
#include "nb_hardwarei.h"
#include <esp_check.h>
#include <esp_err.h>
#include <esp_lvgl_port.h>
#include <check.h>
static const char* TAG = "nb_hardware";
nb_hardware_t _Nonnull* nb_hardware_alloc(nb_config_t _Nonnull* config) {
nb_hardware_t* platform = malloc(sizeof(nb_hardware_t));
nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config) {
furi_check(config->display_driver != NULL, "no display driver configured");
nb_display_driver_t display_driver = config->display_driver();
ESP_LOGI(TAG, "display with driver %s", display_driver.name);
platform->display = nb_display_alloc(&display_driver);
nb_display_t* display = nb_display_alloc(&display_driver);
nb_touch_t* touch = NULL;
if (config->touch_driver != NULL) {
nb_touch_driver_t touch_driver = config->touch_driver();
ESP_LOGI(TAG, "touch with driver %s", touch_driver.name);
platform->touch = nb_touch_alloc(&touch_driver);
touch = nb_touch_alloc(&touch_driver);
} else {
ESP_LOGI(TAG, "no touch configured");
platform->touch = NULL;
touch = NULL;
}
return platform;
return (nb_hardware_t) {
.display = display,
.touch = touch
};
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include "nb_hardware.h"
#include "nb_config.h"
#ifdef __cplusplus
extern "C" {
#endif
extern nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config);
#ifdef __cplusplus
}
#endif
+21 -18
View File
@@ -1,13 +1,11 @@
#include "nb_lvgl.h"
#include "nb_hardware.h"
#include <esp_check.h>
#include "nb_lvgli.h"
#include "nb_hardwarei.h"
#include <esp_lvgl_port.h>
#include <check.h>
static const char* TAG = "nb_lvgl";
nb_lvgl_t nb_lvgl_init(nb_hardware_t* platform) {
nb_lvgl_t lvgl;
nb_lvgl_t nb_lvgl_init(nb_hardware_t _Nonnull* hardware) {
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = 4,
.task_stack = 4096,
@@ -15,8 +13,10 @@ nb_lvgl_t nb_lvgl_init(nb_hardware_t* platform) {
.task_max_sleep_ms = 500,
.timer_period_ms = 5
};
furi_check(lvgl_port_init(&lvgl_cfg) == ESP_OK, "lvgl port init failed");
nb_display_t _Nonnull* display = platform->display;
nb_display_t _Nonnull* display = hardware->display;
// Add display
ESP_LOGD(TAG, "lvgl add display");
const lvgl_port_display_cfg_t disp_cfg = {
@@ -27,28 +27,31 @@ nb_lvgl_t nb_lvgl_init(nb_hardware_t* platform) {
.hres = display->horizontal_resolution,
.vres = display->vertical_resolution,
.monochrome = false,
/* Rotation values must be same as defined in driver */
// TODO: expose data from driver
.rotation = {
.swap_xy = false,
.mirror_x = true,
.mirror_y = false,
.mirror_x = display->mirror_x,
.mirror_y = display->mirror_y,
},
.flags = {
.buff_dma = true,
}
};
lvgl.disp = lvgl_port_add_disp(&disp_cfg);
lv_disp_t _Nonnull* disp = lvgl_port_add_disp(&disp_cfg);
lv_indev_t _Nullable* touch_indev = NULL;
// Add touch
if (platform->touch != NULL) {
if (hardware->touch != NULL) {
const lvgl_port_touch_cfg_t touch_cfg = {
.disp = lvgl.disp,
.handle = platform->touch->touch_handle,
.disp = disp,
.handle = hardware->touch->touch_handle,
};
lvgl.touch_indev = lvgl_port_add_touch(&touch_cfg);
furi_check(lvgl.touch_indev != NULL, "failed to add touch to lvgl");
touch_indev = lvgl_port_add_touch(&touch_cfg);
furi_check(touch_indev != NULL, "failed to add touch to lvgl");
}
return lvgl;
return (nb_lvgl_t) {
.disp = disp,
.touch_indev = touch_indev
};
}
-21
View File
@@ -1,21 +0,0 @@
#pragma once
#include <esp_lvgl_port.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct nb_lvgl nb_lvgl_t;
struct nb_lvgl {
lv_disp_t* _Nonnull disp;
lv_indev_t* _Nullable touch_indev;
};
typedef struct nb_hardware nb_hardware_t;
extern nb_lvgl_t nb_lvgl_init(nb_hardware_t* platform);
#ifdef __cplusplus
}
#endif
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include "nb_lvgl.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct nb_hardware nb_hardware_t;
extern nb_lvgl_t nb_lvgl_init(nb_hardware_t _Nonnull* hardware);
#ifdef __cplusplus
}
#endif