[FL-2627] Flipper applications: SDK, build and debug system (#1387)

* Added support for running applications from SD card (FAPs - Flipper Application Packages)
* Added plugin_dist target for fbt to build FAPs
* All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default
* Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them
* Added debugging support for FAPs with fbt debug & VSCode
* Added public firmware API with automated versioning

Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
SG
2022-09-15 02:11:38 +10:00
committed by Aleksandr Kutuzov
parent 0f6f9ad52e
commit b9a766d909
895 changed files with 8862 additions and 1465 deletions

View File

@@ -0,0 +1,11 @@
App(
appid="file_browser_test",
name="File Browser Test",
apptype=FlipperAppType.DEBUG,
entry_point="file_browser_app",
cdefines=["APP_FILE_BROWSER_TEST"],
requires=["gui"],
stack_size=2 * 1024,
order=150,
fap_category="Debug",
)

View File

@@ -0,0 +1,99 @@
#include "assets_icons.h"
#include "file_browser_app_i.h"
#include "gui/modules/file_browser.h"
#include "m-string.h"
#include <furi.h>
#include <furi_hal.h>
#include <storage/storage.h>
#include <lib/toolbox/path.h>
static bool file_browser_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
FileBrowserApp* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
static bool file_browser_app_back_event_callback(void* context) {
furi_assert(context);
FileBrowserApp* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
static void file_browser_app_tick_event_callback(void* context) {
furi_assert(context);
FileBrowserApp* app = context;
scene_manager_handle_tick_event(app->scene_manager);
}
FileBrowserApp* file_browser_app_alloc(char* arg) {
UNUSED(arg);
FileBrowserApp* app = malloc(sizeof(FileBrowserApp));
app->gui = furi_record_open(RECORD_GUI);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
app->scene_manager = scene_manager_alloc(&file_browser_scene_handlers, app);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_tick_event_callback(
app->view_dispatcher, file_browser_app_tick_event_callback, 500);
view_dispatcher_set_custom_event_callback(
app->view_dispatcher, file_browser_app_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, file_browser_app_back_event_callback);
app->widget = widget_alloc();
string_init(app->file_path);
app->file_browser = file_browser_alloc(app->file_path);
file_browser_configure(app->file_browser, "*", true, &I_badusb_10px, true);
view_dispatcher_add_view(
app->view_dispatcher, FileBrowserAppViewStart, widget_get_view(app->widget));
view_dispatcher_add_view(
app->view_dispatcher, FileBrowserAppViewResult, widget_get_view(app->widget));
view_dispatcher_add_view(
app->view_dispatcher, FileBrowserAppViewBrowser, file_browser_get_view(app->file_browser));
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(app->scene_manager, FileBrowserSceneStart);
return app;
}
void file_browser_app_free(FileBrowserApp* app) {
furi_assert(app);
// Views
view_dispatcher_remove_view(app->view_dispatcher, FileBrowserAppViewStart);
view_dispatcher_remove_view(app->view_dispatcher, FileBrowserAppViewResult);
view_dispatcher_remove_view(app->view_dispatcher, FileBrowserAppViewBrowser);
widget_free(app->widget);
file_browser_free(app->file_browser);
// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
// Close records
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_DIALOGS);
string_clear(app->file_path);
free(app);
}
int32_t file_browser_app(void* p) {
FileBrowserApp* file_browser_app = file_browser_app_alloc((char*)p);
view_dispatcher_run(file_browser_app->view_dispatcher);
file_browser_app_free(file_browser_app);
return 0;
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include "scenes/file_browser_scene.h"
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/submenu.h>
#include <gui/modules/file_browser.h>
#include <dialogs/dialogs.h>
#include <notification/notification_messages.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/widget.h>
typedef struct FileBrowserApp FileBrowserApp;
struct FileBrowserApp {
Gui* gui;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
DialogsApp* dialogs;
Widget* widget;
FileBrowser* file_browser;
string_t file_path;
};
typedef enum {
FileBrowserAppViewStart,
FileBrowserAppViewBrowser,
FileBrowserAppViewResult,
} FileBrowserAppView;

View File

@@ -0,0 +1,30 @@
#include "file_browser_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const file_browser_scene_on_enter_handlers[])(void*) = {
#include "file_browser_scene_config.h"
};
#undef ADD_SCENE
// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const file_browser_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "file_browser_scene_config.h"
};
#undef ADD_SCENE
// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const file_browser_scene_on_exit_handlers[])(void* context) = {
#include "file_browser_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers file_browser_scene_handlers = {
.on_enter_handlers = file_browser_scene_on_enter_handlers,
.on_event_handlers = file_browser_scene_on_event_handlers,
.on_exit_handlers = file_browser_scene_on_exit_handlers,
.scene_num = FileBrowserSceneNum,
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <gui/scene_manager.h>
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) FileBrowserScene##id,
typedef enum {
#include "file_browser_scene_config.h"
FileBrowserSceneNum,
} FileBrowserScene;
#undef ADD_SCENE
extern const SceneManagerHandlers file_browser_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "file_browser_scene_config.h"
#undef ADD_SCENE
// Generate scene on_event handlers declaration
#define ADD_SCENE(prefix, name, id) \
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
#include "file_browser_scene_config.h"
#undef ADD_SCENE
// Generate scene on_exit handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
#include "file_browser_scene_config.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,43 @@
#include "../file_browser_app_i.h"
#include <core/check.h>
#include <core/log.h>
#include "furi_hal.h"
#include "m-string.h"
#define DEFAULT_PATH "/"
#define EXTENSION "*"
bool file_browser_scene_browser_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
FileBrowserApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_next_scene(app->scene_manager, FileBrowserSceneResult);
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
}
return consumed;
}
static void file_browser_callback(void* context) {
FileBrowserApp* app = context;
furi_assert(app);
view_dispatcher_send_custom_event(app->view_dispatcher, SceneManagerEventTypeCustom);
}
void file_browser_scene_browser_on_enter(void* context) {
FileBrowserApp* app = context;
file_browser_set_callback(app->file_browser, file_browser_callback, app);
file_browser_start(app->file_browser, app->file_path);
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewBrowser);
}
void file_browser_scene_browser_on_exit(void* context) {
FileBrowserApp* app = context;
file_browser_stop(app->file_browser);
}

View File

@@ -0,0 +1,3 @@
ADD_SCENE(file_browser, start, Start)
ADD_SCENE(file_browser, browser, Browser)
ADD_SCENE(file_browser, result, Result)

View File

@@ -0,0 +1,36 @@
#include "../file_browser_app_i.h"
#include "furi_hal.h"
#include "m-string.h"
void file_browser_scene_result_ok_callback(InputType type, void* context) {
furi_assert(context);
FileBrowserApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, type);
}
bool file_browser_scene_result_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
//FileBrowserApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
}
return consumed;
}
void file_browser_scene_result_on_enter(void* context) {
FileBrowserApp* app = context;
widget_add_string_multiline_element(
app->widget, 64, 10, AlignCenter, AlignTop, FontSecondary, string_get_cstr(app->file_path));
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewResult);
}
void file_browser_scene_result_on_exit(void* context) {
UNUSED(context);
FileBrowserApp* app = context;
widget_reset(app->widget);
}

View File

@@ -0,0 +1,46 @@
#include "../file_browser_app_i.h"
#include <furi_hal.h>
#include <gui/modules/widget_elements/widget_element_i.h>
#include <storage/storage.h>
static void
file_browser_scene_start_ok_callback(GuiButtonType result, InputType type, void* context) {
UNUSED(result);
furi_assert(context);
FileBrowserApp* app = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(app->view_dispatcher, type);
}
}
bool file_browser_scene_start_on_event(void* context, SceneManagerEvent event) {
FileBrowserApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
string_set_str(app->file_path, ANY_PATH("badusb/demo_windows.txt"));
scene_manager_next_scene(app->scene_manager, FileBrowserSceneBrowser);
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
}
return consumed;
}
void file_browser_scene_start_on_enter(void* context) {
FileBrowserApp* app = context;
widget_add_string_multiline_element(
app->widget, 64, 20, AlignCenter, AlignTop, FontSecondary, "Press OK to start");
widget_add_button_element(
app->widget, GuiButtonTypeCenter, "Ok", file_browser_scene_start_ok_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewStart);
}
void file_browser_scene_start_on_exit(void* context) {
UNUSED(context);
FileBrowserApp* app = context;
widget_reset(app->widget);
}