mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
code style aligned with furi lib
This commit is contained in:
parent
f4088f5762
commit
34a067c2b1
@ -4,5 +4,5 @@ During the pre-alpha stage, contributions will not yet be considered.
|
|||||||
|
|
||||||
# Code Style
|
# Code Style
|
||||||
|
|
||||||
See [github.com/MaJerle/c-code-style](https://github.com/MaJerle/c-code-style).
|
See [this document](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/CODING_STYLE.md).
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ IRAM_ATTR static bool prv_on_color_trans_done(esp_lcd_panel_io_handle_t io_handl
|
|||||||
return (need_yield == pdTRUE);
|
return (need_yield == pdTRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool prv_create_display(nb_display_t* display) {
|
static bool prv_create_display(NbDisplay* display) {
|
||||||
ESP_LOGI(TAG, "creating display");
|
ESP_LOGI(TAG, "creating display");
|
||||||
|
|
||||||
gpio_config_t io_conf = {
|
gpio_config_t io_conf = {
|
||||||
@ -122,8 +122,8 @@ static bool prv_create_display(nb_display_t* display) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nb_display_driver_t board_2432s024_create_display_driver() {
|
NbDisplayDriver board_2432s024_create_display_driver() {
|
||||||
return (nb_display_driver_t) {
|
return (NbDisplayDriver) {
|
||||||
.name = "ili9341_2432s024",
|
.name = "ili9341_2432s024",
|
||||||
.create_display = &prv_create_display
|
.create_display = &prv_create_display
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <nb_display.h>
|
#include <nb_display.h>
|
||||||
|
|
||||||
extern nb_display_driver_t board_2432s024_create_display_driver();
|
extern NbDisplayDriver board_2432s024_create_display_driver();
|
||||||
|
|
||||||
#endif //NANOBAKE_BOARD_2432S024_DISPLAY_H
|
#endif //NANOBAKE_BOARD_2432S024_DISPLAY_H
|
||||||
|
|||||||
@ -64,8 +64,8 @@ static bool prv_create_touch(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nb_touch_driver_t board_2432s024_create_touch_driver() {
|
NbTouchDriver board_2432s024_create_touch_driver() {
|
||||||
return (nb_touch_driver_t) {
|
return (NbTouchDriver) {
|
||||||
.name = "cst816s_2432s024",
|
.name = "cst816s_2432s024",
|
||||||
.create_touch = &prv_create_touch
|
.create_touch = &prv_create_touch
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <nb_touch.h>
|
#include <nb_touch.h>
|
||||||
|
|
||||||
nb_touch_driver_t board_2432s024_create_touch_driver();
|
NbTouchDriver board_2432s024_create_touch_driver();
|
||||||
|
|
||||||
#endif // NANOBAKE_BOARD_2432S024_TOUCH_H
|
#endif // NANOBAKE_BOARD_2432S024_TOUCH_H
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
#include "nb_applications.h"
|
#include "nb_applications.h"
|
||||||
|
|
||||||
// System services
|
// System services
|
||||||
extern const nb_app_t desktop_app;
|
extern const NbApp desktop_app;
|
||||||
extern const nb_app_t gui_app;
|
extern const NbApp gui_app;
|
||||||
extern const nb_app_t loader_app;
|
extern const NbApp loader_app;
|
||||||
|
|
||||||
// System apps
|
// System apps
|
||||||
extern const nb_app_t system_info_app;
|
extern const NbApp system_info_app;
|
||||||
|
|
||||||
const nb_app_t* const FLIPPER_SERVICES[] = {
|
const NbApp* const FLIPPER_SERVICES[] = {
|
||||||
&desktop_app,
|
&desktop_app,
|
||||||
&gui_app,
|
&gui_app,
|
||||||
&loader_app
|
&loader_app
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t FLIPPER_SERVICES_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(nb_app_t*);
|
const size_t FLIPPER_SERVICES_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(NbApp*);
|
||||||
|
|
||||||
const nb_app_t* const FLIPPER_SYSTEM_APPS[] = {
|
const NbApp* const FLIPPER_SYSTEM_APPS[] = {
|
||||||
&system_info_app
|
&system_info_app
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t FLIPPER_SYSTEM_APPS_COUNT = sizeof(FLIPPER_SYSTEM_APPS) / sizeof(nb_app_t*);
|
const size_t FLIPPER_SYSTEM_APPS_COUNT = sizeof(FLIPPER_SYSTEM_APPS) / sizeof(NbApp*);
|
||||||
|
|
||||||
const nb_on_system_start_ FLIPPER_ON_SYSTEM_START[] = {
|
const NbOnSystemStart FLIPPER_ON_SYSTEM_START[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t FLIPPER_ON_SYSTEM_START_COUNT = sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(nb_on_system_start_);
|
const size_t FLIPPER_ON_SYSTEM_START_COUNT = sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(NbOnSystemStart);
|
||||||
|
|||||||
@ -1,23 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "nb_app.h"
|
#include "nb_app.h"
|
||||||
|
#include "nb_hardware.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Forward declaration
|
typedef void (*NbOnSystemStart)(NbHardware* hardware);
|
||||||
typedef struct nb_hardware nb_hardware_t;
|
|
||||||
|
|
||||||
typedef void (*nb_on_system_start_)(nb_hardware_t* hardware);
|
extern const NbApp* const FLIPPER_SERVICES[];
|
||||||
|
|
||||||
extern const nb_app_t* const FLIPPER_SERVICES[];
|
|
||||||
extern const size_t FLIPPER_SERVICES_COUNT;
|
extern const size_t FLIPPER_SERVICES_COUNT;
|
||||||
|
|
||||||
extern const nb_app_t* const FLIPPER_SYSTEM_APPS[];
|
extern const NbApp* const FLIPPER_SYSTEM_APPS[];
|
||||||
extern const size_t FLIPPER_SYSTEM_APPS_COUNT;
|
extern const size_t FLIPPER_SYSTEM_APPS_COUNT;
|
||||||
|
|
||||||
extern const nb_on_system_start_ FLIPPER_ON_SYSTEM_START[];
|
extern const NbOnSystemStart FLIPPER_ON_SYSTEM_START[];
|
||||||
extern const size_t FLIPPER_ON_SYSTEM_START_COUNT;
|
extern const size_t FLIPPER_ON_SYSTEM_START_COUNT;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -8,7 +8,7 @@ static int32_t prv_desktop_main(void* param) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nb_app_t desktop_app = {
|
const NbApp desktop_app = {
|
||||||
.id = "desktop",
|
.id = "desktop",
|
||||||
.name = "Desktop",
|
.name = "Desktop",
|
||||||
.type = SERVICE,
|
.type = SERVICE,
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const nb_app_t desktop_app;
|
extern const NbApp desktop_app;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,55 +1,36 @@
|
|||||||
#include "gui.h"
|
#include "gui_i.h"
|
||||||
#include "core_defines.h"
|
#include "core_defines.h"
|
||||||
#include <record.h>
|
#include <record.h>
|
||||||
#include <mutex.h>
|
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
#include <m-dict.h>
|
|
||||||
#include <m-core.h>
|
|
||||||
|
|
||||||
typedef struct screen screen_t;
|
static ScreenId screen_counter = 0;
|
||||||
struct screen {
|
|
||||||
screen_id_t id;
|
|
||||||
lv_obj_t* parent;
|
|
||||||
on_init_lvgl _Nonnull callback;
|
|
||||||
};
|
|
||||||
|
|
||||||
static screen_id_t screen_counter = 0;
|
NbGuiHandle gui_alloc() {
|
||||||
|
struct NbGui* gui = malloc(sizeof(struct NbGui));
|
||||||
DICT_DEF2(screen_dict, screen_id_t, M_BASIC_OPLIST, screen_t, M_POD_OPLIST)
|
|
||||||
|
|
||||||
typedef struct Gui Gui;
|
|
||||||
struct Gui {
|
|
||||||
// TODO: use mutex
|
|
||||||
FuriMutex* mutex;
|
|
||||||
screen_dict_t screens;
|
|
||||||
};
|
|
||||||
|
|
||||||
Gui* gui_alloc() {
|
|
||||||
Gui* gui = malloc(sizeof(Gui));
|
|
||||||
screen_dict_init(gui->screens);
|
screen_dict_init(gui->screens);
|
||||||
gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_free(Gui* gui) {
|
void gui_free(NbGuiHandle gui) {
|
||||||
screen_dict_clear(gui->screens);
|
screen_dict_clear(gui->screens);
|
||||||
furi_mutex_free(gui->mutex);
|
furi_mutex_free(gui->mutex);
|
||||||
free(gui);
|
free(gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_lock(Gui* gui) {
|
void gui_lock(NbGuiHandle gui) {
|
||||||
furi_assert(gui);
|
furi_assert(gui);
|
||||||
furi_check(furi_mutex_acquire(gui->mutex, FuriWaitForever) == FuriStatusOk);
|
furi_check(furi_mutex_acquire(gui->mutex, FuriWaitForever) == FuriStatusOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_unlock(Gui* gui) {
|
void gui_unlock(NbGuiHandle gui) {
|
||||||
furi_assert(gui);
|
furi_assert(gui);
|
||||||
furi_check(furi_mutex_release(gui->mutex) == FuriStatusOk);
|
furi_check(furi_mutex_release(gui->mutex) == FuriStatusOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback) {
|
ScreenId gui_screen_create(NbGuiHandle gui, InitScreen callback) {
|
||||||
screen_id_t id = screen_counter++;
|
ScreenId id = screen_counter++;
|
||||||
screen_t screen = {
|
NbScreen screen = {
|
||||||
.id = id,
|
.id = id,
|
||||||
.parent = NULL,
|
.parent = NULL,
|
||||||
.callback = callback
|
.callback = callback
|
||||||
@ -68,20 +49,20 @@ screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback) {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t* gui_screen_get_parent(Gui* gui, screen_id_t id) {
|
lv_obj_t* gui_screen_get_parent(NbGuiHandle gui, ScreenId id) {
|
||||||
screen_t* screen = screen_dict_get(gui->screens, id);
|
NbScreen* screen = screen_dict_get(gui->screens, id);
|
||||||
furi_check(screen != NULL);
|
furi_check(screen != NULL);
|
||||||
return screen->parent;
|
return screen->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_screen_set_parent(Gui* gui, screen_id_t id, lv_obj_t* parent) {
|
void gui_screen_set_parent(NbGuiHandle gui, ScreenId id, lv_obj_t* parent) {
|
||||||
screen_t* screen = screen_dict_get(gui->screens, id);
|
NbScreen* screen = screen_dict_get(gui->screens, id);
|
||||||
furi_check(screen != NULL);
|
furi_check(screen != NULL);
|
||||||
screen->parent = parent;
|
screen->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_screen_free(Gui* gui, screen_id_t id) {
|
void gui_screen_free(NbGuiHandle gui, ScreenId id) {
|
||||||
screen_t* screen = screen_dict_get(gui->screens, id);
|
NbScreen* screen = screen_dict_get(gui->screens, id);
|
||||||
furi_check(screen != NULL);
|
furi_check(screen != NULL);
|
||||||
|
|
||||||
// TODO: notify? use callback? (done from desktop service)
|
// TODO: notify? use callback? (done from desktop service)
|
||||||
@ -93,13 +74,13 @@ void gui_screen_free(Gui* gui, screen_id_t id) {
|
|||||||
static int32_t prv_gui_main(void* param) {
|
static int32_t prv_gui_main(void* param) {
|
||||||
UNUSED(param);
|
UNUSED(param);
|
||||||
|
|
||||||
Gui* gui = gui_alloc();
|
struct NbGui* gui = gui_alloc();
|
||||||
furi_record_create(RECORD_GUI, gui);
|
furi_record_create(RECORD_GUI, gui);
|
||||||
printf("gui app init\n");
|
printf("gui app init\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nb_app_t gui_app = {
|
const NbApp gui_app = {
|
||||||
.id = "gui",
|
.id = "gui",
|
||||||
.name = "GUI",
|
.name = "GUI",
|
||||||
.type = SERVICE,
|
.type = SERVICE,
|
||||||
|
|||||||
@ -8,18 +8,18 @@ extern "C" {
|
|||||||
|
|
||||||
#define RECORD_GUI "gui"
|
#define RECORD_GUI "gui"
|
||||||
|
|
||||||
typedef uint16_t screen_id_t;
|
typedef uint16_t ScreenId;
|
||||||
|
|
||||||
typedef struct Gui Gui;
|
typedef struct NbGui* NbGuiHandle;
|
||||||
typedef void (*on_init_lvgl)(lv_obj_t*, screen_id_t);
|
typedef void (*InitScreen)(lv_obj_t*, ScreenId);
|
||||||
|
|
||||||
screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback);
|
ScreenId gui_screen_create(NbGuiHandle _Nonnull gui, InitScreen callback);
|
||||||
void gui_screen_free(Gui* gui, screen_id_t id);
|
void gui_screen_free(NbGuiHandle _Nonnull gui, ScreenId id);
|
||||||
// TODO make internal
|
// TODO make internal
|
||||||
void gui_screen_set_parent(Gui* gui, screen_id_t id, lv_obj_t* parent);
|
void gui_screen_set_parent(NbGuiHandle _Nonnull gui, ScreenId id, lv_obj_t* parent);
|
||||||
lv_obj_t* gui_screen_get_parent(Gui* gui, screen_id_t id);
|
lv_obj_t* gui_screen_get_parent(NbGuiHandle _Nonnull gui, ScreenId id);
|
||||||
|
|
||||||
extern const nb_app_t gui_app;
|
extern const NbApp gui_app;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
20
components/nanobake/src/applications/services/gui/gui_i.h
Normal file
20
components/nanobake/src/applications/services/gui/gui_i.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "gui.h"
|
||||||
|
#include <mutex.h>
|
||||||
|
#include <m-dict.h>
|
||||||
|
#include <m-core.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ScreenId id;
|
||||||
|
lv_obj_t* parent;
|
||||||
|
InitScreen _Nonnull callback;
|
||||||
|
} NbScreen;
|
||||||
|
|
||||||
|
DICT_DEF2(screen_dict, ScreenId, M_BASIC_OPLIST, NbScreen, M_POD_OPLIST)
|
||||||
|
|
||||||
|
struct NbGui {
|
||||||
|
// TODO: use mutex
|
||||||
|
FuriMutex* mutex;
|
||||||
|
screen_dict_t screens;
|
||||||
|
};
|
||||||
@ -7,7 +7,7 @@ static int32_t prv_loader_main(void* param) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nb_app_t loader_app = {
|
const NbApp loader_app = {
|
||||||
.id = "loader",
|
.id = "loader",
|
||||||
.name = "Loader",
|
.name = "Loader",
|
||||||
.type = SERVICE,
|
.type = SERVICE,
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const nb_app_t loader_app;
|
extern const NbApp loader_app;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ static int32_t system_info_entry_point(void* param) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nb_app_t system_info_app = {
|
NbApp system_info_app = {
|
||||||
.id = "systeminfo",
|
.id = "systeminfo",
|
||||||
.name = "System Info",
|
.name = "System Info",
|
||||||
.type = SYSTEM,
|
.type = SYSTEM,
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern nb_app_t system_info_app;
|
extern NbApp system_info_app;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "nanobake.h"
|
#include "nanobake.h"
|
||||||
#include "nb_hardwarei.h"
|
#include "nb_hardware_i.h"
|
||||||
#include "nb_lvgli.h"
|
#include "nb_lvgl_i.h"
|
||||||
#include "nb_appi.h"
|
#include "nb_app_i.h"
|
||||||
#include "applications/nb_applications.h"
|
#include "applications/nb_applications.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <m-list.h>
|
#include <m-list.h>
|
||||||
@ -34,7 +34,7 @@ size_t nanobake_get_app_thread_count() {
|
|||||||
return thread_ids_size(prv_thread_ids);
|
return thread_ids_size(prv_thread_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prv_start_app(const nb_app_t _Nonnull* app) {
|
static void prv_start_app(const NbApp _Nonnull* app) {
|
||||||
ESP_LOGI(TAG, "Starting %s app \"%s\"",
|
ESP_LOGI(TAG, "Starting %s app \"%s\"",
|
||||||
nb_app_type_to_string(app->type),
|
nb_app_type_to_string(app->type),
|
||||||
app->name
|
app->name
|
||||||
@ -58,11 +58,11 @@ static void prv_start_app(const nb_app_t _Nonnull* app) {
|
|||||||
thread_ids_push_back(prv_thread_ids, thread_id);
|
thread_ids_push_back(prv_thread_ids, thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused)) extern void nanobake_start(nb_config_t _Nonnull* config) {
|
__attribute__((unused)) extern void nanobake_start(NbConfig _Nonnull* config) {
|
||||||
prv_furi_init();
|
prv_furi_init();
|
||||||
|
|
||||||
nb_hardware_t hardware = nb_hardware_create(config);
|
NbHardware hardware = nb_hardware_create(config);
|
||||||
/*nb_lvgl_t lvgl =*/ nb_lvgl_init(&hardware);
|
/*NbLvgl lvgl =*/ nb_lvgl_init(&hardware);
|
||||||
|
|
||||||
thread_ids_init(prv_thread_ids);
|
thread_ids_init(prv_thread_ids);
|
||||||
|
|
||||||
|
|||||||
@ -10,9 +10,8 @@ extern "C" {
|
|||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
typedef void* FuriThreadId;
|
typedef void* FuriThreadId;
|
||||||
typedef struct nb_lvgl nb_lvgl_t;
|
|
||||||
|
|
||||||
__attribute__((unused)) extern void nanobake_start(nb_config_t _Nonnull * config);
|
__attribute__((unused)) extern void nanobake_start(NbConfig _Nonnull * config);
|
||||||
|
|
||||||
extern FuriThreadId nanobake_get_app_thread_id(size_t index);
|
extern FuriThreadId nanobake_get_app_thread_id(size_t index);
|
||||||
extern size_t nanobake_get_app_thread_count();
|
extern size_t nanobake_get_app_thread_count();
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
#include "nb_appi.h"
|
#include "nb_app_i.h"
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
|
||||||
const char* prv_type_service = "service";
|
const char* prv_type_service = "service";
|
||||||
const char* prv_type_system = "system";
|
const char* prv_type_system = "system";
|
||||||
const char* prv_type_user = "user";
|
const char* prv_type_user = "user";
|
||||||
|
|
||||||
const char* nb_app_type_to_string(nb_app_type_t type) {
|
const char* nb_app_type_to_string(NbAppType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SERVICE:
|
case SERVICE:
|
||||||
return prv_type_service;
|
return prv_type_service;
|
||||||
|
|||||||
@ -11,26 +11,22 @@ extern "C" {
|
|||||||
#define NB_APP_ID_LENGTH 32
|
#define NB_APP_ID_LENGTH 32
|
||||||
#define NB_APP_NAME_LENGTH 32
|
#define NB_APP_NAME_LENGTH 32
|
||||||
|
|
||||||
typedef enum nb_app_type nb_app_type_t;
|
typedef enum {
|
||||||
|
|
||||||
enum nb_app_type {
|
|
||||||
SERVICE,
|
SERVICE,
|
||||||
SYSTEM,
|
SYSTEM,
|
||||||
USER
|
USER
|
||||||
};
|
} NbAppType;
|
||||||
|
|
||||||
typedef struct nb_app nb_app_t;
|
typedef int32_t (*NbAppEntryPoint) (void _Nonnull* parameter);
|
||||||
|
|
||||||
typedef int32_t (*nb_app_entry_point) (void _Nonnull* parameter);
|
typedef struct {
|
||||||
|
|
||||||
struct nb_app {
|
|
||||||
const char id[NB_APP_ID_LENGTH];
|
const char id[NB_APP_ID_LENGTH];
|
||||||
const char name[NB_APP_NAME_LENGTH];
|
const char name[NB_APP_NAME_LENGTH];
|
||||||
const nb_app_type_t type;
|
const NbAppType type;
|
||||||
const nb_app_entry_point _Nullable entry_point;
|
const NbAppEntryPoint _Nullable entry_point;
|
||||||
const size_t stack_size;
|
const size_t stack_size;
|
||||||
const uint32_t priority;
|
const uint32_t priority;
|
||||||
};
|
} NbApp;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const char* nb_app_type_to_string(nb_app_type_t type);
|
extern const char* nb_app_type_to_string(NbAppType type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -8,19 +8,18 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef nb_touch_driver_t (*create_touch_driver)();
|
typedef NbTouchDriver (*CreateTouchDriver)();
|
||||||
typedef nb_display_driver_t (*create_display_driver)();
|
typedef NbDisplayDriver (*CreateDisplayDriver)();
|
||||||
|
|
||||||
typedef struct nb_config nb_config_t;
|
typedef struct {
|
||||||
struct nb_config {
|
|
||||||
// Required driver for display
|
// Required driver for display
|
||||||
const create_display_driver _Nonnull display_driver;
|
const CreateDisplayDriver _Nonnull display_driver;
|
||||||
// Optional driver for touch input
|
// Optional driver for touch input
|
||||||
const create_touch_driver _Nullable touch_driver;
|
const CreateTouchDriver _Nullable touch_driver;
|
||||||
// List of user applications
|
// List of user applications
|
||||||
const size_t apps_count;
|
const size_t apps_count;
|
||||||
const nb_app_t* const apps[];
|
const NbApp* const apps[];
|
||||||
};
|
} NbConfig;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#include "nb_display.h"
|
#include "nb_display.h"
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
|
||||||
nb_display_t _Nonnull* nb_display_alloc(nb_display_driver_t _Nonnull* driver) {
|
NbDisplay _Nonnull* nb_display_alloc(NbDisplayDriver _Nonnull* driver) {
|
||||||
nb_display_t _Nonnull* display = malloc(sizeof(nb_display_t));
|
NbDisplay _Nonnull* display = malloc(sizeof(NbDisplay));
|
||||||
memset(display, 0, sizeof(nb_display_t));
|
memset(display, 0, sizeof(NbDisplay));
|
||||||
furi_check(driver->create_display(display), "failed to create display");
|
furi_check(driver->create_display(display), "failed to create display");
|
||||||
furi_check(display->io_handle != NULL);
|
furi_check(display->io_handle != NULL);
|
||||||
furi_check(display->display_handle != NULL);
|
furi_check(display->display_handle != NULL);
|
||||||
|
|||||||
@ -6,9 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct nb_display nb_display_t;
|
typedef struct {
|
||||||
|
|
||||||
struct nb_display {
|
|
||||||
uint16_t horizontal_resolution;
|
uint16_t horizontal_resolution;
|
||||||
uint16_t vertical_resolution;
|
uint16_t vertical_resolution;
|
||||||
uint16_t draw_buffer_height;
|
uint16_t draw_buffer_height;
|
||||||
@ -18,20 +16,20 @@ struct nb_display {
|
|||||||
bool mirror_x;
|
bool mirror_x;
|
||||||
bool mirror_y;
|
bool mirror_y;
|
||||||
bool swap_xy;
|
bool swap_xy;
|
||||||
};
|
} NbDisplay;
|
||||||
|
|
||||||
typedef struct nb_display_driver nb_display_driver_t;
|
typedef bool(*CreateDisplay)(NbDisplay* display);
|
||||||
|
|
||||||
struct nb_display_driver {
|
typedef struct {
|
||||||
char name[32];
|
char name[32];
|
||||||
bool (*create_display)(nb_display_t* display);
|
CreateDisplay create_display;
|
||||||
};
|
} NbDisplayDriver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param[in] driver
|
* @param[in] driver
|
||||||
* @return allocated display object
|
* @return allocated display object
|
||||||
*/
|
*/
|
||||||
nb_display_t _Nonnull* nb_display_alloc(nb_display_driver_t _Nonnull* driver);
|
NbDisplay _Nonnull* nb_display_alloc(NbDisplayDriver _Nonnull* driver);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
#include "nb_hardwarei.h"
|
#include "nb_hardware_i.h"
|
||||||
#include <esp_check.h>
|
#include <esp_check.h>
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
|
||||||
static const char* TAG = "nb_hardware";
|
static const char* TAG = "nb_hardware";
|
||||||
|
|
||||||
nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config) {
|
NbHardware nb_hardware_create(NbConfig _Nonnull* config) {
|
||||||
|
|
||||||
furi_check(config->display_driver != NULL, "no display driver configured");
|
furi_check(config->display_driver != NULL, "no display driver configured");
|
||||||
nb_display_driver_t display_driver = config->display_driver();
|
NbDisplayDriver display_driver = config->display_driver();
|
||||||
ESP_LOGI(TAG, "display with driver %s", display_driver.name);
|
ESP_LOGI(TAG, "display with driver %s", display_driver.name);
|
||||||
nb_display_t* display = nb_display_alloc(&display_driver);
|
NbDisplay* display = nb_display_alloc(&display_driver);
|
||||||
|
|
||||||
nb_touch_t* touch = NULL;
|
NbTouch* touch = NULL;
|
||||||
if (config->touch_driver != NULL) {
|
if (config->touch_driver != NULL) {
|
||||||
nb_touch_driver_t touch_driver = config->touch_driver();
|
NbTouchDriver touch_driver = config->touch_driver();
|
||||||
ESP_LOGI(TAG, "touch with driver %s", touch_driver.name);
|
ESP_LOGI(TAG, "touch with driver %s", touch_driver.name);
|
||||||
touch = nb_touch_alloc(&touch_driver);
|
touch = nb_touch_alloc(&touch_driver);
|
||||||
} else {
|
} else {
|
||||||
@ -22,7 +22,7 @@ nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config) {
|
|||||||
touch = NULL;
|
touch = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (nb_hardware_t) {
|
return (NbHardware) {
|
||||||
.display = display,
|
.display = display,
|
||||||
.touch = touch
|
.touch = touch
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,11 +7,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct nb_hardware nb_hardware_t;
|
typedef struct {
|
||||||
struct nb_hardware {
|
NbDisplay* _Nonnull display;
|
||||||
nb_display_t* _Nonnull display;
|
NbTouch* _Nullable touch;
|
||||||
nb_touch_t* _Nullable touch;
|
} NbHardware;
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config);
|
extern NbHardware nb_hardware_create(NbConfig _Nonnull* config);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -1,11 +1,10 @@
|
|||||||
#include "nb_lvgli.h"
|
#include "nb_lvgl_i.h"
|
||||||
#include "nb_hardwarei.h"
|
|
||||||
#include <esp_lvgl_port.h>
|
#include <esp_lvgl_port.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
|
||||||
static const char* TAG = "nb_lvgl";
|
static const char* TAG = "nb_lvgl";
|
||||||
|
|
||||||
nb_lvgl_t nb_lvgl_init(nb_hardware_t _Nonnull* hardware) {
|
NbLvgl nb_lvgl_init(NbHardware _Nonnull* hardware) {
|
||||||
const lvgl_port_cfg_t lvgl_cfg = {
|
const lvgl_port_cfg_t lvgl_cfg = {
|
||||||
.task_priority = 4,
|
.task_priority = 4,
|
||||||
.task_stack = 4096,
|
.task_stack = 4096,
|
||||||
@ -15,7 +14,7 @@ nb_lvgl_t nb_lvgl_init(nb_hardware_t _Nonnull* hardware) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
furi_check(lvgl_port_init(&lvgl_cfg) == ESP_OK, "lvgl port init failed");
|
furi_check(lvgl_port_init(&lvgl_cfg) == ESP_OK, "lvgl port init failed");
|
||||||
nb_display_t _Nonnull* display = hardware->display;
|
NbDisplay _Nonnull* display = hardware->display;
|
||||||
|
|
||||||
// Add display
|
// Add display
|
||||||
ESP_LOGD(TAG, "lvgl add display");
|
ESP_LOGD(TAG, "lvgl add display");
|
||||||
@ -50,7 +49,7 @@ nb_lvgl_t nb_lvgl_init(nb_hardware_t _Nonnull* hardware) {
|
|||||||
furi_check(touch_indev != NULL, "failed to add touch to lvgl");
|
furi_check(touch_indev != NULL, "failed to add touch to lvgl");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (nb_lvgl_t) {
|
return (NbLvgl) {
|
||||||
.disp = disp,
|
.disp = disp,
|
||||||
.touch_indev = touch_indev
|
.touch_indev = touch_indev
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,11 +6,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct nb_lvgl nb_lvgl_t;
|
typedef struct {
|
||||||
struct nb_lvgl {
|
|
||||||
lv_disp_t* _Nonnull disp;
|
lv_disp_t* _Nonnull disp;
|
||||||
lv_indev_t* _Nullable touch_indev;
|
lv_indev_t* _Nullable touch_indev;
|
||||||
};
|
} NbLvgl;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
15
components/nanobake/src/nb_lvgl_i.h
Normal file
15
components/nanobake/src/nb_lvgl_i.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "nb_lvgl.h"
|
||||||
|
#include "nb_hardware.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern NbLvgl nb_lvgl_init(NbHardware _Nonnull* hardware);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -1,15 +0,0 @@
|
|||||||
#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,8 +1,8 @@
|
|||||||
#include "nb_touch.h"
|
#include "nb_touch.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
nb_touch_t _Nonnull* nb_touch_alloc(nb_touch_driver_t _Nonnull* driver) {
|
NbTouch _Nonnull* nb_touch_alloc(NbTouchDriver _Nonnull* driver) {
|
||||||
nb_touch_t _Nonnull* touch = malloc(sizeof(nb_touch_t));
|
NbTouch _Nonnull* touch = malloc(sizeof(NbTouch));
|
||||||
bool success = driver->create_touch(
|
bool success = driver->create_touch(
|
||||||
&(touch->io_handle),
|
&(touch->io_handle),
|
||||||
&(touch->touch_handle)
|
&(touch->touch_handle)
|
||||||
|
|||||||
@ -7,25 +7,23 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct nb_touch_driver nb_touch_driver_t;
|
typedef bool (*CreateTouch)(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_handle_t* touch_handle);
|
||||||
|
|
||||||
struct nb_touch_driver {
|
typedef struct {
|
||||||
char name[32];
|
char name[32];
|
||||||
bool (*create_touch)(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_handle_t* touch_handle);
|
CreateTouch create_touch;
|
||||||
};
|
} NbTouchDriver;
|
||||||
|
|
||||||
typedef struct nb_touch nb_touch_t;
|
typedef struct {
|
||||||
|
|
||||||
struct nb_touch {
|
|
||||||
esp_lcd_panel_io_handle_t _Nonnull io_handle;
|
esp_lcd_panel_io_handle_t _Nonnull io_handle;
|
||||||
esp_lcd_touch_handle_t _Nonnull touch_handle;
|
esp_lcd_touch_handle_t _Nonnull touch_handle;
|
||||||
};
|
} NbTouch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param[in] driver
|
* @param[in] driver
|
||||||
* @return a newly allocated instance
|
* @return a newly allocated instance
|
||||||
*/
|
*/
|
||||||
nb_touch_t _Nonnull* nb_touch_alloc(nb_touch_driver_t _Nonnull* driver);
|
NbTouch _Nonnull* nb_touch_alloc(NbTouchDriver _Nonnull* driver);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,10 +12,10 @@ static const char* TAG = "app_helloworld";
|
|||||||
static void prv_on_button_click(lv_event_t _Nonnull* event) {
|
static void prv_on_button_click(lv_event_t _Nonnull* event) {
|
||||||
ESP_LOGI(TAG, "button clicked");
|
ESP_LOGI(TAG, "button clicked");
|
||||||
// Open Gui record
|
// Open Gui record
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
struct NbGui* gui = furi_record_open(RECORD_GUI);
|
||||||
|
|
||||||
// Free this screen
|
// Free this screen
|
||||||
screen_id_t screen_id = (screen_id_t)event->user_data;
|
ScreenId screen_id = (ScreenId)event->user_data;
|
||||||
gui_screen_free(gui, screen_id);
|
gui_screen_free(gui, screen_id);
|
||||||
|
|
||||||
// Close Gui record
|
// Close Gui record
|
||||||
@ -23,7 +23,7 @@ static void prv_on_button_click(lv_event_t _Nonnull* event) {
|
|||||||
gui = NULL;
|
gui = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prv_hello_world_lvgl(lv_obj_t* parent, screen_id_t screen_id) {
|
static void prv_hello_world_lvgl(lv_obj_t* parent, ScreenId screen_id) {
|
||||||
lvgl_port_lock(0);
|
lvgl_port_lock(0);
|
||||||
|
|
||||||
lv_obj_t* label = lv_label_create(parent);
|
lv_obj_t* label = lv_label_create(parent);
|
||||||
@ -48,7 +48,7 @@ static int32_t prv_hello_world_main(void* param) {
|
|||||||
UNUSED(param);
|
UNUSED(param);
|
||||||
|
|
||||||
// Open Gui record
|
// Open Gui record
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
NbGuiHandle gui = furi_record_open(RECORD_GUI);
|
||||||
|
|
||||||
// Register an lvgl screen
|
// Register an lvgl screen
|
||||||
gui_screen_create(gui, &prv_hello_world_lvgl);
|
gui_screen_create(gui, &prv_hello_world_lvgl);
|
||||||
@ -60,7 +60,7 @@ static int32_t prv_hello_world_main(void* param) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nb_app_t hello_world_app = {
|
const NbApp hello_world_app = {
|
||||||
.id = "helloworld",
|
.id = "helloworld",
|
||||||
.name = "Hello World",
|
.name = "Hello World",
|
||||||
.type = USER,
|
.type = USER,
|
||||||
|
|||||||
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
#include "nb_app.h"
|
#include "nb_app.h"
|
||||||
|
|
||||||
extern const nb_app_t hello_world_app;
|
extern const NbApp hello_world_app;
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "hello_world/hello_world.h"
|
#include "hello_world/hello_world.h"
|
||||||
|
|
||||||
__attribute__((unused)) void app_main(void) {
|
__attribute__((unused)) void app_main(void) {
|
||||||
static nb_config_t config = {
|
static NbConfig config = {
|
||||||
.display_driver = &board_2432s024_create_display_driver,
|
.display_driver = &board_2432s024_create_display_driver,
|
||||||
.touch_driver = &board_2432s024_create_touch_driver,
|
.touch_driver = &board_2432s024_create_touch_driver,
|
||||||
.apps = {
|
.apps = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user