[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,409 @@
#include "../animation_manager.h"
#include "../animation_storage.h"
#include "bubble_animation_view.h"
#include <furi_hal.h>
#include <furi.h>
#include <gui/canvas.h>
#include <gui/elements.h>
#include <gui/view.h>
#include <gui/icon_i.h>
#include <input/input.h>
#include <stdint.h>
#include <core/dangerous_defines.h>
#define ACTIVE_SHIFT 2
typedef struct {
const BubbleAnimation* current;
const FrameBubble* current_bubble;
uint8_t current_frame;
uint8_t active_cycle;
uint8_t active_bubbles;
uint8_t passive_bubbles;
uint8_t active_shift;
TickType_t active_ended_at;
Icon* freeze_frame;
} BubbleAnimationViewModel;
struct BubbleAnimationView {
View* view;
FuriTimer* timer;
BubbleAnimationInteractCallback interact_callback;
void* interact_callback_context;
};
static void bubble_animation_activate(BubbleAnimationView* view, bool force);
static void bubble_animation_activate_right_now(BubbleAnimationView* view);
static uint8_t bubble_animation_get_frame_index(BubbleAnimationViewModel* model) {
furi_assert(model);
uint8_t icon_index = 0;
const BubbleAnimation* animation = model->current;
if(model->current_frame < animation->passive_frames) {
icon_index = model->current_frame;
} else {
icon_index =
(model->current_frame - animation->passive_frames) % animation->active_frames +
animation->passive_frames;
}
furi_assert(icon_index < (animation->passive_frames + animation->active_frames));
return animation->frame_order[icon_index];
}
static void bubble_animation_draw_callback(Canvas* canvas, void* model_) {
furi_assert(model_);
furi_assert(canvas);
BubbleAnimationViewModel* model = model_;
const BubbleAnimation* animation = model->current;
if(model->freeze_frame) {
uint8_t y_offset = canvas_height(canvas) - icon_get_height(model->freeze_frame);
canvas_draw_icon(canvas, 0, y_offset, model->freeze_frame);
return;
}
if(!animation) {
return;
}
furi_assert(model->current_frame < 255);
uint8_t index = bubble_animation_get_frame_index(model);
uint8_t width = icon_get_width(&animation->icon_animation);
uint8_t height = icon_get_height(&animation->icon_animation);
uint8_t y_offset = canvas_height(canvas) - height;
canvas_draw_bitmap(
canvas, 0, y_offset, width, height, animation->icon_animation.frames[index]);
const FrameBubble* bubble = model->current_bubble;
if(bubble) {
if((model->current_frame >= bubble->start_frame) &&
(model->current_frame <= bubble->end_frame)) {
const Bubble* b = &bubble->bubble;
elements_bubble_str(canvas, b->x, b->y, b->text, b->align_h, b->align_v);
}
}
}
static const FrameBubble*
bubble_animation_pick_bubble(BubbleAnimationViewModel* model, bool active) {
const FrameBubble* bubble = NULL;
if((model->active_bubbles == 0) && (model->passive_bubbles == 0)) {
return NULL;
}
uint8_t index =
furi_hal_random_get() % (active ? model->active_bubbles : model->passive_bubbles);
const BubbleAnimation* animation = model->current;
for(int i = 0; i < animation->frame_bubble_sequences_count; ++i) {
if((animation->frame_bubble_sequences[i]->start_frame < animation->passive_frames) ^
active) {
if(!index) {
bubble = animation->frame_bubble_sequences[i];
}
--index;
}
}
return bubble;
}
static bool bubble_animation_input_callback(InputEvent* event, void* context) {
furi_assert(context);
furi_assert(event);
BubbleAnimationView* animation_view = context;
bool consumed = false;
if(event->type == InputTypePress) {
bubble_animation_activate(animation_view, false);
}
if(event->key == InputKeyRight) {
/* Right button reserved for animation activation, so consume */
consumed = true;
if(event->type == InputTypeShort) {
if(animation_view->interact_callback) {
animation_view->interact_callback(animation_view->interact_callback_context);
}
}
}
return consumed;
}
static void bubble_animation_activate(BubbleAnimationView* view, bool force) {
furi_assert(view);
bool activate = true;
BubbleAnimationViewModel* model = view_get_model(view->view);
if(model->current == NULL) {
activate = false;
} else if(model->freeze_frame) {
activate = false;
} else if(model->current->active_frames == 0) {
activate = false;
}
if(model->current != NULL) {
if(!force) {
if((model->active_ended_at + model->current->active_cooldown * 1000) >
xTaskGetTickCount()) {
activate = false;
} else if(model->active_shift) {
activate = false;
} else if(model->current_frame >= model->current->passive_frames) {
activate = false;
}
}
}
view_commit_model(view->view, false);
if(!activate && !force) {
return;
}
if(ACTIVE_SHIFT > 0) {
BubbleAnimationViewModel* model = view_get_model(view->view);
model->active_shift = ACTIVE_SHIFT;
view_commit_model(view->view, false);
} else {
bubble_animation_activate_right_now(view);
}
}
static void bubble_animation_activate_right_now(BubbleAnimationView* view) {
furi_assert(view);
uint8_t frame_rate = 0;
BubbleAnimationViewModel* model = view_get_model(view->view);
if(model->current && (model->current->active_frames > 0) && (!model->freeze_frame)) {
model->current_frame = model->current->passive_frames;
model->current_bubble = bubble_animation_pick_bubble(model, true);
frame_rate = model->current->icon_animation.frame_rate;
}
view_commit_model(view->view, true);
if(frame_rate) {
furi_timer_start(view->timer, 1000 / frame_rate);
}
}
static void bubble_animation_next_frame(BubbleAnimationViewModel* model) {
furi_assert(model);
if(!model->current) {
return;
}
if(model->current_frame < model->current->passive_frames) {
model->current_frame = (model->current_frame + 1) % model->current->passive_frames;
} else {
++model->current_frame;
model->active_cycle +=
!((model->current_frame - model->current->passive_frames) %
model->current->active_frames);
if(model->active_cycle >= model->current->active_cycles) {
// switch to passive
model->active_cycle = 0;
model->current_frame = 0;
model->current_bubble = bubble_animation_pick_bubble(model, false);
model->active_ended_at = xTaskGetTickCount();
}
if(model->current_bubble) {
if(model->current_frame > model->current_bubble->end_frame) {
model->current_bubble = model->current_bubble->next_bubble;
}
}
}
}
static void bubble_animation_timer_callback(void* context) {
furi_assert(context);
BubbleAnimationView* view = context;
bool activate = false;
BubbleAnimationViewModel* model = view_get_model(view->view);
if(model->active_shift > 0) {
activate = (--model->active_shift == 0);
}
if(!model->freeze_frame && !activate) {
bubble_animation_next_frame(model);
}
view_commit_model(view->view, !activate);
if(activate) {
bubble_animation_activate_right_now(view);
}
}
/* always freeze first passive frame, because
* animation is always activated at unfreezing and played
* passive frame first, and 2 frames after - active
*/
static Icon* bubble_animation_clone_first_frame(const Icon* icon_orig) {
furi_assert(icon_orig);
furi_assert(icon_orig->frames);
furi_assert(icon_orig->frames[0]);
Icon* icon_clone = malloc(sizeof(Icon));
memcpy(icon_clone, icon_orig, sizeof(Icon));
icon_clone->frames = malloc(sizeof(uint8_t*));
/* icon bitmap can be either compressed or not. It is compressed if
* compressed size is less than original, so max size for bitmap is
* uncompressed (width * height) + 1 byte (in uncompressed case)
* for compressed header
*/
size_t max_bitmap_size = ROUND_UP_TO(icon_orig->width, 8) * icon_orig->height + 1;
FURI_CONST_ASSIGN_PTR(icon_clone->frames[0], malloc(max_bitmap_size));
memcpy((void*)icon_clone->frames[0], icon_orig->frames[0], max_bitmap_size);
FURI_CONST_ASSIGN(icon_clone->frame_count, 1);
return icon_clone;
}
static void bubble_animation_release_frame(Icon** icon) {
furi_assert(icon);
furi_assert(*icon);
free((void*)(*icon)->frames[0]);
free((void*)(*icon)->frames);
free(*icon);
*icon = NULL;
}
static void bubble_animation_enter(void* context) {
furi_assert(context);
BubbleAnimationView* view = context;
bubble_animation_activate(view, false);
BubbleAnimationViewModel* model = view_get_model(view->view);
uint8_t frame_rate = 0;
if(model->current != NULL) {
frame_rate = model->current->icon_animation.frame_rate;
}
view_commit_model(view->view, false);
if(frame_rate) {
furi_timer_start(view->timer, 1000 / frame_rate);
}
}
static void bubble_animation_exit(void* context) {
furi_assert(context);
BubbleAnimationView* view = context;
furi_timer_stop(view->timer);
}
BubbleAnimationView* bubble_animation_view_alloc(void) {
BubbleAnimationView* view = malloc(sizeof(BubbleAnimationView));
view->view = view_alloc();
view->interact_callback = NULL;
view->timer = furi_timer_alloc(bubble_animation_timer_callback, FuriTimerTypePeriodic, view);
view_allocate_model(view->view, ViewModelTypeLocking, sizeof(BubbleAnimationViewModel));
view_set_context(view->view, view);
view_set_draw_callback(view->view, bubble_animation_draw_callback);
view_set_input_callback(view->view, bubble_animation_input_callback);
view_set_enter_callback(view->view, bubble_animation_enter);
view_set_exit_callback(view->view, bubble_animation_exit);
return view;
}
void bubble_animation_view_free(BubbleAnimationView* view) {
furi_assert(view);
view_set_draw_callback(view->view, NULL);
view_set_input_callback(view->view, NULL);
view_set_context(view->view, NULL);
view_free(view->view);
view->view = NULL;
free(view);
}
void bubble_animation_view_set_interact_callback(
BubbleAnimationView* view,
BubbleAnimationInteractCallback callback,
void* context) {
furi_assert(view);
view->interact_callback_context = context;
view->interact_callback = callback;
}
void bubble_animation_view_set_animation(
BubbleAnimationView* view,
const BubbleAnimation* new_animation) {
furi_assert(view);
furi_assert(new_animation);
BubbleAnimationViewModel* model = view_get_model(view->view);
furi_assert(model);
model->current = new_animation;
model->active_ended_at = xTaskGetTickCount() - (model->current->active_cooldown * 1000);
model->active_bubbles = 0;
model->passive_bubbles = 0;
for(int i = 0; i < new_animation->frame_bubble_sequences_count; ++i) {
if(new_animation->frame_bubble_sequences[i]->start_frame < new_animation->passive_frames) {
++model->passive_bubbles;
} else {
++model->active_bubbles;
}
}
/* select bubble sequence */
model->current_bubble = bubble_animation_pick_bubble(model, false);
model->current_frame = 0;
model->active_cycle = 0;
view_commit_model(view->view, true);
furi_timer_start(view->timer, 1000 / new_animation->icon_animation.frame_rate);
}
void bubble_animation_freeze(BubbleAnimationView* view) {
furi_assert(view);
BubbleAnimationViewModel* model = view_get_model(view->view);
furi_assert(model->current);
furi_assert(!model->freeze_frame);
model->freeze_frame = bubble_animation_clone_first_frame(&model->current->icon_animation);
model->current = NULL;
view_commit_model(view->view, false);
furi_timer_stop(view->timer);
}
void bubble_animation_unfreeze(BubbleAnimationView* view) {
furi_assert(view);
uint8_t frame_rate;
BubbleAnimationViewModel* model = view_get_model(view->view);
furi_assert(model->freeze_frame);
bubble_animation_release_frame(&model->freeze_frame);
furi_assert(model->current);
frame_rate = model->current->icon_animation.frame_rate;
view_commit_model(view->view, true);
furi_timer_start(view->timer, 1000 / frame_rate);
bubble_animation_activate(view, false);
}
View* bubble_animation_get_view(BubbleAnimationView* view) {
furi_assert(view);
return view->view;
}

View File

@@ -0,0 +1,89 @@
#pragma once
#include <gui/view.h>
#include "../animation_manager.h"
/** Bubble Animation instance */
typedef struct BubbleAnimationView BubbleAnimationView;
/** Callback type to be called when interact button pressed */
typedef void (*BubbleAnimationInteractCallback)(void*);
/**
* Allocate bubble animation view.
* This is animation with bubbles, and 2 phases:
* active and passive.
*
* @return instance of new bubble animation
*/
BubbleAnimationView* bubble_animation_view_alloc(void);
/**
* Free bubble animation view.
*
* @view bubble animation view instance
*/
void bubble_animation_view_free(BubbleAnimationView* view);
/**
* Set callback for interact action for animation.
* Currently this is right button.
*
* @view bubble animation view instance
* @callback callback to call when button pressed
* @context context
*/
void bubble_animation_view_set_interact_callback(
BubbleAnimationView* view,
BubbleAnimationInteractCallback callback,
void* context);
/**
* Set new animation.
* BubbleAnimation doesn't posses Bubble Animation object
* so it doesn't handle any memory manipulation on Bubble Animations.
*
* @view bubble animation view instance
* @new_bubble_animation new animation to set
*/
void bubble_animation_view_set_animation(
BubbleAnimationView* view,
const BubbleAnimation* new_bubble_animation);
/**
* Get view of bubble animation.
*
* @view bubble animation view instance
* @return view
*/
View* bubble_animation_get_view(BubbleAnimationView* view);
/**
* Freeze current playing animation. Saves a frame to be shown
* during next unfreeze called.
* bubble_animation_freeze() stops any reference to 'current' animation
* so it can be freed. Therefore lock unfreeze should be preceeded with
* new animation set.
*
* Freeze/Unfreeze usage example:
*
* animation_view_alloc()
* set_animation()
* ...
* freeze_animation()
* // release animation
* ...
* // allocate animation
* set_animation()
* unfreeze()
*
* @view bubble animation view instance
*/
void bubble_animation_freeze(BubbleAnimationView* view);
/**
* Starts bubble animation after freezing.
*
* @view bubble animation view instance
*/
void bubble_animation_unfreeze(BubbleAnimationView* view);

View File

@@ -0,0 +1,130 @@
#include "one_shot_animation_view.h"
#include <furi.h>
#include <portmacro.h>
#include <gui/canvas.h>
#include <gui/view.h>
#include <gui/icon_i.h>
#include <stdint.h>
typedef void (*OneShotInteractCallback)(void*);
struct OneShotView {
View* view;
TimerHandle_t update_timer;
OneShotInteractCallback interact_callback;
void* interact_callback_context;
};
typedef struct {
const Icon* icon;
uint32_t index;
bool block_input;
} OneShotViewModel;
static void one_shot_view_update_timer_callback(TimerHandle_t xTimer) {
OneShotView* view = (void*)pvTimerGetTimerID(xTimer);
OneShotViewModel* model = view_get_model(view->view);
if((model->index + 1) < model->icon->frame_count) {
++model->index;
} else {
model->block_input = false;
model->index = model->icon->frame_count - 2;
}
view_commit_model(view->view, true);
}
static void one_shot_view_draw(Canvas* canvas, void* model_) {
furi_assert(canvas);
furi_assert(model_);
OneShotViewModel* model = model_;
furi_check(model->index < model->icon->frame_count);
uint8_t y_offset = canvas_height(canvas) - model->icon->height;
canvas_draw_bitmap(
canvas,
0,
y_offset,
model->icon->width,
model->icon->height,
model->icon->frames[model->index]);
}
static bool one_shot_view_input(InputEvent* event, void* context) {
furi_assert(context);
furi_assert(event);
OneShotView* view = context;
bool consumed = false;
OneShotViewModel* model = view_get_model(view->view);
consumed = model->block_input;
view_commit_model(view->view, false);
if(!consumed) {
if(event->key == InputKeyRight) {
/* Right button reserved for animation activation, so consume */
consumed = true;
if(event->type == InputTypeShort) {
if(view->interact_callback) {
view->interact_callback(view->interact_callback_context);
}
}
}
}
return consumed;
}
OneShotView* one_shot_view_alloc(void) {
OneShotView* view = malloc(sizeof(OneShotView));
view->view = view_alloc();
view->update_timer =
xTimerCreate(NULL, 1000, pdTRUE, view, one_shot_view_update_timer_callback);
view_allocate_model(view->view, ViewModelTypeLocking, sizeof(OneShotViewModel));
view_set_context(view->view, view);
view_set_draw_callback(view->view, one_shot_view_draw);
view_set_input_callback(view->view, one_shot_view_input);
return view;
}
void one_shot_view_free(OneShotView* view) {
furi_assert(view);
xTimerDelete(view->update_timer, portMAX_DELAY);
view_free(view->view);
view->view = NULL;
free(view);
}
void one_shot_view_set_interact_callback(
OneShotView* view,
OneShotInteractCallback callback,
void* context) {
furi_assert(view);
view->interact_callback_context = context;
view->interact_callback = callback;
}
void one_shot_view_start_animation(OneShotView* view, const Icon* icon) {
furi_assert(view);
furi_assert(icon);
furi_check(icon->frame_count >= 2);
OneShotViewModel* model = view_get_model(view->view);
model->index = 0;
model->icon = icon;
model->block_input = true;
view_commit_model(view->view, true);
xTimerChangePeriod(view->update_timer, 1000 / model->icon->frame_rate, portMAX_DELAY);
}
View* one_shot_view_get_view(OneShotView* view) {
furi_assert(view);
return view->view;
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include <furi.h>
#include <gui/view.h>
#include <stdint.h>
typedef void (*OneShotInteractCallback)(void*);
typedef struct OneShotView OneShotView;
OneShotView* one_shot_view_alloc(void);
void one_shot_view_free(OneShotView* view);
void one_shot_view_set_interact_callback(
OneShotView* view,
OneShotInteractCallback callback,
void* context);
void one_shot_view_start_animation(OneShotView* view, const Icon* icon);
View* one_shot_view_get_view(OneShotView* view);