Przeglądaj źródła

install VGM firmware + update Marauder to 1.2

currently only FlipperHTTP, since the official firmware is included in the app and I haven't heard of any other VGM firmwares yet
jblanked 1 rok temu
rodzic
commit
fecb6f73a1

+ 5 - 1
alloc/flip_store_alloc.c

@@ -38,7 +38,11 @@ FlipStoreApp *flip_store_app_alloc()
     {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_firmwares, FlipStoreViewFirmwares, "ESP32 Firmwares", callback_to_submenu_options, &app->view_dispatcher))
+    if (!easy_flipper_set_submenu(&app->submenu_firmwares, FlipStoreViewFirmwares, "ESP32 Firmware", callback_to_submenu_options, &app->view_dispatcher))
+    {
+        return NULL;
+    }
+    if (!easy_flipper_set_submenu(&app->submenu_vgm_firmwares, FlipStoreViewVGMFirmwares, "VGM Firmware", callback_to_submenu_options, &app->view_dispatcher))
     {
         return NULL;
     }

+ 1 - 0
assets/CHANGELOG.md

@@ -3,6 +3,7 @@
 - Switched to use Flipper catalog API.
 - Added an option to download Video Game Module firmware (FlipperHTTP)
 - Added an option to download Github repositories.
+- Updated Marauder to the version 1.2
 
 ## v0.7.2
 - Final memory allocation improvements

+ 112 - 8
callback/flip_store_callback.c

@@ -97,6 +97,40 @@ static void flip_store_switch_to_firmware_list(FlipStoreApp *app)
 {
     flip_store_generic_switch_to_view(app, firmwares[selected_firmware_index].name, flip_store_fetch_firmware, flip_store_parse_firmware, FIRMWARE_LINKS, callback_to_firmware_list, FlipStoreViewLoader);
 }
+//
+static bool flip_store_fetch_vgm_firmware(DataLoaderModel *model)
+{
+    if (!model->fhttp)
+    {
+        FURI_LOG_E(TAG, "FlipperHTTP is NULL");
+        return false;
+    }
+    model->fhttp->state = IDLE;
+    if (model->request_index == 0)
+    {
+        vgm_firmware_free();
+        vgm_firmwares = vgm_firmware_alloc();
+        if (!vgm_firmwares)
+        {
+            return false;
+        }
+        return flip_store_get_firmware_file(
+            model->fhttp,
+            vgm_firmwares[selected_firmware_index].link,
+            vgm_firmwares[selected_firmware_index].name,
+            strrchr(vgm_firmwares[selected_firmware_index].link, '/') + 1);
+    }
+    return false;
+}
+static char *flip_store_parse_vgm_firmware(DataLoaderModel *model)
+{
+    UNUSED(model);
+    return "Firmware downloaded successfully";
+}
+static void flip_store_switch_to_vgm_firmware_list(FlipStoreApp *app)
+{
+    flip_store_generic_switch_to_view(app, vgm_firmwares[selected_firmware_index].name, flip_store_fetch_vgm_firmware, flip_store_parse_vgm_firmware, 1, callback_to_vgm_firmware_list, FlipStoreViewLoader);
+}
 
 // Function to draw the message on the canvas with word wrapping
 static void draw_description(Canvas *canvas, const char *description, int x, int y)
@@ -361,6 +395,11 @@ uint32_t callback_to_firmware_list(void *context)
     UNUSED(context);
     return FlipStoreViewFirmwares;
 }
+uint32_t callback_to_vgm_firmware_list(void *context)
+{
+    UNUSED(context);
+    return FlipStoreViewVGMFirmwares;
+}
 static uint32_t callback_to_app_category_list(void *context)
 {
     UNUSED(context);
@@ -377,7 +416,6 @@ static uint32_t callback_to_wifi_settings(void *context)
     UNUSED(context);
     return FlipStoreViewSettings;
 }
-
 static void dialog_firmware_callback(DialogExResult result, void *context)
 {
     FlipStoreApp *app = (FlipStoreApp *)context;
@@ -389,12 +427,26 @@ static void dialog_firmware_callback(DialogExResult result, void *context)
     if (result == DialogExResultLeft) // No
     {
         // switch to the firmware list
-        view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewFirmwares);
+        if (is_esp32_firmware)
+        {
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewFirmwares);
+        }
+        else
+        {
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewVGMFirmwares);
+        }
     }
     else if (result == DialogExResultRight)
     {
         // download the firmware then return to the firmware list
-        flip_store_switch_to_firmware_list(app);
+        if (is_esp32_firmware)
+        {
+            flip_store_switch_to_firmware_list(app);
+        }
+        else
+        {
+            flip_store_switch_to_vgm_firmware_list(app);
+        }
     }
 }
 
@@ -597,7 +649,7 @@ static bool alloc_dialog_firmware(void *context)
         if (!easy_flipper_set_dialog_ex(
                 &app->dialog_firmware,
                 FlipStoreViewFirmwareDialog,
-                "Download Firmware",
+                is_esp32_firmware ? "Download ESP32 Firmware" : "Download VGM Firmware",
                 0,
                 0,
                 "Are you sure you want to\ndownload this firmware?",
@@ -617,7 +669,14 @@ static bool alloc_dialog_firmware(void *context)
         {
             return false;
         }
-        dialog_ex_set_header(app->dialog_firmware, firmwares[selected_firmware_index].name, 0, 0, AlignLeft, AlignTop);
+        if (is_esp32_firmware)
+        {
+            dialog_ex_set_header(app->dialog_firmware, firmwares[selected_firmware_index].name, 0, 0, AlignLeft, AlignTop);
+        }
+        else
+        {
+            dialog_ex_set_header(app->dialog_firmware, vgm_firmwares[selected_firmware_index].name, 0, 0, AlignLeft, AlignTop);
+        }
     }
     return true;
 }
@@ -702,6 +761,7 @@ void free_all_views(FlipStoreApp *app, bool should_free_variable_item_list)
     free_dialog_firmware(app);
     free_app_info_view(app);
     firmware_free();
+    vgm_firmware_free();
 }
 uint32_t callback_exit_app(void *context)
 {
@@ -817,7 +877,7 @@ void callback_submenu_choices(void *context, uint32_t index)
         flip_store_app_does_exist = false;
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppList);
         break;
-    case FlipStoreSubmenuIndexFirmwares:
+    case FlipStoreSubmenuIndexFirmwares: // esp32 firmwares
         firmwares = firmware_alloc();
         if (firmwares == NULL)
         {
@@ -832,6 +892,21 @@ void callback_submenu_choices(void *context, uint32_t index)
         }
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewFirmwares);
         break;
+    case FlipStoreSubmenuIndexVGMFirmwares: // vgm firmwares
+        vgm_firmwares = vgm_firmware_alloc();
+        if (vgm_firmwares == NULL)
+        {
+            FURI_LOG_E(TAG, "Failed to allocate memory for vgm firmwares");
+            return;
+        }
+        submenu_reset(app->submenu_vgm_firmwares);
+        submenu_set_header(app->submenu_vgm_firmwares, "VGM Firmwares");
+        for (int i = 0; i < VGM_FIRMWARE_COUNT; i++)
+        {
+            submenu_add_item(app->submenu_vgm_firmwares, vgm_firmwares[i].name, FlipStoreSubmenuIndexStartVGMFirmwares + i, callback_submenu_choices, app);
+        }
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewVGMFirmwares);
+        break;
     case FlipStoreSubmenuIndexAppListBluetooth:
         free_all_views(app, true);
         flip_store_category_index = 0;
@@ -899,8 +974,8 @@ void callback_submenu_choices(void *context, uint32_t index)
         fetch_appropiate_app_list(app, 0);
         break;
     default:
-        // Check if the index is within the firmwares list range
-        if (index >= FlipStoreSubmenuIndexStartFirmwares && index < FlipStoreSubmenuIndexStartFirmwares + 3)
+        // Check if the index is within the ESP32 firmwares list range
+        if (index >= FlipStoreSubmenuIndexStartFirmwares && index < FlipStoreSubmenuIndexStartFirmwares + FIRMWARE_COUNT)
         {
             // Get the firmware index
             uint32_t firmware_index = index - FlipStoreSubmenuIndexStartFirmwares;
@@ -910,6 +985,35 @@ void callback_submenu_choices(void *context, uint32_t index)
             {
                 // Get the firmware name
                 selected_firmware_index = firmware_index;
+                is_esp32_firmware = true;
+
+                // Switch to the firmware download view
+                free_dialog_firmware(app);
+                if (!alloc_dialog_firmware(app))
+                {
+                    FURI_LOG_E(TAG, "Failed to allocate dialog firmware");
+                    return;
+                }
+                view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewFirmwareDialog);
+            }
+            else
+            {
+                FURI_LOG_E(TAG, "Invalid firmware index");
+                easy_flipper_dialog("Error", "Issue parsing firmware.");
+            }
+        }
+        // Check if the index is within the VGM firmwares list range
+        else if (index >= FlipStoreSubmenuIndexStartVGMFirmwares && index < FlipStoreSubmenuIndexStartVGMFirmwares + VGM_FIRMWARE_COUNT)
+        {
+            // Get the firmware index
+            uint32_t firmware_index = index - FlipStoreSubmenuIndexStartVGMFirmwares;
+
+            // Check if the firmware index is valid
+            if ((int)firmware_index >= 0 && firmware_index < VGM_FIRMWARE_COUNT)
+            {
+                // Get the firmware name
+                selected_firmware_index = firmware_index;
+                is_esp32_firmware = false;
 
                 // Switch to the firmware download view
                 free_dialog_firmware(app);

+ 1 - 0
callback/flip_store_callback.h

@@ -20,6 +20,7 @@ uint32_t callback_to_submenu(void *context);
 uint32_t callback_to_submenu_options(void *context);
 
 uint32_t callback_to_firmware_list(void *context);
+uint32_t callback_to_vgm_firmware_list(void *context);
 
 uint32_t callback_to_app_list(void *context);
 

+ 48 - 51
firmwares/flip_store_firmwares.c

@@ -2,6 +2,7 @@
 
 Firmware *firmwares = NULL;
 VGMFirmware *vgm_firmwares = NULL;
+bool is_esp32_firmware = true;
 
 Firmware *firmware_alloc()
 {
@@ -11,62 +12,44 @@ Firmware *firmware_alloc()
         FURI_LOG_E(TAG, "Failed to allocate memory for Firmware");
         return NULL;
     }
-    for (int i = 0; i < FIRMWARE_COUNT; i++)
-    {
-        if (fw[i].name == NULL)
-        {
-            fw[i].name = (char *)malloc(16);
-            if (!fw[i].name)
-            {
-                FURI_LOG_E(TAG, "Failed to allocate memory for Firmware name");
-                return NULL;
-            }
-        }
-        for (int j = 0; j < FIRMWARE_LINKS; j++)
-        {
-            if (fw[i].links[j] == NULL)
-            {
-                fw[i].links[j] = (char *)malloc(256);
-                if (!fw[i].links[j])
-                {
-                    FURI_LOG_E(TAG, "Failed to allocate memory for Firmware links");
-                    return NULL;
-                }
-            }
-        }
-    }
 
     // Black Magic
-    fw[0].name = "Black Magic";
-    fw[0].links[0] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/bootloader.bin";
-    fw[0].links[1] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/partition-table.bin";
-    fw[0].links[2] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/blackmagic.bin";
+    snprintf(fw[0].name, sizeof(fw[0].name), "%s", "Black Magic");
+    snprintf(fw[0].links[0], sizeof(fw[0].links[0]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/bootloader.bin");
+    snprintf(fw[0].links[1], sizeof(fw[0].links[1]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/partition-table.bin");
+    snprintf(fw[0].links[2], sizeof(fw[0].links[2]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/blackmagic.bin");
 
     // FlipperHTTP
-    fw[1].name = "FlipperHTTP";
-    fw[1].links[0] = "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_bootloader.bin";
-    fw[1].links[1] = "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_firmware_a.bin";
-    fw[1].links[2] = "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_partitions.bin";
+    snprintf(fw[1].name, sizeof(fw[1].name), "%s", "FlipperHTTP");
+    snprintf(fw[1].links[0], sizeof(fw[1].links[0]), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_bootloader.bin");
+    snprintf(fw[1].links[1], sizeof(fw[1].links[1]), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_firmware_a.bin");
+    snprintf(fw[1].links[2], sizeof(fw[1].links[2]), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_partitions.bin");
 
     // Marauder
-    fw[2].name = "Marauder";
-    fw[2].links[0] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.bootloader.bin";
-    fw[2].links[1] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.partitions.bin";
-    fw[2].links[2] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/CURRENT/esp32_marauder_v1_1_0_20241128_flipper.bin";
+    snprintf(fw[2].name, sizeof(fw[2].name), "%s", "Marauder");
+    snprintf(fw[2].links[0], sizeof(fw[2].links[0]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.bootloader.bin");
+    snprintf(fw[2].links[1], sizeof(fw[2].links[1]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.partitions.bin");
+    snprintf(fw[2].links[2], sizeof(fw[2].links[2]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/CURRENT/esp32_marauder_v1_2_0_12192024_flipper.bin");
+
+    return fw;
+}
 
-    // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/BM/bootloader.bin
-    // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/BM/partition-table.bin
-    // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/BM/blackmagic.bin
+VGMFirmware *vgm_firmware_alloc()
+{
+    VGMFirmware *fw = (VGMFirmware *)malloc(VGM_FIRMWARE_COUNT * sizeof(VGMFirmware));
+    if (!fw)
+    {
+        FURI_LOG_E(TAG, "Failed to allocate memory for VGM Firmware");
+        return NULL;
+    }
 
-    // https://api.github.com/repos/jblanked/FlipperHTTP/contents/flipper_http_bootloader.bin
-    // https://api.github.com/repos/jblanked/FlipperHTTP/contents/flipper_http_firmware_a.bin
-    // https://api.github.com/repos/jblanked/FlipperHTTP/contents/flipper_http_partitions.bin
+    // FlipperHTTP
+    snprintf(fw[0].name, sizeof(fw[0].name), "%s", "FlipperHTTP");
+    snprintf(fw[0].link, sizeof(fw[0].link), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/Video%20Game%20Module/MicroPython/flipper_http_vgm_micro_python.uf2");
 
-    // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.bootloader.bin
-    // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.partitions.bin
-    // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/CURRENT/esp32_marauder_v1_0_0_20240626_flipper.bin
     return fw;
 }
+
 void firmware_free()
 {
     if (firmwares)
@@ -75,7 +58,7 @@ void firmware_free()
         firmwares = NULL;
     }
 }
-void vg_firmware_free()
+void vgm_firmware_free()
 {
     if (vgm_firmwares)
     {
@@ -95,13 +78,27 @@ bool flip_store_get_firmware_file(FlipperHTTP *fhttp, char *link, char *name, ch
     {
         return false;
     }
+
     Storage *storage = furi_record_open(RECORD_STORAGE);
+
     char directory_path[64];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher");
-    storage_common_mkdir(storage, directory_path);
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s", firmwares[selected_firmware_index].name);
-    storage_common_mkdir(storage, directory_path);
-    snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s/%s", name, filename);
+    // save in ESP32 flasher directory
+    if (is_esp32_firmware)
+    {
+        snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher");
+        storage_common_mkdir(storage, directory_path);
+        snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s", firmwares[selected_firmware_index].name);
+        storage_common_mkdir(storage, directory_path);
+        snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s/%s", name, filename);
+    }
+    else // install in app_data directory
+    {
+        snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/vgm");
+        storage_common_mkdir(storage, directory_path);
+        snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/vgm/%s", name);
+        storage_common_mkdir(storage, directory_path);
+        snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/vgm/%s/%s", name, filename);
+    }
     furi_record_close(RECORD_STORAGE);
     fhttp->save_received_data = false;
     fhttp->is_bytes_request = true;

+ 5 - 4
firmwares/flip_store_firmwares.h

@@ -7,14 +7,14 @@
 
 typedef struct
 {
-    char *name;
-    char *links[FIRMWARE_LINKS];
+    char name[16];
+    char links[FIRMWARE_LINKS][256];
 } Firmware;
 
 typedef struct
 {
-    char *name;
-    char *link;
+    char name[16];
+    char link[256];
 } VGMFirmware;
 
 extern Firmware *firmwares;
@@ -23,6 +23,7 @@ Firmware *firmware_alloc();
 VGMFirmware *vgm_firmware_alloc();
 void firmware_free();
 void vgm_firmware_free();
+extern bool is_esp32_firmware;
 
 // download and waiting process
 bool flip_store_get_firmware_file(FlipperHTTP *fhttp, char *link, char *name, char *filename);

+ 5 - 0
flip_store.c

@@ -46,6 +46,11 @@ void flip_store_app_free(FlipStoreApp *app)
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewFirmwares);
         submenu_free(app->submenu_firmwares);
     }
+    if (app->submenu_vgm_firmwares)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewVGMFirmwares);
+        submenu_free(app->submenu_vgm_firmwares);
+    }
 
     free_all_views(app, true);
 

+ 5 - 1
flip_store.h

@@ -21,6 +21,9 @@
 #define FIRMWARE_COUNT 3
 #define FIRMWARE_LINKS 3
 
+#define VGM_FIRMWARE_COUNT 1
+#define VGM_FIRMWARE_LINKS 1
+
 // Define the submenu items for our FlipStore application
 typedef enum
 {
@@ -46,7 +49,8 @@ typedef enum
     FlipStoreSubmenuIndexAppListTools,
     FlipStoreSubmenuIndexAppListUSB,
     //
-    FlipStoreSubmenuIndexStartFirmwares,
+    FlipStoreSubmenuIndexStartFirmwares = 50,
+    FlipStoreSubmenuIndexStartVGMFirmwares = 60,
     //
     FlipStoreSubmenuIndexStartAppList = 100,
 } FlipStoreSubmenuIndex;