mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
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:
parent
25b0aa09e2
commit
88c5c55be3
@ -108,14 +108,15 @@ static bool prv_create_display(nb_display_t* display) {
|
||||
display->vertical_resolution = VERTICAL_RESOLUTION;
|
||||
display->draw_buffer_height = DRAW_BUFFER_HEIGHT;
|
||||
display->bits_per_pixel = BITS_PER_PIXEL;
|
||||
display->mirror_x = true;
|
||||
display->mirror_y = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
nb_display_driver_t board_2432s024_create_display_driver() {
|
||||
nb_display_driver_t driver = {
|
||||
return (nb_display_driver_t) {
|
||||
.name = "ili9341_2432s024",
|
||||
.create_display = &prv_create_display
|
||||
};
|
||||
return driver;
|
||||
}
|
||||
|
||||
@ -65,9 +65,8 @@ static bool prv_create_touch(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch
|
||||
}
|
||||
|
||||
nb_touch_driver_t board_2432s024_create_touch_driver() {
|
||||
nb_touch_driver_t driver = {
|
||||
return (nb_touch_driver_t) {
|
||||
.name = "cst816s_2432s024",
|
||||
.create_touch = &prv_create_touch
|
||||
};
|
||||
return driver;
|
||||
}
|
||||
|
||||
@ -146,7 +146,6 @@ FURI_NORETURN void __furi_crash_implementation() {
|
||||
// Check if debug enabled by DAP
|
||||
// https://developer.arm.com/documentation/ddi0403/d/Debug-Architecture/ARMv7-M-Debug/Debug-register-support-in-the-SCS/Debug-Halting-Control-and-Status-Register--DHCSR?lang=en
|
||||
// bool debug = CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
|
||||
bool debug = true;
|
||||
#ifdef FURI_NDEBUG
|
||||
if(debug) {
|
||||
#endif
|
||||
|
||||
@ -37,7 +37,7 @@ FURI_NORETURN void __furi_halt_implementation();
|
||||
/** Crash system with message. */
|
||||
#define __furi_crash(message) \
|
||||
do { \
|
||||
ESP_LOGE("crash", "%s\n\tat %s:%d", (message) ? (message) : "", __FILE__, __LINE__); \
|
||||
ESP_LOGE("crash", "%s\n\tat %s:%d", ((message) ? ((const char*)message) : ""), __FILE__, __LINE__); \
|
||||
__furi_crash_implementation(); \
|
||||
} while(0)
|
||||
|
||||
@ -50,7 +50,7 @@ FURI_NORETURN void __furi_halt_implementation();
|
||||
/** Halt system with message. */
|
||||
#define __furi_halt(message) \
|
||||
do { \
|
||||
ESP_LOGE("halt", "%s\n\tat %s:%d", (message) ? (message) : "", __FILE__, __LINE__); \
|
||||
ESP_LOGE("halt", "%s\n\tat %s:%d", ((message) ? ((const char*)message) : ""), __FILE__, __LINE__); \
|
||||
__furi_halt_implementation(); \
|
||||
} while(0)
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ static void furi_thread_body(void* context) {
|
||||
furi_assert(thread->state == FuriThreadStateStarting);
|
||||
furi_thread_set_state(thread, FuriThreadStateRunning);
|
||||
|
||||
TaskHandle_t task_handle = xTaskGetCurrentTaskHandle();
|
||||
// TaskHandle_t task_handle = xTaskGetCurrentTaskHandle();
|
||||
// if(thread->heap_trace_enabled == true) {
|
||||
// memmgr_heap_enable_thread_trace((FuriThreadId)task_handle);
|
||||
// }
|
||||
|
||||
@ -2,14 +2,17 @@
|
||||
|
||||
#include "nb_hardware.h"
|
||||
#include "nb_app.h"
|
||||
#include "nb_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void nanobake_start(nb_config_t _Nonnull * config);
|
||||
|
||||
// Forward declarations
|
||||
typedef void* FuriThreadId;
|
||||
typedef struct nb_lvgl nb_lvgl_t;
|
||||
|
||||
extern void nanobake_start(nb_config_t _Nonnull * config);
|
||||
|
||||
extern FuriThreadId nanobake_get_app_thread_id(size_t index);
|
||||
extern size_t nanobake_get_app_thread_count();
|
||||
|
||||
@ -18,7 +18,8 @@ struct nb_config {
|
||||
// Optional driver for touch input
|
||||
const create_touch_driver _Nullable touch_driver;
|
||||
// List of user applications
|
||||
const nb_app_t* apps[];
|
||||
const size_t apps_count;
|
||||
const nb_app_t* const apps[];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -15,6 +15,8 @@ struct nb_display {
|
||||
uint16_t bits_per_pixel;
|
||||
esp_lcd_panel_io_handle_t _Nonnull io_handle;
|
||||
esp_lcd_panel_handle_t _Nonnull display_handle;
|
||||
bool mirror_x;
|
||||
bool mirror_y;
|
||||
};
|
||||
|
||||
typedef struct nb_display_driver nb_display_driver_t;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "nb_config.h"
|
||||
#include <lvgl.h>
|
||||
#include "nb_display.h"
|
||||
#include "nb_touch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -13,12 +13,6 @@ struct nb_hardware {
|
||||
nb_touch_t* _Nullable touch;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param[in] config
|
||||
* @return a newly allocated platform instance (caller takes ownership)
|
||||
*/
|
||||
nb_hardware_t _Nonnull* nb_hardware_alloc(nb_config_t _Nonnull* config);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <esp_lvgl_port.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -12,10 +12,6 @@ struct nb_lvgl {
|
||||
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
|
||||
@ -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);
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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
components/nanobake/src/nb_hardwarei.h
Normal file
14
components/nanobake/src/nb_hardwarei.h
Normal 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
|
||||
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
15
components/nanobake/src/nb_lvgli.h
Normal file
15
components/nanobake/src/nb_lvgli.h
Normal 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
|
||||
@ -1,9 +1,10 @@
|
||||
#include "hello_world.h"
|
||||
#include "core_defines.h"
|
||||
#include <core_defines.h>
|
||||
|
||||
#include "esp_lvgl_port.h"
|
||||
#include <nb_lvgl.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
#include <esp_log.h>
|
||||
#include "nb_hardware.h"
|
||||
#include <nb_hardware.h>
|
||||
|
||||
static const char* TAG = "app_helloworld";
|
||||
|
||||
@ -13,22 +14,24 @@ static void prv_on_button_click(lv_event_t _Nonnull* event) {
|
||||
|
||||
static int32_t prv_on_create(void* param) {
|
||||
UNUSED(param);
|
||||
// lvgl_port_lock(0);
|
||||
//
|
||||
// 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_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
// lv_label_set_text(label, "Hello, world!");
|
||||
// lv_obj_align(label, LV_ALIGN_CENTER, 0, -30);
|
||||
//
|
||||
// lv_obj_t* btn = lv_btn_create(lv_parent);
|
||||
// label = lv_label_create(btn);
|
||||
// lv_label_set_text_static(label, "Button");
|
||||
// lv_obj_align(btn, LV_ALIGN_CENTER, 0, 30);
|
||||
// lv_obj_add_event_cb(btn, prv_on_button_click, LV_EVENT_CLICKED, NULL);
|
||||
//
|
||||
// lvgl_port_unlock();
|
||||
lvgl_port_lock(0);
|
||||
|
||||
lv_obj_t* lv_parent = lv_scr_act();
|
||||
|
||||
lv_obj_t* label = lv_label_create(lv_parent);
|
||||
lv_label_set_recolor(label, true);
|
||||
lv_obj_set_width(label, 200);
|
||||
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_label_set_text(label, "Hello, world!");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -30);
|
||||
|
||||
lv_obj_t* btn = lv_btn_create(lv_parent);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text_static(label, "Button");
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 30);
|
||||
lv_obj_add_event_cb(btn, prv_on_button_click, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
lvgl_port_unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -8,13 +8,14 @@
|
||||
#include "hello_world/hello_world.h"
|
||||
|
||||
void app_main(void) {
|
||||
static nb_config_t platform_config = {
|
||||
static nb_config_t config = {
|
||||
.display_driver = &board_2432s024_create_display_driver,
|
||||
.touch_driver = &board_2432s024_create_touch_driver,
|
||||
.apps = {
|
||||
&hello_world_app
|
||||
}
|
||||
},
|
||||
.apps_count = 1
|
||||
};
|
||||
|
||||
nanobake_start(&platform_config);
|
||||
nanobake_start(&config);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user