jblanked 1 год назад
Родитель
Сommit
4429df3fcb
59 измененных файлов с 9197 добавлено и 0 удалено
  1. 69 0
      alloc/alloc.c
  2. 6 0
      alloc/alloc.h
  3. 53 0
      app.c
  4. BIN
      app.png
  5. 11 0
      application.fam
  6. BIN
      assets/KeyBackspaceSelected_16x9.png
  7. BIN
      assets/KeyBackspace_16x9.png
  8. BIN
      assets/KeySaveSelected_24x11.png
  9. BIN
      assets/KeySave_24x11.png
  10. BIN
      assets/WarningDolphin_45x42.png
  11. BIN
      assets/sprites/player.fxbm
  12. 473 0
      callback/callback.c
  13. 6 0
      callback/callback.h
  14. 590 0
      easy_flipper/easy_flipper.c
  15. 269 0
      easy_flipper/easy_flipper.h
  16. 674 0
      engine/LICENSE
  17. 28 0
      engine/canvas.c
  18. 32 0
      engine/canvas.h
  19. 53 0
      engine/clock_timer.c
  20. 15 0
      engine/clock_timer.h
  21. 25 0
      engine/engine.h
  22. 217 0
      engine/entity.c
  23. 65 0
      engine/entity.h
  24. 58 0
      engine/entity_i.h
  25. 199 0
      engine/game_engine.c
  26. 88 0
      engine/game_engine.h
  27. 162 0
      engine/game_manager.c
  28. 40 0
      engine/game_manager.h
  29. 24 0
      engine/game_manager_i.h
  30. 214 0
      engine/level.c
  31. 61 0
      engine/level.h
  32. 26 0
      engine/level_i.h
  33. 59 0
      engine/main.c
  34. 84 0
      engine/scripts/sprite_builder.py
  35. 297 0
      engine/sensors/ICM42688P/ICM42688P.c
  36. 127 0
      engine/sensors/ICM42688P/ICM42688P.h
  37. 176 0
      engine/sensors/ICM42688P/ICM42688P_regs.h
  38. 326 0
      engine/sensors/imu.c
  39. 15 0
      engine/sensors/imu.h
  40. 69 0
      engine/sprite.c
  41. 44 0
      engine/sprite.h
  42. 33 0
      engine/vector.c
  43. 32 0
      engine/vector.h
  44. 186 0
      flip_storage/storage.c
  45. 25 0
      flip_storage/storage.h
  46. 1 0
      flip_world.c
  47. 52 0
      flip_world.h
  48. 1524 0
      flipper_http/flipper_http.c
  49. 385 0
      flipper_http/flipper_http.h
  50. 316 0
      font/font.c
  51. 13 0
      font/font.h
  52. 221 0
      game.c
  53. 8 0
      game.h
  54. 747 0
      jsmn/jsmn.c
  55. 132 0
      jsmn/jsmn.h
  56. 0 0
      sprites/.gitkeep
  57. BIN
      sprites/player.png
  58. 784 0
      text_input/uart_text_input.c
  59. 83 0
      text_input/uart_text_input.h

+ 69 - 0
alloc/alloc.c

@@ -0,0 +1,69 @@
+#include <alloc/alloc.h>
+
+/**
+ * @brief Navigation callback for exiting the application
+ * @param context The context - unused
+ * @return next view id (VIEW_NONE to exit the app)
+ */
+static uint32_t callback_exit_app(void *context)
+{
+    // Exit the application
+    UNUSED(context);
+    return VIEW_NONE; // Return VIEW_NONE to exit the app
+}
+
+// Function to allocate resources for the FlipWorldApp
+FlipWorldApp *flip_world_app_alloc()
+{
+    FlipWorldApp *app = (FlipWorldApp *)malloc(sizeof(FlipWorldApp));
+
+    Gui *gui = furi_record_open(RECORD_GUI);
+
+    // Allocate ViewDispatcher
+    if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
+    {
+        return NULL;
+    }
+
+    // Submenu
+    if (!easy_flipper_set_submenu(&app->submenu, FlipWorldViewSubmenu, VERSION_TAG, callback_exit_app, &app->view_dispatcher))
+    {
+        return NULL;
+    }
+    submenu_add_item(app->submenu, "Play", FlipWorldSubmenuIndexRun, callback_submenu_choices, app);
+    submenu_add_item(app->submenu, "About", FlipWorldSubmenuIndexAbout, callback_submenu_choices, app);
+    submenu_add_item(app->submenu, "Settings", FlipWorldSubmenuIndexSettings, callback_submenu_choices, app);
+
+    // Switch to the main view
+    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
+
+    return app;
+}
+
+// Function to free the resources used by FlipWorldApp
+void flip_world_app_free(FlipWorldApp *app)
+{
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+
+    // Free Submenu(s)
+    if (app->submenu)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewSubmenu);
+        submenu_free(app->submenu);
+    }
+
+    free_all_views(app, true);
+
+    // free the view dispatcher
+    view_dispatcher_free(app->view_dispatcher);
+
+    // close the gui
+    furi_record_close(RECORD_GUI);
+
+    // free the app
+    free(app);
+}

+ 6 - 0
alloc/alloc.h

@@ -0,0 +1,6 @@
+#pragma once
+#include <flip_world.h>
+#include <callback/callback.h>
+
+extern FlipWorldApp *flip_world_app_alloc();
+extern void flip_world_app_free(FlipWorldApp *app);

+ 53 - 0
app.c

@@ -0,0 +1,53 @@
+#include <alloc/alloc.h>
+
+// Entry point for the FlipWorld application
+int32_t flip_world_main(void *p)
+{
+    // Suppress unused parameter warning
+    UNUSED(p);
+
+    // Initialize the FlipWorld application
+    FlipWorldApp *app = flip_world_app_alloc();
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "Failed to allocate FlipWorldApp");
+        return -1;
+    }
+
+    // check if board is connected (Derek Jamison)
+    // initialize the http
+    if (flipper_http_init(flipper_http_rx_callback, app))
+    {
+        if (!flipper_http_ping())
+        {
+            FURI_LOG_E(TAG, "Failed to ping the device");
+            return -1;
+        }
+
+        // Try to wait for pong response.
+        uint8_t counter = 10;
+        while (fhttp.state == INACTIVE && --counter > 0)
+        {
+            FURI_LOG_D(TAG, "Waiting for PONG");
+            furi_delay_ms(100);
+        }
+
+        if (counter == 0)
+            easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
+
+        flipper_http_deinit();
+    }
+    else
+    {
+        easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
+    }
+
+    // Run the view dispatcher
+    view_dispatcher_run(app->view_dispatcher);
+
+    // Free the resources used by the FlipWorld application
+    flip_world_app_free(app);
+
+    // Return 0 to indicate success
+    return 0;
+}


+ 11 - 0
application.fam

@@ -0,0 +1,11 @@
+App(
+    appid="flip_world",
+    name="FlipWorld",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="flip_world_main",
+    stack_size=4 * 1024,
+    fap_icon="app.png",
+    fap_category="GPIO",
+    fap_icon_assets="assets",
+    fap_description="Open World Multiplayer game, best played with the VGM."
+)

BIN
assets/KeyBackspaceSelected_16x9.png


BIN
assets/KeyBackspace_16x9.png


BIN
assets/KeySaveSelected_24x11.png


BIN
assets/KeySave_24x11.png


BIN
assets/WarningDolphin_45x42.png


BIN
assets/sprites/player.fxbm


+ 473 - 0
callback/callback.c

@@ -0,0 +1,473 @@
+#include <callback/callback.h>
+
+static bool alloc_about_view(void *context);
+static bool alloc_main_view(void *context);
+static bool alloc_text_input_view(void *context, char *title);
+static bool alloc_variable_item_list(void *context);
+//
+static void settings_item_selected(void *context, uint32_t index);
+static void text_updated_ssid(void *context);
+static void text_updated_pass(void *context);
+
+static uint32_t callback_to_submenu(void *context)
+{
+    UNUSED(context);
+    return FlipWorldViewSubmenu;
+}
+static uint32_t callback_to_wifi_settings(void *context)
+{
+    UNUSED(context);
+    return FlipWorldViewSettings;
+}
+
+// Callback for drawing the main screen
+static void flip_world_view_game_draw_callback(Canvas *canvas, void *model)
+{
+    UNUSED(model);
+    canvas_clear(canvas);
+    canvas_set_font_custom(canvas, FONT_SIZE_XLARGE);
+    canvas_draw_str(canvas, 0, 10, "Game");
+}
+static void flip_world_view_about_draw_callback(Canvas *canvas, void *model)
+{
+    UNUSED(model);
+    canvas_clear(canvas);
+    canvas_set_font_custom(canvas, FONT_SIZE_XLARGE);
+    canvas_draw_str(canvas, 0, 10, VERSION_TAG);
+    canvas_set_font_custom(canvas, FONT_SIZE_MEDIUM);
+    canvas_draw_str(canvas, 0, 20, "- @JBlanked @codeallnight");
+    canvas_set_font_custom(canvas, FONT_SIZE_SMALL);
+    canvas_draw_str(canvas, 0, 30, "- github.com/JBlanked/FlipWorld");
+
+    canvas_draw_str_multi(canvas, 0, 55, "The first open world multiplayer\ngame on the Flipper Zero.");
+}
+
+// alloc
+static bool alloc_about_view(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return false;
+    }
+    if (!app->view_about)
+    {
+        if (!easy_flipper_set_view(&app->view_about, FlipWorldViewAbout, flip_world_view_about_draw_callback, NULL, callback_to_submenu, &app->view_dispatcher, app))
+        {
+            return false;
+        }
+        if (!app->view_about)
+        {
+            return false;
+        }
+    }
+    return true;
+}
+
+static bool alloc_main_view(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return false;
+    }
+    if (!app->view_main)
+    {
+        if (!easy_flipper_set_view(&app->view_main, FlipWorldViewMain, flip_world_view_game_draw_callback, NULL, callback_to_submenu, &app->view_dispatcher, app))
+        {
+            return false;
+        }
+        if (!app->view_main)
+        {
+            return false;
+        }
+    }
+    return true;
+}
+static bool alloc_text_input_view(void *context, char *title)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return false;
+    }
+    if (!title)
+    {
+        FURI_LOG_E(TAG, "Title is NULL");
+        return false;
+    }
+    app->text_input_buffer_size = 64;
+    if (!app->text_input_buffer)
+    {
+        if (!easy_flipper_set_buffer(&app->text_input_buffer, app->text_input_buffer_size))
+        {
+            return false;
+        }
+    }
+    if (!app->text_input_temp_buffer)
+    {
+        if (!easy_flipper_set_buffer(&app->text_input_temp_buffer, app->text_input_buffer_size))
+        {
+            return false;
+        }
+    }
+    if (!app->text_input)
+    {
+        if (!easy_flipper_set_uart_text_input(
+                &app->text_input,
+                FlipWorldViewTextInput,
+                title,
+                app->text_input_temp_buffer,
+                app->text_input_buffer_size,
+                strcmp(title, "SSID") == 0 ? text_updated_ssid : text_updated_pass,
+                callback_to_wifi_settings,
+                &app->view_dispatcher,
+                app))
+        {
+            return false;
+        }
+        if (!app->text_input)
+        {
+            return false;
+        }
+    }
+    return true;
+}
+static bool alloc_variable_item_list(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return false;
+    }
+    if (!app->variable_item_list)
+    {
+        if (!easy_flipper_set_variable_item_list(&app->variable_item_list, FlipWorldViewSettings, settings_item_selected, callback_to_submenu, &app->view_dispatcher, app))
+            return false;
+
+        if (!app->variable_item_list)
+            return false;
+
+        if (!app->variable_item_ssid)
+        {
+            app->variable_item_ssid = variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
+            variable_item_set_current_value_text(app->variable_item_ssid, "");
+        }
+        if (!app->variable_item_pass)
+        {
+            app->variable_item_pass = variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);
+            variable_item_set_current_value_text(app->variable_item_pass, "");
+        }
+        char ssid[64];
+        char pass[64];
+        if (load_settings(ssid, sizeof(ssid), pass, sizeof(pass)))
+        {
+            variable_item_set_current_value_text(app->variable_item_ssid, ssid);
+            // variable_item_set_current_value_text(app->variable_item_pass, pass);
+        }
+    }
+    return true;
+}
+// free
+static void free_about_view(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    if (app->view_about)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewAbout);
+        view_free(app->view_about);
+        app->view_about = NULL;
+    }
+}
+static void free_main_view(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    if (app->view_main)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewMain);
+        view_free(app->view_main);
+        app->view_main = NULL;
+    }
+}
+
+static void free_text_input_view(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    if (app->text_input)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewTextInput);
+        uart_text_input_free(app->text_input);
+        app->text_input = NULL;
+    }
+    if (app->text_input_buffer)
+    {
+        free(app->text_input_buffer);
+        app->text_input_buffer = NULL;
+    }
+    if (app->text_input_temp_buffer)
+    {
+        free(app->text_input_temp_buffer);
+        app->text_input_temp_buffer = NULL;
+    }
+}
+static void free_variable_item_list(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    if (app->variable_item_list)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewSettings);
+        variable_item_list_free(app->variable_item_list);
+        app->variable_item_list = NULL;
+    }
+    if (app->variable_item_ssid)
+    {
+        free(app->variable_item_ssid);
+        app->variable_item_ssid = NULL;
+    }
+    if (app->variable_item_pass)
+    {
+        free(app->variable_item_pass);
+        app->variable_item_pass = NULL;
+    }
+}
+void free_all_views(void *context, bool should_free_variable_item_list)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    if (should_free_variable_item_list)
+    {
+        free_variable_item_list(app);
+    }
+    free_about_view(app);
+    free_main_view(app);
+    free_text_input_view(app);
+}
+
+void callback_submenu_choices(void *context, uint32_t index)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    switch (index)
+    {
+    case FlipWorldSubmenuIndexRun:
+        free_all_views(app, true);
+        if (!alloc_main_view(app))
+        {
+            FURI_LOG_E(TAG, "Failed to allocate main view");
+            return;
+        }
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewMain);
+        break;
+    case FlipWorldSubmenuIndexAbout:
+        free_all_views(app, true);
+        if (!alloc_about_view(app))
+        {
+            FURI_LOG_E(TAG, "Failed to allocate about view");
+            return;
+        }
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewAbout);
+        break;
+    case FlipWorldSubmenuIndexSettings:
+        free_all_views(app, true);
+        if (!alloc_variable_item_list(app))
+        {
+            FURI_LOG_E(TAG, "Failed to allocate variable item list");
+            return;
+        }
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSettings);
+        break;
+    default:
+        break;
+    }
+}
+
+static void text_updated_ssid(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+
+    // store the entered text
+    strncpy(app->text_input_buffer, app->text_input_temp_buffer, app->text_input_buffer_size);
+
+    // Ensure null-termination
+    app->text_input_buffer[app->text_input_buffer_size - 1] = '\0';
+
+    // save the setting
+    save_char("WiFi-SSID", app->text_input_buffer);
+
+    // update the variable item text
+    if (app->variable_item_ssid)
+    {
+        variable_item_set_current_value_text(app->variable_item_ssid, app->text_input_buffer);
+
+        // get value of password
+        char pass[64];
+        if (load_char("WiFi-Password", pass, sizeof(pass)))
+        {
+            if (strlen(pass) > 0 && strlen(app->text_input_buffer) > 0)
+            {
+                // save the settings
+                save_settings(app->text_input_buffer, pass);
+
+                // initialize the http
+                if (flipper_http_init(flipper_http_rx_callback, app))
+                {
+                    // save the wifi if the device is connected
+                    if (!flipper_http_save_wifi(app->text_input_buffer, pass))
+                    {
+                        easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
+                    }
+
+                    // free the resources
+                    flipper_http_deinit();
+                }
+                else
+                {
+                    easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
+                }
+            }
+        }
+    }
+
+    // switch to the settings view
+    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSettings);
+}
+static void text_updated_pass(void *context)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+
+    // store the entered text
+    strncpy(app->text_input_buffer, app->text_input_temp_buffer, app->text_input_buffer_size);
+
+    // Ensure null-termination
+    app->text_input_buffer[app->text_input_buffer_size - 1] = '\0';
+
+    // save the setting
+    save_char("WiFi-Password", app->text_input_buffer);
+
+    // update the variable item text
+    if (app->variable_item_pass)
+    {
+        // variable_item_set_current_value_text(app->variable_item_pass, app->text_input_buffer);
+    }
+
+    // get value of ssid
+    char ssid[64];
+    if (load_char("WiFi-SSID", ssid, sizeof(ssid)))
+    {
+        if (strlen(ssid) > 0 && strlen(app->text_input_buffer) > 0)
+        {
+            // save the settings
+            save_settings(ssid, app->text_input_buffer);
+
+            // initialize the http
+            if (flipper_http_init(flipper_http_rx_callback, app))
+            {
+                // save the wifi if the device is connected
+                if (!flipper_http_save_wifi(ssid, app->text_input_buffer))
+                {
+                    easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
+                }
+
+                // free the resources
+                flipper_http_deinit();
+            }
+            else
+            {
+                easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
+            }
+        }
+    }
+
+    // switch to the settings view
+    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSettings);
+}
+
+static void settings_item_selected(void *context, uint32_t index)
+{
+    FlipWorldApp *app = (FlipWorldApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWorldApp is NULL");
+        return;
+    }
+    switch (index)
+    {
+    case 0: // Input SSID
+        free_all_views(app, false);
+        if (!alloc_text_input_view(app, "SSID"))
+        {
+            FURI_LOG_E(TAG, "Failed to allocate text input view");
+            return;
+        }
+        // load SSID
+        char ssid[64];
+        if (load_char("WiFi-SSID", ssid, sizeof(ssid)))
+        {
+            strncpy(app->text_input_temp_buffer, ssid, app->text_input_buffer_size - 1);
+            app->text_input_temp_buffer[app->text_input_buffer_size - 1] = '\0';
+        }
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewTextInput);
+        break;
+    case 1: // Input Password
+        free_all_views(app, false);
+        if (!alloc_text_input_view(app, "Password"))
+        {
+            FURI_LOG_E(TAG, "Failed to allocate text input view");
+            return;
+        }
+        // load password
+        char pass[64];
+        if (load_char("WiFi-Password", pass, sizeof(pass)))
+        {
+            strncpy(app->text_input_temp_buffer, pass, app->text_input_buffer_size - 1);
+            app->text_input_temp_buffer[app->text_input_buffer_size - 1] = '\0';
+        }
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewTextInput);
+        break;
+    default:
+        FURI_LOG_E(TAG, "Unknown configuration item index");
+        break;
+    }
+}

+ 6 - 0
callback/callback.h

@@ -0,0 +1,6 @@
+#pragma once
+#include <flip_world.h>
+#include <flip_storage/storage.h>
+
+void free_all_views(void *context, bool free_variable_item_list);
+void callback_submenu_choices(void *context, uint32_t index);

+ 590 - 0
easy_flipper/easy_flipper.c

@@ -0,0 +1,590 @@
+#include <easy_flipper/easy_flipper.h>
+
+void easy_flipper_dialog(
+    char *header,
+    char *text)
+{
+    DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
+    DialogMessage *message = dialog_message_alloc();
+    dialog_message_set_header(
+        message, header, 64, 0, AlignCenter, AlignTop);
+    dialog_message_set_text(
+        message,
+        text,
+        0,
+        63,
+        AlignLeft,
+        AlignBottom);
+    dialog_message_show(dialogs, message);
+    dialog_message_free(message);
+    furi_record_close(RECORD_DIALOGS);
+}
+
+/**
+ * @brief Navigation callback for exiting the application
+ * @param context The context - unused
+ * @return next view id (VIEW_NONE to exit the app)
+ */
+uint32_t easy_flipper_callback_exit_app(void *context)
+{
+    // Exit the application
+    if (!context)
+    {
+        FURI_LOG_E(EASY_TAG, "Context is NULL");
+        return VIEW_NONE;
+    }
+    UNUSED(context);
+    return VIEW_NONE; // Return VIEW_NONE to exit the app
+}
+
+/**
+ * @brief Initialize a buffer
+ * @param buffer The buffer to initialize
+ * @param buffer_size The size of the buffer
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
+{
+    if (!buffer)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
+        return false;
+    }
+    *buffer = (char *)malloc(buffer_size);
+    if (!*buffer)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
+        return false;
+    }
+    *buffer[0] = '\0';
+    return true;
+}
+
+/**
+ * @brief Initialize a View object
+ * @param view The View object to initialize
+ * @param view_id The ID/Index of the view
+ * @param draw_callback The draw callback function (set to NULL if not needed)
+ * @param input_callback The input callback function (set to NULL if not needed)
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_view(
+    View **view,
+    int32_t view_id,
+    void draw_callback(Canvas *, void *),
+    bool input_callback(InputEvent *, void *),
+    uint32_t (*previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context)
+{
+    if (!view || !view_dispatcher)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
+        return false;
+    }
+    *view = view_alloc();
+    if (!*view)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate View");
+        return false;
+    }
+    if (draw_callback)
+    {
+        view_set_draw_callback(*view, draw_callback);
+    }
+    if (input_callback)
+    {
+        view_set_input_callback(*view, input_callback);
+    }
+    if (context)
+    {
+        view_set_context(*view, context);
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(*view, previous_callback);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, *view);
+    return true;
+}
+
+/**
+ * @brief Initialize a ViewDispatcher object
+ * @param view_dispatcher The ViewDispatcher object to initialize
+ * @param gui The GUI object
+ * @param context The context to pass to the event callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
+{
+    if (!view_dispatcher)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
+        return false;
+    }
+    *view_dispatcher = view_dispatcher_alloc();
+    if (!*view_dispatcher)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
+        return false;
+    }
+    view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
+    if (context)
+    {
+        view_dispatcher_set_event_callback_context(*view_dispatcher, context);
+    }
+    return true;
+}
+
+/**
+ * @brief Initialize a Submenu object
+ * @note This does not set the items in the submenu
+ * @param submenu The Submenu object to initialize
+ * @param view_id The ID/Index of the view
+ * @param title The title/header of the submenu
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_submenu(
+    Submenu **submenu,
+    int32_t view_id,
+    char *title,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher)
+{
+    if (!submenu)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
+        return false;
+    }
+    *submenu = submenu_alloc();
+    if (!*submenu)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
+        return false;
+    }
+    if (title)
+    {
+        submenu_set_header(*submenu, title);
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
+    return true;
+}
+/**
+ * @brief Initialize a Menu object
+ * @note This does not set the items in the menu
+ * @param menu The Menu object to initialize
+ * @param view_id The ID/Index of the view
+ * @param item_callback The item callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_menu(
+    Menu **menu,
+    int32_t view_id,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher)
+{
+    if (!menu)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
+        return false;
+    }
+    *menu = menu_alloc();
+    if (!*menu)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
+        return false;
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(menu_get_view(*menu), previous_callback);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
+    return true;
+}
+
+/**
+ * @brief Initialize a Widget object
+ * @param widget The Widget object to initialize
+ * @param view_id The ID/Index of the view
+ * @param text The text to display in the widget
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_widget(
+    Widget **widget,
+    int32_t view_id,
+    char *text,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher)
+{
+    if (!widget)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
+        return false;
+    }
+    *widget = widget_alloc();
+    if (!*widget)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
+        return false;
+    }
+    if (text)
+    {
+        widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(widget_get_view(*widget), previous_callback);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
+    return true;
+}
+
+/**
+ * @brief Initialize a VariableItemList object
+ * @note This does not set the items in the VariableItemList
+ * @param variable_item_list The VariableItemList object to initialize
+ * @param view_id The ID/Index of the view
+ * @param enter_callback The enter callback function (can be set to NULL)
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the enter callback (usually the app)
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_variable_item_list(
+    VariableItemList **variable_item_list,
+    int32_t view_id,
+    void (*enter_callback)(void *, uint32_t),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context)
+{
+    if (!variable_item_list)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
+        return false;
+    }
+    *variable_item_list = variable_item_list_alloc();
+    if (!*variable_item_list)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
+        return false;
+    }
+    if (enter_callback)
+    {
+        variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    return true;
+}
+
+/**
+ * @brief Initialize a TextInput object
+ * @param text_input The TextInput object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_text_input(
+    TextInput **text_input,
+    int32_t view_id,
+    char *header_text,
+    char *text_input_temp_buffer,
+    uint32_t text_input_buffer_size,
+    void (*result_callback)(void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context)
+{
+    if (!text_input)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
+        return false;
+    }
+    *text_input = text_input_alloc();
+    if (!*text_input)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
+        return false;
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
+    }
+    if (header_text)
+    {
+        text_input_set_header_text(*text_input, header_text);
+    }
+    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
+    {
+        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
+    return true;
+}
+
+/**
+ * @brief Initialize a UART_TextInput object
+ * @param uart_text_input The UART_TextInput object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_uart_text_input(
+    UART_TextInput **uart_text_input,
+    int32_t view_id,
+    char *header_text,
+    char *uart_text_input_temp_buffer,
+    uint32_t uart_text_input_buffer_size,
+    void (*result_callback)(void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context)
+{
+    if (!uart_text_input)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
+        return false;
+    }
+    *uart_text_input = uart_text_input_alloc();
+    if (!*uart_text_input)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
+        return false;
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
+    }
+    if (header_text)
+    {
+        uart_text_input_set_header_text(*uart_text_input, header_text);
+    }
+    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
+    {
+        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    return true;
+}
+
+/**
+ * @brief Initialize a DialogEx object
+ * @param dialog_ex The DialogEx object to initialize
+ * @param view_id The ID/Index of the view
+ * @param header The header of the dialog
+ * @param header_x The x coordinate of the header
+ * @param header_y The y coordinate of the header
+ * @param text The text of the dialog
+ * @param text_x The x coordinate of the dialog
+ * @param text_y The y coordinate of the dialog
+ * @param left_button_text The text of the left button
+ * @param right_button_text The text of the right button
+ * @param center_button_text The text of the center button
+ * @param result_callback The result callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the result callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_dialog_ex(
+    DialogEx **dialog_ex,
+    int32_t view_id,
+    char *header,
+    uint16_t header_x,
+    uint16_t header_y,
+    char *text,
+    uint16_t text_x,
+    uint16_t text_y,
+    char *left_button_text,
+    char *right_button_text,
+    char *center_button_text,
+    void (*result_callback)(DialogExResult, void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context)
+{
+    if (!dialog_ex)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
+        return false;
+    }
+    *dialog_ex = dialog_ex_alloc();
+    if (!*dialog_ex)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
+        return false;
+    }
+    if (header)
+    {
+        dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
+    }
+    if (text)
+    {
+        dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
+    }
+    if (left_button_text)
+    {
+        dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
+    }
+    if (right_button_text)
+    {
+        dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
+    }
+    if (center_button_text)
+    {
+        dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
+    }
+    if (result_callback)
+    {
+        dialog_ex_set_result_callback(*dialog_ex, result_callback);
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
+    }
+    if (context)
+    {
+        dialog_ex_set_context(*dialog_ex, context);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
+    return true;
+}
+
+/**
+ * @brief Initialize a Popup object
+ * @param popup The Popup object to initialize
+ * @param view_id The ID/Index of the view
+ * @param header The header of the dialog
+ * @param header_x The x coordinate of the header
+ * @param header_y The y coordinate of the header
+ * @param text The text of the dialog
+ * @param text_x The x coordinate of the dialog
+ * @param text_y The y coordinate of the dialog
+ * @param result_callback The result callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the result callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_popup(
+    Popup **popup,
+    int32_t view_id,
+    char *header,
+    uint16_t header_x,
+    uint16_t header_y,
+    char *text,
+    uint16_t text_x,
+    uint16_t text_y,
+    void (*result_callback)(void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context)
+{
+    if (!popup)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
+        return false;
+    }
+    *popup = popup_alloc();
+    if (!*popup)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
+        return false;
+    }
+    if (header)
+    {
+        popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
+    }
+    if (text)
+    {
+        popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
+    }
+    if (result_callback)
+    {
+        popup_set_callback(*popup, result_callback);
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(popup_get_view(*popup), previous_callback);
+    }
+    if (context)
+    {
+        popup_set_context(*popup, context);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
+    return true;
+}
+
+/**
+ * @brief Initialize a Loading object
+ * @param loading The Loading object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_loading(
+    Loading **loading,
+    int32_t view_id,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher)
+{
+    if (!loading)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
+        return false;
+    }
+    *loading = loading_alloc();
+    if (!*loading)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
+        return false;
+    }
+    if (previous_callback)
+    {
+        view_set_previous_callback(loading_get_view(*loading), previous_callback);
+    }
+    view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
+    return true;
+}
+
+/**
+ * @brief Set a char butter to a FuriString
+ * @param furi_string The FuriString object
+ * @param buffer The buffer to copy the string to
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
+{
+    if (!furi_string)
+    {
+        FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
+        return false;
+    }
+    *furi_string = furi_string_alloc();
+    if (!furi_string)
+    {
+        FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
+        return false;
+    }
+    furi_string_set_str(*furi_string, buffer);
+    return true;
+}

+ 269 - 0
easy_flipper/easy_flipper.h

@@ -0,0 +1,269 @@
+#ifndef EASY_FLIPPER_H
+#define EASY_FLIPPER_H
+
+#include <malloc.h>
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <gui/view.h>
+#include <gui/modules/submenu.h>
+#include <gui/view_dispatcher.h>
+#include <gui/elements.h>
+#include <gui/modules/menu.h>
+#include <gui/modules/submenu.h>
+#include <gui/modules/widget.h>
+#include <gui/modules/text_input.h>
+#include <gui/modules/text_box.h>
+#include <gui/modules/variable_item_list.h>
+#include <gui/modules/dialog_ex.h>
+#include <notification/notification.h>
+#include <dialogs/dialogs.h>
+#include <gui/modules/popup.h>
+#include <gui/modules/loading.h>
+#include <text_input/uart_text_input.h>
+#include <stdio.h>
+#include <string.h>
+#include <jsmn/jsmn.h>
+
+#define EASY_TAG "EasyFlipper"
+
+void easy_flipper_dialog(
+    char *header,
+    char *text);
+
+/**
+ * @brief Navigation callback for exiting the application
+ * @param context The context - unused
+ * @return next view id (VIEW_NONE to exit the app)
+ */
+uint32_t easy_flipper_callback_exit_app(void *context);
+/**
+ * @brief Initialize a buffer
+ * @param buffer The buffer to initialize
+ * @param buffer_size The size of the buffer
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size);
+/**
+ * @brief Initialize a View object
+ * @param view The View object to initialize
+ * @param view_id The ID/Index of the view
+ * @param draw_callback The draw callback function (set to NULL if not needed)
+ * @param input_callback The input callback function (set to NULL if not needed)
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_view(
+    View **view,
+    int32_t view_id,
+    void draw_callback(Canvas *, void *),
+    bool input_callback(InputEvent *, void *),
+    uint32_t (*previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context);
+
+/**
+ * @brief Initialize a ViewDispatcher object
+ * @param view_dispatcher The ViewDispatcher object to initialize
+ * @param gui The GUI object
+ * @param context The context to pass to the event callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context);
+
+/**
+ * @brief Initialize a Submenu object
+ * @note This does not set the items in the submenu
+ * @param submenu The Submenu object to initialize
+ * @param view_id The ID/Index of the view
+ * @param title The title/header of the submenu
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_submenu(
+    Submenu **submenu,
+    int32_t view_id,
+    char *title,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher);
+
+/**
+ * @brief Initialize a Menu object
+ * @note This does not set the items in the menu
+ * @param menu The Menu object to initialize
+ * @param view_id The ID/Index of the view
+ * @param item_callback The item callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_menu(
+    Menu **menu,
+    int32_t view_id,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher);
+
+/**
+ * @brief Initialize a Widget object
+ * @param widget The Widget object to initialize
+ * @param view_id The ID/Index of the view
+ * @param text The text to display in the widget
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_widget(
+    Widget **widget,
+    int32_t view_id,
+    char *text,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher);
+
+/**
+ * @brief Initialize a VariableItemList object
+ * @note This does not set the items in the VariableItemList
+ * @param variable_item_list The VariableItemList object to initialize
+ * @param view_id The ID/Index of the view
+ * @param enter_callback The enter callback function (can be set to NULL)
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the enter callback (usually the app)
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_variable_item_list(
+    VariableItemList **variable_item_list,
+    int32_t view_id,
+    void (*enter_callback)(void *, uint32_t),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context);
+
+/**
+ * @brief Initialize a TextInput object
+ * @param text_input The TextInput object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_text_input(
+    TextInput **text_input,
+    int32_t view_id,
+    char *header_text,
+    char *text_input_temp_buffer,
+    uint32_t text_input_buffer_size,
+    void (*result_callback)(void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context);
+
+/**
+ * @brief Initialize a UART_TextInput object
+ * @param uart_text_input The UART_TextInput object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_uart_text_input(
+    UART_TextInput **uart_text_input,
+    int32_t view_id,
+    char *header_text,
+    char *uart_text_input_temp_buffer,
+    uint32_t uart_text_input_buffer_size,
+    void (*result_callback)(void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context);
+
+/**
+ * @brief Initialize a DialogEx object
+ * @param dialog_ex The DialogEx object to initialize
+ * @param view_id The ID/Index of the view
+ * @param header The header of the dialog
+ * @param header_x The x coordinate of the header
+ * @param header_y The y coordinate of the header
+ * @param text The text of the dialog
+ * @param text_x The x coordinate of the dialog
+ * @param text_y The y coordinate of the dialog
+ * @param left_button_text The text of the left button
+ * @param right_button_text The text of the right button
+ * @param center_button_text The text of the center button
+ * @param result_callback The result callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the result callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_dialog_ex(
+    DialogEx **dialog_ex,
+    int32_t view_id,
+    char *header,
+    uint16_t header_x,
+    uint16_t header_y,
+    char *text,
+    uint16_t text_x,
+    uint16_t text_y,
+    char *left_button_text,
+    char *right_button_text,
+    char *center_button_text,
+    void (*result_callback)(DialogExResult, void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context);
+
+/**
+ * @brief Initialize a Popup object
+ * @param popup The Popup object to initialize
+ * @param view_id The ID/Index of the view
+ * @param header The header of the dialog
+ * @param header_x The x coordinate of the header
+ * @param header_y The y coordinate of the header
+ * @param text The text of the dialog
+ * @param text_x The x coordinate of the dialog
+ * @param text_y The y coordinate of the dialog
+ * @param result_callback The result callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the result callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_popup(
+    Popup **popup,
+    int32_t view_id,
+    char *header,
+    uint16_t header_x,
+    uint16_t header_y,
+    char *text,
+    uint16_t text_x,
+    uint16_t text_y,
+    void (*result_callback)(void *),
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher,
+    void *context);
+
+/**
+ * @brief Initialize a Loading object
+ * @param loading The Loading object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_loading(
+    Loading **loading,
+    int32_t view_id,
+    uint32_t(previous_callback)(void *),
+    ViewDispatcher **view_dispatcher);
+
+/**
+ * @brief Set a char butter to a FuriString
+ * @param furi_string The FuriString object
+ * @param buffer The buffer to copy the string to
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer);
+
+#endif

+ 674 - 0
engine/LICENSE

@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 28 - 0
engine/canvas.c

@@ -0,0 +1,28 @@
+#include <furi.h>
+#include "canvas.h"
+
+void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...) {
+    FuriString* string = furi_string_alloc();
+    va_list args;
+    va_start(args, format);
+    furi_string_vprintf(string, format, args);
+    va_end(args);
+
+    canvas_draw_str(canvas, x, y, furi_string_get_cstr(string));
+
+    furi_string_free(string);
+}
+
+size_t canvas_printf_width(Canvas* canvas, const char* format, ...) {
+    FuriString* string = furi_string_alloc();
+    va_list args;
+    va_start(args, format);
+    furi_string_vprintf(string, format, args);
+    va_end(args);
+
+    size_t size = canvas_string_width(canvas, furi_string_get_cstr(string));
+
+    furi_string_free(string);
+
+    return size;
+}

+ 32 - 0
engine/canvas.h

@@ -0,0 +1,32 @@
+#pragma once
+#include <stddef.h>
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Print formatted string to canvas
+ * 
+ * @param canvas canvas instance
+ * @param x x position
+ * @param y y position
+ * @param format format string
+ * @param ...  arguments
+ */
+void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...);
+
+/**
+ * @brief Get width of formatted string
+ * 
+ * @param canvas canvas instance
+ * @param format format string
+ * @param ... arguments
+ * @return size_t width of formatted string
+ */
+size_t canvas_printf_width(Canvas* canvas, const char* format, ...);
+
+#ifdef __cplusplus
+}
+#endif

+ 53 - 0
engine/clock_timer.c

@@ -0,0 +1,53 @@
+#include "clock_timer.h"
+#include <stdlib.h>
+
+#include <furi_hal_interrupt.h>
+#include <furi_hal_bus.h>
+#include <stm32wbxx_ll_tim.h>
+
+#define FURI_HAL_CLOCK_TIMER TIM2
+#define FURI_HAL_CLOCK_TIMER_BUS FuriHalBusTIM2
+#define FURI_HAL_CLOCK_TIMER_IRQ FuriHalInterruptIdTIM2
+
+typedef struct {
+    ClockTimerCallback callback;
+    void* context;
+} ClockTimer;
+
+static ClockTimer clock_timer = {
+    .callback = NULL,
+    .context = NULL,
+};
+
+static void clock_timer_isr(void* context) {
+    if(clock_timer.callback) {
+        clock_timer.callback(context);
+    }
+
+    LL_TIM_ClearFlag_UPDATE(FURI_HAL_CLOCK_TIMER);
+}
+
+void clock_timer_start(ClockTimerCallback callback, void* context, float period) {
+    clock_timer.callback = callback;
+    clock_timer.context = context;
+
+    furi_hal_bus_enable(FURI_HAL_CLOCK_TIMER_BUS);
+
+    // init timer to produce interrupts
+    LL_TIM_InitTypeDef TIM_InitStruct = {0};
+    TIM_InitStruct.Autoreload = (SystemCoreClock / period) - 1;
+    LL_TIM_Init(FURI_HAL_CLOCK_TIMER, &TIM_InitStruct);
+
+    furi_hal_interrupt_set_isr(FURI_HAL_CLOCK_TIMER_IRQ, clock_timer_isr, clock_timer.context);
+
+    LL_TIM_EnableIT_UPDATE(FURI_HAL_CLOCK_TIMER);
+    LL_TIM_EnableCounter(FURI_HAL_CLOCK_TIMER);
+}
+
+void clock_timer_stop(void) {
+    LL_TIM_DisableIT_UPDATE(FURI_HAL_CLOCK_TIMER);
+    LL_TIM_DisableCounter(FURI_HAL_CLOCK_TIMER);
+
+    furi_hal_bus_disable(FURI_HAL_CLOCK_TIMER_BUS);
+    furi_hal_interrupt_set_isr(FURI_HAL_CLOCK_TIMER_IRQ, NULL, NULL);
+}

+ 15 - 0
engine/clock_timer.h

@@ -0,0 +1,15 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*ClockTimerCallback)(void* context);
+
+void clock_timer_start(ClockTimerCallback callback, void* context, float period);
+
+void clock_timer_stop(void);
+
+#ifdef __cplusplus
+}
+#endif

+ 25 - 0
engine/engine.h

@@ -0,0 +1,25 @@
+#pragma once
+#include <furi.h>
+#include "game_engine.h"
+#include "level.h"
+#include "entity.h"
+#include "game_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+    float target_fps;
+    bool show_fps;
+    bool always_backlight;
+    void (*start)(GameManager* game_manager, void* context);
+    void (*stop)(void* context);
+    size_t context_size;
+} Game;
+
+extern const Game game;
+
+#ifdef __cplusplus
+}
+#endif

+ 217 - 0
engine/entity.c

@@ -0,0 +1,217 @@
+#include "entity.h"
+#include "entity_i.h"
+#include <stdlib.h>
+#include <furi.h>
+
+#ifdef ENTITY_DEBUG
+#define ENTITY_D(...) FURI_LOG_D("Entity", __VA_ARGS__)
+#else
+#define ENTITY_D(...)
+#endif
+
+static int32_t entities_count = 0;
+
+int32_t entities_get_count(void) {
+    return entities_count;
+}
+
+Entity* entity_alloc(const EntityDescription* description) {
+    entities_count++;
+    Entity* entity = malloc(sizeof(Entity));
+    entity->position = VECTOR_ZERO;
+    entity->description = description;
+    entity->context = NULL;
+    if(description && description->context_size > 0) {
+        entity->context = malloc(description->context_size);
+    }
+    entity->collider = NULL;
+    entity->collider_offset = VECTOR_ZERO;
+    ENTITY_D("Allocated at %p", entity);
+    entity->collider_dirty = false;
+    return entity;
+}
+
+void entity_collider_add_circle(Entity* entity, float radius) {
+    furi_check(entity->collider == NULL, "Collider already added");
+    entity->collider = malloc(sizeof(Collider));
+    entity->collider->type = ColliderTypeCircle;
+    entity->collider->circle.radius = radius;
+    entity->collider_dirty = true;
+}
+
+void entity_collider_add_rect(Entity* entity, float width, float height) {
+    furi_check(entity->collider == NULL, "Collider already added");
+    entity->collider = malloc(sizeof(Collider));
+    entity->collider->type = ColliderTypeRect;
+    entity->collider->rect.half_width = width / 2;
+    entity->collider->rect.half_height = height / 2;
+    entity->collider_dirty = true;
+}
+
+void entity_collider_remove(Entity* entity) {
+    furi_check(entity->collider != NULL, "Collider not added");
+    free(entity->collider);
+    entity->collider = NULL;
+    entity->collider_dirty = false;
+}
+
+void entity_collider_offset_set(Entity* entity, Vector offset) {
+    entity->collider_offset = offset;
+    entity->collider_dirty = true;
+}
+
+Vector entity_collider_offset_get(Entity* entity) {
+    return entity->collider_offset;
+}
+
+static Vector entity_collider_position_get(Entity* entity) {
+    return (Vector){
+        .x = entity->position.x + entity->collider_offset.x,
+        .y = entity->position.y + entity->collider_offset.y,
+    };
+}
+
+void entity_free(Entity* entity) {
+    entities_count--;
+    ENTITY_D("Freeing at %p", entity);
+    if(entity->context) {
+        free(entity->context);
+    }
+    if(entity->collider) {
+        free(entity->collider);
+    }
+    free(entity);
+}
+
+const EntityDescription* entity_description_get(Entity* entity) {
+    return entity->description;
+}
+
+Vector entity_pos_get(Entity* entity) {
+    return entity->position;
+}
+
+void entity_pos_set(Entity* entity, Vector position) {
+    entity->position = position;
+    entity->collider_dirty = true;
+}
+
+void* entity_context_get(Entity* entity) {
+    return entity->context;
+}
+
+void entity_call_start(Entity* entity, GameManager* manager) {
+    if(entity->description && entity->description->start) {
+        entity->description->start(entity, manager, entity->context);
+    }
+}
+
+void entity_call_stop(Entity* entity, GameManager* manager) {
+    if(entity->description && entity->description->stop) {
+        entity->description->stop(entity, manager, entity->context);
+    }
+}
+
+void entity_call_update(Entity* entity, GameManager* manager) {
+    if(entity->description && entity->description->update) {
+        entity->description->update(entity, manager, entity->context);
+    }
+}
+
+void entity_call_render(Entity* entity, GameManager* manager, Canvas* canvas) {
+    if(entity->description && entity->description->render) {
+        entity->description->render(entity, manager, canvas, entity->context);
+    }
+}
+
+void entity_call_collision(Entity* entity, Entity* other, GameManager* manager) {
+    if(entity->description && entity->description->collision) {
+        entity->description->collision(entity, other, manager, entity->context);
+    }
+}
+
+bool entity_collider_circle_circle(Entity* entity, Entity* other) {
+    Vector pos1 = entity_collider_position_get(entity);
+    Vector pos2 = entity_collider_position_get(other);
+
+    float dx = pos1.x - pos2.x;
+    float dy = pos1.y - pos2.y;
+    float distance = sqrtf(dx * dx + dy * dy);
+    return distance < entity->collider->circle.radius + other->collider->circle.radius;
+}
+
+bool entity_collider_rect_rect(Entity* entity, Entity* other) {
+    Vector pos1 = entity_collider_position_get(entity);
+    Vector pos2 = entity_collider_position_get(other);
+
+    float left1 = pos1.x - entity->collider->rect.half_width;
+    float right1 = pos1.x + entity->collider->rect.half_width;
+    float top1 = pos1.y - entity->collider->rect.half_height;
+    float bottom1 = pos1.y + entity->collider->rect.half_height;
+
+    float left2 = pos2.x - other->collider->rect.half_width;
+    float right2 = pos2.x + other->collider->rect.half_width;
+    float top2 = pos2.y - other->collider->rect.half_height;
+    float bottom2 = pos2.y + other->collider->rect.half_height;
+
+    return left1 < right2 && right1 > left2 && top1 < bottom2 && bottom1 > top2;
+}
+
+bool entity_collider_circle_rect(Entity* circle, Entity* rect) {
+    Vector pos1 = entity_collider_position_get(circle);
+    Vector pos2 = entity_collider_position_get(rect);
+
+    float left = pos2.x - rect->collider->rect.half_width;
+    float right = pos2.x + rect->collider->rect.half_width;
+    float top = pos2.y - rect->collider->rect.half_height;
+    float bottom = pos2.y + rect->collider->rect.half_height;
+
+    float closestX = fmaxf(left, fminf(pos1.x, right));
+    float closestY = fmaxf(top, fminf(pos1.y, bottom));
+
+    float dx = pos1.x - closestX;
+    float dy = pos1.y - closestY;
+    float distance = sqrtf(dx * dx + dy * dy);
+    return distance < circle->collider->circle.radius;
+}
+
+bool entity_collider_check_collision(Entity* entity, Entity* other) {
+    furi_check(entity->collider);
+    furi_check(other->collider);
+
+    if(entity->collider->type == ColliderTypeCircle) {
+        Entity* circle = entity;
+        if(other->collider->type == ColliderTypeCircle) {
+            return entity_collider_circle_circle(circle, other);
+        } else {
+            return entity_collider_circle_rect(circle, other);
+        }
+    } else {
+        Entity* rect = entity;
+        if(other->collider->type == ColliderTypeCircle) {
+            return entity_collider_circle_rect(other, rect);
+        } else {
+            return entity_collider_rect_rect(rect, other);
+        }
+    }
+}
+
+bool entity_collider_exists(Entity* entity) {
+    return entity->collider != NULL;
+}
+
+void entity_send_event(
+    Entity* sender,
+    Entity* receiver,
+    GameManager* manager,
+    uint32_t type,
+    EntityEventValue value) {
+    if(receiver->description && receiver->description->event) {
+        EntityEvent event = {
+            .type = type,
+            .sender = sender,
+            .value = value,
+        };
+        receiver->description->event(receiver, manager, event, receiver->context);
+    }
+}

+ 65 - 0
engine/entity.h

@@ -0,0 +1,65 @@
+#pragma once
+#include "vector.h"
+#include "game_engine.h"
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Entity Entity;
+
+typedef struct Level Level;
+
+typedef union {
+    uint32_t value;
+    void* pointer;
+} EntityEventValue;
+
+typedef struct {
+    uint32_t type;
+    Entity* sender;
+    EntityEventValue value;
+} EntityEvent;
+
+typedef struct Level Level;
+typedef struct GameManager GameManager;
+
+typedef struct {
+    void (*start)(Entity* self, GameManager* manager, void* context);
+    void (*stop)(Entity* self, GameManager* manager, void* context);
+    void (*update)(Entity* self, GameManager* manager, void* context);
+    void (*render)(Entity* self, GameManager* manager, Canvas* canvas, void* context);
+    void (*collision)(Entity* self, Entity* other, GameManager* manager, void* context);
+    void (*event)(Entity* self, GameManager* manager, EntityEvent event, void* context);
+    size_t context_size;
+} EntityDescription;
+
+const EntityDescription* entity_description_get(Entity* entity);
+
+Vector entity_pos_get(Entity* entity);
+
+void entity_pos_set(Entity* entity, Vector position);
+
+void* entity_context_get(Entity* entity);
+
+void entity_collider_add_circle(Entity* entity, float radius);
+
+void entity_collider_add_rect(Entity* entity, float width, float height);
+
+void entity_collider_remove(Entity* entity);
+
+void entity_collider_offset_set(Entity* entity, Vector offset);
+
+Vector entity_collider_offset_get(Entity* entity);
+
+void entity_send_event(
+    Entity* sender,
+    Entity* receiver,
+    GameManager* manager,
+    uint32_t type,
+    EntityEventValue value);
+
+#ifdef __cplusplus
+}
+#endif

+ 58 - 0
engine/entity_i.h

@@ -0,0 +1,58 @@
+#pragma once
+#include "entity.h"
+#include "game_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    ColliderTypeCircle,
+    ColliderTypeRect,
+} ColliderType;
+
+typedef struct {
+    ColliderType type;
+    union {
+        struct {
+            float radius;
+        } circle;
+        struct {
+            float half_width;
+            float half_height;
+        } rect;
+    };
+} Collider;
+
+struct Entity {
+    Vector position;
+    const EntityDescription* description;
+    void* context;
+    Collider* collider;
+    Vector collider_offset;
+    bool collider_dirty;
+};
+
+Entity* entity_alloc(const EntityDescription* behaviour);
+
+void entity_free(Entity* entity);
+
+void entity_call_start(Entity* entity, GameManager* manager);
+
+void entity_call_stop(Entity* entity, GameManager* manager);
+
+void entity_call_update(Entity* entity, GameManager* manager);
+
+void entity_call_render(Entity* entity, GameManager* manager, Canvas* canvas);
+
+void entity_call_collision(Entity* entity, Entity* other, GameManager* manager);
+
+bool entity_collider_check_collision(Entity* entity, Entity* other);
+
+bool entity_collider_exists(Entity* entity);
+
+int32_t entities_get_count(void);
+
+#ifdef __cplusplus
+}
+#endif

+ 199 - 0
engine/game_engine.c

@@ -0,0 +1,199 @@
+#include "game_engine.h"
+#include <furi.h>
+#include <gui/gui.h>
+#include <input/input.h>
+#include <notification/notification_messages.h>
+#include "clock_timer.h"
+
+typedef _Atomic uint32_t AtomicUint32;
+
+GameEngineSettings game_engine_settings_init() {
+    GameEngineSettings settings;
+    settings.target_fps = 30.0f;
+    settings.show_fps = false;
+    settings.always_backlight = true;
+    settings.start_callback = NULL;
+    settings.frame_callback = NULL;
+    settings.stop_callback = NULL;
+    settings.context = NULL;
+    return settings;
+}
+
+struct GameEngine {
+    Gui* gui;
+    NotificationApp* notifications;
+    FuriPubSub* input_pubsub;
+    FuriThreadId thread_id;
+    GameEngineSettings settings;
+    float fps;
+};
+
+typedef enum {
+    GameThreadFlagUpdate = 1 << 0,
+    GameThreadFlagStop = 1 << 1,
+} GameThreadFlag;
+
+#define GameThreadFlagMask (GameThreadFlagUpdate | GameThreadFlagStop)
+
+GameEngine* game_engine_alloc(GameEngineSettings settings) {
+    furi_check(settings.frame_callback != NULL);
+
+    GameEngine* engine = malloc(sizeof(GameEngine));
+    engine->gui = furi_record_open(RECORD_GUI);
+    engine->notifications = furi_record_open(RECORD_NOTIFICATION);
+    engine->input_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
+    engine->thread_id = furi_thread_get_current_id();
+    engine->settings = settings;
+    engine->fps = 1.0f;
+
+    return engine;
+}
+
+void game_engine_free(GameEngine* engine) {
+    furi_record_close(RECORD_GUI);
+    furi_record_close(RECORD_NOTIFICATION);
+    furi_record_close(RECORD_INPUT_EVENTS);
+    free(engine);
+}
+
+static void clock_timer_callback(void* context) {
+    GameEngine* engine = context;
+    furi_thread_flags_set(engine->thread_id, GameThreadFlagUpdate);
+}
+
+static const GameKey keys[] = {
+    [InputKeyUp] = GameKeyUp,
+    [InputKeyDown] = GameKeyDown,
+    [InputKeyRight] = GameKeyRight,
+    [InputKeyLeft] = GameKeyLeft,
+    [InputKeyOk] = GameKeyOk,
+    [InputKeyBack] = GameKeyBack,
+};
+
+static const size_t keys_count = sizeof(keys) / sizeof(keys[0]);
+
+static void input_events_callback(const void* value, void* context) {
+    AtomicUint32* input_state = context;
+    const InputEvent* event = value;
+
+    if(event->key < keys_count) {
+        switch(event->type) {
+        case InputTypePress:
+            *input_state |= (keys[event->key]);
+            break;
+        case InputTypeRelease:
+            *input_state &= ~(keys[event->key]);
+            break;
+        default:
+            break;
+        }
+    }
+}
+
+void game_engine_run(GameEngine* engine) {
+    // input state
+    AtomicUint32 input_state = 0;
+    uint32_t input_prev_state = 0;
+
+    // set backlight if needed
+    if(engine->settings.always_backlight) {
+        notification_message(engine->notifications, &sequence_display_backlight_enforce_on);
+    }
+
+    // acquire gui canvas
+    Canvas* canvas = gui_direct_draw_acquire(engine->gui);
+
+    // subscribe to input events
+    FuriPubSubSubscription* input_subscription =
+        furi_pubsub_subscribe(engine->input_pubsub, input_events_callback, &input_state);
+
+    // call start callback, if any
+    if(engine->settings.start_callback) {
+        engine->settings.start_callback(engine, engine->settings.context);
+    }
+
+    // start "game update" timer
+    clock_timer_start(clock_timer_callback, engine, engine->settings.target_fps);
+
+    // init fps counter
+    uint32_t time_start = DWT->CYCCNT;
+
+    while(true) {
+        uint32_t flags =
+            furi_thread_flags_wait(GameThreadFlagMask, FuriFlagWaitAny, FuriWaitForever);
+        furi_check((flags & FuriFlagError) == 0);
+
+        if(flags & GameThreadFlagUpdate) {
+            // update fps counter
+            uint32_t time_end = DWT->CYCCNT;
+            uint32_t time_delta = time_end - time_start;
+            time_start = time_end;
+
+            // update input state
+            uint32_t input_current_state = input_state;
+            InputState input = {
+                .held = input_current_state,
+                .pressed = input_current_state & ~input_prev_state,
+                .released = ~input_current_state & input_prev_state,
+            };
+            input_prev_state = input_current_state;
+
+            // clear screen
+            canvas_reset(canvas);
+
+            // calculate actual fps
+            engine->fps = (float)SystemCoreClock / time_delta;
+
+            // do the work
+            engine->settings.frame_callback(engine, canvas, input, engine->settings.context);
+
+            // show fps if needed
+            if(engine->settings.show_fps) {
+                canvas_set_color(canvas, ColorXOR);
+                canvas_printf(canvas, 0, 7, "%u", (uint32_t)roundf(engine->fps));
+            }
+
+            // and output screen buffer
+            canvas_commit(canvas);
+
+            // throttle a bit
+            furi_delay_tick(2);
+        }
+
+        if(flags & GameThreadFlagStop) {
+            break;
+        }
+    }
+
+    // stop timer
+    clock_timer_stop();
+
+    // call stop callback, if any
+    if(engine->settings.stop_callback) {
+        engine->settings.stop_callback(engine, engine->settings.context);
+    }
+
+    // release gui canvas and unsubscribe from input events
+    gui_direct_draw_release(engine->gui);
+    furi_pubsub_unsubscribe(engine->input_pubsub, input_subscription);
+
+    if(engine->settings.always_backlight) {
+        notification_message(engine->notifications, &sequence_display_backlight_enforce_auto);
+    }
+}
+
+void game_engine_stop(GameEngine* engine) {
+    furi_thread_flags_set(engine->thread_id, GameThreadFlagStop);
+}
+
+float game_engine_get_delta_time(GameEngine* engine) {
+    return 1.0f / engine->fps;
+}
+
+float game_engine_get_delta_frames(GameEngine* engine) {
+    return engine->fps / engine->settings.target_fps;
+}
+
+void game_engine_show_fps_set(GameEngine* engine, bool show_fps) {
+    engine->settings.show_fps = show_fps;
+}

+ 88 - 0
engine/game_engine.h

@@ -0,0 +1,88 @@
+#pragma once
+#include <stdbool.h>
+#include "canvas.h"
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    GameKeyUp = 1 << 0,
+    GameKeyDown = 1 << 1,
+    GameKeyRight = 1 << 2,
+    GameKeyLeft = 1 << 3,
+    GameKeyOk = 1 << 4,
+    GameKeyBack = 1 << 5,
+} GameKey;
+
+typedef struct {
+    uint32_t held; // mask of GameKey held in current frame
+    uint32_t pressed; // mask of GameKey pressed in current frame
+    uint32_t released; // mask of GameKey released in current frame
+} InputState;
+
+typedef struct GameEngine GameEngine;
+
+typedef void (*GameEngineStartCallback)(GameEngine* engine, void* context);
+
+typedef void (*GameEngineStopCallback)(GameEngine* engine, void* context);
+
+typedef void (
+    *GameEngineFrameCallback)(GameEngine* engine, Canvas* canvas, InputState input, void* context);
+
+typedef struct {
+    float target_fps; // target fps
+    bool show_fps; // show fps counter
+    bool always_backlight; // keep backlight on
+    GameEngineStartCallback start_callback; // called when engine starts
+    GameEngineFrameCallback frame_callback; // frame callback, called at target fps
+    GameEngineStopCallback stop_callback; // called when engine stops
+    void* context; // user context passed to callback
+} GameEngineSettings;
+
+/** Default settings initializer */
+GameEngineSettings game_engine_settings_init(void);
+
+/** Game Engine allocator
+ * @param settings engine settings
+ * @return GameEngine*  GameEngine instance
+ */
+GameEngine* game_engine_alloc(GameEngineSettings settings);
+
+/** Run the Game Engine. Blocks until game_engine_stop() is called.
+ * @param engine GameEngine instance
+ */
+void game_engine_run(GameEngine* engine);
+
+/** Free the Game Engine
+ * @param engine GameEngine instance
+ */
+void game_engine_free(GameEngine* engine);
+
+/** Stop the Game Engine, will not block execution
+ * @param engine GameEngine instance
+ */
+void game_engine_stop(GameEngine* engine);
+
+/** Get delta time between current and previous frame
+ * @param engine GameEngine instance
+ * @return float  delta time in seconds
+ */
+float game_engine_get_delta_time(GameEngine* engine);
+
+/** Get delta frames between current and previous frame
+ * @param engine GameEngine instance
+ * @return float  delta frames
+ */
+float game_engine_get_delta_frames(GameEngine* engine);
+
+/** Enable/disable show fps counter
+ * @param engine GameEngine instance
+ * @param show_fps show fps counter
+ */
+void game_engine_show_fps_set(GameEngine* engine, bool show_fps);
+
+#ifdef __cplusplus
+}
+#endif

+ 162 - 0
engine/game_manager.c

@@ -0,0 +1,162 @@
+#include "game_manager.h"
+#include "level_i.h"
+#include <furi.h>
+#include <m-list.h>
+#include <storage/storage.h>
+
+typedef struct {
+    Sprite* sprite;
+    FuriString* path;
+} SpriteCache;
+
+LIST_DEF(LevelList, Level*, M_POD_OPLIST);
+LIST_DEF(SpriteCacheList, SpriteCache, M_POD_OPLIST);
+
+struct GameManager {
+    LevelList_t levels;
+    Level* current_level;
+    Level* next_level;
+
+    GameEngine* engine;
+    InputState input;
+    void* game_context;
+
+    SpriteCacheList_t sprites;
+};
+
+GameManager* game_manager_alloc() {
+    GameManager* manager = malloc(sizeof(GameManager));
+    LevelList_init(manager->levels);
+    manager->current_level = NULL;
+    manager->next_level = NULL;
+    manager->engine = NULL;
+    manager->game_context = NULL;
+    memset(&manager->input, 0, sizeof(InputState));
+    SpriteCacheList_init(manager->sprites);
+    return manager;
+}
+
+void game_manager_free(GameManager* manager) {
+    level_call_stop(manager->current_level);
+
+    // Free all levels
+    {
+        LevelList_it_t it;
+        LevelList_it(it, manager->levels);
+        while(!LevelList_end_p(it)) {
+            level_call_free(*LevelList_cref(it));
+            level_free(*LevelList_cref(it));
+            LevelList_next(it);
+        }
+    }
+
+    LevelList_clear(manager->levels);
+
+    // Free all sprites
+    {
+        SpriteCacheList_it_t it;
+        SpriteCacheList_it(it, manager->sprites);
+        while(!SpriteCacheList_end_p(it)) {
+            furi_string_free(SpriteCacheList_cref(it)->path);
+            sprite_free(SpriteCacheList_cref(it)->sprite);
+            SpriteCacheList_next(it);
+        }
+    }
+    SpriteCacheList_clear(manager->sprites);
+    free(manager);
+}
+
+Level* game_manager_add_level(GameManager* manager, const LevelBehaviour* behaviour) {
+    UNUSED(manager);
+    Level* level = level_alloc(behaviour, manager);
+    LevelList_push_back(manager->levels, level);
+    level_call_alloc(level);
+    if(!manager->current_level) {
+        manager->current_level = level;
+        level_call_start(level);
+    }
+    return level;
+}
+
+void game_manager_next_level_set(GameManager* manager, Level* next_level) {
+    manager->next_level = next_level;
+}
+
+void game_manager_game_stop(GameManager* manager) {
+    GameEngine* engine = game_manager_engine_get(manager);
+    game_engine_stop(engine);
+}
+
+Level* game_manager_current_level_get(GameManager* manager) {
+    return manager->current_level;
+}
+
+void game_manager_update(GameManager* manager) {
+    if(manager->next_level) {
+        level_call_stop(manager->current_level);
+        manager->current_level = manager->next_level;
+        level_call_start(manager->current_level);
+        manager->next_level = NULL;
+    }
+
+    level_update(manager->current_level, manager);
+}
+
+void game_manager_render(GameManager* manager, Canvas* canvas) {
+    level_render(manager->current_level, manager, canvas);
+}
+
+void game_manager_engine_set(GameManager* manager, GameEngine* engine) {
+    manager->engine = engine;
+}
+
+void game_manager_input_set(GameManager* manager, InputState input) {
+    manager->input = input;
+}
+
+void game_manager_game_context_set(GameManager* manager, void* context) {
+    manager->game_context = context;
+}
+
+GameEngine* game_manager_engine_get(GameManager* manager) {
+    return manager->engine;
+}
+
+InputState game_manager_input_get(GameManager* manager) {
+    return manager->input;
+}
+
+void* game_manager_game_context_get(GameManager* manager) {
+    return manager->game_context;
+}
+
+void game_manager_show_fps_set(GameManager* manager, bool show_fps) {
+    GameEngine* engine = game_manager_engine_get(manager);
+    game_engine_show_fps_set(engine, show_fps);
+}
+
+Sprite* game_manager_sprite_load(GameManager* manager, const char* path) {
+    SpriteCacheList_it_t it;
+    SpriteCacheList_it(it, manager->sprites);
+    while(!SpriteCacheList_end_p(it)) {
+        if(furi_string_cmp(SpriteCacheList_cref(it)->path, path) == 0) {
+            return SpriteCacheList_cref(it)->sprite;
+        }
+        SpriteCacheList_next(it);
+    }
+
+    FuriString* path_full = furi_string_alloc_set(APP_ASSETS_PATH("sprites/"));
+    furi_string_cat(path_full, path);
+
+    Sprite* sprite = sprite_alloc(furi_string_get_cstr(path_full));
+    if(sprite) {
+        SpriteCache cache = {
+            .sprite = sprite,
+            .path = furi_string_alloc_set(path),
+        };
+        SpriteCacheList_push_back(manager->sprites, cache);
+    }
+    furi_string_free(path_full);
+
+    return sprite;
+}

+ 40 - 0
engine/game_manager.h

@@ -0,0 +1,40 @@
+#pragma once
+#include "level.h"
+#include "game_engine.h"
+#include "sprite.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct GameManager GameManager;
+
+Level* game_manager_add_level(GameManager* manager, const LevelBehaviour* behaviour);
+
+void game_manager_next_level_set(GameManager* manager, Level* level);
+
+Level* game_manager_current_level_get(GameManager* manager);
+
+GameEngine* game_manager_engine_get(GameManager* manager);
+
+InputState game_manager_input_get(GameManager* manager);
+
+void* game_manager_game_context_get(GameManager* manager);
+
+void game_manager_game_stop(GameManager* manager);
+
+void game_manager_show_fps_set(GameManager* manager, bool show_fps);
+
+/**
+ * @brief Load a sprite from a file
+ * Sprite will be cached and reused if the same file is loaded again
+ * 
+ * @param manager game manager instance
+ * @param path sprite file path, relative to the game's assets folder
+ * @return Sprite* or NULL if the sprite could not be loaded
+ */
+Sprite* game_manager_sprite_load(GameManager* manager, const char* path);
+
+#ifdef __cplusplus
+}
+#endif

+ 24 - 0
engine/game_manager_i.h

@@ -0,0 +1,24 @@
+#pragma once
+#include "game_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+GameManager* game_manager_alloc(void);
+
+void game_manager_free(GameManager* manager);
+
+void game_manager_update(GameManager* manager);
+
+void game_manager_render(GameManager* manager, Canvas* canvas);
+
+void game_manager_engine_set(GameManager* manager, GameEngine* engine);
+
+void game_manager_input_set(GameManager* manager, InputState input);
+
+void game_manager_game_context_set(GameManager* manager, void* context);
+
+#ifdef __cplusplus
+}
+#endif

+ 214 - 0
engine/level.c

@@ -0,0 +1,214 @@
+#include "level.h"
+#include "level_i.h"
+#include "entity_i.h"
+#include <m-list.h>
+#include <furi.h>
+
+LIST_DEF(EntityList, Entity*, M_POD_OPLIST);
+#define M_OPL_EntityList_t() LIST_OPLIST(EntityList)
+#define FOREACH(name, list) for \
+    M_EACH(name, list, EntityList_t)
+
+#define LEVEL_DEBUG(...) FURI_LOG_D("Level", __VA_ARGS__)
+#define LEVEL_ERROR(...) FURI_LOG_E("Level", __VA_ARGS__)
+
+struct Level {
+    EntityList_t entities;
+    EntityList_t to_add;
+    EntityList_t to_remove;
+    const LevelBehaviour* behaviour;
+    void* context;
+    GameManager* manager;
+};
+
+Level* level_alloc(const LevelBehaviour* behaviour, GameManager* manager) {
+    Level* level = malloc(sizeof(Level));
+    level->manager = manager;
+    EntityList_init(level->entities);
+    EntityList_init(level->to_add);
+    EntityList_init(level->to_remove);
+    level->behaviour = behaviour;
+    if(behaviour->context_size > 0) {
+        level->context = malloc(behaviour->context_size);
+    } else {
+        level->context = NULL;
+    }
+    LEVEL_DEBUG("Allocated level at %p", level);
+    return level;
+}
+
+static void level_process_add(Level* level) {
+    // move entities from to_add to entities
+    FOREACH(item, level->to_add) {
+        EntityList_push_back(level->entities, *item);
+    }
+    EntityList_clear(level->to_add);
+}
+
+static void level_process_remove(Level* level) {
+    // remove entities in to_remove from entities and free them
+    FOREACH(item, level->to_remove) {
+        entity_free(*item);
+        EntityList_it_t it;
+
+        // find and remove the entity from the entities list
+        for(EntityList_it(it, level->entities); !EntityList_end_p(it); EntityList_next(it)) {
+            if(*EntityList_ref(it) == *item) {
+                EntityList_remove(level->entities, it);
+                break;
+            }
+        }
+    }
+    EntityList_clear(level->to_remove);
+}
+
+static bool level_entity_in_list_p(EntityList_t list, Entity* entity) {
+    FOREACH(item, list) {
+        if(*item == entity) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void level_free(Level* level) {
+    level_clear(level);
+
+    EntityList_clear(level->entities);
+    EntityList_clear(level->to_add);
+    EntityList_clear(level->to_remove);
+
+    if(level->behaviour->context_size > 0) {
+        free(level->context);
+    }
+
+    LEVEL_DEBUG("Freeing level at %p", level);
+    free(level);
+}
+
+void level_clear(Level* level) {
+    size_t iterations = 0;
+
+    do {
+        // process to_add and to_remove
+        level_process_add(level);
+        level_process_remove(level);
+
+        // remove entities from entities list
+        FOREACH(item, level->entities) {
+            if(!level_entity_in_list_p(level->to_remove, *item)) {
+                level_remove_entity(level, *item);
+            }
+        }
+
+        // check if we are looping too many times
+        iterations++;
+        if(iterations >= 100) {
+            LEVEL_ERROR("Level free looped too many times");
+        }
+
+        // entity_call_stop can call level_remove_entity or level_add_entity
+        // so we need to process to_add and to_remove again
+    } while(!EntityList_empty_p(level->to_add) || !EntityList_empty_p(level->to_remove));
+}
+
+Entity* level_add_entity(Level* level, const EntityDescription* description) {
+    Entity* entity = entity_alloc(description);
+    EntityList_push_back(level->to_add, entity);
+    entity_call_start(entity, level->manager);
+    return entity;
+}
+
+void level_remove_entity(Level* level, Entity* entity) {
+    EntityList_push_back(level->to_remove, entity);
+    entity_call_stop(entity, level->manager);
+}
+
+void level_send_event(
+    Level* level,
+    Entity* sender,
+    const EntityDescription* receiver_desc,
+    uint32_t type,
+    EntityEventValue value) {
+    FOREACH(item, level->entities) {
+        if(receiver_desc == entity_description_get(*item) || receiver_desc == NULL) {
+            entity_send_event(sender, *item, level->manager, type, value);
+        }
+    }
+}
+
+static void level_process_update(Level* level, GameManager* manager) {
+    FOREACH(item, level->entities) {
+        entity_call_update(*item, manager);
+    }
+}
+
+static void level_process_collision(Level* level, GameManager* manager) {
+    EntityList_it_t it_first;
+    EntityList_it_t it_second;
+
+    EntityList_it(it_first, level->entities);
+    while(!EntityList_end_p(it_first)) {
+        Entity* first = *EntityList_ref(it_first);
+        if(entity_collider_exists(first)) {
+            // start second iterator at the next entity,
+            // so we don't check the same pair twice
+            EntityList_it_set(it_second, it_first);
+            EntityList_next(it_second);
+            while(!EntityList_end_p(it_second)) {
+                Entity* second = *EntityList_ref(it_second);
+                if(first->collider_dirty || second->collider_dirty) {
+                    if(entity_collider_exists(second)) {
+                        if(entity_collider_check_collision(first, second)) {
+                            entity_call_collision(first, second, manager);
+                            entity_call_collision(second, first, manager);
+                        }
+                    }
+                }
+                EntityList_next(it_second);
+            }
+        }
+        EntityList_next(it_first);
+    }
+
+    FOREACH(item, level->entities) {
+        (*item)->collider_dirty = false;
+    }
+}
+
+void level_update(Level* level, GameManager* manager) {
+    level_process_add(level);
+    level_process_remove(level);
+    level_process_update(level, manager);
+    level_process_collision(level, manager);
+}
+
+void level_render(Level* level, GameManager* manager, Canvas* canvas) {
+    FOREACH(item, level->entities) {
+        entity_call_render(*item, manager, canvas);
+    }
+}
+
+void level_call_start(Level* level) {
+    if(level->behaviour->start) {
+        level->behaviour->start(level, level->manager, level->context);
+    }
+}
+
+void level_call_stop(Level* level) {
+    if(level->behaviour->stop) {
+        level->behaviour->stop(level, level->manager, level->context);
+    }
+}
+
+void level_call_alloc(Level* level) {
+    if(level->behaviour->alloc) {
+        level->behaviour->alloc(level, level->manager, level->context);
+    }
+}
+
+void level_call_free(Level* level) {
+    if(level->behaviour->free) {
+        level->behaviour->free(level, level->manager, level->context);
+    }
+}

+ 61 - 0
engine/level.h

@@ -0,0 +1,61 @@
+#pragma once
+#include <stddef.h>
+#include "entity.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct GameManager GameManager;
+
+typedef struct {
+    void (*alloc)(Level* level, GameManager* manager, void* context);
+    void (*free)(Level* level, GameManager* manager, void* context);
+    void (*start)(Level* level, GameManager* manager, void* context);
+    void (*stop)(Level* level, GameManager* manager, void* context);
+    size_t context_size;
+} LevelBehaviour;
+
+/**
+ * @brief Remove all entities from the level
+ * 
+ * @param level level instance
+ */
+void level_clear(Level* level);
+
+/**
+ * @brief Add an entity to the level
+ * 
+ * @param level level instance
+ * @param behaviour entity behaviour
+ * @return Entity* 
+ */
+Entity* level_add_entity(Level* level, const EntityDescription* behaviour);
+
+/**
+ * @brief Remove an entity from the level
+ * 
+ * @param level level instance
+ * @param entity entity to remove
+ */
+void level_remove_entity(Level* level, Entity* entity);
+
+/**
+ * @brief Send an event to all entities of a certain type in the level
+ * 
+ * @param level level instance
+ * @param sender entity that sends the event
+ * @param receiver_desc entity description that will receive the event, NULL for all entities
+ * @param type event type
+ * @param value event value
+ */
+void level_send_event(
+    Level* level,
+    Entity* sender,
+    const EntityDescription* receiver_desc,
+    uint32_t type,
+    EntityEventValue value);
+
+#ifdef __cplusplus
+}
+#endif

+ 26 - 0
engine/level_i.h

@@ -0,0 +1,26 @@
+#pragma once
+#include "level.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+Level* level_alloc(const LevelBehaviour* behaviour, GameManager* manager);
+
+void level_free(Level* level);
+
+void level_update(Level* level, GameManager* manager);
+
+void level_render(Level* level, GameManager* manager, Canvas* canvas);
+
+void level_call_alloc(Level* level);
+
+void level_call_free(Level* level);
+
+void level_call_start(Level* level);
+
+void level_call_stop(Level* level);
+
+#ifdef __cplusplus
+}
+#endif

+ 59 - 0
engine/main.c

@@ -0,0 +1,59 @@
+#include <furi.h>
+#include "engine.h"
+#include "game_engine.h"
+#include "game_manager_i.h"
+#include "level_i.h"
+#include "entity_i.h"
+
+static void frame_cb(GameEngine *engine, Canvas *canvas, InputState input, void *context)
+{
+    UNUSED(engine);
+    GameManager *game_manager = context;
+    game_manager_input_set(game_manager, input);
+    game_manager_update(game_manager);
+    game_manager_render(game_manager, canvas);
+}
+
+int32_t game_app(void *p)
+{
+    UNUSED(p);
+    GameManager *game_manager = game_manager_alloc();
+
+    GameEngineSettings settings = game_engine_settings_init();
+    settings.target_fps = game.target_fps;
+    settings.show_fps = game.show_fps;
+    settings.always_backlight = game.always_backlight;
+    settings.frame_callback = frame_cb;
+    settings.context = game_manager;
+
+    GameEngine *engine = game_engine_alloc(settings);
+    game_manager_engine_set(game_manager, engine);
+
+    void *game_context = NULL;
+    if (game.context_size > 0)
+    {
+        game_context = malloc(game.context_size);
+        game_manager_game_context_set(game_manager, game_context);
+    }
+    game.start(game_manager, game_context);
+
+    game_engine_run(engine);
+    game_engine_free(engine);
+
+    game_manager_free(game_manager);
+
+    game.stop(game_context);
+    if (game_context)
+    {
+        free(game_context);
+    }
+
+    int32_t entities = entities_get_count();
+    if (entities != 0)
+    {
+        FURI_LOG_E("Game", "Memory leak detected: %ld entities still allocated", entities);
+        return -1;
+    }
+
+    return 0;
+}

+ 84 - 0
engine/scripts/sprite_builder.py

@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+import argparse
+import io
+import logging
+import os
+import struct
+
+from PIL import Image, ImageOps
+
+# XBM flipper sprite (.fxbm) is 1-bit depth, width-padded to 8 bits
+# file format:
+#   uint32 size of the rest of the file in bytes
+#   uint32 width in px
+#   uint32 height in px
+#   uint8[] pixel data, every row is padded to 8 bits (like XBM)
+
+def image2xbm(input_file_path):
+    with Image.open(input_file_path) as im:
+        with io.BytesIO() as output:
+            bw = im.convert("1")
+            bw = ImageOps.invert(bw)
+            bw.save(output, format="XBM")
+            return output.getvalue()
+
+def xbm2fxbm(data):
+    # hell as it is, but it works
+    f = io.StringIO(data.decode().strip())
+    width = int(f.readline().strip().split(" ")[2])
+    height = int(f.readline().strip().split(" ")[2])
+    data = f.read().strip().replace("\n", "").replace(" ", "").split("=")[1][:-1]
+    data_str = data[1:-1].replace(",", " ").replace("0x", "")
+    image_bin = bytearray.fromhex(data_str)
+
+    output = struct.pack("<I", len(image_bin) + 8)
+    output += struct.pack("<II", width, height)
+    output += image_bin
+    return output
+
+def process_sprites(input_dir, output_dir):
+    for root, dirs, files in os.walk(input_dir):
+        for file in files:
+            if file.startswith('.'):
+                continue
+            
+            try:
+                input_file_path = os.path.join(root, file)
+                rel_path = os.path.relpath(input_file_path, input_dir)
+                new_rel_path = os.path.splitext(rel_path)[0] + ".fxbm"
+                output_file_path = os.path.join(output_dir, new_rel_path)
+
+                os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
+
+                print(f"Converting '{rel_path}' to '{new_rel_path}'")
+                xbm = image2xbm(input_file_path)
+                img_data = xbm2fxbm(xbm)
+                with open(output_file_path, "wb") as f:
+                    f.write(img_data)
+            except Exception as e:
+                print(f"Cannot convert '{rel_path}': {e}")
+
+def clear_directory(directory):
+    for root, dirs, files in os.walk(directory, topdown=False):
+        for name in files:
+            os.remove(os.path.join(root, name))
+        for name in dirs:
+            os.rmdir(os.path.join(root, name))
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("source", help="Source directory")
+    parser.add_argument("target", help="Target directory")
+    args = parser.parse_args()
+
+    logging.basicConfig(level=logging.ERROR)
+    logger = logging.getLogger(__name__)
+    logger.debug(f"Building sprites from {args.source} to {args.target}")
+
+    clear_directory(args.target)
+    process_sprites(args.source, args.target)
+
+    return 0
+
+if __name__ == "__main__":
+    main()

+ 297 - 0
engine/sensors/ICM42688P/ICM42688P.c

@@ -0,0 +1,297 @@
+#include "ICM42688P_regs.h"
+#include "ICM42688P.h"
+
+#define TAG "ICM42688P"
+
+#define ICM42688P_TIMEOUT 100
+
+struct ICM42688P {
+    FuriHalSpiBusHandle* spi_bus;
+    const GpioPin* irq_pin;
+    float accel_scale;
+    float gyro_scale;
+};
+
+static const struct AccelFullScale {
+    float value;
+    uint8_t reg_mask;
+} accel_fs_modes[] = {
+    [AccelFullScale16G] = {16.f, ICM42688_AFS_16G},
+    [AccelFullScale8G] = {8.f, ICM42688_AFS_8G},
+    [AccelFullScale4G] = {4.f, ICM42688_AFS_4G},
+    [AccelFullScale2G] = {2.f, ICM42688_AFS_2G},
+};
+
+static const struct GyroFullScale {
+    float value;
+    uint8_t reg_mask;
+} gyro_fs_modes[] = {
+    [GyroFullScale2000DPS] = {2000.f, ICM42688_GFS_2000DPS},
+    [GyroFullScale1000DPS] = {1000.f, ICM42688_GFS_1000DPS},
+    [GyroFullScale500DPS] = {500.f, ICM42688_GFS_500DPS},
+    [GyroFullScale250DPS] = {250.f, ICM42688_GFS_250DPS},
+    [GyroFullScale125DPS] = {125.f, ICM42688_GFS_125DPS},
+    [GyroFullScale62_5DPS] = {62.5f, ICM42688_GFS_62_5DPS},
+    [GyroFullScale31_25DPS] = {31.25f, ICM42688_GFS_31_25DPS},
+    [GyroFullScale15_625DPS] = {15.625f, ICM42688_GFS_15_625DPS},
+};
+
+static bool icm42688p_write_reg(FuriHalSpiBusHandle* spi_bus, uint8_t addr, uint8_t value) {
+    bool res = false;
+    furi_hal_spi_acquire(spi_bus);
+    do {
+        uint8_t cmd_data[2] = {addr & 0x7F, value};
+        if(!furi_hal_spi_bus_tx(spi_bus, cmd_data, 2, ICM42688P_TIMEOUT)) break;
+        res = true;
+    } while(0);
+    furi_hal_spi_release(spi_bus);
+    return res;
+}
+
+static bool icm42688p_read_reg(FuriHalSpiBusHandle* spi_bus, uint8_t addr, uint8_t* value) {
+    bool res = false;
+    furi_hal_spi_acquire(spi_bus);
+    do {
+        uint8_t cmd_byte = addr | (1 << 7);
+        if(!furi_hal_spi_bus_tx(spi_bus, &cmd_byte, 1, ICM42688P_TIMEOUT)) break;
+        if(!furi_hal_spi_bus_rx(spi_bus, value, 1, ICM42688P_TIMEOUT)) break;
+        res = true;
+    } while(0);
+    furi_hal_spi_release(spi_bus);
+    return res;
+}
+
+static bool
+    icm42688p_read_mem(FuriHalSpiBusHandle* spi_bus, uint8_t addr, uint8_t* data, uint8_t len) {
+    bool res = false;
+    furi_hal_spi_acquire(spi_bus);
+    do {
+        uint8_t cmd_byte = addr | (1 << 7);
+        if(!furi_hal_spi_bus_tx(spi_bus, &cmd_byte, 1, ICM42688P_TIMEOUT)) break;
+        if(!furi_hal_spi_bus_rx(spi_bus, data, len, ICM42688P_TIMEOUT)) break;
+        res = true;
+    } while(0);
+    furi_hal_spi_release(spi_bus);
+    return res;
+}
+
+bool icm42688p_accel_config(
+    ICM42688P* icm42688p,
+    ICM42688PAccelFullScale full_scale,
+    ICM42688PDataRate rate) {
+    icm42688p->accel_scale = accel_fs_modes[full_scale].value;
+    uint8_t reg_value = accel_fs_modes[full_scale].reg_mask | rate;
+    return icm42688p_write_reg(icm42688p->spi_bus, ICM42688_ACCEL_CONFIG0, reg_value);
+}
+
+float icm42688p_accel_get_full_scale(ICM42688P* icm42688p) {
+    return icm42688p->accel_scale;
+}
+
+bool icm42688p_gyro_config(
+    ICM42688P* icm42688p,
+    ICM42688PGyroFullScale full_scale,
+    ICM42688PDataRate rate) {
+    icm42688p->gyro_scale = gyro_fs_modes[full_scale].value;
+    uint8_t reg_value = gyro_fs_modes[full_scale].reg_mask | rate;
+    return icm42688p_write_reg(icm42688p->spi_bus, ICM42688_GYRO_CONFIG0, reg_value);
+}
+
+float icm42688p_gyro_get_full_scale(ICM42688P* icm42688p) {
+    return icm42688p->gyro_scale;
+}
+
+bool icm42688p_read_accel_raw(ICM42688P* icm42688p, ICM42688PRawData* data) {
+    bool ret = icm42688p_read_mem(
+        icm42688p->spi_bus, ICM42688_ACCEL_DATA_X1, (uint8_t*)data, sizeof(ICM42688PRawData));
+    return ret;
+}
+
+bool icm42688p_read_gyro_raw(ICM42688P* icm42688p, ICM42688PRawData* data) {
+    bool ret = icm42688p_read_mem(
+        icm42688p->spi_bus, ICM42688_GYRO_DATA_X1, (uint8_t*)data, sizeof(ICM42688PRawData));
+    return ret;
+}
+
+bool icm42688p_write_gyro_offset(ICM42688P* icm42688p, ICM42688PScaledData* scaled_data) {
+    if((fabsf(scaled_data->x) > 64.f) || (fabsf(scaled_data->y) > 64.f) ||
+       (fabsf(scaled_data->z) > 64.f)) {
+        return false;
+    }
+
+    uint16_t offset_x = (uint16_t)(-(int16_t)(scaled_data->x * 32.f) * 16) >> 4;
+    uint16_t offset_y = (uint16_t)(-(int16_t)(scaled_data->y * 32.f) * 16) >> 4;
+    uint16_t offset_z = (uint16_t)(-(int16_t)(scaled_data->z * 32.f) * 16) >> 4;
+
+    uint8_t offset_regs[9];
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 4);
+    icm42688p_read_mem(icm42688p->spi_bus, ICM42688_OFFSET_USER0, offset_regs, 5);
+
+    offset_regs[0] = offset_x & 0xFF;
+    offset_regs[1] = (offset_x & 0xF00) >> 8;
+    offset_regs[1] |= (offset_y & 0xF00) >> 4;
+    offset_regs[2] = offset_y & 0xFF;
+    offset_regs[3] = offset_z & 0xFF;
+    offset_regs[4] &= 0xF0;
+    offset_regs[4] |= (offset_z & 0x0F00) >> 8;
+
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER0, offset_regs[0]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER1, offset_regs[1]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER2, offset_regs[2]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER3, offset_regs[3]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER4, offset_regs[4]);
+
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0);
+    return true;
+}
+
+void icm42688p_apply_scale(ICM42688PRawData* raw_data, float full_scale, ICM42688PScaledData* data) {
+    data->x = ((float)(raw_data->x)) / 32768.f * full_scale;
+    data->y = ((float)(raw_data->y)) / 32768.f * full_scale;
+    data->z = ((float)(raw_data->z)) / 32768.f * full_scale;
+}
+
+void icm42688p_apply_scale_fifo(
+    ICM42688P* icm42688p,
+    ICM42688PFifoPacket* fifo_data,
+    ICM42688PScaledData* accel_data,
+    ICM42688PScaledData* gyro_data) {
+    float full_scale = icm42688p->accel_scale;
+    accel_data->x = ((float)(fifo_data->a_x)) / 32768.f * full_scale;
+    accel_data->y = ((float)(fifo_data->a_y)) / 32768.f * full_scale;
+    accel_data->z = ((float)(fifo_data->a_z)) / 32768.f * full_scale;
+
+    full_scale = icm42688p->gyro_scale;
+    gyro_data->x = ((float)(fifo_data->g_x)) / 32768.f * full_scale;
+    gyro_data->y = ((float)(fifo_data->g_y)) / 32768.f * full_scale;
+    gyro_data->z = ((float)(fifo_data->g_z)) / 32768.f * full_scale;
+}
+
+float icm42688p_read_temp(ICM42688P* icm42688p) {
+    uint8_t reg_val[2];
+
+    icm42688p_read_mem(icm42688p->spi_bus, ICM42688_TEMP_DATA1, reg_val, 2);
+    int16_t temp_int = (reg_val[0] << 8) | reg_val[1];
+    return ((float)temp_int / 132.48f) + 25.f;
+}
+
+void icm42688_fifo_enable(
+    ICM42688P* icm42688p,
+    ICM42688PIrqCallback irq_callback,
+    void* irq_context) {
+    // FIFO mode: stream
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG, (1 << 6));
+    // Little-endian data, FIFO count in records
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INTF_CONFIG0, (1 << 7) | (1 << 6));
+    // FIFO partial read, FIFO packet: gyro + accel TODO: 20bit
+    icm42688p_write_reg(
+        icm42688p->spi_bus, ICM42688_FIFO_CONFIG1, (1 << 6) | (1 << 5) | (1 << 1) | (1 << 0));
+    // FIFO irq watermark
+    uint16_t fifo_watermark = 1;
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG2, fifo_watermark & 0xFF);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG3, fifo_watermark >> 8);
+
+    // IRQ1: push-pull, active high
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_CONFIG, (1 << 1) | (1 << 0));
+    // Clear IRQ on status read
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_CONFIG0, 0);
+    // IRQ pulse duration
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_CONFIG1, (1 << 6) | (1 << 5));
+
+    uint8_t reg_data = 0;
+    icm42688p_read_reg(icm42688p->spi_bus, ICM42688_INT_STATUS, &reg_data);
+
+    furi_hal_gpio_init(icm42688p->irq_pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedVeryHigh);
+    furi_hal_gpio_remove_int_callback(icm42688p->irq_pin);
+    furi_hal_gpio_add_int_callback(icm42688p->irq_pin, irq_callback, irq_context);
+
+    // IRQ1 source: FIFO threshold
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE0, (1 << 2));
+}
+
+void icm42688_fifo_disable(ICM42688P* icm42688p) {
+    furi_hal_gpio_remove_int_callback(icm42688p->irq_pin);
+    furi_hal_gpio_init(icm42688p->irq_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE0, 0);
+
+    // FIFO mode: bypass
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG, 0);
+}
+
+uint16_t icm42688_fifo_get_count(ICM42688P* icm42688p) {
+    uint16_t reg_val = 0;
+    icm42688p_read_mem(icm42688p->spi_bus, ICM42688_FIFO_COUNTH, (uint8_t*)&reg_val, 2);
+    return reg_val;
+}
+
+bool icm42688_fifo_read(ICM42688P* icm42688p, ICM42688PFifoPacket* data) {
+    icm42688p_read_mem(
+        icm42688p->spi_bus, ICM42688_FIFO_DATA, (uint8_t*)data, sizeof(ICM42688PFifoPacket));
+    return (data->header) & (1 << 7);
+}
+
+ICM42688P* icm42688p_alloc(FuriHalSpiBusHandle* spi_bus, const GpioPin* irq_pin) {
+    ICM42688P* icm42688p = malloc(sizeof(ICM42688P));
+    icm42688p->spi_bus = spi_bus;
+    icm42688p->irq_pin = irq_pin;
+    return icm42688p;
+}
+
+void icm42688p_free(ICM42688P* icm42688p) {
+    free(icm42688p);
+}
+
+bool icm42688p_init(ICM42688P* icm42688p) {
+    furi_hal_spi_bus_handle_init(icm42688p->spi_bus);
+
+    // Software reset
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0); // Set reg bank to 0
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_DEVICE_CONFIG, 0x01); // SPI Mode 0, SW reset
+    furi_delay_ms(1);
+
+    uint8_t reg_value = 0;
+    bool read_ok = icm42688p_read_reg(icm42688p->spi_bus, ICM42688_WHO_AM_I, &reg_value);
+    if(!read_ok) {
+        FURI_LOG_E(TAG, "Chip ID read failed");
+        return false;
+    } else if(reg_value != ICM42688_WHOAMI) {
+        FURI_LOG_E(
+            TAG, "Sensor returned wrong ID 0x%02X, expected 0x%02X", reg_value, ICM42688_WHOAMI);
+        return false;
+    }
+
+    // Disable all interrupts
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE0, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE1, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE3, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE4, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 4);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE6, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE7, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0);
+
+    // Data format: little endian
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INTF_CONFIG0, 0);
+
+    // Enable all sensors
+    icm42688p_write_reg(
+        icm42688p->spi_bus,
+        ICM42688_PWR_MGMT0,
+        ICM42688_PWR_TEMP_ON | ICM42688_PWR_GYRO_MODE_LN | ICM42688_PWR_ACCEL_MODE_LN);
+    furi_delay_ms(45);
+
+    icm42688p_accel_config(icm42688p, AccelFullScale16G, DataRate1kHz);
+    icm42688p_gyro_config(icm42688p, GyroFullScale2000DPS, DataRate1kHz);
+
+    return true;
+}
+
+bool icm42688p_deinit(ICM42688P* icm42688p) {
+    // Software reset
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0); // Set reg bank to 0
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_DEVICE_CONFIG, 0x01); // SPI Mode 0, SW reset
+
+    furi_hal_spi_bus_handle_deinit(icm42688p->spi_bus);
+    return true;
+}

+ 127 - 0
engine/sensors/ICM42688P/ICM42688P.h

@@ -0,0 +1,127 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    DataRate32kHz = 0x01,
+    DataRate16kHz = 0x02,
+    DataRate8kHz = 0x03,
+    DataRate4kHz = 0x04,
+    DataRate2kHz = 0x05,
+    DataRate1kHz = 0x06,
+    DataRate200Hz = 0x07,
+    DataRate100Hz = 0x08,
+    DataRate50Hz = 0x09,
+    DataRate25Hz = 0x0A,
+    DataRate12_5Hz = 0x0B,
+    DataRate6_25Hz = 0x0C, // Accelerometer only
+    DataRate3_125Hz = 0x0D, // Accelerometer only
+    DataRate1_5625Hz = 0x0E, // Accelerometer only
+    DataRate500Hz = 0x0F,
+} ICM42688PDataRate;
+
+typedef enum {
+    AccelFullScale16G = 0,
+    AccelFullScale8G,
+    AccelFullScale4G,
+    AccelFullScale2G,
+    AccelFullScaleTotal,
+} ICM42688PAccelFullScale;
+
+typedef enum {
+    GyroFullScale2000DPS = 0,
+    GyroFullScale1000DPS,
+    GyroFullScale500DPS,
+    GyroFullScale250DPS,
+    GyroFullScale125DPS,
+    GyroFullScale62_5DPS,
+    GyroFullScale31_25DPS,
+    GyroFullScale15_625DPS,
+    GyroFullScaleTotal,
+} ICM42688PGyroFullScale;
+
+typedef struct {
+    int16_t x;
+    int16_t y;
+    int16_t z;
+} __attribute__((packed)) ICM42688PRawData;
+
+typedef struct {
+    uint8_t header;
+    int16_t a_x;
+    int16_t a_y;
+    int16_t a_z;
+    int16_t g_x;
+    int16_t g_y;
+    int16_t g_z;
+    uint8_t temp;
+    uint16_t ts;
+} __attribute__((packed)) ICM42688PFifoPacket;
+
+typedef struct {
+    float x;
+    float y;
+    float z;
+} ICM42688PScaledData;
+
+typedef struct ICM42688P ICM42688P;
+
+typedef void (*ICM42688PIrqCallback)(void* ctx);
+
+ICM42688P* icm42688p_alloc(FuriHalSpiBusHandle* spi_bus, const GpioPin* irq_pin);
+
+bool icm42688p_init(ICM42688P* icm42688p);
+
+bool icm42688p_deinit(ICM42688P* icm42688p);
+
+void icm42688p_free(ICM42688P* icm42688p);
+
+bool icm42688p_accel_config(
+    ICM42688P* icm42688p,
+    ICM42688PAccelFullScale full_scale,
+    ICM42688PDataRate rate);
+
+float icm42688p_accel_get_full_scale(ICM42688P* icm42688p);
+
+bool icm42688p_gyro_config(
+    ICM42688P* icm42688p,
+    ICM42688PGyroFullScale full_scale,
+    ICM42688PDataRate rate);
+
+float icm42688p_gyro_get_full_scale(ICM42688P* icm42688p);
+
+bool icm42688p_read_accel_raw(ICM42688P* icm42688p, ICM42688PRawData* data);
+
+bool icm42688p_read_gyro_raw(ICM42688P* icm42688p, ICM42688PRawData* data);
+
+bool icm42688p_write_gyro_offset(ICM42688P* icm42688p, ICM42688PScaledData* scaled_data);
+
+void icm42688p_apply_scale(ICM42688PRawData* raw_data, float full_scale, ICM42688PScaledData* data);
+
+void icm42688p_apply_scale_fifo(
+    ICM42688P* icm42688p,
+    ICM42688PFifoPacket* fifo_data,
+    ICM42688PScaledData* accel_data,
+    ICM42688PScaledData* gyro_data);
+
+float icm42688p_read_temp(ICM42688P* icm42688p);
+
+void icm42688_fifo_enable(
+    ICM42688P* icm42688p,
+    ICM42688PIrqCallback irq_callback,
+    void* irq_context);
+
+void icm42688_fifo_disable(ICM42688P* icm42688p);
+
+uint16_t icm42688_fifo_get_count(ICM42688P* icm42688p);
+
+bool icm42688_fifo_read(ICM42688P* icm42688p, ICM42688PFifoPacket* data);
+
+#ifdef __cplusplus
+}
+#endif

+ 176 - 0
engine/sensors/ICM42688P/ICM42688P_regs.h

@@ -0,0 +1,176 @@
+#pragma once
+
+#define ICM42688_WHOAMI 0x47
+
+// Bank 0
+#define ICM42688_DEVICE_CONFIG 0x11
+#define ICM42688_DRIVE_CONFIG 0x13
+#define ICM42688_INT_CONFIG 0x14
+#define ICM42688_FIFO_CONFIG 0x16
+#define ICM42688_TEMP_DATA1 0x1D
+#define ICM42688_TEMP_DATA0 0x1E
+#define ICM42688_ACCEL_DATA_X1 0x1F
+#define ICM42688_ACCEL_DATA_X0 0x20
+#define ICM42688_ACCEL_DATA_Y1 0x21
+#define ICM42688_ACCEL_DATA_Y0 0x22
+#define ICM42688_ACCEL_DATA_Z1 0x23
+#define ICM42688_ACCEL_DATA_Z0 0x24
+#define ICM42688_GYRO_DATA_X1 0x25
+#define ICM42688_GYRO_DATA_X0 0x26
+#define ICM42688_GYRO_DATA_Y1 0x27
+#define ICM42688_GYRO_DATA_Y0 0x28
+#define ICM42688_GYRO_DATA_Z1 0x29
+#define ICM42688_GYRO_DATA_Z0 0x2A
+#define ICM42688_TMST_FSYNCH 0x2B
+#define ICM42688_TMST_FSYNCL 0x2C
+#define ICM42688_INT_STATUS 0x2D
+#define ICM42688_FIFO_COUNTH 0x2E
+#define ICM42688_FIFO_COUNTL 0x2F
+#define ICM42688_FIFO_DATA 0x30
+#define ICM42688_APEX_DATA0 0x31
+#define ICM42688_APEX_DATA1 0x32
+#define ICM42688_APEX_DATA2 0x33
+#define ICM42688_APEX_DATA3 0x34
+#define ICM42688_APEX_DATA4 0x35
+#define ICM42688_APEX_DATA5 0x36
+#define ICM42688_INT_STATUS2 0x37
+#define ICM42688_INT_STATUS3 0x38
+#define ICM42688_SIGNAL_PATH_RESET 0x4B
+#define ICM42688_INTF_CONFIG0 0x4C
+#define ICM42688_INTF_CONFIG1 0x4D
+#define ICM42688_PWR_MGMT0 0x4E
+#define ICM42688_GYRO_CONFIG0 0x4F
+#define ICM42688_ACCEL_CONFIG0 0x50
+#define ICM42688_GYRO_CONFIG1 0x51
+#define ICM42688_GYRO_ACCEL_CONFIG0 0x52
+#define ICM42688_ACCEL_CONFIG1 0x53
+#define ICM42688_TMST_CONFIG 0x54
+#define ICM42688_APEX_CONFIG0 0x56
+#define ICM42688_SMD_CONFIG 0x57
+#define ICM42688_FIFO_CONFIG1 0x5F
+#define ICM42688_FIFO_CONFIG2 0x60
+#define ICM42688_FIFO_CONFIG3 0x61
+#define ICM42688_FSYNC_CONFIG 0x62
+#define ICM42688_INT_CONFIG0 0x63
+#define ICM42688_INT_CONFIG1 0x64
+#define ICM42688_INT_SOURCE0 0x65
+#define ICM42688_INT_SOURCE1 0x66
+#define ICM42688_INT_SOURCE3 0x68
+#define ICM42688_INT_SOURCE4 0x69
+#define ICM42688_FIFO_LOST_PKT0 0x6C
+#define ICM42688_FIFO_LOST_PKT1 0x6D
+#define ICM42688_SELF_TEST_CONFIG 0x70
+#define ICM42688_WHO_AM_I 0x75
+#define ICM42688_REG_BANK_SEL 0x76
+
+// Bank 1
+#define ICM42688_SENSOR_CONFIG0 0x03
+#define ICM42688_GYRO_CONFIG_STATIC2 0x0B
+#define ICM42688_GYRO_CONFIG_STATIC3 0x0C
+#define ICM42688_GYRO_CONFIG_STATIC4 0x0D
+#define ICM42688_GYRO_CONFIG_STATIC5 0x0E
+#define ICM42688_GYRO_CONFIG_STATIC6 0x0F
+#define ICM42688_GYRO_CONFIG_STATIC7 0x10
+#define ICM42688_GYRO_CONFIG_STATIC8 0x11
+#define ICM42688_GYRO_CONFIG_STATIC9 0x12
+#define ICM42688_GYRO_CONFIG_STATIC10 0x13
+#define ICM42688_XG_ST_DATA 0x5F
+#define ICM42688_YG_ST_DATA 0x60
+#define ICM42688_ZG_ST_DATA 0x61
+#define ICM42688_TMSTVAL0 0x62
+#define ICM42688_TMSTVAL1 0x63
+#define ICM42688_TMSTVAL2 0x64
+#define ICM42688_INTF_CONFIG4 0x7A
+#define ICM42688_INTF_CONFIG5 0x7B
+#define ICM42688_INTF_CONFIG6 0x7C
+
+// Bank 2
+#define ICM42688_ACCEL_CONFIG_STATIC2 0x03
+#define ICM42688_ACCEL_CONFIG_STATIC3 0x04
+#define ICM42688_ACCEL_CONFIG_STATIC4 0x05
+#define ICM42688_XA_ST_DATA 0x3B
+#define ICM42688_YA_ST_DATA 0x3C
+#define ICM42688_ZA_ST_DATA 0x3D
+
+// Bank 4
+#define ICM42688_APEX_CONFIG1 0x40
+#define ICM42688_APEX_CONFIG2 0x41
+#define ICM42688_APEX_CONFIG3 0x42
+#define ICM42688_APEX_CONFIG4 0x43
+#define ICM42688_APEX_CONFIG5 0x44
+#define ICM42688_APEX_CONFIG6 0x45
+#define ICM42688_APEX_CONFIG7 0x46
+#define ICM42688_APEX_CONFIG8 0x47
+#define ICM42688_APEX_CONFIG9 0x48
+#define ICM42688_ACCEL_WOM_X_THR 0x4A
+#define ICM42688_ACCEL_WOM_Y_THR 0x4B
+#define ICM42688_ACCEL_WOM_Z_THR 0x4C
+#define ICM42688_INT_SOURCE6 0x4D
+#define ICM42688_INT_SOURCE7 0x4E
+#define ICM42688_INT_SOURCE8 0x4F
+#define ICM42688_INT_SOURCE9 0x50
+#define ICM42688_INT_SOURCE10 0x51
+#define ICM42688_OFFSET_USER0 0x77
+#define ICM42688_OFFSET_USER1 0x78
+#define ICM42688_OFFSET_USER2 0x79
+#define ICM42688_OFFSET_USER3 0x7A
+#define ICM42688_OFFSET_USER4 0x7B
+#define ICM42688_OFFSET_USER5 0x7C
+#define ICM42688_OFFSET_USER6 0x7D
+#define ICM42688_OFFSET_USER7 0x7E
+#define ICM42688_OFFSET_USER8 0x7F
+
+// PWR_MGMT0
+#define ICM42688_PWR_TEMP_ON (0 << 5)
+#define ICM42688_PWR_TEMP_OFF (1 << 5)
+#define ICM42688_PWR_IDLE (1 << 4)
+#define ICM42688_PWR_GYRO_MODE_OFF (0 << 2)
+#define ICM42688_PWR_GYRO_MODE_LN (3 << 2)
+#define ICM42688_PWR_ACCEL_MODE_OFF (0 << 0)
+#define ICM42688_PWR_ACCEL_MODE_LP (2 << 0)
+#define ICM42688_PWR_ACCEL_MODE_LN (3 << 0)
+
+// GYRO_CONFIG0
+#define ICM42688_GFS_2000DPS (0x00 << 5)
+#define ICM42688_GFS_1000DPS (0x01 << 5)
+#define ICM42688_GFS_500DPS (0x02 << 5)
+#define ICM42688_GFS_250DPS (0x03 << 5)
+#define ICM42688_GFS_125DPS (0x04 << 5)
+#define ICM42688_GFS_62_5DPS (0x05 << 5)
+#define ICM42688_GFS_31_25DPS (0x06 << 5)
+#define ICM42688_GFS_15_625DPS (0x07 << 5)
+
+#define ICM42688_GODR_32kHz 0x01
+#define ICM42688_GODR_16kHz 0x02
+#define ICM42688_GODR_8kHz 0x03
+#define ICM42688_GODR_4kHz 0x04
+#define ICM42688_GODR_2kHz 0x05
+#define ICM42688_GODR_1kHz 0x06
+#define ICM42688_GODR_200Hz 0x07
+#define ICM42688_GODR_100Hz 0x08
+#define ICM42688_GODR_50Hz 0x09
+#define ICM42688_GODR_25Hz 0x0A
+#define ICM42688_GODR_12_5Hz 0x0B
+#define ICM42688_GODR_500Hz 0x0F
+
+// ACCEL_CONFIG0
+#define ICM42688_AFS_16G (0x00 << 5)
+#define ICM42688_AFS_8G (0x01 << 5)
+#define ICM42688_AFS_4G (0x02 << 5)
+#define ICM42688_AFS_2G (0x03 << 5)
+
+#define ICM42688_AODR_32kHz 0x01
+#define ICM42688_AODR_16kHz 0x02
+#define ICM42688_AODR_8kHz 0x03
+#define ICM42688_AODR_4kHz 0x04
+#define ICM42688_AODR_2kHz 0x05
+#define ICM42688_AODR_1kHz 0x06
+#define ICM42688_AODR_200Hz 0x07
+#define ICM42688_AODR_100Hz 0x08
+#define ICM42688_AODR_50Hz 0x09
+#define ICM42688_AODR_25Hz 0x0A
+#define ICM42688_AODR_12_5Hz 0x0B
+#define ICM42688_AODR_6_25Hz 0x0C
+#define ICM42688_AODR_3_125Hz 0x0D
+#define ICM42688_AODR_1_5625Hz 0x0E
+#define ICM42688_AODR_500Hz 0x0F

+ 326 - 0
engine/sensors/imu.c

@@ -0,0 +1,326 @@
+#include <furi.h>
+#include "imu.h"
+#include "ICM42688P/ICM42688P.h"
+
+#define TAG "IMU"
+
+#define ACCEL_GYRO_RATE DataRate100Hz
+
+#define FILTER_SAMPLE_FREQ 100.f
+#define FILTER_BETA 0.08f
+
+#define SAMPLE_RATE_DIV 5
+
+#define SENSITIVITY_K 30.f
+#define EXP_RATE 1.1f
+
+#define IMU_CALI_AVG 64
+
+typedef enum {
+    ImuStop = (1 << 0),
+    ImuNewData = (1 << 1),
+} ImuThreadFlags;
+
+#define FLAGS_ALL (ImuStop | ImuNewData)
+
+typedef struct {
+    float q0;
+    float q1;
+    float q2;
+    float q3;
+    float roll;
+    float pitch;
+    float yaw;
+} ImuProcessedData;
+
+typedef struct {
+    FuriThread* thread;
+    ICM42688P* icm42688p;
+    ImuProcessedData processed_data;
+} ImuThread;
+
+static void imu_madgwick_filter(
+    ImuProcessedData* out,
+    ICM42688PScaledData* accel,
+    ICM42688PScaledData* gyro);
+
+static void imu_irq_callback(void* context) {
+    furi_assert(context);
+    ImuThread* imu = context;
+    furi_thread_flags_set(furi_thread_get_id(imu->thread), ImuNewData);
+}
+
+static void imu_process_data(ImuThread* imu, ICM42688PFifoPacket* in_data) {
+    ICM42688PScaledData accel_data;
+    ICM42688PScaledData gyro_data;
+
+    // Get accel and gyro data in g and degrees/s
+    icm42688p_apply_scale_fifo(imu->icm42688p, in_data, &accel_data, &gyro_data);
+
+    // Gyro: degrees/s to rads/s
+    gyro_data.x = gyro_data.x / 180.f * M_PI;
+    gyro_data.y = gyro_data.y / 180.f * M_PI;
+    gyro_data.z = gyro_data.z / 180.f * M_PI;
+
+    // Sensor Fusion algorithm
+    ImuProcessedData* out = &imu->processed_data;
+    imu_madgwick_filter(out, &accel_data, &gyro_data);
+
+    // Quaternion to euler angles
+    float roll = atan2f(
+        out->q0 * out->q1 + out->q2 * out->q3, 0.5f - out->q1 * out->q1 - out->q2 * out->q2);
+    float pitch = asinf(-2.0f * (out->q1 * out->q3 - out->q0 * out->q2));
+    float yaw = atan2f(
+        out->q1 * out->q2 + out->q0 * out->q3, 0.5f - out->q2 * out->q2 - out->q3 * out->q3);
+
+    // Euler angles: rads to degrees
+    out->roll = roll / M_PI * 180.f;
+    out->pitch = pitch / M_PI * 180.f;
+    out->yaw = yaw / M_PI * 180.f;
+}
+
+static void calibrate_gyro(ImuThread* imu) {
+    ICM42688PRawData data;
+    ICM42688PScaledData offset_scaled = {.x = 0.f, .y = 0.f, .z = 0.f};
+
+    icm42688p_write_gyro_offset(imu->icm42688p, &offset_scaled);
+    furi_delay_ms(10);
+
+    int32_t avg_x = 0;
+    int32_t avg_y = 0;
+    int32_t avg_z = 0;
+
+    for(uint8_t i = 0; i < IMU_CALI_AVG; i++) {
+        icm42688p_read_gyro_raw(imu->icm42688p, &data);
+        avg_x += data.x;
+        avg_y += data.y;
+        avg_z += data.z;
+        furi_delay_ms(2);
+    }
+
+    data.x = avg_x / IMU_CALI_AVG;
+    data.y = avg_y / IMU_CALI_AVG;
+    data.z = avg_z / IMU_CALI_AVG;
+
+    icm42688p_apply_scale(&data, icm42688p_gyro_get_full_scale(imu->icm42688p), &offset_scaled);
+    FURI_LOG_I(
+        TAG,
+        "Offsets: x %f, y %f, z %f",
+        (double)offset_scaled.x,
+        (double)offset_scaled.y,
+        (double)offset_scaled.z);
+    icm42688p_write_gyro_offset(imu->icm42688p, &offset_scaled);
+}
+
+// static float imu_angle_diff(float a, float b) {
+//     float diff = a - b;
+//     if(diff > 180.f)
+//         diff -= 360.f;
+//     else if(diff < -180.f)
+//         diff += 360.f;
+
+//     return diff;
+// }
+
+static int32_t imu_thread(void* context) {
+    furi_assert(context);
+    ImuThread* imu = context;
+
+    // float yaw_last = 0.f;
+    // float pitch_last = 0.f;
+    // float diff_x = 0.f;
+    // float diff_y = 0.f;
+
+    calibrate_gyro(imu);
+
+    icm42688p_accel_config(imu->icm42688p, AccelFullScale16G, ACCEL_GYRO_RATE);
+    icm42688p_gyro_config(imu->icm42688p, GyroFullScale2000DPS, ACCEL_GYRO_RATE);
+
+    imu->processed_data.q0 = 1.f;
+    imu->processed_data.q1 = 0.f;
+    imu->processed_data.q2 = 0.f;
+    imu->processed_data.q3 = 0.f;
+    icm42688_fifo_enable(imu->icm42688p, imu_irq_callback, imu);
+
+    while(1) {
+        uint32_t events = furi_thread_flags_wait(FLAGS_ALL, FuriFlagWaitAny, FuriWaitForever);
+
+        if(events & ImuStop) {
+            break;
+        }
+
+        if(events & ImuNewData) {
+            uint16_t data_pending = icm42688_fifo_get_count(imu->icm42688p);
+            ICM42688PFifoPacket data;
+            while(data_pending--) {
+                icm42688_fifo_read(imu->icm42688p, &data);
+                imu_process_data(imu, &data);
+            }
+        }
+    }
+
+    icm42688_fifo_disable(imu->icm42688p);
+
+    return 0;
+}
+
+ImuThread* imu_start(ICM42688P* icm42688p) {
+    ImuThread* imu = malloc(sizeof(ImuThread));
+    imu->icm42688p = icm42688p;
+    imu->thread = furi_thread_alloc_ex("ImuThread", 4096, imu_thread, imu);
+
+    furi_thread_start(imu->thread);
+
+    return imu;
+}
+
+void imu_stop(ImuThread* imu) {
+    furi_assert(imu);
+
+    furi_thread_flags_set(furi_thread_get_id(imu->thread), ImuStop);
+
+    furi_thread_join(imu->thread);
+    furi_thread_free(imu->thread);
+
+    free(imu);
+}
+
+static float imu_inv_sqrt(float number) {
+    union {
+        float f;
+        uint32_t i;
+    } conv = {.f = number};
+    conv.i = 0x5F3759Df - (conv.i >> 1);
+    conv.f *= 1.5f - (number * 0.5f * conv.f * conv.f);
+    return conv.f;
+}
+
+/* Simple madgwik filter, based on: https://github.com/arduino-libraries/MadgwickAHRS/ */
+
+static void imu_madgwick_filter(
+    ImuProcessedData* out,
+    ICM42688PScaledData* accel,
+    ICM42688PScaledData* gyro) {
+    float recipNorm;
+    float s0, s1, s2, s3;
+    float qDot1, qDot2, qDot3, qDot4;
+    float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2, _8q1, _8q2, q0q0, q1q1, q2q2, q3q3;
+
+    // Rate of change of quaternion from gyroscope
+    qDot1 = 0.5f * (-out->q1 * gyro->x - out->q2 * gyro->y - out->q3 * gyro->z);
+    qDot2 = 0.5f * (out->q0 * gyro->x + out->q2 * gyro->z - out->q3 * gyro->y);
+    qDot3 = 0.5f * (out->q0 * gyro->y - out->q1 * gyro->z + out->q3 * gyro->x);
+    qDot4 = 0.5f * (out->q0 * gyro->z + out->q1 * gyro->y - out->q2 * gyro->x);
+
+    // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation)
+    if(!((accel->x == 0.0f) && (accel->y == 0.0f) && (accel->z == 0.0f))) {
+        // Normalise accelerometer measurement
+        recipNorm = imu_inv_sqrt(accel->x * accel->x + accel->y * accel->y + accel->z * accel->z);
+        accel->x *= recipNorm;
+        accel->y *= recipNorm;
+        accel->z *= recipNorm;
+
+        // Auxiliary variables to avoid repeated arithmetic
+        _2q0 = 2.0f * out->q0;
+        _2q1 = 2.0f * out->q1;
+        _2q2 = 2.0f * out->q2;
+        _2q3 = 2.0f * out->q3;
+        _4q0 = 4.0f * out->q0;
+        _4q1 = 4.0f * out->q1;
+        _4q2 = 4.0f * out->q2;
+        _8q1 = 8.0f * out->q1;
+        _8q2 = 8.0f * out->q2;
+        q0q0 = out->q0 * out->q0;
+        q1q1 = out->q1 * out->q1;
+        q2q2 = out->q2 * out->q2;
+        q3q3 = out->q3 * out->q3;
+
+        // Gradient decent algorithm corrective step
+        s0 = _4q0 * q2q2 + _2q2 * accel->x + _4q0 * q1q1 - _2q1 * accel->y;
+        s1 = _4q1 * q3q3 - _2q3 * accel->x + 4.0f * q0q0 * out->q1 - _2q0 * accel->y - _4q1 +
+             _8q1 * q1q1 + _8q1 * q2q2 + _4q1 * accel->z;
+        s2 = 4.0f * q0q0 * out->q2 + _2q0 * accel->x + _4q2 * q3q3 - _2q3 * accel->y - _4q2 +
+             _8q2 * q1q1 + _8q2 * q2q2 + _4q2 * accel->z;
+        s3 = 4.0f * q1q1 * out->q3 - _2q1 * accel->x + 4.0f * q2q2 * out->q3 - _2q2 * accel->y;
+        recipNorm =
+            imu_inv_sqrt(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3); // normalise step magnitude
+        s0 *= recipNorm;
+        s1 *= recipNorm;
+        s2 *= recipNorm;
+        s3 *= recipNorm;
+
+        // Apply feedback step
+        qDot1 -= FILTER_BETA * s0;
+        qDot2 -= FILTER_BETA * s1;
+        qDot3 -= FILTER_BETA * s2;
+        qDot4 -= FILTER_BETA * s3;
+    }
+
+    // Integrate rate of change of quaternion to yield quaternion
+    out->q0 += qDot1 * (1.0f / FILTER_SAMPLE_FREQ);
+    out->q1 += qDot2 * (1.0f / FILTER_SAMPLE_FREQ);
+    out->q2 += qDot3 * (1.0f / FILTER_SAMPLE_FREQ);
+    out->q3 += qDot4 * (1.0f / FILTER_SAMPLE_FREQ);
+
+    // Normalise quaternion
+    recipNorm = imu_inv_sqrt(
+        out->q0 * out->q0 + out->q1 * out->q1 + out->q2 * out->q2 + out->q3 * out->q3);
+    out->q0 *= recipNorm;
+    out->q1 *= recipNorm;
+    out->q2 *= recipNorm;
+    out->q3 *= recipNorm;
+}
+
+/* IMU API */
+
+struct Imu {
+    FuriHalSpiBusHandle* icm42688p_device;
+    ICM42688P* icm42688p;
+    ImuThread* thread;
+    bool present;
+};
+
+Imu* imu_alloc(void) {
+    Imu* imu = malloc(sizeof(Imu));
+    imu->icm42688p_device = malloc(sizeof(FuriHalSpiBusHandle));
+    memcpy(imu->icm42688p_device, &furi_hal_spi_bus_handle_external, sizeof(FuriHalSpiBusHandle));
+    imu->icm42688p_device->cs = &gpio_ext_pc3;
+
+    imu->icm42688p = icm42688p_alloc(imu->icm42688p_device, &gpio_ext_pb2);
+    imu->present = icm42688p_init(imu->icm42688p);
+
+    if(imu->present) {
+        imu->thread = imu_start(imu->icm42688p);
+    }
+
+    return imu;
+}
+
+void imu_free(Imu* imu) {
+    if(imu->present) {
+        imu_stop(imu->thread);
+    }
+    icm42688p_deinit(imu->icm42688p);
+    icm42688p_free(imu->icm42688p);
+    free(imu->icm42688p_device);
+    free(imu);
+}
+
+bool imu_present(Imu* imu) {
+    return imu->present;
+}
+
+float imu_pitch_get(Imu* imu) {
+    // we pretend that reading a float is an atomic operation
+    return imu->thread->processed_data.pitch;
+}
+
+float imu_roll_get(Imu* imu) {
+    // we pretend that reading a float is an atomic operation
+    return imu->thread->processed_data.roll;
+}
+
+float imu_yaw_get(Imu* imu) {
+    // we pretend that reading a float is an atomic operation
+    return imu->thread->processed_data.yaw;
+}

+ 15 - 0
engine/sensors/imu.h

@@ -0,0 +1,15 @@
+#pragma once
+
+typedef struct Imu Imu;
+
+Imu* imu_alloc(void);
+
+void imu_free(Imu* imu);
+
+bool imu_present(Imu* imu);
+
+float imu_pitch_get(Imu* imu);
+
+float imu_roll_get(Imu* imu);
+
+float imu_yaw_get(Imu* imu);

+ 69 - 0
engine/sprite.c

@@ -0,0 +1,69 @@
+#include "sprite.h"
+#include <storage/storage.h>
+
+#ifdef SPRITE_DEBUG
+#define SPRITE_D(...) FURI_LOG_D("Sprite", __VA_ARGS__)
+#define SPRITE_E(...) FURI_LOG_E("Sprite", __VA_ARGS__)
+#else
+#define SPRITE_D(...)
+#define SPRITE_E(...)
+#endif
+
+struct Sprite {
+    uint32_t width;
+    uint32_t height;
+    uint8_t data[];
+};
+
+Sprite* sprite_alloc(const char* path) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
+    Sprite* sprite = NULL;
+
+    do {
+        if(!storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
+            SPRITE_E("Failed to open file: %s", path);
+            break;
+        }
+
+        uint32_t size = 0;
+        if(storage_file_read(file, &size, sizeof(size)) != sizeof(size)) {
+            SPRITE_E("Failed to read file size: %s", path);
+            break;
+        }
+
+        sprite = malloc(size);
+        if(storage_file_read(file, sprite, size) != size) {
+            SPRITE_E("Failed to read file: %s", path);
+            free(sprite);
+            sprite = NULL;
+            break;
+        }
+
+        SPRITE_D(
+            "Loaded sprite: %s, width: %lu, height: %lu", path, sprite->width, sprite->height);
+    } while(false);
+
+    storage_file_free(file);
+
+    return sprite;
+}
+
+void sprite_free(Sprite* sprite) {
+    free(sprite);
+}
+
+size_t sprite_get_width(Sprite* sprite) {
+    return sprite->width;
+}
+
+size_t sprite_get_height(Sprite* sprite) {
+    return sprite->height;
+}
+
+void canvas_draw_sprite(Canvas* canvas, Sprite* sprite, int32_t x, int32_t y) {
+    furi_check(sprite->width);
+    furi_check(sprite->height);
+    furi_check(sprite->data);
+    canvas_draw_xbm(canvas, x, y, sprite->width, sprite->height, sprite->data);
+}

+ 44 - 0
engine/sprite.h

@@ -0,0 +1,44 @@
+#pragma once
+#include <stdbool.h>
+#include <stddef.h>
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Sprite Sprite;
+
+/** Sprite allocator
+ * @return Sprite*  Sprite instance or NULL, if failed
+ */
+Sprite* sprite_alloc(const char* path);
+
+/** Sprite deallocator
+ * @param sprite Sprite instance
+ */
+void sprite_free(Sprite* sprite);
+
+/** Get sprite width
+ * @param sprite Sprite instance
+ * @return size_t sprite width
+ */
+size_t sprite_get_width(Sprite* sprite);
+
+/** Get sprite height
+ * @param sprite Sprite instance
+ * @return size_t sprite height
+ */
+size_t sprite_get_height(Sprite* sprite);
+
+/** Draw sprite on canvas
+ * @param canvas Canvas instance
+ * @param sprite Sprite instance
+ * @param x x coordinate
+ * @param y y coordinate
+ */
+void canvas_draw_sprite(Canvas* canvas, Sprite* sprite, int32_t x, int32_t y);
+
+#ifdef __cplusplus
+}
+#endif

+ 33 - 0
engine/vector.c

@@ -0,0 +1,33 @@
+#include "vector.h"
+
+Vector vector_add(Vector a, Vector b) {
+    return (Vector){.x = a.x + b.x, .y = a.y + b.y};
+}
+
+Vector vector_sub(Vector a, Vector b) {
+    return (Vector){.x = a.x - b.x, .y = a.y - b.y};
+}
+
+Vector vector_mul(Vector a, Vector b) {
+    return (Vector){.x = a.x * b.x, .y = a.y * b.y};
+}
+
+Vector vector_div(Vector a, Vector b) {
+    return (Vector){.x = a.x / b.x, .y = a.y / b.y};
+}
+
+Vector vector_addf(Vector a, float b) {
+    return (Vector){.x = a.x + b, .y = a.y + b};
+}
+
+Vector vector_subf(Vector a, float b) {
+    return (Vector){.x = a.x - b, .y = a.y - b};
+}
+
+Vector vector_mulf(Vector a, float b) {
+    return (Vector){.x = a.x * b, .y = a.y * b};
+}
+
+Vector vector_divf(Vector a, float b) {
+    return (Vector){.x = a.x / b, .y = a.y / b};
+}

+ 32 - 0
engine/vector.h

@@ -0,0 +1,32 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+    float x;
+    float y;
+} Vector;
+
+#define VECTOR_ZERO ((Vector){0, 0})
+
+Vector vector_add(Vector a, Vector b);
+
+Vector vector_sub(Vector a, Vector b);
+
+Vector vector_mul(Vector a, Vector b);
+
+Vector vector_div(Vector a, Vector b);
+
+Vector vector_addf(Vector a, float b);
+
+Vector vector_subf(Vector a, float b);
+
+Vector vector_mulf(Vector a, float b);
+
+Vector vector_divf(Vector a, float b);
+
+#ifdef __cplusplus
+}
+#endif

+ 186 - 0
flip_storage/storage.c

@@ -0,0 +1,186 @@
+
+#include "flip_storage/storage.h"
+
+void save_settings(
+    const char *ssid,
+    const char *password)
+{
+    // Create the directory for saving settings
+    char directory_path[256];
+    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world");
+
+    // Create the directory
+    Storage *storage = furi_record_open(RECORD_STORAGE);
+    storage_common_mkdir(storage, directory_path);
+
+    // Open the settings file
+    File *file = storage_file_alloc(storage);
+    if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
+    {
+        FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return;
+    }
+
+    // Save the ssid length and data
+    size_t ssid_length = strlen(ssid) + 1; // Include null terminator
+    if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+        storage_file_write(file, ssid, ssid_length) != ssid_length)
+    {
+        FURI_LOG_E(TAG, "Failed to write SSID");
+    }
+
+    // Save the password length and data
+    size_t password_length = strlen(password) + 1; // Include null terminator
+    if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+        storage_file_write(file, password, password_length) != password_length)
+    {
+        FURI_LOG_E(TAG, "Failed to write password");
+    }
+
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+}
+
+bool load_settings(
+    char *ssid,
+    size_t ssid_size,
+    char *password,
+    size_t password_size)
+{
+    Storage *storage = furi_record_open(RECORD_STORAGE);
+    File *file = storage_file_alloc(storage);
+
+    if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
+    {
+        FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false; // Return false if the file does not exist
+    }
+
+    // Load the ssid
+    size_t ssid_length;
+    if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
+        storage_file_read(file, ssid, ssid_length) != ssid_length)
+    {
+        FURI_LOG_E(TAG, "Failed to read SSID");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false;
+    }
+    ssid[ssid_length - 1] = '\0'; // Ensure null-termination
+
+    // Load the password
+    size_t password_length;
+    if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
+        storage_file_read(file, password, password_length) != password_length)
+    {
+        FURI_LOG_E(TAG, "Failed to read password");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false;
+    }
+    password[password_length - 1] = '\0'; // Ensure null-termination
+
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+
+    return true;
+}
+
+bool save_char(
+    const char *path_name, const char *value)
+{
+    if (!value)
+    {
+        return false;
+    }
+    // Create the directory for saving settings
+    char directory_path[256];
+    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world");
+
+    // Create the directory
+    Storage *storage = furi_record_open(RECORD_STORAGE);
+    storage_common_mkdir(storage, directory_path);
+
+    // Open the settings file
+    File *file = storage_file_alloc(storage);
+    char file_path[256];
+    snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/%s.txt", path_name);
+
+    // Open the file in write mode
+    if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false;
+    }
+
+    // Write the data to the file
+    size_t data_size = strlen(value) + 1; // Include null terminator
+    if (storage_file_write(file, value, data_size) != data_size)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false;
+    }
+
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+
+    return true;
+}
+
+bool load_char(
+    const char *path_name,
+    char *value,
+    size_t value_size)
+{
+    if (!value)
+    {
+        return false;
+    }
+    Storage *storage = furi_record_open(RECORD_STORAGE);
+    File *file = storage_file_alloc(storage);
+
+    char file_path[256];
+    snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/%s.txt", path_name);
+
+    // Open the file for reading
+    if (!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
+    {
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL; // Return false if the file does not exist
+    }
+
+    // Read data into the buffer
+    size_t read_count = storage_file_read(file, value, value_size);
+    if (storage_file_get_error(file) != FSE_OK)
+    {
+        FURI_LOG_E(HTTP_TAG, "Error reading from file.");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false;
+    }
+
+    // Ensure null-termination
+    value[read_count - 1] = '\0';
+
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+
+    return true;
+}

+ 25 - 0
flip_storage/storage.h

@@ -0,0 +1,25 @@
+#pragma once
+
+#include <furi.h>
+#include <storage/storage.h>
+#include <flip_world.h>
+
+#define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/settings.bin"
+
+void save_settings(
+    const char *ssid,
+    const char *password);
+
+bool load_settings(
+    char *ssid,
+    size_t ssid_size,
+    char *password,
+    size_t password_size);
+
+bool save_char(
+    const char *path_name, const char *value);
+
+bool load_char(
+    const char *path_name,
+    char *value,
+    size_t value_size);

+ 1 - 0
flip_world.c

@@ -0,0 +1 @@
+#include <flip_world.h>

+ 52 - 0
flip_world.h

@@ -0,0 +1,52 @@
+#pragma once
+#include <font/font.h>
+#include <flipper_http/flipper_http.h>
+#include <easy_flipper/easy_flipper.h>
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <gui/view.h>
+#include <gui/modules/submenu.h>
+#include <gui/view_dispatcher.h>
+#include <notification/notification.h>
+#include <dialogs/dialogs.h>
+
+#define TAG "FlipWorld"
+#define VERSION_TAG "FlipWorld v0.1"
+
+// Define the submenu items for our FlipWorld application
+typedef enum
+{
+    FlipWorldSubmenuIndexRun, // Click to run the FlipWorld application
+    FlipWorldSubmenuIndexAbout,
+    FlipWorldSubmenuIndexSettings,
+} FlipWorldSubmenuIndex;
+
+// Define a single view for our FlipWorld application
+typedef enum
+{
+    FlipWorldViewMain,      // The main screen
+    FlipWorldViewSubmenu,   // The submenu
+    FlipWorldViewAbout,     // The about screen
+    FlipWorldViewSettings,  // The settings screen
+    FlipWorldViewTextInput, // The text input screen
+    FlipWorldlViewDialog,   // The dialog screen
+} FlipWorldView;
+
+// Each screen will have its own view
+typedef struct
+{
+    // necessary
+    ViewDispatcher *view_dispatcher;      // Switches between our views
+    View *view_main;                      // The game screen
+    View *view_about;                     // The about screen
+    Submenu *submenu;                     // The submenu
+    VariableItemList *variable_item_list; // The variable item list (settngs)
+    VariableItem *variable_item_ssid;     // The variable item
+    VariableItem *variable_item_pass;     // The variable item
+
+    UART_TextInput *text_input;      // The text input
+    char *text_input_buffer;         // Buffer for the text input
+    char *text_input_temp_buffer;    // Temporary buffer for the text input
+    uint32_t text_input_buffer_size; // Size of the text input buffer
+} FlipWorldApp;

+ 1524 - 0
flipper_http/flipper_http.c

@@ -0,0 +1,1524 @@
+// Description: Flipper HTTP API (For use with Flipper Zero and the FlipperHTTP flash: https://github.com/jblanked/FlipperHTTP)
+// License: MIT
+// Author: JBlanked
+// File: flipper_http.c
+#include <flipper_http/flipper_http.h> // change this to where flipper_http.h is located
+FlipperHTTP fhttp = {0};
+// Function to append received data to file
+// make sure to initialize the file path before calling this function
+bool flipper_http_append_to_file(
+    const void *data,
+    size_t data_size,
+    bool start_new_file,
+    char *file_path)
+{
+    Storage *storage = furi_record_open(RECORD_STORAGE);
+    File *file = storage_file_alloc(storage);
+
+    if (start_new_file)
+    {
+        // Delete the file if it already exists
+        if (storage_file_exists(storage, file_path))
+        {
+            if (!storage_simply_remove_recursive(storage, file_path))
+            {
+                FURI_LOG_E(HTTP_TAG, "Failed to delete file: %s", file_path);
+                storage_file_free(file);
+                furi_record_close(RECORD_STORAGE);
+                return false;
+            }
+        }
+        // Open the file in write mode
+        if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
+        {
+            FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
+            storage_file_free(file);
+            furi_record_close(RECORD_STORAGE);
+            return false;
+        }
+    }
+    else
+    {
+        // Open the file in append mode
+        if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_OPEN_APPEND))
+        {
+            FURI_LOG_E(HTTP_TAG, "Failed to open file for appending: %s", file_path);
+            storage_file_free(file);
+            furi_record_close(RECORD_STORAGE);
+            return false;
+        }
+    }
+
+    // Write the data to the file
+    if (storage_file_write(file, data, data_size) != data_size)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return false;
+    }
+
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+    return true;
+}
+
+FuriString *flipper_http_load_from_file(char *file_path)
+{
+    // Open the storage record
+    Storage *storage = furi_record_open(RECORD_STORAGE);
+    if (!storage)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to open storage record");
+        return NULL;
+    }
+
+    // Allocate a file handle
+    File *file = storage_file_alloc(storage);
+    if (!file)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate storage file");
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Open the file for reading
+    if (!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
+    {
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL; // Return false if the file does not exist
+    }
+
+    // Allocate a FuriString to hold the received data
+    FuriString *str_result = furi_string_alloc();
+    if (!str_result)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate FuriString");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Reset the FuriString to ensure it's empty before reading
+    furi_string_reset(str_result);
+
+    // Define a buffer to hold the read data
+    uint8_t *buffer = (uint8_t *)malloc(MAX_FILE_SHOW);
+    if (!buffer)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate buffer");
+        furi_string_free(str_result);
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Read data into the buffer
+    size_t read_count = storage_file_read(file, buffer, MAX_FILE_SHOW);
+    if (storage_file_get_error(file) != FSE_OK)
+    {
+        FURI_LOG_E(HTTP_TAG, "Error reading from file.");
+        furi_string_free(str_result);
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Append each byte to the FuriString
+    for (size_t i = 0; i < read_count; i++)
+    {
+        furi_string_push_back(str_result, buffer[i]);
+    }
+
+    // Check if there is more data beyond the maximum size
+    char extra_byte;
+    storage_file_read(file, &extra_byte, 1);
+
+    // Clean up
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+    free(buffer);
+    return str_result;
+}
+
+// UART worker thread
+/**
+ * @brief      Worker thread to handle UART data asynchronously.
+ * @return     0
+ * @param      context   The context to pass to the callback.
+ * @note       This function will handle received data asynchronously via the callback.
+ */
+// UART worker thread
+int32_t flipper_http_worker(void *context)
+{
+    UNUSED(context);
+    size_t rx_line_pos = 0;
+
+    while (1)
+    {
+        uint32_t events = furi_thread_flags_wait(
+            WorkerEvtStop | WorkerEvtRxDone, FuriFlagWaitAny, FuriWaitForever);
+        if (events & WorkerEvtStop)
+        {
+            break;
+        }
+        if (events & WorkerEvtRxDone)
+        {
+            // Continuously read from the stream buffer until it's empty
+            while (!furi_stream_buffer_is_empty(fhttp.flipper_http_stream))
+            {
+                // Read one byte at a time
+                char c = 0;
+                size_t received = furi_stream_buffer_receive(fhttp.flipper_http_stream, &c, 1, 0);
+
+                if (received == 0)
+                {
+                    // No more data to read
+                    break;
+                }
+
+                // Append the received byte to the file if saving is enabled
+                if (fhttp.save_bytes)
+                {
+                    // Add byte to the buffer
+                    fhttp.file_buffer[fhttp.file_buffer_len++] = c;
+                    // Write to file if buffer is full
+                    if (fhttp.file_buffer_len >= FILE_BUFFER_SIZE)
+                    {
+                        if (!flipper_http_append_to_file(
+                                fhttp.file_buffer,
+                                fhttp.file_buffer_len,
+                                fhttp.just_started_bytes,
+                                fhttp.file_path))
+                        {
+                            FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
+                        }
+                        fhttp.file_buffer_len = 0;
+                        fhttp.just_started_bytes = false;
+                    }
+                }
+
+                // Handle line buffering only if callback is set (text data)
+                if (fhttp.handle_rx_line_cb)
+                {
+                    // Handle line buffering
+                    if (c == '\n' || rx_line_pos >= RX_LINE_BUFFER_SIZE - 1)
+                    {
+                        fhttp.rx_line_buffer[rx_line_pos] = '\0'; // Null-terminate the line
+
+                        // Invoke the callback with the complete line
+                        fhttp.handle_rx_line_cb(fhttp.rx_line_buffer, fhttp.callback_context);
+
+                        // Reset the line buffer position
+                        rx_line_pos = 0;
+                    }
+                    else
+                    {
+                        fhttp.rx_line_buffer[rx_line_pos++] = c; // Add character to the line buffer
+                    }
+                }
+            }
+        }
+    }
+
+    return 0;
+}
+// Timer callback function
+/**
+ * @brief      Callback function for the GET timeout timer.
+ * @return     0
+ * @param      context   The context to pass to the callback.
+ * @note       This function will be called when the GET request times out.
+ */
+void get_timeout_timer_callback(void *context)
+{
+    UNUSED(context);
+    FURI_LOG_E(HTTP_TAG, "Timeout reached: 2 seconds without receiving the end.");
+
+    // Reset the state
+    fhttp.started_receiving_get = false;
+    fhttp.started_receiving_post = false;
+    fhttp.started_receiving_put = false;
+    fhttp.started_receiving_delete = false;
+
+    // Update UART state
+    fhttp.state = ISSUE;
+}
+
+// UART RX Handler Callback (Interrupt Context)
+/**
+ * @brief      A private callback function to handle received data asynchronously.
+ * @return     void
+ * @param      handle    The UART handle.
+ * @param      event     The event type.
+ * @param      context   The context to pass to the callback.
+ * @note       This function will handle received data asynchronously via the callback.
+ */
+void _flipper_http_rx_callback(
+    FuriHalSerialHandle *handle,
+    FuriHalSerialRxEvent event,
+    void *context)
+{
+    UNUSED(context);
+    if (event == FuriHalSerialRxEventData)
+    {
+        uint8_t data = furi_hal_serial_async_rx(handle);
+        furi_stream_buffer_send(fhttp.flipper_http_stream, &data, 1, 0);
+        furi_thread_flags_set(fhttp.rx_thread_id, WorkerEvtRxDone);
+    }
+}
+
+// UART initialization function
+/**
+ * @brief      Initialize UART.
+ * @return     true if the UART was initialized successfully, false otherwise.
+ * @param      callback  The callback function to handle received data (ex. flipper_http_rx_callback).
+ * @param      context   The context to pass to the callback.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_init(FlipperHTTP_Callback callback, void *context)
+{
+    if (!context)
+    {
+        FURI_LOG_E(HTTP_TAG, "Invalid context provided to flipper_http_init.");
+        return false;
+    }
+    if (!callback)
+    {
+        FURI_LOG_E(HTTP_TAG, "Invalid callback provided to flipper_http_init.");
+        return false;
+    }
+    fhttp.flipper_http_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
+    if (!fhttp.flipper_http_stream)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate UART stream buffer.");
+        return false;
+    }
+
+    fhttp.rx_thread = furi_thread_alloc();
+    if (!fhttp.rx_thread)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate UART thread.");
+        furi_stream_buffer_free(fhttp.flipper_http_stream);
+        return false;
+    }
+
+    furi_thread_set_name(fhttp.rx_thread, "FlipperHTTP_RxThread");
+    furi_thread_set_stack_size(fhttp.rx_thread, 1024);
+    furi_thread_set_context(fhttp.rx_thread, &fhttp);
+    furi_thread_set_callback(fhttp.rx_thread, flipper_http_worker);
+
+    fhttp.handle_rx_line_cb = callback;
+    fhttp.callback_context = context;
+
+    furi_thread_start(fhttp.rx_thread);
+    fhttp.rx_thread_id = furi_thread_get_id(fhttp.rx_thread);
+
+    // handle when the UART control is busy to avoid furi_check failed
+    if (furi_hal_serial_control_is_busy(UART_CH))
+    {
+        FURI_LOG_E(HTTP_TAG, "UART control is busy.");
+        return false;
+    }
+
+    fhttp.serial_handle = furi_hal_serial_control_acquire(UART_CH);
+    if (!fhttp.serial_handle)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to acquire UART control - handle is NULL");
+        // Cleanup resources
+        furi_thread_free(fhttp.rx_thread);
+        furi_stream_buffer_free(fhttp.flipper_http_stream);
+        return false;
+    }
+
+    // Initialize UART with acquired handle
+    furi_hal_serial_init(fhttp.serial_handle, BAUDRATE);
+
+    // Enable RX direction
+    furi_hal_serial_enable_direction(fhttp.serial_handle, FuriHalSerialDirectionRx);
+
+    // Start asynchronous RX with the callback
+    furi_hal_serial_async_rx_start(fhttp.serial_handle, _flipper_http_rx_callback, &fhttp, false);
+
+    // Wait for the TX to complete to ensure UART is ready
+    furi_hal_serial_tx_wait_complete(fhttp.serial_handle);
+
+    // Allocate the timer for handling timeouts
+    fhttp.get_timeout_timer = furi_timer_alloc(
+        get_timeout_timer_callback, // Callback function
+        FuriTimerTypeOnce,          // One-shot timer
+        &fhttp                      // Context passed to callback
+    );
+
+    if (!fhttp.get_timeout_timer)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate HTTP request timeout timer.");
+        // Cleanup resources
+        furi_hal_serial_async_rx_stop(fhttp.serial_handle);
+        furi_hal_serial_disable_direction(fhttp.serial_handle, FuriHalSerialDirectionRx);
+        furi_hal_serial_control_release(fhttp.serial_handle);
+        furi_hal_serial_deinit(fhttp.serial_handle);
+        furi_thread_flags_set(fhttp.rx_thread_id, WorkerEvtStop);
+        furi_thread_join(fhttp.rx_thread);
+        furi_thread_free(fhttp.rx_thread);
+        furi_stream_buffer_free(fhttp.flipper_http_stream);
+        return false;
+    }
+
+    // Set the timer thread priority if needed
+    furi_timer_set_thread_priority(FuriTimerThreadPriorityElevated);
+
+    fhttp.last_response = (char *)malloc(RX_BUF_SIZE);
+    if (!fhttp.last_response)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate memory for last_response.");
+        return false;
+    }
+
+    // FURI_LOG_I(HTTP_TAG, "UART initialized successfully.");
+    return true;
+}
+
+// Deinitialize UART
+/**
+ * @brief      Deinitialize UART.
+ * @return     void
+ * @note       This function will stop the asynchronous RX, release the serial handle, and free the resources.
+ */
+void flipper_http_deinit()
+{
+    if (fhttp.serial_handle == NULL)
+    {
+        FURI_LOG_E(HTTP_TAG, "UART handle is NULL. Already deinitialized?");
+        return;
+    }
+    // Stop asynchronous RX
+    furi_hal_serial_async_rx_stop(fhttp.serial_handle);
+
+    // Release and deinitialize the serial handle
+    furi_hal_serial_disable_direction(fhttp.serial_handle, FuriHalSerialDirectionRx);
+    furi_hal_serial_control_release(fhttp.serial_handle);
+    furi_hal_serial_deinit(fhttp.serial_handle);
+
+    // Signal the worker thread to stop
+    furi_thread_flags_set(fhttp.rx_thread_id, WorkerEvtStop);
+    // Wait for the thread to finish
+    furi_thread_join(fhttp.rx_thread);
+    // Free the thread resources
+    furi_thread_free(fhttp.rx_thread);
+
+    // Free the stream buffer
+    furi_stream_buffer_free(fhttp.flipper_http_stream);
+
+    // Free the timer
+    if (fhttp.get_timeout_timer)
+    {
+        furi_timer_free(fhttp.get_timeout_timer);
+        fhttp.get_timeout_timer = NULL;
+    }
+
+    // Free the last response
+    if (fhttp.last_response)
+    {
+        free(fhttp.last_response);
+        fhttp.last_response = NULL;
+    }
+
+    // FURI_LOG_I("FlipperHTTP", "UART deinitialized successfully.");
+}
+
+// Function to send data over UART with newline termination
+/**
+ * @brief      Send data over UART with newline termination.
+ * @return     true if the data was sent successfully, false otherwise.
+ * @param      data  The data to send over UART.
+ * @note       The data will be sent over UART with a newline character appended.
+ */
+bool flipper_http_send_data(const char *data)
+{
+    size_t data_length = strlen(data);
+    if (data_length == 0)
+    {
+        FURI_LOG_E("FlipperHTTP", "Attempted to send empty data.");
+        return false;
+    }
+
+    // Create a buffer with data + '\n'
+    size_t send_length = data_length + 1; // +1 for '\n'
+    if (send_length > 256)
+    { // Ensure buffer size is sufficient
+        FURI_LOG_E("FlipperHTTP", "Data too long to send over FHTTP.");
+        return false;
+    }
+
+    char send_buffer[257]; // 256 + 1 for safety
+    strncpy(send_buffer, data, 256);
+    send_buffer[data_length] = '\n';     // Append newline
+    send_buffer[data_length + 1] = '\0'; // Null-terminate
+
+    if (fhttp.state == INACTIVE && ((strstr(send_buffer, "[PING]") == NULL) &&
+                                    (strstr(send_buffer, "[WIFI/CONNECT]") == NULL)))
+    {
+        FURI_LOG_E("FlipperHTTP", "Cannot send data while INACTIVE.");
+        fhttp.last_response = "Cannot send data while INACTIVE.";
+        return false;
+    }
+
+    fhttp.state = SENDING;
+    furi_hal_serial_tx(fhttp.serial_handle, (const uint8_t *)send_buffer, send_length);
+
+    // Uncomment below line to log the data sent over UART
+    // FURI_LOG_I("FlipperHTTP", "Sent data over UART: %s", send_buffer);
+    fhttp.state = IDLE;
+    return true;
+}
+
+// Function to send a PING request
+/**
+ * @brief      Send a PING request to check if the Wifi Dev Board is connected.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ * @note       This is best used to check if the Wifi Dev Board is connected.
+ * @note       The state will remain INACTIVE until a PONG is received.
+ */
+bool flipper_http_ping()
+{
+    const char *command = "[PING]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send PING command.");
+        return false;
+    }
+    // set state as INACTIVE to be made IDLE if PONG is received
+    fhttp.state = INACTIVE;
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to list available commands
+/**
+ * @brief      Send a command to list available commands.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_list_commands()
+{
+    const char *command = "[LIST]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send LIST command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to turn on the LED
+/**
+ * @brief      Allow the LED to display while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_on()
+{
+    const char *command = "[LED/ON]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send LED ON command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to turn off the LED
+/**
+ * @brief      Disable the LED from displaying while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_off()
+{
+    const char *command = "[LED/OFF]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send LED OFF command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to parse JSON data
+/**
+ * @brief      Parse JSON data.
+ * @return     true if the JSON data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON data.
+ * @param      json_data The JSON data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json(const char *key, const char *json_data)
+{
+    if (!key || !json_data)
+    {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_parse_json.");
+        return false;
+    }
+
+    char buffer[256];
+    int ret =
+        snprintf(buffer, sizeof(buffer), "[PARSE]{\"key\":\"%s\",\"json\":%s}", key, json_data);
+    if (ret < 0 || ret >= (int)sizeof(buffer))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format JSON parse command.");
+        return false;
+    }
+
+    if (!flipper_http_send_data(buffer))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send JSON parse command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to parse JSON array data
+/**
+ * @brief      Parse JSON array data.
+ * @return     true if the JSON array data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON array data.
+ * @param      index     The index to parse from the JSON array data.
+ * @param      json_data The JSON array data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json_array(const char *key, int index, const char *json_data)
+{
+    if (!key || !json_data)
+    {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_parse_json_array.");
+        return false;
+    }
+
+    char buffer[256];
+    int ret = snprintf(
+        buffer,
+        sizeof(buffer),
+        "[PARSE/ARRAY]{\"key\":\"%s\",\"index\":%d,\"json\":%s}",
+        key,
+        index,
+        json_data);
+    if (ret < 0 || ret >= (int)sizeof(buffer))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format JSON parse array command.");
+        return false;
+    }
+
+    if (!flipper_http_send_data(buffer))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send JSON parse array command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to scan for WiFi networks
+/**
+ * @brief      Send a command to scan for WiFi networks.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_scan_wifi()
+{
+    const char *command = "[WIFI/SCAN]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send WiFi scan command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to save WiFi settings (returns true if successful)
+/**
+ * @brief      Send a command to save WiFi settings.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_save_wifi(const char *ssid, const char *password)
+{
+    if (!ssid || !password)
+    {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_save_wifi.");
+        return false;
+    }
+    char buffer[256];
+    int ret = snprintf(
+        buffer, sizeof(buffer), "[WIFI/SAVE]{\"ssid\":\"%s\",\"password\":\"%s\"}", ssid, password);
+    if (ret < 0 || ret >= (int)sizeof(buffer))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format WiFi save command.");
+        return false;
+    }
+
+    if (!flipper_http_send_data(buffer))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send WiFi save command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to get IP address of WiFi Devboard
+/**
+ * @brief      Send a command to get the IP address of the WiFi Devboard
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_address()
+{
+    const char *command = "[IP/ADDRESS]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send IP address command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to get IP address of the connected WiFi network
+/**
+ * @brief      Send a command to get the IP address of the connected WiFi network.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_wifi()
+{
+    const char *command = "[WIFI/IP]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send WiFi IP command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to disconnect from WiFi (returns true if successful)
+/**
+ * @brief      Send a command to disconnect from WiFi.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_disconnect_wifi()
+{
+    const char *command = "[WIFI/DISCONNECT]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send WiFi disconnect command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to connect to WiFi (returns true if successful)
+/**
+ * @brief      Send a command to connect to WiFi.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_connect_wifi()
+{
+    const char *command = "[WIFI/CONNECT]";
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send WiFi connect command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to send a GET request
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request(const char *url)
+{
+    if (!url)
+    {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_get_request.");
+        return false;
+    }
+
+    // Prepare GET request command
+    char command[256];
+    int ret = snprintf(command, sizeof(command), "[GET]%s", url);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format GET request command.");
+        return false;
+    }
+
+    // Send GET request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send GET request command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to send a GET request with headers
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @param      headers  The headers to send with the GET request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request_with_headers(const char *url, const char *headers)
+{
+    if (!url || !headers)
+    {
+        FURI_LOG_E(
+            "FlipperHTTP", "Invalid arguments provided to flipper_http_get_request_with_headers.");
+        return false;
+    }
+
+    // Prepare GET request command with headers
+    char command[256];
+    int ret = snprintf(
+        command, sizeof(command), "[GET/HTTP]{\"url\":\"%s\",\"headers\":%s}", url, headers);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format GET request command with headers.");
+        return false;
+    }
+
+    // Send GET request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send GET request command with headers.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to send a GET request with headers and return bytes
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @param      headers  The headers to send with the GET request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request_bytes(const char *url, const char *headers)
+{
+    if (!url || !headers)
+    {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_get_request_bytes.");
+        return false;
+    }
+
+    // Prepare GET request command with headers
+    char command[256];
+    int ret = snprintf(
+        command, sizeof(command), "[GET/BYTES]{\"url\":\"%s\",\"headers\":%s}", url, headers);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format GET request command with headers.");
+        return false;
+    }
+
+    // Send GET request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send GET request command with headers.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to send a POST request with headers
+/**
+ * @brief      Send a POST request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the POST request to.
+ * @param      headers  The headers to send with the POST request.
+ * @param      data  The data to send with the POST request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_post_request_with_headers(
+    const char *url,
+    const char *headers,
+    const char *payload)
+{
+    if (!url || !headers || !payload)
+    {
+        FURI_LOG_E(
+            "FlipperHTTP",
+            "Invalid arguments provided to flipper_http_post_request_with_headers.");
+        return false;
+    }
+
+    // Prepare POST request command with headers and data
+    char command[256];
+    int ret = snprintf(
+        command,
+        sizeof(command),
+        "[POST/HTTP]{\"url\":\"%s\",\"headers\":%s,\"payload\":%s}",
+        url,
+        headers,
+        payload);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format POST request command with headers and data.");
+        return false;
+    }
+
+    // Send POST request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send POST request command with headers and data.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to send a POST request with headers and return bytes
+/**
+ * @brief      Send a POST request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the POST request to.
+ * @param      headers  The headers to send with the POST request.
+ * @param      payload  The data to send with the POST request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_post_request_bytes(const char *url, const char *headers, const char *payload)
+{
+    if (!url || !headers || !payload)
+    {
+        FURI_LOG_E(
+            "FlipperHTTP", "Invalid arguments provided to flipper_http_post_request_bytes.");
+        return false;
+    }
+
+    // Prepare POST request command with headers and data
+    char command[256];
+    int ret = snprintf(
+        command,
+        sizeof(command),
+        "[POST/BYTES]{\"url\":\"%s\",\"headers\":%s,\"payload\":%s}",
+        url,
+        headers,
+        payload);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format POST request command with headers and data.");
+        return false;
+    }
+
+    // Send POST request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send POST request command with headers and data.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to send a PUT request with headers
+/**
+ * @brief      Send a PUT request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the PUT request to.
+ * @param      headers  The headers to send with the PUT request.
+ * @param      data  The data to send with the PUT request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_put_request_with_headers(
+    const char *url,
+    const char *headers,
+    const char *payload)
+{
+    if (!url || !headers || !payload)
+    {
+        FURI_LOG_E(
+            "FlipperHTTP", "Invalid arguments provided to flipper_http_put_request_with_headers.");
+        return false;
+    }
+
+    // Prepare PUT request command with headers and data
+    char command[256];
+    int ret = snprintf(
+        command,
+        sizeof(command),
+        "[PUT/HTTP]{\"url\":\"%s\",\"headers\":%s,\"payload\":%s}",
+        url,
+        headers,
+        payload);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to format PUT request command with headers and data.");
+        return false;
+    }
+
+    // Send PUT request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send PUT request command with headers and data.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to send a DELETE request with headers
+/**
+ * @brief      Send a DELETE request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the DELETE request to.
+ * @param      headers  The headers to send with the DELETE request.
+ * @param      data  The data to send with the DELETE request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_delete_request_with_headers(
+    const char *url,
+    const char *headers,
+    const char *payload)
+{
+    if (!url || !headers || !payload)
+    {
+        FURI_LOG_E(
+            "FlipperHTTP",
+            "Invalid arguments provided to flipper_http_delete_request_with_headers.");
+        return false;
+    }
+
+    // Prepare DELETE request command with headers and data
+    char command[256];
+    int ret = snprintf(
+        command,
+        sizeof(command),
+        "[DELETE/HTTP]{\"url\":\"%s\",\"headers\":%s,\"payload\":%s}",
+        url,
+        headers,
+        payload);
+    if (ret < 0 || ret >= (int)sizeof(command))
+    {
+        FURI_LOG_E(
+            "FlipperHTTP", "Failed to format DELETE request command with headers and data.");
+        return false;
+    }
+
+    // Send DELETE request via UART
+    if (!flipper_http_send_data(command))
+    {
+        FURI_LOG_E("FlipperHTTP", "Failed to send DELETE request command with headers and data.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+// Function to trim leading and trailing spaces and newlines from a constant string
+static char *trim(const char *str)
+{
+    const char *end;
+    char *trimmed_str;
+    size_t len;
+
+    // Trim leading space
+    while (isspace((unsigned char)*str))
+        str++;
+
+    // All spaces?
+    if (*str == 0)
+        return strdup(""); // Return an empty string if all spaces
+
+    // Trim trailing space
+    end = str + strlen(str) - 1;
+    while (end > str && isspace((unsigned char)*end))
+        end--;
+
+    // Set length for the trimmed string
+    len = end - str + 1;
+
+    // Allocate space for the trimmed string and null terminator
+    trimmed_str = (char *)malloc(len + 1);
+    if (trimmed_str == NULL)
+    {
+        return NULL; // Handle memory allocation failure
+    }
+
+    // Copy the trimmed part of the string into trimmed_str
+    strncpy(trimmed_str, str, len);
+    trimmed_str[len] = '\0'; // Null terminate the string
+
+    return trimmed_str;
+}
+
+// Function to handle received data asynchronously
+/**
+ * @brief      Callback function to handle received data asynchronously.
+ * @return     void
+ * @param      line     The received line.
+ * @param      context  The context passed to the callback.
+ * @note       The received data will be handled asynchronously via the callback and handles the state of the UART.
+ */
+void flipper_http_rx_callback(const char *line, void *context)
+{
+    if (!line || !context)
+    {
+        FURI_LOG_E(HTTP_TAG, "Invalid arguments provided to flipper_http_rx_callback.");
+        return;
+    }
+
+    // Trim the received line to check if it's empty
+    char *trimmed_line = trim(line);
+    if (trimmed_line != NULL && trimmed_line[0] != '\0')
+    {
+        // if the line is not [GET/END] or [POST/END] or [PUT/END] or [DELETE/END]
+        if (strstr(trimmed_line, "[GET/END]") == NULL &&
+            strstr(trimmed_line, "[POST/END]") == NULL &&
+            strstr(trimmed_line, "[PUT/END]") == NULL &&
+            strstr(trimmed_line, "[DELETE/END]") == NULL)
+        {
+            strncpy(fhttp.last_response, trimmed_line, RX_BUF_SIZE);
+        }
+    }
+    free(trimmed_line); // Free the allocated memory for trimmed_line
+
+    if (fhttp.state != INACTIVE && fhttp.state != ISSUE)
+    {
+        fhttp.state = RECEIVING;
+    }
+
+    // Uncomment below line to log the data received over UART
+    // FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
+
+    // Check if we've started receiving data from a GET request
+    if (fhttp.started_receiving_get)
+    {
+        // Restart the timeout timer each time new data is received
+        furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+
+        if (strstr(line, "[GET/END]") != NULL)
+        {
+            FURI_LOG_I(HTTP_TAG, "GET request completed.");
+            // Stop the timer since we've completed the GET request
+            furi_timer_stop(fhttp.get_timeout_timer);
+            fhttp.started_receiving_get = false;
+            fhttp.just_started_get = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.save_received_data = false;
+
+            if (fhttp.is_bytes_request)
+            {
+                // Search for the binary marker `[GET/END]` in the file buffer
+                const char marker[] = "[GET/END]";
+                const size_t marker_len = sizeof(marker) - 1; // Exclude null terminator
+
+                for (size_t i = 0; i <= fhttp.file_buffer_len - marker_len; i++)
+                {
+                    // Check if the marker is found
+                    if (memcmp(&fhttp.file_buffer[i], marker, marker_len) == 0)
+                    {
+                        // Remove the marker by shifting the remaining data left
+                        size_t remaining_len = fhttp.file_buffer_len - (i + marker_len);
+                        memmove(&fhttp.file_buffer[i], &fhttp.file_buffer[i + marker_len], remaining_len);
+                        fhttp.file_buffer_len -= marker_len;
+                        break;
+                    }
+                }
+
+                // If there is data left in the buffer, append it to the file
+                if (fhttp.file_buffer_len > 0)
+                {
+                    if (!flipper_http_append_to_file(fhttp.file_buffer, fhttp.file_buffer_len, false, fhttp.file_path))
+                    {
+                        FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+                    }
+                    fhttp.file_buffer_len = 0;
+                }
+            }
+
+            fhttp.is_bytes_request = false;
+            return;
+        }
+
+        // Append the new line to the existing data
+        if (fhttp.save_received_data &&
+            !flipper_http_append_to_file(
+                line, strlen(line), !fhttp.just_started_get, fhttp.file_path))
+        {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_get = false;
+            fhttp.just_started_get = false;
+            fhttp.state = IDLE;
+            return;
+        }
+
+        if (!fhttp.just_started_get)
+        {
+            fhttp.just_started_get = true;
+        }
+        return;
+    }
+
+    // Check if we've started receiving data from a POST request
+    else if (fhttp.started_receiving_post)
+    {
+        // Restart the timeout timer each time new data is received
+        furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+
+        if (strstr(line, "[POST/END]") != NULL)
+        {
+            FURI_LOG_I(HTTP_TAG, "POST request completed.");
+            // Stop the timer since we've completed the POST request
+            furi_timer_stop(fhttp.get_timeout_timer);
+            fhttp.started_receiving_post = false;
+            fhttp.just_started_post = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.save_received_data = false;
+
+            if (fhttp.is_bytes_request)
+            {
+                // Search for the binary marker `[POST/END]` in the file buffer
+                const char marker[] = "[POST/END]";
+                const size_t marker_len = sizeof(marker) - 1; // Exclude null terminator
+
+                for (size_t i = 0; i <= fhttp.file_buffer_len - marker_len; i++)
+                {
+                    // Check if the marker is found
+                    if (memcmp(&fhttp.file_buffer[i], marker, marker_len) == 0)
+                    {
+                        // Remove the marker by shifting the remaining data left
+                        size_t remaining_len = fhttp.file_buffer_len - (i + marker_len);
+                        memmove(&fhttp.file_buffer[i], &fhttp.file_buffer[i + marker_len], remaining_len);
+                        fhttp.file_buffer_len -= marker_len;
+                        break;
+                    }
+                }
+
+                // If there is data left in the buffer, append it to the file
+                if (fhttp.file_buffer_len > 0)
+                {
+                    if (!flipper_http_append_to_file(fhttp.file_buffer, fhttp.file_buffer_len, false, fhttp.file_path))
+                    {
+                        FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+                    }
+                    fhttp.file_buffer_len = 0;
+                }
+            }
+
+            fhttp.is_bytes_request = false;
+            return;
+        }
+
+        // Append the new line to the existing data
+        if (fhttp.save_received_data &&
+            !flipper_http_append_to_file(
+                line, strlen(line), !fhttp.just_started_post, fhttp.file_path))
+        {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_post = false;
+            fhttp.just_started_post = false;
+            fhttp.state = IDLE;
+            return;
+        }
+
+        if (!fhttp.just_started_post)
+        {
+            fhttp.just_started_post = true;
+        }
+        return;
+    }
+
+    // Check if we've started receiving data from a PUT request
+    else if (fhttp.started_receiving_put)
+    {
+        // Restart the timeout timer each time new data is received
+        furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+
+        if (strstr(line, "[PUT/END]") != NULL)
+        {
+            FURI_LOG_I(HTTP_TAG, "PUT request completed.");
+            // Stop the timer since we've completed the PUT request
+            furi_timer_stop(fhttp.get_timeout_timer);
+            fhttp.started_receiving_put = false;
+            fhttp.just_started_put = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.is_bytes_request = false;
+            fhttp.save_received_data = false;
+            return;
+        }
+
+        // Append the new line to the existing data
+        if (fhttp.save_received_data &&
+            !flipper_http_append_to_file(
+                line, strlen(line), !fhttp.just_started_put, fhttp.file_path))
+        {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_put = false;
+            fhttp.just_started_put = false;
+            fhttp.state = IDLE;
+            return;
+        }
+
+        if (!fhttp.just_started_put)
+        {
+            fhttp.just_started_put = true;
+        }
+        return;
+    }
+
+    // Check if we've started receiving data from a DELETE request
+    else if (fhttp.started_receiving_delete)
+    {
+        // Restart the timeout timer each time new data is received
+        furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+
+        if (strstr(line, "[DELETE/END]") != NULL)
+        {
+            FURI_LOG_I(HTTP_TAG, "DELETE request completed.");
+            // Stop the timer since we've completed the DELETE request
+            furi_timer_stop(fhttp.get_timeout_timer);
+            fhttp.started_receiving_delete = false;
+            fhttp.just_started_delete = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.is_bytes_request = false;
+            fhttp.save_received_data = false;
+            return;
+        }
+
+        // Append the new line to the existing data
+        if (fhttp.save_received_data &&
+            !flipper_http_append_to_file(
+                line, strlen(line), !fhttp.just_started_delete, fhttp.file_path))
+        {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_delete = false;
+            fhttp.just_started_delete = false;
+            fhttp.state = IDLE;
+            return;
+        }
+
+        if (!fhttp.just_started_delete)
+        {
+            fhttp.just_started_delete = true;
+        }
+        return;
+    }
+
+    // Handle different types of responses
+    if (strstr(line, "[SUCCESS]") != NULL || strstr(line, "[CONNECTED]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "Operation succeeded.");
+    }
+    else if (strstr(line, "[INFO]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "Received info: %s", line);
+
+        if (fhttp.state == INACTIVE && strstr(line, "[INFO] Already connected to Wifi.") != NULL)
+        {
+            fhttp.state = IDLE;
+        }
+    }
+    else if (strstr(line, "[GET/SUCCESS]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "GET request succeeded.");
+        fhttp.started_receiving_get = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        fhttp.state = RECEIVING;
+        // for GET request, save data only if it's a bytes request
+        fhttp.save_bytes = fhttp.is_bytes_request;
+        fhttp.just_started_bytes = true;
+        fhttp.file_buffer_len = 0;
+        return;
+    }
+    else if (strstr(line, "[POST/SUCCESS]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "POST request succeeded.");
+        fhttp.started_receiving_post = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        fhttp.state = RECEIVING;
+        // for POST request, save data only if it's a bytes request
+        fhttp.save_bytes = fhttp.is_bytes_request;
+        fhttp.just_started_bytes = true;
+        fhttp.file_buffer_len = 0;
+        return;
+    }
+    else if (strstr(line, "[PUT/SUCCESS]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "PUT request succeeded.");
+        fhttp.started_receiving_put = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        fhttp.state = RECEIVING;
+        return;
+    }
+    else if (strstr(line, "[DELETE/SUCCESS]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "DELETE request succeeded.");
+        fhttp.started_receiving_delete = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        fhttp.state = RECEIVING;
+        return;
+    }
+    else if (strstr(line, "[DISCONNECTED]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "WiFi disconnected successfully.");
+    }
+    else if (strstr(line, "[ERROR]") != NULL)
+    {
+        FURI_LOG_E(HTTP_TAG, "Received error: %s", line);
+        fhttp.state = ISSUE;
+        return;
+    }
+    else if (strstr(line, "[PONG]") != NULL)
+    {
+        FURI_LOG_I(HTTP_TAG, "Received PONG response: Wifi Dev Board is still alive.");
+
+        // send command to connect to WiFi
+        if (fhttp.state == INACTIVE)
+        {
+            fhttp.state = IDLE;
+            return;
+        }
+    }
+
+    if (fhttp.state == INACTIVE && strstr(line, "[PONG]") != NULL)
+    {
+        fhttp.state = IDLE;
+    }
+    else if (fhttp.state == INACTIVE && strstr(line, "[PONG]") == NULL)
+    {
+        fhttp.state = INACTIVE;
+    }
+    else
+    {
+        fhttp.state = IDLE;
+    }
+}
+
+/**
+ * @brief Process requests and parse JSON data asynchronously
+ * @param http_request The function to send the request
+ * @param parse_json The function to parse the JSON
+ * @return true if successful, false otherwise
+ */
+bool flipper_http_process_response_async(bool (*http_request)(void), bool (*parse_json)(void))
+{
+    if (http_request()) // start the async request
+    {
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        fhttp.state = RECEIVING;
+    }
+    else
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to send request");
+        return false;
+    }
+    while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
+    {
+        // Wait for the request to be received
+        furi_delay_ms(100);
+    }
+    furi_timer_stop(fhttp.get_timeout_timer);
+    if (!parse_json()) // parse the JSON before switching to the view (synchonous)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to parse the JSON...");
+        return false;
+    }
+    return true;
+}
+
+/**
+ * @brief Perform a task while displaying a loading screen
+ * @param http_request The function to send the request
+ * @param parse_response The function to parse the response
+ * @param success_view_id The view ID to switch to on success
+ * @param failure_view_id The view ID to switch to on failure
+ * @param view_dispatcher The view dispatcher to use
+ * @return
+ */
+void flipper_http_loading_task(bool (*http_request)(void),
+                               bool (*parse_response)(void),
+                               uint32_t success_view_id,
+                               uint32_t failure_view_id,
+                               ViewDispatcher **view_dispatcher)
+{
+    if (fhttp.state == INACTIVE)
+    {
+        view_dispatcher_switch_to_view(*view_dispatcher, failure_view_id);
+        return;
+    }
+    Loading *loading;
+    int32_t loading_view_id = 987654321; // Random ID
+
+    loading = loading_alloc();
+    if (!loading)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate loading");
+        view_dispatcher_switch_to_view(*view_dispatcher, failure_view_id);
+
+        return;
+    }
+
+    view_dispatcher_add_view(*view_dispatcher, loading_view_id, loading_get_view(loading));
+
+    // Switch to the loading view
+    view_dispatcher_switch_to_view(*view_dispatcher, loading_view_id);
+
+    // Make the request
+    if (!flipper_http_process_response_async(http_request, parse_response))
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to make request");
+        view_dispatcher_switch_to_view(*view_dispatcher, failure_view_id);
+        view_dispatcher_remove_view(*view_dispatcher, loading_view_id);
+        loading_free(loading);
+
+        return;
+    }
+
+    // Switch to the success view
+    view_dispatcher_switch_to_view(*view_dispatcher, success_view_id);
+    view_dispatcher_remove_view(*view_dispatcher, loading_view_id);
+    loading_free(loading); // comment this out if you experience a freeze
+}

+ 385 - 0
flipper_http/flipper_http.h

@@ -0,0 +1,385 @@
+// Description: Flipper HTTP API (For use with Flipper Zero and the FlipperHTTP flash: https://github.com/jblanked/FlipperHTTP)
+// License: MIT
+// Author: JBlanked
+// File: flipper_http.h
+#ifndef FLIPPER_HTTP_H
+#define FLIPPER_HTTP_H
+
+#include <gui/gui.h>
+#include <gui/view.h>
+#include <gui/view_dispatcher.h>
+#include <gui/modules/loading.h>
+#include <furi.h>
+#include <furi_hal.h>
+#include <furi_hal_gpio.h>
+#include <furi_hal_serial.h>
+#include <storage/storage.h>
+
+// STORAGE_EXT_PATH_PREFIX is defined in the Furi SDK as /ext
+
+#define HTTP_TAG "FlipWorld"              // change this to your app name
+#define http_tag "flip_world"             // change this to your app id
+#define UART_CH (FuriHalSerialIdUsart)    // UART channel
+#define TIMEOUT_DURATION_TICKS (5 * 1000) // 5 seconds
+#define BAUDRATE (115200)                 // UART baudrate
+#define RX_BUF_SIZE 1024                  // UART RX buffer size
+#define RX_LINE_BUFFER_SIZE 4096          // UART RX line buffer size (increase for large responses)
+#define MAX_FILE_SHOW 4096                // Maximum data from file to show
+#define FILE_BUFFER_SIZE 512              // File buffer size
+
+// Forward declaration for callback
+typedef void (*FlipperHTTP_Callback)(const char *line, void *context);
+
+// State variable to track the UART state
+typedef enum
+{
+    INACTIVE,  // Inactive state
+    IDLE,      // Default state
+    RECEIVING, // Receiving data
+    SENDING,   // Sending data
+    ISSUE,     // Issue with connection
+} SerialState;
+
+// Event Flags for UART Worker Thread
+typedef enum
+{
+    WorkerEvtStop = (1 << 0),
+    WorkerEvtRxDone = (1 << 1),
+} WorkerEvtFlags;
+
+// FlipperHTTP Structure
+typedef struct
+{
+    FuriStreamBuffer *flipper_http_stream;  // Stream buffer for UART communication
+    FuriHalSerialHandle *serial_handle;     // Serial handle for UART communication
+    FuriThread *rx_thread;                  // Worker thread for UART
+    FuriThreadId rx_thread_id;              // Worker thread ID
+    FlipperHTTP_Callback handle_rx_line_cb; // Callback for received lines
+    void *callback_context;                 // Context for the callback
+    SerialState state;                      // State of the UART
+
+    // variable to store the last received data from the UART
+    char *last_response;
+    char file_path[256]; // Path to save the received data
+
+    // Timer-related members
+    FuriTimer *get_timeout_timer; // Timer for HTTP request timeout
+
+    bool started_receiving_get; // Indicates if a GET request has started
+    bool just_started_get;      // Indicates if GET data reception has just started
+
+    bool started_receiving_post; // Indicates if a POST request has started
+    bool just_started_post;      // Indicates if POST data reception has just started
+
+    bool started_receiving_put; // Indicates if a PUT request has started
+    bool just_started_put;      // Indicates if PUT data reception has just started
+
+    bool started_receiving_delete; // Indicates if a DELETE request has started
+    bool just_started_delete;      // Indicates if DELETE data reception has just started
+
+    // Buffer to hold the raw bytes received from the UART
+    uint8_t *received_bytes;
+    size_t received_bytes_len; // Length of the received bytes
+    bool is_bytes_request;     // Flag to indicate if the request is for bytes
+    bool save_bytes;           // Flag to save the received data to a file
+    bool save_received_data;   // Flag to save the received data to a file
+
+    bool just_started_bytes; // Indicates if bytes data reception has just started
+
+    char rx_line_buffer[RX_LINE_BUFFER_SIZE];
+    uint8_t file_buffer[FILE_BUFFER_SIZE];
+    size_t file_buffer_len;
+} FlipperHTTP;
+
+extern FlipperHTTP fhttp;
+
+// fhttp.last_response holds the last received data from the UART
+
+// Function to append received data to file
+// make sure to initialize the file path before calling this function
+bool flipper_http_append_to_file(
+    const void *data,
+    size_t data_size,
+    bool start_new_file,
+    char *file_path);
+
+FuriString *flipper_http_load_from_file(char *file_path);
+
+// UART worker thread
+/**
+ * @brief      Worker thread to handle UART data asynchronously.
+ * @return     0
+ * @param      context   The context to pass to the callback.
+ * @note       This function will handle received data asynchronously via the callback.
+ */
+// UART worker thread
+int32_t flipper_http_worker(void *context);
+
+// Timer callback function
+/**
+ * @brief      Callback function for the GET timeout timer.
+ * @return     0
+ * @param      context   The context to pass to the callback.
+ * @note       This function will be called when the GET request times out.
+ */
+void get_timeout_timer_callback(void *context);
+
+// UART RX Handler Callback (Interrupt Context)
+/**
+ * @brief      A private callback function to handle received data asynchronously.
+ * @return     void
+ * @param      handle    The UART handle.
+ * @param      event     The event type.
+ * @param      context   The context to pass to the callback.
+ * @note       This function will handle received data asynchronously via the callback.
+ */
+void _flipper_http_rx_callback(
+    FuriHalSerialHandle *handle,
+    FuriHalSerialRxEvent event,
+    void *context);
+
+// UART initialization function
+/**
+ * @brief      Initialize UART.
+ * @return     true if the UART was initialized successfully, false otherwise.
+ * @param      callback  The callback function to handle received data (ex. flipper_http_rx_callback).
+ * @param      context   The context to pass to the callback.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_init(FlipperHTTP_Callback callback, void *context);
+
+// Deinitialize UART
+/**
+ * @brief      Deinitialize UART.
+ * @return     void
+ * @note       This function will stop the asynchronous RX, release the serial handle, and free the resources.
+ */
+void flipper_http_deinit();
+
+// Function to send data over UART with newline termination
+/**
+ * @brief      Send data over UART with newline termination.
+ * @return     true if the data was sent successfully, false otherwise.
+ * @param      data  The data to send over UART.
+ * @note       The data will be sent over UART with a newline character appended.
+ */
+bool flipper_http_send_data(const char *data);
+
+// Function to send a PING request
+/**
+ * @brief      Send a PING request to check if the Wifi Dev Board is connected.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ * @note       This is best used to check if the Wifi Dev Board is connected.
+ * @note       The state will remain INACTIVE until a PONG is received.
+ */
+bool flipper_http_ping();
+
+// Function to list available commands
+/**
+ * @brief      Send a command to list available commands.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_list_commands();
+
+// Function to turn on the LED
+/**
+ * @brief      Allow the LED to display while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_on();
+
+// Function to turn off the LED
+/**
+ * @brief      Disable the LED from displaying while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_off();
+
+// Function to parse JSON data
+/**
+ * @brief      Parse JSON data.
+ * @return     true if the JSON data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON data.
+ * @param      json_data The JSON data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json(const char *key, const char *json_data);
+
+// Function to parse JSON array data
+/**
+ * @brief      Parse JSON array data.
+ * @return     true if the JSON array data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON array data.
+ * @param      index     The index to parse from the JSON array data.
+ * @param      json_data The JSON array data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json_array(const char *key, int index, const char *json_data);
+
+// Function to scan for WiFi networks
+/**
+ * @brief      Send a command to scan for WiFi networks.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_scan_wifi();
+
+// Function to save WiFi settings (returns true if successful)
+/**
+ * @brief      Send a command to save WiFi settings.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_save_wifi(const char *ssid, const char *password);
+
+// Function to get IP address of WiFi Devboard
+/**
+ * @brief      Send a command to get the IP address of the WiFi Devboard
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_address();
+
+// Function to get IP address of the connected WiFi network
+/**
+ * @brief      Send a command to get the IP address of the connected WiFi network.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_wifi();
+
+// Function to disconnect from WiFi (returns true if successful)
+/**
+ * @brief      Send a command to disconnect from WiFi.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_disconnect_wifi();
+
+// Function to connect to WiFi (returns true if successful)
+/**
+ * @brief      Send a command to connect to WiFi.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_connect_wifi();
+
+// Function to send a GET request
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request(const char *url);
+
+// Function to send a GET request with headers
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @param      headers  The headers to send with the GET request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request_with_headers(const char *url, const char *headers);
+
+// Function to send a GET request with headers and return bytes
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @param      headers  The headers to send with the GET request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request_bytes(const char *url, const char *headers);
+
+// Function to send a POST request with headers
+/**
+ * @brief      Send a POST request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the POST request to.
+ * @param      headers  The headers to send with the POST request.
+ * @param      data  The data to send with the POST request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_post_request_with_headers(
+    const char *url,
+    const char *headers,
+    const char *payload);
+
+// Function to send a POST request with headers and return bytes
+/**
+ * @brief      Send a POST request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the POST request to.
+ * @param      headers  The headers to send with the POST request.
+ * @param      payload  The data to send with the POST request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_post_request_bytes(const char *url, const char *headers, const char *payload);
+
+// Function to send a PUT request with headers
+/**
+ * @brief      Send a PUT request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the PUT request to.
+ * @param      headers  The headers to send with the PUT request.
+ * @param      data  The data to send with the PUT request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_put_request_with_headers(
+    const char *url,
+    const char *headers,
+    const char *payload);
+
+// Function to send a DELETE request with headers
+/**
+ * @brief      Send a DELETE request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the DELETE request to.
+ * @param      headers  The headers to send with the DELETE request.
+ * @param      data  The data to send with the DELETE request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_delete_request_with_headers(
+    const char *url,
+    const char *headers,
+    const char *payload);
+
+// Function to handle received data asynchronously
+/**
+ * @brief      Callback function to handle received data asynchronously.
+ * @return     void
+ * @param      line     The received line.
+ * @param      context  The context passed to the callback.
+ * @note       The received data will be handled asynchronously via the callback and handles the state of the UART.
+ */
+void flipper_http_rx_callback(const char *line, void *context);
+
+/**
+ * @brief Process requests and parse JSON data asynchronously
+ * @param http_request The function to send the request
+ * @param parse_json The function to parse the JSON
+ * @return true if successful, false otherwise
+ */
+bool flipper_http_process_response_async(bool (*http_request)(void), bool (*parse_json)(void));
+
+/**
+ * @brief Perform a task while displaying a loading screen
+ * @param http_request The function to send the request
+ * @param parse_response The function to parse the response
+ * @param success_view_id The view ID to switch to on success
+ * @param failure_view_id The view ID to switch to on failure
+ * @param view_dispatcher The view dispatcher to use
+ * @return
+ */
+void flipper_http_loading_task(bool (*http_request)(void),
+                               bool (*parse_response)(void),
+                               uint32_t success_view_id,
+                               uint32_t failure_view_id,
+                               ViewDispatcher **view_dispatcher);
+#endif // FLIPPER_HTTP_H

+ 316 - 0
font/font.c

@@ -0,0 +1,316 @@
+#include <font/font.h>
+
+static const uint8_t u8g2_font_4x6_tf[];
+static const uint8_t u8g2_font_6x10_tf[];
+static const uint8_t u8g2_font_5x8_tf[];
+static const uint8_t u8g2_font_9x15_tf[];
+
+bool canvas_set_font_custom(Canvas *canvas, FontSize font_size)
+{
+    if (!canvas)
+    {
+        return false;
+    }
+    switch (font_size)
+    {
+    case FONT_SIZE_SMALL:
+        canvas_set_custom_u8g2_font(canvas, u8g2_font_4x6_tf);
+        break;
+    case FONT_SIZE_MEDIUM:
+        canvas_set_custom_u8g2_font(canvas, u8g2_font_5x8_tf);
+        break;
+    case FONT_SIZE_LARGE:
+        canvas_set_custom_u8g2_font(canvas, u8g2_font_6x10_tf);
+        break;
+    case FONT_SIZE_XLARGE:
+        canvas_set_custom_u8g2_font(canvas, u8g2_font_9x15_tf);
+        break;
+    default:
+        return false;
+    }
+    return true;
+}
+
+void canvas_draw_str_multi(Canvas *canvas, uint8_t x, uint8_t y, const char *str)
+{
+    if (!canvas || !str)
+    {
+        return;
+    }
+    elements_multiline_text(canvas, x, y, str);
+}
+
+/*
+  Fontname: -Misc-Fixed-Medium-R-Normal--6-60-75-75-C-40-ISO10646-1
+  Copyright: Public domain font.  Share and enjoy.
+  Glyphs: 191/919
+  BBX Build Mode: 0
+*/
+static const uint8_t u8g2_font_4x6_tf[] =
+    "\277\0\2\2\3\3\2\4\4\4\6\0\377\5\377\5\377\0\351\1\323\5\216 \5\200\315\0!\6\351\310"
+    "\254\0\42\6\223\313$\25#\12\254\310\244\64T\32*\1$\11\263\307\245\241GJ\0%\10\253\310d"
+    "\324F\1&\11\254\310\305\24\253\230\2'\5\321\313\10(\7\362\307\251f\0)\10\262\307\304T)\0"
+    "*\7\253\310\244j\65+\10\253\310\305\264b\2,\6\222\307)\0-\5\213\312\14.\5\311\310\4/"
+    "\7\253\310Ve\4\60\10\253\310UCU\0\61\7\253\310%Y\15\62\7\253\310\65S\32\63\10\253\310"
+    "\314\224\27\0\64\10\253\310$\65b\1\65\10\253\310\214\250\27\0\66\7\253\310M\325\2\67\10\253\310\314"
+    "TF\0\70\7\253\310\255\326\2\71\7\253\310\265\344\2:\6\341\310\304\0;\7\252\307e\250\0<\7"
+    "\253\310\246\272\0=\6\233\311\354\1>\7\253\310\344\252\4\77\10\253\310\350\224a\2@\6\253\310-["
+    "A\10\253\310UC\251\0B\10\253\310\250\264\322\2C\10\253\310U\62U\0D\10\253\310\250d-\0"
+    "E\10\253\310\214\250\342\0F\10\253\310\214\250b\4G\10\253\310\315\244\222\0H\10\253\310$\65\224\12"
+    "I\7\253\310\254X\15J\7\253\310\226\252\2K\10\253\310$\265\222\12L\7\253\310\304\346\0M\10\253"
+    "\310\244\61\224\12N\10\253\310\252\241$\0O\7\253\310UV\5P\10\253\310\250\264b\4Q\7\263\307"
+    "UV\35R\10\253\310\250\264\222\12S\7\253\310\355\274\0T\7\253\310\254\330\2U\7\253\310$\327\10"
+    "V\10\253\310$k\244\4W\10\253\310$\65\206\12X\10\253\310$\325R\1Y\10\253\310$UV\0"
+    "Z\7\253\310\314T\16[\6\352\310\254J\134\7\253\310\304\134\6]\6\252\310\250j^\5\223\313\65_"
+    "\5\213\307\14`\6\322\313\304\0a\7\243\310-\225\4b\10\253\310D\225\324\2c\6\243\310\315,d"
+    "\10\253\310\246\245\222\0e\6\243\310USf\10\253\310\246\264b\2g\10\253\307\255$\27\0h\10\253"
+    "\310D\225\254\0i\10\253\310e$\323\0j\10\263\307fX.\0k\10\253\310\304\264\222\12l\7\253"
+    "\310\310\326\0m\10\243\310\244\241T\0n\7\243\310\250d\5o\7\243\310U\252\2p\10\253\307\250\264"
+    "b\4q\10\253\307-\225d\0r\10\243\310\244\25#\0s\7\243\310\215\274\0t\10\253\310\245\25s"
+    "\0u\7\243\310$+\11v\7\243\310$\253\2w\10\243\310$\65T\0x\7\243\310\244\62\25y\10"
+    "\253\307$\225\344\2z\7\243\310\314\224\6{\10\263\307\246$\353\0|\6\351\310\14\1}\11\263\307\344"
+    "\250b\212\0~\7\224\313%\225\0\240\5\200\315\0\241\6\351\310\244\1\242\10\253\310\245\21W\2\243\7"
+    "\253\310\246\250\32\244\10\244\310\304$U\14\245\10\253\310\244j\305\4\246\6\351\310(\1\247\10\263\307\215"
+    "T\311\5\250\6\213\314\244\0\251\11\264\307\251\270\226L\12\252\7\253\310\255\244\7\253\10\234\311%\25S"
+    "\0\254\6\223\311\314\0\255\5\213\312\14\256\10\244\311\251\261\222\2\257\5\213\314\14\260\6\233\312u\1\261"
+    "\10\253\310\245\225\321\0\262\6\242\311(\3\263\7\252\310(\251\0\264\6\322\313)\0\265\10\253\307$k"
+    "E\0\266\7\254\310\15\265z\267\5\311\312\4\270\6\322\310)\0\271\6\242\311\255\2\272\7\253\310u\243"
+    "\1\273\10\234\311\244\230T\2\274\10\264\307\344\32U;\275\10\264\307\344J\307,\276\11\264\307\350\230Q"
+    "\262\3\277\10\253\310e\230\262\0\300\10\253\310\344\224\206\12\301\10\253\310\246j\250\0\302\10\253\310\310\224"
+    "\206\12\303\10\253\310\215\224\206\12\304\10\253\310\244\326P\1\305\10\253\310\305\224\206\12\306\11\254\310\215\224"
+    "\206\252\4\307\10\263\307U\62\65\1\310\10\253\310\304\241\342\0\311\7\253\310\216\25\7\312\10\253\310\215\221"
+    "\342\0\313\10\253\310\244\261\342\0\314\10\253\310\304\25\323\0\315\10\253\310\216\24\323\0\316\10\253\310\245\25"
+    "\323\0\317\7\253\310\244\262\32\320\11\254\310\314\264\252\221\0\321\10\254\310%\225\256\12\322\10\253\310\344\224"
+    "T\5\323\10\253\310\246JU\0\324\10\253\310\305\224T\5\325\10\254\310\215\325\31\1\326\10\253\310\244\226"
+    "\252\0\327\6\233\311\244\16\330\7\253\310\35j\1\331\10\253\310\344\224\324\10\332\10\253\310\246J\215\0\333"
+    "\10\253\310e\224\324\10\334\10\253\310\244\234\324\10\335\10\253\310\346T&\0\336\10\253\310D\225V\4\337"
+    "\10\263\307U+\15\11\340\10\253\310\344\270\222\0\341\10\253\310\246\270\222\0\342\10\253\310i\264\222\0\343"
+    "\11\254\310%\25U\251\0\344\10\253\310\244\214V\22\345\10\253\310e\270\222\0\346\10\244\310\215\264\342\0"
+    "\347\10\253\307UZ%\0\350\10\253\310\344\224\246\0\351\7\253\310\246j\12\352\10\253\310\310\224\246\0\353"
+    "\7\253\310\244\326\24\354\7\253\310\344X\15\355\6\253\310\316j\356\7\253\310u\246\1\357\10\253\310\244,"
+    "\323\0\360\10\253\310\244rU\0\361\11\254\310%\225dj\1\362\10\253\310\344\230Z\0\363\10\253\310\246"
+    "\230Z\0\364\10\253\310e\230Z\0\365\7\253\310l\324\5\366\10\253\310\244\214\272\0\367\10\253\310e\264"
+    "Q\2\370\7\243\310-\265\0\371\10\253\310\344\224T\22\372\10\253\310\246J%\1\373\10\253\310e\224T"
+    "\22\374\10\253\310\244\234T\22\375\10\263\307\246j\304\5\376\11\263\307\304\250\322\212\0\377\11\263\307\244\234"
+    "F\134\0\0\0\0\4\377\377\0";
+/*
+  Fontname: -Misc-Fixed-Medium-R-Normal--8-80-75-75-C-50-ISO10646-1
+  Copyright: Public domain font.  Share and enjoy.
+  Glyphs: 191/1426
+  BBX Build Mode: 0
+*/
+static const uint8_t u8g2_font_5x8_tf[] =
+    "\277\0\2\2\3\4\3\4\4\5\10\0\377\6\377\6\0\1\32\2\61\6\226 \5\0~\3!\7\61c"
+    "\63R\0\42\7\233n\223\254\0#\15=bW\246\64T\65T\231\22\0$\12=b\233W\275S\332"
+    "\21%\10\253f\23Sg\0&\12<b\27S\263j\246\0'\5\31o\63(\7\262b\247\232\1)"
+    "\10\262b\23S\245\0*\12,b\23\223\32I\305\0+\12-b\233Q\34\62\243\10,\7\233^\247"
+    "J\0-\6\14j\63\2.\7\233^\227V\2/\10\64b_\266\63\0\60\10\263bW\271*\0\61"
+    "\7\263b\227dk\62\12\64b\247bN*\217\0\63\12\64b\63b\324H&\5\64\12\64b\33U"
+    "\65bN\0\65\12\64b\63\364F\62)\0\66\12\64b\247\362\212\62)\0\67\12\64b\63r\314\61"
+    "G\0\70\12\64b\247bRQ&\5\71\12\64b\247\242L;)\0:\7\252b\63\342\10;\10\263"
+    "^g#U\2<\7\263b\233\312\134=\10\34f\63\62\32\1>\10\263b\223\313T\2\77\11\263b"
+    "\327L\31&\0@\14E^+\243\134I%YC\5A\11\64b\247\242\34S\6B\12\64b\263\342"
+    "HQ\216\4C\11\64b\247\242.\223\2D\11\64b\263\242s$\0E\11\64b\63\364\312y\4F"
+    "\11\64b\63\364\312\65\0G\12\64b\247\242N\63)\0H\11\64b\23\345\230f\0I\7\263b\263"
+    "bkJ\11\64b\67sUF\0K\11\64b\23U\222\251\63L\10\64b\223\273G\0M\11\64b"
+    "\23\307\21\315\0N\11\64b\23\327Xg\0O\11\64b\247\242\63)\0P\12\64b\263\242\34)g"
+    "\0Q\11<^\247\242\134n\24R\12\64b\263\242\34)\312\0S\12\64b\247b\312\250L\12T\10"
+    "\263b\263b\27\0U\10\64b\23=\223\2V\11\64b\23\235I*\0W\11\64b\23\315q\304\0"
+    "X\12\64b\23e\222*\312\0Y\13\65b\223u\252\63\312(\2Z\11\64b\63rl\217\0[\7"
+    "\263b\63bs\134\12\64b\223\63\312(\243\34]\7\263b\63\233#^\6\223r\327\0_\6\14^"
+    "\63\2`\6\222r\23\3a\10$b\67\242L\3b\12\64b\223\363\212r$\0c\7\243b\67\263"
+    "\0d\11\64b_\215(\323\0e\10$b\247\322\310\12f\11\64b[\225\63G\0g\11,^\247"
+    "b\332I\1h\11\64b\223\363\212f\0i\10\263b\227\221\254\6j\11\273^\233a\251*\0k\11"
+    "\64b\223\313\221\242\14l\7\263b#\273\6m\11%b\243Z*\251\2n\7$b\263\242\31o\10"
+    "$b\247\242L\12p\11,^\263\342H\71\3q\10,^\67b\332\5r\10$b\223\222\235\1s"
+    "\7\243b\67\362\2t\12\64b\227\343\314)&\0u\7$b\23\315\64v\7\243b\223\254\12w\11"
+    "%b\223UR]\0x\10$b\23\223T\61y\12,^\23e\32\61)\0z\10$b\63b\71"
+    "\2{\13<b\253\62J\32\305\214\4|\5\61cs}\14<b\243Q\314He\224$\0~\7\24"
+    "r\227T\2\240\5\0~\3\241\7\61c\223F\0\242\11\64^\33Gj\316\4\243\12\64b[\215\230"
+    "\223J\0\244\12-b\223\323Lq\345\0\245\13\65b\223S\65d\34\62\2\246\6\71c\263\6\247\12"
+    "<b\67\362\212i\217\4\250\6\213v\223\2\251\12\65b\267\252\71U\265\0\252\7\253j\267\222\36\253"
+    "\10\34f\227TL\1\254\6\233b\63\13\255\5\213j\63\256\11\65b\367\241\226Z\0\257\5\213v\63"
+    "\260\6\233n\327\5\261\10\253b\227VF\3\262\7\253j\327Li\263\7\253j\243/\0\264\6\222r"
+    "\247\0\265\11,^\23\315\221\62\0\266\14\65b\67F\32)\251\230b\12\267\5\11k\23\270\6\222^"
+    "\247\0\271\7\253j\227d\65\272\7\253j\327\215\6\273\10\34f\223bR\11\274\12<b\223[Q\215"
+    "\230\0\275\12<b\223\253\244r\214\3\276\14<b\223Q\314HU#&\0\277\11\263b\227a\212\251"
+    "\2\300\12<b\227QTqL\31\301\11<b[\253\70\246\14\302\12<b\247bRqL\31\303\12"
+    "<b\227TTqL\31\304\12<b\23\63TqL\31\305\12<b\247bRqL\31\306\11\64b"
+    "\67Rk\250J\307\12<^\247\242.\223\214\0\310\12<b\227Q\32z\345\21\311\11<b[\16\275"
+    "\362\10\312\12<b\247\342\330+\217\0\313\12<b\23\63\32z\345\21\314\11\273b\223\323\212\325\0\315"
+    "\11\273b\233\322\212\325\0\316\11\273bW\215\24\253\1\317\11\273b\223\362\212\325\0\320\13\65b\67\343"
+    "He\212i\1\321\12<b\227T\271\324\224\1\322\12<b\227QT\321L\12\323\11<b[\253h"
+    "&\5\324\12<b\247bR\321L\12\325\12<b\227TT\321L\12\326\12<b\23\63T\321L\12"
+    "\327\6\233b\223:\330\11\64b\67\322\221\216\4\331\11<b\227Q\351L\12\332\10<b\333t&\5"
+    "\333\11<b\247\242gR\0\334\12<b\23\63\212\316\244\0\335\13=b_\346Tg\224Q\4\336\12"
+    "\64b\223W\224#e\0\337\11\64b\247\242\352T\11\340\12<b\227Q\306#\312\64\341\11<b["
+    "S#\312\64\342\12<b[e\70\242L\3\343\12<b\227T\306#\312\64\344\11\64bW\303\21e"
+    "\32\345\12<b\247b\222#\312\64\346\11%b\63\242\62G\0\347\10\253^\67\263J\0\350\13<b"
+    "\227Q\306*\215\254\0\351\12<b[S*\215\254\0\352\13<b\247b\206*\215\254\0\353\12\64b"
+    "WC\225FV\0\354\11\273b\223\63\222\325\0\355\11\273b\233\62\222\325\0\356\10\273b\327\226\325\0"
+    "\357\10\263b\223\262\254\6\360\14<b\223b\225Q\32\61)\0\361\12<b\227T\206+\232\1\362\13"
+    "<b\227Q\306*\312\244\0\363\12<b[S*\312\244\0\364\13<b\247b\206*\312\244\0\365\13"
+    "<b\227T\306*\312\244\0\366\12\64b\23\63TQ&\5\367\10\253b\227\321F\11\370\11$b\67"
+    "\322H#\1\371\12<b\227Q\206\321L\3\372\11<b[\343h\246\1\373\12<b\247bF\321L"
+    "\3\374\11\64b\23\63\212f\32\375\13D^[\343(\323\210I\1\376\12<^\223\363\212#\345\14\377"
+    "\14<^\23\63\212\62\215\230\24\0\0\0\0\4\377\377\0";
+/*
+  Fontname: -Misc-Fixed-Medium-R-Normal--10-100-75-75-C-60-ISO10646-1
+  Copyright: Public domain terminal emulator font.  Share and enjoy.
+  Glyphs: 191/1597
+  BBX Build Mode: 0
+*/
+static const uint8_t u8g2_font_6x10_tf[] =
+    "\277\0\2\2\3\4\3\5\4\6\12\0\376\7\376\7\0\1B\2\222\7\263 \5\0b\7!\7\71C"
+    "g\250\0\42\7\233R'Y\1#\15=B\257Li\250j\250\62%\0$\13=B\67\257z\247\264"
+    "#\0%\13=B/\252\356\252%\23\0&\14=B/\247\230r\225dT\1'\5\31Sg(\10"
+    "\273B\67\225u\1)\10\273B'\227U\11*\12-F'\247j\250v\0+\12-F\67\243\70d"
+    "F\21,\7\233>O\225\0-\6\15Ng\10.\7\233>/\255\4/\13=B\37e\224\273QF"
+    "\0\60\12=B\67\247\332Nu\4\61\14=B\67\313\224QF\31\305!\62\14=Bo\345\214\242\314"
+    "\31\15\1\63\14=Bgh\224\263\206:-\0\64\14=B\77\313T\246\241\63J\0\65\13=B\347"
+    "F\311\314H\247\5\66\13=BW\346\214\222\251\323\2\67\14=Bgh\224\63\312\65\312\0\70\13="
+    "Boe\235V\326i\1\71\14=Boe\251TF\71J\0:\12\273>/\255\14\323J\0;\11"
+    "\273>/\255\14U\11<\12\274B\77\266QF\31\5=\10\35Jgh\70\4>\13\274B'\243\214"
+    "\62\212m\0\77\12=Bo\345\66\312t\4@\13=Boe\271\222\225\341\2A\13=B\67\247Z"
+    "\217\221u\0B\14=Bg\304*\246Y\305\241\0C\14=Boe\215\62\312(\247\5D\15=B"
+    "g\304*\246\230b\212C\1E\14=B\347F\31\215\224QFCF\15=B\347F\31\215\224QF"
+    "\31\1G\14=Boe\215\62\212;-\0H\11=B'\333cd;I\10\273Bg\305\256\1J"
+    "\14=Bwg\224QFe\224\0K\13=B'\313T\352\24\253\34L\16=B'\243\214\62\312("
+    "\243\214\206\0M\12=B'\353\265\222\266\3N\12=B'\353\251\222\334:O\11=Boe\357\264"
+    "\0P\15=Bg\244\254\207\312(\243\214\0Q\12E>oe\257j\303\0R\13=Bg\244\254\207"
+    "*\253\34S\13=Boe\15\67\324i\1T\16=Bg\310\214\62\312(\243\214\42\0U\10=B"
+    "'\373N\13V\13=B'\333\251L\61\345\10W\12=B'\273\222Jw\0X\12=B'\353T"
+    "W\265\16Y\14=B'\353Tg\224QF\21Z\12=Bgh\224\273\321\20[\10\273Bg\304\316"
+    "\1\134\15=B'\243\14\63\314\60\303\214\2]\10\273Bgv\216\0^\7\35R\67\247:_\6\15"
+    ">g\10`\6\22['\6a\12-Bo\303\64t\32\1b\14=B'\243\214\222\251\247R\0c"
+    "\12-Boe\215rZ\0d\13=B\37e\224\314-\225\12e\12-Bo\345\61\62\134\0f\14"
+    "=BWVy\304\214\62\312\0g\14=:oh\235FF:-\0h\13=B'\243\214\222\251\355"
+    "\0i\10\273B/#\331\32j\13\314:\77c]K\231\24\0k\14=B'\243\214\262L\263\312\1"
+    "l\7\273BG\366\32m\12-BG\265TRI\7n\10-B'\231\332\16o\11-Boe;"
+    "-\0p\14=:'\231z*\225QF\0q\13=:\317\334R\251\214\62\12r\13-B'\231\32"
+    "e\224\21\0s\12-Boe\270\341P\0t\15=B/\243<bF\31\305\250\0u\10-B'"
+    ";\225\12v\12-B'\353T\246\34\1w\11-B'[Iu\1x\11-B'\247\272\252\3y"
+    "\13=:'\233Je\244\323\2z\10-Bg\350\366\20{\13\274BWe\224\64\212\31\11|\6\71"
+    "C\347\10}\14\274BG\243\230\221\312(I\0~\11\35R/\252$\23\0\240\5\0b\7\241\7\71"
+    "C'\15\1\242\14=>\67\17\25SLy\304\10\243\13=BWVyg\24\225\2\244\12-B'"
+    "\247\231\342\312\1\245\15E>'\353T\307!\63\312(\2\246\6\71Cg\15\247\13E>oe\64;"
+    "\67J\13\250\6\213^'\5\251\14=Boe\225\246J:-\0\252\12\264FoD\245j\64\2\253"
+    "\13.B\267\212)\346\230c\0\254\7\224Jg\344\0\255\6\214Ng\4\256\13=Bo\345\221\346\324"
+    "i\1\257\6\15^g\10\260\6\233R\257\13\261\13\65B\67\243\70dFq\10\262\10\254NO\305\346"
+    "\10\263\12\254Ng\243\244\321H\0\264\6\22[O\1\265\12\65>'\333S\251\214\0\266\16=Bo"
+    "\214\64RR\61\305\24S\0\267\5\11O'\270\6\22;O\1\271\7\253N/\311j\272\12\264FO"
+    "E\231\64\34\1\273\14.B'\346\230c\212)F\0\274\20N>/#\15\63\314hf\244S\34\31"
+    "\6\275\20N>/#\15\63\314heT\303\214\62\32\276\16M>G\303\234a\224Y\246\64\62\12\277"
+    "\12=B\67\323\31\345\326\2\300\14EB/\303\274\262\36#\353\0\301\13EB\277^Y\217\221u\0"
+    "\302\14EB\67\247\270\262\36#\353\0\303\14EB/*\271\262\36#\353\0\304\13EB\257\246V\326"
+    "cd\35\305\14EB\67\247\270\262\36#\353\0\306\13>Bw\244\262\71Fl\16\307\15M:oe"
+    "\215\62\312(\247]\3\310\16EB/\217\215\62\32)\243\214\206\0\311\16EB\77\215\215\62\32)\243"
+    "\214\206\0\312\16EB\67\216\215\62\32)\243\214\206\0\313\16EB\257\32\33e\64RF\31\15\1\314"
+    "\11\303B'\247\25[\3\315\11\303B\67\245\25[\3\316\11\303B\257\32)\266\6\317\11\303B'\345"
+    "\25[\3\320\15=Bg\304*\216T\246\70\24\0\321\13EB\67uO\225\344\326\1\322\13EB/"
+    "\303\274\262;-\0\323\12EB\277^\331\235\26\0\324\13EB\67\247\270\262;-\0\325\12EB\67"
+    "\65Wv\247\5\326\12EB\257\246Vv\247\5\327\11-B'\247\272\252\3\330\13=Bo\305+\315"
+    "\231\26\0\331\12EB/\303\332;-\0\332\11EB\277\314\336i\1\333\13EB\67\247\214\263;-"
+    "\0\334\12EB\257\306\331;-\0\335\14EB\277\314:\325\31e\24\1\336\16=B'\243\221\362P"
+    "\31e\224\21\0\337\13=Boe\231\312*+\5\340\14EB/\303Ln\230\206N#\341\13EB"
+    "\277&\67LC\247\21\342\14EB\67\247Lm\230\206N#\343\14EB\67\265\251\15\323\320i\4\344"
+    "\13=B\257\246\66LC\247\21\345\14EB\67\247\234\67LC\247\21\346\13.BodT\215\231\207"
+    "\0\347\13=:oe\215r\332\65\0\350\14EB/\303L\256<F\206\13\351\13EB\277&W\36"
+    "#\303\5\352\14EB\67\247L\255<F\206\13\353\13=B\257\246V\36#\303\5\354\11\303B'g"
+    "$[\3\355\10\303B\257\206\262\65\356\10\303B\257-[\3\357\10\273B'e\331\32\360\13=BG"
+    "C\271\262\235\26\0\361\12EB\67\265q\62\265\35\362\13EB/\303L\256l\247\5\363\12EB\277"
+    "&W\266\323\2\364\13EB\67\247L\255l\247\5\365\13EB\67\265\251\225\355\264\0\366\12=B\257"
+    "\246V\266\323\2\367\11-F\67SCS\21\370\12-Bo\310\225\346P\0\371\13EB/\303Le"
+    "\247R\1\372\12EB\277\246\262S\251\0\373\13EB\67\247\214\263S\251\0\374\12=B\257\306\331\251"
+    "T\0\375\14M:\277\314\246R\31\351\264\0\376\15E:'\243\221\262=TF\31\1\377\15M:\257"
+    "\306\331T*#\235\26\0\0\0\0\4\377\377\0";
+
+/*
+  Fontname: -Misc-Fixed-Medium-R-Normal--15-140-75-75-C-90-ISO10646-1
+  Copyright: Public domain font.  Share and enjoy.
+  Glyphs: 191/4777
+  BBX Build Mode: 0
+*/
+static const uint8_t u8g2_font_9x15_tf[] =
+    "\277\0\3\2\4\4\4\5\5\11\17\0\375\12\375\13\377\1\223\3*\12\21 \5\0\310\63!\10\261\14"
+    "\63\16\221\0\42\10\64{\63\42S\0#\16\206\31s\242\226a\211Z\206%j\1$\24\267\371\362\302"
+    "A\211\42)L\322\65\11#\251\62\210\31\0%\21\247\11sB%JJ\255q\32\265\224\22\61\1&"
+    "\22\247\11s\304(\213\262(T\65)\251E\225H\13'\6\61|\63\6(\14\303\373\262\222(\211z"
+    "\213\262\0)\14\303\373\62\262(\213z\211\222\10*\15w\71\363J\225\266-i\252e\0+\13w\31"
+    "\363\342\332\60dq\15,\11R\334\62\206$Q\0-\7\27I\63\16\1.\7\42\14\63\206\0/\14"
+    "\247\11\263\323\70-\247\345\64\6\60\15\247\11\263\266J\352k\222e\23\0\61\15\247\11\363R\61\311\242"
+    "\270\267a\10\62\14\247\11s\6%U\373y\30\2\63\16\247\11\63\16qZ\335\343XM\6\5\64\21"
+    "\247\11sS\61\311\242Z\22&\303\220\306\25\0\65\17\247\11\63\16reH\304\270\254&\203\2\66\20"
+    "\247\11\263\206(\215+C\42\252\326dP\0\67\16\247\11\63\16q\32\247q\32\247q\10\70\21\247\11"
+    "\263\266J\232d\331VI\325$\313&\0\71\17\247\11s\6%uT\206$\256FC\4:\10r\14"
+    "\63\206x\10;\12\242\334\62\206xH\22\5<\11\245\12\63\263\216i\7=\12G)\63\16\71>\14"
+    "\1>\12\245\12\63\322\216YG\0\77\16\247\11s\6%U\343\264\71\207\63\0@\21\247\11s\6%"
+    "\65\15J\246D\223\42\347\203\2A\15\247\11\363\322$\253\244\326\341j\15B\22\247\11\63\6)LR"
+    "\61\31\244\60I\215\311 \1C\15\247\11s\6%\225\373\232\14\12\0D\15\247\11\63\6)LR\77"
+    "&\203\4E\15\247\11\63\16ry\220\342\346a\10F\14\247\11\63\16ry\220\342\316\0G\17\247\11"
+    "s\6%\225\333\206\324\232\14\12\0H\12\247\11\63R\327\341\352\65I\12\245\12\63\6)\354\247AJ"
+    "\15\250\11\363\6\65\357S\230\15\31\0K\21\247\11\63R\61\311\242\332\230\204QV\12\223\64L\12\247"
+    "\11\63\342\376<\14\1M\20\247\11\63Ru[*JE\212\244H\265\6N\17\247\11\63RuT\62"
+    ")\322\22q\265\6O\14\247\11s\6%\365\327dP\0P\15\247\11\63.\251u\30\222\270\63\0Q"
+    "\16\307\351r\6%\365K&U\6\65\27R\20\247\11\63.\251u\30\222(+\205I\252\6S\16\247"
+    "\11s\6%\265\357V\65\31\24\0T\12\247\11\63\16Y\334\337\0U\13\247\11\63R\377\232\14\12\0"
+    "V\21\247\11\63Rk\222EY\224U\302$L\322\14W\20\247\11\63RO\221\24I\221\24)\335\22"
+    "\0X\20\247\11\63R\65\311*i\234&Y%U\3Y\15\247\11\63R\65\311*i\334\33\0Z\14"
+    "\247\11\63\16q\332\347x\30\2[\12\304\373\62\6\255\177\33\2\134\13\247\11\63\362\70/\347\345<]"
+    "\12\304\372\62\206\254\177\33\4^\12Gi\363\322$\253\244\1_\7\30\370\62\16\2`\7\63\213\63\262"
+    "\2a\16w\11s\6=N\206!\25\225!\11b\17\247\11\63\342\226!\21U\353\250\14\11\0c\14"
+    "w\11s\6%\225[\223A\1d\15\247\11\263[\206D\134\35\225!\11e\15w\11s\6%U\207"
+    "s>(\0f\16\247\11\363\266R\26\305\341 \306\215\0g\23\247\331r\206DL\302$\214\206(\37"
+    "\224TM\6\5h\14\247\11\63\342\226!\21U\257\1i\12\245\12stt\354i\20j\15\326\331\62"
+    "u\312\332U\64&C\2k\17\247\11\63\342VMI\64\65\321\62%\15l\11\245\12\63\306\376\64\10"
+    "m\20w\11\63\26%\212\244H\212\244H\212\324\0n\13w\11\63\222!\21U\257\1o\14w\11s"
+    "\6%\365\232\14\12\0p\17\247\331\62\222!\21U\353\250\14I\134\6q\15\247\331r\206D\134\35\225"
+    "!\211\33r\14w\11\63\242IK\302$n\5s\15w\11s\6%\325\7]M\6\5t\14\227\11"
+    "\263\342p\330\342n\331\2u\20w\11\63\302$L\302$L\302$\214\206$v\16w\11\63R\65\311"
+    "\242\254\22&i\6w\16w\11\63RS$ER\244tK\0x\15w\11\63\322$\253\244\225\254\222"
+    "\6y\15\246\331\62B\337\224%\25\223!\1z\12w\11\63\16i\257\303\20{\15\305\373\262\226\260\32"
+    "ij\26V\7|\6\301\374\62>}\16\305\371\62\326\260\226jR\32V&\0~\12\67ys\64)"
+    "\322\24\0\240\5\0\310\63\241\10\261\14\63\244a\10\242\21\206\11\63\243!\211\22\251\222%Q\62D!"
+    "\0\243\21\247\11\363\266R\34\16b\234\212I\226$\13\0\244\16g\71\63\322d\220\262(\213\6%\15"
+    "\245\20\247\11\63R\65\311*\331 \206\203\30\327\0\246\10\261\374\62\6e\20\247\16\264\372r\224HT"
+    "\42S\42J\211\2\250\7%\232\63\62-\251\25\230\30\263\206,L\42K\224(\241\22%\222\224\204\331"
+    "\20\1\252\14u\71s\244\322\22EC:\10\253\15\207\31\363\242~\213\302(\214\302(\254\7F)\63"
+    "\256\15\255\7\25J\63\6\1\256\25\230\30\263\206,L\222I\211\22eRJJ\224\24\263!\2\257\6"
+    "\26\231\63\16\260\12Dks\224HJ\24\0\261\16\227\31\363\342\332\60dq\35\33\206\0\262\13dI"
+    "s\224(K\224l\10\263\13dIs\224\250(%\12\0\264\10\63\213\263\222\22\0\265\14\227\351\62R"
+    "\257\333\262\310\61\0\266\26\247\11s\206!K\264DK\222!\11\223\60\11\223\60\11\223\0\267\7\42L"
+    "\63\206\0\270\10\64\332\262\246D\1\271\10cIs\22\251e\272\12eIs\226LK\346A\273\16\207"
+    "\31\63\242\60\12\243\60\312\242~\3\274\17\247\11sR\271q\210\304$\213\62%\25\275\16\247\11sR"
+    "\271I\31\242\70\24\343!\276\21\247\11s\304(\315\263\250\42\211I\26eJ*\277\15\247\11\363r\270"
+    "\332\234\252\311\240\0\300\16\307\11s\362:\272URu\270Z\3\301\15\307\11s\333\321\255\222\252\303\325"
+    "\32\302\17\307\11\363\322$\253c[%U\207\253\65\303\17\267\11s\64i\307\266J\252\16Wk\0\304"
+    "\17\267\11s\262(\313\261\255\222\252\303\325\32\305\17\267\11\263\266\332\230d\225T\35\256\326\0\306\25\247"
+    "\11s\224!\312\242,\312\242lX\242,\312\242,\32\2\307\20\327\331r\6%\225\373\232\14\242\26\205"
+    "\32\0\310\21\307\11s\362:\66\14I\34\17Y\134\35\206\0\311\20\307\11s\333\261aH\342x\310\342"
+    "\352\60\4\312\22\307\11\363\322$\253#\303\220\304\361\220\305\325a\10\313\22\267\11s\262(\313\221aH"
+    "\342x\310\342\352\60\4\314\14\305\12\63\322\372 \205=\15\2\315\14\305\12\63\263\372 \205=\15\2\316"
+    "\15\305\12\263\262\244\226\16R\330\323 \317\14\265\12\63\62-\35\244\260\247A\320\25\250\10s\6-\214"
+    "\322$\35\302$M\322$M\302h\220\0\321\22\267\11s\64iG\322Q\311\244H\212\264D\134\3\322"
+    "\16\307\11s\362:\70(\251\257\311\240\0\323\15\307\11s\333\301AI}M\6\5\324\20\307\11\363\322"
+    "$\253C\203\222\372\232\14\12\0\325\17\267\11s\64i\207\6%\365\65\31\24\0\326\17\267\11s\262("
+    "\313\241AI}M\6\5\327\15w\31\63\322$\253\244\225\254\222\6\330\26\307\371\262\223A\11\267DK"
+    "\244H\212\224L\311\306dPb\0\331\15\307\11s\362:\226\372\65\31\24\0\332\14\307\11s\333\261\324"
+    "\257\311\240\0\333\16\307\11\363\322$\253#\251_\223A\1\334\16\267\11s\262(\313\221\324\257\311\240\0"
+    "\335\16\307\11s\333\261TM\262J\32\267\1\336\16\247\11\63\342xXR\353\60$q\31\337\24\246\11"
+    "\263\246,\311\222(Q\262\250\226dI\226$\12\0\340\21\267\11\263\362:\66\350q\62\14\251\250\14I"
+    "\0\341\20\267\11s\333\301A\217\223aHEeH\2\342\22\267\11\363\322$\253C\203\36'\303\220\212"
+    "\312\220\4\343\22\247\11\263\244$\322\241A\217\223aHEeH\2\344\22\247\11s\262(\313\241A\217"
+    "\223aHEeH\2\345\22\267\11\363\304(\324\261A\217\223aHEeH\2\346\17w\11s,Q"
+    "-J\6%\312\242\212\62\347\17\247\331r\6%\225[\223A\324\242P\3\350\17\267\11s\362:\70("
+    "\251:\234\363A\1\351\17\267\11s\333\301AI\325\341\234\17\12\0\352\21\267\11\363\322$\253C\203\222"
+    "\252\303\71\37\24\0\353\21\247\11s\262(\313\241AI\325\341\234\17\12\0\354\12\265\12\63\322\372\330\323"
+    " \355\12\265\12\363\332\221\261\247A\356\15\266\11\263\302$\312rd\355m\20\357\14\245\12\63\242$\212"
+    "\307\236\6\1\360\20\267\11s\242PL\362lPR\257\311\240\0\361\16\247\11s\64iG\222!\21U"
+    "\257\1\362\16\267\11s\362:\70(\251\327dP\0\363\15\267\11s\333\301AI\275&\203\2\364\17\267"
+    "\11\363\322$\253C\203\222zM\6\5\365\17\247\11s\64i\207\6%\365\232\14\12\0\366\17\247\11s"
+    "\262(\313\241AI\275&\203\2\367\16\227\11\363\322\65\307\206!\307\322\65\3\370\23\227\371\262\223A\311"
+    "\22-\221\42%S\262dPb\0\371\23\267\11s\362:\26&a\22&a\22&a\64$\1\372\22"
+    "\267\11s\333\261\60\11\223\60\11\223\60\11\243!\11\373\24\267\11\363\322$\253#a\22&a\22&a"
+    "\22FC\22\374\24\247\11s\242,\312\241\60\11\223\60\11\223\60\11\243!\11\375\17\346\331\62\333\241\320"
+    "\67eI\305dH\0\376\20\307\331\62\342\226!\21UuT\206$.\3\377\17\326\331r\242\366\320\67"
+    "eI\305dH\0\0\0\0\4\377\377\0";

+ 13 - 0
font/font.h

@@ -0,0 +1,13 @@
+#pragma once
+#include <stdint.h>
+#include <gui/view.h>
+#include <gui/elements.h>
+typedef enum
+{
+    FONT_SIZE_SMALL = 1,
+    FONT_SIZE_MEDIUM = 2,
+    FONT_SIZE_LARGE = 3,
+    FONT_SIZE_XLARGE = 4
+} FontSize;
+extern bool canvas_set_font_custom(Canvas *canvas, FontSize font_size);
+extern void canvas_draw_str_multi(Canvas *canvas, uint8_t x, uint8_t y, const char *str);

+ 221 - 0
game.c

@@ -0,0 +1,221 @@
+#include "game.h"
+
+/****** Entities: Player ******/
+
+typedef struct
+{
+    Sprite *sprite;
+} PlayerContext;
+
+// Forward declaration of player_desc, because it's used in player_spawn function.
+static const EntityDescription player_desc;
+
+static void player_spawn(Level *level, GameManager *manager)
+{
+    Entity *player = level_add_entity(level, &player_desc);
+
+    // Set player position.
+    // Depends on your game logic, it can be done in start entity function, but also can be done here.
+    entity_pos_set(player, (Vector){64, 32});
+
+    // Add collision box to player entity
+    // Box is centered in player x and y, and it's size is 10x10
+    entity_collider_add_rect(player, 10, 10);
+
+    // Get player context
+    PlayerContext *player_context = entity_context_get(player);
+
+    // Load player sprite
+    player_context->sprite = game_manager_sprite_load(manager, "player.fxbm");
+}
+
+static void player_update(Entity *self, GameManager *manager, void *context)
+{
+    UNUSED(context);
+
+    // Get game input
+    InputState input = game_manager_input_get(manager);
+
+    // Get player position
+    Vector pos = entity_pos_get(self);
+
+    // Control player movement
+    if (input.held & GameKeyUp)
+        pos.y -= 2;
+    if (input.held & GameKeyDown)
+        pos.y += 2;
+    if (input.held & GameKeyLeft)
+        pos.x -= 2;
+    if (input.held & GameKeyRight)
+        pos.x += 2;
+
+    // Clamp player position to screen bounds, considering player sprite size (10x10)
+    pos.x = CLAMP(pos.x, 123, 5);
+    pos.y = CLAMP(pos.y, 59, 5);
+
+    // Set new player position
+    entity_pos_set(self, pos);
+
+    // Control game exit
+    if (input.pressed & GameKeyBack)
+    {
+        game_manager_game_stop(manager);
+    }
+}
+
+static void player_render(Entity *self, GameManager *manager, Canvas *canvas, void *context)
+{
+    // Get player context
+    PlayerContext *player = context;
+
+    // Get player position
+    Vector pos = entity_pos_get(self);
+
+    // Draw player sprite
+    // We subtract 5 from x and y, because collision box is 10x10, and we want to center sprite in it.
+    canvas_draw_sprite(canvas, player->sprite, pos.x - 5, pos.y - 5);
+
+    // Get game context
+    GameContext *game_context = game_manager_game_context_get(manager);
+
+    // Draw score
+    canvas_printf(canvas, 0, 7, "Score: %lu", game_context->score);
+}
+
+static const EntityDescription player_desc = {
+    .start = NULL,           // called when entity is added to the level
+    .stop = NULL,            // called when entity is removed from the level
+    .update = player_update, // called every frame
+    .render = player_render, // called every frame, after update
+    .collision = NULL,       // called when entity collides with another entity
+    .event = NULL,           // called when entity receives an event
+    .context_size =
+        sizeof(PlayerContext), // size of entity context, will be automatically allocated and freed
+};
+
+/****** Entities: Target ******/
+
+static Vector random_pos(void)
+{
+    return (Vector){rand() % 120 + 4, rand() % 58 + 4};
+}
+
+static void target_start(Entity *self, GameManager *manager, void *context)
+{
+    UNUSED(context);
+    UNUSED(manager);
+    // Set target position
+    entity_pos_set(self, random_pos());
+    // Add collision circle to target entity
+    // Circle is centered in target x and y, and it's radius is 3
+    entity_collider_add_circle(self, 3);
+}
+
+static void target_render(Entity *self, GameManager *manager, Canvas *canvas, void *context)
+{
+    UNUSED(context);
+    UNUSED(manager);
+
+    // Get target position
+    Vector pos = entity_pos_get(self);
+
+    // Draw target
+    canvas_draw_disc(canvas, pos.x, pos.y, 3);
+
+    // Draw background
+    canvas_draw_box(canvas, 0, 20, 40, 20);
+}
+
+static void target_collision(Entity *self, Entity *other, GameManager *manager, void *context)
+{
+    UNUSED(context);
+    // Check if target collided with player
+    if (entity_description_get(other) == &player_desc)
+    {
+        // Increase score
+        GameContext *game_context = game_manager_game_context_get(manager);
+        game_context->score++;
+
+        // Move target to new random position
+        entity_pos_set(self, random_pos());
+    }
+}
+
+static const EntityDescription target_desc = {
+    .start = target_start,         // called when entity is added to the level
+    .stop = NULL,                  // called when entity is removed from the level
+    .update = NULL,                // called every frame
+    .render = target_render,       // called every frame, after update
+    .collision = target_collision, // called when entity collides with another entity
+    .event = NULL,                 // called when entity receives an event
+    .context_size = 0,             // size of entity context, will be automatically allocated and freed
+};
+
+/****** Level ******/
+
+static void level_alloc(Level *level, GameManager *manager, void *context)
+{
+    UNUSED(manager);
+    UNUSED(context);
+
+    // Add player entity to the level
+    player_spawn(level, manager);
+
+    // Add first target entity to the level
+    level_add_entity(level, &target_desc);
+
+    // Add second target entity to the level
+    level_add_entity(level, &target_desc);
+}
+
+static const LevelBehaviour level = {
+    .alloc = level_alloc, // called once, when level allocated
+    .free = NULL,         // called once, when level freed
+    .start = NULL,        // called when level is changed to this level
+    .stop = NULL,         // called when level is changed from this level
+    .context_size = 0,    // size of level context, will be automatically allocated and freed
+};
+
+/****** Game ******/
+
+/*
+    Write here the start code for your game, for example: creating a level and so on.
+    Game context is allocated (game.context_size) and passed to this function, you can use it to store your game data.
+*/
+static void game_start(GameManager *game_manager, void *ctx)
+{
+    UNUSED(game_manager);
+
+    // Do some initialization here, for example you can load score from storage.
+    // For simplicity, we will just set it to 0.
+    GameContext *game_context = ctx;
+    game_context->score = 0;
+
+    // Add level to the game
+    game_manager_add_level(game_manager, &level);
+}
+
+/*
+    Write here the stop code for your game, for example, freeing memory, if it was allocated.
+    You don't need to free level, sprites or entities, it will be done automatically.
+    Also, you don't need to free game_context, it will be done automatically, after this function.
+*/
+static void game_stop(void *ctx)
+{
+    GameContext *game_context = ctx;
+    // Do some deinitialization here, for example you can save score to storage.
+    // For simplicity, we will just print it.
+    FURI_LOG_I("Game", "Your score: %lu", game_context->score);
+}
+
+/*
+    Your game configuration, do not rename this variable, but you can change its content here.
+*/
+const Game game = {
+    .target_fps = 30,                    // target fps, game will try to keep this value
+    .show_fps = false,                   // show fps counter on the screen
+    .always_backlight = true,            // keep display backlight always on
+    .start = game_start,                 // will be called once, when game starts
+    .stop = game_stop,                   // will be called once, when game stops
+    .context_size = sizeof(GameContext), // size of game context
+};

+ 8 - 0
game.h

@@ -0,0 +1,8 @@
+#pragma once
+#include "engine/engine.h"
+
+/* Global game defines go here */
+
+typedef struct {
+    uint32_t score;
+} GameContext;

+ 747 - 0
jsmn/jsmn.c

@@ -0,0 +1,747 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2010 Serge Zaitsev
+ *
+ * [License text continues...]
+ */
+
+#include <jsmn/jsmn.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * Allocates a fresh unused token from the token pool.
+ */
+static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
+                                   const size_t num_tokens)
+{
+    jsmntok_t *tok;
+
+    if (parser->toknext >= num_tokens)
+    {
+        return NULL;
+    }
+    tok = &tokens[parser->toknext++];
+    tok->start = tok->end = -1;
+    tok->size = 0;
+#ifdef JSMN_PARENT_LINKS
+    tok->parent = -1;
+#endif
+    return tok;
+}
+
+/**
+ * Fills token type and boundaries.
+ */
+static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
+                            const int start, const int end)
+{
+    token->type = type;
+    token->start = start;
+    token->end = end;
+    token->size = 0;
+}
+
+/**
+ * Fills next available token with JSON primitive.
+ */
+static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
+                                const size_t len, jsmntok_t *tokens,
+                                const size_t num_tokens)
+{
+    jsmntok_t *token;
+    int start;
+
+    start = parser->pos;
+
+    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
+    {
+        switch (js[parser->pos])
+        {
+#ifndef JSMN_STRICT
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
+#endif
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if (js[parser->pos] < 32 || js[parser->pos] >= 127)
+        {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
+    }
+#ifdef JSMN_STRICT
+    /* In strict mode primitive must be followed by a comma/object/array */
+    parser->pos = start;
+    return JSMN_ERROR_PART;
+#endif
+
+found:
+    if (tokens == NULL)
+    {
+        parser->pos--;
+        return 0;
+    }
+    token = jsmn_alloc_token(parser, tokens, num_tokens);
+    if (token == NULL)
+    {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
+    }
+    jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
+#ifdef JSMN_PARENT_LINKS
+    token->parent = parser->toksuper;
+#endif
+    parser->pos--;
+    return 0;
+}
+
+/**
+ * Fills next token with JSON string.
+ */
+static int jsmn_parse_string(jsmn_parser *parser, const char *js,
+                             const size_t len, jsmntok_t *tokens,
+                             const size_t num_tokens)
+{
+    jsmntok_t *token;
+
+    int start = parser->pos;
+
+    /* Skip starting quote */
+    parser->pos++;
+
+    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
+    {
+        char c = js[parser->pos];
+
+        /* Quote: end of string */
+        if (c == '\"')
+        {
+            if (tokens == NULL)
+            {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if (token == NULL)
+            {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+#ifdef JSMN_PARENT_LINKS
+            token->parent = parser->toksuper;
+#endif
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if (c == '\\' && parser->pos + 1 < len)
+        {
+            int i;
+            parser->pos++;
+            switch (js[parser->pos])
+            {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++)
+                {
+                    /* If it isn't a hex character we have an error */
+                    if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                          (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                          (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
+                    { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
+        }
+    }
+    parser->pos = start;
+    return JSMN_ERROR_PART;
+}
+
+/**
+ * Create JSON parser over an array of tokens
+ */
+void jsmn_init(jsmn_parser *parser)
+{
+    parser->pos = 0;
+    parser->toknext = 0;
+    parser->toksuper = -1;
+}
+
+/**
+ * Parse JSON string and fill tokens.
+ */
+int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
+               jsmntok_t *tokens, const unsigned int num_tokens)
+{
+    int r;
+    int i;
+    jsmntok_t *token;
+    int count = parser->toknext;
+
+    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
+    {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch (c)
+        {
+        case '{':
+        case '[':
+            count++;
+            if (tokens == NULL)
+            {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if (token == NULL)
+            {
+                return JSMN_ERROR_NOMEM;
+            }
+            if (parser->toksuper != -1)
+            {
+                jsmntok_t *t = &tokens[parser->toksuper];
+#ifdef JSMN_STRICT
+                /* In strict mode an object or array can't become a key */
+                if (t->type == JSMN_OBJECT)
+                {
+                    return JSMN_ERROR_INVAL;
+                }
+#endif
+                t->size++;
+#ifdef JSMN_PARENT_LINKS
+                token->parent = parser->toksuper;
+#endif
+            }
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case '}':
+        case ']':
+            if (tokens == NULL)
+            {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if (parser->toknext < 1)
+            {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for (;;)
+            {
+                if (token->start != -1 && token->end == -1)
+                {
+                    if (token->type != type)
+                    {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if (token->parent == -1)
+                {
+                    if (token->type != type || parser->toksuper == -1)
+                    {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
+            }
+#else
+            for (i = parser->toknext - 1; i >= 0; i--)
+            {
+                token = &tokens[i];
+                if (token->start != -1 && token->end == -1)
+                {
+                    if (token->type != type)
+                    {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
+            }
+            /* Error if unmatched closing bracket */
+            if (i == -1)
+            {
+                return JSMN_ERROR_INVAL;
+            }
+            for (; i >= 0; i--)
+            {
+                token = &tokens[i];
+                if (token->start != -1 && token->end == -1)
+                {
+                    parser->toksuper = i;
+                    break;
+                }
+            }
+#endif
+            break;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if (r < 0)
+            {
+                return r;
+            }
+            count++;
+            if (parser->toksuper != -1 && tokens != NULL)
+            {
+                tokens[parser->toksuper].size++;
+            }
+            break;
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if (tokens != NULL && parser->toksuper != -1 &&
+                tokens[parser->toksuper].type != JSMN_ARRAY &&
+                tokens[parser->toksuper].type != JSMN_OBJECT)
+            {
+#ifdef JSMN_PARENT_LINKS
+                parser->toksuper = tokens[parser->toksuper].parent;
+#else
+                for (i = parser->toknext - 1; i >= 0; i--)
+                {
+                    if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
+                    {
+                        if (tokens[i].start != -1 && tokens[i].end == -1)
+                        {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
+#endif
+            }
+            break;
+#ifdef JSMN_STRICT
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if (tokens != NULL && parser->toksuper != -1)
+            {
+                const jsmntok_t *t = &tokens[parser->toksuper];
+                if (t->type == JSMN_OBJECT ||
+                    (t->type == JSMN_STRING && t->size != 0))
+                {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
+#else
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
+#endif
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if (r < 0)
+            {
+                return r;
+            }
+            count++;
+            if (parser->toksuper != -1 && tokens != NULL)
+            {
+                tokens[parser->toksuper].size++;
+            }
+            break;
+
+#ifdef JSMN_STRICT
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
+#endif
+        }
+    }
+
+    if (tokens != NULL)
+    {
+        for (i = parser->toknext - 1; i >= 0; i--)
+        {
+            /* Unmatched opened object or array */
+            if (tokens[i].start != -1 && tokens[i].end == -1)
+            {
+                return JSMN_ERROR_PART;
+            }
+        }
+    }
+
+    return count;
+}
+
+// Helper function to create a JSON object
+char *jsmn(const char *key, const char *value)
+{
+    int length = strlen(key) + strlen(value) + 8;         // Calculate required length
+    char *result = (char *)malloc(length * sizeof(char)); // Allocate memory
+    if (result == NULL)
+    {
+        return NULL; // Handle memory allocation failure
+    }
+    snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
+    return result; // Caller is responsible for freeing this memory
+}
+
+// Helper function to compare JSON keys
+int jsoneq(const char *json, jsmntok_t *tok, const char *s)
+{
+    if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+        strncmp(json + tok->start, s, tok->end - tok->start) == 0)
+    {
+        return 0;
+    }
+    return -1;
+}
+
+// Return the value of the key in the JSON data
+char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
+{
+    // Parse the JSON feed
+    if (json_data != NULL)
+    {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if (tokens == NULL)
+        {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
+
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if (ret < 0)
+        {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
+
+        // Ensure that the root element is an object
+        if (ret < 1 || tokens[0].type != JSMN_OBJECT)
+        {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
+
+        // Loop through the tokens to find the key
+        for (int i = 1; i < ret; i++)
+        {
+            if (jsoneq(json_data, &tokens[i], key) == 0)
+            {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char *value = malloc(length + 1);
+                if (value == NULL)
+                {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
+        }
+
+        // Free the token array if key was not found
+        free(tokens);
+    }
+    else
+    {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
+    }
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
+}
+
+// Revised get_json_array_value function
+char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
+{
+    // Retrieve the array string for the given key
+    char *array_str = get_json_value(key, json_data, max_tokens);
+    if (array_str == NULL)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
+
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
+
+    // Allocate memory for JSON tokens
+    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if (tokens == NULL)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
+    }
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if (ret < 0)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    // Ensure the root element is an array
+    if (ret < 1 || tokens[0].type != JSMN_ARRAY)
+    {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    // Check if the index is within bounds
+    if (index >= (uint32_t)tokens[0].size)
+    {
+        FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for (uint32_t i = 0; i < index; i++)
+    {
+        if (tokens[current_token].type == JSMN_OBJECT)
+        {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        }
+        else if (tokens[current_token].type == JSMN_ARRAY)
+        {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        }
+        else
+        {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
+
+        // Safety check to prevent out-of-bounds
+        if (current_token >= ret)
+        {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
+
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char *value = malloc(length + 1);
+    if (value == NULL)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
+
+    // Clean up
+    free(tokens);
+    free(array_str);
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
+{
+    // Retrieve the array string for the given key
+    char *array_str = get_json_value(key, json_data, max_tokens);
+    if (array_str == NULL)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
+
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
+
+    // Allocate memory for JSON tokens
+    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if (tokens == NULL)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
+    }
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if (ret < 0)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    // Ensure the root element is an array
+    if (tokens[0].type != JSMN_ARRAY)
+    {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char **values = malloc(array_size * sizeof(char *));
+    if (values == NULL)
+    {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for (int i = 0; i < array_size; i++)
+    {
+        if (current_token >= ret)
+        {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
+
+        if (element.type != JSMN_OBJECT)
+        {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
+
+        int length = element.end - element.start;
+
+        // Allocate a new string for the value and copy the data
+        char *value = malloc(length + 1);
+        if (value == NULL)
+        {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for (int j = 0; j < actual_num_values; j++)
+            {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
+    }
+
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if (actual_num_values < array_size)
+    {
+        char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
+        if (reduced_values != NULL)
+        {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for (int i = actual_num_values; i < array_size; i++)
+        {
+            free(values[i]);
+        }
+    }
+
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
+}

+ 132 - 0
jsmn/jsmn.h

@@ -0,0 +1,132 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2010 Serge Zaitsev
+ *
+ * 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:
+ *
+ * [License text continues...]
+ */
+
+#ifndef JSMN_H
+#define JSMN_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef JSMN_STATIC
+#define JSMN_API static
+#else
+#define JSMN_API extern
+#endif
+
+    /**
+     * JSON type identifier. Basic types are:
+     * 	o Object
+     * 	o Array
+     * 	o String
+     * 	o Other primitive: number, boolean (true/false) or null
+     */
+    typedef enum
+    {
+        JSMN_UNDEFINED = 0,
+        JSMN_OBJECT = 1 << 0,
+        JSMN_ARRAY = 1 << 1,
+        JSMN_STRING = 1 << 2,
+        JSMN_PRIMITIVE = 1 << 3
+    } jsmntype_t;
+
+    enum jsmnerr
+    {
+        /* Not enough tokens were provided */
+        JSMN_ERROR_NOMEM = -1,
+        /* Invalid character inside JSON string */
+        JSMN_ERROR_INVAL = -2,
+        /* The string is not a full JSON packet, more bytes expected */
+        JSMN_ERROR_PART = -3
+    };
+
+    /**
+     * JSON token description.
+     * type		type (object, array, string etc.)
+     * start	start position in JSON data string
+     * end		end position in JSON data string
+     */
+    typedef struct
+    {
+        jsmntype_t type;
+        int start;
+        int end;
+        int size;
+#ifdef JSMN_PARENT_LINKS
+        int parent;
+#endif
+    } jsmntok_t;
+
+    /**
+     * JSON parser. Contains an array of token blocks available. Also stores
+     * the string being parsed now and current position in that string.
+     */
+    typedef struct
+    {
+        unsigned int pos;     /* offset in the JSON string */
+        unsigned int toknext; /* next token to allocate */
+        int toksuper;         /* superior token node, e.g. parent object or array */
+    } jsmn_parser;
+
+    /**
+     * Create JSON parser over an array of tokens
+     */
+    JSMN_API void jsmn_init(jsmn_parser *parser);
+
+    /**
+     * Run JSON parser. It parses a JSON data string into and array of tokens, each
+     * describing a single JSON object.
+     */
+    JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
+                            jsmntok_t *tokens, const unsigned int num_tokens);
+
+#ifndef JSMN_HEADER
+/* Implementation has been moved to jsmn.c */
+#endif /* JSMN_HEADER */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSMN_H */
+
+/* Custom Helper Functions */
+#ifndef JB_JSMN_EDIT
+#define JB_JSMN_EDIT
+/* Added in by JBlanked on 2024-10-16 for use in Flipper Zero SDK*/
+
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <furi.h>
+
+// Helper function to create a JSON object
+char *jsmn(const char *key, const char *value);
+// Helper function to compare JSON keys
+int jsoneq(const char *json, jsmntok_t *tok, const char *s);
+
+// Return the value of the key in the JSON data
+char *get_json_value(char *key, char *json_data, uint32_t max_tokens);
+
+// Revised get_json_array_value function
+char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens);
+
+// Revised get_json_array_values function with correct token skipping
+char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values);
+#endif /* JB_JSMN_EDIT */

+ 0 - 0
sprites/.gitkeep


BIN
sprites/player.png


+ 784 - 0
text_input/uart_text_input.c

@@ -0,0 +1,784 @@
+// from https://github.com/xMasterX/all-the-plugins/blob/dev/base_pack/uart_terminal/uart_text_input.c
+// all credits to xMasterX for the code
+#include "uart_text_input.h"
+#include <gui/elements.h>
+#include "flip_world_icons.h"
+#include <furi.h>
+
+struct UART_TextInput
+{
+    View *view;
+    FuriTimer *timer;
+};
+
+typedef struct
+{
+    const char text;
+    const uint8_t x;
+    const uint8_t y;
+} UART_TextInputKey;
+
+typedef struct
+{
+    const char *header;
+    char *text_buffer;
+    size_t text_buffer_size;
+    bool clear_default_text;
+
+    UART_TextInputCallback callback;
+    void *callback_context;
+
+    uint8_t selected_row;
+    uint8_t selected_column;
+
+    UART_TextInputValidatorCallback validator_callback;
+    void *validator_callback_context;
+    FuriString *validator_text;
+    bool valadator_message_visible;
+} UART_TextInputModel;
+
+static const uint8_t keyboard_origin_x = 1;
+static const uint8_t keyboard_origin_y = 29;
+static const uint8_t keyboard_row_count = 4;
+
+#define mode_AT "Send AT command to UART"
+
+#define ENTER_KEY '\r'
+#define BACKSPACE_KEY '\b'
+
+static const UART_TextInputKey keyboard_keys_row_1[] = {
+    {'{', 1, 0},
+    {'(', 9, 0},
+    {'[', 17, 0},
+    {'|', 25, 0},
+    {'@', 33, 0},
+    {'&', 41, 0},
+    {'#', 49, 0},
+    {';', 57, 0},
+    {'^', 65, 0},
+    {'*', 73, 0},
+    {'`', 81, 0},
+    {'"', 89, 0},
+    {'~', 97, 0},
+    {'\'', 105, 0},
+    {'.', 113, 0},
+    {'/', 120, 0},
+};
+
+static const UART_TextInputKey keyboard_keys_row_2[] = {
+    {'q', 1, 10},
+    {'w', 9, 10},
+    {'e', 17, 10},
+    {'r', 25, 10},
+    {'t', 33, 10},
+    {'y', 41, 10},
+    {'u', 49, 10},
+    {'i', 57, 10},
+    {'o', 65, 10},
+    {'p', 73, 10},
+    {'0', 81, 10},
+    {'1', 89, 10},
+    {'2', 97, 10},
+    {'3', 105, 10},
+    {'=', 113, 10},
+    {'-', 120, 10},
+};
+
+static const UART_TextInputKey keyboard_keys_row_3[] = {
+    {'a', 1, 21},
+    {'s', 9, 21},
+    {'d', 18, 21},
+    {'f', 25, 21},
+    {'g', 33, 21},
+    {'h', 41, 21},
+    {'j', 49, 21},
+    {'k', 57, 21},
+    {'l', 65, 21},
+    {BACKSPACE_KEY, 72, 13},
+    {'4', 89, 21},
+    {'5', 97, 21},
+    {'6', 105, 21},
+    {'$', 113, 21},
+    {'%', 120, 21},
+
+};
+
+static const UART_TextInputKey keyboard_keys_row_4[] = {
+    {'z', 1, 33},
+    {'x', 9, 33},
+    {'c', 18, 33},
+    {'v', 25, 33},
+    {'b', 33, 33},
+    {'n', 41, 33},
+    {'m', 49, 33},
+    {'_', 57, 33},
+    {ENTER_KEY, 64, 24},
+    {'7', 89, 33},
+    {'8', 97, 33},
+    {'9', 105, 33},
+    {'!', 113, 33},
+    {'+', 120, 33},
+};
+
+static uint8_t get_row_size(uint8_t row_index)
+{
+    uint8_t row_size = 0;
+
+    switch (row_index + 1)
+    {
+    case 1:
+        row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
+        break;
+    case 2:
+        row_size = sizeof(keyboard_keys_row_2) / sizeof(UART_TextInputKey);
+        break;
+    case 3:
+        row_size = sizeof(keyboard_keys_row_3) / sizeof(UART_TextInputKey);
+        break;
+    case 4:
+        row_size = sizeof(keyboard_keys_row_4) / sizeof(UART_TextInputKey);
+        break;
+    }
+
+    return row_size;
+}
+
+static const UART_TextInputKey *get_row(uint8_t row_index)
+{
+    const UART_TextInputKey *row = NULL;
+
+    switch (row_index + 1)
+    {
+    case 1:
+        row = keyboard_keys_row_1;
+        break;
+    case 2:
+        row = keyboard_keys_row_2;
+        break;
+    case 3:
+        row = keyboard_keys_row_3;
+        break;
+    case 4:
+        row = keyboard_keys_row_4;
+        break;
+    }
+
+    return row;
+}
+
+static char get_selected_char(UART_TextInputModel *model)
+{
+    return get_row(model->selected_row)[model->selected_column].text;
+}
+
+static bool char_is_lowercase(char letter)
+{
+    return (letter >= 0x61 && letter <= 0x7A);
+}
+
+static bool char_is_uppercase(char letter)
+{
+    return (letter >= 0x41 && letter <= 0x5A);
+}
+
+static char char_to_lowercase(const char letter)
+{
+    switch (letter)
+    {
+    case ' ':
+        return 0x5f;
+        break;
+    case ')':
+        return 0x28;
+        break;
+    case '}':
+        return 0x7b;
+        break;
+    case ']':
+        return 0x5b;
+        break;
+    case '\\':
+        return 0x2f;
+        break;
+    case ':':
+        return 0x3b;
+        break;
+    case ',':
+        return 0x2e;
+        break;
+    case '?':
+        return 0x21;
+        break;
+    case '>':
+        return 0x3c;
+        break;
+    }
+    if (char_is_uppercase(letter))
+    {
+        return (letter + 0x20);
+    }
+    else
+    {
+        return letter;
+    }
+}
+
+static char char_to_uppercase(const char letter)
+{
+    switch (letter)
+    {
+    case '_':
+        return 0x20;
+        break;
+    case '(':
+        return 0x29;
+        break;
+    case '{':
+        return 0x7d;
+        break;
+    case '[':
+        return 0x5d;
+        break;
+    case '/':
+        return 0x5c;
+        break;
+    case ';':
+        return 0x3a;
+        break;
+    case '.':
+        return 0x2c;
+        break;
+    case '!':
+        return 0x3f;
+        break;
+    case '<':
+        return 0x3e;
+        break;
+    }
+    if (char_is_lowercase(letter))
+    {
+        return (letter - 0x20);
+    }
+    else
+    {
+        return letter;
+    }
+}
+
+static void uart_text_input_backspace_cb(UART_TextInputModel *model)
+{
+    uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
+    if (text_length > 0)
+    {
+        model->text_buffer[text_length - 1] = 0;
+    }
+}
+
+static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
+{
+    UART_TextInputModel *model = _model;
+    // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
+    uint8_t needed_string_width = canvas_width(canvas) - 8;
+    uint8_t start_pos = 4;
+
+    const char *text = model->text_buffer;
+
+    canvas_clear(canvas);
+    canvas_set_color(canvas, ColorBlack);
+
+    canvas_draw_str(canvas, 2, 7, model->header);
+    elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
+
+    if (canvas_string_width(canvas, text) > needed_string_width)
+    {
+        canvas_draw_str(canvas, start_pos, 17, "...");
+        start_pos += 6;
+        needed_string_width -= 8;
+    }
+
+    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
+    {
+        text++;
+    }
+
+    if (model->clear_default_text)
+    {
+        elements_slightly_rounded_box(
+            canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
+        canvas_set_color(canvas, ColorWhite);
+    }
+    else
+    {
+        canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
+        canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
+    }
+    canvas_draw_str(canvas, start_pos, 17, text);
+
+    canvas_set_font(canvas, FontKeyboard);
+
+    for (uint8_t row = 0; row <= keyboard_row_count; row++)
+    {
+        const uint8_t column_count = get_row_size(row);
+        const UART_TextInputKey *keys = get_row(row);
+
+        for (size_t column = 0; column < column_count; column++)
+        {
+            if (keys[column].text == ENTER_KEY)
+            {
+                canvas_set_color(canvas, ColorBlack);
+                if (model->selected_row == row && model->selected_column == column)
+                {
+                    canvas_draw_icon(
+                        canvas,
+                        keyboard_origin_x + keys[column].x,
+                        keyboard_origin_y + keys[column].y,
+                        &I_KeySaveSelected_24x11);
+                }
+                else
+                {
+                    canvas_draw_icon(
+                        canvas,
+                        keyboard_origin_x + keys[column].x,
+                        keyboard_origin_y + keys[column].y,
+                        &I_KeySave_24x11);
+                }
+            }
+            else if (keys[column].text == BACKSPACE_KEY)
+            {
+                canvas_set_color(canvas, ColorBlack);
+                if (model->selected_row == row && model->selected_column == column)
+                {
+                    canvas_draw_icon(
+                        canvas,
+                        keyboard_origin_x + keys[column].x,
+                        keyboard_origin_y + keys[column].y,
+                        &I_KeyBackspaceSelected_16x9);
+                }
+                else
+                {
+                    canvas_draw_icon(
+                        canvas,
+                        keyboard_origin_x + keys[column].x,
+                        keyboard_origin_y + keys[column].y,
+                        &I_KeyBackspace_16x9);
+                }
+            }
+            else
+            {
+                if (model->selected_row == row && model->selected_column == column)
+                {
+                    canvas_set_color(canvas, ColorBlack);
+                    canvas_draw_box(
+                        canvas,
+                        keyboard_origin_x + keys[column].x - 1,
+                        keyboard_origin_y + keys[column].y - 8,
+                        7,
+                        10);
+                    canvas_set_color(canvas, ColorWhite);
+                }
+                else
+                {
+                    canvas_set_color(canvas, ColorBlack);
+                }
+                if (0 == strcmp(model->header, mode_AT))
+                {
+                    canvas_draw_glyph(
+                        canvas,
+                        keyboard_origin_x + keys[column].x,
+                        keyboard_origin_y + keys[column].y,
+                        char_to_uppercase(keys[column].text));
+                }
+                else
+                {
+                    canvas_draw_glyph(
+                        canvas,
+                        keyboard_origin_x + keys[column].x,
+                        keyboard_origin_y + keys[column].y,
+                        keys[column].text);
+                }
+            }
+        }
+    }
+    if (model->valadator_message_visible)
+    {
+        canvas_set_font(canvas, FontSecondary);
+        canvas_set_color(canvas, ColorWhite);
+        canvas_draw_box(canvas, 8, 10, 110, 48);
+        canvas_set_color(canvas, ColorBlack);
+        canvas_draw_icon(canvas, 10, 14, &I_WarningDolphin_45x42);
+        canvas_draw_rframe(canvas, 8, 8, 112, 50, 3);
+        canvas_draw_rframe(canvas, 9, 9, 110, 48, 2);
+        elements_multiline_text(canvas, 62, 20, furi_string_get_cstr(model->validator_text));
+        canvas_set_font(canvas, FontKeyboard);
+    }
+}
+
+static void
+uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
+{
+    UNUSED(uart_text_input);
+    if (model->selected_row > 0)
+    {
+        model->selected_row--;
+        if (model->selected_column > get_row_size(model->selected_row) - 6)
+        {
+            model->selected_column = model->selected_column + 1;
+        }
+    }
+}
+
+static void
+uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
+{
+    UNUSED(uart_text_input);
+    if (model->selected_row < keyboard_row_count - 1)
+    {
+        model->selected_row++;
+        if (model->selected_column > get_row_size(model->selected_row) - 4)
+        {
+            model->selected_column = model->selected_column - 1;
+        }
+    }
+}
+
+static void
+uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
+{
+    UNUSED(uart_text_input);
+    if (model->selected_column > 0)
+    {
+        model->selected_column--;
+    }
+    else
+    {
+        model->selected_column = get_row_size(model->selected_row) - 1;
+    }
+}
+
+static void
+uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
+{
+    UNUSED(uart_text_input);
+    if (model->selected_column < get_row_size(model->selected_row) - 1)
+    {
+        model->selected_column++;
+    }
+    else
+    {
+        model->selected_column = 0;
+    }
+}
+
+static void uart_text_input_handle_ok(
+    UART_TextInput *uart_text_input,
+    UART_TextInputModel *model,
+    bool shift)
+{
+    char selected = get_selected_char(model);
+    uint8_t text_length = strlen(model->text_buffer);
+
+    if (0 == strcmp(model->header, mode_AT))
+    {
+        selected = char_to_uppercase(selected);
+    }
+
+    if (shift)
+    {
+        if (0 == strcmp(model->header, mode_AT))
+        {
+            selected = char_to_lowercase(selected);
+        }
+        else
+        {
+            selected = char_to_uppercase(selected);
+        }
+    }
+
+    if (selected == ENTER_KEY)
+    {
+        if (model->validator_callback &&
+            (!model->validator_callback(
+                model->text_buffer, model->validator_text, model->validator_callback_context)))
+        {
+            model->valadator_message_visible = true;
+            furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
+        }
+        else if (model->callback != 0 && text_length > 0)
+        {
+            model->callback(model->callback_context);
+        }
+    }
+    else if (selected == BACKSPACE_KEY)
+    {
+        uart_text_input_backspace_cb(model);
+    }
+    else
+    {
+        if (model->clear_default_text)
+        {
+            text_length = 0;
+        }
+        if (text_length < (model->text_buffer_size - 1))
+        {
+            model->text_buffer[text_length] = selected;
+            model->text_buffer[text_length + 1] = 0;
+        }
+    }
+    model->clear_default_text = false;
+}
+
+static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
+{
+    UART_TextInput *uart_text_input = context;
+    furi_assert(uart_text_input);
+
+    bool consumed = false;
+
+    // Acquire model
+    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+
+    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+        model->valadator_message_visible)
+    {
+        model->valadator_message_visible = false;
+        consumed = true;
+    }
+    else if (event->type == InputTypeShort)
+    {
+        consumed = true;
+        switch (event->key)
+        {
+        case InputKeyUp:
+            uart_text_input_handle_up(uart_text_input, model);
+            break;
+        case InputKeyDown:
+            uart_text_input_handle_down(uart_text_input, model);
+            break;
+        case InputKeyLeft:
+            uart_text_input_handle_left(uart_text_input, model);
+            break;
+        case InputKeyRight:
+            uart_text_input_handle_right(uart_text_input, model);
+            break;
+        case InputKeyOk:
+            uart_text_input_handle_ok(uart_text_input, model, false);
+            break;
+        default:
+            consumed = false;
+            break;
+        }
+    }
+    else if (event->type == InputTypeLong)
+    {
+        consumed = true;
+        switch (event->key)
+        {
+        case InputKeyUp:
+            uart_text_input_handle_up(uart_text_input, model);
+            break;
+        case InputKeyDown:
+            uart_text_input_handle_down(uart_text_input, model);
+            break;
+        case InputKeyLeft:
+            uart_text_input_handle_left(uart_text_input, model);
+            break;
+        case InputKeyRight:
+            uart_text_input_handle_right(uart_text_input, model);
+            break;
+        case InputKeyOk:
+            uart_text_input_handle_ok(uart_text_input, model, true);
+            break;
+        case InputKeyBack:
+            uart_text_input_backspace_cb(model);
+            break;
+        default:
+            consumed = false;
+            break;
+        }
+    }
+    else if (event->type == InputTypeRepeat)
+    {
+        consumed = true;
+        switch (event->key)
+        {
+        case InputKeyUp:
+            uart_text_input_handle_up(uart_text_input, model);
+            break;
+        case InputKeyDown:
+            uart_text_input_handle_down(uart_text_input, model);
+            break;
+        case InputKeyLeft:
+            uart_text_input_handle_left(uart_text_input, model);
+            break;
+        case InputKeyRight:
+            uart_text_input_handle_right(uart_text_input, model);
+            break;
+        case InputKeyBack:
+            uart_text_input_backspace_cb(model);
+            break;
+        default:
+            consumed = false;
+            break;
+        }
+    }
+
+    // Commit model
+    view_commit_model(uart_text_input->view, consumed);
+
+    return consumed;
+}
+
+void uart_text_input_timer_callback(void *context)
+{
+    furi_assert(context);
+    UART_TextInput *uart_text_input = context;
+
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        { model->valadator_message_visible = false; },
+        true);
+}
+
+UART_TextInput *uart_text_input_alloc()
+{
+    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+    uart_text_input->view = view_alloc();
+    view_set_context(uart_text_input->view, uart_text_input);
+    view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
+    view_set_draw_callback(uart_text_input->view, uart_text_input_view_draw_callback);
+    view_set_input_callback(uart_text_input->view, uart_text_input_view_input_callback);
+
+    uart_text_input->timer =
+        furi_timer_alloc(uart_text_input_timer_callback, FuriTimerTypeOnce, uart_text_input);
+
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        { model->validator_text = furi_string_alloc(); },
+        false);
+
+    uart_text_input_reset(uart_text_input);
+
+    return uart_text_input;
+}
+
+void uart_text_input_free(UART_TextInput *uart_text_input)
+{
+    furi_assert(uart_text_input);
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        { furi_string_free(model->validator_text); },
+        false);
+
+    // Send stop command
+    furi_timer_stop(uart_text_input->timer);
+    // Release allocated memory
+    furi_timer_free(uart_text_input->timer);
+
+    view_free(uart_text_input->view);
+
+    free(uart_text_input);
+}
+
+void uart_text_input_reset(UART_TextInput *uart_text_input)
+{
+    furi_assert(uart_text_input);
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        {
+            model->text_buffer_size = 0;
+            model->header = "";
+            model->selected_row = 0;
+            model->selected_column = 0;
+            model->clear_default_text = false;
+            model->text_buffer = NULL;
+            model->text_buffer_size = 0;
+            model->callback = NULL;
+            model->callback_context = NULL;
+            model->validator_callback = NULL;
+            model->validator_callback_context = NULL;
+            furi_string_reset(model->validator_text);
+            model->valadator_message_visible = false;
+        },
+        true);
+}
+
+View *uart_text_input_get_view(UART_TextInput *uart_text_input)
+{
+    furi_assert(uart_text_input);
+    return uart_text_input->view;
+}
+
+void uart_text_input_set_result_callback(
+    UART_TextInput *uart_text_input,
+    UART_TextInputCallback callback,
+    void *callback_context,
+    char *text_buffer,
+    size_t text_buffer_size,
+    bool clear_default_text)
+{
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        {
+            model->callback = callback;
+            model->callback_context = callback_context;
+            model->text_buffer = text_buffer;
+            model->text_buffer_size = text_buffer_size;
+            model->clear_default_text = clear_default_text;
+            if (text_buffer && text_buffer[0] != '\0')
+            {
+                // Set focus on Save
+                model->selected_row = 2;
+                model->selected_column = 8;
+            }
+        },
+        true);
+}
+
+void uart_text_input_set_validator(
+    UART_TextInput *uart_text_input,
+    UART_TextInputValidatorCallback callback,
+    void *callback_context)
+{
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        {
+            model->validator_callback = callback;
+            model->validator_callback_context = callback_context;
+        },
+        true);
+}
+
+UART_TextInputValidatorCallback
+uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
+{
+    UART_TextInputValidatorCallback validator_callback = NULL;
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        { validator_callback = model->validator_callback; },
+        false);
+    return validator_callback;
+}
+
+void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
+{
+    void *validator_callback_context = NULL;
+    with_view_model(
+        uart_text_input->view,
+        UART_TextInputModel * model,
+        { validator_callback_context = model->validator_callback_context; },
+        false);
+    return validator_callback_context;
+}
+
+void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
+{
+    with_view_model(
+        uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
+}

+ 83 - 0
text_input/uart_text_input.h

@@ -0,0 +1,83 @@
+#pragma once
+// from https://github.com/xMasterX/all-the-plugins/blob/dev/base_pack/uart_terminal/uart_text_input.c
+// all credits to xMasterX for the code
+#include <gui/view.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+    /** Text input anonymous structure */
+    typedef struct UART_TextInput UART_TextInput;
+    typedef void (*UART_TextInputCallback)(void *context);
+    typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+
+    /** Allocate and initialize text input
+     *
+     * This text input is used to enter string
+     *
+     * @return     UART_TextInput instance
+     */
+    UART_TextInput *uart_text_input_alloc();
+
+    /** Deinitialize and free text input
+     *
+     * @param      uart_text_input  UART_TextInput instance
+     */
+    void uart_text_input_free(UART_TextInput *uart_text_input);
+
+    /** Clean text input view Note: this function does not free memory
+     *
+     * @param      uart_text_input  Text input instance
+     */
+    void uart_text_input_reset(UART_TextInput *uart_text_input);
+
+    /** Get text input view
+     *
+     * @param      uart_text_input  UART_TextInput instance
+     *
+     * @return     View instance that can be used for embedding
+     */
+    View *uart_text_input_get_view(UART_TextInput *uart_text_input);
+
+    /** Set text input result callback
+     *
+     * @param      uart_text_input          UART_TextInput instance
+     * @param      callback            callback fn
+     * @param      callback_context    callback context
+     * @param      text_buffer         pointer to YOUR text buffer, that we going
+     *                                 to modify
+     * @param      text_buffer_size    YOUR text buffer size in bytes. Max string
+     *                                 length will be text_buffer_size-1.
+     * @param      clear_default_text  clear text from text_buffer on first OK
+     *                                 event
+     */
+    void uart_text_input_set_result_callback(
+        UART_TextInput *uart_text_input,
+        UART_TextInputCallback callback,
+        void *callback_context,
+        char *text_buffer,
+        size_t text_buffer_size,
+        bool clear_default_text);
+
+    void uart_text_input_set_validator(
+        UART_TextInput *uart_text_input,
+        UART_TextInputValidatorCallback callback,
+        void *callback_context);
+
+    UART_TextInputValidatorCallback
+    uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+
+    void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input);
+
+    /** Set text input header text
+     *
+     * @param      uart_text_input  UART_TextInput instance
+     * @param      text        text to be shown
+     */
+    void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text);
+
+#ifdef __cplusplus
+}
+#endif