[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,30 @@
#include "bad_usb_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const bad_usb_scene_on_enter_handlers[])(void*) = {
#include "bad_usb_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 bad_usb_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "bad_usb_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 bad_usb_scene_on_exit_handlers[])(void* context) = {
#include "bad_usb_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers bad_usb_scene_handlers = {
.on_enter_handlers = bad_usb_scene_on_enter_handlers,
.on_event_handlers = bad_usb_scene_on_event_handlers,
.on_exit_handlers = bad_usb_scene_on_exit_handlers,
.scene_num = BadUsbSceneNum,
};

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) BadUsbScene##id,
typedef enum {
#include "bad_usb_scene_config.h"
BadUsbSceneNum,
} BadUsbScene;
#undef ADD_SCENE
extern const SceneManagerHandlers bad_usb_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "bad_usb_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 "bad_usb_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 "bad_usb_scene_config.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,3 @@
ADD_SCENE(bad_usb, file_select, FileSelect)
ADD_SCENE(bad_usb, work, Work)
ADD_SCENE(bad_usb, error, Error)

View File

@@ -0,0 +1,65 @@
#include "../bad_usb_app_i.h"
typedef enum {
BadUsbCustomEventErrorBack,
} BadUsbCustomEvent;
static void
bad_usb_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
BadUsbApp* app = context;
if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(app->view_dispatcher, BadUsbCustomEventErrorBack);
}
}
void bad_usb_scene_error_on_enter(void* context) {
BadUsbApp* app = context;
if(app->error == BadUsbAppErrorNoFiles) {
widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);
widget_add_string_multiline_element(
app->widget,
81,
4,
AlignCenter,
AlignTop,
FontSecondary,
"No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");
widget_add_button_element(
app->widget, GuiButtonTypeLeft, "Back", bad_usb_scene_error_event_callback, app);
} else if(app->error == BadUsbAppErrorCloseRpc) {
widget_add_icon_element(app->widget, 78, 0, &I_ActiveConnection_50x64);
widget_add_string_multiline_element(
app->widget, 3, 2, AlignLeft, AlignTop, FontPrimary, "Connection\nis active!");
widget_add_string_multiline_element(
app->widget,
3,
30,
AlignLeft,
AlignTop,
FontSecondary,
"Disconnect from\nPC or phone to\nuse this function.");
}
view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewError);
}
bool bad_usb_scene_error_on_event(void* context, SceneManagerEvent event) {
BadUsbApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == BadUsbCustomEventErrorBack) {
view_dispatcher_stop(app->view_dispatcher);
consumed = true;
}
}
return consumed;
}
void bad_usb_scene_error_on_exit(void* context) {
BadUsbApp* app = context;
widget_reset(app->widget);
}

View File

@@ -0,0 +1,42 @@
#include "../bad_usb_app_i.h"
#include "furi_hal_power.h"
#include "furi_hal_usb.h"
static bool bad_usb_file_select(BadUsbApp* bad_usb) {
furi_assert(bad_usb);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, BAD_USB_APP_EXTENSION, &I_badusb_10px);
// Input events and views are managed by file_browser
bool res = dialog_file_browser_show(
bad_usb->dialogs, bad_usb->file_path, bad_usb->file_path, &browser_options);
return res;
}
void bad_usb_scene_file_select_on_enter(void* context) {
BadUsbApp* bad_usb = context;
furi_hal_usb_disable();
if(bad_usb_file_select(bad_usb)) {
scene_manager_next_scene(bad_usb->scene_manager, BadUsbSceneWork);
} else {
furi_hal_usb_enable();
//scene_manager_previous_scene(bad_usb->scene_manager);
view_dispatcher_stop(bad_usb->view_dispatcher);
}
}
bool bad_usb_scene_file_select_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
// BadUsbApp* bad_usb = context;
return false;
}
void bad_usb_scene_file_select_on_exit(void* context) {
UNUSED(context);
// BadUsbApp* bad_usb = context;
}

View File

@@ -0,0 +1,48 @@
#include "../bad_usb_script.h"
#include "../bad_usb_app_i.h"
#include "../views/bad_usb_view.h"
#include "furi_hal.h"
#include "m-string.h"
#include "toolbox/path.h"
void bad_usb_scene_work_ok_callback(InputType type, void* context) {
furi_assert(context);
BadUsbApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, type);
}
bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
BadUsbApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
bad_usb_script_toggle(app->bad_usb_script);
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
}
return consumed;
}
void bad_usb_scene_work_on_enter(void* context) {
BadUsbApp* app = context;
string_t file_name;
string_init(file_name);
path_extract_filename(app->file_path, file_name, true);
bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name));
app->bad_usb_script = bad_usb_script_open(app->file_path);
string_clear(file_name);
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
bad_usb_set_ok_callback(app->bad_usb_view, bad_usb_scene_work_ok_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork);
}
void bad_usb_scene_work_on_exit(void* context) {
BadUsbApp* app = context;
bad_usb_script_close(app->bad_usb_script);
}