Skip to content

Commit

Permalink
Settings: Hybrid internal/external, unused for now
Browse files Browse the repository at this point in the history
- Reverts part of acc352e
- Reverts part of ca5f3bb
- Based partly on 71d1c1d
- Use FlipperInternalApplication for settings for settings
- Set FlipperInternalApplicationFlagExternal accordingly
- Keep storage and power settings internal, all others external
- Unused for now, uses too much flash:
  - Previously: 29kb free flash
  - All internal: 4kb free flash
  - Power internal: 22kb free flash
  - Power and storage internal: 16kb free flash
  • Loading branch information
Willy-JL committed Sep 5, 2024
1 parent f65d4bb commit 1d4cba8
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 60 deletions.
21 changes: 14 additions & 7 deletions applications/services/applications.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
#include <gui/icon.h>

typedef enum {
FlipperApplicationFlagDefault = 0,
FlipperApplicationFlagInsomniaSafe = (1 << 0),
} FlipperApplicationFlag;
FlipperInternalApplicationFlagDefault = 0,
FlipperInternalApplicationFlagInsomniaSafe = (1 << 0),

// Workaround for int and ext apps in same array:
// - use FlipperInternalApplication struct and array
// - set this flag to indicate it is external
FlipperInternalApplicationFlagExternal = (1 << 7),
} FlipperInternalApplicationFlag;

typedef struct {
const FuriThreadCallback app;
const char* name;
const char* appid;
union {
const char* appid; // When internal
const char* path; // When flag FlipperInternalApplicationFlagExternal is set
};
const size_t stack_size;
const Icon* icon;
const FlipperApplicationFlag flags;
const FlipperInternalApplicationFlag flags;
} FlipperInternalApplication;

typedef struct {
const char* name;
const Icon* icon;
const char* path;
const FlipperApplicationFlag flags;
} FlipperExternalApplication;

typedef void (*FlipperInternalOnStartHook)(void);
Expand Down Expand Up @@ -63,7 +70,7 @@ extern const FlipperInternalApplication FLIPPER_ARCHIVE;
/* Settings list
* Spawned by loader
*/
extern const FlipperExternalApplication FLIPPER_SETTINGS_APPS[];
extern const FlipperInternalApplication FLIPPER_SETTINGS_APPS[];
extern const size_t FLIPPER_SETTINGS_APPS_COUNT;

/* External Menu Apps list
Expand Down
21 changes: 13 additions & 8 deletions applications/services/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

// helpers

static const char*
loader_find_external_application_by_name(const char* app_name, FlipperApplicationFlag* flags) {
static const char* loader_find_external_application_by_name(
const char* app_name,
FlipperInternalApplicationFlag* flags) {
for(size_t i = 0; i < FLIPPER_EXTERNAL_APPS_COUNT; i++) {
if(strcmp(FLIPPER_EXTERNAL_APPS[i].name, app_name) == 0) {
if(flags) *flags = FLIPPER_EXTERNAL_APPS[i].flags;
if(flags) *flags = FlipperInternalApplicationFlagDefault;
return FLIPPER_EXTERNAL_APPS[i].path;
}
}

for(size_t i = 0; i < FLIPPER_SETTINGS_APPS_COUNT; i++) {
FlipperInternalApplicationFlag app_flags = FLIPPER_SETTINGS_APPS[i].flags;
if(!(app_flags & FlipperInternalApplicationFlagExternal)) continue;
if(strcmp(FLIPPER_SETTINGS_APPS[i].name, app_name) == 0) {
if(flags) *flags = FLIPPER_SETTINGS_APPS[i].flags;
if(flags) *flags = app_flags & ~FlipperInternalApplicationFlagExternal;
return FLIPPER_SETTINGS_APPS[i].path;
}
}
Expand Down Expand Up @@ -358,6 +361,7 @@ static FlipperInternalApplication const* loader_find_application_by_name_in_list
const FlipperInternalApplication* list,
const uint32_t n_apps) {
for(size_t i = 0; i < n_apps; i++) {
if(list[i].flags & FlipperInternalApplicationFlagExternal) continue;
if((strcmp(name, list[i].name) == 0) || (strcmp(name, list[i].appid) == 0)) {
return &list[i];
}
Expand All @@ -371,6 +375,7 @@ static const FlipperInternalApplication* loader_find_application_by_name(const c
const uint32_t count;
} lists[] = {
{FLIPPER_APPS, FLIPPER_APPS_COUNT},
{FLIPPER_SETTINGS_APPS, FLIPPER_SETTINGS_APPS_COUNT},
{FLIPPER_SYSTEM_APPS, FLIPPER_SYSTEM_APPS_COUNT},
{FLIPPER_DEBUG_APPS, FLIPPER_DEBUG_APPS_COUNT},
};
Expand All @@ -386,7 +391,7 @@ static const FlipperInternalApplication* loader_find_application_by_name(const c
return NULL;
}

static void loader_start_app_thread(Loader* loader, FlipperApplicationFlag flags) {
static void loader_start_app_thread(Loader* loader, FlipperInternalApplicationFlag flags) {
// setup heap trace
FuriHalRtcHeapTrackMode mode = furi_hal_rtc_get_heap_track_mode();
if(mode > FuriHalRtcHeapTrackModeNone) {
Expand All @@ -396,7 +401,7 @@ static void loader_start_app_thread(Loader* loader, FlipperApplicationFlag flags
}

// setup insomnia
if(!(flags & FlipperApplicationFlagInsomniaSafe)) {
if(!(flags & FlipperInternalApplicationFlagInsomniaSafe)) {
furi_hal_power_insomnia_enter();
loader->app.insomniac = true;
} else {
Expand Down Expand Up @@ -502,7 +507,7 @@ static LoaderMessageLoaderStatusResult loader_start_external_app(
const char* path,
const char* args,
FuriString* error_message,
FlipperApplicationFlag flags) {
FlipperInternalApplicationFlag flags) {
LoaderMessageLoaderStatusResult result;
result.value = loader_make_success_status(error_message);
result.error = LoaderStatusErrorUnknown;
Expand Down Expand Up @@ -700,7 +705,7 @@ static LoaderMessageLoaderStatusResult loader_do_start_by_name(
}

// check External Applications
FlipperApplicationFlag flags = FlipperApplicationFlagDefault;
FlipperInternalApplicationFlag flags = FlipperInternalApplicationFlagDefault;
{
const char* path = loader_find_external_application_by_name(name, &flags);
if(path) {
Expand Down
2 changes: 1 addition & 1 deletion applications/settings/about/application.fam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="about",
name="About",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="about_settings_app",
cdefines=["APP_ABOUT"],
requires=[
Expand Down
2 changes: 1 addition & 1 deletion applications/settings/bt_settings_app/application.fam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="bt_settings",
name="Bluetooth",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="bt_settings_app",
stack_size=1 * 1024,
requires=[
Expand Down
2 changes: 1 addition & 1 deletion applications/settings/desktop_settings/application.fam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="desktop_settings",
name="Desktop",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="desktop_settings_app",
requires=[
"desktop",
Expand Down
2 changes: 1 addition & 1 deletion applications/settings/dolphin_passport/application.fam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="passport",
name="Passport",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="passport_app",
cdefines=["APP_PASSPORT"],
requires=[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="expansion_settings",
name="Expansion Modules",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="expansion_settings_app",
requires=["gui"],
flags=["InsomniaSafe"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="notification_settings",
name="LCD and Notifications",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="notification_settings_app",
requires=["notification"],
flags=["InsomniaSafe"],
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion applications/settings/system/application.fam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
App(
appid="system_settings",
name="System",
apptype=FlipperAppType.SETTINGS,
apptype=FlipperAppType.SETTINGSEXTERNAL,
entry_point="system_settings_app",
requires=["gui", "locale"],
flags=["InsomniaSafe"],
Expand Down
4 changes: 3 additions & 1 deletion scripts/fbt/appmanifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FlipperAppType(Enum):
STARTUP = "StartupHook"
EXTERNAL = "External"
MENUEXTERNAL = "MenuExternal"
SETTINGSEXTERNAL = "SettingsExternal"
METAPACKAGE = "Package"
PLUGIN = "Plugin"

Expand Down Expand Up @@ -250,6 +251,7 @@ class AppBuildset:
FlipperAppType.APP,
FlipperAppType.DEBUG,
FlipperAppType.ARCHIVE,
FlipperAppType.SETTINGS,
FlipperAppType.STARTUP,
)
EXTERNAL_APP_TYPES_MAP = {
Expand All @@ -258,7 +260,7 @@ class AppBuildset:
FlipperAppType.PLUGIN: True,
FlipperAppType.DEBUG: True,
FlipperAppType.MENUEXTERNAL: False,
FlipperAppType.SETTINGS: False,
FlipperAppType.SETTINGSEXTERNAL: False,
}

@classmethod
Expand Down
61 changes: 34 additions & 27 deletions scripts/fbt_tools/fbt_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ class ApplicationsCGenerator:
FlipperAppType.SYSTEM: ("FlipperInternalApplication", "FLIPPER_SYSTEM_APPS"),
FlipperAppType.APP: ("FlipperInternalApplication", "FLIPPER_APPS"),
FlipperAppType.DEBUG: ("FlipperInternalApplication", "FLIPPER_DEBUG_APPS"),
FlipperAppType.SETTINGS: (
"FlipperInternalApplication",
"FLIPPER_SETTINGS_APPS",
),
FlipperAppType.STARTUP: (
"FlipperInternalOnStartHook",
"FLIPPER_ON_SYSTEM_START",
),
}

EXTERNAL_TYPE_MAP = {
FlipperAppType.MENUEXTERNAL: (
"FlipperExternalApplication",
"FLIPPER_EXTERNAL_APPS",
),
FlipperAppType.SETTINGS: (
"FlipperExternalApplication",
"FLIPPER_SETTINGS_APPS",
),
}
APP_EXTERNAL_TYPE = (
"FlipperExternalApplication",
"FLIPPER_EXTERNAL_APPS",
)

def __init__(self, buildset: AppBuildset, autorun_app: str = ""):
self.buildset = buildset
Expand All @@ -52,13 +50,26 @@ def get_app_ep_forward(self, app: FlipperApplication):
def get_app_descr(self, app: FlipperApplication):
if app.apptype == FlipperAppType.STARTUP:
return app.entry_point
if app.apptype == FlipperAppType.SETTINGSEXTERNAL:
app_path = "/ext/apps"
if app.fap_category:
app_path += f"/{app.fap_category}"
app_path += f"/{app.appid}.fap"
flags = app.flags + ["External"]
return f"""
{{.app = NULL,
.name = "{app.name}",
.path = "{app_path}",
.stack_size = 0,
.icon = {f"&{app.icon}" if app.icon else "NULL"},
.flags = {'|'.join(f"FlipperInternalApplicationFlag{flag}" for flag in flags)} }}"""
return f"""
{{.app = {app.entry_point},
.name = "{app.name}",
.appid = "{app.appid}",
.stack_size = {app.stack_size},
.icon = {f"&{app.icon}" if app.icon else "NULL"},
.flags = {'|'.join(f"FlipperApplicationFlag{flag}" for flag in app.flags)} }}"""
.flags = {'|'.join(f"FlipperInternalApplicationFlag{flag}" for flag in app.flags)} }}"""

def get_external_app_descr(self, app: FlipperApplication):
app_path = "/ext/apps"
Expand All @@ -69,8 +80,7 @@ def get_external_app_descr(self, app: FlipperApplication):
{{
.name = "{app.name}",
.icon = {f"&{app.icon}" if app.icon else "NULL"},
.path = "{app_path}",
.flags = {'|'.join(f"FlipperApplicationFlag{flag}" for flag in app.flags)} }}"""
.path = "{app_path}" }}"""

def generate(self):
contents = [
Expand All @@ -84,11 +94,11 @@ def generate(self):
)
entry_type, entry_block = self.APP_TYPE_MAP[apptype]
contents.append(f"const {entry_type} {entry_block}[] = {{")
contents.append(
",\n".join(
map(self.get_app_descr, self.buildset.get_apps_of_type(apptype))
)
)
apps = self.buildset.get_apps_of_type(apptype)
if apptype is FlipperAppType.SETTINGS:
apps += self.buildset.get_apps_of_type(FlipperAppType.SETTINGSEXTERNAL)
apps.sort(key=lambda app: app.order)
contents.append(",\n".join(map(self.get_app_descr, apps)))
contents.append("};")
contents.append(
f"const size_t {entry_block}_COUNT = COUNT_OF({entry_block});"
Expand All @@ -103,15 +113,12 @@ def generate(self):
]
)

for apptype in self.EXTERNAL_TYPE_MAP:
entry_type, entry_block = self.EXTERNAL_TYPE_MAP[apptype]
external_apps = self.buildset.get_apps_of_type(apptype)
contents.append(f"const {entry_type} {entry_block}[] = {{")
contents.append(",\n".join(map(self.get_external_app_descr, external_apps)))
contents.append("};")
contents.append(
f"const size_t {entry_block}_COUNT = COUNT_OF({entry_block});"
)
entry_type, entry_block = self.APP_EXTERNAL_TYPE
external_apps = self.buildset.get_apps_of_type(FlipperAppType.MENUEXTERNAL)
contents.append(f"const {entry_type} {entry_block}[] = {{")
contents.append(",\n".join(map(self.get_external_app_descr, external_apps)))
contents.append("};")
contents.append(f"const size_t {entry_block}_COUNT = COUNT_OF({entry_block});")

return "\n".join(contents)

Expand Down
2 changes: 1 addition & 1 deletion scripts/fbt_tools/fbt_extapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def _add_host_app_to_targets(host_app):
if host_app.apptype in [
FlipperAppType.EXTERNAL,
FlipperAppType.MENUEXTERNAL,
FlipperAppType.SETTINGS,
FlipperAppType.SETTINGSEXTERNAL,
]:
components.add_app(host_app)
else:
Expand Down
2 changes: 1 addition & 1 deletion scripts/ufbt/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ apps_to_build_as_faps = [
FlipperAppType.PLUGIN,
FlipperAppType.EXTERNAL,
FlipperAppType.MENUEXTERNAL,
FlipperAppType.SETTINGS,
FlipperAppType.SETTINGSEXTERNAL,
]

known_extapps = [
Expand Down
2 changes: 1 addition & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3852,7 +3852,7 @@ Variable,-,FLIPPER_ON_SYSTEM_START,const FlipperInternalOnStartHook[],
Variable,-,FLIPPER_ON_SYSTEM_START_COUNT,const size_t,
Variable,-,FLIPPER_SERVICES,const FlipperInternalApplication[],
Variable,-,FLIPPER_SERVICES_COUNT,const size_t,
Variable,+,FLIPPER_SETTINGS_APPS,const FlipperExternalApplication[],
Variable,+,FLIPPER_SETTINGS_APPS,const FlipperInternalApplication[],
Variable,+,FLIPPER_SETTINGS_APPS_COUNT,const size_t,
Variable,-,FLIPPER_SYSTEM_APPS,const FlipperInternalApplication[],
Variable,-,FLIPPER_SYSTEM_APPS_COUNT,const size_t,
Expand Down

0 comments on commit 1d4cba8

Please sign in to comment.