From e842e30ab3f2e5fde2e0e799e2c97629597934c7 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Fri, 5 Jan 2024 19:38:39 +0100 Subject: [PATCH] created ServiceManifest (#5) based on AppManifest --- components/furi/src/app_manifest.h | 11 +- components/furi/src/app_manifest_registry.c | 6 +- components/furi/src/check.h | 4 +- components/furi/src/furi.c | 8 +- components/furi/src/furi.h | 1 - components/furi/src/record.c | 151 ------------------ components/furi/src/record.h | 80 ---------- components/furi/src/service_manifest.h | 32 ++++ components/nanobake/CMakeLists.txt | 8 +- .../src/apps/services/desktop/desktop.h | 13 -- components/nanobake/src/nanobake.c | 71 ++++---- components/nanobake/src/nanobake.h | 8 +- .../src/{apps => }/services/desktop/desktop.c | 19 +-- .../src/{apps => }/services/gui/gui.c | 11 +- .../src/{apps => }/services/gui/gui.h | 10 +- .../src/{apps => }/services/gui/gui_draw.c | 7 +- .../src/{apps => }/services/gui/gui_i.h | 0 .../src/{apps => }/services/gui/gui_input.c | 0 .../src/{apps => }/services/gui/icon.c | 0 .../src/{apps => }/services/gui/icon.h | 0 .../src/{apps => }/services/gui/icon_i.h | 0 .../src/{apps => }/services/gui/view_port.c | 3 +- .../src/{apps => }/services/gui/view_port.h | 0 .../src/{apps => }/services/gui/view_port_i.h | 0 .../{apps => }/services/gui/view_port_input.c | 0 .../{apps => }/services/gui/view_port_input.h | 0 .../{apps => }/services/gui/widgets/spacer.c | 0 .../{apps => }/services/gui/widgets/spacer.h | 0 .../{apps => }/services/gui/widgets/toolbar.c | 7 +- .../{apps => }/services/gui/widgets/toolbar.h | 0 .../{apps => }/services/gui/widgets/top_bar.c | 0 .../{apps => }/services/gui/widgets/top_bar.h | 0 .../{apps => }/services/gui/widgets/widgets.c | 0 .../{apps => }/services/gui/widgets/widgets.h | 0 .../src/{apps => }/services/loader/loader.c | 19 +-- .../src/{apps => }/services/loader/loader.h | 3 +- .../src/{apps => }/services/loader/loader_i.h | 3 +- main/src/hello_world/hello_world.c | 4 +- main/src/main.c | 7 +- 39 files changed, 134 insertions(+), 352 deletions(-) delete mode 100644 components/furi/src/record.c delete mode 100644 components/furi/src/record.h create mode 100644 components/furi/src/service_manifest.h delete mode 100644 components/nanobake/src/apps/services/desktop/desktop.h rename components/nanobake/src/{apps => }/services/desktop/desktop.c (82%) rename components/nanobake/src/{apps => }/services/gui/gui.c (94%) rename components/nanobake/src/{apps => }/services/gui/gui.h (72%) rename components/nanobake/src/{apps => }/services/gui/gui_draw.c (96%) rename components/nanobake/src/{apps => }/services/gui/gui_i.h (100%) rename components/nanobake/src/{apps => }/services/gui/gui_input.c (100%) rename components/nanobake/src/{apps => }/services/gui/icon.c (100%) rename components/nanobake/src/{apps => }/services/gui/icon.h (100%) rename components/nanobake/src/{apps => }/services/gui/icon_i.h (100%) rename components/nanobake/src/{apps => }/services/gui/view_port.c (97%) rename components/nanobake/src/{apps => }/services/gui/view_port.h (100%) rename components/nanobake/src/{apps => }/services/gui/view_port_i.h (100%) rename components/nanobake/src/{apps => }/services/gui/view_port_input.c (100%) rename components/nanobake/src/{apps => }/services/gui/view_port_input.h (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/spacer.c (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/spacer.h (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/toolbar.c (89%) rename components/nanobake/src/{apps => }/services/gui/widgets/toolbar.h (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/top_bar.c (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/top_bar.h (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/widgets.c (100%) rename components/nanobake/src/{apps => }/services/gui/widgets/widgets.h (100%) rename components/nanobake/src/{apps => }/services/loader/loader.c (96%) rename components/nanobake/src/{apps => }/services/loader/loader.h (98%) rename components/nanobake/src/{apps => }/services/loader/loader_i.h (96%) diff --git a/components/furi/src/app_manifest.h b/components/furi/src/app_manifest.h index d463b67a..0b84d93e 100644 --- a/components/furi/src/app_manifest.h +++ b/components/furi/src/app_manifest.h @@ -10,20 +10,11 @@ extern "C" { typedef struct _lv_obj_t lv_obj_t; typedef enum { - AppTypeService, AppTypeSystem, - AppTypeDesktop, + AppTypeSettings, AppTypeUser } AppType; -typedef enum { - AppStackSizeTiny = 512, - AppStackSizeSmall = 1024, - AppStackSizeNormal = 2048, - AppStackSizeLarge = 4096, - AppStackSizeHuge = 8192, -} AppStackSize; - typedef void (*AppOnStart)(void _Nonnull* parameter); typedef void (*AppOnStop)(); typedef void (*AppOnShow)(lv_obj_t* parent, void* context); diff --git a/components/furi/src/app_manifest_registry.c b/components/furi/src/app_manifest_registry.c index e5d626af..94f57912 100644 --- a/components/furi/src/app_manifest_registry.c +++ b/components/furi/src/app_manifest_registry.c @@ -6,10 +6,6 @@ #define TAG "app_registry" -typedef struct { - const AppManifest* manifest; -} AppEntry; - DICT_DEF2(AppManifestDict, const char*, M_CSTR_DUP_OPLIST, const AppManifest*, M_PTR_OPLIST) #define APP_REGISTRY_FOR_EACH(manifest_var_name, code_to_execute) \ @@ -17,7 +13,7 @@ DICT_DEF2(AppManifestDict, const char*, M_CSTR_DUP_OPLIST, const AppManifest*, M app_registry_lock(); \ AppManifestDict_it_t it; \ for (AppManifestDict_it(it, app_manifest_dict); !AppManifestDict_end_p(it); AppManifestDict_next(it)) { \ - const AppManifest* (manifest_var_name) = AppManifestDict_cref(it)->value; \ + const AppManifest*(manifest_var_name) = AppManifestDict_cref(it)->value; \ code_to_execute; \ } \ app_registry_unlock(); \ diff --git a/components/furi/src/check.h b/components/furi/src/check.h index 098b0e1e..122819bd 100644 --- a/components/furi/src/check.h +++ b/components/furi/src/check.h @@ -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) ? ((const char*)message) : ""), __FILE__, __LINE__); \ + ESP_LOGE("crash", "%s\n\tat %s:%d", ((message) ? (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) ? ((const char*)message) : ""), __FILE__, __LINE__); \ + ESP_LOGE("halt", "%s\n\tat %s:%d", ((message) ? (message) : ""), __FILE__, __LINE__); \ __furi_halt_implementation(); \ } while (0) diff --git a/components/furi/src/furi.c b/components/furi/src/furi.c index cb69ae50..b21ce6dc 100644 --- a/components/furi/src/furi.c +++ b/components/furi/src/furi.c @@ -1,19 +1,18 @@ #include "furi.h" #include "app_manifest_registry.h" -#include - #include "freertos/FreeRTOS.h" #include "freertos/queue.h" +#define TAG "furi" + void furi_init() { + FURI_LOG_I(TAG, "init start"); furi_assert(!furi_kernel_is_irq()); if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) { vTaskSuspendAll(); } - furi_record_init(); - xTaskResumeAll(); #if defined(__ARM_ARCH_7A__) && (__ARM_ARCH_7A__ == 0U) @@ -24,4 +23,5 @@ void furi_init() { #endif app_manifest_registry_init(); + FURI_LOG_I(TAG, "init complete"); } diff --git a/components/furi/src/furi.h b/components/furi/src/furi.h index 044d4b35..9e20f726 100644 --- a/components/furi/src/furi.h +++ b/components/furi/src/furi.h @@ -10,7 +10,6 @@ #include "message_queue.h" #include "mutex.h" #include "pubsub.h" -#include "record.h" #include "semaphore.h" #include "stream_buffer.h" #include "string.h" diff --git a/components/furi/src/record.c b/components/furi/src/record.c deleted file mode 100644 index 110363d1..00000000 --- a/components/furi/src/record.c +++ /dev/null @@ -1,151 +0,0 @@ -#include "record.h" -#include "check.h" -#include "event_flag.h" -#include "mutex.h" -#include "m-dict.h" -#include "m_cstr_dup.h" -#include "log.h" - -#define TAG "record" - -#define FURI_RECORD_FLAG_READY (0x1) - -typedef struct { - FuriEventFlag* flags; - void* data; - size_t holders_count; -} FuriRecordData; - -DICT_DEF2(FuriRecordDataDict, const char*, M_CSTR_DUP_OPLIST, FuriRecordData, M_POD_OPLIST) - -typedef struct { - FuriMutex* mutex; - FuriRecordDataDict_t records; -} FuriRecord; - -static FuriRecord* furi_record = NULL; - -static FuriRecordData* furi_record_get(const char* name) { - return FuriRecordDataDict_get(furi_record->records, name); -} - -static void furi_record_put(const char* name, FuriRecordData* record_data) { - FuriRecordDataDict_set_at(furi_record->records, name, *record_data); -} - -static void furi_record_erase(const char* name, FuriRecordData* record_data) { - furi_event_flag_free(record_data->flags); - FuriRecordDataDict_erase(furi_record->records, name); -} - -void furi_record_init() { - furi_record = malloc(sizeof(FuriRecord)); - furi_record->mutex = furi_mutex_alloc(FuriMutexTypeRecursive); - furi_check(furi_record->mutex); - FuriRecordDataDict_init(furi_record->records); -} - -static FuriRecordData* furi_record_data_get_or_create(const char* name) { - furi_assert(furi_record); - FuriRecordData* record_data = furi_record_get(name); - if (!record_data) { - FuriRecordData new_record; - new_record.flags = furi_event_flag_alloc(); - new_record.data = NULL; - new_record.holders_count = 0; - furi_record_put(name, &new_record); - record_data = furi_record_get(name); - } - return record_data; -} - -static void furi_record_lock() { - furi_check(furi_mutex_acquire(furi_record->mutex, FuriWaitForever) == FuriStatusOk); -} - -static void furi_record_unlock() { - furi_check(furi_mutex_release(furi_record->mutex) == FuriStatusOk); -} - -bool furi_record_exists(const char* name) { - furi_assert(furi_record); - furi_assert(name); - - bool ret = false; - - furi_record_lock(); - ret = (furi_record_get(name) != NULL); - furi_record_unlock(); - - return ret; -} - -void furi_record_create(const char* name, void* data) { - furi_assert(furi_record); - - furi_record_lock(); - - // Get record data and fill it - FuriRecordData* record_data = furi_record_data_get_or_create(name); - furi_assert(record_data->data == NULL); - record_data->data = data; - furi_event_flag_set(record_data->flags, FURI_RECORD_FLAG_READY); - - furi_record_unlock(); -} - -bool furi_record_destroy(const char* name) { - furi_assert(furi_record); - - bool ret = false; - - furi_record_lock(); - - FuriRecordData* record_data = furi_record_get(name); - furi_assert(record_data); - if (record_data->holders_count == 0) { - furi_record_erase(name, record_data); - ret = true; - } - - furi_record_unlock(); - - return ret; -} - -void* furi_record_open(const char* name) { - furi_assert(name); - furi_assert(furi_record); - - furi_record_lock(); - - FuriRecordData* record_data = furi_record_data_get_or_create(name); - record_data->holders_count++; - - furi_record_unlock(); - - // Wait for record to become ready - furi_check( - furi_event_flag_wait( - record_data->flags, - FURI_RECORD_FLAG_READY, - FuriFlagWaitAny | FuriFlagNoClear, - FuriWaitForever - ) == FURI_RECORD_FLAG_READY - ); - - return record_data->data; -} - -void furi_record_close(const char* name) { - furi_assert(name); - furi_assert(furi_record); - - furi_record_lock(); - - FuriRecordData* record_data = furi_record_get(name); - furi_assert(record_data); - record_data->holders_count--; - - furi_record_unlock(); -} diff --git a/components/furi/src/record.h b/components/furi/src/record.h deleted file mode 100644 index 0c873c33..00000000 --- a/components/furi/src/record.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file record.h - * Furi: record API - */ - -#pragma once - -#include "furi_extra_defines.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Opens a record, calls the code and then closes the record. - * @param record_name const char* that contains the name of the record - * @param variable_name the name of the variable that is used in the `code` - * @param code the code to execute: consider putting it between {} - */ -#define FURI_RECORD_TRANSACTION(record_name, variable_type, variable_name, code) \ - { \ - variable_type (variable_name) = (variable_type)furi_record_open(record_name); \ - code; \ - furi_record_close(record_name); \ - } - -/** Initialize record storage For internal use only. - */ -void furi_record_init(); - -/** Check if record exists - * - * @param name record name - * @note Thread safe. Create and destroy must be executed from the same - * thread. - */ -bool furi_record_exists(const char* name); - -/** Create record - * - * @param name record name - * @param data data pointer - * @note Thread safe. Create and destroy must be executed from the same - * thread. - */ -void furi_record_create(const char* name, void* data); - -/** Destroy record - * - * @param name record name - * - * @return true if successful, false if still have holders or thread is not - * owner. - * @note Thread safe. Create and destroy must be executed from the same - * thread. - */ -bool furi_record_destroy(const char* name); - -/** Open record - * - * @param name record name - * - * @return pointer to the record - * @note Thread safe. Open and close must be executed from the same - * thread. Suspends caller thread till record is available - */ -FURI_RETURNS_NONNULL void* furi_record_open(const char* name); - -/** Close record - * - * @param name record name - * @note Thread safe. Open and close must be executed from the same - * thread. - */ -void furi_record_close(const char* name); - -#ifdef __cplusplus -} -#endif diff --git a/components/furi/src/service_manifest.h b/components/furi/src/service_manifest.h new file mode 100644 index 00000000..6418d86a --- /dev/null +++ b/components/furi/src/service_manifest.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*ServiceOnStart)(void _Nonnull* parameter); +typedef void (*ServiceOnStop)(); + +typedef struct { + /** + * The identifier by which the app is launched by the system and other apps. + */ + const char* _Nonnull id; + + /** + * Non-blocking method to call when service is started. + */ + const ServiceOnStart _Nullable on_start; + + /** + * Non-blocking method to call when service is stopped. + */ + const ServiceOnStop _Nullable on_stop; + +} ServiceManifest; + +#ifdef __cplusplus +} +#endif diff --git a/components/nanobake/CMakeLists.txt b/components/nanobake/CMakeLists.txt index c46b78ab..e83d2717 100644 --- a/components/nanobake/CMakeLists.txt +++ b/components/nanobake/CMakeLists.txt @@ -1,10 +1,10 @@ idf_component_register( SRC_DIRS "src" "src/apps/system/system_info" - "src/apps/services/desktop" - "src/apps/services/loader" - "src/apps/services/gui" - "src/apps/services/gui/widgets" + "src/services/desktop" + "src/services/loader" + "src/services/gui" + "src/services/gui/widgets" INCLUDE_DIRS "src" REQUIRES esp_lvgl_port esp_lcd esp_lcd_touch driver mlib cmsis_core furi nvs_flash spiffs fatfs ) diff --git a/components/nanobake/src/apps/services/desktop/desktop.h b/components/nanobake/src/apps/services/desktop/desktop.h deleted file mode 100644 index 13ba7acb..00000000 --- a/components/nanobake/src/apps/services/desktop/desktop.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "app_manifest.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const AppManifest desktop_app; - -#ifdef __cplusplus -} -#endif diff --git a/components/nanobake/src/nanobake.c b/components/nanobake/src/nanobake.c index 982e65bc..f737eb1d 100644 --- a/components/nanobake/src/nanobake.c +++ b/components/nanobake/src/nanobake.c @@ -4,52 +4,66 @@ #include "furi.h" #include "graphics_i.h" #include "partitions.h" -#include "apps/services/gui/gui.h" +#include "services/gui/gui.h" + #define TAG "nanobake" Gui* gui_alloc(); // System services -extern const AppManifest gui_app; -extern const AppManifest loader_app; - -// Desktop -extern const AppManifest desktop_app; +extern const ServiceManifest gui_service; +extern const ServiceManifest loader_service; +extern const ServiceManifest desktop_service; // System apps extern const AppManifest system_info_app; -void start_service(const AppManifest* _Nonnull manifest, void* _Nullable context) { - UNUSED(context); - FURI_LOG_I(TAG, "Starting service %s", manifest->name); +void start_service(const ServiceManifest* _Nonnull manifest) { + FURI_LOG_I(TAG, "Starting service %s", manifest->id); furi_check(manifest->on_start, "service must define on_start"); manifest->on_start(NULL); // TODO: keep track of running services } -static void register_apps(Config* _Nonnull config) { - FURI_LOG_I(TAG, "Registering core apps"); - app_manifest_registry_add(&gui_app); - app_manifest_registry_add(&desktop_app); - app_manifest_registry_add(&loader_app); +static void register_system_apps() { + FURI_LOG_I(TAG, "Registering default apps"); app_manifest_registry_add(&system_info_app); +} +static void register_user_apps(const Config* _Nonnull config) { FURI_LOG_I(TAG, "Registering user apps"); - for (size_t i = 0; i < config->apps_count; i++) { - app_manifest_registry_add(config->apps[i]); + for (size_t i = 0; i < CONFIG_APPS_LIMIT; i++) { + const AppManifest* manifest = config->apps[i]; + if (manifest != NULL) { + app_manifest_registry_add(manifest); + } else { + // reached end of list + break; + } } } -static void start_services() { - FURI_LOG_I(TAG, "Starting services"); - app_manifest_registry_for_each_of_type(AppTypeService, NULL, start_service); - FURI_LOG_I(TAG, "Startup complete"); +static void start_system_services() { + FURI_LOG_I(TAG, "Starting system services"); + start_service(&gui_service); + start_service(&loader_service); + start_service(&desktop_service); + FURI_LOG_I(TAG, "System services started"); } -static void start_desktop() { - FURI_LOG_I(TAG, "Starting desktop"); - desktop_app.on_start(NULL); - FURI_LOG_I(TAG, "Startup complete"); +static void start_user_services(const Config* _Nonnull config) { + FURI_LOG_I(TAG, "Starting user services"); + for (size_t i = 0; i < CONFIG_SERVICES_LIMIT; i++) { + const ServiceManifest* manifest = config->services[i]; + if (manifest != NULL) { + // TODO: keep track of running services + manifest->on_start(NULL); + } else { + // reached end of list + break; + } + } + FURI_LOG_I(TAG, "User services started"); } __attribute__((unused)) extern void nanobake_start(const Config* _Nonnull config) { @@ -60,8 +74,11 @@ __attribute__((unused)) extern void nanobake_start(const Config* _Nonnull config Hardware hardware = nb_hardware_init(config->hardware); /*NbLvgl lvgl =*/nb_graphics_init(&hardware); - register_apps(config); + // Register all apps + register_system_apps(); + register_user_apps(config); - start_services(); - start_desktop(); + // Start all services + start_system_services(); + start_user_services(config); } diff --git a/components/nanobake/src/nanobake.h b/components/nanobake/src/nanobake.h index 9160d079..3d38f410 100644 --- a/components/nanobake/src/nanobake.h +++ b/components/nanobake/src/nanobake.h @@ -3,11 +3,15 @@ #include "app_manifest.h" #include "devices.h" #include "furi_extra_defines.h" +#include "service_manifest.h" #ifdef __cplusplus extern "C" { #endif +#define CONFIG_APPS_LIMIT 32 +#define CONFIG_SERVICES_LIMIT 32 + // Forward declarations typedef void* FuriThreadId; typedef void (*Bootstrap)(); @@ -26,8 +30,8 @@ typedef struct { typedef struct { const HardwareConfig* hardware; // List of user applications - const size_t apps_count; - const AppManifest* const apps[]; + const AppManifest* const apps[CONFIG_APPS_LIMIT]; + const ServiceManifest* const services[CONFIG_SERVICES_LIMIT]; } Config; __attribute__((unused)) extern void nanobake_start(const Config _Nonnull* config); diff --git a/components/nanobake/src/apps/services/desktop/desktop.c b/components/nanobake/src/services/desktop/desktop.c similarity index 82% rename from components/nanobake/src/apps/services/desktop/desktop.c rename to components/nanobake/src/services/desktop/desktop.c index c457651f..6e56b612 100644 --- a/components/nanobake/src/apps/services/desktop/desktop.c +++ b/components/nanobake/src/services/desktop/desktop.c @@ -1,10 +1,9 @@ -#include "desktop.h" -#include "lvgl.h" -#include "check.h" -#include "apps/services/loader/loader.h" -#include "apps/services/gui/gui.h" -#include "apps/services/gui/view_port.h" #include "app_manifest_registry.h" +#include "check.h" +#include "lvgl.h" +#include "services/gui/gui.h" +#include "services/gui/view_port.h" +#include "services/loader/loader.h" static void on_open_app(lv_event_t* e) { lv_event_code_t code = lv_event_get_code(e); @@ -42,12 +41,8 @@ static void desktop_stop() { furi_crash("desktop_stop is not implemented"); } -const AppManifest desktop_app = { +const ServiceManifest desktop_service = { .id = "desktop", - .name = "Desktop", - .icon = NULL, - .type = AppTypeDesktop, .on_start = &desktop_start, - .on_stop = &desktop_stop, - .on_show = NULL + .on_stop = &desktop_stop }; diff --git a/components/nanobake/src/apps/services/gui/gui.c b/components/nanobake/src/services/gui/gui.c similarity index 94% rename from components/nanobake/src/apps/services/gui/gui.c rename to components/nanobake/src/services/gui/gui.c index 944333c8..152accb8 100644 --- a/components/nanobake/src/apps/services/gui/gui.c +++ b/components/nanobake/src/services/gui/gui.c @@ -3,7 +3,6 @@ #include "furi_extra_defines.h" #include "gui_i.h" #include "log.h" -#include "record.h" #include "kernel.h" #define TAG "gui" @@ -21,7 +20,7 @@ Gui* gui_alloc() { furi_check(instance != NULL); instance->thread = furi_thread_alloc_ex( "gui", - AppStackSizeLarge, // Last known minimum was 2800 for launching desktop + 4096, // Last known minimum was 2800 for launching desktop &gui_main, NULL ); @@ -165,14 +164,10 @@ static void gui_stop() { gui_free(gui); } -const AppManifest gui_app = { +const ServiceManifest gui_service = { .id = "gui", - .name = "GUI", - .icon = NULL, - .type = AppTypeService, .on_start = &gui_start, - .on_stop = &gui_stop, - .on_show = NULL + .on_stop = &gui_stop }; // endregion diff --git a/components/nanobake/src/apps/services/gui/gui.h b/components/nanobake/src/services/gui/gui.h similarity index 72% rename from components/nanobake/src/apps/services/gui/gui.h rename to components/nanobake/src/services/gui/gui.h index 644239f9..5f5a18f3 100644 --- a/components/nanobake/src/apps/services/gui/gui.h +++ b/components/nanobake/src/services/gui/gui.h @@ -1,20 +1,18 @@ #pragma once -#include "app_manifest.h" +#include "service_manifest.h" #include "view_port.h" #ifdef __cplusplus extern "C" { #endif -extern const AppManifest gui_app; - /** Gui layers */ typedef enum { - GuiLayerDesktop, /**< Desktop layer for internal use. Like fullscreen but with status bar */ - GuiLayerWindow, /**< Window layer, status bar is shown */ + GuiLayerDesktop, /**< Desktop layer for internal use. Like fullscreen but with status bar */ + GuiLayerWindow, /**< Window layer, status bar is shown */ GuiLayerFullscreen, /**< Fullscreen layer, no status bar */ - GuiLayerMAX /**< Don't use or move, special value */ + GuiLayerMAX /**< Don't use or move, special value */ } GuiLayer; typedef struct Gui Gui; diff --git a/components/nanobake/src/apps/services/gui/gui_draw.c b/components/nanobake/src/services/gui/gui_draw.c similarity index 96% rename from components/nanobake/src/apps/services/gui/gui_draw.c rename to components/nanobake/src/services/gui/gui_draw.c index 3144f6ad..05f117c0 100644 --- a/components/nanobake/src/apps/services/gui/gui_draw.c +++ b/components/nanobake/src/services/gui/gui_draw.c @@ -1,10 +1,9 @@ #include "check.h" +#include "esp_lvgl_port.h" #include "gui_i.h" #include "log.h" -#include "record.h" -#include "esp_lvgl_port.h" -#include "apps/services/gui/widgets/widgets.h" -#include "apps/services/loader/loader.h" +#include "services/gui/widgets/widgets.h" +#include "services/loader/loader.h" #define TAG "gui" diff --git a/components/nanobake/src/apps/services/gui/gui_i.h b/components/nanobake/src/services/gui/gui_i.h similarity index 100% rename from components/nanobake/src/apps/services/gui/gui_i.h rename to components/nanobake/src/services/gui/gui_i.h diff --git a/components/nanobake/src/apps/services/gui/gui_input.c b/components/nanobake/src/services/gui/gui_input.c similarity index 100% rename from components/nanobake/src/apps/services/gui/gui_input.c rename to components/nanobake/src/services/gui/gui_input.c diff --git a/components/nanobake/src/apps/services/gui/icon.c b/components/nanobake/src/services/gui/icon.c similarity index 100% rename from components/nanobake/src/apps/services/gui/icon.c rename to components/nanobake/src/services/gui/icon.c diff --git a/components/nanobake/src/apps/services/gui/icon.h b/components/nanobake/src/services/gui/icon.h similarity index 100% rename from components/nanobake/src/apps/services/gui/icon.h rename to components/nanobake/src/services/gui/icon.h diff --git a/components/nanobake/src/apps/services/gui/icon_i.h b/components/nanobake/src/services/gui/icon_i.h similarity index 100% rename from components/nanobake/src/apps/services/gui/icon_i.h rename to components/nanobake/src/services/gui/icon_i.h diff --git a/components/nanobake/src/apps/services/gui/view_port.c b/components/nanobake/src/services/gui/view_port.c similarity index 97% rename from components/nanobake/src/apps/services/gui/view_port.c rename to components/nanobake/src/services/gui/view_port.c index e74a0ef8..c88dd70f 100644 --- a/components/nanobake/src/apps/services/gui/view_port.c +++ b/components/nanobake/src/services/gui/view_port.c @@ -1,8 +1,7 @@ -#include "apps/services/gui/widgets/widgets.h" #include "check.h" -#include "esp_lvgl_port.h" #include "gui.h" #include "gui_i.h" +#include "services/gui/widgets/widgets.h" #include "view_port_i.h" #define TAG "viewport" diff --git a/components/nanobake/src/apps/services/gui/view_port.h b/components/nanobake/src/services/gui/view_port.h similarity index 100% rename from components/nanobake/src/apps/services/gui/view_port.h rename to components/nanobake/src/services/gui/view_port.h diff --git a/components/nanobake/src/apps/services/gui/view_port_i.h b/components/nanobake/src/services/gui/view_port_i.h similarity index 100% rename from components/nanobake/src/apps/services/gui/view_port_i.h rename to components/nanobake/src/services/gui/view_port_i.h diff --git a/components/nanobake/src/apps/services/gui/view_port_input.c b/components/nanobake/src/services/gui/view_port_input.c similarity index 100% rename from components/nanobake/src/apps/services/gui/view_port_input.c rename to components/nanobake/src/services/gui/view_port_input.c diff --git a/components/nanobake/src/apps/services/gui/view_port_input.h b/components/nanobake/src/services/gui/view_port_input.h similarity index 100% rename from components/nanobake/src/apps/services/gui/view_port_input.h rename to components/nanobake/src/services/gui/view_port_input.h diff --git a/components/nanobake/src/apps/services/gui/widgets/spacer.c b/components/nanobake/src/services/gui/widgets/spacer.c similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/spacer.c rename to components/nanobake/src/services/gui/widgets/spacer.c diff --git a/components/nanobake/src/apps/services/gui/widgets/spacer.h b/components/nanobake/src/services/gui/widgets/spacer.h similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/spacer.h rename to components/nanobake/src/services/gui/widgets/spacer.h diff --git a/components/nanobake/src/apps/services/gui/widgets/toolbar.c b/components/nanobake/src/services/gui/widgets/toolbar.c similarity index 89% rename from components/nanobake/src/apps/services/gui/widgets/toolbar.c rename to components/nanobake/src/services/gui/widgets/toolbar.c index 8886b05e..0040b9a8 100644 --- a/components/nanobake/src/apps/services/gui/widgets/toolbar.c +++ b/components/nanobake/src/services/gui/widgets/toolbar.c @@ -1,7 +1,6 @@ #include "toolbar.h" -#include "record.h" -#include "apps/services/gui/widgets/widgets.h" -#include "apps/services/loader/loader.h" +#include "services/gui/widgets/widgets.h" +#include "services/loader/loader.h" static void app_toolbar_close(lv_event_t* event) { loader_stop_app(); @@ -19,7 +18,7 @@ void toolbar(lv_obj_t* parent, lv_coord_t offset_y, const AppManifest* manifest) lv_obj_t* close_button = lv_btn_create(toolbar); lv_obj_set_size(close_button, TOOLBAR_HEIGHT - 4, TOOLBAR_HEIGHT - 4); lv_obj_set_style_no_padding(close_button); - lv_obj_add_event_cb(close_button, &app_toolbar_close,LV_EVENT_CLICKED, NULL); + lv_obj_add_event_cb(close_button, &app_toolbar_close, LV_EVENT_CLICKED, NULL); lv_obj_t* close_button_image = lv_img_create(close_button); lv_img_set_src(close_button_image, LV_SYMBOL_CLOSE); lv_obj_align(close_button_image, LV_ALIGN_CENTER, 0, 0); diff --git a/components/nanobake/src/apps/services/gui/widgets/toolbar.h b/components/nanobake/src/services/gui/widgets/toolbar.h similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/toolbar.h rename to components/nanobake/src/services/gui/widgets/toolbar.h diff --git a/components/nanobake/src/apps/services/gui/widgets/top_bar.c b/components/nanobake/src/services/gui/widgets/top_bar.c similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/top_bar.c rename to components/nanobake/src/services/gui/widgets/top_bar.c diff --git a/components/nanobake/src/apps/services/gui/widgets/top_bar.h b/components/nanobake/src/services/gui/widgets/top_bar.h similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/top_bar.h rename to components/nanobake/src/services/gui/widgets/top_bar.h diff --git a/components/nanobake/src/apps/services/gui/widgets/widgets.c b/components/nanobake/src/services/gui/widgets/widgets.c similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/widgets.c rename to components/nanobake/src/services/gui/widgets/widgets.c diff --git a/components/nanobake/src/apps/services/gui/widgets/widgets.h b/components/nanobake/src/services/gui/widgets/widgets.h similarity index 100% rename from components/nanobake/src/apps/services/gui/widgets/widgets.h rename to components/nanobake/src/services/gui/widgets/widgets.h diff --git a/components/nanobake/src/apps/services/loader/loader.c b/components/nanobake/src/services/loader/loader.c similarity index 96% rename from components/nanobake/src/apps/services/loader/loader.c rename to components/nanobake/src/services/loader/loader.c index 15b4075e..012f8c56 100644 --- a/components/nanobake/src/apps/services/loader/loader.c +++ b/components/nanobake/src/services/loader/loader.c @@ -1,12 +1,13 @@ -#include "loader.h" #include "app_i.h" #include "app_manifest.h" #include "app_manifest_registry.h" -#include "loader_i.h" -#include #include "esp_heap_caps.h" -#include "apps/services/gui/gui.h" +#include "freertos/FreeRTOS.h" #include "freertos/semphr.h" +#include "loader_i.h" +#include "service_manifest.h" +#include "services/gui/gui.h" +#include #define TAG "Loader" @@ -22,7 +23,7 @@ static Loader* loader_alloc() { loader->queue = furi_message_queue_alloc(1, sizeof(LoaderMessage)); loader->thread = furi_thread_alloc_ex( "loader", - AppStackSizeLarge, // Last known minimum was 2400 for starting Hello World app + 4096, // Last known minimum was 2400 for starting Hello World app &loader_main, NULL ); @@ -307,14 +308,10 @@ static void loader_stop() { loader = NULL; } -const AppManifest loader_app = { +const ServiceManifest loader_service = { .id = "loader", - .name = "Loader", - .icon = NULL, - .type = AppTypeService, .on_start = &loader_start, - .on_stop = &loader_stop, - .on_show = NULL + .on_stop = &loader_stop }; // endregion \ No newline at end of file diff --git a/components/nanobake/src/apps/services/loader/loader.h b/components/nanobake/src/services/loader/loader.h similarity index 98% rename from components/nanobake/src/apps/services/loader/loader.h rename to components/nanobake/src/services/loader/loader.h index b0dca57f..75e914f8 100644 --- a/components/nanobake/src/apps/services/loader/loader.h +++ b/components/nanobake/src/services/loader/loader.h @@ -1,8 +1,9 @@ #pragma once +#include "app_manifest.h" #include "furi_core.h" #include "furi_string.h" #include "pubsub.h" -#include "app_manifest.h" +#include "service_manifest.h" #ifdef __cplusplus extern "C" { diff --git a/components/nanobake/src/apps/services/loader/loader_i.h b/components/nanobake/src/services/loader/loader_i.h similarity index 96% rename from components/nanobake/src/apps/services/loader/loader_i.h rename to components/nanobake/src/services/loader/loader_i.h index 39cdb462..028274bc 100644 --- a/components/nanobake/src/apps/services/loader/loader_i.h +++ b/components/nanobake/src/services/loader/loader_i.h @@ -1,12 +1,13 @@ #pragma once + #include "api_lock.h" #include "app_manifest.h" -#include "apps/services/gui/view_port.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "loader.h" #include "message_queue.h" #include "pubsub.h" +#include "services/gui/view_port.h" #include "thread.h" typedef struct { diff --git a/main/src/hello_world/hello_world.c b/main/src/hello_world/hello_world.c index ffb4ec78..c5f7015d 100644 --- a/main/src/hello_world/hello_world.c +++ b/main/src/hello_world/hello_world.c @@ -1,6 +1,6 @@ #include "hello_world.h" -#include "apps/services/gui/gui.h" -#include "apps/services/loader/loader.h" +#include "services/gui/gui.h" +#include "services/loader/loader.h" static void app_show(lv_obj_t* parent, void* context) { UNUSED(context); diff --git a/main/src/main.c b/main/src/main.c index 6fe352b1..f19f2a26 100644 --- a/main/src/main.c +++ b/main/src/main.c @@ -8,9 +8,12 @@ __attribute__((unused)) void app_main(void) { static const Config config = { .hardware = NB_BOARD_HARDWARE, .apps = { - &hello_world_app + &hello_world_app, + NULL // NULL terminator - do not remove + }, + .services = { + NULL // NULL terminator - do not remove }, - .apps_count = 1 }; nanobake_start(&config);