diff options
169 files changed, 1010 insertions, 4536 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 15499106..8bdd773c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -19,10 +19,6 @@ firmware/targets/f4/api-hal/api-hal-boot.c @skotopes debug/** @skotopes -# local target - -firmware/targets/local/** @glitchcore - # BLE firmware/targets/f4/ble-glue/** @skotopes diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebbe3f98..655f8310 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,16 +32,6 @@ jobs: with: run: /syntax_check.sh - - name: Build local testing firmware in docker - uses: ./.github/actions/docker - with: - run: make -C firmware TARGET=local - - - name: Run local tests - uses: ./.github/actions/docker - with: - run: make -C firmware TARGET=local APP_TEST=1 run - - name: Build F4 bootloader in docker uses: ./.github/actions/docker with: @@ -25,14 +25,7 @@ Flipper Zero's firmware consists of two components: Bootloader and main firmware ## Build from source -You can run firmware locally (with HAL stub): - -* `docker-compose exec dev make -C firmware TARGET=local APP_TEST=1 run` for running tests -* `docker-compose exec dev make -C firmware TARGET=local APP_*=1 run` for running examples (see `applications/applications.mk` for list of applications/examples) - -Or on your flipper: - -`docker-compose exec dev make -C firmware TARGET=f4 APP_*=1 flash` for build and flash dev board (see `applications/applications.mk` for list of applications/examples) +`docker-compose exec dev make -C firmware TARGET=f4 APP_RELEASE=1 flash` for build and flash dev board (see `applications/applications.mk` for list of applications/examples) # Links * Task tracker: [Jira](https://flipperzero.atlassian.net/) diff --git a/applications/app-loader/app-loader.c b/applications/app-loader/app-loader.c index d86d2fb6..6100a162 100644 --- a/applications/app-loader/app-loader.c +++ b/applications/app-loader/app-loader.c @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> #include <cli/cli.h> #include <gui/gui.h> #include "menu/menu.h" @@ -8,14 +8,15 @@ #include <api-hal.h> typedef struct { - FuriApp* handler; + osThreadAttr_t app_thread_attr; + osThreadId_t app_thread_id; Widget* widget; - const FlipperStartupApp* current_app; + const FuriApplication* current_app; } AppLoaderState; typedef struct { AppLoaderState* state; - const FlipperStartupApp* app; + const FuriApplication* app; } AppLoaderContext; // TODO add mutex for contex @@ -36,7 +37,7 @@ static void input_callback(InputEvent* input_event, void* _ctx) { AppLoaderState* ctx = (AppLoaderState*)_ctx; if(input_event->state && input_event->input == InputBack) { - furiac_kill(ctx->handler); + osThreadTerminate(ctx->app_thread_id); widget_enabled_set(ctx->widget, false); api_hal_timebase_insomnia_exit(); } @@ -54,7 +55,16 @@ static void handle_menu(void* _ctx) { api_hal_timebase_insomnia_enter(); ctx->state->current_app = ctx->app; - ctx->state->handler = furiac_start(ctx->app->app, ctx->app->name, NULL); + ctx->state->app_thread_attr.name = ctx->app->name; + ctx->state->app_thread_attr.attr_bits = osThreadDetached; + ctx->state->app_thread_attr.cb_mem = NULL; + ctx->state->app_thread_attr.cb_size = 0; + ctx->state->app_thread_attr.stack_mem = NULL; + ctx->state->app_thread_attr.stack_size = 1024; + ctx->state->app_thread_attr.priority = osPriorityNormal; + ctx->state->app_thread_attr.tz_module = 0; + ctx->state->app_thread_attr.reserved = 0; + ctx->state->app_thread_id = osThreadNew(ctx->app->app, NULL, &ctx->state->app_thread_attr); } static void handle_cli(string_t args, void* _ctx) { @@ -65,13 +75,22 @@ static void handle_cli(string_t args, void* _ctx) { cli_print("Starting furi application\r\n"); ctx->state->current_app = ctx->app; - ctx->state->handler = furiac_start(ctx->app->app, ctx->app->name, NULL); + ctx->state->app_thread_attr.name = ctx->app->name; + ctx->state->app_thread_attr.attr_bits = osThreadDetached; + ctx->state->app_thread_attr.cb_mem = NULL; + ctx->state->app_thread_attr.cb_size = 0; + ctx->state->app_thread_attr.stack_mem = NULL; + ctx->state->app_thread_attr.stack_size = 1024; + ctx->state->app_thread_attr.priority = osPriorityNormal; + ctx->state->app_thread_attr.tz_module = 0; + ctx->state->app_thread_attr.reserved = 0; + ctx->state->app_thread_id = osThreadNew(ctx->app->app, NULL, &ctx->state->app_thread_attr); cli_print("Press any key to kill application"); char c; cli_read(&c, 1); - furiac_kill(ctx->state->handler); + osThreadTerminate(ctx->state->app_thread_id); } void app_loader(void* p) { @@ -79,37 +98,23 @@ void app_loader(void* p) { furi_check(self_id); AppLoaderState state; - state.handler = NULL; + state.app_thread_id = NULL; state.widget = widget_alloc(); widget_enabled_set(state.widget, false); widget_draw_callback_set(state.widget, render_callback, &state); widget_input_callback_set(state.widget, input_callback, &state); - ValueMutex* menu_mutex = furi_open("menu"); - if(menu_mutex == NULL) { - printf("menu is not available\n"); - furiac_exit(NULL); - } - - Cli* cli = furi_open("cli"); + ValueMutex* menu_mutex = furi_record_open("menu"); + Cli* cli = furi_record_open("cli"); + Gui* gui = furi_record_open("gui"); - // Open GUI and register widget - Gui* gui = furi_open("gui"); - if(gui == NULL) { - printf("gui is not available\n"); - furiac_exit(NULL); - } gui_add_widget(gui, state.widget, GuiLayerFullscreen); - // FURI startup - const size_t flipper_app_count = sizeof(FLIPPER_APPS) / sizeof(FLIPPER_APPS[0]); - const size_t flipper_plugins_count = sizeof(FLIPPER_PLUGINS) / sizeof(FLIPPER_PLUGINS[0]); - // Main menu with_value_mutex( menu_mutex, (Menu * menu) { - for(size_t i = 0; i < flipper_app_count; i++) { + for(size_t i = 0; i < FLIPPER_APPS_size(); i++) { AppLoaderContext* ctx = furi_alloc(sizeof(AppLoaderContext)); ctx->state = &state; ctx->app = &FLIPPER_APPS[i]; @@ -123,13 +128,11 @@ void app_loader(void* p) { ctx)); // Add cli command - if(cli) { - string_t cli_name; - string_init_set_str(cli_name, "app_"); - string_cat_str(cli_name, FLIPPER_APPS[i].name); - cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx); - string_clear(cli_name); - } + string_t cli_name; + string_init_set_str(cli_name, "app_"); + string_cat_str(cli_name, FLIPPER_APPS[i].name); + cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx); + string_clear(cli_name); } }); @@ -157,7 +160,7 @@ void app_loader(void* p) { MenuItem* menu_plugins = menu_item_alloc_menu("Plugins", assets_icons_get(A_Plugins_14)); - for(size_t i = 0; i < flipper_plugins_count; i++) { + for(size_t i = 0; i < FLIPPER_PLUGINS_size(); i++) { AppLoaderContext* ctx = furi_alloc(sizeof(AppLoaderContext)); ctx->state = &state; ctx->app = &FLIPPER_PLUGINS[i]; @@ -171,13 +174,11 @@ void app_loader(void* p) { ctx)); // Add cli command - if(cli) { - string_t cli_name; - string_init_set_str(cli_name, "app_"); - string_cat_str(cli_name, FLIPPER_PLUGINS[i].name); - cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx); - string_clear(cli_name); - } + string_t cli_name; + string_init_set_str(cli_name, "app_"); + string_cat_str(cli_name, FLIPPER_PLUGINS[i].name); + cli_add_command(cli, string_get_cstr(cli_name), handle_cli, ctx); + string_clear(cli_name); } menu_item_add(menu, menu_plugins); @@ -186,4 +187,4 @@ void app_loader(void* p) { printf("[app loader] start\n"); osThreadSuspend(self_id); -}
\ No newline at end of file +} diff --git a/applications/applications.c b/applications/applications.c new file mode 100644 index 00000000..fa552e09 --- /dev/null +++ b/applications/applications.c @@ -0,0 +1,220 @@ +#include "applications.h" + +#ifdef APP_TEST +void flipper_test_app(void* p); +#endif + +void application_blink(void* p); +void application_uart_write(void* p); +void application_ipc_display(void* p); +void application_ipc_widget(void* p); +void application_input_dump(void* p); +void display_u8g2(void* p); +void u8g2_example(void* p); +void input_task(void* p); +void menu_task(void* p); +void coreglitch_demo_0(void* p); +void u8g2_qrcode(void* p); +void fatfs_list(void* p); +void gui_task(void* p); +void backlight_control(void* p); +void irda(void* p); +void app_loader(void* p); +void cc1101_workaround(void* p); +void lf_rfid_workaround(void* p); +void nfc_task(void* p); +void dolphin_task(void* p); +void power_task(void* p); +void bt_task(void* p); +void sd_card_test(void* p); +void application_vibro(void* p); +void app_gpio_test(void* p); +void app_ibutton(void* p); +void cli_task(void* p); +void music_player(void* p); +void sdnfc(void* p); +void floopper_bloopper(void* p); +void sd_filesystem(void* p); + +const FuriApplication FLIPPER_SERVICES[] = { +#ifdef APP_DISPLAY + {.app = display_u8g2, .name = "display_u8g2", .icon = A_Plugins_14}, +#endif + +#ifdef APP_CLI + {.app = cli_task, .name = "cli_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_EXAMPLE_BLINK + {.app = application_blink, .name = "blink", .icon = A_Plugins_14}, +#endif + +#ifdef APP_INPUT + {.app = input_task, .name = "input_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_EXAMPLE_INPUT_DUMP + {.app = application_input_dump, .name = "input dump", .icon = A_Plugins_14}, +#endif + +#ifdef APP_GUI + {.app = backlight_control, .name = "backlight_control", .icon = A_Plugins_14}, + {.app = gui_task, .name = "gui_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_MENU + {.app = menu_task, .name = "menu_task", .icon = A_Plugins_14}, + {.app = app_loader, .name = "app_loader", .icon = A_Plugins_14}, +#endif + +#ifdef APP_SD_FILESYSTEM + {.app = sd_filesystem, .name = "sd_filesystem", .icon = A_Plugins_14}, +#endif + +#ifdef APP_DOLPHIN + {.app = dolphin_task, .name = "dolphin_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_POWER + {.app = power_task, .name = "power_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_BT + {.app = bt_task, .name = "bt_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_CC1101 + {.app = cc1101_workaround, .name = "cc1101 workaround", .icon = A_Plugins_14}, +#endif + +#ifdef APP_LF_RFID + {.app = lf_rfid_workaround, .name = "lf rfid workaround", .icon = A_Plugins_14}, +#endif + +#ifdef APP_IRDA + {.app = irda, .name = "irda", .icon = A_Plugins_14}, +#endif + +#ifdef APP_NFC + {.app = nfc_task, .name = "nfc_task", .icon = A_Plugins_14}, +#endif + +#ifdef APP_TEST + {.app = flipper_test_app, .name = "test app", .icon = A_Plugins_14}, +#endif + +#ifdef APP_EXAMPLE_IPC + {.app = application_ipc_display, .name = "ipc display", .icon = A_Plugins_14}, + {.app = application_ipc_widget, .name = "ipc widget", .icon = A_Plugins_14}, +#endif + +#ifdef APP_EXAMPLE_QRCODE + {.app = u8g2_qrcode, .name = "u8g2_qrcode", .icon = A_Plugins_14}, +#endif + +#ifdef APP_EXAMPLE_FATFS + {.app = fatfs_list, .name = "fatfs_list", .icon = A_Plugins_14}, +#endif + +#ifdef APP_EXAMPLE_DISPLAY + {.app = u8g2_example, .name = "u8g2_example", .icon = A_Plugins_14}, +#endif + +#ifdef APP_SPEAKER_DEMO + {.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .icon = A_Plugins_14}, +#endif + +#ifdef APP_SD_TEST + {.app = sd_card_test, .name = "sd_card_test", .icon = A_Plugins_14}, +#endif + +#ifdef APP_MUSIC_PLAYER + {.app = music_player, .name = "music player", .icon = A_Plugins_14}, +#endif + +#ifdef APP_IBUTTON + {.app = app_ibutton, .name = "ibutton", .icon = A_Plugins_14}, +#endif + +#ifdef APP_GPIO_DEMO + {.app = app_gpio_test, .name = "gpio test", .icon = A_Plugins_14}, +#endif + +#ifdef APP_FLOOPPER_BLOOPPER + {.app = floopper_bloopper, .name = "Floopper Bloopper", .icon = A_Games_14}, +#endif + +#ifdef APP_SDNFC + {.app = sdnfc, .name = "sdnfc", .icon = A_Plugins_14}, +#endif +}; + +size_t FLIPPER_SERVICES_size() { + return sizeof(FLIPPER_SERVICES) / sizeof(FuriApplication); +} + +// Main menu APP +const FuriApplication FLIPPER_APPS[] = { +#ifdef BUILD_CC1101 + {.app = cc1101_workaround, .name = "Sub-1 GHz", .icon = A_Sub1ghz_14}, +#endif + +#ifdef BUILD_LF_RFID + {.app = lf_rfid_workaround, .name = "125 kHz RFID", .icon = A_125khz_14}, +#endif + +#ifdef BUILD_IRDA + {.app = irda, .name = "Infrared", .icon = A_Infrared_14}, +#endif + +#ifdef BUILD_IBUTTON + {.app = app_ibutton, .name = "iButton", .icon = A_iButton_14}, +#endif + +#ifdef BUILD_GPIO_DEMO + {.app = app_gpio_test, .name = "GPIO", .icon = A_GPIO_14}, +#endif +}; + +size_t FLIPPER_APPS_size() { + return sizeof(FLIPPER_APPS) / sizeof(FuriApplication); +} + +// Plugin menu +const FuriApplication FLIPPER_PLUGINS[] = { +#ifdef BUILD_EXAMPLE_BLINK + {.app = application_blink, .name = "blink", .icon = A_Plugins_14}, +#endif + +#ifdef BUILD_EXAMPLE_INPUT_DUMP + {.app = application_input_dump, .name = "input dump", .icon = A_Plugins_14}, +#endif + +#ifdef BUILD_SPEAKER_DEMO + {.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .icon = A_Plugins_14}, +#endif + +#ifdef BUILD_SD_TEST + {.app = sd_card_test, .name = "sd_card_test", .icon = A_Plugins_14}, +#endif + +#ifdef BUILD_VIBRO_DEMO + {.app = application_vibro, .name = "application_vibro", .icon = A_Plugins_14}, +#endif + +#ifdef BUILD_MUSIC_PLAYER + {.app = music_player, .name = "music player", .icon = A_Plugins_14}, +#endif + +#ifdef BUILD_FLOOPPER_BLOOPPER + {.app = floopper_bloopper, .name = "Floopper Bloopper", .icon = A_Games_14}, +#endif + +#ifdef BUILD_SDNFC + {.app = sdnfc, .name = "sdnfc", .icon = A_Plugins_14}, +#endif +}; + +size_t FLIPPER_PLUGINS_size() { + return sizeof(FLIPPER_PLUGINS) / sizeof(FuriApplication); +} diff --git a/applications/applications.h b/applications/applications.h index 1b80891f..44c25acd 100644 --- a/applications/applications.h +++ b/applications/applications.h @@ -1,296 +1,21 @@ #pragma once -#include "flipper.h" +#include <furi.h> +#include <assets_icons.h> -#ifdef APP_TEST -void flipper_test_app(void* p); -#endif +typedef void (*FlipperApplication)(void*); -void application_blink(void* p); -void application_uart_write(void* p); -void application_ipc_display(void* p); -void application_ipc_widget(void* p); -void application_input_dump(void* p); +typedef struct { + const FlipperApplication app; + const char* name; + const IconName icon; +} FuriApplication; -void display_u8g2(void* p); +extern const FuriApplication FLIPPER_SERVICES[]; +size_t FLIPPER_SERVICES_size(); -void u8g2_example(void* p); +extern const FuriApplication FLIPPER_APPS[]; +size_t FLIPPER_APPS_size(); -void input_task(void* p); -void menu_task(void* p); - -void coreglitch_demo_0(void* p); - -void u8g2_qrcode(void* p); -void fatfs_list(void* p); -void gui_task(void* p); -void backlight_control(void* p); -void irda(void* p); -void app_loader(void* p); -void cc1101_workaround(void* p); -void lf_rfid_workaround(void* p); -void nfc_task(void* p); -void dolphin_task(void* p); -void power_task(void* p); -void bt_task(void* p); -void sd_card_test(void* p); -void application_vibro(void* p); -void app_gpio_test(void* p); -void app_ibutton(void* p); -void cli_task(void* p); -void music_player(void* p); -void sdnfc(void* p); -void floopper_bloopper(void* p); -void sd_filesystem(void* p); - -const FlipperStartupApp FLIPPER_STARTUP[] = { -#ifdef APP_DISPLAY - {.app = display_u8g2, .name = "display_u8g2", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_CLI - {.app = cli_task, .name = "cli_task", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_EXAMPLE_BLINK - {.app = application_blink, - .name = "blink", - .libs = {1, FURI_LIB{"input_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_INPUT - {.app = input_task, .name = "input_task", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_EXAMPLE_INPUT_DUMP - {.app = application_input_dump, - .name = "input dump", - .libs = {1, FURI_LIB{"input_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_GUI - {.app = backlight_control, - .name = "backlight_control", - .libs = {1, FURI_LIB{"input_task"}}, - .icon = A_Plugins_14}, - {.app = gui_task, .name = "gui_task", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_MENU - {.app = menu_task, - .name = "menu_task", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, - {.app = app_loader, - .name = "app_loader", - .libs = {2, FURI_LIB{"menu_task", "cli_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_SD_FILESYSTEM - {.app = sd_filesystem, - .name = "sd_filesystem", - .libs = {1, FURI_LIB{"menu_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_DOLPHIN - {.app = dolphin_task, - .name = "dolphin_task", - .libs = {1, FURI_LIB{"menu_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_POWER - {.app = power_task, - .name = "power_task", - .libs = {2, FURI_LIB{"cli_task", "gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_BT - {.app = bt_task, .name = "bt_task", .libs = {1, FURI_LIB{"cli_task"}}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_CC1101 - {.app = cc1101_workaround, - .name = "cc1101 workaround", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_LF_RFID - {.app = lf_rfid_workaround, - .name = "lf rfid workaround", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_IRDA - {.app = irda, .name = "irda", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_NFC - {.app = nfc_task, .name = "nfc_task", .libs = {1, FURI_LIB{"menu_task"}}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_TEST - {.app = flipper_test_app, .name = "test app", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_EXAMPLE_IPC - {.app = application_ipc_display, .name = "ipc display", .libs = {0}, .icon = A_Plugins_14}, - {.app = application_ipc_widget, .name = "ipc widget", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_EXAMPLE_QRCODE - {.app = u8g2_qrcode, - .name = "u8g2_qrcode", - .libs = {1, FURI_LIB{"display_u8g2"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_EXAMPLE_FATFS - {.app = fatfs_list, - .name = "fatfs_list", - .libs = {2, FURI_LIB{"display_u8g2", "input_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_EXAMPLE_DISPLAY - {.app = u8g2_example, - .name = "u8g2_example", - .libs = {1, FURI_LIB{"display_u8g2"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_SPEAKER_DEMO - {.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef APP_SD_TEST - {.app = sd_card_test, - .name = "sd_card_test", - .libs = {2, FURI_LIB{"gui_task", "sd_filesystem"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_MUSIC_PLAYER - {.app = music_player, - .name = "music player", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_IBUTTON - {.app = app_ibutton, - .name = "ibutton", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_GPIO_DEMO - {.app = app_gpio_test, - .name = "gpio test", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef APP_FLOOPPER_BLOOPPER - {.app = floopper_bloopper, - .name = "Floopper Bloopper", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Games_14}, -#endif - -#ifdef APP_SDNFC - {.app = sdnfc, .name = "sdnfc", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_Plugins_14}, -#endif -}; - -// Main menu APP -const FlipperStartupApp FLIPPER_APPS[] = { -#ifdef BUILD_CC1101 - {.app = cc1101_workaround, - .name = "Sub-1 GHz", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Sub1ghz_14}, -#endif - -#ifdef BUILD_LF_RFID - {.app = lf_rfid_workaround, - .name = "125 kHz RFID", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_125khz_14}, -#endif - -#ifdef BUILD_IRDA - {.app = irda, .name = "Infrared", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_Infrared_14}, -#endif - -#ifdef BUILD_IBUTTON - {.app = app_ibutton, - .name = "iButton", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_iButton_14}, -#endif - -#ifdef BUILD_GPIO_DEMO - {.app = app_gpio_test, .name = "GPIO", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_GPIO_14}, -#endif -}; - -// Plugin menu -const FlipperStartupApp FLIPPER_PLUGINS[] = { -#ifdef BUILD_EXAMPLE_BLINK - {.app = application_blink, - .name = "blink", - .libs = {1, FURI_LIB{"input_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef BUILD_EXAMPLE_INPUT_DUMP - {.app = application_input_dump, - .name = "input dump", - .libs = {1, FURI_LIB{"input_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef BUILD_SPEAKER_DEMO - {.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .libs = {0}, .icon = A_Plugins_14}, -#endif - -#ifdef BUILD_SD_TEST - {.app = sd_card_test, - .name = "sd_card_test", - .libs = {2, FURI_LIB{"gui_task", "sd_filesystem"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef BUILD_VIBRO_DEMO - {.app = application_vibro, - .name = "application_vibro", - .libs = {1, FURI_LIB{"input_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef BUILD_MUSIC_PLAYER - {.app = music_player, - .name = "music player", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Plugins_14}, -#endif - -#ifdef BUILD_FLOOPPER_BLOOPPER - {.app = floopper_bloopper, - .name = "Floopper Bloopper", - .libs = {1, FURI_LIB{"gui_task"}}, - .icon = A_Games_14}, -#endif - -#ifdef BUILD_SDNFC - {.app = sdnfc, .name = "sdnfc", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_Plugins_14}, -#endif -};
\ No newline at end of file +extern const FuriApplication FLIPPER_PLUGINS[]; +size_t FLIPPER_PLUGINS_size(); diff --git a/applications/applications.mk b/applications/applications.mk index e27f6146..d79926c0 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -2,6 +2,7 @@ APP_DIR = $(PROJECT_ROOT)/applications LIB_DIR = $(PROJECT_ROOT)/lib CFLAGS += -I$(APP_DIR) +C_SOURCES += $(APP_DIR)/applications.c # Use APP_* for autostart app # Use BUILD_* for add app to build diff --git a/applications/backlight-control/backlight-control.c b/applications/backlight-control/backlight-control.c index a640b5aa..ed412f91 100644 --- a/applications/backlight-control/backlight-control.c +++ b/applications/backlight-control/backlight-control.c @@ -1,11 +1,12 @@ -#include "flipper_v2.h" +#include <furi.h> + +#define BACKLIGHT_TIME 10000 +#define BACKLIGHT_FLAG_ACTIVITY 0x00000001U static void event_cb(const void* value, void* ctx) { - xSemaphoreGive((SemaphoreHandle_t*)ctx); + osThreadFlagsSet((osThreadId_t)ctx, BACKLIGHT_FLAG_ACTIVITY); } -const uint32_t BACKLIGHT_TIME = 10000; - void backlight_control(void* p) { // TODO open record const GpioPin* backlight_record = &backlight_gpio; @@ -14,20 +15,14 @@ void backlight_control(void* p) { gpio_init(backlight_record, GpioModeOutputPushPull); gpio_write(backlight_record, true); - StaticSemaphore_t event_descriptor; - SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor); - // open record - PubSub* event_record = furi_open("input_events"); - furi_check(event_record); - subscribe_pubsub(event_record, event_cb, (void*)update); - - // we ready to work - furiac_ready(); + PubSub* event_record = furi_record_open("input_events"); + subscribe_pubsub(event_record, event_cb, (void*)osThreadGetId()); while(1) { // wait for event - if(xSemaphoreTake(update, BACKLIGHT_TIME) == pdTRUE) { + if(osThreadFlagsWait(BACKLIGHT_FLAG_ACTIVITY, osFlagsWaitAny, BACKLIGHT_TIME) == + BACKLIGHT_FLAG_ACTIVITY) { gpio_write(backlight_record, true); } else { gpio_write(backlight_record, false); diff --git a/applications/bt/bt.c b/applications/bt/bt.c index d77293e2..bc2a4cb0 100644 --- a/applications/bt/bt.c +++ b/applications/bt/bt.c @@ -2,16 +2,23 @@ Bt* bt_alloc() { Bt* bt = furi_alloc(sizeof(Bt)); - bt->cli = furi_open("cli"); + + bt->cli = furi_record_open("cli"); + cli_add_command(bt->cli, "bt_info", bt_cli_info, bt); + bt->gui = furi_record_open("gui"); + bt->menu = furi_record_open("menu"); bt->statusbar_icon = assets_icons_get(I_Bluetooth_5x8); bt->statusbar_widget = widget_alloc(); widget_set_width(bt->statusbar_widget, icon_get_width(bt->statusbar_icon)); widget_draw_callback_set(bt->statusbar_widget, bt_draw_statusbar_callback, bt); widget_enabled_set(bt->statusbar_widget, false); + gui_add_widget(bt->gui, bt->statusbar_widget, GuiLayerStatusBarLeft); bt->menu_icon = assets_icons_get(A_Bluetooth_14); bt->menu_item = menu_item_alloc_menu("Bluetooth", bt->menu_icon); + with_value_mutex( + bt->menu, (Menu * menu) { menu_item_add(menu, bt->menu_item); }); return bt; } @@ -33,23 +40,7 @@ void bt_cli_info(string_t args, void* context) { void bt_task() { Bt* bt = bt_alloc(); - if(bt->cli) { - cli_add_command(bt->cli, "bt_info", bt_cli_info, bt); - } - - // TODO: add ValueMutex(bt) to "bt" record - if(!furi_create("bt", bt)) { - printf("[bt_task] unable to create bt record\n"); - furiac_exit(NULL); - } - - Gui* gui = furi_open("gui"); - gui_add_widget(gui, bt->statusbar_widget, GuiLayerStatusBarLeft); - - with_value_mutex( - furi_open("menu"), (Menu * menu) { menu_item_add(menu, bt->menu_item); }); - - furiac_ready(); + furi_record_create("bt", bt); api_hal_bt_init(); diff --git a/applications/bt/bt_i.h b/applications/bt/bt_i.h index a6eec8ff..01acfca8 100644 --- a/applications/bt/bt_i.h +++ b/applications/bt/bt_i.h @@ -2,10 +2,9 @@ #include "bt.h" -#include <cli/cli.h> +#include <furi.h> -#include <flipper.h> -#include <flipper_v2.h> +#include <cli/cli.h> #include <gui/gui.h> #include <gui/widget.h> @@ -15,6 +14,8 @@ typedef struct { Cli* cli; + Gui* gui; + ValueMutex* menu; // Status bar Icon* statusbar_icon; Widget* statusbar_widget; @@ -26,3 +27,7 @@ typedef struct { Bt* bt_alloc(); void bt_draw_statusbar_callback(Canvas* canvas, void* context); + +void bt_cli_info(string_t args, void* context); + +void bt_draw_statusbar_callback(Canvas* canvas, void* context); diff --git a/applications/cc1101-workaround/cc1101-workaround.cpp b/applications/cc1101-workaround/cc1101-workaround.cpp index 57405ed7..d6140c22 100644 --- a/applications/cc1101-workaround/cc1101-workaround.cpp +++ b/applications/cc1101-workaround/cc1101-workaround.cpp @@ -1,6 +1,7 @@ -#include "flipper.h" - -#include "cc1101-workaround/cc1101.h" +#include "cc1101.h" +#include <furi.h> +#include <gui/gui.h> +#include <input/input.h> extern "C" void cli_print(const char* str); @@ -335,7 +336,7 @@ static void render_callback(Canvas* canvas, void* ctx) { } static void input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = (QueueHandle_t)ctx; + osMessageQueueId_t event_queue = ctx; AppEvent event; event.type = EventTypeKey; @@ -370,7 +371,7 @@ extern "C" void cc1101_workaround(void* p) { widget_input_callback_set(widget, input_callback, event_queue); // Open GUI and register widget - Gui* gui = (Gui*)furi_open("gui"); + Gui* gui = (Gui*)furi_record_open("gui"); if(gui == NULL) { printf("[cc1101] gui is not available\n"); furiac_exit(NULL); diff --git a/applications/cc1101-workaround/cc1101.cpp b/applications/cc1101-workaround/cc1101.cpp index 620902d0..2ef2930e 100644 --- a/applications/cc1101-workaround/cc1101.cpp +++ b/applications/cc1101-workaround/cc1101.cpp @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> #include "cc1101-workaround/cc1101.h" #include "spi.h" #include <math.h> diff --git a/applications/cc1101-workaround/cc1101.h b/applications/cc1101-workaround/cc1101.h index aa36e279..236b899d 100644 --- a/applications/cc1101-workaround/cc1101.h +++ b/applications/cc1101-workaround/cc1101.h @@ -1,6 +1,6 @@ #pragma once -#include "flipper_v2.h" +#include <furi.h> #define F_OSC 26e6 diff --git a/applications/cli/cli.c b/applications/cli/cli.c index befebf08..3d587dfe 100644 --- a/applications/cli/cli.c +++ b/applications/cli/cli.c @@ -1,8 +1,6 @@ #include "cli_i.h" #include "cli_commands.h" -#include <api-hal-vcp.h> - Cli* cli_alloc() { Cli* cli = furi_alloc(sizeof(Cli)); CliCommandDict_init(cli->commands); @@ -175,12 +173,7 @@ void cli_task(void* p) { // Init basic cli commands cli_commands_init(cli); - if(!furi_create("cli", cli)) { - printf("[cli_task] cannot create the cli record\n"); - furiac_exit(NULL); - } - - furiac_ready(); + furi_record_create("cli", cli); while(1) { cli_process_input(cli); diff --git a/applications/cli/cli_i.h b/applications/cli/cli_i.h index e8a8363d..9873c398 100644 --- a/applications/cli/cli_i.h +++ b/applications/cli/cli_i.h @@ -2,8 +2,7 @@ #include "cli.h" -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> #include <m-dict.h> diff --git a/applications/coreglitch_demo_0/coreglitch_demo_0.c b/applications/coreglitch_demo_0/coreglitch_demo_0.c index 12e1ebd1..3e9debc1 100644 --- a/applications/coreglitch_demo_0/coreglitch_demo_0.c +++ b/applications/coreglitch_demo_0/coreglitch_demo_0.c @@ -1,12 +1,10 @@ -#include "flipper.h" +#include <furi.h> #include "u8g2/u8g2.h" extern TIM_HandleTypeDef SPEAKER_TIM; void coreglitch_demo_0(void* p) { - FuriRecordSubscriber* log = get_default_log(); - - fuprintf(log, "coreglitch demo!\n"); + printf("coreglitch demo!\n"); float notes[] = { 0.0, diff --git a/applications/display-u8g2/display-u8g2.c b/applications/display-u8g2/display-u8g2.c deleted file mode 100644 index c51cb1ca..00000000 --- a/applications/display-u8g2/display-u8g2.c +++ /dev/null @@ -1,195 +0,0 @@ -#include "u8g2/u8g2.h" -#include "flipper.h" -#include "main.h" - -extern SPI_HandleTypeDef SPI_D; - -// TODO: fix log -#ifdef DEBUG -#undef DEBUG -#endif - -// TODO rewrite u8g2 to pass thread-local context in this handlers - -static uint8_t -u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { - switch(msg) { - //Initialize SPI peripheral - case U8X8_MSG_GPIO_AND_DELAY_INIT: - /* HAL initialization contains all what we need so we can skip this part. */ - break; - - //Function which implements a delay, arg_int contains the amount of ms - case U8X8_MSG_DELAY_MILLI: - osDelay(arg_int); - break; - - //Function which delays 10us - case U8X8_MSG_DELAY_10MICRO: - delay_us(10); - break; - - //Function which delays 100ns - case U8X8_MSG_DELAY_100NANO: - asm("nop"); - break; - - // Function to define the logic level of the RESET line - case U8X8_MSG_GPIO_RESET: -#ifdef DEBUG - fuprintf(log, "[u8g2] rst %d\n", arg_int); -#endif - - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin( - DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET); - break; - - default: -#ifdef DEBUG - fufuprintf(log, "[u8g2] unknown io %d\n", msg); -#endif - - return 0; //A message was received which is not implemented, return 0 to indicate an error - } - - return 1; // command processed successfully. -} - -static uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) { - switch(msg) { - case U8X8_MSG_BYTE_SEND: -#ifdef DEBUG - fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]); -#endif - - // TODO change it to FuriRecord SPI - HAL_SPI_Transmit(&SPI_D, (uint8_t*)arg_ptr, arg_int, 10000); - break; - - case U8X8_MSG_BYTE_SET_DC: -#ifdef DEBUG - fuprintf(log, "[u8g2] dc %d\n", arg_int); -#endif - - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin( - DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET); - break; - - case U8X8_MSG_BYTE_INIT: -#ifdef DEBUG - fuprintf(log, "[u8g2] init\n"); -#endif - - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET); - break; - - case U8X8_MSG_BYTE_START_TRANSFER: -#ifdef DEBUG - fuprintf(log, "[u8g2] start\n"); -#endif - - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET); - asm("nop"); - break; - - case U8X8_MSG_BYTE_END_TRANSFER: -#ifdef DEBUG - fuprintf(log, "[u8g2] end\n"); -#endif - - asm("nop"); - // TODO change it to FuriRecord pin - HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET); - break; - - default: -#ifdef DEBUG - fuprintf(log, "[u8g2] unknown xfer %d\n", msg); -#endif - - return 0; - } - - return 1; -} - -typedef struct { - SemaphoreHandle_t update; // queue to pass events from callback to app thread - FuriRecordSubscriber* log; // app logger -} DisplayCtx; - -static void handle_fb_change(const void* fb, size_t fb_size, void* raw_ctx) { - DisplayCtx* ctx = (DisplayCtx*)raw_ctx; // make right type - - // fuprintf(ctx->log, "[display_u8g2] change fb\n"); - - // send update to app thread - xSemaphoreGive(ctx->update); -} - -void display_u8g2(void* p) { - FuriRecordSubscriber* log = get_default_log(); - - // TODO we need different app to contol backlight - HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET); - - u8g2_t _u8g2; - u8g2_Setup_st7565_erc12864_alt_f( - &_u8g2, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); - u8g2_InitDisplay( - &_u8g2); // send init sequence to the display, display is in sleep mode after this - u8g2_SetContrast(&_u8g2, 36); - - if(!furi_create_deprecated("u8g2_fb", (void*)&_u8g2, sizeof(_u8g2))) { - fuprintf(log, "[display_u8g2] cannot create fb record\n"); - furiac_exit(NULL); - } - - StaticSemaphore_t event_descriptor; - // create stack-based counting semaphore - SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor); - - if(update == NULL) { - fuprintf(log, "[display_u8g2] cannot create update semaphore\n"); - furiac_exit(NULL); - } - - // save log and event queue in context structure - DisplayCtx ctx = {.update = update, .log = log}; - - // subscribe to record. ctx will be passed to handle_fb_change - FuriRecordSubscriber* fb_record = - furi_open_deprecated("u8g2_fb", false, false, handle_fb_change, NULL, &ctx); - - if(fb_record == NULL) { - fuprintf(log, "[display] cannot open fb record\n"); - furiac_exit(NULL); - } - - u8g2_t* u8g2 = (u8g2_t*)furi_take(fb_record); - u8g2_SetPowerSave(u8g2, 0); // wake up display - u8g2_SendBuffer(u8g2); - furi_give(fb_record); - - // we ready to work - furiac_ready(); - - while(1) { - // wait for event - if(xSemaphoreTake(update, 10000) == pdTRUE) { - HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET); - - u8g2_t* u8g2 = (u8g2_t*)furi_take(fb_record); - u8g2_SetPowerSave(u8g2, 0); // wake up display - u8g2_SendBuffer(u8g2); - furi_give(fb_record); - } else { - // TODO we need different app to contol backlight - HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET); - } - } -}
\ No newline at end of file diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c index 619c5fc2..cae109c3 100644 --- a/applications/dolphin/dolphin.c +++ b/applications/dolphin/dolphin.c @@ -67,8 +67,7 @@ Dolphin* dolphin_alloc() { // State dolphin->state = dolphin_state_alloc(); // Menu - dolphin->menu_vm = furi_open("menu"); - furi_check(dolphin->menu_vm); + dolphin->menu_vm = furi_record_open("menu"); // GUI dolphin->idle_view_dispatcher = view_dispatcher_alloc(); // First start View @@ -125,7 +124,7 @@ void dolphin_deed(Dolphin* dolphin, DolphinDeed deed) { void dolphin_task() { Dolphin* dolphin = dolphin_alloc(); - Gui* gui = furi_open("gui"); + Gui* gui = furi_record_open("gui"); view_dispatcher_attach_to_gui(dolphin->idle_view_dispatcher, gui, ViewDispatcherTypeWindow); if(dolphin_state_load(dolphin->state)) { view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain); @@ -138,12 +137,7 @@ void dolphin_task() { model->butthurt = dolphin_state_get_butthurt(dolphin->state); }); - if(!furi_create("dolphin", dolphin)) { - printf("[dolphin_task] cannot create the dolphin record\n"); - furiac_exit(NULL); - } - - furiac_ready(); + furi_record_create("dolphin", dolphin); DolphinEvent event; while(1) { diff --git a/applications/dolphin/dolphin_i.h b/applications/dolphin/dolphin_i.h index 79a2b2fa..3d67f98c 100644 --- a/applications/dolphin/dolphin_i.h +++ b/applications/dolphin/dolphin_i.h @@ -4,7 +4,7 @@ #include "dolphin_state.h" #include "dolphin_views.h" -#include <flipper_v2.h> +#include <furi.h> #include <gui/gui.h> #include <gui/view_dispatcher.h> diff --git a/applications/dolphin/dolphin_state.c b/applications/dolphin/dolphin_state.c index afe007bb..77344c65 100644 --- a/applications/dolphin/dolphin_state.c +++ b/applications/dolphin/dolphin_state.c @@ -1,6 +1,5 @@ #include "dolphin_state.h" -#include <api-hal-flash.h> -#include <flipper_v2.h> +#include <furi.h> typedef struct { uint8_t magic; diff --git a/applications/dolphin/dolphin_views.h b/applications/dolphin/dolphin_views.h index 8c353e5d..212b57b1 100644 --- a/applications/dolphin/dolphin_views.h +++ b/applications/dolphin/dolphin_views.h @@ -3,7 +3,8 @@ #include <stdint.h> #include <stdbool.h> #include <gui/canvas.h> -#include <flipper_v2.h> +#include <input/input.h> +#include <furi.h> // Idle scree typedef enum { diff --git a/applications/examples/blink.c b/applications/examples/blink.c index cf5718ce..1362f7d3 100644 --- a/applications/examples/blink.c +++ b/applications/examples/blink.c @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> void rgb_set( bool r, diff --git a/applications/examples/fatfs_list.c b/applications/examples/fatfs_list.c deleted file mode 100644 index 60361f51..00000000 --- a/applications/examples/fatfs_list.c +++ /dev/null @@ -1,155 +0,0 @@ -#include "u8g2/u8g2.h" -#include "fatfs/ff.h" -#include "flipper_v2.h" -#include <stdio.h> - -extern uint8_t BSP_SD_Init(); - -// TODO currently we have small stack, so it will be static -FuriRecordSubscriber* furi_log; -#define STR_BUFFER_SIZE 128 -char str_buffer[STR_BUFFER_SIZE]; -uint8_t line_current = 0; -uint16_t line_position = 0; - -// TODO this should be in the target driver -FATFS SD_FatFs; -char SD_Path[4]; - -typedef enum { - EventTypeStart, - EventTypeKey, -} AppEventType; - -typedef struct { - union { - InputEvent input; - } value; - AppEventType type; -} AppEvent; - -static void event_cb(const void* value, void* ctx) { - QueueHandle_t event_queue = (QueueHandle_t)ctx; - - AppEvent event; - event.type = EventTypeKey; - event.value.input = *(InputEvent*)value; - xQueueSend(event_queue, (void*)&event, 0); -} - -void fatfs_list(void* p) { - const uint8_t line_size = 10; - const uint8_t lines_on_display = 6; - - uint8_t bsp_result; - FRESULT result; - DIR dir; - FILINFO fno; - AppEvent event; - - QueueHandle_t event_queue = xQueueCreate(2, sizeof(AppEvent)); - - furi_log = get_default_log(); - fuprintf(furi_log, "[fatfs_list] app start\n"); - fuprintf(furi_log, "[fatfs_list] wait for sd insert\n"); - - while(!hal_gpio_read_sd_detect()) { - delay(100); - } - - fuprintf(furi_log, "[fatfs_list] sd inserted\n"); - - FuriRecordSubscriber* fb_record = - furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL); - if(fb_record == NULL) { - fuprintf(furi_log, "[fatfs_list] cannot create fb record\n"); - furiac_exit(NULL); - } - - PubSub* event_record = furi_open("input_events"); - if(event_record == NULL) { - fuprintf(furi_log, "[fatfs_list] cannot open input_events record\n"); - furiac_exit(NULL); - } - PubSubItem* subscription = subscribe_pubsub(event_record, event_cb, event_queue); - if(subscription == NULL) { - fuprintf(furi_log, "[fatfs_list] cannot register input_events callback\n"); - furiac_exit(NULL); - } - - bsp_result = BSP_SD_Init(); - - if(bsp_result != 0) { - fuprintf(furi_log, "[fatfs_list] SD card init error\n"); - furiac_exit(NULL); - } - - result = f_mount(&SD_FatFs, (TCHAR const*)SD_Path, 1); - - if(result != FR_OK) { - fuprintf(furi_log, "[fatfs_list] SD card mount error\n"); - furiac_exit(NULL); - } - - // ok, now we can work with sd card - - // send start event - event.type = EventTypeStart; - xQueueSend(event_queue, (void*)&event, 0); - - while(1) { - if(xQueueReceive(event_queue, (void*)&event, portMAX_DELAY)) { - // process buttons event - if(event.type == EventTypeKey) { - // button pressed - if(event.value.input.state == true) { - if(event.value.input.input == InputUp && line_position > 0) { - line_position--; - } - if(event.value.input.input == InputDown) { - line_position++; - } - } - } - - line_current = 1; - - // open root dir - result = f_opendir(&dir, ""); - - while(1) { - // read a directory item - result = f_readdir(&dir, &fno); - - if(result != FR_OK) { - // cannot read dir - break; - } - - if(fno.fname[0] == 0) { - // Break on end of dir - break; - } - - // draw files on display - if(line_current > line_position && - line_current <= (line_position + lines_on_display)) { - if(fno.fattrib & AM_DIR) { - snprintf(str_buffer, STR_BUFFER_SIZE, "DIR %s\n", fno.fname); - } else { - snprintf(str_buffer, STR_BUFFER_SIZE, "FIL %s\n", fno.fname); - } - fuprintf(furi_log, str_buffer); - } - - line_current++; - } - - result = f_closedir(&dir); - - furi_commit(fb_record); - } - } - - furiac_exit(NULL); -} diff --git a/applications/examples/input_dump.c b/applications/examples/input_dump.c index caaeca0c..a1482d74 100644 --- a/applications/examples/input_dump.c +++ b/applications/examples/input_dump.c @@ -1,5 +1,6 @@ -#include "flipper_v2.h" +#include <furi.h> #include <stdio.h> +#include <input/input.h> typedef union { unsigned int packed; @@ -21,12 +22,10 @@ static void event_cb(const void* value, void* ctx) { void application_input_dump(void* p) { // open record - ValueManager* state_record = furi_open("input_state"); - furi_check(state_record); + ValueManager* state_record = furi_record_open("input_state"); subscribe_pubsub(&state_record->pubsub, state_cb, NULL); - PubSub* event_record = furi_open("input_events"); - furi_check(event_record); + PubSub* event_record = furi_record_open("input_events"); subscribe_pubsub(event_record, event_cb, NULL); printf("Example app [input dump]\n"); diff --git a/applications/examples/ipc.c b/applications/examples/ipc.c deleted file mode 100644 index a965db98..00000000 --- a/applications/examples/ipc.c +++ /dev/null @@ -1,155 +0,0 @@ -#include "flipper.h" -#include <string.h> - -#define FB_WIDTH 10 -#define FB_HEIGHT 3 -#define FB_SIZE (FB_WIDTH * FB_HEIGHT) - -// context structure used for pass some object from app thread to callback -typedef struct { - SemaphoreHandle_t events; // queue to pass events from callback to app thread - FuriRecordSubscriber* log; // app logger -} IpcCtx; - -static void handle_fb_change(const void* fb, size_t fb_size, void* raw_ctx) { - IpcCtx* ctx = (IpcCtx*)raw_ctx; // make right type - - fuprintf(ctx->log, "[cb] framebuffer updated\n"); - - // send event to app thread - xSemaphoreGive(ctx->events); - - // Attention! Please, do not make blocking operation like IO and waits inside callback - // Remember that callback execute in calling thread/context -} - -static void print_fb(char* fb, FuriRecordSubscriber* log) { - if(fb == NULL) return; - - /* draw framebuffer like this: - +==========+ - | | - | | - | | - +==========+ - */ - - char row_buffer[FB_WIDTH + 1]; - row_buffer[FB_WIDTH] = '\0'; - - // FB layout is hardcoded here - fuprintf(log, "+==========+\n"); - for(uint8_t i = 0; i < FB_HEIGHT; i++) { - strncpy(row_buffer, &fb[FB_WIDTH * i], FB_WIDTH); - fuprintf(log, "|%s|\n", row_buffer); - } - fuprintf(log, "+==========+\n"); -} - -void application_ipc_display(void* p) { - // get logger - FuriRecordSubscriber* log = get_default_log(); - - // create ASCII "framebuffer" - // FB_WIDTH x FB_HEIGHT char buffer - char _framebuffer[FB_SIZE]; - - // init framebuffer by spaces - for(size_t i = 0; i < FB_SIZE; i++) { - _framebuffer[i] = ' '; - } - - // create record - if(!furi_create_deprecated("test_fb", (void*)_framebuffer, FB_SIZE)) { - fuprintf(log, "[display] cannot create fb record\n"); - furiac_exit(NULL); - } - - StaticSemaphore_t event_descriptor; - // create stack-based counting semaphore - SemaphoreHandle_t events = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor); - - if(events == NULL) { - fuprintf(log, "[display] cannot create event semaphore\n"); - furiac_exit(NULL); - } - - // save log and event queue in context structure - IpcCtx ctx = {.events = events, .log = log}; - - // subscribe to record. ctx will be passed to handle_fb_change - FuriRecordSubscriber* fb_record = - furi_open_deprecated("test_fb", false, false, handle_fb_change, NULL, &ctx); - - if(fb_record == NULL) { - fuprintf(log, "[display] cannot open fb record\n"); - furiac_exit(NULL); - } - -#ifdef HW_DISPLAY - // on Flipper target -- open screen - - // draw border - -#else - // on Local target -- print "blank screen" - { - void* fb = furi_take(fb_record); - print_fb((char*)fb, log); - furi_give(fb_record); - } -#endif - - while(1) { - // wait for event - if(xSemaphoreTake(events, portMAX_DELAY) == pdTRUE) { - fuprintf(log, "[display] get fb update\n\n"); - -#ifdef HW_DISPLAY -// on Flipper target draw the screen -#else - // on local target just print - { - void* fb = furi_take(fb_record); - print_fb((char*)fb, log); - furi_give(fb_record); - } -#endif - } - } -} - -// Widget application -void application_ipc_widget(void* p) { - FuriRecordSubscriber* log = get_default_log(); - - // open record - FuriRecordSubscriber* fb_record = - furi_open_deprecated("test_fb", false, false, NULL, NULL, NULL); - - if(fb_record == NULL) { - fuprintf(log, "[widget] cannot create fb record\n"); - furiac_exit(NULL); - } - - uint8_t counter = 0; - - while(1) { - delay(120); - - // write some ascii demo here: '#'' symbol run on overall screen - char* fb = (char*)furi_take(fb_record); - - if(fb == NULL) furiac_exit(NULL); - - for(size_t i = 0; i < FB_SIZE; i++) { - fb[i] = ' '; - } - - fb[counter % FB_SIZE] = '#'; - - furi_commit(fb_record); - - counter++; - } -}
\ No newline at end of file diff --git a/applications/examples/strobe.c b/applications/examples/strobe.c index fad250e9..ea922196 100644 --- a/applications/examples/strobe.c +++ b/applications/examples/strobe.c @@ -1,4 +1,5 @@ -#include "flipper_v2.h" +#include <furi.h> +#include <input.h> static void event_cb(const void* value, void* ctx) { const InputEvent* event = value; @@ -38,8 +39,7 @@ void application_strobe(void* p) { ValueMutex delay_mutex; init_mutex(&delay_mutex, &delay_time_holder, sizeof(delay_time_holder)); - PubSub* event_record = furi_open("input_events"); - furi_check(event_record); + PubSub* event_record = furi_record_open("input_events"); subscribe_pubsub(event_record, event_cb, &delay_mutex); while(1) { diff --git a/applications/examples/u8g2_example.c b/applications/examples/u8g2_example.c index e77012d4..8f745a87 100644 --- a/applications/examples/u8g2_example.c +++ b/applications/examples/u8g2_example.c @@ -1,32 +1,14 @@ #include "u8g2/u8g2.h" -#include "flipper.h" +#include <furi.h> void u8g2_example(void* p) { - FuriRecordSubscriber* log = get_default_log(); - // open record - FuriRecordSubscriber* fb_record = - furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL); - - if(fb_record == NULL) { - fuprintf(log, "[widget] cannot create fb record\n"); - furiac_exit(NULL); - } - - while(1) { - u8g2_t* fb = furi_take(fb_record); - if(fb != NULL) { - u8g2_SetFont(fb, u8g2_font_6x10_mf); - u8g2_SetDrawColor(fb, 1); - u8g2_SetFontMode(fb, 1); - u8g2_DrawStr(fb, 2, 12, "hello world!"); - } - furi_commit(fb_record); - - if(fb != NULL) { - furiac_exit(NULL); - } - - delay(1); - } + u8g2_t* fb = furi_record_open("u8g2_fb"); + u8g2_SetFont(fb, u8g2_font_6x10_mf); + u8g2_SetDrawColor(fb, 1); + u8g2_SetFontMode(fb, 1); + u8g2_DrawStr(fb, 2, 12, "hello world!"); + furi_record_close("u8g2_fb"); + + furiac_exit(NULL); }
\ No newline at end of file diff --git a/applications/examples/u8g2_qrcode.c b/applications/examples/u8g2_qrcode.c index 2799df33..92f5a359 100644 --- a/applications/examples/u8g2_qrcode.c +++ b/applications/examples/u8g2_qrcode.c @@ -1,6 +1,9 @@ #include "u8g2/u8g2.h" #include "qrcode/qrcode.h" -#include "flipper.h" +#include <furi.h> + +/* +TODO: rework with new app api void u8g2_DrawPixelSize(u8g2_t* u8g2, uint8_t x, uint8_t y, uint8_t size) { for(uint8_t px = 0; px < size; px++) { @@ -11,8 +14,6 @@ void u8g2_DrawPixelSize(u8g2_t* u8g2, uint8_t x, uint8_t y, uint8_t size) { } void u8g2_qrcode(void* p) { - FuriRecordSubscriber* log = get_default_log(); - // open record FuriRecordSubscriber* fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL); @@ -36,7 +37,7 @@ void u8g2_qrcode(void* p) { qrcode_initText(&qrcode, qrcodeBytes, qr_version, qr_error_correction, "HELLO FLIPPER"); if(fb_record == NULL) { - fuprintf(log, "[widget] cannot create fb record\n"); + printf("[widget] cannot create fb record\n"); furiac_exit(NULL); } @@ -69,4 +70,5 @@ void u8g2_qrcode(void* p) { delay(1); } -}
\ No newline at end of file +} +*/
\ No newline at end of file diff --git a/applications/examples/uart_write.c b/applications/examples/uart_write.c index 217b1563..7b6697ed 100644 --- a/applications/examples/uart_write.c +++ b/applications/examples/uart_write.c @@ -1,7 +1,5 @@ -#include "flipper.h" +#include <furi.h> #include <string.h> -#include "log.h" -#include "flipper_v2.h" void application_uart_write(void* p) { // Red led for showing progress @@ -11,12 +9,9 @@ void application_uart_write(void* p) { gpio_init(led_record, GpioModeOutputOpenDrain); - // get_default_log open "tty" record - FuriRecordSubscriber* log = get_default_log(); - // create buffer const char test_string[] = "test\n"; - furi_write(log, test_string, strlen(test_string)); + printf(test_string); // for example, create counter and show its value uint8_t counter = 0; diff --git a/applications/examples/vibro.c b/applications/examples/vibro.c index 51b9fae3..4189910d 100644 --- a/applications/examples/vibro.c +++ b/applications/examples/vibro.c @@ -1,4 +1,5 @@ -#include "flipper_v2.h" +#include <furi.h> +#include <input/input.h> typedef struct { GpioPin* led; @@ -24,7 +25,7 @@ void application_vibro(void* p) { gpio_write(ctx.vibro, false); // subscribe on buttons - PubSub* event_record = furi_open("input_events"); + PubSub* event_record = furi_record_open("input_events"); furi_check(event_record); subscribe_pubsub(event_record, button_handler, &ctx); diff --git a/applications/floopper-bloopper b/applications/floopper-bloopper -Subproject 25a2cc076c3162aad721e0d92009cfa7b9100c7 +Subproject 621044255a8be4d2c3f342e2b22178a342ccbfe diff --git a/applications/gpio-tester/gpio-tester.c b/applications/gpio-tester/gpio-tester.c index ab971e4c..695fbdf9 100644 --- a/applications/gpio-tester/gpio-tester.c +++ b/applications/gpio-tester/gpio-tester.c @@ -1,4 +1,6 @@ -#include "flipper_v2.h" +#include <furi.h> +#include <gui/gui.h> +#include <input/input.h> typedef struct { const char* name; @@ -47,7 +49,7 @@ static void render_callback(Canvas* canvas, void* ctx) { } static void input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = (QueueHandle_t)ctx; + osMessageQueueId_t event_queue = ctx; AppEvent event; event.type = EventTypeKey; @@ -74,11 +76,7 @@ void app_gpio_test(void* p) { widget_input_callback_set(widget, input_callback, event_queue); // Open GUI and register widget - Gui* gui = (Gui*)furi_open("gui"); - if(gui == NULL) { - printf("[gpio-tester] gui is not available\n"); - furiac_exit(NULL); - } + Gui* gui = furi_record_open("gui"); gui_add_widget(gui, widget, GuiLayerFullscreen); // configure pin diff --git a/applications/gui/canvas.c b/applications/gui/canvas.c index 7d4f8261..a8ea67eb 100644 --- a/applications/gui/canvas.c +++ b/applications/gui/canvas.c @@ -1,8 +1,7 @@ #include "canvas_i.h" #include "icon_i.h" -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> struct Canvas { u8g2_t fb; diff --git a/applications/gui/canvas.h b/applications/gui/canvas.h index 2ce6b309..7bc04066 100644 --- a/applications/gui/canvas.h +++ b/applications/gui/canvas.h @@ -5,6 +5,10 @@ #include <gui/icon.h> #include <assets_icons_i.h> +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { ColorWhite = 0x00, ColorBlack = 0x01, @@ -91,3 +95,7 @@ void canvas_draw_line(Canvas* canvas, uint8_t x1, uint8_t y1, uint8_t x2, uint8_ * Draw glyph */ void canvas_draw_glyph(Canvas* canvas, uint8_t x, uint8_t y, uint16_t ch); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/elements.h b/applications/gui/elements.h index d2bec004..bbdbe0fa 100644 --- a/applications/gui/elements.h +++ b/applications/gui/elements.h @@ -3,6 +3,10 @@ #include <stdint.h> #include "canvas.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Draw scrollbar on canvas. * width 3px, height equal to canvas height @@ -17,3 +21,7 @@ void elements_scrollbar(Canvas* canvas, uint8_t pos, uint8_t total); * @param width, height - frame width and height */ void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/gui.c b/applications/gui/gui.c index fdce8eab..38584ea1 100644 --- a/applications/gui/gui.c +++ b/applications/gui/gui.c @@ -1,8 +1,7 @@ #include "gui.h" #include "gui_i.h" -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> #include <m-array.h> #include <stdio.h> @@ -207,13 +206,9 @@ Gui* gui_alloc() { void gui_task(void* p) { Gui* gui = gui_alloc(); - // Create FURI record - if(!furi_create("gui", gui)) { - printf("[gui_task] cannot create the gui record\n"); - furiac_exit(NULL); - } - furiac_ready(); + // Create FURI record + furi_record_create("gui", gui); // Forever dispatch while(1) { diff --git a/applications/gui/gui.h b/applications/gui/gui.h index d05de799..a314109d 100644 --- a/applications/gui/gui.h +++ b/applications/gui/gui.h @@ -3,6 +3,10 @@ #include "widget.h" #include "canvas.h" +#ifdef __cplusplus +extern "C" { +#endif + #define GUI_DISPLAY_WIDTH 128 #define GUI_DISPLAY_HEIGHT 64 @@ -40,3 +44,7 @@ void gui_add_widget(Gui* gui, Widget* widget, GuiLayer layer); * @remarks thread safe */ void gui_remove_widget(Gui* gui, Widget* widget); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/gui_event.c b/applications/gui/gui_event.c index 57346fdf..eeeb0101 100644 --- a/applications/gui/gui_event.c +++ b/applications/gui/gui_event.c @@ -1,6 +1,6 @@ #include "gui_event.h" -#include <flipper_v2.h> +#include <furi.h> #define GUI_EVENT_MQUEUE_SIZE 8 @@ -45,7 +45,7 @@ GuiEvent* gui_event_alloc() { // osTimerStart(gui_event->timer, 1024 / 4); // Input - gui_event->input_event_record = furi_open("input_events"); + gui_event->input_event_record = furi_record_open("input_events"); furi_check(gui_event->input_event_record != NULL); subscribe_pubsub(gui_event->input_event_record, gui_event_input_events_callback, gui_event); diff --git a/applications/gui/gui_event.h b/applications/gui/gui_event.h index fc2f358f..d9846867 100644 --- a/applications/gui/gui_event.h +++ b/applications/gui/gui_event.h @@ -3,6 +3,10 @@ #include <stdint.h> #include <input/input.h> +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { GuiMessageTypeRedraw = 0x00, GuiMessageTypeInput = 0x01, @@ -23,3 +27,7 @@ void gui_event_free(GuiEvent* gui_event); void gui_event_messsage_send(GuiEvent* gui_event, GuiMessage* message); GuiMessage gui_event_message_next(GuiEvent* gui_event); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/icon.c b/applications/gui/icon.c index 8f02cf6d..37c6eba0 100644 --- a/applications/gui/icon.c +++ b/applications/gui/icon.c @@ -1,8 +1,6 @@ #include "icon_i.h" -#include <cmsis_os2.h> -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> Icon* icon_alloc(const IconData* data) { Icon* icon = furi_alloc(sizeof(Icon)); diff --git a/applications/gui/icon.h b/applications/gui/icon.h index 4df2ed36..72acabd5 100644 --- a/applications/gui/icon.h +++ b/applications/gui/icon.h @@ -3,6 +3,10 @@ #include <stdint.h> #include <stdbool.h> +#ifdef __cplusplus +extern "C" { +#endif + typedef struct IconData IconData; typedef struct Icon Icon; @@ -41,3 +45,7 @@ void icon_start_animation(Icon* icon); * Stop icon animation */ void icon_stop_animation(Icon* icon); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/u8g2_periphery.c b/applications/gui/u8g2_periphery.c index df6c9b2c..b6739977 100644 --- a/applications/gui/u8g2_periphery.c +++ b/applications/gui/u8g2_periphery.c @@ -1,5 +1,5 @@ #include "u8g2/u8g2.h" -#include "flipper.h" +#include <furi.h> #include <main.h> extern SPI_HandleTypeDef SPI_D; @@ -34,7 +34,7 @@ uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, vo // Function to define the logic level of the RESET line case U8X8_MSG_GPIO_RESET: #ifdef DEBUG - fuprintf(log, "[u8g2] rst %d\n", arg_int); + printf("[u8g2] rst %d\n", arg_int); #endif // TODO change it to FuriRecord pin @@ -44,7 +44,7 @@ uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, vo default: #ifdef DEBUG - fufuprintf(log, "[u8g2] unknown io %d\n", msg); + printf("[u8g2] unknown io %d\n", msg); #endif return 0; //A message was received which is not implemented, return 0 to indicate an error @@ -57,7 +57,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ switch(msg) { case U8X8_MSG_BYTE_SEND: #ifdef DEBUG - fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]); + printf("[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]); #endif // TODO change it to FuriRecord SPI @@ -66,7 +66,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ case U8X8_MSG_BYTE_SET_DC: #ifdef DEBUG - fuprintf(log, "[u8g2] dc %d\n", arg_int); + printf("[u8g2] dc %d\n", arg_int); #endif // TODO change it to FuriRecord pin @@ -76,7 +76,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ case U8X8_MSG_BYTE_INIT: #ifdef DEBUG - fuprintf(log, "[u8g2] init\n"); + printf("[u8g2] init\n"); #endif // TODO change it to FuriRecord pin @@ -85,7 +85,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ case U8X8_MSG_BYTE_START_TRANSFER: #ifdef DEBUG - fuprintf(log, "[u8g2] start\n"); + printf("[u8g2] start\n"); #endif // TODO: SPI manager @@ -98,7 +98,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ case U8X8_MSG_BYTE_END_TRANSFER: #ifdef DEBUG - fuprintf(log, "[u8g2] end\n"); + printf("[u8g2] end\n"); #endif asm("nop"); @@ -112,7 +112,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ default: #ifdef DEBUG - fuprintf(log, "[u8g2] unknown xfer %d\n", msg); + printf("[u8g2] unknown xfer %d\n", msg); #endif return 0; diff --git a/applications/gui/view.h b/applications/gui/view.h index e22e0715..832a3ef9 100644 --- a/applications/gui/view.h +++ b/applications/gui/view.h @@ -3,6 +3,10 @@ #include <input/input.h> #include "canvas.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Hides drawing widget */ #define VIEW_NONE 0xFFFFFFFF /* Ignore navigation event */ @@ -127,3 +131,7 @@ void view_commit_model(View* view); ({ void __fn__ function_body __fn__; })(p); \ view_commit_model(view); \ } + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/view_dispatcher.h b/applications/gui/view_dispatcher.h index e87d4b70..27c4abb9 100644 --- a/applications/gui/view_dispatcher.h +++ b/applications/gui/view_dispatcher.h @@ -3,6 +3,10 @@ #include "view.h" #include "gui.h" +#ifdef __cplusplus +extern "C" { +#endif + /* ViewDispatcher widget placement */ typedef enum { ViewDispatcherTypeNone, /* Special layer for internal use only */ @@ -43,3 +47,7 @@ void view_dispatcher_attach_to_gui( ViewDispatcher* view_dispatcher, Gui* gui, ViewDispatcherType type); + +#ifdef __cplusplus +} +#endif diff --git a/applications/gui/view_dispatcher_i.h b/applications/gui/view_dispatcher_i.h index 57e20200..58f1fd5f 100644 --- a/applications/gui/view_dispatcher_i.h +++ b/applications/gui/view_dispatcher_i.h @@ -2,7 +2,7 @@ #include "view_dispatcher.h" #include "view_i.h" -#include <flipper_v2.h> +#include <furi.h> #include <m-dict.h> DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST) diff --git a/applications/gui/view_i.h b/applications/gui/view_i.h index 243fd9e8..572f37f6 100644 --- a/applications/gui/view_i.h +++ b/applications/gui/view_i.h @@ -2,7 +2,7 @@ #include "view.h" #include "view_dispatcher_i.h" -#include <flipper_v2.h> +#include <furi.h> typedef struct { void* data; diff --git a/applications/gui/widget.c b/applications/gui/widget.c index e1470261..d4de1a65 100644 --- a/applications/gui/widget.c +++ b/applications/gui/widget.c @@ -1,8 +1,6 @@ #include "widget_i.h" -#include <cmsis_os.h> -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> #include "gui.h" #include "gui_i.h" @@ -73,8 +71,6 @@ void widget_update(Widget* widget) { void widget_gui_set(Widget* widget, Gui* gui) { furi_assert(widget); - furi_assert(gui); - widget->gui = gui; } diff --git a/applications/gui/widget.h b/applications/gui/widget.h index 6cf1f9c4..e31bbc88 100644 --- a/applications/gui/widget.h +++ b/applications/gui/widget.h @@ -3,6 +3,10 @@ #include <input/input.h> #include "canvas.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct Widget Widget; /* @@ -65,3 +69,7 @@ void widget_input_callback_set(Widget* widget, WidgetInputCallback callback, voi * Rendering will happen later after GUI system process signal. */ void widget_update(Widget* widget); + +#ifdef __cplusplus +} +#endif diff --git a/applications/ibutton/ibutton.cpp b/applications/ibutton/ibutton.cpp index e0637f76..a19b6127 100644 --- a/applications/ibutton/ibutton.cpp +++ b/applications/ibutton/ibutton.cpp @@ -32,7 +32,7 @@ void AppiButton::run() { printf("[ibutton] bye!\n"); // TODO remove all widgets create by app widget_enabled_set(widget, false); - furiac_exit(NULL); + osThreadExit(); } if(event.value.input.state && event.value.input.input == InputLeft) { diff --git a/applications/input/input.c b/applications/input/input.c index cabe655d..8b522d02 100644 --- a/applications/input/input.c +++ b/applications/input/input.c @@ -1,6 +1,6 @@ #include <input/input.h> #include <stdio.h> -#include <flipper_v2.h> +#include <furi.h> #ifdef APP_NFC void nfc_isr(void); @@ -35,18 +35,10 @@ void input_task(void* p) { furiac_exit(NULL); } - if(!furi_create("input_state", &input_state_record)) { - printf("[input_task] cannot create the input_state record\n"); - furiac_exit(NULL); - } - - if(!furi_create("input_events", &input_events_record)) { - printf("[input_task] cannot create the input_events record\n"); - furiac_exit(NULL); - } + furi_record_create("input_state", &input_state_record); + furi_record_create("input_events", &input_events_record); // we ready to work - furiac_ready(); initialized = true; // Force state update diff --git a/applications/irda/irda-decoder/irda-decoder.h b/applications/irda/irda-decoder/irda-decoder.h index fd14ebf0..78f4415c 100644 --- a/applications/irda/irda-decoder/irda-decoder.h +++ b/applications/irda/irda-decoder/irda-decoder.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> #include "irda-decoder-nec.h" #include "irda-decoder-types.h" diff --git a/applications/irda/irda.c b/applications/irda/irda.c index f079e0d4..522a7a50 100644 --- a/applications/irda/irda.c +++ b/applications/irda/irda.c @@ -1,5 +1,7 @@ -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> +#include <gui/gui.h> +#include <input/input.h> + #include "irda_nec.h" #include "irda_samsung.h" #include "irda_protocols.h" @@ -185,7 +187,7 @@ static void render_callback(Canvas* canvas, void* ctx) { } static void input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = (QueueHandle_t)ctx; + osMessageQueueId_t event_queue = ctx; AppEvent event; event.type = EventTypeKey; @@ -271,11 +273,7 @@ void irda(void* p) { widget_input_callback_set(widget, input_callback, event_queue); // Open GUI and register widget - Gui* gui = (Gui*)furi_open("gui"); - if(gui == NULL) { - printf("gui is not available\n"); - furiac_exit(NULL); - } + Gui* gui = furi_record_open("gui"); gui_add_widget(gui, widget, GuiLayerFullscreen); // Red LED diff --git a/applications/irda/irda_nec.c b/applications/irda/irda_nec.c index 9d465e17..8c22cea5 100644 --- a/applications/irda/irda_nec.c +++ b/applications/irda/irda_nec.c @@ -1,4 +1,4 @@ -#include "flipper.h" +#include <furi.h> #include "irda_nec.h" #include "irda_protocols.h" diff --git a/applications/irda/irda_nec.h b/applications/irda/irda_nec.h index eb5d0975..5506b1e7 100644 --- a/applications/irda/irda_nec.h +++ b/applications/irda/irda_nec.h @@ -1,4 +1,4 @@ #pragma once -#include "flipper.h" +#include <furi.h> void ir_nec_send(uint16_t addr, uint8_t data);
\ No newline at end of file diff --git a/applications/irda/irda_samsung.c b/applications/irda/irda_samsung.c index 9227c77c..e608a7da 100644 --- a/applications/irda/irda_samsung.c +++ b/applications/irda/irda_samsung.c @@ -1,4 +1,4 @@ -#include "flipper.h" +#include <furi.h> #include "irda_samsung.h" #include "irda_protocols.h" diff --git a/applications/irda/irda_samsung.h b/applications/irda/irda_samsung.h index 21bf4105..85f98abe 100644 --- a/applications/irda/irda_samsung.h +++ b/applications/irda/irda_samsung.h @@ -1,4 +1,4 @@ #pragma once -#include "flipper.h" +#include <furi.h> void ir_samsung_send(uint16_t addr, uint16_t data);
\ No newline at end of file diff --git a/applications/lf-rfid/em4100.c b/applications/lf-rfid/em4100.c index 43b0893d..bd8aa1c5 100644 --- a/applications/lf-rfid/em4100.c +++ b/applications/lf-rfid/em4100.c @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> void prepare_data(uint32_t ID, uint32_t VENDOR, uint8_t* data) { uint8_t value[10]; diff --git a/applications/lf-rfid/lf-rfid.c b/applications/lf-rfid/lf-rfid.c index 4c2c25c0..5731eeba 100644 --- a/applications/lf-rfid/lf-rfid.c +++ b/applications/lf-rfid/lf-rfid.c @@ -1,4 +1,5 @@ -#include "flipper_v2.h" +#include <furi.h> +#include <gui/gui.h> typedef enum { EventTypeTick, EventTypeKey, EventTypeRx } EventType; @@ -45,7 +46,7 @@ static void render_callback(Canvas* canvas, void* ctx) { } static void input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = (QueueHandle_t)ctx; + osMessageQueueId_t event_queue = ctx; AppEvent event; event.type = EventTypeKey; @@ -67,7 +68,7 @@ void comparator_trigger_callback(void* hcomp, void* comp_ctx) { // gpio_write(&debug_0, true); - osMessageQueueId_t event_queue = (QueueHandle_t)comp_ctx; + osMessageQueueId_t event_queue = comp_ctx; AppEvent event; event.type = EventTypeRx; @@ -202,11 +203,7 @@ void lf_rfid_workaround(void* p) { widget_input_callback_set(widget, input_callback, event_queue); // Open GUI and register widget - Gui* gui = (Gui*)furi_open("gui"); - if(gui == NULL) { - printf("gui is not available\n"); - furiac_exit(NULL); - } + Gui* gui = furi_record_open("gui"); gui_add_widget(gui, widget, GuiLayerFullscreen); AppEvent event; diff --git a/applications/menu/menu.c b/applications/menu/menu.c index 67c00c0a..4a0ae266 100644 --- a/applications/menu/menu.c +++ b/applications/menu/menu.c @@ -1,9 +1,8 @@ #include "menu.h" -#include <cmsis_os.h> #include <stdio.h> #include <stdbool.h> -#include <flipper_v2.h> +#include <furi.h> #include <gui/gui.h> #include <gui/elements.h> @@ -42,8 +41,7 @@ ValueMutex* menu_init() { menu->widget = widget_alloc(); // Open GUI and register fullscreen widget - Gui* gui = furi_open("gui"); - furi_check(gui); + Gui* gui = furi_record_open("gui"); gui_add_widget(gui, menu->widget, GuiLayerFullscreen); widget_enabled_set(menu->widget, false); @@ -237,12 +235,7 @@ void menu_task(void* p) { release_mutex(menu_mutex, menu); } - if(!furi_create("menu", menu_mutex)) { - printf("[menu_task] cannot create the menu record\n"); - furiac_exit(NULL); - } - - furiac_ready(); + furi_record_create("menu", menu_mutex); while(1) { MenuMessage m = menu_event_next(menu_event); diff --git a/applications/menu/menu_event.c b/applications/menu/menu_event.c index e5053af2..eea02905 100644 --- a/applications/menu/menu_event.c +++ b/applications/menu/menu_event.c @@ -1,11 +1,9 @@ #include "menu_event.h" -#include <cmsis_os.h> #include <string.h> #include <stdlib.h> -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> #define MENU_MESSAGE_MQUEUE_SIZE 8 diff --git a/applications/menu/menu_item.c b/applications/menu/menu_item.c index 8c8cb273..8c1a39a1 100644 --- a/applications/menu/menu_item.c +++ b/applications/menu/menu_item.c @@ -1,8 +1,7 @@ #include "menu_item.h" #include <stdlib.h> #include <string.h> -#include <flipper.h> -#include <flipper_v2.h> +#include <furi.h> struct MenuItem { MenuItemType type; diff --git a/applications/music-player/music-player.c b/applications/music-player/music-player.c index d6e38e12..3e8b4406 100644 --- a/applications/music-player/music-player.c +++ b/applications/music-player/music-player.c @@ -1,4 +1,6 @@ -#include "flipper_v2.h" +#include <furi.h> +#include <gui/gui.h> +#include <input/input.h> // TODO float note freq typedef enum { @@ -302,7 +304,7 @@ static void render_callback(Canvas* canvas, void* ctx) { } static void input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = (QueueHandle_t)ctx; + osMessageQueueId_t event_queue = ctx; MusicDemoEvent event; event.type = EventTypeKey; @@ -376,15 +378,11 @@ void music_player(void* p) { widget_input_callback_set(widget, input_callback, event_queue); // Open GUI and register widget - Gui* gui = (Gui*)furi_open("gui"); - if(gui == NULL) { - printf("gui is not available\n"); - furiac_exit(NULL); - } + Gui* gui = furi_record_open("gui"); gui_add_widget(gui, widget, GuiLayerFullscreen); // open input record - PubSub* input_events_record = furi_open("input_events"); + PubSub* input_events_record = furi_record_open("input_events"); // prepare "do nothing" event InputEvent input_event = {InputRight, true}; diff --git a/applications/nfc/nfc.c b/applications/nfc/nfc.c index 854572d7..98abc2ac 100644 --- a/applications/nfc/nfc.c +++ b/applications/nfc/nfc.c @@ -16,8 +16,7 @@ Nfc* nfc_alloc() { nfc->worker = nfc_worker_alloc(nfc->message_queue); nfc->icon = assets_icons_get(A_NFC_14); - nfc->menu_vm = furi_open("menu"); - furi_check(nfc->menu_vm); + nfc->menu_vm = furi_record_open("menu"); nfc->menu = menu_item_alloc_menu("NFC", nfc->icon); menu_item_subitem_add( @@ -102,18 +101,13 @@ void nfc_start(Nfc* nfc, NfcView view_id, NfcWorkerState worker_state) { void nfc_task(void* p) { Nfc* nfc = nfc_alloc(); - Gui* gui = furi_open("gui"); + Gui* gui = furi_record_open("gui"); view_dispatcher_attach_to_gui(nfc->view_dispatcher, gui, ViewDispatcherTypeFullscreen); with_value_mutex( nfc->menu_vm, (Menu * menu) { menu_item_add(menu, nfc->menu); }); - if(!furi_create("nfc", nfc)) { - printf("[nfc_task] cannot create nfc record\n"); - furiac_exit(NULL); - } - - furiac_ready(); + furi_record_create("nfc", nfc); NfcMessage message; while(1) { diff --git a/applications/nfc/nfc_i.h b/applications/nfc/nfc_i.h index d86d62b9..1bd985e7 100644 --- a/applications/nfc/nfc_i.h +++ b/applications/nfc/nfc_i.h @@ -5,7 +5,7 @@ #include "nfc_views.h" #include "nfc_worker.h" -#include <flipper_v2.h> +#include <furi.h> #include <gui/gui.h> #include <gui/view.h> diff --git a/applications/nfc/nfc_views.h b/applications/nfc/nfc_views.h index 9f592d9b..70e3fb15 100644 --- a/applications/nfc/nfc_views.h +++ b/applications/nfc/nfc_views.h @@ -3,7 +3,7 @@ #include <stdint.h> #include <stdbool.h> #include <gui/canvas.h> -#include <flipper_v2.h> +#include <furi.h> #include "nfc_types.h" diff --git a/applications/nfc/nfc_worker_i.h b/applications/nfc/nfc_worker_i.h index c118e1d8..75939879 100644 --- a/applications/nfc/nfc_worker_i.h +++ b/applications/nfc/nfc_worker_i.h @@ -3,8 +3,7 @@ #include "nfc_types.h" #include "nfc_worker.h" -#include <flipper_v2.h> -#include <cmsis_os2.h> +#include <furi.h> #include <stdbool.h> #include <rfal_analogConfig.h> diff --git a/applications/power/power.c b/applications/power/power.c index acb46c8c..9252d85d 100644 --- a/applications/power/power.c +++ b/applications/power/power.c @@ -1,7 +1,7 @@ #include "power.h" #include "power_views.h" -#include <flipper_v2.h> +#include <furi.h> #include <menu/menu.h> #include <menu/menu_item.h> @@ -12,8 +12,8 @@ #include <gui/view_dispatcher.h> #include <assets_icons.h> -#include <api-hal-power.h> #include <cli/cli.h> +#include <stm32wbxx.h> struct Power { ViewDispatcher* view_dispatcher; @@ -47,6 +47,10 @@ void power_draw_battery_callback(Canvas* canvas, void* context) { }); } +uint32_t power_info_back_callback(void* context) { + return VIEW_NONE; +} + void power_menu_off_callback(void* context) { api_hal_power_off(); } @@ -71,10 +75,9 @@ void power_menu_info_callback(void* context) { Power* power_alloc() { Power* power = furi_alloc(sizeof(Power)); - power->menu_vm = furi_open("menu"); - furi_check(power->menu_vm); + power->menu_vm = furi_record_open("menu"); - power->cli = furi_open("cli"); + power->cli = furi_record_open("cli"); power->menu = menu_item_alloc_menu("Power", NULL); menu_item_subitem_add( @@ -163,7 +166,7 @@ void power_task(void* p) { cli_add_command(power->cli, "power_otg_off", power_cli_otg_off, power); } - Gui* gui = furi_open("gui"); + Gui* gui = furi_record_open("gui"); gui_add_widget(gui, power->usb_widget, GuiLayerStatusBarLeft); gui_add_widget(gui, power->battery_widget, GuiLayerStatusBarRight); view_dispatcher_attach_to_gui(power->view_dispatcher, gui, ViewDispatcherTypeFullscreen); @@ -171,14 +174,9 @@ void power_task(void* p) { with_value_mutex( power->menu_vm, (Menu * menu) { menu_item_add(menu, power->menu); }); - if(!furi_create("power", power)) { - printf("[power_task] unable to create power record\n"); - furiac_exit(NULL); - } - api_hal_power_init(); - furiac_ready(); + furi_record_create("power", power); while(1) { with_view_model( diff --git a/applications/power/power_views.h b/applications/power/power_views.h index 97931601..3858b70f 100644 --- a/applications/power/power_views.h +++ b/applications/power/power_views.h @@ -2,8 +2,8 @@ #include <stdint.h> #include <stdbool.h> +#include <furi.h> #include <gui/canvas.h> -#include <flipper_v2.h> #include <gui/view.h> typedef enum { PowerViewInfo } PowerView; @@ -24,8 +24,4 @@ typedef struct { uint8_t charge; } PowerInfoModel; -static uint32_t power_info_back_callback(void* context) { - return VIEW_NONE; -} - void power_info_draw_callback(Canvas* canvas, void* context); diff --git a/applications/sd-card-test/sd-card-test.cpp b/applications/sd-card-test/sd-card-test.cpp index 5431a392..28dd5abb 100644 --- a/applications/sd-card-test/sd-card-test.cpp +++ b/applications/sd-card-test/sd-card-test.cpp @@ -104,23 +104,21 @@ void SdTest::run() { app_ready(); - fs_api = static_cast<FS_Api*>(furi_open("sdcard")); + fs_api = static_cast<FS_Api*>(furi_record_open("sdcard")); if(fs_api == NULL) { set_error({"cannot get sdcard api"}); exit(); } - Cli* cli = static_cast<Cli*>(furi_open("cli")); + Cli* cli = static_cast<Cli*>(furi_record_open("cli")); - if(cli != NULL) { - // read_benchmark and write_benchmark signatures are same. so we must use tags - auto cli_read_cb = cbc::obtain_connector<0>(this, &SdTest::cli_read_benchmark); - cli_add_command(cli, "sd_read_test", cli_read_cb, this); + // read_benchmark and write_benchmark signatures are same. so we must use tags + auto cli_read_cb = cbc::obtain_connector<0>(this, &SdTest::cli_read_benchmark); + cli_add_command(cli, "sd_read_test", cli_read_cb, this); - auto cli_write_cb = cbc::obtain_connector<1>(this, &SdTest::cli_write_benchmark); - cli_add_command(cli, "sd_write_test", cli_write_cb, this); - } + auto cli_write_cb = cbc::obtain_connector<1>(this, &SdTest::cli_write_benchmark); + cli_add_command(cli, "sd_write_test", cli_write_cb, this); detect_sd_card(); get_sd_card_info(); @@ -893,6 +891,7 @@ template <class T> void SdTest::set_text(std::initializer_list<T> list) { printf("------------------------\n"); release_state(); + update_gui(); } // render app diff --git a/applications/sd-filesystem/sd-filesystem.c b/applications/sd-filesystem/sd-filesystem.c index cd48ce93..bafa12ee 100644 --- a/applications/sd-filesystem/sd-filesystem.c +++ b/applications/sd-filesystem/sd-filesystem.c @@ -480,22 +480,19 @@ void sd_filesystem(void* p) { SdApp* sd_app = sd_app_alloc(); FS_Api* fs_api = fs_api_alloc(); - Gui* gui = furi_open("gui"); + Gui* gui = furi_record_open("gui"); + Cli* cli = furi_record_open("cli"); + ValueMutex* menu_vm = furi_record_open("menu"); + gui_add_widget(gui, sd_app->widget, GuiLayerFullscreen); gui_add_widget(gui, sd_app->icon.widget, GuiLayerStatusBarLeft); - Cli* cli = furi_open("cli"); - - if(cli != NULL) { - cli_add_command(cli, "sd_status", cli_sd_status, sd_app); - cli_add_command(cli, "sd_format", cli_sd_format, sd_app); - cli_add_command(cli, "sd_info", cli_sd_info, sd_app); - } + cli_add_command(cli, "sd_status", cli_sd_status, sd_app); + cli_add_command(cli, "sd_format", cli_sd_format, sd_app); + cli_add_command(cli, "sd_info", cli_sd_info, sd_app); // add api record - if(!furi_create("sdcard", fs_api)) { - furiac_exit(NULL); - } + furi_record_create("sdcard", fs_api); // init menu // TODO menu icon @@ -510,15 +507,15 @@ void sd_filesystem(void* p) { menu_item, menu_item_alloc_function("Eject", NULL, app_sd_eject_callback, sd_app)); // add item to menu - ValueMutex* menu_vm = furi_open("menu"); furi_check(menu_vm); with_value_mutex( menu_vm, (Menu * menu) { menu_item_add(menu, menu_item); }); - furiac_ready(); - printf("[sd_filesystem] start\n"); + // add api record + furi_record_create("sdcard", fs_api); + // sd card cycle bool sd_was_present = true; diff --git a/applications/sd-filesystem/sd-filesystem.h b/applications/sd-filesystem/sd-filesystem.h index 171de48c..0ca0c321 100644 --- a/applications/sd-filesystem/sd-filesystem.h +++ b/applications/sd-filesystem/sd-filesystem.h @@ -1,6 +1,8 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" + +#include <furi.h> +#include <gui/gui.h> +#include <input/input.h> #define SD_FS_MAX_FILES _FS_LOCK #define SD_STATE_LINES_COUNT 6 diff --git a/applications/template/template.c.example b/applications/template/template.c.example index fffcb07c..8cbe3255 100644 --- a/applications/template/template.c.example +++ b/applications/template/template.c.example @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> typedef enum { EventTypeTick, @@ -54,7 +54,7 @@ void template_app(void* p) { widget_input_callback_set(widget, input_callback, event_queue); // Open GUI and register widget - Gui* gui = (Gui*)furi_open("gui"); + Gui* gui = furi_record_open("gui"); if(gui == NULL) { printf("gui is not available\n"); furiac_exit(NULL); diff --git a/applications/tests/furi_event_test.c b/applications/tests/furi_event_test.c index 2edb0af8..90335098 100644 --- a/applications/tests/furi_event_test.c +++ b/applications/tests/furi_event_test.c @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> #include "minunit.h" static void furi_concurent_app(void* p) { @@ -10,7 +10,9 @@ static void furi_concurent_app(void* p) { } void test_furi_event() { - Event event; + mu_assert(false, "please reimplement or delete test"); + + /*Event event; mu_check(init_event(&event)); @@ -27,5 +29,5 @@ void test_furi_event() { // The event should not be signalled once it's processed mu_check(!wait_event_with_timeout(&event, 100)); - mu_check(delete_event(&event)); + mu_check(delete_event(&event));*/ } diff --git a/applications/tests/furi_pubsub_test.c b/applications/tests/furi_pubsub_test.c index 5d3a0a9e..d52b6bd3 100644 --- a/applications/tests/furi_pubsub_test.c +++ b/applications/tests/furi_pubsub_test.c @@ -1,8 +1,6 @@ #include <stdio.h> #include <string.h> -#include "flipper_v2.h" -#include "log.h" - +#include <furi.h> #include "minunit.h" const uint32_t context_value = 0xdeadbeef; diff --git a/applications/tests/furi_record_test.c b/applications/tests/furi_record_test.c index 4481602c..0b4d7a46 100644 --- a/applications/tests/furi_record_test.c +++ b/applications/tests/furi_record_test.c @@ -1,16 +1,14 @@ #include <stdio.h> #include <string.h> -#include "flipper.h" -#include "flipper_v2.h" -#include "log.h" +#include <furi.h> #include "minunit.h" void test_furi_create_open() { // 1. Create record uint8_t test_data = 0; - mu_check(furi_create("test/holding", (void*)&test_data)); + furi_record_create("test/holding", (void*)&test_data); // 2. Open it - void* record = furi_open("test/holding"); + void* record = furi_record_open("test/holding"); mu_assert_pointers_eq(record, &test_data); } diff --git a/applications/tests/furi_value_expanders_test.c b/applications/tests/furi_value_expanders_test.c index 5d9a965c..361c52cb 100644 --- a/applications/tests/furi_value_expanders_test.c +++ b/applications/tests/furi_value_expanders_test.c @@ -1,4 +1,4 @@ -#include "flipper_v2.h" +#include <furi.h> #include "minunit.h" #include <stdint.h> diff --git a/applications/tests/furi_valuemutex_test.c b/applications/tests/furi_valuemutex_test.c index 88bd6673..e9258a61 100644 --- a/applications/tests/furi_valuemutex_test.c +++ b/applications/tests/furi_valuemutex_test.c @@ -1,7 +1,6 @@ #include <stdio.h> #include <string.h> -#include "flipper_v2.h" -#include "log.h" +#include <furi.h> #include "minunit.h" @@ -88,6 +87,8 @@ void furi_concurent_app(void* p) { } void test_furi_concurrent_access() { + mu_assert(false, "please reimplement or delete test"); + /* // 1. Create holding record ConcurrentValue value = {.a = 0, .b = 0}; ValueMutex mutex; @@ -123,4 +124,5 @@ void test_furi_concurrent_access() { mu_assert_int_eq(value.a, value.b); mu_check(delete_mutex(&mutex)); + */ }
\ No newline at end of file diff --git a/applications/tests/furiac_test.c b/applications/tests/furiac_test.c index 05eaaeae..c19e629a 100644 --- a/applications/tests/furiac_test.c +++ b/applications/tests/furiac_test.c @@ -1,7 +1,6 @@ #include <stdio.h> #include <string.h> -#include "flipper.h" -#include "log.h" +#include <furi.h> /* Test: creating and killing task @@ -24,6 +23,8 @@ void create_kill_app(void* p) { } bool test_furi_ac_create_kill() { + mu_assert(false, "please reimplement or delete test"); + /* uint8_t counter = 0; uint8_t value_a = counter; @@ -56,6 +57,7 @@ bool test_furi_ac_create_kill() { } return true; + */ } /* diff --git a/applications/tests/minunit_test.c b/applications/tests/minunit_test.c index 9d6a93f4..0fa28313 100644 --- a/applications/tests/minunit_test.c +++ b/applications/tests/minunit_test.c @@ -1,6 +1,5 @@ #include <stdio.h> -#include "flipper.h" -#include "log.h" +#include <furi.h> #include "minunit_vars.h" #include "minunit.h" diff --git a/applications/tests/test_index.c b/applications/tests/test_index.c index 133259fb..51bff386 100644 --- a/applications/tests/test_index.c +++ b/applications/tests/test_index.c @@ -1,7 +1,5 @@ #include <stdio.h> -#include "flipper.h" -#include "flipper_v2.h" -#include "log.h" +#include <furi.h> // #include "flipper-core.h" TODO: Rust build disabled diff --git a/core/api-basic/flapp.h b/core/api-basic/flapp.h deleted file mode 100644 index 3ccaf7ee..00000000 --- a/core/api-basic/flapp.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "flipper.h" - -// == Flipper Application control (flapp) == - -typedef FlappHandler uint32_t; // TODO - -/* -simply starts application. It call `app` entrypoint with `param` passed as argument -Useful for daemon applications and pop-up. -*/ -FlappHandler* flapp_start(void(app*)(void*), char* name, void* param); - -/* -swtich to other application. -System **stop current app**, call `app` entrypoint with `param` passed -as argument and save current application entrypoint to `prev` field in -current application registry. Useful for UI or "active" application. -*/ -FlappHandler* flapp_switch(void(app*)(void*), char* name, void* param); - -/* -Exit application -stop current application (stop thread and clear application's stack), -start application from `prev` entry in current application registry, -cleanup current application registry. -*/ -void flapp_exit(void* param); - -/* -stop specified `app` without returning to `prev` application. -*/ -bool flapp_kill(FlappHandler* app); - -/* -If case one app depend on other, notify that app is ready. -*/ -void flapp_ready(); - -/* -Register on-exit callback. -It called before app will be killed. -Not recommended to use in user scenario, only for system purpose -(unregister callbacks, release mutexes, etc.) -*/ -bool flapp_on_exit(void(cb*)(void*), void* ctx); diff --git a/core/api-basic/furi.c b/core/api-basic/furi.c deleted file mode 100644 index 62ca8ce2..00000000 --- a/core/api-basic/furi.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "furi.h" -#include "furi-deprecated.h" - -bool furi_create(const char* name, void* ptr) { - return furi_create_deprecated(name, ptr, sizeof(size_t)); -} - -void* furi_open(const char* name) { - FuriRecordSubscriber* record = furi_open_deprecated(name, false, false, NULL, NULL, NULL); - void* res = furi_take(record); - furi_give(record); - - return res; -}
\ No newline at end of file diff --git a/core/api-basic/furi.h b/core/api-basic/furi.h deleted file mode 100644 index 0729eca0..00000000 --- a/core/api-basic/furi.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "flipper.h" - -/* -== Flipper universal registry implementation (FURI) == - -## Requirements - -* start daemon app -* kill app -* start child thread (kill when parent app was killed) -* switch between UI apps -*/ - -/* -Create record. -creates new record in registry and store pointer into it -*/ -bool furi_create(const char* name, void* ptr); - -/* -Open record. -get stored pointer by its name -*/ -void* furi_open(const char* name); diff --git a/core/api-hal/api-gpio.c b/core/api-hal/api-gpio.c index f1206025..dd8cffbf 100644 --- a/core/api-hal/api-gpio.c +++ b/core/api-hal/api-gpio.c @@ -1,4 +1,6 @@ #include "api-gpio.h" +#include <cmsis_os2.h> +#include <furi/record.h> osMutexId_t gpioInitMutex; @@ -37,7 +39,7 @@ void gpio_disable(GpioDisableRecord* gpio_record) { // get GPIO record ValueMutex* gpio_open_mutex(const char* name) { - ValueMutex* gpio_mutex = (ValueMutex*)furi_open(name); + ValueMutex* gpio_mutex = (ValueMutex*)furi_record_open(name); // TODO disable gpio on app exit //if(gpio_mutex != NULL) flapp_on_exit(gpio_disable, gpio_mutex); @@ -48,6 +50,6 @@ ValueMutex* gpio_open_mutex(const char* name) { // get GPIO record and acquire mutex GpioPin* gpio_open(const char* name) { ValueMutex* gpio_mutex = gpio_open_mutex(name); - GpioPin* gpio_pin = acquire_mutex(gpio_mutex, FLIPPER_HELPER_TIMEOUT); + GpioPin* gpio_pin = acquire_mutex(gpio_mutex, osWaitForever); return gpio_pin; }
\ No newline at end of file diff --git a/core/api-hal/api-gpio.h b/core/api-hal/api-gpio.h index 116c6ffb..76ed319e 100644 --- a/core/api-hal/api-gpio.h +++ b/core/api-hal/api-gpio.h @@ -1,7 +1,11 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" + #include "api-hal-gpio.h" +#include <furi/valuemutex.h> + +#ifdef __cplusplus +extern "C" { +#endif typedef struct { ValueMutex* gpio_mutex; @@ -38,4 +42,8 @@ void gpio_disable(GpioDisableRecord* gpio_record); ValueMutex* gpio_open_mutex(const char* name); // get GPIO record and acquire mutex -GpioPin* gpio_open(const char* name);
\ No newline at end of file +GpioPin* gpio_open(const char* name); + +#ifdef __cplusplus +} +#endif diff --git a/core/api-hal/api-interrupt-mgr.c b/core/api-hal/api-interrupt-mgr.c index 3fa27481..1dffffa8 100644 --- a/core/api-hal/api-interrupt-mgr.c +++ b/core/api-hal/api-interrupt-mgr.c @@ -1,5 +1,8 @@ #include "api-interrupt-mgr.h" +#include <m-list.h> +#include <cmsis_os2.h> + LIST_DEF(list_interrupt, InterruptCallbackItem, M_POD_OPLIST); list_interrupt_t interrupts; osMutexId_t interrupt_list_mutex; diff --git a/core/api-hal/api-interrupt-mgr.h b/core/api-hal/api-interrupt-mgr.h index 02a75e4e..e34a4c3a 100644 --- a/core/api-hal/api-interrupt-mgr.h +++ b/core/api-hal/api-interrupt-mgr.h @@ -1,5 +1,10 @@ #pragma once -#include "flipper_v2.h" + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif typedef void (*InterruptCallback)(void*, void*); @@ -18,4 +23,8 @@ typedef struct { bool api_interrupt_init(); void api_interrupt_add(InterruptCallback callback, InterruptType type, void* context); void api_interrupt_remove(InterruptCallback callback); -void api_interrupt_call(InterruptType type, void* hw);
\ No newline at end of file +void api_interrupt_call(InterruptType type, void* hw); + +#ifdef __cplusplus +} +#endif diff --git a/core/api-hal/api-spi.h b/core/api-hal/api-spi.h index 74559c54..131cc13c 100644 --- a/core/api-hal/api-spi.h +++ b/core/api-hal/api-spi.h @@ -1,4 +1,8 @@ -#include "flipper_v2.h" +#include <furi.h> + +#ifdef __cplusplus +extern "C" { +#endif /* struct used for handling SPI info. @@ -133,4 +137,8 @@ void cc1101_example() { } } ``` -*/
\ No newline at end of file +*/ + +#ifdef __cplusplus +} +#endif diff --git a/core/app.cpp b/core/app.cpp deleted file mode 100644 index 1c6153ca..00000000 --- a/core/app.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> -#include "flipper.h" -#include "flipper_v2.h" - -extern "C" { -#include "log.h" -#include "applications.h" -#include "tty_uart.h" -} - -// for testing purpose -uint32_t exitcode = 0; -extern "C" void set_exitcode(uint32_t _exitcode) { - exitcode = _exitcode; -} - -extern "C" int app() { - init_flipper_api(); - register_tty_uart(); - - FuriRecordSubscriber* log = get_default_log(); - fuprintf(log, "\n=== Welcome to Flipper Zero! ===\n\n"); - - // FURI startup - const size_t flipper_app_count = sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0]); - FuriApp* handlers[flipper_app_count]; - - for(size_t i = 0; i < flipper_app_count; i++) { - // TODO create a dependency tree and run tasks in the desired order - furiac_wait_libs(&FLIPPER_STARTUP[i].libs); - handlers[i] = furiac_start(FLIPPER_STARTUP[i].app, FLIPPER_STARTUP[i].name, NULL); - } - - bool is_alive = false; - do { - is_alive = false; - for(size_t i = 0; i < flipper_app_count; i++) { - if(handlers[i]->handler != NULL) { - is_alive = true; - } - } - delay(500); - } while(is_alive); - - fuprintf(log, "\n=== Bye from Flipper Zero! ===\n\n"); - - return (int)exitcode; -}
\ No newline at end of file diff --git a/core/core.mk b/core/core.mk index 478e4e80..5e8fd51e 100644 --- a/core/core.mk +++ b/core/core.mk @@ -1,8 +1,8 @@ CORE_DIR = $(PROJECT_ROOT)/core -CFLAGS += -I$(CORE_DIR) +CFLAGS += -I$(CORE_DIR) -D_GNU_SOURCE ASM_SOURCES += $(wildcard $(CORE_DIR)/*.s) C_SOURCES += $(wildcard $(CORE_DIR)/*.c) -C_SOURCES += $(wildcard $(CORE_DIR)/api-basic/*.c) +C_SOURCES += $(wildcard $(CORE_DIR)/furi/*.c) C_SOURCES += $(wildcard $(CORE_DIR)/api-hal/*.c) CPP_SOURCES += $(wildcard $(CORE_DIR)/*.cpp) diff --git a/core/flipper.h b/core/flipper.h deleted file mode 100644 index 0b33f9a9..00000000 --- a/core/flipper.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "api-hal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "main.h" -#include "cmsis_os.h" -#include "furi-deprecated.h" - -#include "log.h" -#include "input/input.h" - -#include <stdio.h> - -void set_exitcode(uint32_t _exitcode); - -#define FURI_LIB (const char*[]) - -#ifdef __cplusplus -} -#endif diff --git a/core/flipper_arduino.h b/core/flipper_arduino.h deleted file mode 100644 index fe1da069..00000000 --- a/core/flipper_arduino.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include "stdint.h" - -// Arduino defines -#define pinMode gpio_init -#define digitalWrite gpio_write -#define digitalRead gpio_read -#define delayMicroseconds delay_us -#define delay osDelay - -#define OUTPUT GpioModeOutputPushPull -#define INPUT GpioModeInput -#define LOW false -#define HIGH true - -typedef uint8_t byte;
\ No newline at end of file diff --git a/core/flipper_v2.c b/core/flipper_v2.c deleted file mode 100644 index d84dfda5..00000000 --- a/core/flipper_v2.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "flipper_v2.h" - -bool init_flipper_api(void) { - bool no_errors = true; - - if(!furi_init()) { - no_errors = false; - } - - if(!gpio_api_init()) { - no_errors = false; - } - - if(!api_interrupt_init()) { - no_errors = false; - } - - return no_errors; -}
\ No newline at end of file diff --git a/core/flipper_v2.h b/core/flipper_v2.h deleted file mode 100644 index 012d2aab..00000000 --- a/core/flipper_v2.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "flipper.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "api-basic/furi.h" -//#include "api-basic/flapp.h" -#include "cmsis_os2.h" -#include "api-basic/valuemutex.h" -#include "api-basic/pubsub.h" -#include "api-basic/value-expanders.h" -#include "api-basic/event.h" - -#include "api-basic/memmgr.h" -#include "api-basic/check.h" - -#include "api-hal/api-gpio.h" -#include "api-hal/api-interrupt-mgr.h" -#include "api-hal-resources.h" - -#include "gui/gui.h" - -// tmeout for helper functions -#define FLIPPER_HELPER_TIMEOUT 10 - -bool init_flipper_api(void); - -#ifdef __cplusplus -} -#endif
\ No newline at end of file diff --git a/core/furi-deprecated.c b/core/furi-deprecated.c deleted file mode 100644 index af420d49..00000000 --- a/core/furi-deprecated.c +++ /dev/null @@ -1,295 +0,0 @@ -#include "furi-deprecated.h" -#include <string.h> - -// TODO: this file contains printf, that not implemented on uC target - -#ifdef FURI_DEBUG -#include <stdio.h> -#endif - -#define MAX_RECORD_COUNT 32 - -static FuriRecord records[MAX_RECORD_COUNT]; -static size_t current_buffer_idx = 0; -osMutexId_t furi_core_mutex; - -bool furi_init(void) { - furi_core_mutex = osMutexNew(NULL); - if(furi_core_mutex == NULL) return false; - return true; -} - -// find record pointer by name -static FuriRecord* find_record(const char* name) { - if(name == NULL) return NULL; - - FuriRecord* res = NULL; - for(size_t i = 0; i < MAX_RECORD_COUNT; i++) { - if(records[i].name != NULL && strcmp(name, records[i].name) == 0) { - res = &records[i]; - } - } - - return res; -} - -// TODO: change open-create to only open -bool furi_create_deprecated(const char* name, void* value, size_t size) { -#ifdef FURI_DEBUG - printf("[FURI] creating %s record\n", name); -#endif - - // acquire mutex to prevent simultaneous write to record with same index - if(osMutexAcquire(furi_core_mutex, osWaitForever) != osOK) { - return false; - } - - FuriRecord* record = find_record(name); - - if(record != NULL) { -#ifdef FURI_DEBUG - printf("[FURI] record already exist\n"); -#endif - - record->value = value; - record->size = size; - - return true; - } - - // record not exist, create new - - if(current_buffer_idx >= MAX_RECORD_COUNT) { -// max record count exceed -#ifdef FURI_DEBUG - printf("[FURI] create: max record count exceed\n"); -#endif - return NULL; - } - - records[current_buffer_idx].mute_counter = 0; - records[current_buffer_idx].mutex = - xSemaphoreCreateMutexStatic(&records[current_buffer_idx].mutex_buffer); - records[current_buffer_idx].value = value; - records[current_buffer_idx].size = size; - records[current_buffer_idx].name = name; - - for(size_t i = 0; i < MAX_RECORD_SUBSCRIBERS; i++) { - records[current_buffer_idx].subscribers[i].allocated = false; - records[current_buffer_idx].subscribers[i].ctx = NULL; - } - - current_buffer_idx++; - - osMutexRelease(furi_core_mutex); - - return true; -} - -FuriRecordSubscriber* furi_open_deprecated( - const char* name, - bool solo, - bool no_mute, - FlipperRecordCallback value_callback, - FlipperRecordStateCallback state_callback, - void* ctx) { -#ifdef FURI_DEBUG - printf("[FURI] opening %s record\n", name); -#endif - - // get furi record by name - FuriRecord* record = find_record(name); - - if(record == NULL) { -// cannot find record -#ifdef FURI_DEBUG - printf("[FURI] cannot find record %s\n", name); -#endif - - // create record if not exist - if(!furi_create_deprecated(name, NULL, 0)) { - return NULL; - } - - record = find_record(name); - - if(record == NULL) { - return NULL; - } - } - - // allocate subscriber - FuriRecordSubscriber* subscriber = NULL; - - for(size_t i = 0; i < MAX_RECORD_SUBSCRIBERS; i++) { - if(!record->subscribers[i].allocated) { - subscriber = &record->subscribers[i]; - break; - } - } - - if(subscriber == NULL) { -// cannot add subscriber (full) -#ifdef FURI_DEBUG - printf("[FURI] open: cannot add subscriber (full)\n"); -#endif - - return NULL; - } - - // increase mute_counter - if(solo) { - record->mute_counter++; - } - - // set all parameters - subscriber->allocated = true; - subscriber->mute_counter = record->mute_counter; - subscriber->no_mute = no_mute; - subscriber->cb = value_callback; - subscriber->state_cb = state_callback; - subscriber->record = record; - subscriber->ctx = ctx; - - // register record in application - FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle()); - - if(current_task != NULL) { - current_task->records[current_task->records_count] = record; - current_task->records_count++; - } else { -#ifdef FURI_DEBUG - printf("[FURI] open: no current task\n"); -#endif - } - - return subscriber; -} - -void furi_close(FuriRecordSubscriber* handler) { -#ifdef FURI_DEBUG - printf("[FURI] closing %s record\n", handler->record->name); -#endif - - // deallocate subscriber - handler->allocated = false; - - // set mute counter to next max value - uint8_t max_mute_counter = 0; - for(size_t i = 0; i < MAX_RECORD_SUBSCRIBERS; i++) { - if(handler->record->subscribers[i].allocated) { - if(handler->record->subscribers[i].mute_counter > max_mute_counter) { - max_mute_counter = handler->record->subscribers[i].mute_counter; - } - } - } - handler->record->mute_counter = max_mute_counter; -} - -static void furi_notify(FuriRecordSubscriber* handler, const void* value, size_t size) { - for(size_t i = 0; i < MAX_RECORD_SUBSCRIBERS; i++) { - if(handler->record->subscribers[i].allocated) { - if(handler->record->subscribers[i].cb != NULL) { - handler->record->subscribers[i].cb( - value, size, handler->record->subscribers[i].ctx); - } - } - } -} - -void* furi_take(FuriRecordSubscriber* handler) { - if(handler == NULL || handler->record == NULL) return NULL; - - if(xSemaphoreTake(handler->record->mutex, portMAX_DELAY) == pdTRUE) { - return handler->record->value; - } else { - return NULL; - } -} - -void furi_give(FuriRecordSubscriber* handler) { - if(handler == NULL || handler->record == NULL) return; - - xSemaphoreGive(handler->record->mutex); -} - -void furi_commit(FuriRecordSubscriber* handler) { - if(handler == NULL || handler->record == NULL) return; - - furi_notify(handler, handler->record->value, handler->record->size); - furi_give(handler); -} - -bool furi_read(FuriRecordSubscriber* handler, void* value, size_t size) { -#ifdef FURI_DEBUG - printf("[FURI] read from %s\n", handler->record->name); -#endif - - if(handler == NULL || handler->record == NULL || value == NULL) return false; - - if(size > handler->record->size) return false; - - // return false if read from pipe - if(handler->record->value == NULL) return false; - - furi_take(handler); - memcpy(value, handler->record->value, size); - furi_notify(handler, value, size); - furi_give(handler); - - return true; -} - -bool furi_write(FuriRecordSubscriber* handler, const void* value, size_t size) { -#ifdef FURI_DEBUG - printf("[FURI] write to %s\n", handler->record->name); -#endif - - if(handler == NULL || handler->record == NULL || value == NULL) { -#ifdef FURI_DEBUG - printf( - "[FURI] write: null param %x %x\n", - (uint32_t)(size_t)handler, - (uint32_t)(size_t)value); -#endif - - return false; - } - - // check if closed - if(!handler->allocated) { -#ifdef FURI_DEBUG - printf("[FURI] write: handler closed\n"); -#endif - return false; - } - - if(handler->record->value != NULL && size > handler->record->size) { -#ifdef FURI_DEBUG - printf("[FURI] write: wrong size %d\n", (uint32_t)size); -#endif - return false; - } - - // check mute - if(handler->record->mute_counter != handler->mute_counter && !handler->no_mute) { -#ifdef FURI_DEBUG - printf("[FURI] write: muted\n"); -#endif - return false; - } - - furi_take(handler); - if(handler->record->value != NULL) { - // real write to value - memcpy(handler->record->value, value, size); - - // notify subscribers - furi_notify(handler, handler->record->value, handler->record->size); - } else { - furi_notify(handler, value, size); - } - furi_give(handler); - - return true; -}
\ No newline at end of file diff --git a/core/furi-deprecated.h b/core/furi-deprecated.h deleted file mode 100644 index dead0e41..00000000 --- a/core/furi-deprecated.h +++ /dev/null @@ -1,207 +0,0 @@ -#pragma once - -#include "cmsis_os.h" - -#ifdef HAVE_FREERTOS -#include <semphr.h> -#endif - -#include <stdbool.h> -#include <stdlib.h> -#include <stdint.h> -#include <string.h> -#include <assert.h> - -#include "assets_icons.h" - -#define MAX_TASK_RECORDS 8 -#define MAX_RECORD_SUBSCRIBERS 8 - -inline static void* furi_alloc(size_t size) { - void* p = malloc(size); - assert(p); - return memset(p, 0, size); -} - -/// application is just a function -typedef void (*FlipperApplication)(void*); - -/// pointer to value callback function -typedef void (*FlipperRecordCallback)(const void*, size_t, void*); - -typedef enum { - FlipperRecordStateMute, ///< record open and mute this handler - FlipperRecordStateUnmute, ///< record unmuted - FlipperRecordStateDeleted ///< record owner halt -} FlipperRecordState; - -/// pointer to state callback function -typedef void (*FlipperRecordStateCallback)(FlipperRecordState, void*); - -struct _FuriRecord; - -typedef struct { - bool allocated; - FlipperRecordCallback cb; ///< value cb - FlipperRecordStateCallback state_cb; ///< state cb - uint8_t mute_counter; ///< see "wiki/FURI#mute-algorithm" - bool no_mute; - struct _FuriRecord* record; ///< parent record - void* ctx; -} FuriRecordSubscriber; - -/// FURI record handler -struct _FuriRecord { - const char* name; - void* value; - size_t size; - StaticSemaphore_t mutex_buffer; - SemaphoreHandle_t mutex; - uint8_t mute_counter; - FuriRecordSubscriber subscribers[MAX_RECORD_SUBSCRIBERS]; -}; - -typedef struct _FuriRecord FuriRecord; - -/// store info about active task -typedef struct { - const char* name; - FlipperApplication application; - const char* prev_name; - FlipperApplication prev; - TaskHandle_t handler; - uint8_t records_count; ///< count of records which task open - FuriRecord* records[MAX_TASK_RECORDS]; ///< list of records which task open - - bool ready; -} FuriApp; - -// application dependency info -typedef struct { - uint8_t count; - const char** name; -} FlipperAppLibrary; - -// application startup info -typedef struct { - FlipperApplication app; - const char* name; - FlipperAppLibrary libs; - IconName icon; -} FlipperStartupApp; - -// Init core -bool furi_init(void); - -/*! -Simply starts application. -It call app entrypoint with param passed as argument. -Useful for daemon applications and pop-up. -*/ -FuriApp* furiac_start(FlipperApplication app, const char* name, void* param); - -/*! -Swtich to other application. -FURI stop current app, call app entrypoint with param passed as -argument and save current application entrypoint to prev field -in current application registry. -Useful for UI or "active" application. -*/ -void furiac_switch(FlipperApplication app, char* name, void* param); - -/*! -Stop current application -(stop thread and clear application's stack), start application -from prev entry in current application registry, cleanup current -application registry. -*/ -void furiac_exit(void* param); - -/*! -Mark application as prepared and ready to perform actions -*/ -void furiac_ready(); - -/* -Wait for the libraries we depend on -*/ -void furiac_wait_libs(const FlipperAppLibrary* libs); - -/*! -Stop specified app without returning to prev application. -*/ -bool furiac_kill(FuriApp* app); - -// find task pointer by handle -FuriApp* find_task(TaskHandle_t handler); - -/*! -Creates named FURI record. -\param[in] name you can open this record anywhere -\param[in] value pointer to data. -\param[in] size size of data. -If NULL, create FURI Pipe (only callbacks management, no data/mutex) - -Returns false if registry have not enough memory for creating. -*/ -bool furi_create_deprecated(const char* name, void* value, size_t size); - -/*! -Opens existing FURI record by name. -Returns NULL if record does not exist. -\param[in] solo if true another applications handlers set into "muted" state. -When appication has exited or record has closed, all handlers is unmuted. -It may be useful for concurrently acces to resources like framebuffer or beeper. -\param[in] no_mute if true, another applications cannot mute this handler. -*/ -FuriRecordSubscriber* furi_open_deprecated( - const char* name, - bool solo, - bool no_mute, - FlipperRecordCallback value_callback, - FlipperRecordStateCallback state_callback, - void* ctx); - -/*! - -*/ -void furi_close(FuriRecordSubscriber* handler); - -/*! -read message from record. -Returns true if success, false otherwise (closed/non-existent record) -Also return false if you try to read from FURI pipe - -TODO: enum return value with execution status -*/ -bool furi_read(FuriRecordSubscriber* record, void* data, size_t size); - -/*! -write message to record. -Returns true if success, false otherwise (closed/non-existent record or muted). - -TODO: enum return value with execution status -*/ -bool furi_write(FuriRecordSubscriber* record, const void* data, size_t size); - -/*! -lock value mutex. -It can be useful if records contain pointer to buffer which you want to change. -You must call furi_give after operation on data and -you shouldn't block executing between take and give calls - -Returns pointer to data, NULL if closed/non-existent record or muted - -TODO: enum return value with execution status -*/ -void* furi_take(FuriRecordSubscriber* record); - -/*! -unlock value mutex. -*/ -void furi_give(FuriRecordSubscriber* record); - -/*! -unlock value mutex and notify subscribers that data is chaned. -*/ -void furi_commit(FuriRecordSubscriber* handler); diff --git a/core/furi.c b/core/furi.c new file mode 100644 index 00000000..aaaad400 --- /dev/null +++ b/core/furi.c @@ -0,0 +1,36 @@ +#include "furi.h" +#include <applications.h> + +// for testing purpose +uint32_t exitcode = 0; + +void set_exitcode(uint32_t _exitcode) { + exitcode = _exitcode; +} + +void furi_init() { + gpio_api_init(); + api_interrupt_init(); + furi_record_init(); + furi_stdglue_init(); +} + +int systemd() { + furi_init(); + + // FURI startup + for(size_t i = 0; i < FLIPPER_SERVICES_size(); i++) { + osThreadAttr_t* attr = furi_alloc(sizeof(osThreadAttr_t)); + attr->name = FLIPPER_SERVICES[i].name; + attr->stack_size = 1024; + osThreadNew(FLIPPER_SERVICES[i].app, NULL, attr); + } + + while(1) { + osThreadSuspend(osThreadGetId()); + } + + printf("\n=== Bye from Flipper Zero! ===\n\n"); + + return (int)exitcode; +}
\ No newline at end of file diff --git a/core/furi.h b/core/furi.h new file mode 100644 index 00000000..6512f9b2 --- /dev/null +++ b/core/furi.h @@ -0,0 +1,28 @@ +#pragma once + +#include <cmsis_os2.h> + +#include <furi/check.h> +#include <furi/event.h> +#include <furi/memmgr.h> +#include <furi/pubsub.h> +#include <furi/record.h> +#include <furi/stdglue.h> +#include <furi/value-expanders.h> +#include <furi/valuemutex.h> + +#include <api-hal/api-gpio.h> +#include <api-hal/api-interrupt-mgr.h> + +#include <api-hal.h> +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define furiac_exit(ptr) osThreadExit() + +#ifdef __cplusplus +} +#endif diff --git a/core/api-basic/check.c b/core/furi/check.c index edd50a7d..5bd019ca 100644 --- a/core/api-basic/check.c +++ b/core/furi/check.c @@ -1,5 +1,6 @@ #include "check.h" #include "api-hal-task.h" +#include <stdio.h> void __furi_abort(void); @@ -22,20 +23,21 @@ void __furi_check_debug(const char* file, int line, const char* function, const if(task_is_isr_context()) { printf(" in [ISR] context"); } else { - FuriApp* app = find_task(xTaskGetCurrentTaskHandle()); + // FuriApp* app = find_task(xTaskGetCurrentTaskHandle()); - if(app == NULL) { - printf(", in [main] context"); - } else { - printf(", in [%s] app context", app->name); - } + // if(app == NULL) { + // printf(", in [main] context"); + // } else { + // printf(", in [%s] app context", app->name); + // } } __furi_abort(); } void __furi_abort(void) { - taskDISABLE_INTERRUPTS(); + __disable_irq(); + asm("bkpt 1"); while(1) { } }
\ No newline at end of file diff --git a/core/api-basic/check.h b/core/furi/check.h index 60758792..0f012cd2 100644 --- a/core/api-basic/check.h +++ b/core/furi/check.h @@ -1,6 +1,8 @@ #pragma once -#include "flipper.h" +#ifdef __cplusplus +extern "C" { +#endif // Find how to how get function's pretty name #ifndef __FURI_CHECK_FUNC @@ -38,4 +40,8 @@ // !NDEBUG void __furi_check(void); -void __furi_check_debug(const char* file, int line, const char* function, const char* condition);
\ No newline at end of file +void __furi_check_debug(const char* file, int line, const char* function, const char* condition); + +#ifdef __cplusplus +} +#endif diff --git a/core/api-basic/event.c b/core/furi/event.c index 1fc9cbfd..1fc9cbfd 100644 --- a/core/api-basic/event.c +++ b/core/furi/event.c diff --git a/core/api-basic/event.h b/core/furi/event.h index 7905676e..a7683bd1 100644 --- a/core/api-basic/event.h +++ b/core/furi/event.h @@ -2,7 +2,11 @@ #include <stdbool.h> #include <stdint.h> -#include "cmsis_os.h" +#include <cmsis_os2.h> + +#ifdef __cplusplus +extern "C" { +#endif typedef struct { osSemaphoreId_t semaphore_id; @@ -34,3 +38,7 @@ void wait_event(Event* event); Waits with a timeout until the event is signalled. */ bool wait_event_with_timeout(Event* event, uint32_t timeout_ms); + +#ifdef __cplusplus +} +#endif diff --git a/core/api-basic/memmgr.c b/core/furi/memmgr.c index e67b7e7b..e84bbc0e 100644 --- a/core/api-basic/memmgr.c +++ b/core/furi/memmgr.c @@ -42,6 +42,23 @@ void* calloc(size_t count, size_t size) { return ptr; } +char* strdup(const char* s) { + if(s == NULL) { + return NULL; + } + + size_t siz = strlen(s) + 1; + char* y = malloc(siz); + + if(y != NULL) { + memcpy(y, s, siz); + } else { + return NULL; + } + + return y; +} + size_t memmgr_get_free_heap(void) { return xPortGetFreeHeapSize(); } diff --git a/core/api-basic/memmgr.h b/core/furi/memmgr.h index 70a32e4b..27d2fbf3 100644 --- a/core/api-basic/memmgr.h +++ b/core/furi/memmgr.h @@ -1,5 +1,12 @@ #pragma once + #include <stddef.h> +#include <string.h> +#include "check.h" + +#ifdef __cplusplus +extern "C" { +#endif // define for test case "link against furi memmgr" #define FURI_MEMMGR_GUARD 1 @@ -11,3 +18,13 @@ void* calloc(size_t count, size_t size); size_t memmgr_get_free_heap(void); size_t memmgr_get_minimum_free_heap(void); + +inline static void* furi_alloc(size_t size) { + void* p = malloc(size); + furi_check(p); + return memset(p, 0, size); +} + +#ifdef __cplusplus +} +#endif diff --git a/core/api-basic/pubsub.c b/core/furi/pubsub.c index 8161ebf2..2cfb6141 100644 --- a/core/api-basic/pubsub.c +++ b/core/furi/pubsub.c @@ -1,5 +1,5 @@ #include "pubsub.h" -#include "flipper_v2.h" +#include <furi.h> bool init_pubsub(PubSub* pubsub) { // mutex without name, diff --git a/core/api-basic/pubsub.h b/core/furi/pubsub.h index 1bd5bedc..62a7f2b3 100644 --- a/core/api-basic/pubsub.h +++ b/core/furi/pubsub.h @@ -3,6 +3,10 @@ #include "cmsis_os.h" #include "m-list.h" +#ifdef __cplusplus +extern "C" { +#endif + /* == PubSub == @@ -53,6 +57,10 @@ Use `notify_pubsub` to notify subscribers. */ bool notify_pubsub(PubSub* pubsub, void* arg); +#ifdef __cplusplus +} +#endif + /* ```C @@ -84,4 +92,4 @@ void pubsub_test() { } } ``` -*/
\ No newline at end of file +*/ diff --git a/core/furi/record.c b/core/furi/record.c new file mode 100644 index 00000000..23e35e07 --- /dev/null +++ b/core/furi/record.c @@ -0,0 +1,123 @@ +#include "record.h" +#include "check.h" + +#include <cmsis_os2.h> +#include <m-string.h> +#include <m-dict.h> + +#define FURI_RECORD_FLAG_UPDATED 0x00000001U + +DICT_SET_DEF(osThreadIdSet, uint32_t) + +typedef struct { + void* data; + osThreadId_t owner; + osThreadIdSet_t holders; +} FuriRecord; + +DICT_DEF2(FuriRecordDict, string_t, STRING_OPLIST, FuriRecord, M_POD_OPLIST) + +typedef struct { + osMutexId_t records_mutex; + FuriRecordDict_t records; +} FuriRecordData; + +FuriRecordData furi_record_data; + +void furi_record_init() { + furi_record_data.records_mutex = osMutexNew(NULL); + FuriRecordDict_init(furi_record_data.records); +} + +FuriRecord* furi_record_get_or_create(string_t name_str) { + FuriRecord* record = FuriRecordDict_get(furi_record_data.records, name_str); + if(!record) { + FuriRecord new_record; + new_record.data = NULL; + new_record.owner = NULL; + osThreadIdSet_init(new_record.holders); + FuriRecordDict_set_at(furi_record_data.records, name_str, new_record); + record = FuriRecordDict_get(furi_record_data.records, name_str); + } + return record; +} + +void furi_record_create(const char* name, void* data) { + osThreadId_t thread_id = osThreadGetId(); + + string_t name_str; + string_init_set_str(name_str, name); + + // Acquire mutex + furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK); + FuriRecord* record = furi_record_get_or_create(name_str); + record->data = data; + record->owner = thread_id; + + // For each holder set event flag + osThreadIdSet_it_t it; + for(osThreadIdSet_it(it, record->holders); !osThreadIdSet_end_p(it); osThreadIdSet_next(it)) { + osThreadFlagsSet((osThreadId_t)*osThreadIdSet_ref(it), FURI_RECORD_FLAG_UPDATED); + } + // Release mutex + furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK); + + string_clear(name_str); +} + +bool furi_record_destroy(const char* name) { + osThreadId_t thread_id = osThreadGetId(); + + string_t name_str; + string_init_set_str(name_str, name); + + bool destroyed = false; + furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK); + FuriRecord* record = FuriRecordDict_get(furi_record_data.records, name_str); + if(record && record->owner == thread_id && osThreadIdSet_size(record->holders) == 0) { + osThreadIdSet_clear(record->holders); + FuriRecordDict_erase(furi_record_data.records, name_str); + } + furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK); + + string_clear(name_str); + return destroyed; +} + +void* furi_record_open(const char* name) { + osThreadId_t thread_id = osThreadGetId(); + + string_t name_str; + string_init_set_str(name_str, name); + + FuriRecord* record = NULL; + while(1) { + furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK); + record = furi_record_get_or_create(name_str); + osThreadIdSet_push(record->holders, (uint32_t)thread_id); + furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK); + // Check if owner is already arrived + if(record->owner) { + break; + } + // Wait for thread flag to appear + osThreadFlagsWait(FURI_RECORD_FLAG_UPDATED, osFlagsWaitAny, osWaitForever); + } + + string_clear(name_str); + return record->data; +} + +void furi_record_close(const char* name) { + osThreadId_t thread_id = osThreadGetId(); + + string_t name_str; + string_init_set_str(name_str, name); + + furi_check(osMutexAcquire(furi_record_data.records_mutex, osWaitForever) == osOK); + FuriRecord* record = FuriRecordDict_get(furi_record_data.records, name_str); + osThreadIdSet_erase(record->holders, (uint32_t)thread_id); + furi_check(osMutexRelease(furi_record_data.records_mutex) == osOK); + + string_clear(name_str); +} diff --git a/core/furi/record.h b/core/furi/record.h new file mode 100644 index 00000000..965d1908 --- /dev/null +++ b/core/furi/record.h @@ -0,0 +1,44 @@ +#pragma once + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initialize record storage + * For internal use only. + */ +void furi_record_init(); + +/* Create record + * @param name - record name + * @param data - data pointer + * @note Thread safe. Create and destroy must be executed from the same thread. + */ +void furi_record_create(const char* name, void* data); + +/* Destroy record + * @param name - record name + * @return true if successful, false if still have holders or thread is not owner. + * @note Thread safe. Create and destroy must be executed from the same thread. + */ +bool furi_record_destroy(const char* name); + +/* Open record + * @param name - record name + * @return pointer to the record + * @note Thread safe. Open and close must be executed from the same thread. + * Suspends caller thread till record appear + */ +void* furi_record_open(const char* name); + +/* Close record + * @param name - record name + * @note Thread safe. Open and close must be executed from the same thread. + */ +void furi_record_close(const char* name); + +#ifdef __cplusplus +} +#endif diff --git a/core/furi/stdglue.c b/core/furi/stdglue.c new file mode 100644 index 00000000..13b8cd39 --- /dev/null +++ b/core/furi/stdglue.c @@ -0,0 +1,38 @@ +#include "stdglue.h" +#include <main.h> + +#include <stdio.h> +#include <string.h> + +extern UART_HandleTypeDef DEBUG_UART; + +static ssize_t stdout_write(void* _cookie, const char* data, size_t size) { + if(data == 0) { + /* + * This means that we should flush internal buffers. Since we + * don't we just return. (Remember, "handle" == -1 means that all + * handles should be flushed.) + */ + return 0; + } + + HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY); + + return size; +} + +bool furi_stdglue_init() { + FILE* fp = fopencookie( + NULL, + "w", + (cookie_io_functions_t){ + .read = NULL, + .write = stdout_write, + .seek = NULL, + .close = NULL, + }); + setvbuf(fp, NULL, _IONBF, 0); + stdout = fp; + + return true; +} diff --git a/core/furi/stdglue.h b/core/furi/stdglue.h new file mode 100644 index 00000000..d093d33d --- /dev/null +++ b/core/furi/stdglue.h @@ -0,0 +1,13 @@ +#pragma once + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +bool furi_stdglue_init(); + +#ifdef __cplusplus +} +#endif diff --git a/core/api-basic/value-expanders.c b/core/furi/value-expanders.c index 845ea4dc..845ea4dc 100644 --- a/core/api-basic/value-expanders.c +++ b/core/furi/value-expanders.c diff --git a/core/api-basic/value-expanders.h b/core/furi/value-expanders.h index 57ef4c13..aef4a117 100644 --- a/core/api-basic/value-expanders.h +++ b/core/furi/value-expanders.h @@ -1,10 +1,13 @@ #pragma once -#include "flipper.h" #include "valuemutex.h" #include "pubsub.h" #include "event.h" -#include "m-list.h" +#include <m-list.h> + +#ifdef __cplusplus +extern "C" { +#endif /* == Value composer == @@ -106,3 +109,7 @@ bool write_managed(ValueManager* managed, void* data, size_t len, uint32_t timeo commit_managed works as `release_mutex` but send notify with current value. */ bool commit_managed(ValueManager* managed, void* value); + +#ifdef __cplusplus +} +#endif diff --git a/core/api-basic/valuemutex.c b/core/furi/valuemutex.c index 7679ff9b..2dbd0cc0 100644 --- a/core/api-basic/valuemutex.c +++ b/core/furi/valuemutex.c @@ -1,4 +1,5 @@ #include "valuemutex.h" + #include <string.h> bool init_mutex(ValueMutex* valuemutex, void* value, size_t size) { diff --git a/core/api-basic/valuemutex.h b/core/furi/valuemutex.h index 46084176..df224e1a 100644 --- a/core/api-basic/valuemutex.h +++ b/core/furi/valuemutex.h @@ -1,6 +1,11 @@ #pragma once -#include "flipper.h" +#include <cmsis_os2.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif /* == ValueMutex == @@ -76,6 +81,10 @@ inline static bool read_mutex_block(ValueMutex* valuemutex, void* data, size_t l return read_mutex(valuemutex, data, len, osWaitForever); } +#ifdef __cplusplus +} +#endif + /* Usage example @@ -95,10 +104,7 @@ void provider_app(void* _p) { flapp_exit(NULL); } - if(furi_create("provider/example", (void*)&example_mutex)) { - printf("critical error\n"); - flapp_exit(NULL); - } + furi_record_create("provider/example", (void*)&example_mutex); // we are ready to provide record to other apps flapp_ready(); @@ -123,7 +129,7 @@ void consumer_app(void* _p) { // this app run after flapp_ready call in all requirements app // open mutex value - ValueMutex* counter_mutex = furi_open("provider/example"); + ValueMutex* counter_mutex = furi_record_open("provider/example"); if(counter_mutex == NULL) { printf("critical error\n"); flapp_exit(NULL); diff --git a/core/furi_ac.c b/core/furi_ac.c deleted file mode 100644 index 75cc110d..00000000 --- a/core/furi_ac.c +++ /dev/null @@ -1,190 +0,0 @@ -#include "flipper.h" -#include "api-hal-task.h" - -// TODO: this file contains printf, that not implemented on uC target - -#ifdef FURI_DEBUG -#include <stdio.h> -#endif - -#include <string.h> - -#define INVALID_TASK_ID UINT16_MAX - -static StaticTask_t task_info_buffer[MAX_TASK_COUNT]; -static StackType_t stack_buffer[MAX_TASK_COUNT][DEFAULT_STACK_SIZE / 4]; -static FuriApp task_buffer[MAX_TASK_COUNT]; - -static size_t current_buffer_idx = 0; - -uint16_t furiac_get_task_id_by_name(const char* app_name) { - for(size_t i = 0; i < MAX_TASK_RECORDS; i++) { - if(strcmp(task_buffer[i].name, app_name) == 0) return i; - } - - return INVALID_TASK_ID; -} - -void furiac_wait_libs(const FlipperAppLibrary* libs) { - for(uint8_t i = 0; i < libs->count; i++) { - uint16_t app_id = furiac_get_task_id_by_name(libs->name[i]); - - if(app_id == INVALID_TASK_ID) { -#ifdef FURI_DEBUG - printf("[FURIAC] Invalid library name %s\n", libs->name[i]); -#endif - } else { - while(!task_buffer[app_id].ready) { -#ifdef FURI_DEBUG - printf("[FURIAC] waiting for library \"%s\"\n", libs->name[i]); -#endif - osDelay(50); - } - } - } -} - -// find task pointer by handle -FuriApp* find_task(TaskHandle_t handler) { - FuriApp* res = NULL; - for(size_t i = 0; i < MAX_TASK_COUNT; i++) { - if(task_equal(task_buffer[i].handler, handler)) { - res = &task_buffer[i]; - } - } - - return res; -} - -FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) { -#ifdef FURI_DEBUG - printf("[FURIAC] start %s\n", name); -#endif - - // TODO check first free item (.handler == NULL) and use it - - if(current_buffer_idx >= MAX_TASK_COUNT) { -// max task count exceed -#ifdef FURI_DEBUG - printf("[FURIAC] max task count exceed\n"); -#endif - return NULL; - } - - // application ready - task_buffer[current_buffer_idx].ready = false; - - // create task on static stack memory - task_buffer[current_buffer_idx].handler = xTaskCreateStatic( - (TaskFunction_t)app, - (const char* const)name, - DEFAULT_STACK_SIZE / 4, // freertos specify stack size in words - (void* const)param, - tskIDLE_PRIORITY + 3, // normal priority - stack_buffer[current_buffer_idx], - &task_info_buffer[current_buffer_idx]); - - // save task - task_buffer[current_buffer_idx].application = app; - task_buffer[current_buffer_idx].prev_name = NULL; - task_buffer[current_buffer_idx].prev = NULL; - task_buffer[current_buffer_idx].records_count = 0; - task_buffer[current_buffer_idx].name = name; - - current_buffer_idx++; - - return &task_buffer[current_buffer_idx - 1]; -} - -bool furiac_kill(FuriApp* app) { -#ifdef FURI_DEBUG - printf("[FURIAC] kill %s\n", app->name); -#endif - - // check handler - if(app == NULL || app->handler == NULL) return false; - - // kill task - vTaskDelete(app->handler); - - // cleanup its registry - // TODO realy free memory - app->handler = NULL; - - return true; -} - -void furiac_exit(void* param) { - // get current task handler - FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle()); - - // run prev - if(current_task != NULL) { -#ifdef FURI_DEBUG - printf("[FURIAC] exit %s\n", current_task->name); -#endif - - if(current_task->prev != NULL) { - furiac_start(current_task->prev, current_task->prev_name, param); - } else { -#ifdef FURI_DEBUG - printf("[FURIAC] no prev\n"); -#endif - } - - // cleanup registry - // TODO realy free memory - current_task->handler = NULL; - } - - // kill itself - vTaskDelete(NULL); -} - -void furiac_switch(FlipperApplication app, char* name, void* param) { - // get current task handler - FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle()); - - if(current_task == NULL) { -#ifdef FURI_DEBUG - printf("[FURIAC] no current task found\n"); -#endif - } - -#ifdef FURI_DEBUG - printf("[FURIAC] switch %s to %s\n", current_task->name, name); -#endif - - // run next - FuriApp* next = furiac_start(app, name, param); - - if(next != NULL) { - // save current application pointer as prev - next->prev = current_task->application; - next->prev_name = current_task->name; - - // kill itself - vTaskDelete(NULL); - } -} - -// set task to ready state -void furiac_ready() { - /* - TODO: - Currently i think that better way is to use application name - and restrict applications to "one task per application" - */ - FuriApp* app = find_task(xTaskGetCurrentTaskHandle()); - - if(app == NULL) { -#ifdef FURI_DEBUG - printf("[FURIAC] cannot find task to set ready state\n"); -#endif - } else { -#ifdef FURI_DEBUG - printf("[FURIAC] task is ready\n"); -#endif - app->ready = true; - } -}
\ No newline at end of file diff --git a/core/log.c b/core/log.c deleted file mode 100644 index 3088f425..00000000 --- a/core/log.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _GNU_SOURCE - -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include "log.h" -#include "flipper.h" - -#define PRINT_STR_SIZE 64 - -void fuprintf(FuriRecordSubscriber* f, const char* format, ...) { - char buffer[PRINT_STR_SIZE]; - - va_list args; - va_start(args, format); - vsprintf(buffer, format, args); - va_end(args); - - furi_write(f, buffer, strlen(buffer)); -} - -FuriRecordSubscriber* get_default_log() { - return furi_open_deprecated("tty", false, false, NULL, NULL, NULL); -}
\ No newline at end of file diff --git a/core/log.h b/core/log.h deleted file mode 100644 index 78c3a100..00000000 --- a/core/log.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "flipper.h" - -FuriRecordSubscriber* get_default_log(); -void fuprintf(FuriRecordSubscriber* f, const char* format, ...); diff --git a/core/ring.c b/core/ring.c deleted file mode 100644 index e8fdd767..00000000 --- a/core/ring.c +++ /dev/null @@ -1,138 +0,0 @@ -#include "ring.h" -#include <flipper_v2.h> - -struct Ring { - uint8_t* data; - size_t size; - volatile size_t read_ptr; - volatile size_t write_ptr; -}; - -Ring* ring_alloc(size_t size) { - Ring* ring = furi_alloc(sizeof(Ring)); - ring->size = size + 1; - ring->data = furi_alloc(ring->size); - ring_clear(ring); - return ring; -} - -void ring_free(Ring* ring) { - furi_assert(ring); - free(ring->data); - free(ring); -} - -size_t ring_size(Ring* ring) { - furi_assert(ring); - return ring->size - 1; -} - -inline static size_t ring_read_calculate(Ring* ring, size_t r, size_t w) { - if(w >= r) { - return w - r; - } else { - return ring->size - (r - w); - } -} - -size_t ring_read_space(Ring* ring) { - furi_assert(ring); - - const size_t r = ring->read_ptr; - const size_t w = ring->write_ptr; - - return ring_read_calculate(ring, r, w); -} - -inline static size_t ring_write_calculate(Ring* ring, size_t r, size_t w) { - if(r > w) { - return r - w - 1; - } else { - return ring->size - (r - w); - } -} - -size_t ring_write_space(Ring* ring) { - furi_assert(ring); - - const size_t r = ring->read_ptr; - const size_t w = ring->write_ptr; - - return ring_write_calculate(ring, r, w); -} - -size_t ring_push(Ring* ring, const uint8_t* data, size_t size) { - furi_assert(ring); - furi_assert(data); - - const size_t r = ring->read_ptr; - size_t w = ring->write_ptr; - const size_t write_space = ring_write_calculate(ring, r, w); - - if(write_space == 0) return 0; - - const size_t to_write = size > write_space ? write_space : size; - size_t end, first, second; - - end = w + to_write; - if(end > ring->size) { - first = ring->size - w; - second = end % ring->size; - } else { - first = to_write; - second = 0; - } - - memcpy(ring->data + w, data, first); - w = (w + first) % ring->size; - - if(second) { - memcpy(ring->data + w, data + first, second); - w = (w + second) % ring->size; - } - - ring->write_ptr = w; - - return to_write; -} - -size_t ring_pull(Ring* ring, uint8_t* data, size_t size) { - furi_assert(ring); - furi_assert(data); - - size_t r = ring->read_ptr; - const size_t w = ring->write_ptr; - const size_t read_space = ring_read_calculate(ring, r, w); - - if(read_space == 0) return 0; - - size_t to_read = size > read_space ? read_space : size; - size_t end, first, second; - - end = r + to_read; - if(end > ring->size) { - first = ring->size - r; - second = end % ring->size; - } else { - first = to_read; - second = 0; - } - - memcpy(data, ring->data + r, first); - r = (r + first) % ring->size; - - if(second) { - memcpy(data + first, ring->data + r, second); - r = (r + second) % ring->size; - } - - ring->read_ptr = r; - - return to_read; -} - -void ring_clear(Ring* ring) { - furi_assert(ring); - ring->read_ptr = 0; - ring->write_ptr = 0; -} diff --git a/core/ring.h b/core/ring.h deleted file mode 100644 index 069a81cd..00000000 --- a/core/ring.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include <stdint.h> -#include <string.h> - -typedef struct Ring Ring; - -Ring* ring_alloc(size_t size); - -void ring_free(Ring* ring); - -size_t ring_size(Ring* ring); - -size_t ring_read_space(Ring* ring); - -size_t ring_write_space(Ring* ring); - -size_t ring_push(Ring* ring, const uint8_t* data, size_t size); - -size_t ring_pull(Ring* ring, uint8_t* data, size_t size); - -void ring_clear(Ring* ring); diff --git a/core/tty_uart.c b/core/tty_uart.c deleted file mode 100644 index b748d9c1..00000000 --- a/core/tty_uart.c +++ /dev/null @@ -1,57 +0,0 @@ -#define _GNU_SOURCE -#include <stdio.h> -#include "flipper.h" -#include "main.h" - -extern UART_HandleTypeDef DEBUG_UART; - -void handle_uart_write(const void* data, size_t size, void* ctx) { - HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY); -} - -static ssize_t stdout_write(void* _cookie, const char* buf, size_t n) { - FuriRecordSubscriber* log = pvTaskGetThreadLocalStoragePointer(NULL, 0); - if(log == NULL) { - log = furi_open_deprecated("tty", false, false, NULL, NULL, NULL); - if(log == NULL) { - return -1; - } - vTaskSetThreadLocalStoragePointer(NULL, 0, log); - } - if(buf == 0) { - /* - * This means that we should flush internal buffers. Since we - * don't we just return. (Remember, "handle" == -1 means that all - * handles should be flushed.) - */ - return 0; - } - - furi_write(log, buf, n); - - return n; -} - -bool register_tty_uart() { - if(!furi_create_deprecated("tty", NULL, 0)) { - return false; - } - - if(furi_open_deprecated("tty", false, false, handle_uart_write, NULL, NULL) == NULL) { - return false; - } - - FILE* fp = fopencookie( - NULL, - "w", - (cookie_io_functions_t){ - .read = NULL, - .write = stdout_write, - .seek = NULL, - .close = NULL, - }); - setvbuf(fp, NULL, _IONBF, 0); - stdout = fp; - - return true; -} diff --git a/core/tty_uart.h b/core/tty_uart.h deleted file mode 100644 index 21cdd676..00000000 --- a/core/tty_uart.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include <stdbool.h> - -bool register_tty_uart(); diff --git a/firmware/targets/api-hal-include/api-hal.h b/firmware/targets/api-hal-include/api-hal.h index 6884727f..15b4a414 100644 --- a/firmware/targets/api-hal-include/api-hal.h +++ b/firmware/targets/api-hal-include/api-hal.h @@ -4,6 +4,7 @@ template <unsigned int N> struct STOP_EXTERNING_ME {}; #endif +#include "api-hal-resources.h" #include "api-hal-timebase.h" #include "api-hal-boot.h" #include "api-hal-gpio.h" diff --git a/firmware/targets/f4/Inc/FreeRTOSConfig.h b/firmware/targets/f4/Inc/FreeRTOSConfig.h index a864f60b..9d317e97 100644 --- a/firmware/targets/f4/Inc/FreeRTOSConfig.h +++ b/firmware/targets/f4/Inc/FreeRTOSConfig.h @@ -69,7 +69,7 @@ #define configTICK_RATE_HZ ((TickType_t)1024)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
-#define configTOTAL_HEAP_SIZE ((size_t)40960)
+#define configTOTAL_HEAP_SIZE ((size_t)131072)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configGENERATE_RUN_TIME_STATS 1
#define configUSE_TRACE_FACILITY 1
diff --git a/firmware/targets/f4/Src/app_freertos.c b/firmware/targets/f4/Src/app_freertos.c index 0d16ac20..9dd2fdfb 100644 --- a/firmware/targets/f4/Src/app_freertos.c +++ b/firmware/targets/f4/Src/app_freertos.c @@ -1,66 +1,16 @@ -/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * File Name : app_freertos.c
- * Description : Code for freertos applications
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2020 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
-#include "FreeRTOS.h"
-#include "task.h"
-#include "main.h"
-#include "cmsis_os.h"
-
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN PTD */
-
-/* USER CODE END PTD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN Variables */
-
-/* USER CODE END Variables */
-/* Definitions for app_main */
-osThreadId_t app_mainHandle;
-const osThreadAttr_t app_main_attributes = {
- .name = "app_main",
- .priority = (osPriority_t) osPriorityNormal,
- .stack_size = 1024 * 4
+#include <cmsis_os2.h>
+#include <FreeRTOS.h>
+#include <task.h>
+#include <main.h>
+
+osThreadId_t systemdHandle;
+const osThreadAttr_t systemd_attributes = {
+ .name = "systemd",
+ .priority = (osPriority_t) osPriorityNormal,
+ .stack_size = 1024 * 4
};
-/* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN FunctionPrototypes */
-
-/* USER CODE END FunctionPrototypes */
-
-void app(void *argument);
+void systemd(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
@@ -70,107 +20,32 @@ unsigned long getRunTimeCounterValue(void); void vApplicationIdleHook(void);
void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName);
-/* USER CODE BEGIN 1 */
-/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
-__weak void configureTimerForRunTimeStats(void)
-{
-
+__weak void configureTimerForRunTimeStats(void) {
}
-__weak unsigned long getRunTimeCounterValue(void)
-{
-return 0;
+__weak unsigned long getRunTimeCounterValue(void) {
+ return 0;
}
-/* USER CODE END 1 */
-/* USER CODE BEGIN 2 */
-__weak void vApplicationIdleHook( void )
-{
- /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
- to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
- task. It is essential that code added to this hook function never attempts
- to block in any way (for example, call xQueueReceive() with a block time
- specified, or call vTaskDelay()). If the application makes use of the
- vTaskDelete() API function (as this demo application does) then it is also
- important that vApplicationIdleHook() is permitted to return to its calling
- function, because it is the responsibility of the idle task to clean up
- memory allocated by the kernel to any task that has since been deleted. */
+__weak void vApplicationIdleHook( void ) {
+ /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
+ to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
+ task. It is essential that code added to this hook function never attempts
+ to block in any way (for example, call xQueueReceive() with a block time
+ specified, or call vTaskDelay()). If the application makes use of the
+ vTaskDelete() API function (as this demo application does) then it is also
+ important that vApplicationIdleHook() is permitted to return to its calling
+ function, because it is the responsibility of the idle task to clean up
+ memory allocated by the kernel to any task that has since been deleted. */
}
-/* USER CODE END 2 */
-/* USER CODE BEGIN 4 */
-__weak void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
-{
- /* Run time stack overflow checking is performed if
- configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
- called if a stack overflow is detected. */
+__weak void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName) {
+ /* Run time stack overflow checking is performed if
+ configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
+ called if a stack overflow is detected. */
}
-/* USER CODE END 4 */
-/* USER CODE BEGIN VPORT_SUPPORT_TICKS_AND_SLEEP */
-/* USER CODE END VPORT_SUPPORT_TICKS_AND_SLEEP */
-/**
- * @brief FreeRTOS initialization
- * @param None
- * @retval None
- */
void MX_FREERTOS_Init(void) {
- /* USER CODE BEGIN Init */
-
- /* USER CODE END Init */
-
- /* USER CODE BEGIN RTOS_MUTEX */
- /* add mutexes, ... */
- /* USER CODE END RTOS_MUTEX */
-
- /* USER CODE BEGIN RTOS_SEMAPHORES */
- /* add semaphores, ... */
- /* USER CODE END RTOS_SEMAPHORES */
-
- /* USER CODE BEGIN RTOS_TIMERS */
- /* start timers, add new ones, ... */
- /* USER CODE END RTOS_TIMERS */
-
- /* USER CODE BEGIN RTOS_QUEUES */
- /* add queues, ... */
- /* USER CODE END RTOS_QUEUES */
-
- /* Create the thread(s) */
- /* creation of app_main */
- app_mainHandle = osThreadNew(app, NULL, &app_main_attributes);
-
- /* USER CODE BEGIN RTOS_THREADS */
- /* add threads, ... */
- /* USER CODE END RTOS_THREADS */
-
- /* USER CODE BEGIN RTOS_EVENTS */
- /* add events, ... */
- /* USER CODE END RTOS_EVENTS */
-
-}
-
-/* USER CODE BEGIN Header_app */
-/**
- * @brief Function implementing the app_main thread.
- * @param argument: Not used
- * @retval None
- */
-/* USER CODE END Header_app */
-__weak void app(void *argument)
-{
- /* USER CODE BEGIN app */
- /* Infinite loop */
- for(;;)
- {
- osDelay(1);
- }
- /* USER CODE END app */
+ systemdHandle = osThreadNew(systemd, NULL, &systemd_attributes);
}
-
-/* Private application code --------------------------------------------------*/
-/* USER CODE BEGIN Application */
-
-/* USER CODE END Application */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/firmware/targets/f4/Src/spi.c b/firmware/targets/f4/Src/spi.c index 2034a3a6..d1fd0669 100644 --- a/firmware/targets/f4/Src/spi.c +++ b/firmware/targets/f4/Src/spi.c @@ -19,6 +19,7 @@ /* Includes ------------------------------------------------------------------*/
#include "spi.h"
+#include <cmsis_os2.h>
/* USER CODE BEGIN 0 */
void Enable_SPI(SPI_HandleTypeDef* spi);
diff --git a/firmware/targets/f4/Src/target-resources.c b/firmware/targets/f4/Src/target-resources.c index fdc68753..e14619e6 100644 --- a/firmware/targets/f4/Src/target-resources.c +++ b/firmware/targets/f4/Src/target-resources.c @@ -1,5 +1,5 @@ #include "main.h" -#include "flipper_v2.h" +#include <furi.h> const bool input_invert[GPIO_INPUT_PINS_COUNT] = { true, // {BUTTON_UP_GPIO_Port, BUTTON_UP_Pin}, diff --git a/firmware/targets/f4/api-hal/api-hal-resources.c b/firmware/targets/f4/api-hal/api-hal-resources.c index d4e2a2fd..d65d0fb6 100644 --- a/firmware/targets/f4/api-hal/api-hal-resources.c +++ b/firmware/targets/f4/api-hal/api-hal-resources.c @@ -1,5 +1,5 @@ #include "main.h" -#include "flipper_v2.h" +#include <furi.h> const GpioPin input_gpio[GPIO_INPUT_PINS_COUNT] = { {BUTTON_UP_GPIO_Port, BUTTON_UP_Pin}, diff --git a/firmware/targets/f4/api-hal/api-hal-resources.h b/firmware/targets/f4/api-hal/api-hal-resources.h index e095827b..eaedc85b 100644 --- a/firmware/targets/f4/api-hal/api-hal-resources.h +++ b/firmware/targets/f4/api-hal/api-hal-resources.h @@ -1,6 +1,6 @@ #pragma once #include "main.h" -#include "flipper_v2.h" +#include <furi.h> #define DEBOUNCE_TICKS 10 #define GPIO_INPUT_PINS_COUNT 6 diff --git a/firmware/targets/f4/api-hal/api-hal-spi.c b/firmware/targets/f4/api-hal/api-hal-spi.c index 23aacc8f..e0ddc99f 100644 --- a/firmware/targets/f4/api-hal/api-hal-spi.c +++ b/firmware/targets/f4/api-hal/api-hal-spi.c @@ -1,5 +1,5 @@ #include "api-hal-spi.h" -#include <cmsis_os.h> +#include <cmsis_os2.h> #include <stdbool.h> #include <string.h> diff --git a/firmware/targets/f4/api-hal/api-hal-task.c b/firmware/targets/f4/api-hal/api-hal-task.c index 263bc797..48df9fa7 100644 --- a/firmware/targets/f4/api-hal/api-hal-task.c +++ b/firmware/targets/f4/api-hal/api-hal-task.c @@ -52,8 +52,3 @@ bool task_is_isr_context(void) { return IS_IRQ(); } - -bool task_equal(TaskHandle_t a, TaskHandle_t b) { - if(a == NULL || b == NULL) return false; - return a == b; -}
\ No newline at end of file diff --git a/firmware/targets/f4/api-hal/api-hal-task.h b/firmware/targets/f4/api-hal/api-hal-task.h index 84901a72..8b157233 100644 --- a/firmware/targets/f4/api-hal/api-hal-task.h +++ b/firmware/targets/f4/api-hal/api-hal-task.h @@ -1,6 +1,6 @@ #pragma once #include "main.h" -#include <cmsis_os.h> +#include <cmsis_os2.h> #include <stdbool.h> // Task stack size in bytes @@ -9,5 +9,4 @@ // Max system tasks count #define MAX_TASK_COUNT 14 -bool task_equal(TaskHandle_t a, TaskHandle_t b); bool task_is_isr_context(void); diff --git a/firmware/targets/f4/api-hal/api-hal-vcp.c b/firmware/targets/f4/api-hal/api-hal-vcp.c index bf98d7ef..09e2bb44 100644 --- a/firmware/targets/f4/api-hal/api-hal-vcp.c +++ b/firmware/targets/f4/api-hal/api-hal-vcp.c @@ -1,6 +1,6 @@ #include <api-hal-vcp.h> #include <usbd_cdc_if.h> -#include <flipper_v2.h> +#include <furi.h> #include <stream_buffer.h> #define API_HAL_VCP_RX_BUFFER_SIZE 600 diff --git a/firmware/targets/f4/api-hal/api-interrupts.c b/firmware/targets/f4/api-hal/api-interrupts.c index 24e62130..37f1a10b 100644 --- a/firmware/targets/f4/api-hal/api-interrupts.c +++ b/firmware/targets/f4/api-hal/api-interrupts.c @@ -1,4 +1,7 @@ #include "api-hal/api-interrupt-mgr.h" +#include <main.h> + +extern void api_interrupt_call(InterruptType type, void* hw); /* interrupts */ void HAL_COMP_TriggerCallback(COMP_HandleTypeDef* hcomp) { diff --git a/firmware/targets/f4/ble-glue/app_conf.h b/firmware/targets/f4/ble-glue/app_conf.h index 3d785053..222f0cfe 100644 --- a/firmware/targets/f4/ble-glue/app_conf.h +++ b/firmware/targets/f4/ble-glue/app_conf.h @@ -261,7 +261,7 @@ * When set to 1, the low power mode is enable * When set to 0, the device stays in RUN mode */ -#define CFG_LPM_SUPPORTED 0 +#define CFG_LPM_SUPPORTED 1 /****************************************************************************** * Timer Server diff --git a/firmware/targets/f4/ble-glue/tl_dbg_conf.h b/firmware/targets/f4/ble-glue/tl_dbg_conf.h index bc4bf4d6..3966c9ce 100644 --- a/firmware/targets/f4/ble-glue/tl_dbg_conf.h +++ b/firmware/targets/f4/ble-glue/tl_dbg_conf.h @@ -41,14 +41,14 @@ extern UART_HandleTypeDef DEBUG_UART; * The raw data output is the hci binary packet format as specified by the BT specification * */ #define TL_SHCI_CMD_DBG_EN 1 /* Reports System commands sent to CPU2 and the command response */ -#define TL_SHCI_CMD_DBG_RAW_EN 1 /* Reports raw data System commands sent to CPU2 and the command response */ +#define TL_SHCI_CMD_DBG_RAW_EN 0 /* Reports raw data System commands sent to CPU2 and the command response */ #define TL_SHCI_EVT_DBG_EN 1 /* Reports System Asynchronous Events received from CPU2 */ -#define TL_SHCI_EVT_DBG_RAW_EN 1 /* Reports raw data System Asynchronous Events received from CPU2 */ +#define TL_SHCI_EVT_DBG_RAW_EN 0 /* Reports raw data System Asynchronous Events received from CPU2 */ #define TL_HCI_CMD_DBG_EN 1 /* Reports BLE command sent to CPU2 and the command response */ -#define TL_HCI_CMD_DBG_RAW_EN 1 /* Reports raw data BLE command sent to CPU2 and the command response */ +#define TL_HCI_CMD_DBG_RAW_EN 0 /* Reports raw data BLE command sent to CPU2 and the command response */ #define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */ -#define TL_HCI_EVT_DBG_RAW_EN 1 /* Reports raw data BLE Asynchronous Events received from CPU2 */ +#define TL_HCI_EVT_DBG_RAW_EN 0 /* Reports raw data BLE Asynchronous Events received from CPU2 */ #define TL_MM_DBG_EN 1 /* Reports the informations of the buffer released to CPU2 */ diff --git a/firmware/targets/local/Inc/cmsis_os.h b/firmware/targets/local/Inc/cmsis_os.h deleted file mode 100644 index 12019bf8..00000000 --- a/firmware/targets/local/Inc/cmsis_os.h +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -#include "main.h" -#include <stdbool.h> -#include <pthread.h> - -void osDelay(uint32_t ms); - -// some FreeRTOS types -typedef void (*TaskFunction_t)(void*); -typedef size_t UBaseType_t; -typedef uint32_t StackType_t; -typedef uint32_t StaticTask_t; -typedef pthread_t* TaskHandle_t; - -typedef enum { - SemaphoreTypeMutex, - SemaphoreTypeCounting, -} SemaphoreType; -typedef struct { - SemaphoreType type; - pthread_mutex_t mutex; - uint8_t take_counter; - uint8_t give_counter; -} StaticSemaphore_t; -typedef StaticSemaphore_t* SemaphoreHandle_t; - -typedef uint32_t StaticQueue_t; -typedef StaticQueue_t* QueueHandle_t; - -#define portMAX_DELAY -1 - -typedef enum { pdTRUE = 1, pdFALSE = 0 } BaseType_t; - -typedef int32_t TickType_t; - -#define tskIDLE_PRIORITY 0 - -TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode, - const char* const pcName, - const uint32_t ulStackDepth, - void* const pvParameters, - UBaseType_t uxPriority, - StackType_t* const puxStackBuffer, - StaticTask_t* const pxTaskBuffer); - -void vTaskDelete(TaskHandle_t xTask); -TaskHandle_t xTaskGetCurrentTaskHandle(void); -SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer); - -QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength, - UBaseType_t uxItemSize, - uint8_t* pucQueueStorageBuffer, - StaticQueue_t* pxQueueBuffer); - -SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount, - UBaseType_t uxInitialCount, - StaticSemaphore_t* pxSemaphoreBuffer); -BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait); -BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore); - -BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait); - -BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait); - -void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex); -void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue); - -QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize); - -typedef struct { - const char *name; ///< name of the mutex - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osMutexAttr_t; - -typedef SemaphoreHandle_t osMutexId_t; - -osMutexId_t osMutexNew(const osMutexAttr_t *attr); - -/// Status code values returned by CMSIS-RTOS functions. -typedef enum { - osOK = 0, ///< Operation completed successfully. - osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits. - osErrorTimeout = -2, ///< Operation not completed within the timeout period. - osErrorResource = -3, ///< Resource not available. - osErrorParameter = -4, ///< Parameter error. - osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. - osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. - osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osStatus_t; - -osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); -osStatus_t osMutexRelease (osMutexId_t mutex_id); -osStatus_t osMutexDelete (osMutexId_t mutex_id); - -#define osWaitForever portMAX_DELAY - -typedef StaticSemaphore_t osSemaphoreDef_t; -typedef SemaphoreHandle_t osSemaphoreId_t; -typedef struct {} osSemaphoreAttr_t; - -osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); -osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout); -osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id); -osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id); diff --git a/firmware/targets/local/Inc/cmsis_os2.h b/firmware/targets/local/Inc/cmsis_os2.h deleted file mode 100644 index 8633b6bc..00000000 --- a/firmware/targets/local/Inc/cmsis_os2.h +++ /dev/null @@ -1 +0,0 @@ -#include "cmsis_os.h"
\ No newline at end of file diff --git a/firmware/targets/local/Inc/flipper_hal.h b/firmware/targets/local/Inc/flipper_hal.h deleted file mode 100644 index 343ade52..00000000 --- a/firmware/targets/local/Inc/flipper_hal.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -Flipper devices inc. - -GPIO and HAL implementations -*/ - -#pragma once - -#include <stdio.h> -#include <stdbool.h> -#include "main.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define GPIOA "PA" -#define GPIOB "PB" -#define GPIOC "PC" -#define GPIOD "PD" -#define GPIOE "PE" - -#define GPIO_PIN_0 0 -#define GPIO_PIN_1 1 -#define GPIO_PIN_2 2 -#define GPIO_PIN_3 3 -#define GPIO_PIN_4 4 -#define GPIO_PIN_5 5 -#define GPIO_PIN_6 6 -#define GPIO_PIN_7 7 -#define GPIO_PIN_8 8 -#define GPIO_PIN_9 9 -#define GPIO_PIN_10 10 -#define GPIO_PIN_11 11 -#define GPIO_PIN_12 12 -#define GPIO_PIN_13 13 -#define GPIO_PIN_14 14 -#define GPIO_PIN_15 15 - -#define DISPLAY_RST_GPIO_Port "DISPLAY RST" -#define DISPLAY_DI_Pin 0 - -#define DISPLAY_DI_GPIO_Port "DISPLAY DI" -#define DISPLAY_RST_Pin 0 - -#define DISPLAY_CS_GPIO_Port "DISPLAY CS" -#define DISPLAY_CS_Pin 0 - -#define DISPLAY_BACKLIGHT_GPIO_Port "BACKLIGHT" -#define DISPLAY_BACKLIGHT_Pin 0 - -typedef const char* SPI_HandleTypeDef; - -typedef uint32_t HAL_StatusTypeDef; - -HAL_StatusTypeDef -HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t Size, uint32_t Timeout); - -#ifdef __cplusplus -} -#endif diff --git a/firmware/targets/local/Inc/heap.h b/firmware/targets/local/Inc/heap.h deleted file mode 100644 index 45c883eb..00000000 --- a/firmware/targets/local/Inc/heap.h +++ /dev/null @@ -1,37 +0,0 @@ -#include <stdbool.h> -#include <stdlib.h> -#include <stdint.h> -#include <cmsis_os.h> - -#define configTOTAL_HEAP_SIZE ((size_t)(8192 * 16)) -#define configAPPLICATION_ALLOCATED_HEAP 0 -#define portBYTE_ALIGNMENT 8 - -#if portBYTE_ALIGNMENT == 8 -#define portBYTE_ALIGNMENT_MASK (0x0007) -#endif - -/* No test marker by default. */ -#ifndef mtCOVERAGE_TEST_MARKER -#define mtCOVERAGE_TEST_MARKER() -#endif - -/* No tracing by default. */ -#ifndef traceMALLOC -#define traceMALLOC(pvReturn, xWantedSize) -#endif - -/* No tracing by default. */ -#ifndef traceFREE -#define traceFREE(pvReturn, xBlockSize) -#endif - -/* No assert by default. */ -#ifndef configASSERT -#define configASSERT(var) -#endif - -bool prvHeapInit(void); - -void acquire_memalloc_mutex(); -void release_memalloc_mutex();
\ No newline at end of file diff --git a/firmware/targets/local/Inc/input_priv.h b/firmware/targets/local/Inc/input_priv.h deleted file mode 100644 index eed84f4b..00000000 --- a/firmware/targets/local/Inc/input_priv.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef __INPUT_PRIV_H -#define __INPUT_PRIV_H - -#include "main.h" -#include "flipper_hal.h" - -#define DEBOUNCE_TICKS 10 - -const GpioPin input_gpio[] = { - {"Up", 0}, - {"Down", 0}, - {"Right", 0}, - {"Left", 0}, - {"Ok", 0}, - {"Back", 0}, - {"Charg", 0} -}; - -const bool input_invert[] = { - false, // {BUTTON_UP_GPIO_Port, BUTTON_UP_Pin}, - false, // {BUTTON_DOWN_GPIO_Port, BUTTON_DOWN_Pin}, - false, // {BUTTON_RIGHT_GPIO_Port, BUTTON_RIGHT_Pin}, - false, // {BUTTON_LEFT_GPIO_Port, BUTTON_LEFT_Pin}, - false, // {BUTTON_OK_GPIO_Port, BUTTON_OK_Pin}, - false, // {BUTTON_BACK_GPIO_Port, BUTTON_BACK_Pin}, - true, // {CHRG_GPIO_Port, CHRG_Pin} -}; - -#endif /* __INPUT_PRIV_H */ diff --git a/firmware/targets/local/Inc/main.h b/firmware/targets/local/Inc/main.h deleted file mode 100644 index b862dea2..00000000 --- a/firmware/targets/local/Inc/main.h +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdint.h> -#include <stdlib.h> -#include <limits.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define HAL_MAX_DELAY INT_MAX - -typedef uint32_t UART_HandleTypeDef; -uint16_t -HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms); - -typedef uint32_t TIM_HandleTypeDef; - -#define LED_RED_Pin 1 -#define LED_RED_GPIO_Port "Red:" -#define LED_GREEN_Pin 1 -#define LED_GREEN_GPIO_Port "Green:" -#define LED_BLUE_Pin 1 -#define LED_BLUE_GPIO_Port "Blue:" - -#ifdef __cplusplus -} -#endif diff --git a/firmware/targets/local/Src/flipper_hal.c b/firmware/targets/local/Src/flipper_hal.c deleted file mode 100644 index 65392da9..00000000 --- a/firmware/targets/local/Src/flipper_hal.c +++ /dev/null @@ -1,22 +0,0 @@ -/* -Flipper devices inc. - -GPIO and HAL implementations -*/ - -#include "main.h" -#include "flipper_hal.h" -#include <stdio.h> - -HAL_StatusTypeDef -HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t size, uint32_t Timeout) { - printf("[SPI] write %d to %s: ", size, *hspi); - for(size_t i = 0; i < size; i++) { - printf("%02X ", pData[i]); - } - printf("\n"); - - return 0; -} - -SPI_HandleTypeDef hspi1 = "spi1"; diff --git a/firmware/targets/local/Src/heap_4.c b/firmware/targets/local/Src/heap_4.c deleted file mode 100644 index 04abcbf0..00000000 --- a/firmware/targets/local/Src/heap_4.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - * FreeRTOS Kernel V10.2.1 - * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ - -/* - * A sample implementation of pvPortMalloc() and vPortFree() that combines - * (coalescences) adjacent memory blocks as they are freed, and in so doing - * limits memory fragmentation. - * - * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the - * memory management pages of http://www.FreeRTOS.org for more information. - */ -#include "heap.h" - -osMutexId_t heap_managment_mutex = NULL; - -/* Block sizes must not get too small. */ -#define heapMINIMUM_BLOCK_SIZE ((size_t)(xHeapStructSize << 1)) - -/* Assumes 8bit bytes! */ -#define heapBITS_PER_BYTE ((size_t)8) - -/* Allocate the memory for the heap. */ -#if(configAPPLICATION_ALLOCATED_HEAP == 1) -/* The application writer has already defined the array used for the RTOS - heap - probably so it can be placed in a special segment or address. */ -extern uint8_t ucHeap[configTOTAL_HEAP_SIZE]; -#else -static uint8_t ucHeap[configTOTAL_HEAP_SIZE]; -#endif /* configAPPLICATION_ALLOCATED_HEAP */ - -/* Define the linked list structure. This is used to link free blocks in order -of their memory address. */ -typedef struct A_BLOCK_LINK { - struct A_BLOCK_LINK* pxNextFreeBlock; /*<< The next free block in the list. */ - size_t xBlockSize; /*<< The size of the free block. */ -} BlockLink_t; -/*-----------------------------------------------------------*/ - -/* - * Inserts a block of memory that is being freed into the correct position in - * the list of free memory blocks. The block being freed will be merged with - * the block in front it and/or the block behind it if the memory blocks are - * adjacent to each other. - */ -static void prvInsertBlockIntoFreeList(BlockLink_t* pxBlockToInsert); - -// this function is not thread-safe, so it must be called in single thread context -bool prvHeapInit(void); - -/*-----------------------------------------------------------*/ - -/* The size of the structure placed at the beginning of each allocated memory -block must by correctly byte aligned. */ -static const size_t xHeapStructSize = (sizeof(BlockLink_t) + ((size_t)(portBYTE_ALIGNMENT - 1))) & - ~((size_t)portBYTE_ALIGNMENT_MASK); - -/* Create a couple of list links to mark the start and end of the list. */ -static BlockLink_t xStart, *pxEnd = NULL; - -/* Keeps track of the number of free bytes remaining, but says nothing about -fragmentation. */ -static size_t xFreeBytesRemaining = 0U; -static size_t xMinimumEverFreeBytesRemaining = 0U; - -/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize -member of an BlockLink_t structure is set then the block belongs to the -application. When the bit is free the block is still part of the free heap -space. */ -static size_t xBlockAllocatedBit = 0; - -/*-----------------------------------------------------------*/ - -void* pvPortMalloc(size_t xWantedSize) { - BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink; - void* pvReturn = NULL; - - acquire_memalloc_mutex(); - { - /* If this is the first call to malloc then the heap will require - initialisation to setup the list of free blocks. */ - if(pxEnd == NULL) { - prvHeapInit(); - } else { - mtCOVERAGE_TEST_MARKER(); - } - - /* Check the requested block size is not so large that the top bit is - set. The top bit of the block size member of the BlockLink_t structure - is used to determine who owns the block - the application or the - kernel, so it must be free. */ - if((xWantedSize & xBlockAllocatedBit) == 0) { - /* The wanted size is increased so it can contain a BlockLink_t - structure in addition to the requested amount of bytes. */ - if(xWantedSize > 0) { - xWantedSize += xHeapStructSize; - - /* Ensure that blocks are always aligned to the required number - of bytes. */ - if((xWantedSize & portBYTE_ALIGNMENT_MASK) != 0x00) { - /* Byte alignment required. */ - xWantedSize += (portBYTE_ALIGNMENT - (xWantedSize & portBYTE_ALIGNMENT_MASK)); - configASSERT((xWantedSize & portBYTE_ALIGNMENT_MASK) == 0); - } else { - mtCOVERAGE_TEST_MARKER(); - } - } else { - mtCOVERAGE_TEST_MARKER(); - } - - if((xWantedSize > 0) && (xWantedSize <= xFreeBytesRemaining)) { - /* Traverse the list from the start (lowest address) block until - one of adequate size is found. */ - pxPreviousBlock = &xStart; - pxBlock = xStart.pxNextFreeBlock; - while((pxBlock->xBlockSize < xWantedSize) && (pxBlock->pxNextFreeBlock != NULL)) { - pxPreviousBlock = pxBlock; - pxBlock = pxBlock->pxNextFreeBlock; - } - - /* If the end marker was reached then a block of adequate size - was not found. */ - if(pxBlock != pxEnd) { - /* Return the memory space pointed to - jumping over the - BlockLink_t structure at its start. */ - pvReturn = - (void*)(((uint8_t*)pxPreviousBlock->pxNextFreeBlock) + xHeapStructSize); - - /* This block is being returned for use so must be taken out - of the list of free blocks. */ - pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; - - /* If the block is larger than required it can be split into - two. */ - if((pxBlock->xBlockSize - xWantedSize) > heapMINIMUM_BLOCK_SIZE) { - /* This block is to be split into two. Create a new - block following the number of bytes requested. The void - cast is used to prevent byte alignment warnings from the - compiler. */ - pxNewBlockLink = (void*)(((uint8_t*)pxBlock) + xWantedSize); - configASSERT((((size_t)pxNewBlockLink) & portBYTE_ALIGNMENT_MASK) == 0); - - /* Calculate the sizes of two blocks split from the - single block. */ - pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; - pxBlock->xBlockSize = xWantedSize; - - /* Insert the new block into the list of free blocks. */ - prvInsertBlockIntoFreeList(pxNewBlockLink); - } else { - mtCOVERAGE_TEST_MARKER(); - } - - xFreeBytesRemaining -= pxBlock->xBlockSize; - - if(xFreeBytesRemaining < xMinimumEverFreeBytesRemaining) { - xMinimumEverFreeBytesRemaining = xFreeBytesRemaining; - } else { - mtCOVERAGE_TEST_MARKER(); - } - - /* The block is being returned - it is allocated and owned - by the application and has no "next" block. */ - pxBlock->xBlockSize |= xBlockAllocatedBit; - pxBlock->pxNextFreeBlock = NULL; - } else { - mtCOVERAGE_TEST_MARKER(); - } - } else { - mtCOVERAGE_TEST_MARKER(); - } - } else { - mtCOVERAGE_TEST_MARKER(); - } - - traceMALLOC(pvReturn, xWantedSize); - } - release_memalloc_mutex(); - -#if(configUSE_MALLOC_FAILED_HOOK == 1) - { - if(pvReturn == NULL) { - extern void vApplicationMallocFailedHook(void); - vApplicationMallocFailedHook(); - } else { - mtCOVERAGE_TEST_MARKER(); - } - } -#endif - - configASSERT((((size_t)pvReturn) & (size_t)portBYTE_ALIGNMENT_MASK) == 0); - return pvReturn; -} -/*-----------------------------------------------------------*/ - -void vPortFree(void* pv) { - uint8_t* puc = (uint8_t*)pv; - BlockLink_t* pxLink; - - if(pv != NULL) { - /* The memory being freed will have an BlockLink_t structure immediately - before it. */ - puc -= xHeapStructSize; - - /* This casting is to keep the compiler from issuing warnings. */ - pxLink = (void*)puc; - - /* Check the block is actually allocated. */ - configASSERT((pxLink->xBlockSize & xBlockAllocatedBit) != 0); - configASSERT(pxLink->pxNextFreeBlock == NULL); - - if((pxLink->xBlockSize & xBlockAllocatedBit) != 0) { - if(pxLink->pxNextFreeBlock == NULL) { - /* The block is being returned to the heap - it is no longer - allocated. */ - pxLink->xBlockSize &= ~xBlockAllocatedBit; - - acquire_memalloc_mutex(); - { - /* Add this block to the list of free blocks. */ - xFreeBytesRemaining += pxLink->xBlockSize; - traceFREE(pv, pxLink->xBlockSize); - prvInsertBlockIntoFreeList(((BlockLink_t*)pxLink)); - } - release_memalloc_mutex(); - } else { - mtCOVERAGE_TEST_MARKER(); - } - } else { - mtCOVERAGE_TEST_MARKER(); - } - } -} -/*-----------------------------------------------------------*/ - -size_t xPortGetFreeHeapSize(void) { - return xFreeBytesRemaining; -} -/*-----------------------------------------------------------*/ - -size_t xPortGetMinimumEverFreeHeapSize(void) { - return xMinimumEverFreeBytesRemaining; -} -/*-----------------------------------------------------------*/ - -void vPortInitialiseBlocks(void) { - /* This just exists to keep the linker quiet. */ -} -/*-----------------------------------------------------------*/ - -bool prvHeapInit(void) { - BlockLink_t* pxFirstFreeBlock; - uint8_t* pucAlignedHeap; - size_t uxAddress; - size_t xTotalHeapSize = configTOTAL_HEAP_SIZE; - - /* Ensure the heap starts on a correctly aligned boundary. */ - uxAddress = (size_t)ucHeap; - - if((uxAddress & portBYTE_ALIGNMENT_MASK) != 0) { - uxAddress += (portBYTE_ALIGNMENT - 1); - uxAddress &= ~((size_t)portBYTE_ALIGNMENT_MASK); - xTotalHeapSize -= uxAddress - (size_t)ucHeap; - } - - pucAlignedHeap = (uint8_t*)uxAddress; - - /* xStart is used to hold a pointer to the first item in the list of free - blocks. The void cast is used to prevent compiler warnings. */ - xStart.pxNextFreeBlock = (void*)pucAlignedHeap; - xStart.xBlockSize = (size_t)0; - - /* pxEnd is used to mark the end of the list of free blocks and is inserted - at the end of the heap space. */ - uxAddress = ((size_t)pucAlignedHeap) + xTotalHeapSize; - uxAddress -= xHeapStructSize; - uxAddress &= ~((size_t)portBYTE_ALIGNMENT_MASK); - pxEnd = (void*)uxAddress; - pxEnd->xBlockSize = 0; - pxEnd->pxNextFreeBlock = NULL; - - /* To start with there is a single free block that is sized to take up the - entire heap space, minus the space taken by pxEnd. */ - pxFirstFreeBlock = (void*)pucAlignedHeap; - pxFirstFreeBlock->xBlockSize = uxAddress - (size_t)pxFirstFreeBlock; - pxFirstFreeBlock->pxNextFreeBlock = pxEnd; - - /* Only one block exists - and it covers the entire usable heap space. */ - xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; - xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; - - /* Work out the position of the top bit in a size_t variable. */ - xBlockAllocatedBit = ((size_t)1) << ((sizeof(size_t) * heapBITS_PER_BYTE) - 1); - - // now we can use malloc, so we init heap managment mutex - const osMutexAttr_t heap_managment_mutext_attr = { - .name = NULL, .attr_bits = 0, .cb_mem = NULL, .cb_size = 0U}; - - heap_managment_mutex = osMutexNew(&heap_managment_mutext_attr); - - return heap_managment_mutex != NULL; -} -/*-----------------------------------------------------------*/ - -static void prvInsertBlockIntoFreeList(BlockLink_t* pxBlockToInsert) { - BlockLink_t* pxIterator; - uint8_t* puc; - - /* Iterate through the list until a block is found that has a higher address - than the block being inserted. */ - for(pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; - pxIterator = pxIterator->pxNextFreeBlock) { - /* Nothing to do here, just iterate to the right position. */ - } - - /* Do the block being inserted, and the block it is being inserted after - make a contiguous block of memory? */ - puc = (uint8_t*)pxIterator; - if((puc + pxIterator->xBlockSize) == (uint8_t*)pxBlockToInsert) { - pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; - pxBlockToInsert = pxIterator; - } else { - mtCOVERAGE_TEST_MARKER(); - } - - /* Do the block being inserted, and the block it is being inserted before - make a contiguous block of memory? */ - puc = (uint8_t*)pxBlockToInsert; - if((puc + pxBlockToInsert->xBlockSize) == (uint8_t*)pxIterator->pxNextFreeBlock) { - if(pxIterator->pxNextFreeBlock != pxEnd) { - /* Form one big block from the two blocks. */ - pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; - pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; - } else { - pxBlockToInsert->pxNextFreeBlock = pxEnd; - } - } else { - pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; - } - - /* If the block being inserted plugged a gab, so was merged with the block - before and the block after, then it's pxNextFreeBlock pointer will have - already been set, and should not be set here as that would make it point - to itself. */ - if(pxIterator != pxBlockToInsert) { - pxIterator->pxNextFreeBlock = pxBlockToInsert; - } else { - mtCOVERAGE_TEST_MARKER(); - } -} - -/* -at first run (heap init) it not work properly and prvHeapInit -is not thread-safe. But then we init mutex or die -*/ -void acquire_memalloc_mutex() { - if(heap_managment_mutex != NULL) { - osMutexAcquire(heap_managment_mutex, osWaitForever); - } -} - -void release_memalloc_mutex() { - if(heap_managment_mutex != NULL) { - osMutexRelease(heap_managment_mutex); - } -}
\ No newline at end of file diff --git a/firmware/targets/local/Src/lo_hal.c b/firmware/targets/local/Src/lo_hal.c deleted file mode 100644 index b1d3106d..00000000 --- a/firmware/targets/local/Src/lo_hal.c +++ /dev/null @@ -1,21 +0,0 @@ -/* -Flipper devices inc. - -Dummy hal for local fw build -*/ - -#include <stdio.h> -#include "main.h" -#include <unistd.h> - -UART_HandleTypeDef DEBUG_UART = 0; - -uint16_t -HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms) { - uint16_t res = write(1, (const char*)bufer, size); - return res; -} - -uint8_t BSP_SD_Init() { - return 0; -} diff --git a/firmware/targets/local/Src/lo_os.c b/firmware/targets/local/Src/lo_os.c deleted file mode 100644 index 7a8e51ea..00000000 --- a/firmware/targets/local/Src/lo_os.c +++ /dev/null @@ -1,313 +0,0 @@ -#include "cmsis_os.h" -#include <unistd.h> -#include <stdio.h> -#include <pthread.h> -#include <errno.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/msg.h> - -void osDelay(uint32_t ms) { - // printf("[DELAY] %d ms\n", ms); - usleep(ms * 1000); -} - -// temporary struct to pass function ptr and param to wrapper -typedef struct { - TaskFunction_t func; - void* param; -} PthreadTask; - -void* pthread_wrapper(void* p) { - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0x00); - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0x00); - - PthreadTask* task = (PthreadTask*)p; - - task->func(task->param); - - return NULL; -} - -TaskHandle_t xTaskCreateStatic( - TaskFunction_t pxTaskCode, - const char* const pcName, - const uint32_t ulStackDepth, - void* const pvParameters, - UBaseType_t uxPriority, - StackType_t* const puxStackBuffer, - StaticTask_t* const pxTaskBuffer) { - TaskHandle_t thread = malloc(sizeof(TaskHandle_t)); - PthreadTask* task = malloc(sizeof(PthreadTask)); - - task->func = pxTaskCode; - task->param = pvParameters; - - pthread_create(thread, NULL, pthread_wrapper, (void*)task); - - return thread; -} - -void vTaskDelete(TaskHandle_t xTask) { - if(xTask == NULL) { - // kill itself - pthread_exit(NULL); - } - - // maybe thread already join - if(pthread_kill(*xTask, 0) == ESRCH) return; - - // send thread_child signal to stop it сигнал, который ее завершает - pthread_cancel(*xTask); - - // wait for join and close descriptor - pthread_join(*xTask, 0x00); - - // cleanup thread handler - *xTask = 0; -} - -TaskHandle_t xTaskGetCurrentTaskHandle(void) { - TaskHandle_t thread = malloc(sizeof(TaskHandle_t)); - *thread = pthread_self(); - return thread; -} - -BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait) { - // TODO: add implementation - return pdTRUE; -} - -BaseType_t xQueueReceive(QueueHandle_t xQueue, void* pvBuffer, TickType_t xTicksToWait) { - // TODO: add implementation - osDelay(100); - - return pdFALSE; -} - -static uint32_t queue_global_id = 0; - -QueueHandle_t xQueueCreateStatic( - UBaseType_t uxQueueLength, - UBaseType_t uxItemSize, - uint8_t* pucQueueStorageBuffer, - StaticQueue_t* pxQueueBuffer) { - // TODO: check this implementation - int* msgid = malloc(sizeof(int)); - - key_t key = queue_global_id; - queue_global_id++; - - *msgid = msgget(key, IPC_CREAT); - - return (QueueHandle_t)msgid; -} - -QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize) { - return xQueueCreateStatic(uxQueueLength, uxItemSize, 0, NULL); -} - -SemaphoreHandle_t xSemaphoreCreateCountingStatic( - UBaseType_t uxMaxCount, - UBaseType_t uxInitialCount, - StaticSemaphore_t* pxSemaphoreBuffer) { - pxSemaphoreBuffer->type = SemaphoreTypeCounting; - pxSemaphoreBuffer->take_counter = 0; - pxSemaphoreBuffer->give_counter = 0; - return pxSemaphoreBuffer; -} - -SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer) { - pxMutexBuffer->type = SemaphoreTypeMutex; - pthread_mutex_init(&pxMutexBuffer->mutex, NULL); - pxMutexBuffer->take_counter = 0; - pxMutexBuffer->give_counter = 0; - return pxMutexBuffer; -} - -BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait) { - if(xSemaphore == NULL) return pdFALSE; - - if(xSemaphore->type == SemaphoreTypeMutex) { - if(xTicksToWait == portMAX_DELAY) { - if(pthread_mutex_lock(&xSemaphore->mutex) == 0) { - return pdTRUE; - } else { - return pdFALSE; - } - } else { - TickType_t ticks = xTicksToWait; - while(ticks >= 0) { - if(pthread_mutex_trylock(&xSemaphore->mutex) == 0) { - return pdTRUE; - } - if(ticks > 0) { - osDelay(1); - } - ticks--; - } - return pdFALSE; - } - } - - // TODO: need to add inter-process sync or use POSIX primitives - xSemaphore->take_counter++; - - TickType_t ticks = xTicksToWait; - - while(xSemaphore->take_counter != xSemaphore->give_counter && - (ticks > 0 || xTicksToWait == portMAX_DELAY)) { - osDelay(1); - ticks--; - } - - if(xTicksToWait != 0 && ticks == 0) return pdFALSE; - - return pdTRUE; -} - -BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) { - if(xSemaphore == NULL) return pdFALSE; - - if(xSemaphore->type == SemaphoreTypeMutex) { - if(pthread_mutex_unlock(&xSemaphore->mutex) == 0) { - return pdTRUE; - } else { - return pdFALSE; - } - } - - // TODO: need to add inter-process sync or use POSIX primitives - xSemaphore->give_counter++; - - return pdTRUE; -} - -#define TLS_ITEM_COUNT 1 -static pthread_key_t tls_keys[TLS_ITEM_COUNT]; -static pthread_once_t tls_keys_once = PTHREAD_ONCE_INIT; - -static void create_tls_keys() { - for(size_t i = 0; i < TLS_ITEM_COUNT; i++) { - pthread_key_create(&tls_keys[i], NULL); - } -} - -void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex) { - // Non-current task TLS access is not allowed - if(xTaskToQuery != NULL) { - return NULL; - } - - if(xIndex >= TLS_ITEM_COUNT) { - return NULL; - } - - pthread_once(&tls_keys_once, create_tls_keys); - - return pthread_getspecific(tls_keys[xIndex]); -} - -void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void* pvValue) { - // Non-current task TLS access is not allowed - if(xTaskToSet != NULL) { - return; - } - - if(xIndex >= TLS_ITEM_COUNT) { - return; - } - - pthread_once(&tls_keys_once, create_tls_keys); - - pthread_setspecific(tls_keys[xIndex], pvValue); -} - - -osMutexId_t osMutexNew(const osMutexAttr_t *attr) { - StaticSemaphore_t* pxMutexBuffer = malloc(sizeof(StaticSemaphore_t)); - xSemaphoreCreateMutexStatic(pxMutexBuffer); - - return (osMutexId_t)pxMutexBuffer; -} - -osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout) { - if(xSemaphoreTake((SemaphoreHandle_t)mutex_id, (TickType_t)timeout) == pdTRUE) { - return osOK; - } else { - return osErrorTimeout; - } -} - -osStatus_t osMutexRelease (osMutexId_t mutex_id) { - if(xSemaphoreGive((SemaphoreHandle_t)mutex_id) == pdTRUE) { - return osOK; - } else { - return osError; - } -} - -osStatus_t osMutexDelete (osMutexId_t mutex_id) { - osMutexRelease(mutex_id); - - int res = 0; - if((res = pthread_mutex_destroy(&mutex_id->mutex)) == 0) { - return osOK; - } else { - printf("res = %d\n", res); - return osError; - } -} - -osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { - if(max_count != 1) { - // Non-binary semaphors are not supported at the moment - return NULL; - } - if(attr != NULL) { - // Attributes are not supported at the moment - return NULL; - } - - SemaphoreHandle_t handle = osMutexNew(NULL); - if(handle == NULL) return NULL; - - if(initial_count == 0) { - xSemaphoreTake(handle, 0); - } - - return handle; -} - -osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout) { - if(semaphore_id == NULL) { - return osErrorParameter; - } - - if(xSemaphoreTake(semaphore_id, timeout) == pdTRUE) { - return osOK; - } else { - return osErrorTimeout; - } -} - -osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id) { - if(semaphore_id == NULL) { - return osErrorParameter; - } - - if(xSemaphoreGive(semaphore_id) == pdTRUE) { - return osOK; - } else { - return osErrorTimeout; - } -} - -osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id) { - if(semaphore_id == NULL) { - return osErrorParameter; - } - - return osMutexDelete(semaphore_id); -} diff --git a/firmware/targets/local/Src/main.c b/firmware/targets/local/Src/main.c deleted file mode 100644 index d61403c2..00000000 --- a/firmware/targets/local/Src/main.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "heap.h" -#include "errno.h" - -/* -Flipper devices inc. - -Local fw build entry point. -*/ - -int app(); - -int main() { - // this function is not thread-safe, so it must be called in single thread context - if(!prvHeapInit()){ - return ENOMEM; - } - - return app(); -}
\ No newline at end of file diff --git a/firmware/targets/local/api-hal/api-hal-delay.c b/firmware/targets/local/api-hal/api-hal-delay.c deleted file mode 100644 index b9cfb36c..00000000 --- a/firmware/targets/local/api-hal/api-hal-delay.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "api-hal-delay.h" -#include <stdio.h> -#include <unistd.h> - -void delay_us(float microseconds) { - usleep(microseconds); -} - -void delay(float milliseconds) { - usleep(milliseconds * 1000); -}
\ No newline at end of file diff --git a/firmware/targets/local/api-hal/api-hal-gpio.c b/firmware/targets/local/api-hal/api-hal-gpio.c deleted file mode 100644 index 88458e9e..00000000 --- a/firmware/targets/local/api-hal/api-hal-gpio.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "api-hal-gpio.h" -#include <stdio.h> - -// init GPIO -void hal_gpio_init( - const GpioPin* gpio, - const GpioMode mode, - const GpioPull pull, - const GpioSpeed speed) { - // TODO more mode - if(gpio->pin != 0) { - switch(mode) { - case GpioModeInput: - printf("[GPIO] %s%d input\n", gpio->port, gpio->pin); - break; - - case GpioModeOutputPushPull: - printf("[GPIO] %s%d push pull\n", gpio->port, gpio->pin); - break; - - case GpioModeOutputOpenDrain: - printf("[GPIO] %s%d open drain\n", gpio->port, gpio->pin); - break; - - default: - printf("[GPIO] %s%d mode %d unsupported\n", gpio->port, gpio->pin, mode); - break; - } - } else { - printf("[GPIO] no pin\n"); - } -} - -// write value to GPIO, false = LOW, true = HIGH -void hal_gpio_write(const GpioPin* gpio, const bool state) { - if(gpio->pin != 0) { - if(state) { - printf("[GPIO] %s%d on\n", gpio->port, gpio->pin); - } else { - printf("[GPIO] %s%d off\n", gpio->port, gpio->pin); - } - } else { - printf("[GPIO] no pin\n"); - } -} - -// read value from GPIO, false = LOW, true = HIGH -bool hal_gpio_read(const GpioPin* gpio) { - // TODO emulate pin state? - return false; -} - -void enable_cc1101_irq() { - printf("enable cc1101 irq\n"); -} diff --git a/firmware/targets/local/api-hal/api-hal-gpio.h b/firmware/targets/local/api-hal/api-hal-gpio.h deleted file mode 100644 index ac258770..00000000 --- a/firmware/targets/local/api-hal/api-hal-gpio.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once -#include "main.h" -#include "stdbool.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// hw-api - -typedef char GPIO_TypeDef; - -typedef enum { - GpioModeInput, - GpioModeOutputPushPull, - GpioModeOutputOpenDrain, - GpioModeAltFunctionPushPull, - GpioModeAltFunctionOpenDrain, - GpioModeAnalog, - GpioModeInterruptRise, - GpioModeInterruptFall, - GpioModeInterruptRiseFall, - GpioModeEventRise, - GpioModeEventFall, - GpioModeEventRiseFall, -} GpioMode; - -typedef enum { - GpioSpeedLow, - GpioSpeedMedium, - GpioSpeedHigh, - GpioSpeedVeryHigh, -} GpioSpeed; - -typedef enum { - GpioPullNo, - GpioPullUp, - GpioPullDown, -} GpioPull; - -typedef struct { - GPIO_TypeDef* port; - uint16_t pin; -} GpioPin; - -// init GPIO -void hal_gpio_init( - const GpioPin* gpio, - const GpioMode mode, - const GpioPull pull, - const GpioSpeed speed); - -// write value to GPIO, false = LOW, true = HIGH -void hal_gpio_write(const GpioPin* gpio, const bool state); - -// read value from GPIO, false = LOW, true = HIGH -bool hal_gpio_read(const GpioPin* gpio); - -void enable_cc1101_irq(); - -#ifdef __cplusplus -} -#endif diff --git a/firmware/targets/local/api-hal/api-hal-resources.h b/firmware/targets/local/api-hal/api-hal-resources.h deleted file mode 100644 index e69de29b..00000000 --- a/firmware/targets/local/api-hal/api-hal-resources.h +++ /dev/null diff --git a/firmware/targets/local/api-hal/api-hal-task.c b/firmware/targets/local/api-hal/api-hal-task.c deleted file mode 100644 index f3d5f8d1..00000000 --- a/firmware/targets/local/api-hal/api-hal-task.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "api-hal-task.h" - -bool task_equal(TaskHandle_t a, TaskHandle_t b) { - if(a == NULL || b == NULL) return false; - return pthread_equal(*a, *b) != 0; -} - -bool task_is_isr_context(void) { - return false; -} - -void taskDISABLE_INTERRUPTS(void){ - // we cant disable main os sheduler -}; diff --git a/firmware/targets/local/api-hal/api-hal-task.h b/firmware/targets/local/api-hal/api-hal-task.h deleted file mode 100644 index 120dd5f6..00000000 --- a/firmware/targets/local/api-hal/api-hal-task.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "main.h" -#include <cmsis_os.h> -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// Task stack size in bytes -#define DEFAULT_STACK_SIZE 4096 - -// Max system tasks count -#define MAX_TASK_COUNT 10 - -bool task_equal(TaskHandle_t a, TaskHandle_t b); -bool task_is_isr_context(void); -__attribute__((unused)) void taskDISABLE_INTERRUPTS(void); - -#ifdef __cplusplus -} -#endif diff --git a/firmware/targets/local/api-hal/api-hal.h b/firmware/targets/local/api-hal/api-hal.h deleted file mode 100644 index 0125618f..00000000 --- a/firmware/targets/local/api-hal/api-hal.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "api-hal-gpio.h" -#include "api-hal-delay.h" -#include "flipper_hal.h"
\ No newline at end of file diff --git a/firmware/targets/local/fatfs/fatfs.c b/firmware/targets/local/fatfs/fatfs.c deleted file mode 100644 index d52b3d4e..00000000 --- a/firmware/targets/local/fatfs/fatfs.c +++ /dev/null @@ -1,56 +0,0 @@ -/** - ****************************************************************************** - * @file fatfs.c - * @brief Code for fatfs applications - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -#include "fatfs.h" - -uint8_t retUSER; /* Return value for USER */ -char USERPath[4]; /* USER logical drive path */ -FATFS USERFatFS; /* File system object for USER logical drive */ -FIL USERFile; /* File object for USER */ - -/* USER CODE BEGIN Variables */ - -/* USER CODE END Variables */ - -void MX_FATFS_Init(void) -{ - /*## FatFS: Link the USER driver ###########################*/ - retUSER = FATFS_LinkDriver(&USER_Driver, USERPath); - - /* USER CODE BEGIN Init */ - /* additional user code for init */ - /* USER CODE END Init */ -} - -/** - * @brief Gets Time from RTC - * @param None - * @retval Time in DWORD - */ -DWORD get_fattime(void) -{ - /* USER CODE BEGIN get_fattime */ - return 0; - /* USER CODE END get_fattime */ -} - -/* USER CODE BEGIN Application */ - -/* USER CODE END Application */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/local/fatfs/fatfs.h b/firmware/targets/local/fatfs/fatfs.h deleted file mode 100644 index a0775d88..00000000 --- a/firmware/targets/local/fatfs/fatfs.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - ****************************************************************************** - * @file fatfs.h - * @brief Header for fatfs applications - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __fatfs_H -#define __fatfs_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "fatfs/ff.h" -#include "fatfs/ff_gen_drv.h" -#include "user_diskio.h" /* defines USER_Driver as external */ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern uint8_t retUSER; /* Return value for USER */ -extern char USERPath[4]; /* USER logical drive path */ -extern FATFS USERFatFS; /* File system object for USER logical drive */ -extern FIL USERFile; /* File object for USER */ - -void MX_FATFS_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ -#ifdef __cplusplus -} -#endif -#endif /*__fatfs_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/local/fatfs/ffconf.h b/firmware/targets/local/fatfs/ffconf.h deleted file mode 100644 index 4bc3aed6..00000000 --- a/firmware/targets/local/fatfs/ffconf.h +++ /dev/null @@ -1,269 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * FatFs - Generic FAT file system module R0.12c (C)ChaN, 2017 - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -#ifndef _FFCONF -#define _FFCONF 68300 /* Revision ID */ - -/*-----------------------------------------------------------------------------/ -/ Additional user header to be used -/-----------------------------------------------------------------------------*/ - -#include "main.h" -#include "cmsis_os.h" /* _FS_REENTRANT set to 1 and CMSIS API chosen */ - -/*-----------------------------------------------------------------------------/ -/ Function Configurations -/-----------------------------------------------------------------------------*/ - -#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */ -/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) -/ Read-only configuration removes writing API functions, f_write(), f_sync(), -/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() -/ and optional writing functions as well. */ - -#define _FS_MINIMIZE 0 /* 0 to 3 */ -/* This option defines minimization level to remove some basic API functions. -/ -/ 0: All basic functions are enabled. -/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() -/ are removed. -/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. -/ 3: f_lseek() function is removed in addition to 2. */ - -#define _USE_STRFUNC 2 /* 0:Disable or 1-2:Enable */ -/* This option switches string functions, f_gets(), f_putc(), f_puts() and -/ f_printf(). -/ -/ 0: Disable string functions. -/ 1: Enable without LF-CRLF conversion. -/ 2: Enable with LF-CRLF conversion. */ - -#define _USE_FIND 0 -/* This option switches filtered directory read functions, f_findfirst() and -/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ - -#define _USE_MKFS 1 -/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ - -#define _USE_FASTSEEK 1 -/* This option switches fast seek feature. (0:Disable or 1:Enable) */ - -#define _USE_EXPAND 0 -/* This option switches f_expand function. (0:Disable or 1:Enable) */ - -#define _USE_CHMOD 0 -/* This option switches attribute manipulation functions, f_chmod() and f_utime(). -/ (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */ - -#define _USE_LABEL 1 -/* This option switches volume label functions, f_getlabel() and f_setlabel(). -/ (0:Disable or 1:Enable) */ - -#define _USE_FORWARD 0 -/* This option switches f_forward() function. (0:Disable or 1:Enable) */ - -/*-----------------------------------------------------------------------------/ -/ Locale and Namespace Configurations -/-----------------------------------------------------------------------------*/ - -#define _CODE_PAGE 850 -/* This option specifies the OEM code page to be used on the target system. -/ Incorrect setting of the code page can cause a file open failure. -/ -/ 1 - ASCII (No extended character. Non-LFN cfg. only) -/ 437 - U.S. -/ 720 - Arabic -/ 737 - Greek -/ 771 - KBL -/ 775 - Baltic -/ 850 - Latin 1 -/ 852 - Latin 2 -/ 855 - Cyrillic -/ 857 - Turkish -/ 860 - Portuguese -/ 861 - Icelandic -/ 862 - Hebrew -/ 863 - Canadian French -/ 864 - Arabic -/ 865 - Nordic -/ 866 - Russian -/ 869 - Greek 2 -/ 932 - Japanese (DBCS) -/ 936 - Simplified Chinese (DBCS) -/ 949 - Korean (DBCS) -/ 950 - Traditional Chinese (DBCS) -*/ - -#define _USE_LFN 2 /* 0 to 3 */ -#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ -/* The _USE_LFN switches the support of long file name (LFN). -/ -/ 0: Disable support of LFN. _MAX_LFN has no effect. -/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. -/ 2: Enable LFN with dynamic working buffer on the STACK. -/ 3: Enable LFN with dynamic working buffer on the HEAP. -/ -/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added -/ to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and -/ additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255. -/ It should be set 255 to support full featured LFN operations. -/ When use stack for the working buffer, take care on stack overflow. When use heap -/ memory for the working buffer, memory management functions, ff_memalloc() and -/ ff_memfree(), must be added to the project. */ - -#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */ -/* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16) -/ To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1. -/ This option also affects behavior of string I/O functions. */ - -#define _STRF_ENCODE 3 -/* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to -/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). -/ -/ 0: ANSI/OEM -/ 1: UTF-16LE -/ 2: UTF-16BE -/ 3: UTF-8 -/ -/ This option has no effect when _LFN_UNICODE == 0. */ - -#define _FS_RPATH 0 /* 0 to 2 */ -/* This option configures support of relative path. -/ -/ 0: Disable relative path and remove related functions. -/ 1: Enable relative path. f_chdir() and f_chdrive() are available. -/ 2: f_getcwd() function is available in addition to 1. -*/ - -/*---------------------------------------------------------------------------/ -/ Drive/Volume Configurations -/----------------------------------------------------------------------------*/ - -#define _VOLUMES 1 -/* Number of volumes (logical drives) to be used. */ - -/* USER CODE BEGIN Volumes */ -#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */ -#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" -/* _STR_VOLUME_ID switches string support of volume ID. -/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive -/ number in the path name. _VOLUME_STRS defines the drive ID strings for each -/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for -/ the drive ID strings are: A-Z and 0-9. */ -/* USER CODE END Volumes */ - -#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Multiple partition */ -/* This option switches support of multi-partition on a physical drive. -/ By default (0), each logical drive number is bound to the same physical drive -/ number and only an FAT volume found on the physical drive will be mounted. -/ When multi-partition is enabled (1), each logical drive number can be bound to -/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() -/ funciton will be available. */ -#define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */ -#define _MAX_SS 4096 /* 512, 1024, 2048 or 4096 */ -/* These options configure the range of sector size to be supported. (512, 1024, -/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and -/ harddisk. But a larger value may be required for on-board flash memory and some -/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured -/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the -/ disk_ioctl() function. */ - -#define _USE_TRIM 0 -/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable) -/ To enable Trim function, also CTRL_TRIM command should be implemented to the -/ disk_ioctl() function. */ - -#define _FS_NOFSINFO 0 /* 0,1,2 or 3 */ -/* If you need to know correct free space on the FAT32 volume, set bit 0 of this -/ option, and f_getfree() function at first time after volume mount will force -/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. -/ -/ bit0=0: Use free cluster count in the FSINFO if available. -/ bit0=1: Do not trust free cluster count in the FSINFO. -/ bit1=0: Use last allocated cluster number in the FSINFO if available. -/ bit1=1: Do not trust last allocated cluster number in the FSINFO. -*/ - -/*---------------------------------------------------------------------------/ -/ System Configurations -/----------------------------------------------------------------------------*/ - -#define _FS_TINY 1 /* 0:Normal or 1:Tiny */ -/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) -/ At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes. -/ Instead of private sector buffer eliminated from the file object, common sector -/ buffer in the file system object (FATFS) is used for the file data transfer. */ - -#define _FS_EXFAT 1 -/* This option switches support of exFAT file system. (0:Disable or 1:Enable) -/ When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) -/ Note that enabling exFAT discards C89 compatibility. */ - -#define _FS_NORTC 0 -#define _NORTC_MON 6 -#define _NORTC_MDAY 4 -#define _NORTC_YEAR 2015 -/* The option _FS_NORTC switches timestamp functiton. If the system does not have -/ any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable -/ the timestamp function. All objects modified by FatFs will have a fixed timestamp -/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time. -/ To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be -/ added to the project to get current time form real-time clock. _NORTC_MON, -/ _NORTC_MDAY and _NORTC_YEAR have no effect. -/ These options have no effect at read-only configuration (_FS_READONLY = 1). */ - -#define _FS_LOCK 2 /* 0:Disable or >=1:Enable */ -/* The option _FS_LOCK switches file lock function to control duplicated file open -/ and illegal operation to open objects. This option must be 0 when _FS_READONLY -/ is 1. -/ -/ 0: Disable file lock function. To avoid volume corruption, application program -/ should avoid illegal open, remove and rename to the open objects. -/ >0: Enable file lock function. The value defines how many files/sub-directories -/ can be opened simultaneously under file lock control. Note that the file -/ lock control is independent of re-entrancy. */ - -#define _FS_REENTRANT 1 /* 0:Disable or 1:Enable */ -#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ -#define _SYNC_t SemaphoreHandle_t -/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs -/ module itself. Note that regardless of this option, file access to different -/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() -/ and f_fdisk() function, are always not re-entrant. Only file/directory access -/ to the same volume is under control of this function. -/ -/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. -/ 1: Enable re-entrancy. Also user provided synchronization handlers, -/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() -/ function, must be added to the project. Samples are available in -/ option/syscall.c. -/ -/ The _FS_TIMEOUT defines timeout period in unit of time tick. -/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, -/ SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be -/ included somewhere in the scope of ff.h. */ - -/* define the ff_malloc ff_free macros as standard malloc free */ -#if !defined(ff_malloc) && !defined(ff_free) -#include <stdlib.h> -#define ff_malloc malloc -#define ff_free free -#endif - -#endif /* _FFCONF */ diff --git a/firmware/targets/local/fatfs/syscall.c b/firmware/targets/local/fatfs/syscall.c deleted file mode 100644 index d94ad279..00000000 --- a/firmware/targets/local/fatfs/syscall.c +++ /dev/null @@ -1,119 +0,0 @@ -/*------------------------------------------------------------------------*/ -/* Sample code of OS dependent controls for FatFs */ -/* (C)ChaN, 2014 */ -/* Portions COPYRIGHT 2017 STMicroelectronics */ -/* Portions Copyright (C) 2014, ChaN, all right reserved */ -/*------------------------------------------------------------------------*/ - -/** - ****************************************************************************** - * @attention - * - * Copyright (c) 2017 STMicroelectronics. All rights reserved. - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** -**/ - -#include "fatfs/ff.h" - -#if _FS_REENTRANT -/*------------------------------------------------------------------------*/ -/* Create a Synchronization Object */ -/*------------------------------------------------------------------------*/ -/* This function is called in f_mount() function to create a new -/ synchronization object, such as semaphore and mutex. When a 0 is returned, -/ the f_mount() function fails with FR_INT_ERR. -*/ - -int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */ - BYTE vol, /* Corresponding volume (logical drive number) */ - _SYNC_t *sobj /* Pointer to return the created sync object */ -) -{ - return 0; -} - - - -/*------------------------------------------------------------------------*/ -/* Delete a Synchronization Object */ -/*------------------------------------------------------------------------*/ -/* This function is called in f_mount() function to delete a synchronization -/ object that created with ff_cre_syncobj() function. When a 0 is returned, -/ the f_mount() function fails with FR_INT_ERR. -*/ - -int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */ - _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ -) -{ - return 0; -} - - - -/*------------------------------------------------------------------------*/ -/* Request Grant to Access the Volume */ -/*------------------------------------------------------------------------*/ -/* This function is called on entering file functions to lock the volume. -/ When a 0 is returned, the file function fails with FR_TIMEOUT. -*/ - -int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ - _SYNC_t sobj /* Sync object to wait */ -) -{ - return 0; -} - - - -/*------------------------------------------------------------------------*/ -/* Release Grant to Access the Volume */ -/*------------------------------------------------------------------------*/ -/* This function is called on leaving file functions to unlock the volume. -*/ - -void ff_rel_grant ( - _SYNC_t sobj /* Sync object to be signaled */ -) -{ -} - -#endif - - - - -#if _USE_LFN == 3 /* LFN with a working buffer on the heap */ -/*------------------------------------------------------------------------*/ -/* Allocate a memory block */ -/*------------------------------------------------------------------------*/ -/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. -*/ - -void* ff_memalloc ( /* Returns pointer to the allocated memory block */ - UINT msize /* Number of bytes to allocate */ -) -{ - return ff_malloc(msize); /* Allocate a new memory block with POSIX API */ -} - - -/*------------------------------------------------------------------------*/ -/* Free a memory block */ -/*------------------------------------------------------------------------*/ - -void ff_memfree ( - void* mblock /* Pointer to the memory block to free */ -) -{ - ff_free(mblock); /* Discard the memory block with POSIX API */ -} - -#endif diff --git a/firmware/targets/local/fatfs/user_diskio.c b/firmware/targets/local/fatfs/user_diskio.c deleted file mode 100644 index 843e1506..00000000 --- a/firmware/targets/local/fatfs/user_diskio.c +++ /dev/null @@ -1,219 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file user_diskio.c - * @brief This file includes a diskio driver skeleton to be completed by the user. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -#ifdef USE_OBSOLETE_USER_CODE_SECTION_0 -/* - * Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0) - * To be suppressed in the future. - * Kept to ensure backward compatibility with previous CubeMx versions when - * migrating projects. - * User code previously added there should be copied in the new user sections before - * the section contents can be deleted. - */ -/* USER CODE BEGIN 0 */ -/* USER CODE END 0 */ -#endif - -/* USER CODE BEGIN DECL */ - -/* Includes ------------------------------------------------------------------*/ -#include "user_diskio.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ - -/* Private variables ---------------------------------------------------------*/ -/* Disk status */ -static volatile DSTATUS Stat = STA_NOINIT; - -static DSTATUS User_CheckStatus(BYTE lun) { - Stat = STA_NOINIT; - - if(BSP_SD_GetCardState() == MSD_OK) { - Stat &= ~STA_NOINIT; - } - - return Stat; -} -/* USER CODE END DECL */ - -/* Private function prototypes -----------------------------------------------*/ -DSTATUS USER_initialize(BYTE pdrv); -DSTATUS USER_status(BYTE pdrv); -DRESULT USER_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count); -#if _USE_WRITE == 1 -DRESULT USER_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); -#endif /* _USE_WRITE == 1 */ -#if _USE_IOCTL == 1 -DRESULT USER_ioctl(BYTE pdrv, BYTE cmd, void* buff); -#endif /* _USE_IOCTL == 1 */ - -Diskio_drvTypeDef USER_Driver = { - USER_initialize, - USER_status, - USER_read, -#if _USE_WRITE - USER_write, -#endif /* _USE_WRITE == 1 */ -#if _USE_IOCTL == 1 - USER_ioctl, -#endif /* _USE_IOCTL == 1 */ -}; - -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Initializes a Drive - * @param pdrv: Physical drive number (0..) - * @retval DSTATUS: Operation status - */ -DSTATUS USER_initialize(BYTE pdrv /* Physical drive nmuber to identify the drive */ -) { - /* USER CODE BEGIN INIT */ - return User_CheckStatus(pdrv); - /* USER CODE END INIT */ -} - -/** - * @brief Gets Disk Status - * @param pdrv: Physical drive number (0..) - * @retval DSTATUS: Operation status - */ -DSTATUS USER_status(BYTE pdrv /* Physical drive number to identify the drive */ -) { - /* USER CODE BEGIN STATUS */ - return Stat; - /* USER CODE END STATUS */ -} - -/** - * @brief Reads Sector(s) - * @param pdrv: Physical drive number (0..) - * @param *buff: Data buffer to store read data - * @param sector: Sector address (LBA) - * @param count: Number of sectors to read (1..128) - * @retval DRESULT: Operation result - */ -DRESULT USER_read( - BYTE pdrv, /* Physical drive nmuber to identify the drive */ - BYTE* buff, /* Data buffer to store read data */ - DWORD sector, /* Sector address in LBA */ - UINT count /* Number of sectors to read */ -) { - /* USER CODE BEGIN READ */ - DRESULT res = RES_ERROR; - if(BSP_SD_ReadBlocks((uint32_t*)buff, (uint32_t)(sector), count, SD_DATATIMEOUT) == MSD_OK) { - /* wait until the read operation is finished */ - while(BSP_SD_GetCardState() != MSD_OK) { - } - res = RES_OK; - } - - return res; - /* USER CODE END READ */ -} - -/** - * @brief Writes Sector(s) - * @param pdrv: Physical drive number (0..) - * @param *buff: Data to be written - * @param sector: Sector address (LBA) - * @param count: Number of sectors to write (1..128) - * @retval DRESULT: Operation result - */ -#if _USE_WRITE == 1 -DRESULT USER_write( - BYTE pdrv, /* Physical drive nmuber to identify the drive */ - const BYTE* buff, /* Data to be written */ - DWORD sector, /* Sector address in LBA */ - UINT count /* Number of sectors to write */ -) { - /* USER CODE BEGIN WRITE */ - /* USER CODE HERE */ - DRESULT res = RES_ERROR; - - if(BSP_SD_WriteBlocks((uint32_t*)buff, (uint32_t)(sector), count, SD_DATATIMEOUT) == MSD_OK) { - /* wait until the Write operation is finished */ - while(BSP_SD_GetCardState() != MSD_OK) { - } - res = RES_OK; - } - - return res; - /* USER CODE END WRITE */ -} -#endif /* _USE_WRITE == 1 */ - -/** - * @brief I/O control operation - * @param pdrv: Physical drive number (0..) - * @param cmd: Control code - * @param *buff: Buffer to send/receive control data - * @retval DRESULT: Operation result - */ -#if _USE_IOCTL == 1 -DRESULT USER_ioctl( - BYTE pdrv, /* Physical drive nmuber (0..) */ - BYTE cmd, /* Control code */ - void* buff /* Buffer to send/receive control data */ -) { - /* USER CODE BEGIN IOCTL */ - DRESULT res = RES_ERROR; - BSP_SD_CardInfo CardInfo; - - if(Stat & STA_NOINIT) return RES_NOTRDY; - - switch(cmd) { - /* Make sure that no pending write process */ - case CTRL_SYNC: - res = RES_OK; - break; - - /* Get number of sectors on the disk (DWORD) */ - case GET_SECTOR_COUNT: - BSP_SD_GetCardInfo(&CardInfo); - *(DWORD*)buff = CardInfo.LogBlockNbr; - res = RES_OK; - break; - - /* Get R/W sector size (WORD) */ - case GET_SECTOR_SIZE: - BSP_SD_GetCardInfo(&CardInfo); - *(WORD*)buff = CardInfo.LogBlockSize; - res = RES_OK; - break; - - /* Get erase block size in unit of sector (DWORD) */ - case GET_BLOCK_SIZE: - BSP_SD_GetCardInfo(&CardInfo); - *(DWORD*)buff = CardInfo.LogBlockSize; - res = RES_OK; - break; - - default: - res = RES_PARERR; - } - - return res; - /* USER CODE END IOCTL */ -} -#endif /* _USE_IOCTL == 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\ No newline at end of file diff --git a/firmware/targets/local/fatfs/user_diskio.h b/firmware/targets/local/fatfs/user_diskio.h deleted file mode 100644 index 93ad1f01..00000000 --- a/firmware/targets/local/fatfs/user_diskio.h +++ /dev/null @@ -1,47 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file user_diskio.h - * @brief This file contains the common defines and functions prototypes for - * the user_diskio driver. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USER_DISKIO_H -#define __USER_DISKIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* USER CODE BEGIN 0 */ - -/* Includes ------------------------------------------------------------------*/ -#include "fatfs/ff_gen_drv.h" -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -extern Diskio_drvTypeDef USER_Driver; - -/* USER CODE END 0 */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USER_DISKIO_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/local/target.mk b/firmware/targets/local/target.mk deleted file mode 100644 index d8ae2454..00000000 --- a/firmware/targets/local/target.mk +++ /dev/null @@ -1,25 +0,0 @@ -TOOLCHAIN = x86 - -# Sources -C_SOURCES += $(TARGET_DIR)/Src/main.c -C_SOURCES += $(TARGET_DIR)/Src/flipper_hal.c -C_SOURCES += $(TARGET_DIR)/Src/lo_os.c -C_SOURCES += $(TARGET_DIR)/Src/lo_hal.c - -# CFLAGS += -DFURI_DEBUG -CFLAGS += -I$(TARGET_DIR)/Inc -CFLAGS += -Wall -fdata-sections -ffunction-sections -pthread -LDFLAGS += -pthread - -# FatFs library -CFLAGS += -I$(TARGET_DIR)/fatfs -C_SOURCES += $(TARGET_DIR)/fatfs/syscall.c - -# memory manager -C_SOURCES += $(TARGET_DIR)/Src/heap_4.c - -CFLAGS += -I$(TARGET_DIR)/api-hal -C_SOURCES += $(wildcard $(TARGET_DIR)/api-hal/*.c) - -run: all - $(OBJ_DIR)/$(PROJECT).elf
\ No newline at end of file diff --git a/lib/app-template/app-template.cpp b/lib/app-template/app-template.cpp index c754783e..b04210f1 100644 --- a/lib/app-template/app-template.cpp +++ b/lib/app-template/app-template.cpp @@ -1,5 +1,4 @@ -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> #include "app-template.h" /* diff --git a/lib/app-template/app-template.h b/lib/app-template/app-template.h index 960db047..81f232e2 100644 --- a/lib/app-template/app-template.h +++ b/lib/app-template/app-template.h @@ -1,7 +1,8 @@ #pragma once #include "callback-connector.h" -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> +#include <gui/gui.h> +#include <input/input.h> // simple app class with template variables <state, events> template <class TState, class TEvent> class AppTemplate { @@ -33,15 +34,11 @@ template <class TState, class TEvent> AppTemplate<TState, TEvent>::AppTemplate() // TODO: use plain os mutex? if(!init_mutex(&state_mutex, &state, sizeof(TState))) { printf("cannot create mutex\n"); - furiac_exit(NULL); + furiac_exit(); } // open gui - gui = (Gui*)furi_open("gui"); - if(gui == NULL) { - printf("gui is not available\n"); - furiac_exit(NULL); - } + gui = (Gui*)furi_record_open("gui"); // allocate widget widget = widget_alloc(); @@ -101,15 +98,12 @@ template <class TState, class TEvent> void AppTemplate<TState, TEvent>::app_read // add widget gui_add_widget(gui, widget, GuiLayerFullscreen); - - // signal that our app ready to work - furiac_ready(); } template <class TState, class TEvent> void AppTemplate<TState, TEvent>::exit(void) { // TODO remove all widgets create by app widget_enabled_set(widget, false); - furiac_exit(NULL); + osThreadExit(); } template <class TState, class TEvent> void AppTemplate<TState, TEvent>::update_gui(void) { diff --git a/lib/common-api/filesystem-api.h b/lib/common-api/filesystem-api.h index 5a710b0e..15091292 100644 --- a/lib/common-api/filesystem-api.h +++ b/lib/common-api/filesystem-api.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> #ifdef __cplusplus extern "C" { diff --git a/lib/cyfral/cyfral_emulator.h b/lib/cyfral/cyfral_emulator.h index f62b2dee..7f678af9 100644 --- a/lib/cyfral/cyfral_emulator.h +++ b/lib/cyfral/cyfral_emulator.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> class CyfralTiming { public: diff --git a/lib/cyfral/cyfral_reader.h b/lib/cyfral/cyfral_reader.h index 01f72f71..498a4920 100644 --- a/lib/cyfral/cyfral_reader.h +++ b/lib/cyfral/cyfral_reader.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> enum class CyfralReaderError : uint8_t { NO_ERROR = 0, diff --git a/lib/cyfral/cyfral_reader_comp.h b/lib/cyfral/cyfral_reader_comp.h index aa8f6768..fa1b283f 100644 --- a/lib/cyfral/cyfral_reader_comp.h +++ b/lib/cyfral/cyfral_reader_comp.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> #include "callback-connector.h" #include <atomic> @@ -74,9 +74,5 @@ endif CFLAGS += -I$(LIB_DIR)/common-api # drivers -ifneq ($(TARGET), local) -ifneq ($(TARGET), f2) CFLAGS += -I$(LIB_DIR)/drivers C_SOURCES += $(wildcard $(LIB_DIR)/drivers/*.c) -endif -endif diff --git a/lib/onewire/one_wire_gpio.h b/lib/onewire/one_wire_gpio.h index 6d9818d6..a78dcdf2 100644 --- a/lib/onewire/one_wire_gpio.h +++ b/lib/onewire/one_wire_gpio.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> #include "one_wire_timings.h" class OneWireGpio { diff --git a/lib/onewire/one_wire_slave_gpio.h b/lib/onewire/one_wire_slave_gpio.h index d7d7daa8..2f9deb4b 100644 --- a/lib/onewire/one_wire_slave_gpio.h +++ b/lib/onewire/one_wire_slave_gpio.h @@ -1,6 +1,5 @@ #pragma once -#include "flipper.h" -#include "flipper_v2.h" +#include <furi.h> #include "one_wire_timings.h" // TODO fix GPL compability |