[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 "u2f_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const u2f_scene_on_enter_handlers[])(void*) = {
#include "u2f_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 u2f_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "u2f_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 u2f_scene_on_exit_handlers[])(void* context) = {
#include "u2f_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers u2f_scene_handlers = {
.on_enter_handlers = u2f_scene_on_enter_handlers,
.on_event_handlers = u2f_scene_on_event_handlers,
.on_exit_handlers = u2f_scene_on_exit_handlers,
.scene_num = U2fSceneNum,
};

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

View File

@@ -0,0 +1,2 @@
ADD_SCENE(u2f, main, Main)
ADD_SCENE(u2f, error, Error)

View File

@@ -0,0 +1,61 @@
#include "../u2f_app_i.h"
static void u2f_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
U2fApp* app = context;
if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventErrorBack);
}
}
void u2f_scene_error_on_enter(void* context) {
U2fApp* app = context;
if(app->error == U2fAppErrorNoFiles) {
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", u2f_scene_error_event_callback, app);
} else if(app->error == U2fAppErrorCloseRpc) {
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, U2fAppViewError);
}
bool u2f_scene_error_on_event(void* context, SceneManagerEvent event) {
U2fApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == U2fCustomEventErrorBack) {
view_dispatcher_stop(app->view_dispatcher);
consumed = true;
}
}
return consumed;
}
void u2f_scene_error_on_exit(void* context) {
U2fApp* app = context;
widget_reset(app->widget);
}

View File

@@ -0,0 +1,122 @@
#include "../u2f_app_i.h"
#include "../views/u2f_view.h"
#include <dolphin/dolphin.h>
#include "furi_hal.h"
#include "../u2f.h"
#define U2F_REQUEST_TIMEOUT 500
#define U2F_SUCCESS_TIMEOUT 3000
static void u2f_scene_main_ok_callback(InputType type, void* context) {
UNUSED(type);
furi_assert(context);
U2fApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventConfirm);
}
static void u2f_scene_main_event_callback(U2fNotifyEvent evt, void* context) {
furi_assert(context);
U2fApp* app = context;
if(evt == U2fNotifyRegister)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventRegister);
else if(evt == U2fNotifyAuth)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventAuth);
else if(evt == U2fNotifyAuthSuccess)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventAuthSuccess);
else if(evt == U2fNotifyWink)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventWink);
else if(evt == U2fNotifyConnect)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventConnect);
else if(evt == U2fNotifyDisconnect)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDisconnect);
else if(evt == U2fNotifyError)
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventDataError);
}
static void u2f_scene_main_timer_callback(void* context) {
furi_assert(context);
U2fApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, U2fCustomEventTimeout);
}
bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) {
furi_assert(context);
U2fApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == U2fCustomEventConnect) {
furi_timer_stop(app->timer);
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
} else if(event.event == U2fCustomEventDisconnect) {
furi_timer_stop(app->timer);
app->event_cur = U2fCustomEventNone;
u2f_view_set_state(app->u2f_view, U2fMsgNotConnected);
} else if((event.event == U2fCustomEventRegister) || (event.event == U2fCustomEventAuth)) {
furi_timer_start(app->timer, U2F_REQUEST_TIMEOUT);
if(app->event_cur == U2fCustomEventNone) {
app->event_cur = event.event;
if(event.event == U2fCustomEventRegister)
u2f_view_set_state(app->u2f_view, U2fMsgRegister);
else if(event.event == U2fCustomEventAuth)
u2f_view_set_state(app->u2f_view, U2fMsgAuth);
notification_message(app->notifications, &sequence_display_backlight_on);
notification_message(app->notifications, &sequence_single_vibro);
}
notification_message(app->notifications, &sequence_blink_magenta_10);
} else if(event.event == U2fCustomEventWink) {
notification_message(app->notifications, &sequence_blink_magenta_10);
} else if(event.event == U2fCustomEventAuthSuccess) {
notification_message_block(app->notifications, &sequence_set_green_255);
DOLPHIN_DEED(DolphinDeedU2fAuthorized);
furi_timer_start(app->timer, U2F_SUCCESS_TIMEOUT);
app->event_cur = U2fCustomEventNone;
u2f_view_set_state(app->u2f_view, U2fMsgSuccess);
} else if(event.event == U2fCustomEventTimeout) {
notification_message_block(app->notifications, &sequence_reset_rgb);
app->event_cur = U2fCustomEventNone;
u2f_view_set_state(app->u2f_view, U2fMsgIdle);
} else if(event.event == U2fCustomEventConfirm) {
if(app->event_cur != U2fCustomEventNone) {
u2f_confirm_user_present(app->u2f_instance);
}
} else if(event.event == U2fCustomEventDataError) {
notification_message(app->notifications, &sequence_set_red_255);
furi_timer_stop(app->timer);
u2f_view_set_state(app->u2f_view, U2fMsgError);
}
consumed = true;
}
return consumed;
}
void u2f_scene_main_on_enter(void* context) {
U2fApp* app = context;
app->timer = furi_timer_alloc(u2f_scene_main_timer_callback, FuriTimerTypeOnce, app);
app->u2f_instance = u2f_alloc();
app->u2f_ready = u2f_init(app->u2f_instance);
if(app->u2f_ready == true) {
u2f_set_event_callback(app->u2f_instance, u2f_scene_main_event_callback, app);
app->u2f_hid = u2f_hid_start(app->u2f_instance);
u2f_view_set_ok_callback(app->u2f_view, u2f_scene_main_ok_callback, app);
} else {
u2f_free(app->u2f_instance);
u2f_view_set_state(app->u2f_view, U2fMsgError);
}
view_dispatcher_switch_to_view(app->view_dispatcher, U2fAppViewMain);
}
void u2f_scene_main_on_exit(void* context) {
U2fApp* app = context;
notification_message_block(app->notifications, &sequence_reset_rgb);
furi_timer_stop(app->timer);
furi_timer_free(app->timer);
if(app->u2f_ready == true) {
u2f_hid_stop(app->u2f_hid);
u2f_free(app->u2f_instance);
}
}