diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e6bb0725..6a5cf1d7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,5 +4,5 @@ During the pre-alpha stage, contributions will not yet be considered. # 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). diff --git a/components/board_2432s024/board_2432s024_display.c b/components/board_2432s024/board_2432s024_display.c index 218dda3e..f1fd0797 100644 --- a/components/board_2432s024/board_2432s024_display.c +++ b/components/board_2432s024/board_2432s024_display.c @@ -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); } -static bool prv_create_display(nb_display_t* display) { +static bool prv_create_display(NbDisplay* display) { ESP_LOGI(TAG, "creating display"); gpio_config_t io_conf = { @@ -122,8 +122,8 @@ static bool prv_create_display(nb_display_t* display) { return true; } -nb_display_driver_t board_2432s024_create_display_driver() { - return (nb_display_driver_t) { +NbDisplayDriver board_2432s024_create_display_driver() { + return (NbDisplayDriver) { .name = "ili9341_2432s024", .create_display = &prv_create_display }; diff --git a/components/board_2432s024/board_2432s024_display.h b/components/board_2432s024/board_2432s024_display.h index fc43062c..de64a9f0 100644 --- a/components/board_2432s024/board_2432s024_display.h +++ b/components/board_2432s024/board_2432s024_display.h @@ -3,6 +3,6 @@ #include -extern nb_display_driver_t board_2432s024_create_display_driver(); +extern NbDisplayDriver board_2432s024_create_display_driver(); #endif //NANOBAKE_BOARD_2432S024_DISPLAY_H diff --git a/components/board_2432s024/board_2432s024_touch.c b/components/board_2432s024/board_2432s024_touch.c index a43a538f..a8122232 100644 --- a/components/board_2432s024/board_2432s024_touch.c +++ b/components/board_2432s024/board_2432s024_touch.c @@ -64,8 +64,8 @@ static bool prv_create_touch(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch return true; } -nb_touch_driver_t board_2432s024_create_touch_driver() { - return (nb_touch_driver_t) { +NbTouchDriver board_2432s024_create_touch_driver() { + return (NbTouchDriver) { .name = "cst816s_2432s024", .create_touch = &prv_create_touch }; diff --git a/components/board_2432s024/board_2432s024_touch.h b/components/board_2432s024/board_2432s024_touch.h index d53ffbae..3f58a78c 100644 --- a/components/board_2432s024/board_2432s024_touch.h +++ b/components/board_2432s024/board_2432s024_touch.h @@ -3,6 +3,6 @@ #include -nb_touch_driver_t board_2432s024_create_touch_driver(); +NbTouchDriver board_2432s024_create_touch_driver(); #endif // NANOBAKE_BOARD_2432S024_TOUCH_H diff --git a/components/nanobake/src/applications/nb_applications.c b/components/nanobake/src/applications/nb_applications.c index c23df821..a6a034fd 100644 --- a/components/nanobake/src/applications/nb_applications.c +++ b/components/nanobake/src/applications/nb_applications.c @@ -1,28 +1,28 @@ #include "nb_applications.h" // System services -extern const nb_app_t desktop_app; -extern const nb_app_t gui_app; -extern const nb_app_t loader_app; +extern const NbApp desktop_app; +extern const NbApp gui_app; +extern const NbApp loader_app; // 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, &gui_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 }; -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); diff --git a/components/nanobake/src/applications/nb_applications.h b/components/nanobake/src/applications/nb_applications.h index bcef4fc9..152b23a8 100644 --- a/components/nanobake/src/applications/nb_applications.h +++ b/components/nanobake/src/applications/nb_applications.h @@ -1,23 +1,21 @@ #pragma once #include "nb_app.h" +#include "nb_hardware.h" #ifdef __cplusplus extern "C" { #endif -// Forward declaration -typedef struct nb_hardware nb_hardware_t; +typedef void (*NbOnSystemStart)(NbHardware* hardware); -typedef void (*nb_on_system_start_)(nb_hardware_t* hardware); - -extern const nb_app_t* const FLIPPER_SERVICES[]; +extern const NbApp* const FLIPPER_SERVICES[]; 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 nb_on_system_start_ FLIPPER_ON_SYSTEM_START[]; +extern const NbOnSystemStart FLIPPER_ON_SYSTEM_START[]; extern const size_t FLIPPER_ON_SYSTEM_START_COUNT; #ifdef __cplusplus diff --git a/components/nanobake/src/applications/services/desktop/desktop.c b/components/nanobake/src/applications/services/desktop/desktop.c index 96d8a57a..567f2ad8 100644 --- a/components/nanobake/src/applications/services/desktop/desktop.c +++ b/components/nanobake/src/applications/services/desktop/desktop.c @@ -8,7 +8,7 @@ static int32_t prv_desktop_main(void* param) { return 0; } -const nb_app_t desktop_app = { +const NbApp desktop_app = { .id = "desktop", .name = "Desktop", .type = SERVICE, diff --git a/components/nanobake/src/applications/services/desktop/desktop.h b/components/nanobake/src/applications/services/desktop/desktop.h index 09ec5b0d..96e088c3 100644 --- a/components/nanobake/src/applications/services/desktop/desktop.h +++ b/components/nanobake/src/applications/services/desktop/desktop.h @@ -6,7 +6,7 @@ extern "C" { #endif -extern const nb_app_t desktop_app; +extern const NbApp desktop_app; #ifdef __cplusplus } diff --git a/components/nanobake/src/applications/services/gui/gui.c b/components/nanobake/src/applications/services/gui/gui.c index f927d593..664800b8 100644 --- a/components/nanobake/src/applications/services/gui/gui.c +++ b/components/nanobake/src/applications/services/gui/gui.c @@ -1,55 +1,36 @@ -#include "gui.h" +#include "gui_i.h" #include "core_defines.h" #include -#include #include -#include -#include - -typedef struct screen screen_t; -struct screen { - screen_id_t id; - lv_obj_t* parent; - on_init_lvgl _Nonnull callback; -}; - -static screen_id_t screen_counter = 0; -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; -}; +static ScreenId screen_counter = 0; -Gui* gui_alloc() { - Gui* gui = malloc(sizeof(Gui)); +NbGuiHandle gui_alloc() { + struct NbGui* gui = malloc(sizeof(struct NbGui)); screen_dict_init(gui->screens); gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal); return gui; } -void gui_free(Gui* gui) { +void gui_free(NbGuiHandle gui) { screen_dict_clear(gui->screens); furi_mutex_free(gui->mutex); free(gui); } -void gui_lock(Gui* gui) { +void gui_lock(NbGuiHandle gui) { furi_assert(gui); furi_check(furi_mutex_acquire(gui->mutex, FuriWaitForever) == FuriStatusOk); } -void gui_unlock(Gui* gui) { +void gui_unlock(NbGuiHandle gui) { furi_assert(gui); furi_check(furi_mutex_release(gui->mutex) == FuriStatusOk); } -screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback) { - screen_id_t id = screen_counter++; - screen_t screen = { +ScreenId gui_screen_create(NbGuiHandle gui, InitScreen callback) { + ScreenId id = screen_counter++; + NbScreen screen = { .id = id, .parent = NULL, .callback = callback @@ -68,20 +49,20 @@ screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback) { return id; } -lv_obj_t* gui_screen_get_parent(Gui* gui, screen_id_t id) { - screen_t* screen = screen_dict_get(gui->screens, id); +lv_obj_t* gui_screen_get_parent(NbGuiHandle gui, ScreenId id) { + NbScreen* screen = screen_dict_get(gui->screens, id); furi_check(screen != NULL); return screen->parent; } -void gui_screen_set_parent(Gui* gui, screen_id_t id, lv_obj_t* parent) { - screen_t* screen = screen_dict_get(gui->screens, id); +void gui_screen_set_parent(NbGuiHandle gui, ScreenId id, lv_obj_t* parent) { + NbScreen* screen = screen_dict_get(gui->screens, id); furi_check(screen != NULL); screen->parent = parent; } -void gui_screen_free(Gui* gui, screen_id_t id) { - screen_t* screen = screen_dict_get(gui->screens, id); +void gui_screen_free(NbGuiHandle gui, ScreenId id) { + NbScreen* screen = screen_dict_get(gui->screens, id); furi_check(screen != NULL); // 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) { UNUSED(param); - Gui* gui = gui_alloc(); + struct NbGui* gui = gui_alloc(); furi_record_create(RECORD_GUI, gui); printf("gui app init\n"); return 0; } -const nb_app_t gui_app = { +const NbApp gui_app = { .id = "gui", .name = "GUI", .type = SERVICE, diff --git a/components/nanobake/src/applications/services/gui/gui.h b/components/nanobake/src/applications/services/gui/gui.h index ad919ded..79b105d5 100644 --- a/components/nanobake/src/applications/services/gui/gui.h +++ b/components/nanobake/src/applications/services/gui/gui.h @@ -8,18 +8,18 @@ extern "C" { #define RECORD_GUI "gui" -typedef uint16_t screen_id_t; +typedef uint16_t ScreenId; -typedef struct Gui Gui; -typedef void (*on_init_lvgl)(lv_obj_t*, screen_id_t); +typedef struct NbGui* NbGuiHandle; +typedef void (*InitScreen)(lv_obj_t*, ScreenId); -screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback); -void gui_screen_free(Gui* gui, screen_id_t id); +ScreenId gui_screen_create(NbGuiHandle _Nonnull gui, InitScreen callback); +void gui_screen_free(NbGuiHandle _Nonnull gui, ScreenId id); // TODO make internal -void gui_screen_set_parent(Gui* gui, screen_id_t id, lv_obj_t* parent); -lv_obj_t* gui_screen_get_parent(Gui* gui, screen_id_t id); +void gui_screen_set_parent(NbGuiHandle _Nonnull gui, ScreenId id, lv_obj_t* parent); +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 } diff --git a/components/nanobake/src/applications/services/gui/gui_i.h b/components/nanobake/src/applications/services/gui/gui_i.h new file mode 100644 index 00000000..c591f03f --- /dev/null +++ b/components/nanobake/src/applications/services/gui/gui_i.h @@ -0,0 +1,20 @@ +#pragma once + +#include "gui.h" +#include +#include +#include + +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; +}; diff --git a/components/nanobake/src/applications/services/loader/loader.c b/components/nanobake/src/applications/services/loader/loader.c index ae22cf89..c7507d4e 100644 --- a/components/nanobake/src/applications/services/loader/loader.c +++ b/components/nanobake/src/applications/services/loader/loader.c @@ -7,7 +7,7 @@ static int32_t prv_loader_main(void* param) { return 0; } -const nb_app_t loader_app = { +const NbApp loader_app = { .id = "loader", .name = "Loader", .type = SERVICE, diff --git a/components/nanobake/src/applications/services/loader/loader.h b/components/nanobake/src/applications/services/loader/loader.h index 512ba0a2..f5ce71d9 100644 --- a/components/nanobake/src/applications/services/loader/loader.h +++ b/components/nanobake/src/applications/services/loader/loader.h @@ -6,7 +6,7 @@ extern "C" { #endif -extern const nb_app_t loader_app; +extern const NbApp loader_app; #ifdef __cplusplus } diff --git a/components/nanobake/src/applications/system/system_info/system_info.c b/components/nanobake/src/applications/system/system_info/system_info.c index 53fa71e7..62761a00 100644 --- a/components/nanobake/src/applications/system/system_info/system_info.c +++ b/components/nanobake/src/applications/system/system_info/system_info.c @@ -28,7 +28,7 @@ static int32_t system_info_entry_point(void* param) { return 0; } -nb_app_t system_info_app = { +NbApp system_info_app = { .id = "systeminfo", .name = "System Info", .type = SYSTEM, diff --git a/components/nanobake/src/applications/system/system_info/system_info.h b/components/nanobake/src/applications/system/system_info/system_info.h index 88b0cb04..86027b62 100644 --- a/components/nanobake/src/applications/system/system_info/system_info.h +++ b/components/nanobake/src/applications/system/system_info/system_info.h @@ -6,7 +6,7 @@ extern "C" { #endif -extern nb_app_t system_info_app; +extern NbApp system_info_app; #ifdef __cplusplus } diff --git a/components/nanobake/src/nanobake.c b/components/nanobake/src/nanobake.c index 625ae4ee..8e40dfa0 100644 --- a/components/nanobake/src/nanobake.c +++ b/components/nanobake/src/nanobake.c @@ -1,7 +1,7 @@ #include "nanobake.h" -#include "nb_hardwarei.h" -#include "nb_lvgli.h" -#include "nb_appi.h" +#include "nb_hardware_i.h" +#include "nb_lvgl_i.h" +#include "nb_app_i.h" #include "applications/nb_applications.h" #include #include @@ -34,7 +34,7 @@ size_t nanobake_get_app_thread_count() { 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\"", nb_app_type_to_string(app->type), 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); } -__attribute__((unused)) extern void nanobake_start(nb_config_t _Nonnull* config) { +__attribute__((unused)) extern void nanobake_start(NbConfig _Nonnull* config) { prv_furi_init(); - nb_hardware_t hardware = nb_hardware_create(config); - /*nb_lvgl_t lvgl =*/ nb_lvgl_init(&hardware); + NbHardware hardware = nb_hardware_create(config); + /*NbLvgl lvgl =*/ nb_lvgl_init(&hardware); thread_ids_init(prv_thread_ids); diff --git a/components/nanobake/src/nanobake.h b/components/nanobake/src/nanobake.h index 9759cc03..eaeba2af 100644 --- a/components/nanobake/src/nanobake.h +++ b/components/nanobake/src/nanobake.h @@ -10,9 +10,8 @@ extern "C" { // Forward declarations 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 size_t nanobake_get_app_thread_count(); diff --git a/components/nanobake/src/nb_app.c b/components/nanobake/src/nb_app.c index 3e73995e..efabef37 100644 --- a/components/nanobake/src/nb_app.c +++ b/components/nanobake/src/nb_app.c @@ -1,11 +1,11 @@ -#include "nb_appi.h" +#include "nb_app_i.h" #include const char* prv_type_service = "service"; const char* prv_type_system = "system"; 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) { case SERVICE: return prv_type_service; diff --git a/components/nanobake/src/nb_app.h b/components/nanobake/src/nb_app.h index b5c79831..7afacabe 100644 --- a/components/nanobake/src/nb_app.h +++ b/components/nanobake/src/nb_app.h @@ -11,26 +11,22 @@ extern "C" { #define NB_APP_ID_LENGTH 32 #define NB_APP_NAME_LENGTH 32 -typedef enum nb_app_type nb_app_type_t; - -enum nb_app_type { +typedef enum { SERVICE, SYSTEM, USER -}; - -typedef struct nb_app nb_app_t; +} NbAppType; -typedef int32_t (*nb_app_entry_point) (void _Nonnull* parameter); +typedef int32_t (*NbAppEntryPoint) (void _Nonnull* parameter); -struct nb_app { +typedef struct { const char id[NB_APP_ID_LENGTH]; const char name[NB_APP_NAME_LENGTH]; - const nb_app_type_t type; - const nb_app_entry_point _Nullable entry_point; + const NbAppType type; + const NbAppEntryPoint _Nullable entry_point; const size_t stack_size; const uint32_t priority; -}; +} NbApp; #ifdef __cplusplus } diff --git a/components/nanobake/src/nb_appi.h b/components/nanobake/src/nb_app_i.h similarity index 62% rename from components/nanobake/src/nb_appi.h rename to components/nanobake/src/nb_app_i.h index 0c46be22..ba3d434a 100644 --- a/components/nanobake/src/nb_appi.h +++ b/components/nanobake/src/nb_app_i.h @@ -6,7 +6,7 @@ extern "C" { #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 } diff --git a/components/nanobake/src/nb_config.h b/components/nanobake/src/nb_config.h index e9d682e3..3a44963f 100644 --- a/components/nanobake/src/nb_config.h +++ b/components/nanobake/src/nb_config.h @@ -8,19 +8,18 @@ extern "C" { #endif -typedef nb_touch_driver_t (*create_touch_driver)(); -typedef nb_display_driver_t (*create_display_driver)(); +typedef NbTouchDriver (*CreateTouchDriver)(); +typedef NbDisplayDriver (*CreateDisplayDriver)(); -typedef struct nb_config nb_config_t; -struct nb_config { +typedef struct { // Required driver for display - const create_display_driver _Nonnull display_driver; + const CreateDisplayDriver _Nonnull display_driver; // Optional driver for touch input - const create_touch_driver _Nullable touch_driver; + const CreateTouchDriver _Nullable touch_driver; // List of user applications const size_t apps_count; - const nb_app_t* const apps[]; -}; + const NbApp* const apps[]; +} NbConfig; #ifdef __cplusplus } diff --git a/components/nanobake/src/nb_display.c b/components/nanobake/src/nb_display.c index 0ec250c8..69f3e29c 100644 --- a/components/nanobake/src/nb_display.c +++ b/components/nanobake/src/nb_display.c @@ -1,9 +1,9 @@ #include "nb_display.h" #include -nb_display_t _Nonnull* nb_display_alloc(nb_display_driver_t _Nonnull* driver) { - nb_display_t _Nonnull* display = malloc(sizeof(nb_display_t)); - memset(display, 0, sizeof(nb_display_t)); +NbDisplay _Nonnull* nb_display_alloc(NbDisplayDriver _Nonnull* driver) { + NbDisplay _Nonnull* display = malloc(sizeof(NbDisplay)); + memset(display, 0, sizeof(NbDisplay)); furi_check(driver->create_display(display), "failed to create display"); furi_check(display->io_handle != NULL); furi_check(display->display_handle != NULL); diff --git a/components/nanobake/src/nb_display.h b/components/nanobake/src/nb_display.h index 58581d91..c123568f 100644 --- a/components/nanobake/src/nb_display.h +++ b/components/nanobake/src/nb_display.h @@ -6,9 +6,7 @@ extern "C" { #endif -typedef struct nb_display nb_display_t; - -struct nb_display { +typedef struct { uint16_t horizontal_resolution; uint16_t vertical_resolution; uint16_t draw_buffer_height; @@ -18,20 +16,20 @@ struct nb_display { bool mirror_x; bool mirror_y; 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]; - bool (*create_display)(nb_display_t* display); -}; + CreateDisplay create_display; +} NbDisplayDriver; /** * @param[in] driver * @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 } diff --git a/components/nanobake/src/nb_hardware.c b/components/nanobake/src/nb_hardware.c index e2f68997..2e67b26c 100644 --- a/components/nanobake/src/nb_hardware.c +++ b/components/nanobake/src/nb_hardware.c @@ -1,20 +1,20 @@ -#include "nb_hardwarei.h" +#include "nb_hardware_i.h" #include #include #include 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"); - 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); - 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) { - 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); touch = nb_touch_alloc(&touch_driver); } else { @@ -22,7 +22,7 @@ nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config) { touch = NULL; } - return (nb_hardware_t) { + return (NbHardware) { .display = display, .touch = touch }; diff --git a/components/nanobake/src/nb_hardware.h b/components/nanobake/src/nb_hardware.h index e1b694f5..dae73d9a 100644 --- a/components/nanobake/src/nb_hardware.h +++ b/components/nanobake/src/nb_hardware.h @@ -7,11 +7,10 @@ extern "C" { #endif -typedef struct nb_hardware nb_hardware_t; -struct nb_hardware { - nb_display_t* _Nonnull display; - nb_touch_t* _Nullable touch; -}; +typedef struct { + NbDisplay* _Nonnull display; + NbTouch* _Nullable touch; +} NbHardware; #ifdef __cplusplus } diff --git a/components/nanobake/src/nb_hardwarei.h b/components/nanobake/src/nb_hardware_i.h similarity index 65% rename from components/nanobake/src/nb_hardwarei.h rename to components/nanobake/src/nb_hardware_i.h index cb025398..ac6d9a98 100644 --- a/components/nanobake/src/nb_hardwarei.h +++ b/components/nanobake/src/nb_hardware_i.h @@ -7,7 +7,7 @@ extern "C" { #endif -extern nb_hardware_t nb_hardware_create(nb_config_t _Nonnull* config); +extern NbHardware nb_hardware_create(NbConfig _Nonnull* config); #ifdef __cplusplus } diff --git a/components/nanobake/src/nb_lvgl.c b/components/nanobake/src/nb_lvgl.c index 63d469b7..6b4d7052 100644 --- a/components/nanobake/src/nb_lvgl.c +++ b/components/nanobake/src/nb_lvgl.c @@ -1,11 +1,10 @@ -#include "nb_lvgli.h" -#include "nb_hardwarei.h" +#include "nb_lvgl_i.h" #include #include 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 = { .task_priority = 4, .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"); - nb_display_t _Nonnull* display = hardware->display; + NbDisplay _Nonnull* display = hardware->display; // 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"); } - return (nb_lvgl_t) { + return (NbLvgl) { .disp = disp, .touch_indev = touch_indev }; diff --git a/components/nanobake/src/nb_lvgl.h b/components/nanobake/src/nb_lvgl.h index 936a1854..c8d177c7 100644 --- a/components/nanobake/src/nb_lvgl.h +++ b/components/nanobake/src/nb_lvgl.h @@ -6,11 +6,10 @@ extern "C" { #endif -typedef struct nb_lvgl nb_lvgl_t; -struct nb_lvgl { +typedef struct { lv_disp_t* _Nonnull disp; lv_indev_t* _Nullable touch_indev; -}; +} NbLvgl; #ifdef __cplusplus } diff --git a/components/nanobake/src/nb_lvgl_i.h b/components/nanobake/src/nb_lvgl_i.h new file mode 100644 index 00000000..53fead49 --- /dev/null +++ b/components/nanobake/src/nb_lvgl_i.h @@ -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 diff --git a/components/nanobake/src/nb_lvgli.h b/components/nanobake/src/nb_lvgli.h deleted file mode 100644 index f45b757f..00000000 --- a/components/nanobake/src/nb_lvgli.h +++ /dev/null @@ -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 diff --git a/components/nanobake/src/nb_touch.c b/components/nanobake/src/nb_touch.c index faee86eb..e6b980b5 100644 --- a/components/nanobake/src/nb_touch.c +++ b/components/nanobake/src/nb_touch.c @@ -1,8 +1,8 @@ #include "nb_touch.h" #include "check.h" -nb_touch_t _Nonnull* nb_touch_alloc(nb_touch_driver_t _Nonnull* driver) { - nb_touch_t _Nonnull* touch = malloc(sizeof(nb_touch_t)); +NbTouch _Nonnull* nb_touch_alloc(NbTouchDriver _Nonnull* driver) { + NbTouch _Nonnull* touch = malloc(sizeof(NbTouch)); bool success = driver->create_touch( &(touch->io_handle), &(touch->touch_handle) diff --git a/components/nanobake/src/nb_touch.h b/components/nanobake/src/nb_touch.h index 78043024..4628acb8 100644 --- a/components/nanobake/src/nb_touch.h +++ b/components/nanobake/src/nb_touch.h @@ -7,25 +7,23 @@ extern "C" { #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]; - 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; - -struct nb_touch { +typedef struct { esp_lcd_panel_io_handle_t _Nonnull io_handle; esp_lcd_touch_handle_t _Nonnull touch_handle; -}; +} NbTouch; /** * @param[in] driver * @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 } diff --git a/main/src/hello_world/hello_world.c b/main/src/hello_world/hello_world.c index bc66706f..23c7ebb5 100644 --- a/main/src/hello_world/hello_world.c +++ b/main/src/hello_world/hello_world.c @@ -12,10 +12,10 @@ static const char* TAG = "app_helloworld"; static void prv_on_button_click(lv_event_t _Nonnull* event) { ESP_LOGI(TAG, "button clicked"); // Open Gui record - Gui* gui = furi_record_open(RECORD_GUI); + struct NbGui* gui = furi_record_open(RECORD_GUI); // 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); // Close Gui record @@ -23,7 +23,7 @@ static void prv_on_button_click(lv_event_t _Nonnull* event) { 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); lv_obj_t* label = lv_label_create(parent); @@ -48,7 +48,7 @@ static int32_t prv_hello_world_main(void* param) { UNUSED(param); // Open Gui record - Gui* gui = furi_record_open(RECORD_GUI); + NbGuiHandle gui = furi_record_open(RECORD_GUI); // Register an lvgl screen gui_screen_create(gui, &prv_hello_world_lvgl); @@ -60,7 +60,7 @@ static int32_t prv_hello_world_main(void* param) { return 0; } -const nb_app_t hello_world_app = { +const NbApp hello_world_app = { .id = "helloworld", .name = "Hello World", .type = USER, diff --git a/main/src/hello_world/hello_world.h b/main/src/hello_world/hello_world.h index c9539e5d..93b003e2 100644 --- a/main/src/hello_world/hello_world.h +++ b/main/src/hello_world/hello_world.h @@ -2,4 +2,4 @@ #include "nb_app.h" -extern const nb_app_t hello_world_app; +extern const NbApp hello_world_app; diff --git a/main/src/main.c b/main/src/main.c index f2b0c3e4..28b098b9 100644 --- a/main/src/main.c +++ b/main/src/main.c @@ -8,7 +8,7 @@ #include "hello_world/hello_world.h" __attribute__((unused)) void app_main(void) { - static nb_config_t config = { + static NbConfig config = { .display_driver = &board_2432s024_create_display_driver, .touch_driver = &board_2432s024_create_touch_driver, .apps = {