From 58beca313d229fe2c3345005f6f20250deeac09b Mon Sep 17 00:00:00 2001 From: Z3BRO <101530102+Z3BRO@users.noreply.github.com> Date: Thu, 27 Jul 2023 17:25:32 +0200 Subject: [PATCH 1/7] SubGHz External High Power --- .../scenes/subghz_scene_radio_settings.c | 32 ++++++++++++++++ .../main/subghz/subghz_last_settings.c | 19 +++++++++- .../main/subghz/subghz_last_settings.h | 1 + lib/subghz/devices/devices.c | 38 +++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 6fb6e5089..598d6fdce 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -20,6 +20,12 @@ const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = { "ON", }; +#define EXT_MOD_POWER_AMP_COUNT 2 +const char* const ext_mod_power_amp_text[EXT_MOD_POWER_AMP_COUNT] = { + "OFF", + "ON", +}; + #define DEBUG_P_COUNT 2 const char* const debug_pin_text[DEBUG_P_COUNT] = { "OFF", @@ -105,6 +111,22 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) { // subghz_last_settings_save(subghz->last_settings); // } +static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) { + SubGhz* subghz = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]); + + if(index == 1) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } else { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz->last_settings->external_module_power_amp = index == 1; + subghz_last_settings_save(subghz->last_settings); +} + static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -137,6 +159,16 @@ void subghz_scene_radio_settings_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, radio_device_text[value_index]); + item = variable_item_list_add( + variable_item_list, + "Ext High Power", + EXT_MOD_POWER_AMP_COUNT, + subghz_scene_reciever_config_set_ext_mod_power_amp_text, + subghz); + value_index = subghz->last_settings->external_module_power_amp ? 1 : 0; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, ext_mod_power_amp_text[value_index]); + item = variable_item_list_add( variable_item_list, "Time in names", diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index b61ed3769..5f67fc780 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -19,6 +19,7 @@ #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" +#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" SubGhzLastSettings* subghz_last_settings_alloc(void) { @@ -46,6 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count float temp_frequency_analyzer_trigger = 0; bool temp_external_module_enabled = false; bool temp_external_module_power_5v_disable = false; + bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; @@ -77,6 +79,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER, (bool*)&temp_external_module_power_5v_disable, + 1); + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + (bool*)&temp_external_module_power_amp, 1); flipper_format_read_bool( fff_data_file, @@ -96,6 +103,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; + instance->external_module_power_amp = false; instance->timestamp_file_names = false; } else { @@ -118,7 +126,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; instance->timestamp_file_names = temp_timestamp_file_names; - + + instance->external_module_power_amp = temp_external_module_power_amp; + /*/} else { instance->preset = temp_preset; }*/ @@ -188,6 +198,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { &instance->external_module_power_5v_disable, 1)) { break; + } + if(!flipper_format_insert_or_update_bool( + file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + &instance->external_module_power_amp, + 1)) { + break; } if(!flipper_format_insert_or_update_bool( file, diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index d1a5b495f..c351cb6a5 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -13,6 +13,7 @@ typedef struct { // TODO not using but saved so as not to change the version bool external_module_enabled; bool external_module_power_5v_disable; + bool external_module_power_amp; // saved so as not to change the version bool timestamp_file_names; } SubGhzLastSettings; diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index a90bf73a3..525c38323 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -2,14 +2,34 @@ #include "registry.h" +#include + void subghz_devices_init() { furi_check(!subghz_device_registry_is_valid()); subghz_device_registry_init(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } + + subghz_last_settings_free(last_settings); } void subghz_devices_deinit(void) { furi_check(subghz_device_registry_is_valid()); subghz_device_registry_deinit(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz_last_settings_free(last_settings); } const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) { @@ -69,6 +89,7 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); + furi_hal_gpio_write(&gpio_ext_pc3, 0); } } @@ -121,6 +142,15 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_write(&gpio_ext_pc3, 1); + } + + subghz_last_settings_free(last_settings); } return ret; } @@ -161,6 +191,14 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + + subghz_last_settings_free(last_settings); } } From d4ff1e3a5087b58d36b62ae0b4ff0321ed95562c Mon Sep 17 00:00:00 2001 From: Cody Tolene Date: Thu, 27 Jul 2023 22:25:37 -0500 Subject: [PATCH 2/7] Update '[ESP32] Camera Suite' to v1.1.0 --- .../external/camera_suite/camera_suite.c | 25 +- .../external/camera_suite/camera_suite.h | 10 +- .../helpers/camera_suite_custom_event.h | 21 +- ..._style_1.c => camera_suite_scene_camera.c} | 28 +- .../scenes/camera_suite_scene_config.h | 3 +- .../scenes/camera_suite_scene_menu.c | 26 +- .../scenes/camera_suite_scene_start.c | 2 +- .../scenes/camera_suite_scene_style_2.c | 54 ---- ...w_style_1.c => camera_suite_view_camera.c} | 155 +++++------ ...w_style_1.h => camera_suite_view_camera.h} | 27 +- .../views/camera_suite_view_style_2.c | 249 ------------------ .../views/camera_suite_view_style_2.h | 19 -- 12 files changed, 119 insertions(+), 500 deletions(-) rename applications/external/camera_suite/scenes/{camera_suite_scene_style_1.c => camera_suite_scene_camera.c} (59%) delete mode 100644 applications/external/camera_suite/scenes/camera_suite_scene_style_2.c rename applications/external/camera_suite/views/{camera_suite_view_style_1.c => camera_suite_view_camera.c} (72%) rename applications/external/camera_suite/views/{camera_suite_view_style_1.h => camera_suite_view_camera.h} (56%) delete mode 100644 applications/external/camera_suite/views/camera_suite_view_style_2.c delete mode 100644 applications/external/camera_suite/views/camera_suite_view_style_2.h diff --git a/applications/external/camera_suite/camera_suite.c b/applications/external/camera_suite/camera_suite.c index 13ee09c22..cbe7e3d62 100644 --- a/applications/external/camera_suite/camera_suite.c +++ b/applications/external/camera_suite/camera_suite.c @@ -13,7 +13,7 @@ void camera_suite_tick_event_callback(void* context) { scene_manager_handle_tick_event(app->scene_manager); } -//leave app if back button pressed +// Leave app if back button pressed. bool camera_suite_navigation_event_callback(void* context) { furi_assert(context); CameraSuite* app = context; @@ -25,10 +25,10 @@ CameraSuite* camera_suite_app_alloc() { app->gui = furi_record_open(RECORD_GUI); app->notification = furi_record_open(RECORD_NOTIFICATION); - //Turn backlight on, believe me this makes testing your app easier + // Turn backlight on. notification_message(app->notification, &sequence_display_backlight_on); - //Scene additions + // Scene additions app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_enable_queue(app->view_dispatcher); @@ -60,17 +60,11 @@ CameraSuite* camera_suite_app_alloc() { CameraSuiteViewIdStartscreen, camera_suite_view_start_get_view(app->camera_suite_view_start)); - app->camera_suite_view_style_1 = camera_suite_view_style_1_alloc(); + app->camera_suite_view_camera = camera_suite_view_camera_alloc(); view_dispatcher_add_view( app->view_dispatcher, - CameraSuiteViewIdScene1, - camera_suite_view_style_1_get_view(app->camera_suite_view_style_1)); - - app->camera_suite_view_style_2 = camera_suite_view_style_2_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - CameraSuiteViewIdScene2, - camera_suite_view_style_2_get_view(app->camera_suite_view_style_2)); + CameraSuiteViewIdCamera, + camera_suite_view_camera_get_view(app->camera_suite_view_camera)); app->camera_suite_view_guide = camera_suite_view_guide_alloc(); view_dispatcher_add_view( @@ -98,9 +92,9 @@ void camera_suite_app_free(CameraSuite* app) { scene_manager_free(app->scene_manager); // View Dispatcher + view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdStartscreen); view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdMenu); - view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdScene1); - view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdScene2); + view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdCamera); view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdGuide); view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdSettings); submenu_free(app->submenu); @@ -110,8 +104,7 @@ void camera_suite_app_free(CameraSuite* app) { // Free remaining resources camera_suite_view_start_free(app->camera_suite_view_start); - camera_suite_view_style_1_free(app->camera_suite_view_style_1); - camera_suite_view_style_2_free(app->camera_suite_view_style_2); + camera_suite_view_camera_free(app->camera_suite_view_camera); camera_suite_view_guide_free(app->camera_suite_view_guide); button_menu_free(app->button_menu); variable_item_list_free(app->variable_item_list); diff --git a/applications/external/camera_suite/camera_suite.h b/applications/external/camera_suite/camera_suite.h index 2b6a7748b..a8b9825be 100644 --- a/applications/external/camera_suite/camera_suite.h +++ b/applications/external/camera_suite/camera_suite.h @@ -4,9 +4,7 @@ #include "scenes/camera_suite_scene.h" #include "views/camera_suite_view_guide.h" #include "views/camera_suite_view_start.h" -#include "views/camera_suite_view_style_1.h" -#include "views/camera_suite_view_style_2.h" -#include +#include "views/camera_suite_view_camera.h" #include #include #include @@ -29,8 +27,7 @@ typedef struct { SceneManager* scene_manager; VariableItemList* variable_item_list; CameraSuiteViewStart* camera_suite_view_start; - CameraSuiteViewStyle1* camera_suite_view_style_1; - CameraSuiteViewStyle2* camera_suite_view_style_2; + CameraSuiteViewCamera* camera_suite_view_camera; CameraSuiteViewGuide* camera_suite_view_guide; uint32_t orientation; uint32_t haptic; @@ -42,8 +39,7 @@ typedef struct { typedef enum { CameraSuiteViewIdStartscreen, CameraSuiteViewIdMenu, - CameraSuiteViewIdScene1, - CameraSuiteViewIdScene2, + CameraSuiteViewIdCamera, CameraSuiteViewIdGuide, CameraSuiteViewIdSettings, } CameraSuiteViewId; diff --git a/applications/external/camera_suite/helpers/camera_suite_custom_event.h b/applications/external/camera_suite/helpers/camera_suite_custom_event.h index 7727a0de3..4d472d577 100644 --- a/applications/external/camera_suite/helpers/camera_suite_custom_event.h +++ b/applications/external/camera_suite/helpers/camera_suite_custom_event.h @@ -8,20 +8,13 @@ typedef enum { CameraSuiteCustomEventStartRight, CameraSuiteCustomEventStartOk, CameraSuiteCustomEventStartBack, - // Scene events: Camera style 1 - CameraSuiteCustomEventSceneStyle1Up, - CameraSuiteCustomEventSceneStyle1Down, - CameraSuiteCustomEventSceneStyle1Left, - CameraSuiteCustomEventSceneStyle1Right, - CameraSuiteCustomEventSceneStyle1Ok, - CameraSuiteCustomEventSceneStyle1Back, - // Scene events: Camera style 2 - CameraSuiteCustomEventSceneStyle2Up, - CameraSuiteCustomEventSceneStyle2Down, - CameraSuiteCustomEventSceneStyle2Left, - CameraSuiteCustomEventSceneStyle2Right, - CameraSuiteCustomEventSceneStyle2Ok, - CameraSuiteCustomEventSceneStyle2Back, + // Scene events: Camera + CameraSuiteCustomEventSceneCameraUp, + CameraSuiteCustomEventSceneCameraDown, + CameraSuiteCustomEventSceneCameraLeft, + CameraSuiteCustomEventSceneCameraRight, + CameraSuiteCustomEventSceneCameraOk, + CameraSuiteCustomEventSceneCameraBack, // Scene events: Guide CameraSuiteCustomEventSceneGuideUp, CameraSuiteCustomEventSceneGuideDown, diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_style_1.c b/applications/external/camera_suite/scenes/camera_suite_scene_camera.c similarity index 59% rename from applications/external/camera_suite/scenes/camera_suite_scene_style_1.c rename to applications/external/camera_suite/scenes/camera_suite_scene_camera.c index 1aeecec7a..809d9a5c1 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_style_1.c +++ b/applications/external/camera_suite/scenes/camera_suite_scene_camera.c @@ -1,35 +1,35 @@ #include "../camera_suite.h" #include "../helpers/camera_suite_custom_event.h" -#include "../views/camera_suite_view_style_1.h" +#include "../views/camera_suite_view_camera.h" -static void camera_suite_view_style_1_callback(CameraSuiteCustomEvent event, void* context) { +void camera_suite_view_camera_callback(CameraSuiteCustomEvent event, void* context) { furi_assert(context); CameraSuite* app = context; view_dispatcher_send_custom_event(app->view_dispatcher, event); } -void camera_suite_scene_style_1_on_enter(void* context) { +void camera_suite_scene_camera_on_enter(void* context) { furi_assert(context); CameraSuite* app = context; - camera_suite_view_style_1_set_callback( - app->camera_suite_view_style_1, camera_suite_view_style_1_callback, app); - view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdScene1); + camera_suite_view_camera_set_callback( + app->camera_suite_view_camera, camera_suite_view_camera_callback, app); + view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdCamera); } -bool camera_suite_scene_style_1_on_event(void* context, SceneManagerEvent event) { +bool camera_suite_scene_camera_on_event(void* context, SceneManagerEvent event) { CameraSuite* app = context; bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { - case CameraSuiteCustomEventSceneStyle1Left: - case CameraSuiteCustomEventSceneStyle1Right: - case CameraSuiteCustomEventSceneStyle1Up: - case CameraSuiteCustomEventSceneStyle1Down: - case CameraSuiteCustomEventSceneStyle1Ok: + case CameraSuiteCustomEventSceneCameraLeft: + case CameraSuiteCustomEventSceneCameraRight: + case CameraSuiteCustomEventSceneCameraUp: + case CameraSuiteCustomEventSceneCameraDown: + case CameraSuiteCustomEventSceneCameraOk: // Do nothing. break; - case CameraSuiteCustomEventSceneStyle1Back: + case CameraSuiteCustomEventSceneCameraBack: notification_message(app->notification, &sequence_reset_red); notification_message(app->notification, &sequence_reset_green); notification_message(app->notification, &sequence_reset_blue); @@ -46,7 +46,7 @@ bool camera_suite_scene_style_1_on_event(void* context, SceneManagerEvent event) return consumed; } -void camera_suite_scene_style_1_on_exit(void* context) { +void camera_suite_scene_camera_on_exit(void* context) { CameraSuite* app = context; UNUSED(app); } diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_config.h b/applications/external/camera_suite/scenes/camera_suite_scene_config.h index fca73ae16..2cb9245ef 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_config.h +++ b/applications/external/camera_suite/scenes/camera_suite_scene_config.h @@ -1,6 +1,5 @@ ADD_SCENE(camera_suite, start, Start) ADD_SCENE(camera_suite, menu, Menu) -ADD_SCENE(camera_suite, style_1, Style_1) -ADD_SCENE(camera_suite, style_2, Style_2) +ADD_SCENE(camera_suite, camera, Camera) ADD_SCENE(camera_suite, guide, Guide) ADD_SCENE(camera_suite, settings, Settings) \ No newline at end of file diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_menu.c b/applications/external/camera_suite/scenes/camera_suite_scene_menu.c index 09c4dade7..ae37e11b6 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_menu.c +++ b/applications/external/camera_suite/scenes/camera_suite_scene_menu.c @@ -1,10 +1,8 @@ #include "../camera_suite.h" enum SubmenuIndex { - /** Atkinson Dithering Algorithm. */ - SubmenuIndexSceneStyle1 = 10, - /** Floyd-Steinberg Dithering Algorithm. */ - SubmenuIndexSceneStyle2, + /** Camera. */ + SubmenuIndexSceneCamera = 10, /** Guide/how-to. */ SubmenuIndexGuide, /** Settings menu. */ @@ -22,16 +20,9 @@ void camera_suite_scene_menu_on_enter(void* context) { submenu_add_item( app->submenu, "Open Camera", - SubmenuIndexSceneStyle1, + SubmenuIndexSceneCamera, camera_suite_scene_menu_submenu_callback, app); - // Staged view for the future. - // submenu_add_item( - // app->submenu, - // "Test", - // SubmenuIndexSceneStyle2, - // camera_suite_scene_menu_submenu_callback, - // app); submenu_add_item( app->submenu, "Guide", SubmenuIndexGuide, camera_suite_scene_menu_submenu_callback, app); submenu_add_item( @@ -56,15 +47,10 @@ bool camera_suite_scene_menu_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(app->view_dispatcher); return true; } else if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexSceneStyle1) { + if(event.event == SubmenuIndexSceneCamera) { scene_manager_set_scene_state( - app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneStyle1); - scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStyle_1); - return true; - } else if(event.event == SubmenuIndexSceneStyle2) { - scene_manager_set_scene_state( - app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneStyle2); - scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStyle_2); + app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneCamera); + scene_manager_next_scene(app->scene_manager, CameraSuiteSceneCamera); return true; } else if(event.event == SubmenuIndexGuide) { scene_manager_set_scene_state( diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_start.c b/applications/external/camera_suite/scenes/camera_suite_scene_start.c index 12591760c..0dda05ede 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_start.c +++ b/applications/external/camera_suite/scenes/camera_suite_scene_start.c @@ -24,9 +24,9 @@ bool camera_suite_scene_start_on_event(void* context, SceneManagerEvent event) { switch(event.event) { case CameraSuiteCustomEventStartLeft: case CameraSuiteCustomEventStartRight: - break; case CameraSuiteCustomEventStartUp: case CameraSuiteCustomEventStartDown: + // Do nothing. break; case CameraSuiteCustomEventStartOk: scene_manager_next_scene(app->scene_manager, CameraSuiteSceneMenu); diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_style_2.c b/applications/external/camera_suite/scenes/camera_suite_scene_style_2.c deleted file mode 100644 index b74d33784..000000000 --- a/applications/external/camera_suite/scenes/camera_suite_scene_style_2.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "../camera_suite.h" -#include "../helpers/camera_suite_custom_event.h" -#include "../helpers/camera_suite_haptic.h" -#include "../helpers/camera_suite_led.h" -#include "../views/camera_suite_view_style_2.h" - -void camera_suite_view_style_2_callback(CameraSuiteCustomEvent event, void* context) { - furi_assert(context); - CameraSuite* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, event); -} - -void camera_suite_scene_style_2_on_enter(void* context) { - furi_assert(context); - CameraSuite* app = context; - camera_suite_view_style_2_set_callback( - app->camera_suite_view_style_2, camera_suite_view_style_2_callback, app); - view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdScene2); -} - -bool camera_suite_scene_style_2_on_event(void* context, SceneManagerEvent event) { - CameraSuite* app = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - switch(event.event) { - case CameraSuiteCustomEventSceneStyle2Left: - case CameraSuiteCustomEventSceneStyle2Right: - case CameraSuiteCustomEventSceneStyle2Up: - case CameraSuiteCustomEventSceneStyle2Down: - case CameraSuiteCustomEventSceneStyle2Ok: - // Do nothing. - break; - case CameraSuiteCustomEventSceneStyle2Back: - notification_message(app->notification, &sequence_reset_red); - notification_message(app->notification, &sequence_reset_green); - notification_message(app->notification, &sequence_reset_blue); - if(!scene_manager_search_and_switch_to_previous_scene( - app->scene_manager, CameraSuiteSceneMenu)) { - scene_manager_stop(app->scene_manager); - view_dispatcher_stop(app->view_dispatcher); - } - consumed = true; - break; - } - } - - return consumed; -} - -void camera_suite_scene_style_2_on_exit(void* context) { - CameraSuite* app = context; - UNUSED(app); -} diff --git a/applications/external/camera_suite/views/camera_suite_view_style_1.c b/applications/external/camera_suite/views/camera_suite_view_camera.c similarity index 72% rename from applications/external/camera_suite/views/camera_suite_view_style_1.c rename to applications/external/camera_suite/views/camera_suite_view_camera.c index 6d16d0231..5d710044b 100644 --- a/applications/external/camera_suite/views/camera_suite_view_style_1.c +++ b/applications/external/camera_suite/views/camera_suite_view_camera.c @@ -8,23 +8,19 @@ #include "../helpers/camera_suite_speaker.h" #include "../helpers/camera_suite_led.h" -static CameraSuiteViewStyle1* current_instance = NULL; -// Dithering type: -// 0 = Floyd Steinberg (default) -// 1 = Atkinson -static int current_dithering = 0; +static CameraSuiteViewCamera* current_instance = NULL; -struct CameraSuiteViewStyle1 { - CameraSuiteViewStyle1Callback callback; +struct CameraSuiteViewCamera { + CameraSuiteViewCameraCallback callback; FuriStreamBuffer* rx_stream; FuriThread* worker_thread; View* view; void* context; }; -void camera_suite_view_style_1_set_callback( - CameraSuiteViewStyle1* instance, - CameraSuiteViewStyle1Callback callback, +void camera_suite_view_camera_set_callback( + CameraSuiteViewCamera* instance, + CameraSuiteViewCameraCallback callback, void* context) { furi_assert(instance); furi_assert(callback); @@ -32,7 +28,29 @@ void camera_suite_view_style_1_set_callback( instance->context = context; } -static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) { +// Function to draw pixels on the canvas based on camera orientation +static void draw_pixel_by_orientation(Canvas* canvas, uint8_t x, uint8_t y, uint8_t orientation) { + switch(orientation) { + case 0: // Camera rotated 0 degrees (right side up, default) + canvas_draw_dot(canvas, x, y); + break; + case 1: // Camera rotated 90 degrees + canvas_draw_dot(canvas, y, FRAME_WIDTH - 1 - x); + break; + case 2: // Camera rotated 180 degrees (upside down) + canvas_draw_dot(canvas, FRAME_WIDTH - 1 - x, FRAME_HEIGHT - 1 - y); + break; + case 3: // Camera rotated 270 degrees + canvas_draw_dot(canvas, FRAME_HEIGHT - 1 - y, x); + break; + default: + break; + } +} + +static void camera_suite_view_camera_draw(Canvas* canvas, void* _model) { + UartDumpModel* model = _model; + // Clear the screen. canvas_set_color(canvas, ColorBlack); @@ -41,60 +59,17 @@ static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) CameraSuite* app = current_instance->context; - // Draw the pixels with rotation. for(size_t p = 0; p < FRAME_BUFFER_LENGTH; ++p) { uint8_t x = p % ROW_BUFFER_LENGTH; // 0 .. 15 uint8_t y = p / ROW_BUFFER_LENGTH; // 0 .. 63 - // Apply rotation - int16_t rotated_x, rotated_y; - switch(app->orientation) { - case 1: // 90 degrees - rotated_x = y; - rotated_y = FRAME_WIDTH - 1 - x; - break; - case 2: // 180 degrees - rotated_x = FRAME_WIDTH - 1 - x; - rotated_y = FRAME_HEIGHT - 1 - y; - break; - case 3: // 270 degrees - rotated_x = FRAME_HEIGHT - 1 - y; - rotated_y = x; - break; - case 0: // 0 degrees - default: - rotated_x = x; - rotated_y = y; - break; - } - for(uint8_t i = 0; i < 8; ++i) { - if((model->pixels[p] & (1 << i)) != 0) { - // Adjust the coordinates based on the new screen dimensions - uint16_t screen_x, screen_y; - switch(app->orientation) { - case 1: // 90 degrees - screen_x = rotated_x; - screen_y = FRAME_HEIGHT - 8 + (rotated_y * 8) + i; - break; - case 2: // 180 degrees - screen_x = FRAME_WIDTH - 8 + (rotated_x * 8) + i; - screen_y = FRAME_HEIGHT - 1 - rotated_y; - break; - case 3: // 270 degrees - screen_x = FRAME_WIDTH - 1 - rotated_x; - screen_y = rotated_y * 8 + i; - break; - case 0: // 0 degrees - default: - screen_x = rotated_x * 8 + i; - screen_y = rotated_y; - break; - } - canvas_draw_dot(canvas, screen_x, screen_y); + if((model->pixels[p] & (1 << (7 - i))) != 0) { + draw_pixel_by_orientation(canvas, (x * 8) + i, y, app->orientation); } } } + // Draw the guide if the camera is not initialized. if(!model->initialized) { canvas_draw_icon(canvas, 74, 16, &I_DolphinCommon_56x48); @@ -107,15 +82,15 @@ static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) } } -static void camera_suite_view_style_1_model_init(UartDumpModel* const model) { +static void camera_suite_view_camera_model_init(UartDumpModel* const model) { for(size_t i = 0; i < FRAME_BUFFER_LENGTH; i++) { model->pixels[i] = 0; } } -static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { +static bool camera_suite_view_camera_input(InputEvent* event, void* context) { furi_assert(context); - CameraSuiteViewStyle1* instance = context; + CameraSuiteViewCamera* instance = context; if(event->type == InputTypeRelease) { switch(event->key) { default: // Stop all sounds, reset the LED. @@ -144,7 +119,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { UartDumpModel * model, { UNUSED(model); - instance->callback(CameraSuiteCustomEventSceneStyle1Back, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraBack, instance->context); }, true); break; @@ -159,7 +134,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Left, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraLeft, instance->context); }, true); break; @@ -174,7 +149,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Right, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraRight, instance->context); }, true); break; @@ -189,7 +164,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Up, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraUp, instance->context); }, true); break; @@ -204,18 +179,13 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Down, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraDown, instance->context); }, true); break; case InputKeyOk: - if(current_dithering == 0) { - data[0] = 'd'; // Update to Floyd Steinberg dithering. - current_dithering = 1; - } else { - data[0] = 'D'; // Update to Atkinson dithering. - current_dithering = 0; - } + // Switch dithering types. + data[0] = 'D'; with_view_model( instance->view, UartDumpModel * model, @@ -224,7 +194,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Ok, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraOk, instance->context); }, true); break; @@ -237,16 +207,16 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { return true; } -static void camera_suite_view_style_1_exit(void* context) { +static void camera_suite_view_camera_exit(void* context) { furi_assert(context); } -static void camera_suite_view_style_1_enter(void* context) { +static void camera_suite_view_camera_enter(void* context) { // Check `context` for null. If it is null, abort program, else continue. furi_assert(context); - // Cast `context` to `CameraSuiteViewStyle1*` and store it in `instance`. - CameraSuiteViewStyle1* instance = (CameraSuiteViewStyle1*)context; + // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`. + CameraSuiteViewCamera* instance = (CameraSuiteViewCamera*)context; // Assign the current instance to the global variable current_instance = instance; @@ -259,7 +229,7 @@ static void camera_suite_view_style_1_enter(void* context) { with_view_model( instance->view, UartDumpModel * model, - { camera_suite_view_style_1_model_init(model); }, + { camera_suite_view_camera_model_init(model); }, true); } @@ -267,8 +237,8 @@ static void camera_on_irq_cb(UartIrqEvent uartIrqEvent, uint8_t data, void* cont // Check `context` for null. If it is null, abort program, else continue. furi_assert(context); - // Cast `context` to `CameraSuiteViewStyle1*` and store it in `instance`. - CameraSuiteViewStyle1* instance = context; + // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`. + CameraSuiteViewCamera* instance = context; // If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the // `rx_stream` and set the `WorkerEventRx` flag. @@ -319,7 +289,7 @@ static void process_ringbuffer(UartDumpModel* model, uint8_t byte) { static int32_t camera_worker(void* context) { furi_assert(context); - CameraSuiteViewStyle1* instance = context; + CameraSuiteViewCamera* instance = context; while(1) { uint32_t events = @@ -348,14 +318,17 @@ static int32_t camera_worker(void* context) { false); } } while(length > 0); + + with_view_model( + instance->view, UartDumpModel * model, { UNUSED(model); }, true); } } return 0; } -CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() { - CameraSuiteViewStyle1* instance = malloc(sizeof(CameraSuiteViewStyle1)); +CameraSuiteViewCamera* camera_suite_view_camera_alloc() { + CameraSuiteViewCamera* instance = malloc(sizeof(CameraSuiteViewCamera)); instance->view = view_alloc(); @@ -364,15 +337,15 @@ CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() { // Set up views view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(UartDumpModel)); view_set_context(instance->view, instance); // furi_assert crashes in events without this - view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_style_1_draw); - view_set_input_callback(instance->view, camera_suite_view_style_1_input); - view_set_enter_callback(instance->view, camera_suite_view_style_1_enter); - view_set_exit_callback(instance->view, camera_suite_view_style_1_exit); + view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_camera_draw); + view_set_input_callback(instance->view, camera_suite_view_camera_input); + view_set_enter_callback(instance->view, camera_suite_view_camera_enter); + view_set_exit_callback(instance->view, camera_suite_view_camera_exit); with_view_model( instance->view, UartDumpModel * model, - { camera_suite_view_style_1_model_init(model); }, + { camera_suite_view_camera_model_init(model); }, true); instance->worker_thread = furi_thread_alloc_ex("UsbUartWorker", 2048, camera_worker, instance); @@ -386,7 +359,7 @@ CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() { return instance; } -void camera_suite_view_style_1_free(CameraSuiteViewStyle1* instance) { +void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) { furi_assert(instance); with_view_model( @@ -395,7 +368,7 @@ void camera_suite_view_style_1_free(CameraSuiteViewStyle1* instance) { free(instance); } -View* camera_suite_view_style_1_get_view(CameraSuiteViewStyle1* instance) { +View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* instance) { furi_assert(instance); return instance->view; -} +} \ No newline at end of file diff --git a/applications/external/camera_suite/views/camera_suite_view_style_1.h b/applications/external/camera_suite/views/camera_suite_view_camera.h similarity index 56% rename from applications/external/camera_suite/views/camera_suite_view_style_1.h rename to applications/external/camera_suite/views/camera_suite_view_camera.h index c460c94ba..5ccbac71a 100644 --- a/applications/external/camera_suite/views/camera_suite_view_style_1.h +++ b/applications/external/camera_suite/views/camera_suite_view_camera.h @@ -19,11 +19,12 @@ #define FRAME_WIDTH 128 #define FRAME_HEIGHT 64 #define FRAME_BIT_DEPTH 1 -#define FRAME_BUFFER_LENGTH \ - (FRAME_WIDTH * FRAME_HEIGHT * FRAME_BIT_DEPTH / 8) // 128*64*1 / 8 = 1024 -#define ROW_BUFFER_LENGTH (FRAME_WIDTH / 8) // 128/8 = 16 -#define RING_BUFFER_LENGTH (ROW_BUFFER_LENGTH + 3) // ROW_BUFFER_LENGTH + Header => 16 + 3 = 19 -#define LAST_ROW_INDEX (FRAME_BUFFER_LENGTH - ROW_BUFFER_LENGTH) // 1024 - 16 = 1008 +#define FRAME_BUFFER_LENGTH 1024 +#define ROW_BUFFER_LENGTH 16 +#define RING_BUFFER_LENGTH 19 +#define LAST_ROW_INDEX 1008 + +extern const Icon I_DolphinCommon_56x48; typedef struct UartDumpModel UartDumpModel; @@ -35,20 +36,20 @@ struct UartDumpModel { uint8_t row_ringbuffer[RING_BUFFER_LENGTH]; }; -typedef struct CameraSuiteViewStyle1 CameraSuiteViewStyle1; +typedef struct CameraSuiteViewCamera CameraSuiteViewCamera; -typedef void (*CameraSuiteViewStyle1Callback)(CameraSuiteCustomEvent event, void* context); +typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void* context); -void camera_suite_view_style_1_set_callback( - CameraSuiteViewStyle1* camera_suite_view_style_1, - CameraSuiteViewStyle1Callback callback, +void camera_suite_view_camera_set_callback( + CameraSuiteViewCamera* camera_suite_view_camera, + CameraSuiteViewCameraCallback callback, void* context); -CameraSuiteViewStyle1* camera_suite_view_style_1_alloc(); +CameraSuiteViewCamera* camera_suite_view_camera_alloc(); -void camera_suite_view_style_1_free(CameraSuiteViewStyle1* camera_suite_static); +void camera_suite_view_camera_free(CameraSuiteViewCamera* camera_suite_static); -View* camera_suite_view_style_1_get_view(CameraSuiteViewStyle1* camera_suite_static); +View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* camera_suite_static); typedef enum { // Reserved for StreamBuffer internal event diff --git a/applications/external/camera_suite/views/camera_suite_view_style_2.c b/applications/external/camera_suite/views/camera_suite_view_style_2.c deleted file mode 100644 index 0a7ac0b83..000000000 --- a/applications/external/camera_suite/views/camera_suite_view_style_2.c +++ /dev/null @@ -1,249 +0,0 @@ -#include "../camera_suite.h" -#include -#include -#include -#include -#include -#include "../helpers/camera_suite_haptic.h" -#include "../helpers/camera_suite_speaker.h" -#include "../helpers/camera_suite_led.h" - -struct CameraSuiteViewStyle2 { - View* view; - CameraSuiteViewStyle2Callback callback; - void* context; -}; - -typedef struct { - int screen_text; -} CameraSuiteViewStyle2Model; - -char buttonText[11][14] = { - "", - "Press Up", - "Press Down", - "Press Left", - "Press Right", - "Press Ok", - "Release Up", - "Release Down", - "Release Left", - "Release Right", - "Release Ok", -}; - -void camera_suite_view_style_2_set_callback( - CameraSuiteViewStyle2* instance, - CameraSuiteViewStyle2Callback callback, - void* context) { - furi_assert(instance); - furi_assert(callback); - instance->callback = callback; - instance->context = context; -} - -void camera_suite_view_style_2_draw(Canvas* canvas, CameraSuiteViewStyle2Model* model) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "Scene 2: Input Examples"); - canvas_set_font(canvas, FontSecondary); - char* strInput = malloc(15); - strcpy(strInput, buttonText[model->screen_text]); - canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, strInput); - free(strInput); -} - -static void camera_suite_view_style_2_model_init(CameraSuiteViewStyle2Model* const model) { - model->screen_text = 0; -} - -bool camera_suite_view_style_2_input(InputEvent* event, void* context) { - furi_assert(context); - CameraSuiteViewStyle2* instance = context; - if(event->type == InputTypeRelease) { - switch(event->key) { - case InputKeyBack: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - UNUSED(model); - camera_suite_stop_all_sound(instance->context); - instance->callback(CameraSuiteCustomEventSceneStyle2Back, instance->context); - camera_suite_play_long_bump(instance->context); - }, - true); - break; - case InputKeyUp: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 6; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 0, 255); - }, - true); - break; - case InputKeyDown: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 7; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 255, 0); - }, - true); - break; - case InputKeyLeft: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 8; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 0, 255, 255); - }, - true); - break; - case InputKeyRight: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 9; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 0, 0); - }, - true); - break; - case InputKeyOk: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 10; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 255, 255); - }, - true); - break; - case InputKeyMAX: - break; - } - } else if(event->type == InputTypePress) { - switch(event->key) { - case InputKeyUp: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 1; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyDown: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 2; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyLeft: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 3; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyRight: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 4; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyOk: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 5; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyBack: - case InputKeyMAX: - break; - } - } - - return true; -} - -void camera_suite_view_style_2_exit(void* context) { - furi_assert(context); - CameraSuite* app = context; - camera_suite_stop_all_sound(app); - //camera_suite_led_reset(app); -} - -void camera_suite_view_style_2_enter(void* context) { - furi_assert(context); - dolphin_deed(DolphinDeedPluginStart); -} - -CameraSuiteViewStyle2* camera_suite_view_style_2_alloc() { - CameraSuiteViewStyle2* instance = malloc(sizeof(CameraSuiteViewStyle2)); - instance->view = view_alloc(); - view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(CameraSuiteViewStyle2Model)); - view_set_context(instance->view, instance); - view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_style_2_draw); - view_set_input_callback(instance->view, camera_suite_view_style_2_input); - //view_set_enter_callback(instance->view, camera_suite_view_style_2_enter); - view_set_exit_callback(instance->view, camera_suite_view_style_2_exit); - - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { camera_suite_view_style_2_model_init(model); }, - true); - - return instance; -} - -void camera_suite_view_style_2_free(CameraSuiteViewStyle2* instance) { - furi_assert(instance); - - view_free(instance->view); - free(instance); -} - -View* camera_suite_view_style_2_get_view(CameraSuiteViewStyle2* instance) { - furi_assert(instance); - - return instance->view; -} diff --git a/applications/external/camera_suite/views/camera_suite_view_style_2.h b/applications/external/camera_suite/views/camera_suite_view_style_2.h deleted file mode 100644 index d24b895f8..000000000 --- a/applications/external/camera_suite/views/camera_suite_view_style_2.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include "../helpers/camera_suite_custom_event.h" - -typedef struct CameraSuiteViewStyle2 CameraSuiteViewStyle2; - -typedef void (*CameraSuiteViewStyle2Callback)(CameraSuiteCustomEvent event, void* context); - -void camera_suite_view_style_2_set_callback( - CameraSuiteViewStyle2* instance, - CameraSuiteViewStyle2Callback callback, - void* context); - -CameraSuiteViewStyle2* camera_suite_view_style_2_alloc(); - -void camera_suite_view_style_2_free(CameraSuiteViewStyle2* camera_suite_static); - -View* camera_suite_view_style_2_get_view(CameraSuiteViewStyle2* boilerpate_static); From ff2e1acfdb480712b06f6c913424294d9a38e70d Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Fri, 28 Jul 2023 22:45:27 +0300 Subject: [PATCH 3/7] Fix fbtenv restore (#2924) --- scripts/toolchain/fbtenv.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/toolchain/fbtenv.sh b/scripts/toolchain/fbtenv.sh index 85d139040..a86b0eced 100755 --- a/scripts/toolchain/fbtenv.sh +++ b/scripts/toolchain/fbtenv.sh @@ -38,11 +38,11 @@ fbtenv_wget() fbtenv_restore_env() { TOOLCHAIN_ARCH_DIR_SED="$(echo "$TOOLCHAIN_ARCH_DIR" | sed 's/\//\\\//g')" - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/python\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/protobuf\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openocd\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openssl\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/python\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/protobuf\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openocd\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openssl\/bin://g")"; if [ -n "${PS1:-""}" ]; then PS1="$(echo "$PS1" | sed 's/\[fbt\]//g')"; elif [ -n "${PROMPT:-""}" ]; then @@ -104,8 +104,6 @@ fbtenv_check_if_sourced_multiple_times() return 0; fi fi - echo "Warning! FBT environment script was sourced more than once!"; - echo "You might be doing things wrong, please open a new shell!"; return 1; } @@ -160,7 +158,7 @@ fbtenv_get_kernel_type() fbtenv_check_rosetta() { if [ "$ARCH_TYPE" = "arm64" ]; then - if ! /usr/bin/pgrep -q oahd; then + if ! pgrep -q oahd; then echo "Flipper Zero Toolchain needs Rosetta2 to run under Apple Silicon"; echo "Please instal it by typing 'softwareupdate --install-rosetta --agree-to-license'"; return 1; @@ -312,7 +310,9 @@ fbtenv_main() fbtenv_restore_env; return 0; fi - fbtenv_check_if_sourced_multiple_times; + if ! fbtenv_check_if_sourced_multiple_times; then + return 0; + fi; fbtenv_check_env_vars || return 1; fbtenv_check_download_toolchain || return 1; fbtenv_set_shell_prompt; From e698d6274fe5c7fe364fcbbbe5a8b618da2b71bf Mon Sep 17 00:00:00 2001 From: Cody Tolene Date: Fri, 28 Jul 2023 17:49:42 -0500 Subject: [PATCH 4/7] Update to match changes from here: https://github.com/flipperdevices/flipper-application-catalog/pull/90 --- .../external/camera_suite/application.fam | 4 +- .../external/camera_suite/docs/CHANGELOG.md | 20 ++++++++++ .../external/camera_suite/docs/README.md | 35 ++++++++++++++++++ .../screenshots/camera_preview.png | Bin 0 -> 3342 bytes .../camera_suite/screenshots/guide.png | Bin 0 -> 2233 bytes .../camera_suite/screenshots/main_menu.png | Bin 0 -> 1499 bytes .../camera_suite/screenshots/settings.png | Bin 0 -> 1900 bytes .../camera_suite/screenshots/start_screen.png | Bin 0 -> 1707 bytes 8 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 applications/external/camera_suite/docs/CHANGELOG.md create mode 100644 applications/external/camera_suite/docs/README.md create mode 100644 applications/external/camera_suite/screenshots/camera_preview.png create mode 100644 applications/external/camera_suite/screenshots/guide.png create mode 100644 applications/external/camera_suite/screenshots/main_menu.png create mode 100644 applications/external/camera_suite/screenshots/settings.png create mode 100644 applications/external/camera_suite/screenshots/start_screen.png diff --git a/applications/external/camera_suite/application.fam b/applications/external/camera_suite/application.fam index 40131ae9a..63687833e 100644 --- a/applications/external/camera_suite/application.fam +++ b/applications/external/camera_suite/application.fam @@ -1,9 +1,9 @@ App( - appid="camerasuite", + appid="camera_suite", apptype=FlipperAppType.EXTERNAL, cdefines=["APP_CAMERA_SUITE"], entry_point="camera_suite_app", - fap_author="Cody Tolene", + fap_author="@CodyTolene @Z4urce @leedave", fap_category="GPIO", fap_description="A camera suite application for the Flipper Zero ESP32-CAM module.", fap_icon="icons/camera_suite.png", diff --git a/applications/external/camera_suite/docs/CHANGELOG.md b/applications/external/camera_suite/docs/CHANGELOG.md new file mode 100644 index 000000000..40f20dfc4 --- /dev/null +++ b/applications/external/camera_suite/docs/CHANGELOG.md @@ -0,0 +1,20 @@ +## v1.1 + +- Support and picture stabilization for all camera orientations (0°, 90°, 180°, 270°). +- Rename "Scene 1" to "Camera". No UX changes, strictly internal. +- Clean up unused "Scene 2". This was inaccessible to users previously and unused. +- Add new dithering variations (needs new module firmware, see https://github.com/CodyTolene/Flipper-Zero-Camera-Suite#firmware-installation): + - Add `Jarvis Judice` Ninke Dithering option + - Add `Stucki` dithering option. + - Add ability to toggle dithering options from default `Floyd-Steinberg` and back. +- Resolves issue https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues/7 +- Resolves issue https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/pull/17 + +## v1.0 + +- Builds upon Z4urce's software found here (updated 6 months ago): https://github.com/Z4urce/flipperzero-camera +- Utilizes the superb C boilerplate examples laid out by leedave (updated last month): https://github.com/leedave/flipper-zero-fap-boilerplate +- Repurpose and build upon the "[ESP32] Camera" software into the new "[ESP32] Camera Suite" application with new purpose: + - Adding more scene for a guide. + - Adding more scene for saveable settings. + - Add ability to rotate the camera orientation. diff --git a/applications/external/camera_suite/docs/README.md b/applications/external/camera_suite/docs/README.md new file mode 100644 index 000000000..1f436a067 --- /dev/null +++ b/applications/external/camera_suite/docs/README.md @@ -0,0 +1,35 @@ +## Flipper Zero - Camera Suite + +Software to run an ESP32-CAM module on your Flipper Zero device. + +## Software Guide + +### Flipper Zero button mappings: + +🔼 = Contrast Up + +🔽 = Contrast Down + +◀️ = Toggle invert. + +▶️ = Toggle dithering on/off. + +⚪ = Cycle Floyd–Steinberg/Jarvis-Judice-Ninke/Stucki dithering types. + +↩️ = Go back. + +### Camera Suite settings: + +**Orientation** = Rotate the camera image 90 degrees counter-clockwise starting at zero by default (0, 90, 180, 270). This is useful if you have your camera module mounted in a different orientation than the default. + +**Haptic FX** = Toggle haptic feedback on/off. + +**Sound FX** = Toggle sound effects on/off. + +**LED FX** = Toggle LED effects on/off. + +## Links + +Full setup, wiring guide, etc. in the main project README here: https://github.com/CodyTolene/Flipper-Zero-Camera-Suite + +A firmware is needed for the ESP32-CAM module, see here for more information: https://github.com/CodyTolene/Flipper-Zero-Camera-Suite#firmware-installation diff --git a/applications/external/camera_suite/screenshots/camera_preview.png b/applications/external/camera_suite/screenshots/camera_preview.png new file mode 100644 index 0000000000000000000000000000000000000000..5f66ec42c833d6464c028af3aa5be312a7bc09a0 GIT binary patch literal 3342 zcmZ8kYgkh07T$KzEVG!#X|Ri>W6p`p)Ja2AE48vF?Izwrvr#l*w7g)bh||SPGb@HV zD#D~wQz_VJNQjq8dlKU^F51dg3*&Tf9Z&$plb?EQW3UTeMYTKmHO z;9ZLs+AahDU~$myfP(-qXZF$zSnz(?qmI}#yI7vs9gzkA*6r_MMnPDw0066pK>^zj zpQ0-J4_x}@4h;BXBI(i_jc%zgUG#&l%CYE0p^eqNc{VB{15+Qg-n-g=-qM-BEM_+Y zfU#oZN$%VOM!kw;G_{&$KvJ&046Tj){e=-hKiSKZrUaBX3Rj8Titg%fhlvl@3@r1Jo={}7)t+nHq-5Mh04V(8Bc|_0 zZeyojcLFaaba*ESi!tG38o_$qw88F*&Tu?F+oF5UoTDo~9Z-9B{&(d?xX_N@NL{oG zAU#&bxt++S#WqOM`KlrquR6~MIEGT{~ zO<#8cF}-Tj9N^nMzz2-zBDZlz&ajh*4#tS&16OsN_$hQ#o!>1vMb*vJT_i(k_jy=c zCI~X}TjDzoB@DMQvg1!BBT(uoL^LnHb+mVe4CT^~%;W2(DR?}?V7iqv%$RxOIiz*Z ziK&dQ=FpX83zE#tmhSk(f)}|BE;N7XX#Z5ZPqU1%+z;&3cKEC0J(gE@(1qVc)^yv9#Q)y7dXjtQ8bf6V+Nx;YD(>E-J$8>A@g8t;e=olX_H#T zz;T3RP9IvoK2m0$%lEAw&N>2f&MiEj1tuj&f9Iw(t#@<(%`AvgG#Fvz3vnTKNex6YnJb(qYt`e=M zhFA=do|l)!iPUBj^9VtKLYG+)Y08lFa;LOgVp&+Fl#bJzXMx(dDeq<5o!0;ju#Yd= zmd)+BhtKXsXv`dv8UCV%{OP!jxnVTJpvo}~T_K(^cBVZWgS+!>ilO34lKAG4Ibf7F zDL!1`Q=XaJ+>(p*w?olLh)V0wbiG(DgHPUS>VT$TR_ymvrDWuv6l^4n)t$Y5(7&D& zdOiVs)z;aJuZZ_aC7QF1JK+#LOeh8gZt~YzS-SQsMX@m`+RL$kVqMh0_^_+@McV*Ed9FG)fGYC%ih{#r~J$&FsCZ^Wf7L1dhF>lkaU zo-xk4(BHz#xc}9DMAU$@e{$x~5%I7)kleGUaI}p{Uv)gKokv^?+gxQ&r7kJD7Avg! zOi(OjUSd7+5t`GzK&7D-XxCOdH3~z|^3x)JEQd@;JC)2$n2k>GF=pC_WI8ItO^xZD%R=WqRRFsA( zO-WZ8$r=ln(U^!U3_s{W23tVI&$NDL+t;2Hyow6%F^1t zm3LCxJ2%%?Y7?3sLrd%i5pckOgF@Nj5Lq8;TCCaQdlHO3yTD0bf6z%jXgsqVd@NcR zVagp7V~o+z0R2+|-6rjSQyyD~d2vpn6wWAk{NH+;dz|(C)xGyl8lk@M}G5JBr!b zBV)_pG4DvS#)A%c7Cn~a-(LE#wjehI+SV2#m;Ay)w6@lH5QcI<%4Bvl&w*48(j~mI z9paHQfhOEpzUU8V1iwrJ>cQF?am?GcjbgPi^;Ro*o{UvyA_=$B+mAdc5^Z&dTHIr- zS@8@G8)l%3vC((1KRd@na8lrtNpZPGhLuzh0heJap@Oz)c~5A`mSf+X|N6jhiSf;8 z`P9_SFjZXsv>rk9j=&~1tWudu(4x=GyDAOvaiLkRbPd_Bd)Eak)wIIoq5J{QsNy>? zuBe)$CCv-;HN2tKf<*JN+nN z2GIo*bbiS$`bnQuX@T^3zBVpEmTLwucv0#O&+clhz)k^fi|=hOE9saCDBtcx1d9y z^fI|Oj+!=HYx zuOyP4eY*BQ|F9MC_nf(pZrP-$d5+fF>clj%f}8D^?RMQua(;KuoXi=;t2bmKdSxWAA z^iTHGYz-KH^?f_-Dq0@W@x1l3xLro(k+IpCJy%i~_v%eiJnJn90K5K}q#)DtG*G+DFQ!G1cY zuJ_Q{l<5uZ!}_Mr=B1=W>(_(EJe169$8*E+Kx)Wk1}!(hd!}P-tNZv*t!@y9SwHjr z>)s+(z8iJI_T=h!8{w%2_CPgSnQ%y{xir-)!a|vj6M&f>CiN}PeQu@Pa_|z^Y^;e^ jk>*1T`G3D4K+GVif8!4SwB3hk?{5SJ1_v;A96kMCO?d&z literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/guide.png b/applications/external/camera_suite/screenshots/guide.png new file mode 100644 index 0000000000000000000000000000000000000000..87ed51218cb4f7b5cd39414798c3fa0335e10d28 GIT binary patch literal 2233 zcmaJ@dr*^C7QYc`kq)t|18tPZ&a%E&D>BG4fUf1yvC&!-kf?0al0r-nD9;dxEw+n7 z5Tzg$5?ERD077d>Qh5YBl#o_14v?e}61R#56CSJZB@pd2Dq&(A3RIk<6PF9jY-S`0Q>XGhxv9Vb|V08 z)YyajSc%}VXTxfJmYkIHuc}K!ftz9` z5r@N$n(r?oTnB3INl&Fwsx|hwo?J~1AX>G&T)G54nx$MY1dFbkkz zllvB)ApWg>_e=@K?d0pe%z(W_!jSaQ$L3J|;z=?42TE}Y>Jrplsj%bnIr-+8Nk<8J0tcnbbjLdqu|MKS3Qlm13@6RuoC!uV@z%cM z)if^8gPBI$Ua!o{P6xI@bDXb@j7n_?+ve zrdWm8j{P4ckk{<)waJ>0 ztuu+IcswpcQzGD8_cZ2CBox%i-#|_F#6ib;OC!_*ZFq(I6|R3!pE5YJNRT-={&z^+ z4vx#!M?W*Fhs)}GjWs*80~DzCN4%UOoQ;5Z6`XYN4Q8}y@vC9&KZ}R*Z)NElw;~(k z;7hGk%(NoU@6sX2&5c1!%a0Xu$~Cc^s@d0UzE&}x)J&s_KIzLXZ=W8O9Ukngvy7Ky+WNNMGbDwEEXaZD$*P-MnkDJNCmZ-nTL73^xzb6gtk z-zD2_r$gzMAl|p>5Bn51ixq`n3T`%oSaY#QC@OVq7qh!5p`Ca}MVf=e6#86lqwwMS z)3#(BvgXeHRYX|_mG5iwV5Hp$K+r`-OKZP@UFAiK-nryayQBkOEp|R^~OjhZb zC@6a8m}N?bCC{(v3DCf!E;S2?6<+bzBl{tZNynwXxq882$_XP z;Zm3>lwY*dJUCIEA@n?35cx|U`%klHCS(su%a1#{xljb%j^)ZWA-SGFi{?apE@?Fc z5}utT(3*9)QMpfLB%DnHmw^EV2R7TS@UA4A6%>M^lpj_wuH3apo5u8YA zJ$96)+t8ELedAYUf`R^!wM(oxI$PJ18l17KKCM_fc4{!>^v=)1PYhCctL|x|j)fYC`osW0^i-6eo Li3ddolE3^P)2XN* literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/main_menu.png b/applications/external/camera_suite/screenshots/main_menu.png new file mode 100644 index 0000000000000000000000000000000000000000..3ae802cc2d31175779a3914ea594a0390fe8809e GIT binary patch literal 1499 zcmeAS@N?(olHy`uVBq!ia0y~yU;;8388|?c*QZDWAjMhW5n0T@z;^_M8K-LVNi#68 z_IkQFhE&XXdpEFeikCz~;O#R-G4s0%YS$hAacik2JIk)d_j9(-{-SW$_nCL#-@}iu z_vgnm?3lj(etq4)nc{QU8Pru67y_9X1ipU!Bk%oAlJP@a_1n8qj0`TE3=UHm7+h@c z)iN>s*?+UH!IFVt84H7g7X!m0e3YHt{}WZ-^Fm{*zc*wv&FK||m;*HKN?tX?`R_ZX z-#H!k`=@r1Z-en>CWa0nh6W8rh7PL~zJ%_*`}FsJvz?j#W8S}M_p{69?6s@kmR;BO zKfa(e4B|{xAhrB9bH%nN|K7j(_x0BNyPw|6<-UDyy7}q%s_Ulri{>5JABk}N+$#PA z?(a?U=S|zQHzF+C^;YhH=zQkluiqJCKF(Qqh70bktnIc9y5|?nkNjQpbML(D{nPiZ zJ9+Ezo=e*6f6iRb95WHgH;?bCe^|b{UR>_M)NOC}B3TLzIamPJyq9|r^{wjOEF`@j z>=@2Ru)o-Va1t~aD5R?X{Q8*ty}9o1zt5M?%lv)6&i3E5`K&vXv>|~EG<`+?UcN2g z4&G3F#`@Yotgwyj_4oJ>mW=K$grlU)?4L8fbt$)<@oF{>gp`j6&hCp$Ddmd|v z>%PbQF%yC5hz*$FKrz{`{4QJn=e|F;zO(6Do{M|W9PxYeH?{`tO^9%@O5tZ{_-w$= zaKHg#_bEAGf0WN@5uLGjp0Z!vWcCcpcoj+5*(16eUq7?14;VU+qnlA=1fL1gQhVu dhzze|{_==S09OD2 literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/settings.png b/applications/external/camera_suite/screenshots/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..32de46d72a82b836a5cb4da71a8b5dee4f9166f3 GIT binary patch literal 1900 zcmaJ?eN<9s7=MZKYcpIso*DVkvK>8oI$2F;8feYUkENChMfs7_tb;XI9GyW1xm>mU z*m9H=qNbH8*;y?6Km%fnEa6%b99y84#gqiU@Tv&zvT$8@I{V|E_rCA@+~?!>Jip&P zz9}x!*$M9i0C0|uibw!p9`cF-4%Q`Rgc5)(j^9R6XaFqy-TGkI{tK4?VDA|nu|6rE zGpJr)`Xb0>K}UXvv~6<#G0sY@<247DiU38;*}5bJGbhmP=FV-+)8g|d=w`FlAjAwM z3oR2mAydfI&fLxj0MFt9II;+Unp7nKtIuHGZ03XT`l|waAlfzsz-|Y?+B6R={e_6E zS%@ie>x%&{FBoZVj{(@=h}?ZO1vI+Y$Si_k^WMfnf2ndbnGLy`&gQnJO}2`K z?KU&SmEt!di*I~MG42i&ACi+|Lz`snw>5?-&CP_ORXUW*m*ew7Oxt_-LS|Tq{JtCA zl9$Pegc#$u{HhvL25#|}3&;6%Vg|c}cYx<630-5$6aWX(H_koksFFQOP4KRnyt-G! zgwtM^SCE6ZIC7I<1LXw%5x?|$tw4z#!+;K#H&xX?&IbI~sh{;N_M7%RSVUo%!}>Yy zkL*FXqqTm-tLv|JLkjwH{UYj}$hW@kQcV+XI&e@4rdP`T^31{9sfPNOQt{QE*(qfu3GeslJG94XPv7 z<{s@t<#f@Aaeq>gMX|i7o*F5a0S!e0IRQm#Dpfk zyE>{TTBv#Js`z?|I1q(iy{eo_I~4Cc6pd<$p9&#NGAf#)7THYH{ZCt8FPJ|RPJpRF zNV~0Fw6aKs5095Quo$v|?$xN{f9ME#XbfABkdd<#w2jBRx70SmVa9kvoB$S?*7hG5 z^fna;y_kImIyK(JlH`Z}M2WYww|udU&4{bB&34twmeNrPo1FZRPn3kFzQ-2oP*b8f zNo09?3yTbs>ftVF`#_4@q-?~AK)`rwohLL=X>uxRCagT*(dk9>vHMfv9}6~TU5PJN zEb~|Rcd6Lfd)Q%(Pn6iXz5xRx3)D>)^U_7f`dV2Ul0b|D|qN&ta(4&<%v4hIa5Zu7{(zk+S<@Rg? z(%5i=T~8;EAVo)@g|RN_cj81oC{h^{VEg>$TGP67Z=?8T&n1>ZH4`?URf*O~WGXhG zl-5c`+$GeM#OkoY4XaArwY-bXxg){5q%B`_2pJW*-1Jl2?B2il1Eb89s4PggaXZK* zIk|f`uQ>TZsPg&~J$xSJjh%{(>gfEiBQcDWp*{iY%4yf+z3{z1UVv%`o0#~u+67#b z-e+f(&@#)aowSDym-jJq`bHrbJ@be-3KSM{cj9`&*y5H;<}dYwVjq;`G>qZH3%T2d zc;>=-2}1?ZMQA~ywjrt*k^*_cjb(hsU@koD^XG7D==Rgy!-2%(L;&zMi8Usi!{!H} q{64_Xm9m$I{(~2S?HsYRU@Cmq(bqmZDnx#tAo`2Ah^7rY3jYS@P22$h literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/start_screen.png b/applications/external/camera_suite/screenshots/start_screen.png new file mode 100644 index 0000000000000000000000000000000000000000..6fe690c58414675c4fff5ef8552d1619c1ad7442 GIT binary patch literal 1707 zcmd5-ZA@EL7(N9Y4h81o7aNo%lW4+1hD2aMDJXJ*Et{V})iTD%uCWM=YT9z4m(4^s zMrjtNp#&~E{j<>yVnx289j4$YTuH{Q4B9#n3M=-)@DA5P>#ZzuuRr~xKW?6LbIy6+ z=Y5~&&AIT}aVRigUjP6gFf$|V4FG)TB?mm}g{*sm!!+zJ&k%?K2>QYMaXya>+7G}k zVP;zDThiv=%&Dcbu^?sg_UM_4!O$DFFjW}gB^?B4}EZ3mo{9VDcZ?{g}dCN2(DugUzi)Oxk5Z){;q?f$x zP?W&umaGvaf;D6`;WPlR`+z+WG~5SK9Zvb(O9N-05^YJOj`@yO$crTy z+3!_@;P2+#jyClmf9o24cd7RQHc%^Ba||_{DA=_fj*eO!{EI>(cZ`S4KIkilCO+=s zU5FWQaSaWPY^p>8skXWJQw`Yu^>18GC}|mX)*Au1;s*|7(NGnxQy44LH?hL{*)sW* z_*cl%=hQY)!ohd5>rhJT-sqR(h+yRL?c?;Vn_ODTkbfcPUkX$~LuL1;CP^h#z1P!7 zsfJYyGAo><*;=YtM4$;yRozO6?hvbo@g=y`zhwHI$Z#2n&8w41F65EV8AV4bqcA;_ zpl-OO$1q@PLyW|ZnQCOkuqu}@ABACjweEdu+Zr2A=XoVf{<6;s$q zt!qK#ifhJMJ4fr1PP&(njjHGMD*G}-TG6l>m8qf&SFAI zI^v-*XjmX=85m8V74Z$L=5DoVcwg~GLcOIL_u;j4y>2y*5}iLMR_%(}cBV;xE{v2!x(A{VPy5Tel(`2{<rJ}h= zgZML1|M0W#zsL>%k%6f2lf1P%y=4KiuG7! z#XFu^5TqOvf7DW0By<_Y`ZpOSoA%8gC2l(>k@cMR$+9r9s2MTDR45L%ceU!-^CLZa zP-I8ywXhi_EIQ1Ty8%DKGD$xV_c`Zb&-yFrj<@;iE>Oc~=WG(-ww{@u^ohqLr*~*l or@|U?99PkQuxC4-{YS-R{fMTn1YbTuzdj)I)#GW`U(P@GC%ZCr_5c6? literal 0 HcmV?d00001 From 0f9c6ba847f6550709bc4f75ad10222946950881 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 29 Jul 2023 03:51:46 +0300 Subject: [PATCH 5/7] Remake it more properly still has problems, need to rewrite subghz_devices tx/rx switch code, checking strcmp every time is not good too, but better than loading whole config from microsd --- .../scenes/subghz_scene_radio_settings.c | 14 +++-- .../main/subghz/subghz_dangerous_freq.c | 13 ++++ .../main/subghz/subghz_last_settings.c | 34 +++++----- firmware/targets/f7/api_symbols.csv | 2 + .../targets/f7/furi_hal/furi_hal_subghz.c | 11 +++- .../targets/f7/furi_hal/furi_hal_subghz.h | 5 ++ lib/subghz/devices/devices.c | 63 +++++++++---------- 7 files changed, 87 insertions(+), 55 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 598d6fdce..2ff2f565f 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -124,6 +124,10 @@ static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem } subghz->last_settings->external_module_power_amp = index == 1; + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp); + subghz_last_settings_save(subghz->last_settings); } @@ -159,9 +163,9 @@ void subghz_scene_radio_settings_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, radio_device_text[value_index]); - item = variable_item_list_add( + item = variable_item_list_add( variable_item_list, - "Ext High Power", + "Ext Power Amp", EXT_MOD_POWER_AMP_COUNT, subghz_scene_reciever_config_set_ext_mod_power_amp_text, subghz); @@ -171,7 +175,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { item = variable_item_list_add( variable_item_list, - "Time in names", + "Time In Names", TIMESTAMP_NAMES_COUNT, subghz_scene_receiver_config_set_timestamp_file_names, subghz); @@ -182,7 +186,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { item = variable_item_list_add( variable_item_list, - "Counter incr.", + "Counter Incr.", DEBUG_COUNTER_COUNT, subghz_scene_receiver_config_set_debug_counter, subghz); @@ -211,7 +215,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { } else { item = variable_item_list_add( variable_item_list, - "Counter incr.", + "Counter Incr.", 3, subghz_scene_receiver_config_set_debug_counter, subghz); diff --git a/applications/main/subghz/subghz_dangerous_freq.c b/applications/main/subghz/subghz_dangerous_freq.c index 69a54f04b..8552c5f16 100644 --- a/applications/main/subghz/subghz_dangerous_freq.c +++ b/applications/main/subghz/subghz_dangerous_freq.c @@ -5,6 +5,8 @@ #include +#include + void subghz_dangerous_freq() { bool is_extended_i = false; @@ -19,5 +21,16 @@ void subghz_dangerous_freq() { furi_hal_subghz_set_dangerous_frequency(is_extended_i); flipper_format_free(fff_data_file); + + // Load external module power amp setting (TODO: move to other place) + // TODO: Disable this when external module is not CC1101 E07 + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(last_settings->external_module_power_amp); + + subghz_last_settings_free(last_settings); + furi_record_close(RECORD_STORAGE); } diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 5f67fc780..465312b19 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -19,8 +19,8 @@ #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" -#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" +#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -47,7 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count float temp_frequency_analyzer_trigger = 0; bool temp_external_module_enabled = false; bool temp_external_module_power_5v_disable = false; - bool temp_external_module_power_amp = false; + bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; @@ -79,17 +79,17 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER, (bool*)&temp_external_module_power_5v_disable, - 1); - flipper_format_read_bool( - fff_data_file, - SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, - (bool*)&temp_external_module_power_amp, 1); flipper_format_read_bool( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, (bool*)&temp_timestamp_file_names, 1); + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + (bool*)&temp_external_module_power_amp, + 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); @@ -103,8 +103,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; - instance->external_module_power_amp = false; instance->timestamp_file_names = false; + instance->external_module_power_amp = false; } else { instance->frequency = temp_frequency; @@ -126,9 +126,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; instance->timestamp_file_names = temp_timestamp_file_names; - + + // External power amp CC1101 instance->external_module_power_amp = temp_external_module_power_amp; - + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); + /*/} else { instance->preset = temp_preset; }*/ @@ -199,17 +203,17 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { 1)) { break; } - if(!flipper_format_insert_or_update_bool( + if(!flipper_format_insert_or_update_bool( file, - SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, - &instance->external_module_power_amp, + SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, + &instance->timestamp_file_names, 1)) { break; } if(!flipper_format_insert_or_update_bool( file, - SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, - &instance->timestamp_file_names, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + &instance->external_module_power_amp, 1)) { break; } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 81cae4013..a6807e131 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1401,6 +1401,7 @@ Function,-,furi_hal_subghz_dump_state,void, Function,+,furi_hal_subghz_flush_rx,void, Function,+,furi_hal_subghz_flush_tx,void, Function,+,furi_hal_subghz_get_data_gpio,const GpioPin*, +Function,+,furi_hal_subghz_get_ext_power_amp,_Bool, Function,+,furi_hal_subghz_get_lqi,uint8_t, Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t, Function,+,furi_hal_subghz_get_rssi,float, @@ -1418,6 +1419,7 @@ Function,+,furi_hal_subghz_reset,void, Function,+,furi_hal_subghz_rx,void, Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool, Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin* +Function,+,furi_hal_subghz_set_ext_power_amp,void,_Bool Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 936d685fe..b651fc59f 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -53,7 +53,7 @@ typedef struct { const GpioPin* async_mirror_pin; uint8_t rolling_counter_mult; - bool timestamp_file_names : 1; + bool ext_power_amp : 1; bool dangerous_frequency_i : 1; } FuriHalSubGhz; @@ -62,6 +62,7 @@ volatile FuriHalSubGhz furi_hal_subghz = { .regulation = SubGhzRegulationTxRx, .async_mirror_pin = NULL, .rolling_counter_mult = 1, + .ext_power_amp = false, .dangerous_frequency_i = false, }; @@ -77,6 +78,14 @@ void furi_hal_subghz_set_dangerous_frequency(bool state_i) { furi_hal_subghz.dangerous_frequency_i = state_i; } +void furi_hal_subghz_set_ext_power_amp(bool enabled) { + furi_hal_subghz.ext_power_amp = enabled; +} + +bool furi_hal_subghz_get_ext_power_amp() { + return furi_hal_subghz.ext_power_amp; +} + void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) { furi_hal_subghz.async_mirror_pin = pin; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.h b/firmware/targets/f7/furi_hal/furi_hal_subghz.h index c7249e1a6..b390ac6cc 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.h +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.h @@ -282,6 +282,11 @@ void furi_hal_subghz_stop_async_tx(); // */ // void furi_hal_subghz_select_radio_type(SubGhzRadioType state); +// External CC1101 Ebytes power amplifier control +void furi_hal_subghz_set_ext_power_amp(bool enabled); + +bool furi_hal_subghz_get_ext_power_amp(); + #ifdef __cplusplus } #endif diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index 525c38323..98cb0f609 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -2,34 +2,14 @@ #include "registry.h" -#include - void subghz_devices_init() { furi_check(!subghz_device_registry_is_valid()); subghz_device_registry_init(); - - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - - if(last_settings->external_module_power_amp) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); - } - - subghz_last_settings_free(last_settings); } void subghz_devices_deinit(void) { furi_check(subghz_device_registry_is_valid()); subghz_device_registry_deinit(); - - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - - if(last_settings->external_module_power_amp) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); - } - - subghz_last_settings_free(last_settings); } const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) { @@ -50,6 +30,13 @@ bool subghz_devices_begin(const SubGhzDevice* device) { bool ret = false; furi_assert(device); if(device->interconnect->begin) { + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } + } + ret = device->interconnect->begin(); } return ret; @@ -58,6 +45,12 @@ bool subghz_devices_begin(const SubGhzDevice* device) { void subghz_devices_end(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->end) { + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + } device->interconnect->end(); } } @@ -89,7 +82,12 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); - furi_hal_gpio_write(&gpio_ext_pc3, 0); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + } } } @@ -143,14 +141,12 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - - if(last_settings->external_module_power_amp) { - furi_hal_gpio_write(&gpio_ext_pc3, 1); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 1); + } } - - subghz_last_settings_free(last_settings); } return ret; } @@ -191,14 +187,13 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - if(last_settings->external_module_power_amp) { - furi_hal_gpio_write(&gpio_ext_pc3, 0); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } } - - subghz_last_settings_free(last_settings); } } From 2c656f9c49ac69a125353e45a8b0110500ea2a9a Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 29 Jul 2023 05:21:58 +0300 Subject: [PATCH 6/7] Update wifi marauder --- .../wifi_marauder_companion/ReadMe.md | 25 +- .../wifi_marauder_companion/application.fam | 18 +- .../wifi_marauder_companion/docs/changelog.md | 7 + .../lib/esp-serial-flasher/LICENSE | 202 --------- .../lib/esp-serial-flasher/README.md | 154 ------- .../esp-serial-flasher/include/esp_loader.h | 313 ------------- .../include/esp_loader_io.h | 112 ----- .../esp-serial-flasher/include/serial_io.h | 24 - .../lib/esp-serial-flasher/port/esp32_port.c | 181 -------- .../lib/esp-serial-flasher/port/esp32_port.h | 59 --- .../esp-serial-flasher/port/esp32_spi_port.c | 298 ------------- .../esp-serial-flasher/port/esp32_spi_port.h | 60 --- .../esp-serial-flasher/port/raspberry_port.c | 302 ------------- .../esp-serial-flasher/port/raspberry_port.h | 36 -- .../lib/esp-serial-flasher/port/stm32_port.c | 140 ------ .../lib/esp-serial-flasher/port/stm32_port.h | 38 -- .../lib/esp-serial-flasher/port/zephyr_port.c | 170 ------- .../lib/esp-serial-flasher/port/zephyr_port.h | 39 -- .../private_include/esp_targets.h | 33 -- .../private_include/md5_hash.h | 28 -- .../private_include/protocol.h | 230 ---------- .../private_include/protocol_prv.h | 31 -- .../esp-serial-flasher/private_include/slip.h | 28 -- .../lib/esp-serial-flasher/src/esp_loader.c | 415 ------------------ .../lib/esp-serial-flasher/src/esp_targets.c | 263 ----------- .../lib/esp-serial-flasher/src/md5_hash.c | 262 ----------- .../esp-serial-flasher/src/protocol_common.c | 301 ------------- .../lib/esp-serial-flasher/src/protocol_spi.c | 312 ------------- .../esp-serial-flasher/src/protocol_uart.c | 114 ----- .../lib/esp-serial-flasher/src/slip.c | 125 ------ .../esp-serial-flasher/zephyr/CMakeLists.txt | 30 -- .../lib/esp-serial-flasher/zephyr/Kconfig | 16 - .../lib/esp-serial-flasher/zephyr/module.yml | 5 - .../scenes/wifi_marauder_scene_config.h | 1 - .../wifi_marauder_scene_console_output.c | 28 +- .../scenes/wifi_marauder_scene_flasher.c | 266 ----------- .../scenes/wifi_marauder_scene_start.c | 38 +- .../scenes/wifi_marauder_scene_text_input.c | 4 +- .../screenshots/marauder-save-pcaps.png | Bin 0 -> 2336 bytes .../screenshots/marauder-script-demo.png | Bin 0 -> 1599 bytes .../screenshots/marauder-topmenu.png | Bin 0 -> 1752 bytes .../wifi_marauder_app.c | 3 - .../wifi_marauder_app.h | 2 +- .../wifi_marauder_app_i.h | 26 +- .../wifi_marauder_custom_event.h | 4 +- .../wifi_marauder_flasher.c | 251 ----------- .../wifi_marauder_flasher.h | 17 - .../wifi_marauder_pcap.c | 64 --- .../wifi_marauder_pcap.h | 20 - 49 files changed, 37 insertions(+), 5058 deletions(-) delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml delete mode 100644 applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c create mode 100755 applications/external/wifi_marauder_companion/screenshots/marauder-save-pcaps.png create mode 100755 applications/external/wifi_marauder_companion/screenshots/marauder-script-demo.png create mode 100755 applications/external/wifi_marauder_companion/screenshots/marauder-topmenu.png delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_flasher.c delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_flasher.h delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_pcap.c delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_pcap.h diff --git a/applications/external/wifi_marauder_companion/ReadMe.md b/applications/external/wifi_marauder_companion/ReadMe.md index bc14e0f8c..00de70424 100644 --- a/applications/external/wifi_marauder_companion/ReadMe.md +++ b/applications/external/wifi_marauder_companion/ReadMe.md @@ -1,8 +1,10 @@ +[![FAP Build](https://github.com/0xchocolate/flipperzero-wifi-marauder/actions/workflows/build.yml/badge.svg)](https://github.com/0xchocolate/flipperzero-wifi-marauder/actions/workflows/build.yml) + # WiFi Marauder companion app for Flipper Zero Requires a connected dev board running Marauder FW. [See install instructions from UberGuidoZ here.](https://github.com/UberGuidoZ/Flipper/tree/main/Wifi_DevBoard#marauder-install-information) -## https://github.com/0xchocolate/flipperzero-wifi-marauder + ## Get the app 1. Make sure you're logged in with a github account (otherwise the downloads in step 2 won't work) @@ -15,27 +17,8 @@ Requires a connected dev board running Marauder FW. [See install instructions fr From a local clone of this repo, you can also build the app yourself using ufbt. -## In-app ESP32 flasher (WIP) -Guide by [@francis2054](https://github.com/francis2054) +### FYI - the ESP flasher is now its own app: https://github.com/0xchocolate/flipperzero-esp-flasher -The app now contains a work-in-progress of an ESP32 flasher (close to the bottom of the marauder menu). Use at your own risk. This hardcodes addresses for non-S3 ESP32 chips. - -To use this method: -1. Make sure you follow the instructions for how to get the Marauder app on your Flipper Zero, they can be found on the top of this page. Latest release needs to be downloaded and installed. -2. Go to [Justcallmekoko's firmware page](https://github.com/justcallmekoko/ESP32Marauder/wiki/update-firmware#using-spacehuhn-web-updater) and download all files necessary for the board you are flashing, most boards will want all 4 files but for the Wifi Devboard you want to download these 3 files: `0x1000` (Bootloader), `0x8000` (partitions), `0x10000` (Firmware). The `Boot App` is not needed for the Wifi Devboard with this method. The Firmware one will redirect you to the releases page where you'll need to pick the one relevant to the board you're flashing, if you are using the official Wi-Fi Devboard you want to pick the one ending in `_flipper_sd_serial.bin`. -3. Place all files downloaded in step 2 in a new folder on your desktop, the name does not matter. Rename the `_flipper_sd_serial.bin` file you downloaded in step 2 to `Firmware.bin`. -4. Now for transferring the files to the Flipper Zero, drag all the files from the folder on your desktop to the "Marauder" folder inside "apps_data" folder on the Flipper Zero SD card. Preferred method to transfer these files is plugging the SD card into your computer with an adapter, but qFlipper works as well. Insert the Flipper Zero SD Card back into the Flipper before proceeding to the next step. -5. Plug your Wi-Fi Devboard into the Flipper. -6. Press and keep holding the boot button while you press the reset button once, release the boot button after 2 seconds. -7. Open the Marauder app on your Flipper Zero, it should be named "esp32_wifi_marauder" and be located under Apps->GPIO from the main menu if you followed the instructions for how to install the app further up on this page. (You might get an API mismatch error if the Flipper firmware you are running doesn't match the files you've downloaded, you can try "Continue" anyway, otherwise the app needs to be rebuilt or you might need to update the firmware on your Flipper). -8. Press the up arrow on the Flipper three times to get to "Reflash ESP32 (WIP)" and open it. -9. For "Bootloader" scroll down in the list and select `esp32_marauder.ino.bootloader.bin`, for "Paritition table" select `esp32_marauder.ino.partitions.bin` and for "Firmware" select `Firmware.bin`. -10. Scroll down and click "[>] FLASH" and wait for it to complete. (If you get errors here, press back button once and repeat step 6 then try "[>] FLASH" again). -11. Once it says "Done flashing" on the screen, restart the Flipper and you are done :) - -## For future updates, just repeat from step 2 and only download the new "Firmware" bin - -This process will improve with future updates! :) ## Support diff --git a/applications/external/wifi_marauder_companion/application.fam b/applications/external/wifi_marauder_companion/application.fam index 6b3403f39..ee4578efc 100644 --- a/applications/external/wifi_marauder_companion/application.fam +++ b/applications/external/wifi_marauder_companion/application.fam @@ -1,6 +1,7 @@ App( appid="esp32_wifi_marauder", name="[ESP32] WiFi Marauder", + fap_version=(6,0), apptype=FlipperAppType.EXTERNAL, entry_point="wifi_marauder_app", requires=["gui"], @@ -8,22 +9,5 @@ App( order=90, fap_icon="wifi_10px.png", fap_category="GPIO", - fap_private_libs=[ - Lib( - name="esp-serial-flasher", - fap_include_paths=["include"], - sources=[ - "src/esp_loader.c", - "src/esp_targets.c", - "src/md5_hash.c", - "src/protocol_common.c", - "src/protocol_uart.c", - "src/slip.c" - ], - cincludes=["lib/esp-serial-flasher/private_include"], - cdefines=["SERIAL_FLASHER_INTERFACE_UART=1", "MD5_ENABLED=1"], - ), - ], - cdefines=["SERIAL_FLASHER_INTERFACE_UART=1"], fap_icon_assets="assets", ) diff --git a/applications/external/wifi_marauder_companion/docs/changelog.md b/applications/external/wifi_marauder_companion/docs/changelog.md index ae0f328e7..207478f71 100644 --- a/applications/external/wifi_marauder_companion/docs/changelog.md +++ b/applications/external/wifi_marauder_companion/docs/changelog.md @@ -1,3 +1,10 @@ +## v0.6.0 + +Evil Portal and LED control! Thanks @justcallmekoko for adding the commands! See Evil Portal workflow here: https://github.com/justcallmekoko/ESP32Marauder/wiki/evil-portal-workflow + +This version also removes the in-app ESP flasher, but don't worry! It's grown up into its own app, where development will continue separately: https://github.com/0xchocolate/flipperzero-esp-flasher + + ## v0.4.0 Added Signal Monitor (thanks @justcallmekoko!) to support new sigmon command in Marauder v0.10.5: https://github.com/justcallmekoko/ESP32Marauder/releases diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE deleted file mode 100644 index d64569567..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md deleted file mode 100644 index b1ae448d7..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md +++ /dev/null @@ -1,154 +0,0 @@ -# esp-serial-flasher - -`esp-serial-flasher` is a portable C library for flashing or loading apps to RAM of Espressif SoCs from other host microcontrollers. - -## Using the library -Espressif SoCs are normally programmed via serial interface (UART). The port layer for the given host microcontroller has to be implemented if not available. Details can be found in section below. - -Supported **host** microcontrollers: - -- STM32 -- Raspberry Pi SBC -- ESP32 -- Any MCU running Zephyr OS - -Supported **target** microcontrollers: - -- ESP32 -- ESP8266 -- ESP32-S2 -- ESP32-S3 -- ESP32-C3 -- ESP32-C2 -- ESP32-H2 - -Supported hardware interfaces: -- UART -- SPI (only for RAM download, experimental) - -For example usage check the `examples` directory. - -## Supporting a new host target - -In order to support a new target, following functions have to be implemented by user: - -- `loader_port_read()` -- `loader_port_write()` -- `loader_port_enter_bootloader()` -- `loader_port_delay_ms()` -- `loader_port_start_timer()` -- `loader_port_remaining_time()` - -For the SPI interface ports -- `loader_port_spi_set_cs()` -needs to be implemented as well. - -The following functions are part of the [io.h](include/io.h) header for convenience, however, the user does not have to strictly follow function signatures, as there are not called directly from library. - -- `loader_port_change_transmission_rate()` -- `loader_port_reset_target()` -- `loader_port_debug_print()` - -Prototypes of all functions mentioned above can be found in [io.h](include/io.h). - -## Configuration - -These are the configuration toggles available to the user: - -* `SERIAL_FLASHER_INTERFACE_UART/SERIAL_FLASHER_INTERFACE_SPI` - -This defines the hardware interface to use. SPI interface only supports RAM download mode and is in experimental stage and can undergo changes. - -Default: SERIAL_FLASHER_INTERFACE_UART - -* `MD5_ENABLED` - -If enabled, `esp-serial-flasher` is capable of verifying flash integrity after writing to flash. - -Default: Enabled -> Warning: As ROM bootloader of the ESP8266 does not support MD5_CHECK, this option has to be disabled! - -* `SERIAL_FLASHER_RESET_HOLD_TIME_MS` - -This is the time for which the reset pin is asserted when doing a hard reset in milliseconds. - -Default: 100 - -* `SERIAL_FLASHER_BOOT_HOLD_TIME_MS` - -This is the time for which the boot pin is asserted when doing a hard reset in milliseconds. - -Default: 50 - -Configuration can be passed to `cmake` via command line: - -``` -cmake -DMD5_ENABLED=1 .. && cmake --build . -``` - -### STM32 support - -The STM32 port makes use of STM32 HAL libraries, and these do not come with CMake support. In order to compile the project, `stm32-cmake` (a `CMake` support package) has to be pulled as submodule. - -``` -git clone --recursive https://github.com/espressif/esp-serial-flasher.git -``` - -If you have cloned this repository without the `--recursive` flag, you can initialize the submodule using the following command: - -``` -git submodule update --init -``` - -In addition to configuration parameters mentioned above, following definitions has to be set: - -- TOOLCHAIN_PREFIX: path to arm toolchain (i.e /home/user/gcc-arm-none-eabi-9-2019-q4-major) -- STM32Cube_DIR: path to STM32 Cube libraries (i.e /home/user/STM32Cube/Repository/STM32Cube_FW_F4_V1.25.0) -- STM32_CHIP: name of STM32 for which project should be compiled (i.e STM32F407VG) -- PORT: STM32 - -This can be achieved by passing definitions to the command line, such as: - -``` -cmake -DTOOLCHAIN_PREFIX="/path_to_toolchain" -DSTM32Cube_DIR="path_to_stm32Cube" -DSTM32_CHIP="STM32F407VG" -DPORT="STM32" .. && cmake --build . -``` - -Alternatively, those variables can be set in the top level `cmake` directory: - -``` -set(TOOLCHAIN_PREFIX path_to_toolchain) -set(STM32Cube_DIR path_to_stm32_HAL) -set(STM32_CHIP STM32F407VG) -set(PORT STM32) -``` - -### Zephyr support - -The Zephyr port is ready to be integrated into Zephyr apps as a Zephyr module. In the manifest file (west.yml), add: - -``` - - name: esp-flasher - url: https://github.com/espressif/esp-serial-flasher - revision: master - path: modules/lib/esp_flasher -``` - -And add - -``` -CONFIG_ESP_SERIAL_FLASHER=y -CONFIG_CONSOLE_GETCHAR=y -CONFIG_SERIAL_FLASHER_MD5_ENABLED=y -``` - -to the project configuration `prj.conf`. - -For the C/C++ source code, the example code provided in `examples/zephyr_example` can be used as a starting point. - -## Licence - -Code is distributed under Apache 2.0 license. - -## Known limitations - -Size of new binary image has to be known before flashing. diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h deleted file mode 100644 index 43f4fb9d9..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h +++ /dev/null @@ -1,313 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Used for backwards compatibility with the previous API */ -#define esp_loader_change_baudrate esp_loader_change_transmission_rate - -/** - * Macro which can be used to check the error code, - * and return in case the code is not ESP_LOADER_SUCCESS. - */ -#define RETURN_ON_ERROR(x) do { \ - esp_loader_error_t _err_ = (x); \ - if (_err_ != ESP_LOADER_SUCCESS) { \ - return _err_; \ - } \ -} while(0) - -/** - * @brief Error codes - */ -typedef enum { - ESP_LOADER_SUCCESS, /*!< Success */ - ESP_LOADER_ERROR_FAIL, /*!< Unspecified error */ - ESP_LOADER_ERROR_TIMEOUT, /*!< Timeout elapsed */ - ESP_LOADER_ERROR_IMAGE_SIZE, /*!< Image size to flash is larger than flash size */ - ESP_LOADER_ERROR_INVALID_MD5, /*!< Computed and received MD5 does not match */ - ESP_LOADER_ERROR_INVALID_PARAM, /*!< Invalid parameter passed to function */ - ESP_LOADER_ERROR_INVALID_TARGET, /*!< Connected target is invalid */ - ESP_LOADER_ERROR_UNSUPPORTED_CHIP, /*!< Attached chip is not supported */ - ESP_LOADER_ERROR_UNSUPPORTED_FUNC, /*!< Function is not supported on attached target */ - ESP_LOADER_ERROR_INVALID_RESPONSE /*!< Internal error */ -} esp_loader_error_t; - -/** - * @brief Supported targets - */ -typedef enum { - ESP8266_CHIP = 0, - ESP32_CHIP = 1, - ESP32S2_CHIP = 2, - ESP32C3_CHIP = 3, - ESP32S3_CHIP = 4, - ESP32C2_CHIP = 5, - ESP32H4_CHIP = 6, - ESP32H2_CHIP = 7, - ESP_MAX_CHIP = 8, - ESP_UNKNOWN_CHIP = 8 -} target_chip_t; - -/** - * @brief Application binary header - */ -typedef struct { - uint8_t magic; - uint8_t segments; - uint8_t flash_mode; - uint8_t flash_size_freq; - uint32_t entrypoint; -} esp_loader_bin_header_t; - -/** - * @brief Segment binary header - */ -typedef struct { - uint32_t addr; - uint32_t size; - uint8_t *data; -} esp_loader_bin_segment_t; - -/** - * @brief SPI pin configuration arguments - */ -typedef union { - struct { - uint32_t pin_clk: 6; - uint32_t pin_q: 6; - uint32_t pin_d: 6; - uint32_t pin_cs: 6; - uint32_t pin_hd: 6; - uint32_t zero: 2; - }; - uint32_t val; -} esp_loader_spi_config_t; - -/** - * @brief Connection arguments - */ -typedef struct { - uint32_t sync_timeout; /*!< Maximum time to wait for response from serial interface. */ - int32_t trials; /*!< Number of trials to connect to target. If greater than 1, - 100 millisecond delay is inserted after each try. */ -} esp_loader_connect_args_t; - -#define ESP_LOADER_CONNECT_DEFAULT() { \ - .sync_timeout = 100, \ - .trials = 10, \ -} - -/** - * @brief Connects to the target - * - * @param connect_args[in] Timing parameters to be used for connecting to target. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args); - -/** - * @brief Returns attached target chip. - * - * @warning This function can only be called after connection with target - * has been successfully established by calling esp_loader_connect(). - * - * @return One of target_chip_t - */ -target_chip_t esp_loader_get_target(void); - - -#ifdef SERIAL_FLASHER_INTERFACE_UART -/** - * @brief Initiates flash operation - * - * @param offset[in] Address from which flash operation will be performed. - * @param image_size[in] Size of the whole binary to be loaded into flash. - * @param block_size[in] Size of buffer used in subsequent calls to esp_loader_flash_write. - * - * @note image_size is size of the whole image, whereas, block_size is chunk of data sent - * to the target, each time esp_loader_flash_write function is called. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size); - -/** - * @brief Writes supplied data to target's flash memory. - * - * @param payload[in] Data to be flashed into target's memory. - * @param size[in] Size of payload in bytes. - * - * @note size must not be greater that block_size supplied to previously called - * esp_loader_flash_start function. If size is less than block_size, - * remaining bytes of payload buffer will be padded with 0xff. - * Therefore, size of payload buffer has to be equal or greater than block_size. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size); - -/** - * @brief Ends flash operation. - * - * @param reboot[in] reboot the target if true. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_flash_finish(bool reboot); -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - - -/** - * @brief Initiates mem operation, initiates loading for program into target RAM - * - * @param offset[in] Address from which mem operation will be performed. - * @param size[in] Size of the whole binary to be loaded into mem. - * @param block_size[in] Size of buffer used in subsequent calls to esp_loader_mem_write. - * - * @note image_size is size of the whole image, whereas, block_size is chunk of data sent - * to the target, each time esp_mem_flash_write function is called. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_mem_start(uint32_t offset, uint32_t size, uint32_t block_size); - - -/** - * @brief Writes supplied data to target's mem memory. - * - * @param payload[in] Data to be loaded into target's memory. - * @param size[in] Size of data in bytes. - * - * @note size must not be greater that block_size supplied to previously called - * esp_loader_mem_start function. - * Therefore, size of data buffer has to be equal or greater than block_size. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size); - - -/** - * @brief Ends mem operation, finish loading for program into target RAM - * and send the entrypoint of ram_loadable app - * - * @param entrypoint[in] entrypoint of ram program. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_mem_finish(uint32_t entrypoint); - - -/** - * @brief Writes register. - * - * @param address[in] Address of register. - * @param reg_value[in] New register value. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_write_register(uint32_t address, uint32_t reg_value); - -/** - * @brief Reads register. - * - * @param address[in] Address of register. - * @param reg_value[out] Register value. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_read_register(uint32_t address, uint32_t *reg_value); - -/** - * @brief Change baud rate. - * - * @note Baud rate has to be also adjusted accordingly on host MCU, as - * target's baud rate is changed upon return from this function. - * - * @param transmission_rate[in] new baud rate to be set. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - * - ESP_LOADER_ERROR_UNSUPPORTED_FUNC Unsupported on the target - */ -esp_loader_error_t esp_loader_change_transmission_rate(uint32_t transmission_rate); - -/** - * @brief Verify target's flash integrity by checking MD5. - * MD5 checksum is computed from data pushed to target's memory by calling - * esp_loader_flash_write() function and compared against target's MD5. - * Target computes checksum based on offset and image_size passed to - * esp_loader_flash_start() function. - * - * @note This function is only available if MD5_ENABLED is set. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_INVALID_MD5 MD5 does not match - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - * - ESP_LOADER_ERROR_UNSUPPORTED_FUNC Unsupported on the target - */ -#if MD5_ENABLED -esp_loader_error_t esp_loader_flash_verify(void); -#endif -/** - * @brief Toggles reset pin. - */ -void esp_loader_reset_target(void); - - - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h deleted file mode 100644 index 2ff99b4f9..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - #pragma once - -#include -#include "esp_loader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Changes the transmission rate of the used peripheral. - */ -esp_loader_error_t loader_port_change_transmission_rate(uint32_t transmission_rate); - -/** - * @brief Writes data over the io interface. - * - * @param data[in] Buffer with data to be written. - * @param size[in] Size of data in bytes. - * @param timeout[in] Timeout in milliseconds. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed - */ -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout); - -/** - * @brief Reads data from the io interface. - * - * @param data[out] Buffer into which received data will be written. - * @param size[in] Number of bytes to read. - * @param timeout[in] Timeout in milliseconds. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed - */ -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout); - -/** - * @brief Delay in milliseconds. - * - * @param ms[in] Number of milliseconds. - * - */ -void loader_port_delay_ms(uint32_t ms); - -/** - * @brief Starts timeout timer. - * - * @param ms[in] Number of milliseconds. - * - */ -void loader_port_start_timer(uint32_t ms); - -/** - * @brief Returns remaining time since timer was started by calling esp_loader_start_timer. - * 0 if timer has elapsed. - * - * @return Number of milliseconds. - * - */ -uint32_t loader_port_remaining_time(void); - -/** - * @brief Asserts bootstrap pins to enter boot mode and toggles reset pin. - * - * @note Reset pin should stay asserted for at least 20 milliseconds. - */ -void loader_port_enter_bootloader(void); - -/** - * @brief Toggles reset pin. - * - * @note Reset pin should stay asserted for at least 20 milliseconds. - */ -void loader_port_reset_target(void); - -/** - * @brief Function can be defined by user to print debug message. - * - * @note Empty weak function is used, otherwise. - * - */ -void loader_port_debug_print(const char *str); - -#ifdef SERIAL_FLASHER_INTERFACE_SPI -/** - * @brief Sets the chip select to a defined level - */ -void loader_port_spi_set_cs(uint32_t level); -#endif /* SERIAL_FLASHER_INTERFACE_SPI */ - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h deleted file mode 100644 index e34939300..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#warning Please replace serial_io.h with esp_loader_io.h and change the function names \ - to match the new API - -/* Defines used to avoid breaking existing ports */ -#define loader_port_change_baudrate loader_port_change_transmission_rate -#define loader_port_serial_write loader_port_write -#define loader_port_serial_read loader_port_read - -#include "esp_loader_io.h" diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c deleted file mode 100644 index a6c8687c6..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp32_port.h" -#include "driver/uart.h" -#include "driver/gpio.h" -#include "esp_timer.h" -#include "esp_log.h" -#include "esp_idf_version.h" -#include - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printf("%02x ", data[i]); - } -} -#endif - -static int64_t s_time_end; -static int32_t s_uart_port; -static int32_t s_reset_trigger_pin; -static int32_t s_gpio0_trigger_pin; - -esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config) -{ - s_uart_port = config->uart_port; - s_reset_trigger_pin = config->reset_trigger_pin; - s_gpio0_trigger_pin = config->gpio0_trigger_pin; - - // Initialize UART - uart_config_t uart_config = { - .baud_rate = config->baud_rate, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) - .source_clk = UART_SCLK_DEFAULT, -#endif - }; - - int rx_buffer_size = config->rx_buffer_size ? config->rx_buffer_size : 400; - int tx_buffer_size = config->tx_buffer_size ? config->tx_buffer_size : 400; - QueueHandle_t *uart_queue = config->uart_queue ? config->uart_queue : NULL; - int queue_size = config->queue_size ? config->queue_size : 0; - - if ( uart_param_config(s_uart_port, &uart_config) != ESP_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - if ( uart_set_pin(s_uart_port, config->uart_tx_pin, config->uart_rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) != ESP_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - if ( uart_driver_install(s_uart_port, rx_buffer_size, tx_buffer_size, queue_size, uart_queue, 0) != ESP_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - - // Initialize boot pin selection pins - gpio_reset_pin(s_reset_trigger_pin); - gpio_set_pull_mode(s_reset_trigger_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_reset_trigger_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_gpio0_trigger_pin); - gpio_set_pull_mode(s_gpio0_trigger_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_gpio0_trigger_pin, GPIO_MODE_OUTPUT); - - return ESP_LOADER_SUCCESS; -} - -void loader_port_esp32_deinit(void) -{ - uart_driver_delete(s_uart_port); -} - - -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout) -{ - uart_write_bytes(s_uart_port, (const char *)data, size); - esp_err_t err = uart_wait_tx_done(s_uart_port, pdMS_TO_TICKS(timeout)); - - if (err == ESP_OK) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, true); -#endif - return ESP_LOADER_SUCCESS; - } else if (err == ESP_ERR_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout) -{ - int read = uart_read_bytes(s_uart_port, data, size, pdMS_TO_TICKS(timeout)); - - if (read < 0) { - return ESP_LOADER_ERROR_FAIL; - } else if (read < size) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, read, false); -#endif - return ESP_LOADER_ERROR_TIMEOUT; - } else { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, read, false); -#endif - return ESP_LOADER_SUCCESS; - } -} - - -// Set GPIO0 LOW, then -// assert reset pin for 50 milliseconds. -void loader_port_enter_bootloader(void) -{ - gpio_set_level(s_gpio0_trigger_pin, 0); - loader_port_reset_target(); - loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpio_set_level(s_gpio0_trigger_pin, 1); -} - - -void loader_port_reset_target(void) -{ - gpio_set_level(s_reset_trigger_pin, 0); - loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpio_set_level(s_reset_trigger_pin, 1); -} - - -void loader_port_delay_ms(uint32_t ms) -{ - usleep(ms * 1000); -} - - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = esp_timer_get_time() + ms * 1000; -} - - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = (s_time_end - esp_timer_get_time()) / 1000; - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s\n", str); -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - esp_err_t err = uart_set_baudrate(s_uart_port, baudrate); - return (err == ESP_OK) ? ESP_LOADER_SUCCESS : ESP_LOADER_ERROR_FAIL; -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h deleted file mode 100644 index c098762d2..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - #pragma once - -#include "esp_loader_io.h" -#include "freertos/FreeRTOS.h" -#include "freertos/queue.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - uint32_t baud_rate; /*!< Initial baud rate, can be changed later */ - uint32_t uart_port; /*!< UART port */ - uint32_t uart_rx_pin; /*!< This pin will be configured as UART Rx pin */ - uint32_t uart_tx_pin; /*!< This pin will be configured as UART Tx pin */ - uint32_t reset_trigger_pin; /*!< This pin will be used to reset target chip */ - uint32_t gpio0_trigger_pin; /*!< This pin will be used to toggle set IO0 of target chip */ - uint32_t rx_buffer_size; /*!< Set to zero for default RX buffer size */ - uint32_t tx_buffer_size; /*!< Set to zero for default TX buffer size */ - uint32_t queue_size; /*!< Set to zero for default UART queue size */ - QueueHandle_t *uart_queue; /*!< Set to NULL, if UART queue handle is not - necessary. Otherwise, it will be assigned here */ -} loader_esp32_config_t; - -/** - * @brief Initializes serial interface. - * - * @param baud_rate[in] Communication speed. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_FAIL Initialization failure - */ -esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config); - -/** - * @brief Deinitialize serial interface. - */ -void loader_port_esp32_deinit(void); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c deleted file mode 100644 index 55e8f3e57..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c +++ /dev/null @@ -1,298 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp32_spi_port.h" -#include "esp_log.h" -#include "driver/gpio.h" -#include "esp_timer.h" -#include "esp_log.h" -#include "esp_idf_version.h" -#include - -// #define SERIAL_DEBUG_ENABLE - -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) -#define DMA_CHAN SPI_DMA_CH_AUTO -#else -#define DMA_CHAN 1 -#endif - -#define WORD_ALIGNED(ptr) ((size_t)ptr % sizeof(size_t) == 0) - -#ifdef SERIAL_DEBUG_ENABLE - -static void dec_to_hex_str(const uint8_t dec, uint8_t hex_str[3]) -{ - static const uint8_t dec_to_hex[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - - hex_str[0] = dec_to_hex[dec >> 4]; - hex_str[1] = dec_to_hex[dec & 0xF]; - hex_str[2] = '\0'; -} - -static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - uint8_t hex_str[3]; - - if(write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for(uint32_t i = 0; i < size; i++) { - dec_to_hex_str(data[i], hex_str); - printf("%s ", hex_str); - } -} - -#else -static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) { } -#endif - -static spi_host_device_t s_spi_bus; -static spi_bus_config_t s_spi_config; -static spi_device_handle_t s_device_h; -static spi_device_interface_config_t s_device_config; -static int64_t s_time_end; -static uint32_t s_reset_trigger_pin; -static uint32_t s_strap_bit0_pin; -static uint32_t s_strap_bit1_pin; -static uint32_t s_strap_bit2_pin; -static uint32_t s_strap_bit3_pin; -static uint32_t s_spi_cs_pin; - -esp_loader_error_t loader_port_esp32_spi_init(const loader_esp32_spi_config_t *config) -{ - /* Initialize the global static variables*/ - s_spi_bus = config->spi_bus; - s_reset_trigger_pin = config->reset_trigger_pin; - s_strap_bit0_pin = config->strap_bit0_pin; - s_strap_bit1_pin = config->strap_bit1_pin; - s_strap_bit2_pin = config->strap_bit2_pin; - s_strap_bit3_pin = config->strap_bit3_pin; - s_spi_cs_pin = config->spi_cs_pin; - - /* Configure and initialize the SPI bus*/ - s_spi_config.mosi_io_num = config->spi_mosi_pin; - s_spi_config.miso_io_num = config->spi_miso_pin; - s_spi_config.sclk_io_num = config->spi_clk_pin; - s_spi_config.quadwp_io_num = config->spi_quadwp_pin; - s_spi_config.quadhd_io_num = config->spi_quadhd_pin; - s_spi_config.max_transfer_sz = 4096 * 4; - - if (spi_bus_initialize(s_spi_bus, &s_spi_config, DMA_CHAN) != ESP_OK) { - return ESP_LOADER_ERROR_FAIL; - } - - /* Configure and add the device */ - s_device_config.clock_speed_hz = config->frequency; - s_device_config.spics_io_num = -1; /* We're using the chip select pin as GPIO as we need to - chain multiple transactions with CS pulled down */ - s_device_config.flags = SPI_DEVICE_HALFDUPLEX; - s_device_config.queue_size = 16; - - if (spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h) != ESP_OK) { - return ESP_LOADER_ERROR_FAIL; - } - - /* Initialize the pins except for the strapping ones */ - gpio_reset_pin(s_reset_trigger_pin); - gpio_set_pull_mode(s_reset_trigger_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_reset_trigger_pin, GPIO_MODE_OUTPUT); - gpio_set_level(s_reset_trigger_pin, 1); - - gpio_reset_pin(s_spi_cs_pin); - gpio_set_pull_mode(s_spi_cs_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_spi_cs_pin, GPIO_MODE_OUTPUT); - gpio_set_level(s_spi_cs_pin, 1); - - return ESP_LOADER_SUCCESS; -} - - -void loader_port_esp32_spi_deinit(void) -{ - gpio_reset_pin(s_reset_trigger_pin); - gpio_reset_pin(s_spi_cs_pin); - spi_bus_remove_device(s_device_h); - spi_bus_free(s_spi_bus); -} - - -void loader_port_spi_set_cs(const uint32_t level) { - gpio_set_level(s_spi_cs_pin, level); -} - - -esp_loader_error_t loader_port_write(const uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - /* Due to the fact that the SPI driver uses DMA for larger transfers, - and the DMA requirements, the buffer must be word aligned */ - if (data == NULL || !WORD_ALIGNED(data)) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - serial_debug_print(data, size, true); - - spi_transaction_t transaction = { - .tx_buffer = data, - .rx_buffer = NULL, - .length = size * 8U, - .rxlength = 0, - }; - - esp_err_t err = spi_device_transmit(s_device_h, &transaction); - - if (err == ESP_OK) { - serial_debug_print(data, size, false); - return ESP_LOADER_SUCCESS; - } else if (err == ESP_ERR_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - /* Due to the fact that the SPI driver uses DMA for larger transfers, - and the DMA requirements, the buffer must be word aligned */ - if (data == NULL || !WORD_ALIGNED(data)) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - serial_debug_print(data, size, true); - - spi_transaction_t transaction = { - .tx_buffer = NULL, - .rx_buffer = data, - .rxlength = size * 8, - }; - - esp_err_t err = spi_device_transmit(s_device_h, &transaction); - - if (err == ESP_OK) { - serial_debug_print(data, size, false); - return ESP_LOADER_SUCCESS; - } else if (err == ESP_ERR_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -void loader_port_enter_bootloader(void) -{ - /* - We have to initialize the GPIO pins for the target strapping pins here, - as they may overlap with target SPI pins. - For instance in the case of ESP32C3 MISO and strapping bit 0 pins overlap. - */ - spi_bus_remove_device(s_device_h); - spi_bus_free(s_spi_bus); - - gpio_reset_pin(s_strap_bit0_pin); - gpio_set_pull_mode(s_strap_bit0_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit0_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_strap_bit1_pin); - gpio_set_pull_mode(s_strap_bit1_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit1_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_strap_bit2_pin); - gpio_set_pull_mode(s_strap_bit2_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit2_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_strap_bit3_pin); - gpio_set_pull_mode(s_strap_bit3_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit3_pin, GPIO_MODE_OUTPUT); - - /* Set the strapping pins and perform the reset sequence */ - gpio_set_level(s_strap_bit0_pin, 1); - gpio_set_level(s_strap_bit1_pin, 0); - gpio_set_level(s_strap_bit2_pin, 0); - gpio_set_level(s_strap_bit3_pin, 0); - loader_port_reset_target(); - loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpio_set_level(s_strap_bit3_pin, 1); - gpio_set_level(s_strap_bit0_pin, 0); - - /* Disable the strapping pins so they can be used by the slave later */ - gpio_reset_pin(s_strap_bit0_pin); - gpio_reset_pin(s_strap_bit1_pin); - gpio_reset_pin(s_strap_bit2_pin); - gpio_reset_pin(s_strap_bit3_pin); - - /* Restore the SPI bus pins */ - spi_bus_initialize(s_spi_bus, &s_spi_config, DMA_CHAN); - spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h); -} - - -void loader_port_reset_target(void) -{ - gpio_set_level(s_reset_trigger_pin, 0); - loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpio_set_level(s_reset_trigger_pin, 1); -} - - -void loader_port_delay_ms(const uint32_t ms) -{ - usleep(ms * 1000); -} - - -void loader_port_start_timer(const uint32_t ms) -{ - s_time_end = esp_timer_get_time() + ms * 1000; -} - - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = (s_time_end - esp_timer_get_time()) / 1000; - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s\n", str); -} - - -esp_loader_error_t loader_port_change_transmission_rate(const uint32_t frequency) -{ - if (spi_bus_remove_device(s_device_h) != ESP_OK) { - return ESP_LOADER_ERROR_FAIL; - } - - uint32_t old_frequency = s_device_config.clock_speed_hz; - s_device_config.clock_speed_hz = frequency; - - if (spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h) != ESP_OK) { - s_device_config.clock_speed_hz = old_frequency; - return ESP_LOADER_ERROR_FAIL; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h deleted file mode 100644 index 72304c5df..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - #pragma once - -#include "esp_loader_io.h" -#include "driver/spi_master.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - spi_host_device_t spi_bus; - uint32_t frequency; - uint32_t spi_clk_pin; - uint32_t spi_miso_pin; - uint32_t spi_mosi_pin; - uint32_t spi_cs_pin; - uint32_t spi_quadwp_pin; - uint32_t spi_quadhd_pin; - uint32_t reset_trigger_pin; - uint32_t strap_bit0_pin; - uint32_t strap_bit1_pin; - uint32_t strap_bit2_pin; - uint32_t strap_bit3_pin; -} loader_esp32_spi_config_t; - -/** - * @brief Initializes the SPI interface. - * - * @param config[in] Configuration structure - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_FAIL Initialization failure - */ -esp_loader_error_t loader_port_esp32_spi_init(const loader_esp32_spi_config_t *config); - -/** - * @brief Deinitializes the SPI interface. - */ -void loader_port_esp32_spi_deinit(void); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c deleted file mode 100644 index d733db702..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c +++ /dev/null @@ -1,302 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp_loader_io.h" -#include "protocol.h" -#include -#include "raspberry_port.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printf("%02x ", data[i]); - } -} -#endif - -static int serial; -static int64_t s_time_end; -static int32_t s_reset_trigger_pin; -static int32_t s_gpio0_trigger_pin; - - -static speed_t convert_baudrate(int baud) -{ - switch (baud) { - case 50: return B50; - case 75: return B75; - case 110: return B110; - case 134: return B134; - case 150: return B150; - case 200: return B200; - case 300: return B300; - case 600: return B600; - case 1200: return B1200; - case 1800: return B1800; - case 2400: return B2400; - case 4800: return B4800; - case 9600: return B9600; - case 19200: return B19200; - case 38400: return B38400; - case 57600: return B57600; - case 115200: return B115200; - case 230400: return B230400; - case 460800: return B460800; - case 500000: return B500000; - case 576000: return B576000; - case 921600: return B921600; - case 1000000: return B1000000; - case 1152000: return B1152000; - case 1500000: return B1500000; - case 2000000: return B2000000; - case 2500000: return B2500000; - case 3000000: return B3000000; - case 3500000: return B3500000; - case 4000000: return B4000000; - default: return -1; - } -} - -static int serialOpen (const char *device, uint32_t baudrate) -{ - struct termios options; - int status, fd; - - if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1) { - printf("Error occured while opening serial port !\n"); - return -1 ; - } - - fcntl (fd, F_SETFL, O_RDWR) ; - - // Get and modify current options: - - tcgetattr (fd, &options); - speed_t baud = convert_baudrate(baudrate); - - if(baud < 0) { - printf("Invalid baudrate!\n"); - return -1; - } - - cfmakeraw (&options) ; - cfsetispeed (&options, baud) ; - cfsetospeed (&options, baud) ; - - options.c_cflag |= (CLOCAL | CREAD) ; - options.c_cflag &= ~(PARENB | CSTOPB | CSIZE) ; - options.c_cflag |= CS8 ; - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ; - options.c_oflag &= ~OPOST ; - options.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl - options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable any special handling of received bytes - - options.c_cc [VMIN] = 0 ; - options.c_cc [VTIME] = 10 ; // 1 Second - - tcsetattr (fd, TCSANOW, &options) ; - - ioctl (fd, TIOCMGET, &status); - - status |= TIOCM_DTR ; - status |= TIOCM_RTS ; - - ioctl (fd, TIOCMSET, &status); - - usleep (10000) ; // 10mS - - return fd ; -} - -static esp_loader_error_t change_baudrate(int file_desc, int baudrate) -{ - struct termios options; - speed_t baud = convert_baudrate(baudrate); - - if(baud < 0) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - tcgetattr (file_desc, &options); - - cfmakeraw (&options) ; - cfsetispeed (&options, baud); - cfsetospeed (&options, baud); - - tcsetattr (file_desc, TCSANOW, &options); - - return ESP_LOADER_SUCCESS; -} - -static void set_timeout(uint32_t timeout) -{ - struct termios options; - - timeout /= 100; - timeout = MAX(timeout, 1); - - tcgetattr(serial, &options); - options.c_cc[VTIME] = timeout; - tcsetattr(serial, TCSANOW, &options); -} - -static esp_loader_error_t read_char(char *c, uint32_t timeout) -{ - set_timeout(timeout); - int read_bytes = read(serial, c, 1); - - if (read_bytes == 1) { - return ESP_LOADER_SUCCESS; - } else if (read_bytes == 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - -static esp_loader_error_t read_data(char *buffer, uint32_t size) -{ - for (int i = 0; i < size; i++) { - uint32_t remaining_time = loader_port_remaining_time(); - RETURN_ON_ERROR( read_char(&buffer[i], remaining_time) ); - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *config) -{ - s_reset_trigger_pin = config->reset_trigger_pin; - s_gpio0_trigger_pin = config->gpio0_trigger_pin; - - serial = serialOpen(config->device, config->baudrate); - if (serial < 0) { - printf("Serial port could not be opened!\n"); - return ESP_LOADER_ERROR_FAIL; - } - - if (gpioInitialise() < 0) { - printf("pigpio initialisation failed\n"); - return ESP_LOADER_ERROR_FAIL; - } - - gpioSetMode(config->reset_trigger_pin, PI_OUTPUT); - gpioSetMode(config->gpio0_trigger_pin, PI_OUTPUT); - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout) -{ - int written = write(serial, data, size); - - if (written < 0) { - return ESP_LOADER_ERROR_FAIL; - } else if (written < size) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, written, true); -#endif - return ESP_LOADER_ERROR_TIMEOUT; - } else { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, written, true); -#endif - return ESP_LOADER_SUCCESS; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout) -{ - RETURN_ON_ERROR( read_data(data, size) ); - -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, false); -#endif - - return ESP_LOADER_SUCCESS; -} - - -// Set GPIO0 LOW, then assert reset pin for 50 milliseconds. -void loader_port_enter_bootloader(void) -{ - gpioWrite(s_gpio0_trigger_pin, 0); - loader_port_reset_target(); - loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpioWrite(s_gpio0_trigger_pin, 1); -} - - -void loader_port_reset_target(void) -{ - gpioWrite(s_reset_trigger_pin, 0); - loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpioWrite(s_reset_trigger_pin, 1); -} - - -void loader_port_delay_ms(uint32_t ms) -{ - usleep(ms * 1000); -} - - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = clock() + (ms * (CLOCKS_PER_SEC / 1000)); -} - - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = (s_time_end - clock()) / 1000; - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s\n", str); -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - return change_baudrate(serial, baudrate); -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h deleted file mode 100644 index 803ab72dd..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "esp_loader_io.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const char *device; - uint32_t baudrate; - uint32_t reset_trigger_pin; - uint32_t gpio0_trigger_pin; -} loader_raspberry_config_t; - -esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *config); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c deleted file mode 100644 index 716c9c91b..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include "stm32_port.h" - -static UART_HandleTypeDef *uart; -static GPIO_TypeDef* gpio_port_io0, *gpio_port_rst; -static uint16_t gpio_num_io0, gpio_num_rst; - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printf("%02x ", data[i]); - } -} -#endif - -static uint32_t s_time_end; - -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout) -{ - HAL_StatusTypeDef err = HAL_UART_Transmit(uart, (uint8_t *)data, size, timeout); - - if (err == HAL_OK) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, true); -#endif - return ESP_LOADER_SUCCESS; - } else if (err == HAL_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout) -{ - HAL_StatusTypeDef err = HAL_UART_Receive(uart, data, size, timeout); - - if (err == HAL_OK) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, false); -#endif - return ESP_LOADER_SUCCESS; - } else if (err == HAL_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - -void loader_port_stm32_init(loader_stm32_config_t *config) - -{ - uart = config->huart; - gpio_port_io0 = config->port_io0; - gpio_port_rst = config->port_rst; - gpio_num_io0 = config->pin_num_io0; - gpio_num_rst = config->pin_num_rst; -} - -// Set GPIO0 LOW, then -// assert reset pin for 100 milliseconds. -void loader_port_enter_bootloader(void) -{ - HAL_GPIO_WritePin(gpio_port_io0, gpio_num_io0, GPIO_PIN_RESET); - loader_port_reset_target(); - HAL_Delay(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - HAL_GPIO_WritePin(gpio_port_io0, gpio_num_io0, GPIO_PIN_SET); -} - - -void loader_port_reset_target(void) -{ - HAL_GPIO_WritePin(gpio_port_rst, gpio_num_rst, GPIO_PIN_RESET); - HAL_Delay(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - HAL_GPIO_WritePin(gpio_port_rst, gpio_num_rst, GPIO_PIN_SET); -} - - -void loader_port_delay_ms(uint32_t ms) -{ - HAL_Delay(ms); -} - - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = HAL_GetTick() + ms; -} - - -uint32_t loader_port_remaining_time(void) -{ - int32_t remaining = s_time_end - HAL_GetTick(); - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s", str); -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - uart->Init.BaudRate = baudrate; - - if( HAL_UART_Init(uart) != HAL_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h deleted file mode 100644 index a3a89a733..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "esp_loader_io.h" -#include "stm32f4xx_hal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - UART_HandleTypeDef *huart; - GPIO_TypeDef *port_io0; - uint16_t pin_num_io0; - GPIO_TypeDef *port_rst; - uint16_t pin_num_rst; -} loader_stm32_config_t; - -void loader_port_stm32_init(loader_stm32_config_t *config); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c deleted file mode 100644 index 21270ba0a..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2022 KT-Elektronik, Klaucke und Partner GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "zephyr_port.h" -#include -#include - -static const struct device *uart_dev; -static struct gpio_dt_spec enable_spec; -static struct gpio_dt_spec boot_spec; - -static struct tty_serial tty; -static char tty_rx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE]; -static char tty_tx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE]; - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printk("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printk("%02x ", data[i]); - } -} -#endif - -esp_loader_error_t configure_tty() -{ - if (tty_init(&tty, uart_dev) < 0 || - tty_set_rx_buf(&tty, tty_rx_buf, sizeof(tty_rx_buf)) < 0 || - tty_set_tx_buf(&tty, tty_tx_buf, sizeof(tty_tx_buf)) < 0) { - return ESP_LOADER_ERROR_FAIL; - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_read(uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - if (!device_is_ready(uart_dev) || data == NULL || size == 0) { - return ESP_LOADER_ERROR_FAIL; - } - - ssize_t total_read = 0; - ssize_t remaining = size; - - tty_set_rx_timeout(&tty, timeout); - while (remaining > 0) { - const uint16_t chunk_size = remaining < CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE ? - remaining : CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE; - ssize_t read = tty_read(&tty, &data[total_read], chunk_size); - if (read < 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, read, false); -#endif - total_read += read; - remaining -= read; - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_write(const uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - if (!device_is_ready(uart_dev) || data == NULL || size == 0) { - return ESP_LOADER_ERROR_FAIL; - } - - ssize_t total_written = 0; - ssize_t remaining = size; - - tty_set_tx_timeout(&tty, timeout); - while (remaining > 0) { - const uint16_t chunk_size = remaining < CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE ? - remaining : CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE; - ssize_t written = tty_write(&tty, &data[total_written], chunk_size); - if (written < 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, written, true); -#endif - total_written += written; - remaining -= written; - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_zephyr_init(const loader_zephyr_config_t *config) -{ - uart_dev = config->uart_dev; - enable_spec = config->enable_spec; - boot_spec = config->boot_spec; - return configure_tty(); -} - -void loader_port_reset_target(void) -{ - gpio_pin_set_dt(&enable_spec, false); - loader_port_delay_ms(CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpio_pin_set_dt(&enable_spec, true); -} - -void loader_port_enter_bootloader(void) -{ - gpio_pin_set_dt(&boot_spec, false); - loader_port_reset_target(); - loader_port_delay_ms(CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpio_pin_set_dt(&boot_spec, true); -} - -void loader_port_delay_ms(uint32_t ms) -{ - k_msleep(ms); -} - -static uint64_t s_time_end; - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = sys_clock_timeout_end_calc(Z_TIMEOUT_MS(ms)); -} - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = k_ticks_to_ms_floor64(s_time_end - k_uptime_ticks()); - return (remaining > 0) ? (uint32_t)remaining : 0; -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - struct uart_config uart_config; - - if (!device_is_ready(uart_dev)) { - return ESP_LOADER_ERROR_FAIL; - } - - if (uart_config_get(uart_dev, &uart_config) != 0) { - return ESP_LOADER_ERROR_FAIL; - } - uart_config.baudrate = baudrate; - - if (uart_configure(uart_dev, &uart_config) != 0) { - return ESP_LOADER_ERROR_FAIL; - } - - /* bitrate-change can require tty re-configuration */ - return configure_tty(); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h deleted file mode 100644 index 0b104e375..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 KT-Elektronik, Klaucke und Partner GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "esp_loader_io.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const struct device *uart_dev; - const struct gpio_dt_spec enable_spec; - const struct gpio_dt_spec boot_spec; -} loader_zephyr_config_t; - -esp_loader_error_t loader_port_zephyr_init(const loader_zephyr_config_t *config); - -#ifdef __cplusplus -} -#endif - diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h deleted file mode 100644 index cf8af91fa..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "esp_loader.h" - -typedef struct { - uint32_t cmd; - uint32_t usr; - uint32_t usr1; - uint32_t usr2; - uint32_t w0; - uint32_t mosi_dlen; - uint32_t miso_dlen; -} target_registers_t; - -esp_loader_error_t loader_detect_chip(target_chip_t *target, const target_registers_t **regs); -esp_loader_error_t loader_read_spi_config(target_chip_t target_chip, uint32_t *spi_config); -bool encryption_in_begin_flash_cmd(target_chip_t target); \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h deleted file mode 100644 index eb5738c8b..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * MD5 hash implementation and interface functions - * Copyright (c) 2003-2005, Jouni Malinen - * - * This software may be distributed under the terms of the BSD license. - * See README for more details. - */ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif -struct MD5Context { - uint32_t buf[4]; - uint32_t bits[2]; - uint8_t in[64]; -}; - -void MD5Init(struct MD5Context *context); -void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len); -void MD5Final(unsigned char digest[16], struct MD5Context *context); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h deleted file mode 100644 index fb8b086fd..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h +++ /dev/null @@ -1,230 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include "esp_loader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATUS_FAILURE 1 -#define STATUS_SUCCESS 0 - -#define READ_DIRECTION 1 -#define WRITE_DIRECTION 0 - -#define MD5_SIZE 32 - -typedef enum __attribute__((packed)) -{ - FLASH_BEGIN = 0x02, - FLASH_DATA = 0x03, - FLASH_END = 0x04, - MEM_BEGIN = 0x05, - MEM_END = 0x06, - MEM_DATA = 0x07, - SYNC = 0x08, - WRITE_REG = 0x09, - READ_REG = 0x0a, - - SPI_SET_PARAMS = 0x0b, - SPI_ATTACH = 0x0d, - CHANGE_BAUDRATE = 0x0f, - FLASH_DEFL_BEGIN = 0x10, - FLASH_DEFL_DATA = 0x11, - FLASH_DEFL_END = 0x12, - SPI_FLASH_MD5 = 0x13, -} command_t; - -typedef enum __attribute__((packed)) -{ - RESPONSE_OK = 0x00, - INVALID_COMMAND = 0x05, // parameters or length field is invalid - COMMAND_FAILED = 0x06, // Failed to act on received message - INVALID_CRC = 0x07, // Invalid CRC in message - FLASH_WRITE_ERR = 0x08, // After writing a block of data to flash, the ROM loader reads the value back and the 8-bit CRC is compared to the data read from flash. If they don't match, this error is returned. - FLASH_READ_ERR = 0x09, // SPI read failed - READ_LENGTH_ERR = 0x0a, // SPI read request length is too long - DEFLATE_ERROR = 0x0b, // ESP32 compressed uploads only -} error_code_t; - -typedef struct __attribute__((packed)) -{ - uint8_t direction; - uint8_t command; // One of command_t - uint16_t size; - uint32_t checksum; -} command_common_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t erase_size; - uint32_t packet_count; - uint32_t packet_size; - uint32_t offset; - uint32_t encrypted; -} flash_begin_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t data_size; - uint32_t sequence_number; - uint32_t zero_0; - uint32_t zero_1; -} data_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t stay_in_loader; -} flash_end_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t total_size; - uint32_t blocks; - uint32_t block_size; - uint32_t offset; -} mem_begin_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t stay_in_loader; - uint32_t entry_point_address; -} mem_end_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint8_t sync_sequence[36]; -} sync_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t address; - uint32_t value; - uint32_t mask; - uint32_t delay_us; -} write_reg_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t address; -} read_reg_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t configuration; - uint32_t zero; // ESP32 ROM only -} spi_attach_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t new_baudrate; - uint32_t old_baudrate; -} change_baudrate_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t address; - uint32_t size; - uint32_t reserved_0; - uint32_t reserved_1; -} spi_flash_md5_command_t; - -typedef struct __attribute__((packed)) -{ - uint8_t direction; - uint8_t command; // One of command_t - uint16_t size; - uint32_t value; -} common_response_t; - -typedef struct __attribute__((packed)) -{ - uint8_t failed; - uint8_t error; -} response_status_t; - -typedef struct __attribute__((packed)) -{ - common_response_t common; - response_status_t status; -} response_t; - -typedef struct __attribute__((packed)) -{ - common_response_t common; - uint8_t md5[MD5_SIZE]; // ROM only - response_status_t status; -} rom_md5_response_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t id; - uint32_t total_size; - uint32_t block_size; - uint32_t sector_size; - uint32_t page_size; - uint32_t status_mask; -} write_spi_command_t; - -esp_loader_error_t loader_initialize_conn(esp_loader_connect_args_t *connect_args); - -#ifdef SERIAL_FLASHER_INTERFACE_UART -esp_loader_error_t loader_flash_begin_cmd(uint32_t offset, uint32_t erase_size, uint32_t block_size, uint32_t blocks_to_write, bool encryption); - -esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size); - -esp_loader_error_t loader_flash_end_cmd(bool stay_in_loader); - -esp_loader_error_t loader_sync_cmd(void); - -esp_loader_error_t loader_spi_attach_cmd(uint32_t config); - -esp_loader_error_t loader_md5_cmd(uint32_t address, uint32_t size, uint8_t *md5_out); - -esp_loader_error_t loader_spi_parameters(uint32_t total_size); -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - -esp_loader_error_t loader_mem_begin_cmd(uint32_t offset, uint32_t size, uint32_t blocks_to_write, uint32_t block_size); - -esp_loader_error_t loader_mem_data_cmd(const uint8_t *data, uint32_t size); - -esp_loader_error_t loader_mem_end_cmd(uint32_t entrypoint); - -esp_loader_error_t loader_write_reg_cmd(uint32_t address, uint32_t value, uint32_t mask, uint32_t delay_us); - -esp_loader_error_t loader_read_reg_cmd(uint32_t address, uint32_t *reg); - -esp_loader_error_t loader_change_baudrate_cmd(uint32_t baudrate); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h deleted file mode 100644 index 3b9575606..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include "esp_loader.h" -#include "protocol.h" - -void log_loader_internal_error(error_code_t error); - -esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value); - -esp_loader_error_t send_cmd_with_data(const void *cmd_data, size_t cmd_size, - const void *data, size_t data_size); - -esp_loader_error_t send_cmd_md5(const void *cmd_data, size_t cmd_size, uint8_t md5_out[MD5_SIZE]); diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h deleted file mode 100644 index 00f1f7d0d..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "esp_loader.h" -#include -#include - -esp_loader_error_t SLIP_receive_data(uint8_t *buff, size_t size); - -esp_loader_error_t SLIP_receive_packet(uint8_t *buff, size_t size); - -esp_loader_error_t SLIP_send(const uint8_t *data, size_t size); - -esp_loader_error_t SLIP_send_delimiter(void); diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c deleted file mode 100644 index 6ef32673c..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c +++ /dev/null @@ -1,415 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "esp_loader_io.h" -#include "esp_loader.h" -#include "esp_targets.h" -#include "md5_hash.h" -#include -#include - -#ifndef MAX -#define MAX(a, b) ((a) > (b)) ? (a) : (b) -#endif - -#ifndef MIN -#define MIN(a, b) ((a) < (b)) ? (a) : (b) -#endif - -#ifndef ROUNDUP -#define ROUNDUP(a, b) (((int)a + (int)b - 1) / (int)b) -#endif - -static const uint32_t DEFAULT_TIMEOUT = 1000; -static const uint32_t DEFAULT_FLASH_TIMEOUT = 3000; // timeout for most flash operations -static const uint32_t LOAD_RAM_TIMEOUT_PER_MB = 2000000; // timeout (per megabyte) for erasing a region - -typedef enum { - SPI_FLASH_READ_ID = 0x9F -} spi_flash_cmd_t; - -static const target_registers_t *s_reg = NULL; -static target_chip_t s_target = ESP_UNKNOWN_CHIP; - -#if MD5_ENABLED - -static const uint32_t MD5_TIMEOUT_PER_MB = 800; -static struct MD5Context s_md5_context; -static uint32_t s_start_address; -static uint32_t s_image_size; - -static inline void init_md5(uint32_t address, uint32_t size) -{ - s_start_address = address; - s_image_size = size; - MD5Init(&s_md5_context); -} - -static inline void md5_update(const uint8_t *data, uint32_t size) -{ - MD5Update(&s_md5_context, data, size); -} - -static inline void md5_final(uint8_t digets[16]) -{ - MD5Final(digets, &s_md5_context); -} - -#else - -static inline void init_md5(uint32_t address, uint32_t size) { } -static inline void md5_update(const uint8_t *data, uint32_t size) { } -static inline void md5_final(uint8_t digets[16]) { } - -#endif - - -static uint32_t timeout_per_mb(uint32_t size_bytes, uint32_t time_per_mb) -{ - uint32_t timeout = time_per_mb * (size_bytes / 1e6); - return MAX(timeout, DEFAULT_FLASH_TIMEOUT); -} - -esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args) -{ - loader_port_enter_bootloader(); - - RETURN_ON_ERROR(loader_initialize_conn(connect_args)); - - RETURN_ON_ERROR(loader_detect_chip(&s_target, &s_reg)); - -#ifdef SERIAL_FLASHER_INTERFACE_UART - esp_loader_error_t err; - uint32_t spi_config; - if (s_target == ESP8266_CHIP) { - err = loader_flash_begin_cmd(0, 0, 0, 0, s_target); - } else { - RETURN_ON_ERROR( loader_read_spi_config(s_target, &spi_config) ); - loader_port_start_timer(DEFAULT_TIMEOUT); - err = loader_spi_attach_cmd(spi_config); - } - return err; -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - return ESP_LOADER_SUCCESS; -} - -target_chip_t esp_loader_get_target(void) -{ - return s_target; -} - -#ifdef SERIAL_FLASHER_INTERFACE_UART -static uint32_t s_flash_write_size = 0; - -static esp_loader_error_t spi_set_data_lengths(size_t mosi_bits, size_t miso_bits) -{ - if (mosi_bits > 0) { - RETURN_ON_ERROR( esp_loader_write_register(s_reg->mosi_dlen, mosi_bits - 1) ); - } - if (miso_bits > 0) { - RETURN_ON_ERROR( esp_loader_write_register(s_reg->miso_dlen, miso_bits - 1) ); - } - - return ESP_LOADER_SUCCESS; -} - -static esp_loader_error_t spi_set_data_lengths_8266(size_t mosi_bits, size_t miso_bits) -{ - uint32_t mosi_mask = (mosi_bits == 0) ? 0 : mosi_bits - 1; - uint32_t miso_mask = (miso_bits == 0) ? 0 : miso_bits - 1; - return esp_loader_write_register(s_reg->usr1, (miso_mask << 8) | (mosi_mask << 17)); -} - -static esp_loader_error_t spi_flash_command(spi_flash_cmd_t cmd, void *data_tx, size_t tx_size, void *data_rx, size_t rx_size) -{ - assert(rx_size <= 32); // Reading more than 32 bits back from a SPI flash operation is unsupported - assert(tx_size <= 64); // Writing more than 64 bytes of data with one SPI command is unsupported - - uint32_t SPI_USR_CMD = (1 << 31); - uint32_t SPI_USR_MISO = (1 << 28); - uint32_t SPI_USR_MOSI = (1 << 27); - uint32_t SPI_CMD_USR = (1 << 18); - uint32_t CMD_LEN_SHIFT = 28; - - // Save SPI configuration - uint32_t old_spi_usr; - uint32_t old_spi_usr2; - RETURN_ON_ERROR( esp_loader_read_register(s_reg->usr, &old_spi_usr) ); - RETURN_ON_ERROR( esp_loader_read_register(s_reg->usr2, &old_spi_usr2) ); - - if (s_target == ESP8266_CHIP) { - RETURN_ON_ERROR( spi_set_data_lengths_8266(tx_size, rx_size) ); - } else { - RETURN_ON_ERROR( spi_set_data_lengths(tx_size, rx_size) ); - } - - uint32_t usr_reg_2 = (7 << CMD_LEN_SHIFT) | cmd; - uint32_t usr_reg = SPI_USR_CMD; - if (rx_size > 0) { - usr_reg |= SPI_USR_MISO; - } - if (tx_size > 0) { - usr_reg |= SPI_USR_MOSI; - } - - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr, usr_reg) ); - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr2, usr_reg_2 ) ); - - if (tx_size == 0) { - // clear data register before we read it - RETURN_ON_ERROR( esp_loader_write_register(s_reg->w0, 0) ); - } else { - uint32_t *data = (uint32_t *)data_tx; - uint32_t words_to_write = (tx_size + 31) / (8 * 4); - uint32_t data_reg_addr = s_reg->w0; - - while (words_to_write--) { - uint32_t word = *data++; - RETURN_ON_ERROR( esp_loader_write_register(data_reg_addr, word) ); - data_reg_addr += 4; - } - } - - RETURN_ON_ERROR( esp_loader_write_register(s_reg->cmd, SPI_CMD_USR) ); - - uint32_t trials = 10; - while (trials--) { - uint32_t cmd_reg; - RETURN_ON_ERROR( esp_loader_read_register(s_reg->cmd, &cmd_reg) ); - if ((cmd_reg & SPI_CMD_USR) == 0) { - break; - } - } - - if (trials == 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } - - RETURN_ON_ERROR( esp_loader_read_register(s_reg->w0, data_rx) ); - - // Restore SPI configuration - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr, old_spi_usr) ); - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr2, old_spi_usr2) ); - - return ESP_LOADER_SUCCESS; -} - -static esp_loader_error_t detect_flash_size(size_t *flash_size) -{ - uint32_t flash_id = 0; - - RETURN_ON_ERROR( spi_flash_command(SPI_FLASH_READ_ID, NULL, 0, &flash_id, 24) ); - uint32_t size_id = flash_id >> 16; - - if (size_id < 0x12 || size_id > 0x18) { - return ESP_LOADER_ERROR_UNSUPPORTED_CHIP; - } - - *flash_size = 1 << size_id; - - return ESP_LOADER_SUCCESS; -} - -static uint32_t calc_erase_size(const target_chip_t target, const uint32_t offset, - const uint32_t image_size) -{ - if (target != ESP8266_CHIP) { - return image_size; - } else { - /* Needed to fix a bug in the ESP8266 ROM */ - const uint32_t sectors_per_block = 16U; - const uint32_t sector_size = 4096U; - - const uint32_t num_sectors = (image_size + sector_size - 1) / sector_size; - const uint32_t start_sector = offset / sector_size; - - uint32_t head_sectors = sectors_per_block - (start_sector % sectors_per_block); - - /* The ROM bug deletes extra num_sectors if we don't cross the block boundary - and extra head_sectors if we do */ - if (num_sectors <= head_sectors) { - return ((num_sectors + 1) / 2) * sector_size; - } else { - return (num_sectors - head_sectors) * sector_size; - } - } -} - -esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size) -{ - s_flash_write_size = block_size; - - size_t flash_size = 0; - if (detect_flash_size(&flash_size) == ESP_LOADER_SUCCESS) { - if (image_size > flash_size) { - return ESP_LOADER_ERROR_IMAGE_SIZE; - } - loader_port_start_timer(DEFAULT_TIMEOUT); - RETURN_ON_ERROR( loader_spi_parameters(flash_size) ); - } else { - loader_port_debug_print("Flash size detection failed, falling back to default"); - } - - init_md5(offset, image_size); - - bool encryption_in_cmd = encryption_in_begin_flash_cmd(s_target); - const uint32_t erase_size = calc_erase_size(esp_loader_get_target(), offset, image_size); - const uint32_t blocks_to_write = (image_size + block_size - 1) / block_size; - - const uint32_t erase_region_timeout_per_mb = 10000; - loader_port_start_timer(timeout_per_mb(erase_size, erase_region_timeout_per_mb)); - return loader_flash_begin_cmd(offset, erase_size, block_size, blocks_to_write, encryption_in_cmd); -} - - -esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size) -{ - uint32_t padding_bytes = s_flash_write_size - size; - uint8_t *data = (uint8_t *)payload; - uint32_t padding_index = size; - - if (size > s_flash_write_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - const uint8_t padding_pattern = 0xFF; - while (padding_bytes--) { - data[padding_index++] = padding_pattern; - } - - md5_update(payload, (size + 3) & ~3); - - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_flash_data_cmd(data, s_flash_write_size); -} - - -esp_loader_error_t esp_loader_flash_finish(bool reboot) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_flash_end_cmd(!reboot); -} -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - -esp_loader_error_t esp_loader_mem_start(uint32_t offset, uint32_t size, uint32_t block_size) -{ - uint32_t blocks_to_write = ROUNDUP(size, block_size); - loader_port_start_timer(timeout_per_mb(size, LOAD_RAM_TIMEOUT_PER_MB)); - return loader_mem_begin_cmd(offset, size, blocks_to_write, block_size); -} - - -esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size) -{ - const uint8_t *data = (const uint8_t *)payload; - loader_port_start_timer(timeout_per_mb(size, LOAD_RAM_TIMEOUT_PER_MB)); - return loader_mem_data_cmd(data, size); -} - - -esp_loader_error_t esp_loader_mem_finish(uint32_t entrypoint) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - return loader_mem_end_cmd(entrypoint); -} - - -esp_loader_error_t esp_loader_read_register(uint32_t address, uint32_t *reg_value) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_read_reg_cmd(address, reg_value); -} - - -esp_loader_error_t esp_loader_write_register(uint32_t address, uint32_t reg_value) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_write_reg_cmd(address, reg_value, 0xFFFFFFFF, 0); -} - -esp_loader_error_t esp_loader_change_transmission_rate(uint32_t transmission_rate) -{ - if (s_target == ESP8266_CHIP) { - return ESP_LOADER_ERROR_UNSUPPORTED_FUNC; - } - - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_change_baudrate_cmd(transmission_rate); -} - -#if MD5_ENABLED - -static void hexify(const uint8_t raw_md5[16], uint8_t hex_md5_out[32]) -{ - static const uint8_t dec_to_hex[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - for (int i = 0; i < 16; i++) { - *hex_md5_out++ = dec_to_hex[raw_md5[i] >> 4]; - *hex_md5_out++ = dec_to_hex[raw_md5[i] & 0xF]; - } -} - - -esp_loader_error_t esp_loader_flash_verify(void) -{ - if (s_target == ESP8266_CHIP) { - return ESP_LOADER_ERROR_UNSUPPORTED_FUNC; - } - - uint8_t raw_md5[16] = {0}; - - /* Zero termination and new line character require 2 bytes */ - uint8_t hex_md5[MD5_SIZE + 2] = {0}; - uint8_t received_md5[MD5_SIZE + 2] = {0}; - - md5_final(raw_md5); - hexify(raw_md5, hex_md5); - - loader_port_start_timer(timeout_per_mb(s_image_size, MD5_TIMEOUT_PER_MB)); - - RETURN_ON_ERROR( loader_md5_cmd(s_start_address, s_image_size, received_md5) ); - - bool md5_match = memcmp(hex_md5, received_md5, MD5_SIZE) == 0; - - if (!md5_match) { - hex_md5[MD5_SIZE] = '\n'; - received_md5[MD5_SIZE] = '\n'; - - loader_port_debug_print("Error: MD5 checksum does not match:\n"); - loader_port_debug_print("Expected:\n"); - loader_port_debug_print((char *)received_md5); - loader_port_debug_print("Actual:\n"); - loader_port_debug_print((char *)hex_md5); - - return ESP_LOADER_ERROR_INVALID_MD5; - } - - return ESP_LOADER_SUCCESS; -} - -#endif - -void esp_loader_reset_target(void) -{ - loader_port_reset_target(); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c deleted file mode 100644 index 8764d2369..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c +++ /dev/null @@ -1,263 +0,0 @@ -/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp_targets.h" -#include - -#define MAX_MAGIC_VALUES 2 - -typedef esp_loader_error_t (*read_spi_config_t)(uint32_t efuse_base, uint32_t *spi_config); - -typedef struct { - target_registers_t regs; - uint32_t efuse_base; - uint32_t chip_magic_value[MAX_MAGIC_VALUES]; - read_spi_config_t read_spi_config; - bool encryption_in_begin_flash_cmd; -} esp_target_t; - -// This ROM address has a different value on each chip model -#define CHIP_DETECT_MAGIC_REG_ADDR 0x40001000 - -#define ESP8266_SPI_REG_BASE 0x60000200 -#define ESP32S2_SPI_REG_BASE 0x3f402000 -#define ESP32xx_SPI_REG_BASE 0x60002000 -#define ESP32_SPI_REG_BASE 0x3ff42000 - -static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_config); -static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_config); - -static const esp_target_t esp_target[ESP_MAX_CHIP] = { - - // ESP8266 - { - .regs = { - .cmd = ESP8266_SPI_REG_BASE + 0x00, - .usr = ESP8266_SPI_REG_BASE + 0x1c, - .usr1 = ESP8266_SPI_REG_BASE + 0x20, - .usr2 = ESP8266_SPI_REG_BASE + 0x24, - .w0 = ESP8266_SPI_REG_BASE + 0x40, - .mosi_dlen = 0, - .miso_dlen = 0, - }, - .efuse_base = 0, // Not used - .chip_magic_value = { 0xfff0c101, 0 }, - .read_spi_config = NULL, // Not used - }, - - // ESP32 - { - .regs = { - .cmd = ESP32_SPI_REG_BASE + 0x00, - .usr = ESP32_SPI_REG_BASE + 0x1c, - .usr1 = ESP32_SPI_REG_BASE + 0x20, - .usr2 = ESP32_SPI_REG_BASE + 0x24, - .w0 = ESP32_SPI_REG_BASE + 0x80, - .mosi_dlen = ESP32_SPI_REG_BASE + 0x28, - .miso_dlen = ESP32_SPI_REG_BASE + 0x2c, - }, - .efuse_base = 0x3ff5A000, - .chip_magic_value = { 0x00f01d83, 0 }, - .read_spi_config = spi_config_esp32, - }, - - // ESP32S2 - { - .regs = { - .cmd = ESP32S2_SPI_REG_BASE + 0x00, - .usr = ESP32S2_SPI_REG_BASE + 0x18, - .usr1 = ESP32S2_SPI_REG_BASE + 0x1c, - .usr2 = ESP32S2_SPI_REG_BASE + 0x20, - .w0 = ESP32S2_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32S2_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32S2_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x3f41A000, - .chip_magic_value = { 0x000007c6, 0 }, - .read_spi_config = spi_config_esp32xx, - }, - - // ESP32C3 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x60008800, - .chip_magic_value = { 0x6921506f, 0x1b31506f }, - .read_spi_config = spi_config_esp32xx, - }, - - // ESP32S3 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x60007000, - .chip_magic_value = { 0x00000009, 0 }, - .read_spi_config = spi_config_esp32xx, - }, - - // ESP32C2 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x60008800, - .chip_magic_value = { 0x6f51306f, 0x7c41a06f }, - .read_spi_config = spi_config_esp32xx, - }, - // ESP32H4 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x6001A000, - .chip_magic_value = {0xca26cc22, 0x6881b06f}, // ESP32H4-BETA1, ESP32H4-BETA2 - .read_spi_config = spi_config_esp32xx, - }, - // ESP32H2 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x6001A000, - .chip_magic_value = {0xd7b73e80, 0}, - .read_spi_config = spi_config_esp32xx, - }, -}; - -const target_registers_t *get_esp_target_data(target_chip_t chip) -{ - return (const target_registers_t *)&esp_target[chip]; -} - -esp_loader_error_t loader_detect_chip(target_chip_t *target_chip, const target_registers_t **target_data) -{ - uint32_t magic_value; - RETURN_ON_ERROR( esp_loader_read_register(CHIP_DETECT_MAGIC_REG_ADDR, &magic_value) ); - - for (int chip = 0; chip < ESP_MAX_CHIP; chip++) { - for(int index = 0; index < MAX_MAGIC_VALUES; index++) { - if (magic_value == esp_target[chip].chip_magic_value[index]) { - *target_chip = (target_chip_t)chip; - *target_data = (target_registers_t *)&esp_target[chip]; - return ESP_LOADER_SUCCESS; - } - } - } - - return ESP_LOADER_ERROR_INVALID_TARGET; -} - -esp_loader_error_t loader_read_spi_config(target_chip_t target_chip, uint32_t *spi_config) -{ - const esp_target_t *target = &esp_target[target_chip]; - return target->read_spi_config(target->efuse_base, spi_config); -} - -static inline uint32_t efuse_word_addr(uint32_t efuse_base, uint32_t n) -{ - return efuse_base + (n * 4); -} - -// 30->GPIO32 | 31->GPIO33 -static inline uint8_t adjust_pin_number(uint8_t num) -{ - return (num >= 30) ? num + 2 : num; -} - - -static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_config) -{ - *spi_config = 0; - - uint32_t reg5, reg3; - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 5), ®5) ); - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 3), ®3) ); - - uint32_t pins = reg5 & 0xfffff; - - if (pins == 0 || pins == 0xfffff) { - return ESP_LOADER_SUCCESS; - } - - uint8_t clk = adjust_pin_number( (pins >> 0) & 0x1f ); - uint8_t q = adjust_pin_number( (pins >> 5) & 0x1f ); - uint8_t d = adjust_pin_number( (pins >> 10) & 0x1f ); - uint8_t cs = adjust_pin_number( (pins >> 15) & 0x1f ); - uint8_t hd = adjust_pin_number( (reg3 >> 4) & 0x1f ); - - if (clk == cs || clk == d || clk == q || q == cs || q == d || q == d) { - return ESP_LOADER_SUCCESS; - } - - *spi_config = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk; - - return ESP_LOADER_SUCCESS; -} - -// Applies for esp32s2, esp32c3 and esp32c3 -static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_config) -{ - *spi_config = 0; - - uint32_t reg1, reg2; - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 18), ®1) ); - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 19), ®2) ); - - uint32_t pins = ((reg1 >> 16) | ((reg2 & 0xfffff) << 16)) & 0x3fffffff; - - if (pins == 0 || pins == 0xffffffff) { - return ESP_LOADER_SUCCESS; - } - - *spi_config = pins; - return ESP_LOADER_SUCCESS; -} - -bool encryption_in_begin_flash_cmd(target_chip_t target) -{ - return target == ESP32_CHIP || target == ESP8266_CHIP; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c deleted file mode 100644 index 4da76bcb5..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * MD5 hash implementation and interface functions - * Copyright (c) 2003-2005, Jouni Malinen - * - * This software may be distributed under the terms of the BSD license. - * See README for more details. - */ - - -#include "md5_hash.h" -#include -#include - - -static void MD5Transform(uint32_t buf[4], uint32_t const in[16]); - - -/* ===== start - public domain MD5 implementation ===== */ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -#ifndef WORDS_BIGENDIAN -#define byteReverse(buf, len) /* Nothing */ -#else -/* - * Note: this code is harmless on little-endian machines. - */ -static void byteReverse(unsigned char *buf, unsigned longs) -{ - uint32_t t; - do { - t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(uint32_t *) buf = t; - buf += 4; - } while (--longs); -} -#endif - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void MD5Init(struct MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) -{ - uint32_t t; - - /* Update bitcount */ - - t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) { - ctx->bits[1]++; /* Carry from low to high */ - } - ctx->bits[1] += len >> 29; - - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ - - /* Handle any leading odd-sized chunks */ - - if (t) { - unsigned char *p = (unsigned char *) ctx->in + t; - - t = 64 - t; - if (len < t) { - memcpy(p, buf, len); - return; - } - memcpy(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - buf += t; - len -= t; - } - /* Process data in 64-byte chunks */ - - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - - memcpy(ctx->in, buf, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void MD5Final(unsigned char digest[16], struct MD5Context *ctx) -{ - unsigned count; - unsigned char *p; - - /* Compute number of bytes mod 64 */ - count = (ctx->bits[0] >> 3) & 0x3F; - - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - p = ctx->in + count; - *p++ = 0x80; - - /* Bytes of padding needed to make 64 bytes */ - count = 64 - 1 - count; - - /* Pad out to 56 mod 64 */ - if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - - /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset(p, 0, count - 8); - } - byteReverse(ctx->in, 14); - - /* Append length in bits and transform */ - ((uint32_t *) ctx->in)[14] = ctx->bits[0]; - ((uint32_t *) ctx->in)[15] = ctx->bits[1]; - - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - byteReverse((unsigned char *) ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */ -} - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -static void MD5Transform(uint32_t buf[4], uint32_t const in[16]) -{ - register uint32_t a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} -/* ===== end - public domain MD5 implementation ===== */ diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c deleted file mode 100644 index 8d1d9dd53..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c +++ /dev/null @@ -1,301 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "protocol_prv.h" -#include "esp_loader_io.h" -#include -#include - -#define CMD_SIZE(cmd) ( sizeof(cmd) - sizeof(command_common_t) ) - -static uint32_t s_sequence_number = 0; - -static uint8_t compute_checksum(const uint8_t *data, uint32_t size) -{ - uint8_t checksum = 0xEF; - - while (size--) { - checksum ^= *data++; - } - - return checksum; -} - -void log_loader_internal_error(error_code_t error) -{ - loader_port_debug_print("Error: "); - - switch (error) { - case INVALID_CRC: loader_port_debug_print("INVALID_CRC"); break; - case INVALID_COMMAND: loader_port_debug_print("INVALID_COMMAND"); break; - case COMMAND_FAILED: loader_port_debug_print("COMMAND_FAILED"); break; - case FLASH_WRITE_ERR: loader_port_debug_print("FLASH_WRITE_ERR"); break; - case FLASH_READ_ERR: loader_port_debug_print("FLASH_READ_ERR"); break; - case READ_LENGTH_ERR: loader_port_debug_print("READ_LENGTH_ERR"); break; - case DEFLATE_ERROR: loader_port_debug_print("DEFLATE_ERROR"); break; - default: loader_port_debug_print("UNKNOWN ERROR"); break; - } - - loader_port_debug_print("\n"); -} - - -esp_loader_error_t loader_flash_begin_cmd(uint32_t offset, - uint32_t erase_size, - uint32_t block_size, - uint32_t blocks_to_write, - bool encryption) -{ - uint32_t encryption_size = encryption ? sizeof(uint32_t) : 0; - - flash_begin_command_t flash_begin_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = FLASH_BEGIN, - .size = CMD_SIZE(flash_begin_cmd) - encryption_size, - .checksum = 0 - }, - .erase_size = erase_size, - .packet_count = blocks_to_write, - .packet_size = block_size, - .offset = offset, - .encrypted = 0 - }; - - s_sequence_number = 0; - - return send_cmd(&flash_begin_cmd, sizeof(flash_begin_cmd) - encryption_size, NULL); -} - - -esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size) -{ - data_command_t data_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = FLASH_DATA, - .size = CMD_SIZE(data_cmd) + size, - .checksum = compute_checksum(data, size) - }, - .data_size = size, - .sequence_number = s_sequence_number++, - }; - - return send_cmd_with_data(&data_cmd, sizeof(data_cmd), data, size); -} - - -esp_loader_error_t loader_flash_end_cmd(bool stay_in_loader) -{ - flash_end_command_t end_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = FLASH_END, - .size = CMD_SIZE(end_cmd), - .checksum = 0 - }, - .stay_in_loader = stay_in_loader - }; - - return send_cmd(&end_cmd, sizeof(end_cmd), NULL); -} - - -esp_loader_error_t loader_mem_begin_cmd(uint32_t offset, uint32_t size, uint32_t blocks_to_write, uint32_t block_size) -{ - - mem_begin_command_t mem_begin_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = MEM_BEGIN, - .size = CMD_SIZE(mem_begin_cmd), - .checksum = 0 - }, - .total_size = size, - .blocks = blocks_to_write, - .block_size = block_size, - .offset = offset - }; - - s_sequence_number = 0; - - return send_cmd(&mem_begin_cmd, sizeof(mem_begin_cmd), NULL); -} - - -esp_loader_error_t loader_mem_data_cmd(const uint8_t *data, uint32_t size) -{ - data_command_t data_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = MEM_DATA, - .size = CMD_SIZE(data_cmd) + size, - .checksum = compute_checksum(data, size) - }, - .data_size = size, - .sequence_number = s_sequence_number++, - }; - return send_cmd_with_data(&data_cmd, sizeof(data_cmd), data, size); -} - -esp_loader_error_t loader_mem_end_cmd(uint32_t entrypoint) -{ - mem_end_command_t end_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = MEM_END, - .size = CMD_SIZE(end_cmd), - }, - .stay_in_loader = (entrypoint == 0), - .entry_point_address = entrypoint - }; - - return send_cmd(&end_cmd, sizeof(end_cmd), NULL); -} - - -esp_loader_error_t loader_sync_cmd(void) -{ - sync_command_t sync_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SYNC, - .size = CMD_SIZE(sync_cmd), - .checksum = 0 - }, - .sync_sequence = { - 0x07, 0x07, 0x12, 0x20, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - } - }; - - return send_cmd(&sync_cmd, sizeof(sync_cmd), NULL); -} - - -esp_loader_error_t loader_write_reg_cmd(uint32_t address, uint32_t value, - uint32_t mask, uint32_t delay_us) -{ - write_reg_command_t write_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = WRITE_REG, - .size = CMD_SIZE(write_cmd), - .checksum = 0 - }, - .address = address, - .value = value, - .mask = mask, - .delay_us = delay_us - }; - - return send_cmd(&write_cmd, sizeof(write_cmd), NULL); -} - - -esp_loader_error_t loader_read_reg_cmd(uint32_t address, uint32_t *reg) -{ - read_reg_command_t read_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = READ_REG, - .size = CMD_SIZE(read_cmd), - .checksum = 0 - }, - .address = address, - }; - - return send_cmd(&read_cmd, sizeof(read_cmd), reg); -} - - -esp_loader_error_t loader_spi_attach_cmd(uint32_t config) -{ - spi_attach_command_t attach_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SPI_ATTACH, - .size = CMD_SIZE(attach_cmd), - .checksum = 0 - }, - .configuration = config, - .zero = 0 - }; - - return send_cmd(&attach_cmd, sizeof(attach_cmd), NULL); -} - -esp_loader_error_t loader_change_baudrate_cmd(uint32_t baudrate) -{ - change_baudrate_command_t baudrate_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = CHANGE_BAUDRATE, - .size = CMD_SIZE(baudrate_cmd), - .checksum = 0 - }, - .new_baudrate = baudrate, - .old_baudrate = 0 // ESP32 ROM only - }; - - return send_cmd(&baudrate_cmd, sizeof(baudrate_cmd), NULL); -} - -esp_loader_error_t loader_md5_cmd(uint32_t address, uint32_t size, uint8_t *md5_out) -{ - spi_flash_md5_command_t md5_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SPI_FLASH_MD5, - .size = CMD_SIZE(md5_cmd), - .checksum = 0 - }, - .address = address, - .size = size, - .reserved_0 = 0, - .reserved_1 = 0 - }; - - return send_cmd_md5(&md5_cmd, sizeof(md5_cmd), md5_out); -} - -esp_loader_error_t loader_spi_parameters(uint32_t total_size) -{ - write_spi_command_t spi_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SPI_SET_PARAMS, - .size = 24, - .checksum = 0 - }, - .id = 0, - .total_size = total_size, - .block_size = 64 * 1024, - .sector_size = 4 * 1024, - .page_size = 0x100, - .status_mask = 0xFFFF, - }; - - return send_cmd(&spi_cmd, sizeof(spi_cmd), NULL); -} - -__attribute__ ((weak)) void loader_port_debug_print(const char *str) -{ - (void)(str); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c deleted file mode 100644 index bd04fe79f..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c +++ /dev/null @@ -1,312 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "protocol_prv.h" -#include "esp_loader_io.h" -#include -#include - -typedef struct __attribute__((packed)) { - uint8_t cmd; - uint8_t addr; - uint8_t dummy; -} transaction_preamble_t; - -typedef enum { - TRANS_CMD_WRBUF = 0x01, - TRANS_CMD_RDBUF = 0x02, - TRANS_CMD_WRDMA = 0x03, - TRANS_CMD_RDDMA = 0x04, - TRANS_CMD_SEG_DONE = 0x05, - TRANS_CMD_ENQPI = 0x06, - TRANS_CMD_WR_DONE = 0x07, - TRANS_CMD_CMD8 = 0x08, - TRANS_CMD_CMD9 = 0x09, - TRANS_CMD_CMDA = 0x0A, - TRANS_CMD_EXQPI = 0xDD, -} transaction_cmd_t; - -/* Slave protocol registers */ -typedef enum { - SLAVE_REGISTER_VER = 0, - SLAVE_REGISTER_RXSTA = 4, - SLAVE_REGISTER_TXSTA = 8, - SLAVE_REGISTER_CMD = 12, -} slave_register_addr_t; - -#define SLAVE_STA_TOGGLE_BIT (0x01U << 0) -#define SLAVE_STA_INIT_BIT (0x01U << 1) -#define SLAVE_STA_BUF_LENGTH_POS 2U - -typedef enum { - SLAVE_STATE_INIT = SLAVE_STA_TOGGLE_BIT | SLAVE_STA_INIT_BIT, - SLAVE_STATE_FIRST_PACKET = SLAVE_STA_INIT_BIT, -} slave_state_t; - -typedef enum { - /* Target to host */ - SLAVE_CMD_IDLE = 0xAA, - SLAVE_CMD_READY = 0xA5, - /* Host to target */ - SLAVE_CMD_REBOOT = 0xFE, - SLAVE_CMD_COMM_REINIT = 0x5A, - SLAVE_CMD_DONE = 0x55, -} slave_cmd_t; - -static uint8_t s_slave_seq_tx; -static uint8_t s_slave_seq_rx; - -static esp_loader_error_t write_slave_reg(const uint8_t *data, const uint32_t addr, - const uint8_t size); -static esp_loader_error_t read_slave_reg(uint8_t *out_data, const uint32_t addr, - const uint8_t size); -static esp_loader_error_t handle_slave_state(const uint32_t status_reg_addr, uint8_t *seq_state, - bool *slave_ready, uint32_t *buf_size); -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value); - -esp_loader_error_t loader_initialize_conn(esp_loader_connect_args_t *connect_args) -{ - for (uint8_t trial = 0; trial < connect_args->trials; trial++) { - uint8_t slave_ready_flag; - RETURN_ON_ERROR(read_slave_reg(&slave_ready_flag, SLAVE_REGISTER_CMD, - sizeof(slave_ready_flag))); - - if (slave_ready_flag != SLAVE_CMD_IDLE) { - loader_port_debug_print("Waiting for Slave to be idle...\n"); - loader_port_delay_ms(100); - } else { - break; - } - } - - const uint8_t reg_val = SLAVE_CMD_READY; - RETURN_ON_ERROR(write_slave_reg(®_val, SLAVE_REGISTER_CMD, sizeof(reg_val))); - - for (uint8_t trial = 0; trial < connect_args->trials; trial++) { - uint8_t slave_ready_flag; - RETURN_ON_ERROR(read_slave_reg(&slave_ready_flag, SLAVE_REGISTER_CMD, - sizeof(slave_ready_flag))); - - if (slave_ready_flag != SLAVE_CMD_READY) { - loader_port_debug_print("Waiting for Slave to be ready...\n"); - loader_port_delay_ms(100); - } else { - break; - } - } - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value) -{ - command_t command = ((const command_common_t *)cmd_data)->command; - - uint32_t buf_size; - bool slave_ready = false; - while (!slave_ready) { - RETURN_ON_ERROR(handle_slave_state(SLAVE_REGISTER_RXSTA, &s_slave_seq_rx, &slave_ready, - &buf_size)); - } - - if (size > buf_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - /* Start and write the command */ - transaction_preamble_t preamble = {.cmd = TRANS_CMD_WRDMA}; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)cmd_data, size, - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - /* Terminate the write */ - loader_port_spi_set_cs(0); - preamble.cmd = TRANS_CMD_WR_DONE; - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - return check_response(command, reg_value); -} - - -esp_loader_error_t send_cmd_with_data(const void *cmd_data, size_t cmd_size, - const void *data, size_t data_size) -{ - uint32_t buf_size; - bool slave_ready = false; - while (!slave_ready) { - RETURN_ON_ERROR(handle_slave_state(SLAVE_REGISTER_RXSTA, &s_slave_seq_rx, &slave_ready, - &buf_size)); - } - - if (cmd_size + data_size > buf_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - /* Start and write the command and the data */ - transaction_preamble_t preamble = {.cmd = TRANS_CMD_WRDMA}; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)cmd_data, cmd_size, - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)data, data_size, - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - /* Terminate the write */ - loader_port_spi_set_cs(0); - preamble.cmd = TRANS_CMD_WR_DONE; - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - command_t command = ((const command_common_t *)cmd_data)->command; - return check_response(command, NULL); -} - - -static esp_loader_error_t read_slave_reg(uint8_t *out_data, const uint32_t addr, - const uint8_t size) -{ - transaction_preamble_t preamble = { - .cmd = TRANS_CMD_RDBUF, - .addr = addr, - }; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_read(out_data, size, loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t write_slave_reg(const uint8_t *data, const uint32_t addr, - const uint8_t size) -{ - transaction_preamble_t preamble = { - .cmd = TRANS_CMD_WRBUF, - .addr = addr, - }; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write(data, size, loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t handle_slave_state(const uint32_t status_reg_addr, uint8_t *seq_state, - bool *slave_ready, uint32_t *buf_size) -{ - uint32_t status_reg; - RETURN_ON_ERROR(read_slave_reg((uint8_t *)&status_reg, status_reg_addr, - sizeof(status_reg))); - const slave_state_t state = status_reg & (SLAVE_STA_TOGGLE_BIT | SLAVE_STA_INIT_BIT); - - switch(state) { - case SLAVE_STATE_INIT: { - const uint32_t initial = 0U; - RETURN_ON_ERROR(write_slave_reg((uint8_t *)&initial, status_reg_addr, sizeof(initial))); - break; - } - - case SLAVE_STATE_FIRST_PACKET: { - *seq_state = state & SLAVE_STA_TOGGLE_BIT; - *buf_size = status_reg >> SLAVE_STA_BUF_LENGTH_POS; - *slave_ready = true; - break; - } - - default: { - const uint8_t new_seq = state & SLAVE_STA_TOGGLE_BIT; - if (new_seq != *seq_state) { - *seq_state = new_seq; - *buf_size = status_reg >> SLAVE_STA_BUF_LENGTH_POS; - *slave_ready = true; - } - break; - } - } - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value) -{ - response_t resp; - - uint32_t buf_size; - bool slave_ready = false; - while (!slave_ready) { - RETURN_ON_ERROR(handle_slave_state(SLAVE_REGISTER_TXSTA, &s_slave_seq_tx, &slave_ready, - &buf_size)); - } - - if (sizeof(resp) > buf_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - transaction_preamble_t preamble = { - .cmd = TRANS_CMD_RDDMA, - }; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_read((uint8_t *)&resp, sizeof(resp), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - /* Terminate the read */ - loader_port_spi_set_cs(0); - preamble.cmd = TRANS_CMD_CMD8; - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - common_response_t *common = (common_response_t *)&resp; - if ((common->direction != READ_DIRECTION) || (common->command != cmd)) { - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - - response_status_t *status = - (response_status_t *)((uint8_t *)&resp + sizeof(resp) - sizeof(response_status_t)); - if (status->failed) { - log_loader_internal_error(status->error); - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - - if (reg_value != NULL) { - *reg_value = common->value; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c deleted file mode 100644 index c5a51cec6..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "protocol_prv.h" -#include "esp_loader_io.h" -#include "slip.h" -#include -#include - -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value, void* resp, uint32_t resp_size); - -esp_loader_error_t loader_initialize_conn(esp_loader_connect_args_t *connect_args) { - esp_loader_error_t err; - int32_t trials = connect_args->trials; - - do { - loader_port_start_timer(connect_args->sync_timeout); - err = loader_sync_cmd(); - if (err == ESP_LOADER_ERROR_TIMEOUT) { - if (--trials == 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } - loader_port_delay_ms(100); - } else if (err != ESP_LOADER_SUCCESS) { - return err; - } - } while (err != ESP_LOADER_SUCCESS); - - return err; -} - -esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value) -{ - response_t response; - command_t command = ((const command_common_t *)cmd_data)->command; - - RETURN_ON_ERROR( SLIP_send_delimiter() ); - RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, size) ); - RETURN_ON_ERROR( SLIP_send_delimiter() ); - - return check_response(command, reg_value, &response, sizeof(response)); -} - - -esp_loader_error_t send_cmd_with_data(const void *cmd_data, size_t cmd_size, - const void *data, size_t data_size) -{ - response_t response; - command_t command = ((const command_common_t *)cmd_data)->command; - - RETURN_ON_ERROR( SLIP_send_delimiter() ); - RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, cmd_size) ); - RETURN_ON_ERROR( SLIP_send(data, data_size) ); - RETURN_ON_ERROR( SLIP_send_delimiter() ); - - return check_response(command, NULL, &response, sizeof(response)); -} - - -esp_loader_error_t send_cmd_md5(const void *cmd_data, size_t cmd_size, uint8_t md5_out[MD5_SIZE]) -{ - rom_md5_response_t response; - command_t command = ((const command_common_t *)cmd_data)->command; - - RETURN_ON_ERROR( SLIP_send_delimiter() ); - RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, cmd_size) ); - RETURN_ON_ERROR( SLIP_send_delimiter() ); - - RETURN_ON_ERROR( check_response(command, NULL, &response, sizeof(response)) ); - - memcpy(md5_out, response.md5, MD5_SIZE); - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value, void* resp, uint32_t resp_size) -{ - esp_loader_error_t err; - common_response_t *response = (common_response_t *)resp; - - do { - err = SLIP_receive_packet(resp, resp_size); - if (err != ESP_LOADER_SUCCESS) { - return err; - } - } while ((response->direction != READ_DIRECTION) || (response->command != cmd)); - - response_status_t *status = (response_status_t *)((uint8_t *)resp + resp_size - sizeof(response_status_t)); - - if (status->failed) { - log_loader_internal_error(status->error); - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - - if (reg_value != NULL) { - *reg_value = response->value; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c deleted file mode 100644 index ba926169c..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "slip.h" -#include "esp_loader_io.h" - -static const uint8_t DELIMITER = 0xC0; -static const uint8_t C0_REPLACEMENT[2] = {0xDB, 0xDC}; -static const uint8_t DB_REPLACEMENT[2] = {0xDB, 0xDD}; - -static inline esp_loader_error_t peripheral_read(uint8_t *buff, const size_t size) -{ - return loader_port_read(buff, size, loader_port_remaining_time()); -} - -static inline esp_loader_error_t peripheral_write(const uint8_t *buff, const size_t size) -{ - return loader_port_write(buff, size, loader_port_remaining_time()); -} - -esp_loader_error_t SLIP_receive_data(uint8_t *buff, const size_t size) -{ - uint8_t ch; - - for (uint32_t i = 0; i < size; i++) { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - - if (ch == 0xDB) { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - if (ch == 0xDC) { - buff[i] = 0xC0; - } else if (ch == 0xDD) { - buff[i] = 0xDB; - } else { - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - } else { - buff[i] = ch; - } - } - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t SLIP_receive_packet(uint8_t *buff, const size_t size) -{ - uint8_t ch; - - // Wait for delimiter - do { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - } while (ch != DELIMITER); - - // Workaround: bootloader sends two dummy(0xC0) bytes after response when baud rate is changed. - do { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - } while (ch == DELIMITER); - - buff[0] = ch; - - RETURN_ON_ERROR( SLIP_receive_data(&buff[1], size - 1) ); - - // Wait for delimiter - do { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - } while (ch != DELIMITER); - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t SLIP_send(const uint8_t *data, const size_t size) -{ - uint32_t to_write = 0; // Bytes ready to write as they are - uint32_t written = 0; // Bytes already written - - for (uint32_t i = 0; i < size; i++) { - if (data[i] != 0xC0 && data[i] != 0xDB) { - to_write++; // Queue this byte for writing - continue; - } - - // We have a byte that needs encoding, write the queue first - if (to_write > 0) { - RETURN_ON_ERROR( peripheral_write(&data[written], to_write) ); - } - - // Write the encoded byte - if (data[i] == 0xC0) { - RETURN_ON_ERROR( peripheral_write(C0_REPLACEMENT, 2) ); - } else { - RETURN_ON_ERROR( peripheral_write(DB_REPLACEMENT, 2) ); - } - - // Update to start again after the encoded byte - written = i + 1; - to_write = 0; - } - - // Write the rest of the bytes that didn't need encoding - if (to_write > 0) { - RETURN_ON_ERROR( peripheral_write(&data[written], to_write) ); - } - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t SLIP_send_delimiter(void) -{ - return peripheral_write(&DELIMITER, 1); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt deleted file mode 100644 index 97da4eaae..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -if (CONFIG_ESP_SERIAL_FLASHER) - zephyr_include_directories( - "${ZEPHYR_CURRENT_MODULE_DIR}/include" - "${ZEPHYR_CURRENT_MODULE_DIR}/port" - "${ZEPHYR_CURRENT_MODULE_DIR}/private_include" - ) - - zephyr_interface_library_named(esp_flasher) - - zephyr_library() - - zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/esp_loader.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/esp_targets.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/protocol_common.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/protocol_uart.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/slip.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/md5_hash.c - ${ZEPHYR_CURRENT_MODULE_DIR}/port/zephyr_port.c - ) - - target_compile_definitions(esp_flasher INTERFACE SERIAL_FLASHER_INTERFACE_UART) - - zephyr_library_link_libraries(esp_flasher) - - if(DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED) - target_compile_definitions(esp_flasher INTERFACE -DMD5_ENABLED=1) - endif() -endif() diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig deleted file mode 100644 index ebb524c86..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig +++ /dev/null @@ -1,16 +0,0 @@ -config ESP_SERIAL_FLASHER - bool "Enable ESP serial flasher library" - default y - select CONSOLE_SUBSYS - help - Select this option to enable the ESP serial flasher library. - -config ESP_SERIAL_FLASHER_UART_BUFSIZE - int "ESP Serial Flasher UART buffer size" - default 512 - help - Buffer size for UART TX and RX packets - -if ESP_SERIAL_FLASHER - rsource "../Kconfig" -endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml deleted file mode 100644 index 01d484fcb..000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: esp-flasher - -build: - cmake: zephyr - kconfig: zephyr/Kconfig diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h index 402fca479..d223af79a 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h @@ -13,4 +13,3 @@ ADD_SCENE(wifi_marauder, script_stage_edit, ScriptStageEdit) ADD_SCENE(wifi_marauder, script_stage_add, ScriptStageAdd) ADD_SCENE(wifi_marauder, script_stage_edit_list, ScriptStageEditList) ADD_SCENE(wifi_marauder, sniffpmkid_options, SniffPmkidOptions) -ADD_SCENE(wifi_marauder, flasher, Flasher) diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c index 9e1719d08..05d94fe80 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c @@ -1,7 +1,5 @@ #include "../wifi_marauder_app_i.h" -#include "../wifi_marauder_flasher.h" - char* _wifi_marauder_get_prefix_from_cmd(const char* command) { int end = strcspn(command, " "); char* prefix = (char*)malloc(sizeof(char) * (end + 1)); @@ -103,24 +101,13 @@ void wifi_marauder_scene_console_output_on_enter(void* context) { view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput); // Register callbacks to receive data - // setup callback for general log rx thread - if(app->flash_mode) { - wifi_marauder_uart_set_handle_rx_data_cb( - app->uart, - wifi_marauder_flash_handle_rx_data_cb); // setup callback for general log rx thread - } else { - wifi_marauder_uart_set_handle_rx_data_cb( - app->uart, - wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread - } + wifi_marauder_uart_set_handle_rx_data_cb( + app->uart, + wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread wifi_marauder_uart_set_handle_rx_data_cb( app->lp_uart, wifi_marauder_console_output_handle_rx_packets_cb); // setup callback for packets rx thread - if(app->flash_mode) { - wifi_marauder_flash_start_thread(app); - } - // Get ready to send command if((app->is_command && app->selected_tx_string) || app->script) { const char* prefix = @@ -182,11 +169,6 @@ bool wifi_marauder_scene_console_output_on_event(void* context, SceneManagerEven consumed = true; } else if(event.type == SceneManagerEventTypeTick) { consumed = true; - } else { - if(app->flash_worker_busy) { - // ignore button presses while flashing - consumed = true; - } } return consumed; @@ -201,10 +183,6 @@ void wifi_marauder_scene_console_output_on_exit(void* context) { furi_delay_ms(50); } - if(app->flash_mode) { - wifi_marauder_flash_stop_thread(app); - } - // Unregister rx callback wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL); wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, NULL); diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c deleted file mode 100644 index 2d6b8ea50..000000000 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c +++ /dev/null @@ -1,266 +0,0 @@ -#include "../wifi_marauder_app_i.h" -#include "../wifi_marauder_flasher.h" - -enum SubmenuIndex { - SubmenuIndexS3Mode, - SubmenuIndexBoot, - SubmenuIndexPart, - SubmenuIndexNvs, - SubmenuIndexBootApp0, - SubmenuIndexApp, - SubmenuIndexCustom, - SubmenuIndexFlash, -}; - -static void wifi_marauder_scene_flasher_callback(void* context, uint32_t index) { - WifiMarauderApp* app = context; - - scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneFlasher, index); - - // browse for files - FuriString* predefined_filepath = furi_string_alloc_set_str(MARAUDER_APP_FOLDER); - FuriString* selected_filepath = furi_string_alloc(); - DialogsFileBrowserOptions browser_options; - dialog_file_browser_set_basic_options(&browser_options, ".bin", &I_Text_10x10); - - // TODO refactor - switch(index) { - case SubmenuIndexS3Mode: - // toggle S3 mode - app->selected_flash_options[SelectedFlashS3Mode] = - !app->selected_flash_options[SelectedFlashS3Mode]; - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexBoot: - app->selected_flash_options[SelectedFlashBoot] = - !app->selected_flash_options[SelectedFlashBoot]; - if(app->selected_flash_options[SelectedFlashBoot]) { - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_boot, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_boot)); - } - } - if(app->bin_file_path_boot[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashBoot] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexPart: - app->selected_flash_options[SelectedFlashPart] = - !app->selected_flash_options[SelectedFlashPart]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_part, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_part)); - } - if(app->bin_file_path_part[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashPart] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexNvs: - app->selected_flash_options[SelectedFlashNvs] = - !app->selected_flash_options[SelectedFlashNvs]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_nvs, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_nvs)); - } - if(app->bin_file_path_nvs[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashNvs] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexBootApp0: - app->selected_flash_options[SelectedFlashBootApp0] = - !app->selected_flash_options[SelectedFlashBootApp0]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_boot_app0, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_boot_app0)); - } - if(app->bin_file_path_boot_app0[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashBootApp0] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexApp: - app->selected_flash_options[SelectedFlashApp] = - !app->selected_flash_options[SelectedFlashApp]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_app, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_app)); - } - if(app->bin_file_path_app[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashApp] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexCustom: - app->selected_flash_options[SelectedFlashCustom] = - !app->selected_flash_options[SelectedFlashCustom]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_custom, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_custom)); - } - if(app->bin_file_path_custom[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashCustom] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexFlash: - // count how many options are selected - app->num_selected_flash_options = 0; - for(bool* option = &app->selected_flash_options[SelectedFlashBoot]; - option < &app->selected_flash_options[NUM_FLASH_OPTIONS]; - ++option) { - if(*option) { - ++app->num_selected_flash_options; - } - } - if(app->num_selected_flash_options) { - // only start next scene if at least one option is selected - scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput); - } - break; - } - - furi_string_free(selected_filepath); - furi_string_free(predefined_filepath); -} - -#define STR_SELECT "[x]" -#define STR_UNSELECT "[ ]" -#define STR_BOOT "Bootloader (" TOSTRING(ESP_ADDR_BOOT) ")" -#define STR_BOOT_S3 "Bootloader (" TOSTRING(ESP_ADDR_BOOT_S3) ")" -#define STR_PART "Part Table (" TOSTRING(ESP_ADDR_PART) ")" -#define STR_NVS "NVS (" TOSTRING(ESP_ADDR_NVS) ")" -#define STR_BOOT_APP0 "boot_app0 (" TOSTRING(ESP_ADDR_BOOT_APP0) ")" -#define STR_APP "Firmware (" TOSTRING(ESP_ADDR_APP) ")" -#define STR_CUSTOM "Custom" -#define STR_FLASH_S3 "[>] FLASH (ESP32-S3)" -#define STR_FLASH "[>] FLASH" -static void _refresh_submenu(WifiMarauderApp* app) { - Submenu* submenu = app->submenu; - - submenu_reset(app->submenu); - - submenu_set_header(submenu, "Browse for files to flash"); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashS3Mode] ? "[x] Using ESP32-S3" : - "[ ] Check if using S3", - SubmenuIndexS3Mode, - wifi_marauder_scene_flasher_callback, - app); - const char* strSelectBootloader = STR_UNSELECT " " STR_BOOT; - if(app->selected_flash_options[SelectedFlashS3Mode]) { - if(app->selected_flash_options[SelectedFlashBoot]) { - strSelectBootloader = STR_SELECT " " STR_BOOT_S3; - } else { - strSelectBootloader = STR_UNSELECT " " STR_BOOT_S3; - } - } else { - if(app->selected_flash_options[SelectedFlashBoot]) { - strSelectBootloader = STR_SELECT " " STR_BOOT; - } else { - strSelectBootloader = STR_UNSELECT " " STR_BOOT; - } - } - submenu_add_item( - submenu, strSelectBootloader, SubmenuIndexBoot, wifi_marauder_scene_flasher_callback, app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashPart] ? STR_SELECT " " STR_PART : - STR_UNSELECT " " STR_PART, - SubmenuIndexPart, - wifi_marauder_scene_flasher_callback, - app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashNvs] ? STR_SELECT " " STR_NVS : - STR_UNSELECT " " STR_NVS, - SubmenuIndexNvs, - wifi_marauder_scene_flasher_callback, - app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashBootApp0] ? STR_SELECT " " STR_BOOT_APP0 : - STR_UNSELECT " " STR_BOOT_APP0, - SubmenuIndexBootApp0, - wifi_marauder_scene_flasher_callback, - app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashApp] ? STR_SELECT " " STR_APP : - STR_UNSELECT " " STR_APP, - SubmenuIndexApp, - wifi_marauder_scene_flasher_callback, - app); - // TODO: custom addr - //submenu_add_item( - // submenu, app->selected_flash_options[SelectedFlashCustom] ? STR_SELECT " " STR_CUSTOM : STR_UNSELECT " " STR_CUSTOM, SubmenuIndexCustom, wifi_marauder_scene_flasher_callback, app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashS3Mode] ? STR_FLASH_S3 : STR_FLASH, - SubmenuIndexFlash, - wifi_marauder_scene_flasher_callback, - app); - - submenu_set_selected_item( - submenu, scene_manager_get_scene_state(app->scene_manager, WifiMarauderSceneFlasher)); - view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewSubmenu); -} - -void wifi_marauder_scene_flasher_on_enter(void* context) { - WifiMarauderApp* app = context; - - memset(app->selected_flash_options, 0, sizeof(app->selected_flash_options)); - app->bin_file_path_boot[0] = '\0'; - app->bin_file_path_part[0] = '\0'; - app->bin_file_path_nvs[0] = '\0'; - app->bin_file_path_boot_app0[0] = '\0'; - app->bin_file_path_app[0] = '\0'; - app->bin_file_path_custom[0] = '\0'; - - _refresh_submenu(app); -} - -bool wifi_marauder_scene_flasher_on_event(void* context, SceneManagerEvent event) { - WifiMarauderApp* app = context; - bool consumed = false; - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == WifiMarauderEventRefreshSubmenu) { - _refresh_submenu(app); - consumed = true; - } - } - - return consumed; -} - -void wifi_marauder_scene_flasher_on_exit(void* context) { - WifiMarauderApp* app = context; - submenu_reset(app->submenu); -} diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c index 97b26fc7f..6ce66b1a4 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c @@ -68,6 +68,13 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { NO_ARGS, FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP}, + {"Evil Portal", + {"start"}, + 1, + {"evilportal -c start"}, + NO_ARGS, + FOCUS_CONSOLE_END, + SHOW_STOPSCAN_TIP}, {"Targeted Deauth", {"station", "manual"}, 2, @@ -83,11 +90,10 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP}, {"Sniff", - {"beacon", "deauth", "esp", "pmkid", "probe", "pwn", "raw", "bt", "skim"}, - 9, + {"beacon", "deauth", "pmkid", "probe", "pwn", "raw", "bt", "skim"}, + 8, {"sniffbeacon", "sniffdeauth", - "sniffesp", "sniffpmkid", "sniffprobe", "sniffpwn", @@ -105,6 +111,13 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { TOGGLE_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"LED", + {"hex", "pattern"}, + 2, + {"led -s", "led -p"}, + INPUT_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, {"Settings", {"display", "restore", "ForcePMKID", "ForceProbe", "SavePCAP", "EnableLED", "other"}, 7, @@ -118,10 +131,9 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { TOGGLE_ARGS, FOCUS_CONSOLE_START, NO_TIP}, - {"Update", {"ota", "sd"}, 2, {"update -w", "update -s"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"Update", {"sd"}, 1, {"update -s"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Reboot", {""}, 1, {"reboot"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP}, - {"Reflash ESP32 (WIP)", {""}, 1, {""}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Scripts", {""}, 1, {""}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Save to flipper sdcard", // keep as last entry or change logic in callback below {""}, @@ -150,17 +162,6 @@ static void wifi_marauder_scene_start_var_list_enter_callback(void* context, uin item->focus_console; app->show_stopscan_tip = item->show_stopscan_tip; - // TODO cleanup - if(index == NUM_MENU_ITEMS - 3) { - // flasher - app->is_command = false; - app->flash_mode = true; - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartFlasher); - return; - } - - app->flash_mode = false; - if(!app->is_command && selected_option_index == 0) { // View Log from start view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartLogViewer); @@ -243,6 +244,7 @@ void wifi_marauder_scene_start_on_enter(void* context) { } bool wifi_marauder_scene_start_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); WifiMarauderApp* app = context; bool consumed = false; @@ -271,10 +273,6 @@ bool wifi_marauder_scene_start_on_event(void* context, SceneManagerEvent event) scene_manager_set_scene_state( app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index); scene_manager_next_scene(app->scene_manager, WifiMarauderSceneSniffPmkidOptions); - } else if(event.event == WifiMarauderEventStartFlasher) { - scene_manager_set_scene_state( - app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index); - scene_manager_next_scene(app->scene_manager, WifiMarauderSceneFlasher); } consumed = true; } else if(event.type == SceneManagerEventTypeTick) { diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c index 66a508f66..e6091a410 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c @@ -46,9 +46,7 @@ void wifi_marauder_scene_text_input_on_enter(void* context) { // Setup view WIFI_TextInput* text_input = app->text_input; // Add help message to header - if(app->flash_mode) { - wifi_text_input_set_header_text(text_input, "Enter destination address"); - } else if(app->special_case_input_step == 1) { + if(app->special_case_input_step == 1) { wifi_text_input_set_header_text(text_input, "Enter source MAC"); } else if(0 == strncmp("ssid -a -g", app->selected_tx_string, strlen("ssid -a -g"))) { wifi_text_input_set_header_text(text_input, "Enter # SSIDs to generate"); diff --git a/applications/external/wifi_marauder_companion/screenshots/marauder-save-pcaps.png b/applications/external/wifi_marauder_companion/screenshots/marauder-save-pcaps.png new file mode 100755 index 0000000000000000000000000000000000000000..dd4bcc1a0ea4b5bf86b0cd8d5dfb66ae557ca216 GIT binary patch literal 2336 zcmb7GZBSF$89tFJB45^)1y>Sw)~Qq&Tp$CAB$4i_E9nHUMt_*m+PD z{%%JA*#A88>~CW7_{&pC+?iuudj}dW2ly`bz5iEfqi^p=ziepyIey^P*yuXHHFE3b zlMXSsnY_Ja>M7l}Y#9wcM+xiSU`;q-6>(!+C3FVzke`8wU!%Z5y&CorS%=74p_ME! z;aF9~`MSN};3oileF%UD_ftVN4JJa<8u7eQRLI#fZV2I8e|_e4En57jI0(G8n(9GE zwZPnj2?@7tA`~z7%T{r;5BS&#$^3e;VQ>%F|0@7KbOJ?}3@T2^nrAC~AL{l{O0vh8 zk`>MGOj^IvLeAgryt4~!2Lp4x6H6Gc!x^X71GO}>$fwu@SvkYQod`UB!OW^8ptH9DZm^{v$Xd>rQUH64(7B-BPhIm8WX&rq4$@Hs8|jR0Y9 z+coZm#m*Wsx)~;r`9fVMR!0fZK*J=?Q3jI1-X1`qjTFYWPzT)T-lV3|7u*v7Axx9<# z2;?{Hn4eO#>ZMJC+`45^vaX@8{RFq3LDY_v!JXjwJ>+`A_Mm>z!1Ecn^2BmAOxT*v zYg?>-MSiqP;M zH%Y`~tk(DtvNmXfu^2h$e(E9LyADNB`**V)Hn0CVvxT(SjcX{)tMFB;%EYrn^Lg?z zG26okz^Q|~!mR)JHmaoXV#@XYmBA1#q$qEOJF(`f_|}dJs9UM(`V=ju5Vr;Jn8+mn z3E~5Tf!jKkHVB$UxtCvukCE2 zyTN%GYGPd4Vh}Jg{H3JuYz2=wKPJ^B_OBQC>O23!$C}~?HMs2C_@1%l&4n-n&r~p{ zHIvdtUrvl86EqC2=R<-R ziC`@FOn&a_Dh-W}W#qfDmJ+SLYNIl@o`~d$v4~cas|V-XXKKt!K10$ZYRBOPnghus zB}pfs8rikUW(D+Gpo7%yYmhjpxr+(c3efHgYFKcp^pA#cw;tQjM>w*|i>N zn2>09kJ3`P5j?6b78|xleeB2mThq!h`n(%JTr9DC3|J{?zh? zOUm`6yZU9}VfUibkofl@%@&?tZ!IEXt<>>*AMY0h!fpqosl4)vI49c{SR2V>xvXl> zQ$0Fu;Ua@Z6Gtp2dYIR|vsX_cj8Z^%`5tC(lPp=HWd>F2aH@wS!$MYTN!3L}ra8A! z61drqpMRq0a*gaF#C5b;VT7lhhj*#Y|I7n__~M$y^3{((>i|;j+1oIR{foR}0$ddw zx9xZ@$QT~|V~0e4G71s-srZCEiFX&|luT42YrAvO+pYS|!H<|)oUia-j($6HXxMh; P0g>lEJ1hP$<*WYy?q1WU literal 0 HcmV?d00001 diff --git a/applications/external/wifi_marauder_companion/screenshots/marauder-script-demo.png b/applications/external/wifi_marauder_companion/screenshots/marauder-script-demo.png new file mode 100755 index 0000000000000000000000000000000000000000..900fcef7ee210335f4552a2c96a958c58f9704a8 GIT binary patch literal 1599 zcmb`IYfO_@7{{Nt6>1SE*%o2qkS}ga8d7G1$fd1l8G?ySGOjAAX3`CW;i^Jut94sM zAi}b2PR4aI24=KY2}LQ@vWXKmDaxfodf_rILW@+WU}<45vD$;lzU{-C^X9zgJm>%X zp8s>+f{*q^dAMzI0|1ZcJ?uCD0{)7@`qd%kX>uSwkhAwB^8h^WtUlQHR8L<37jrZ_ z;^W+MlP;oobo*P84|YtBeIiO`_iLuf+k!~D?tJ@c&#eh}-;0Iu>5FG=)_+C~XO^u* z@sp<$hTAJEbeazdeBS`rPXPZI05%!K?_=P#72xtZ*!dm6dB?{oO<|dzDdMoTV zG+_|JSCLUQ+h>Umc1W-nh;*p)TjwEp-YEiFaFn^Hh&Wmk#nzaW~tmLgt>= zm{sp>BfdH%y~QKE@T@8bkS4dh*sp77%JxhJ$+1rxEC2jm@2v6Oo_D-N9TRQlV zsI@S|H20ZB3VjbL^>?SNdQ&>+>-2vZ8B04hjajAvoM)ggaDY<#w&uH z(^KXd3}$)UDa;Dsv;IY%wXQJRCY@h*342vp%e0ONoB$DkyW{YbhonG7unVwiC?NjK zk%O+E6ey6(8qZ^?ySD%k9iGt3y}OT93`sLeW@>V<#e{rAEzOSvWnM1;PRTc^4oyGi zT8YI>y1-O;4Ksd-?7ldUHRw0ovxceoh)9ck4wz$HOc;uYdXz=0rZ3$5B4FnQCV;C$ z6+_PeI6c$(d;+Q16%2$jDkBz|Vi+Zq+2k~h-GV{jOKpb@Lh-u@`>e1xeZ-8%I1PV? z+nG2uWWhWhI0Vu3kOW>wU7gK=FQ?Vv%+5NDu-6KenzG`C<(mpiurYjlHPRpTgH}k> z+>jIyThAd0DKlx+1EFokChAOx!1Q3Ek0nkFwH4=?aesa72;1BT=W_Paj4mhAM8ZgQ z+pyrex3oe@QMn-yn|`Kn+FNXg60|)(GG%l`b>1K!xD81Mu2w|4S0idm`Z7kM5}w>< z4IYqLg@ls?PB20+0H-RWAYtNgtD%kBQK|wXY7LwgyVU8kS_%yP`9H#KwqW5`Kd3NE z?4+oS%*HA#=|0ltTSdU_Z<2hqmhNgJ?*F{)*oEPHvW=&P?e?0gAc4B(8g}sbqJ3`U zILOEjU*ng7wrL|vF@Cz;=u<2e{Sr&KQH0bfGm)4pKce)jM(r$@V!12t457A7i6dUp z6|GDfxC@;uo~hJ4$%0!2NFYXQ24z-BfezjjO$ zckN8TvN_!iHFrKPN(ob|Cw3J5dVXNt?vO&m2}{5>hgU6Es>hNir!DH0GQz#LWVR`* zYL}&K2V=jZ7j0 z^+&Iklfa`2Tbh}i+5$m;iWcXl`1v@@mdyph)=oZjNv_MOUVNcUT-Tw!&*U$ndD?bP z*`(t?j-jUV9EaI1J6oK;^kH!?wFSo?i_;hWL4^93(OLE;clv-~=rqxY7E=H#we^U<+)SCp(>{_8{7*?!hTi6Y@`*~t^)lU##2v-hU_{O*E|?TYUZ;Z4}qjtO8W zmCV+7QE>ckb-w!^ui^t#d0_C8`hcTaQ*-8^sM*=LUH|9?4!Yt#WSIUgwn{@xOG_?_ zb2Vy{Dz)^{M9HAZJXIx=YP_d4BLwJnMF1UveoocnEVp=1$1I=p_fy3N;FRox1CvEm zi7Hxg8K-;Ew3EB;O+V{PJw%`boc+(U->t(=kr_A_D|xGYK*k`0;1K55FaZww;<_U~ zYa4Nl?;~!@QH{MH!sSH;!BKR?Q%jQgpq^@=%n$`ET-mujRDsqUogk&?!j`n;qo!}$ zH=~SYGRbL*&;(&@F1O-T? z=4mU$1=7TD9QYjGs(YpaLLH4vO6O-%&xqT{MV?UqB9>*okq3>&d1;KY(P|31Q`oXM zcWwRQF{Nbbds)4_K+E(O9p3IT-2aIWqSFLo?`a0D6t{YFJQQH08%Or-4KzA=^FWVo#C{5oUj`V2*J zLJrF?X?{=~pZ}GKq6!qIXv~(Z2%x`?0TX4|Rz$CY6r&WZ3Q;TS(Epi?ZXj0lPVr0*c%;20OOuYZ`FzI&GeFJ9Sg-UnX9hUfL9z z|3cG)B)!{dTm@~3p%MBca3`RtL)wE2^@Y&I%LMPB!#*IP8DYmvK_Yu%?t zA4M}EnMsD2IK3Mp{B&epXeN{oScfvxQ?qX`2f0-vm6fQHRR6drgt)3B)WyqmEiSUd zvG)1?WZYFsmb${wv&zalQ7)g1DX%OPx^fHvQvQbQSlhrSC80l<(WeTc!ehc(Hl`i; E7q5hJfB*mh literal 0 HcmV?d00001 diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_app.c b/applications/external/wifi_marauder_companion/wifi_marauder_app.c index c27a941ad..97b1d9715 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_app.c +++ b/applications/external/wifi_marauder_companion/wifi_marauder_app.c @@ -86,9 +86,6 @@ WifiMarauderApp* wifi_marauder_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, WifiMarauderAppViewSubmenu, submenu_get_view(app->submenu)); - app->flash_mode = false; - app->flash_worker_busy = false; - scene_manager_next_scene(app->scene_manager, WifiMarauderSceneStart); return app; diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_app.h b/applications/external/wifi_marauder_companion/wifi_marauder_app.h index 187a0aaaa..ceacbb489 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_app.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_app.h @@ -4,7 +4,7 @@ extern "C" { #endif -#define WIFI_MARAUDER_APP_VERSION "v0.5.1" +#define WIFI_MARAUDER_APP_VERSION "v0.6.0" typedef struct WifiMarauderApp WifiMarauderApp; diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h b/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h index a5c4818f0..4920bd229 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h @@ -26,7 +26,7 @@ #include #include -#define NUM_MENU_ITEMS (19) +#define NUM_MENU_ITEMS (20) #define WIFI_MARAUDER_TEXT_BOX_STORE_SIZE (4096) #define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512) @@ -48,17 +48,6 @@ typedef enum WifiMarauderUserInputType { WifiMarauderUserInputTypeFileName } WifiMarauderUserInputType; -typedef enum SelectedFlashOptions { - SelectedFlashS3Mode, - SelectedFlashBoot, - SelectedFlashPart, - SelectedFlashNvs, - SelectedFlashBootApp0, - SelectedFlashApp, - SelectedFlashCustom, - NUM_FLASH_OPTIONS -} SelectedFlashOptions; - struct WifiMarauderApp { Gui* gui; ViewDispatcher* view_dispatcher; @@ -124,19 +113,6 @@ struct WifiMarauderApp { int special_case_input_step; char special_case_input_src_addr[20]; char special_case_input_dst_addr[20]; - - // For flashing - TODO: put into its own struct? - bool selected_flash_options[NUM_FLASH_OPTIONS]; - int num_selected_flash_options; - char bin_file_path_boot[100]; - char bin_file_path_part[100]; - char bin_file_path_nvs[100]; - char bin_file_path_boot_app0[100]; - char bin_file_path_app[100]; - char bin_file_path_custom[100]; - FuriThread* flash_worker; - bool flash_worker_busy; - bool flash_mode; }; // Supported commands: diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h b/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h index ff03f31dd..b6d9f8274 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h @@ -9,7 +9,5 @@ typedef enum { WifiMarauderEventStartSettingsInit, WifiMarauderEventStartLogViewer, WifiMarauderEventStartScriptSelect, - WifiMarauderEventStartSniffPmkidOptions, - WifiMarauderEventStartFlasher, - WifiMarauderEventRefreshSubmenu + WifiMarauderEventStartSniffPmkidOptions } WifiMarauderCustomEvent; diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.c b/applications/external/wifi_marauder_companion/wifi_marauder_flasher.c deleted file mode 100644 index ffc1acb78..000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.c +++ /dev/null @@ -1,251 +0,0 @@ -#include "wifi_marauder_flasher.h" - -FuriStreamBuffer* flash_rx_stream; // TODO make safe -WifiMarauderApp* global_app; // TODO make safe -FuriTimer* timer; // TODO make - -static uint32_t _remaining_time = 0; -static void _timer_callback(void* context) { - UNUSED(context); - if(_remaining_time > 0) { - _remaining_time--; - } -} - -static esp_loader_error_t _flash_file(WifiMarauderApp* app, char* filepath, uint32_t addr) { - // TODO cleanup - esp_loader_error_t err; - static uint8_t payload[1024]; - File* bin_file = storage_file_alloc(app->storage); - - char user_msg[256]; - - // open file - if(!storage_file_open(bin_file, filepath, FSAM_READ, FSOM_OPEN_EXISTING)) { - storage_file_close(bin_file); - storage_file_free(bin_file); - dialog_message_show_storage_error(app->dialogs, "Cannot open file"); - return ESP_LOADER_ERROR_FAIL; - } - - uint64_t size = storage_file_size(bin_file); - - loader_port_debug_print("Erasing flash...this may take a while\n"); - err = esp_loader_flash_start(addr, size, sizeof(payload)); - if(err != ESP_LOADER_SUCCESS) { - storage_file_close(bin_file); - storage_file_free(bin_file); - snprintf(user_msg, sizeof(user_msg), "Erasing flash failed with error %d\n", err); - loader_port_debug_print(user_msg); - return err; - } - - loader_port_debug_print("Start programming\n"); - uint64_t last_updated = size; - while(size > 0) { - if((last_updated - size) > 50000) { - // inform user every 50k bytes - // TODO: draw a progress bar next update - snprintf(user_msg, sizeof(user_msg), "%llu bytes left.\n", size); - loader_port_debug_print(user_msg); - last_updated = size; - } - size_t to_read = MIN(size, sizeof(payload)); - uint16_t num_bytes = storage_file_read(bin_file, payload, to_read); - err = esp_loader_flash_write(payload, num_bytes); - if(err != ESP_LOADER_SUCCESS) { - snprintf(user_msg, sizeof(user_msg), "Packet could not be written! Error: %u\n", err); - storage_file_close(bin_file); - storage_file_free(bin_file); - loader_port_debug_print(user_msg); - return err; - } - - size -= num_bytes; - } - - loader_port_debug_print("Finished programming\n"); - - // TODO verify - - storage_file_close(bin_file); - storage_file_free(bin_file); - - return ESP_LOADER_SUCCESS; -} - -typedef struct { - SelectedFlashOptions selected; - const char* description; - char* path; - uint32_t addr; -} FlashItem; - -static void _flash_all_files(WifiMarauderApp* app) { - esp_loader_error_t err; - const int num_steps = app->num_selected_flash_options; - -#define NUM_FLASH_ITEMS 6 - FlashItem items[NUM_FLASH_ITEMS] = { - {SelectedFlashBoot, - "bootloader", - app->bin_file_path_boot, - app->selected_flash_options[SelectedFlashS3Mode] ? ESP_ADDR_BOOT_S3 : ESP_ADDR_BOOT}, - {SelectedFlashPart, "partition table", app->bin_file_path_part, ESP_ADDR_PART}, - {SelectedFlashNvs, "NVS", app->bin_file_path_nvs, ESP_ADDR_NVS}, - {SelectedFlashBootApp0, "boot_app0", app->bin_file_path_boot_app0, ESP_ADDR_BOOT_APP0}, - {SelectedFlashApp, "firmware", app->bin_file_path_app, ESP_ADDR_APP}, - {SelectedFlashCustom, "custom data", app->bin_file_path_custom, 0x0}, - /* if you add more entries, update NUM_FLASH_ITEMS above! */ - }; - - char user_msg[256]; - - int current_step = 1; - for(FlashItem* item = &items[0]; item < &items[NUM_FLASH_ITEMS]; ++item) { - if(app->selected_flash_options[item->selected]) { - snprintf( - user_msg, - sizeof(user_msg), - "Flashing %s (%d/%d) to address 0x%lx\n", - item->description, - current_step++, - num_steps, - item->addr); - loader_port_debug_print(user_msg); - err = _flash_file(app, item->path, item->addr); - if(err) { - break; - } - } - } -} - -static int32_t wifi_marauder_flash_bin(void* context) { - WifiMarauderApp* app = (void*)context; - esp_loader_error_t err; - - app->flash_worker_busy = true; - - // alloc global objects - flash_rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1); - timer = furi_timer_alloc(_timer_callback, FuriTimerTypePeriodic, app); - - loader_port_debug_print("Connecting\n"); - esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT(); - err = esp_loader_connect(&connect_config); - if(err != ESP_LOADER_SUCCESS) { - char err_msg[256]; - snprintf(err_msg, sizeof(err_msg), "Cannot connect to target. Error: %u\n", err); - loader_port_debug_print(err_msg); - } - -#if 0 // still getting packet drops with this - // higher BR - if(!err) { - loader_port_debug_print("Increasing speed for faster flash\n"); - err = esp_loader_change_transmission_rate(230400); - if (err != ESP_LOADER_SUCCESS) { - char err_msg[256]; - snprintf( - err_msg, - sizeof(err_msg), - "Cannot change transmission rate. Error: %u\n", - err); - loader_port_debug_print(err_msg); - } - furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400); - } -#endif - - if(!err) { - loader_port_debug_print("Connected\n"); - _flash_all_files(app); -#if 0 - loader_port_debug_print("Restoring transmission rate\n"); - furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200); -#endif - loader_port_debug_print("Done flashing. Please reset the board manually.\n"); - } - - // done - app->flash_worker_busy = false; - - // cleanup - furi_stream_buffer_free(flash_rx_stream); - flash_rx_stream = NULL; - furi_timer_free(timer); - return 0; -} - -void wifi_marauder_flash_start_thread(WifiMarauderApp* app) { - global_app = app; - - app->flash_worker = furi_thread_alloc(); - furi_thread_set_name(app->flash_worker, "WifiMarauderFlashWorker"); - furi_thread_set_stack_size(app->flash_worker, 2048); - furi_thread_set_context(app->flash_worker, app); - furi_thread_set_callback(app->flash_worker, wifi_marauder_flash_bin); - furi_thread_start(app->flash_worker); -} - -void wifi_marauder_flash_stop_thread(WifiMarauderApp* app) { - furi_thread_join(app->flash_worker); - furi_thread_free(app->flash_worker); -} - -esp_loader_error_t loader_port_read(uint8_t* data, uint16_t size, uint32_t timeout) { - size_t read = furi_stream_buffer_receive(flash_rx_stream, data, size, pdMS_TO_TICKS(timeout)); - if(read < size) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_SUCCESS; - } -} - -esp_loader_error_t loader_port_write(const uint8_t* data, uint16_t size, uint32_t timeout) { - UNUSED(timeout); - wifi_marauder_uart_tx((uint8_t*)data, size); - return ESP_LOADER_SUCCESS; -} - -void loader_port_enter_bootloader(void) { - // unimplemented -} - -void loader_port_delay_ms(uint32_t ms) { - furi_delay_ms(ms); -} - -void loader_port_start_timer(uint32_t ms) { - _remaining_time = ms; - furi_timer_start(timer, pdMS_TO_TICKS(1)); -} - -uint32_t loader_port_remaining_time(void) { - return _remaining_time; -} - -extern void wifi_marauder_console_output_handle_rx_data_cb( - uint8_t* buf, - size_t len, - void* context); // TODO cleanup -void loader_port_debug_print(const char* str) { - if(global_app) - wifi_marauder_console_output_handle_rx_data_cb((uint8_t*)str, strlen(str), global_app); -} - -void loader_port_spi_set_cs(uint32_t level) { - UNUSED(level); - // unimplemented -} - -void wifi_marauder_flash_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) { - UNUSED(context); - if(flash_rx_stream) { - furi_stream_buffer_send(flash_rx_stream, buf, len, 0); - } else { - // done flashing - if(global_app) wifi_marauder_console_output_handle_rx_data_cb(buf, len, global_app); - } -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.h b/applications/external/wifi_marauder_companion/wifi_marauder_flasher.h deleted file mode 100644 index d875c2dbe..000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "wifi_marauder_app_i.h" -#include "wifi_marauder_uart.h" -#define SERIAL_FLASHER_INTERFACE_UART /* TODO why is application.fam not passing this via cdefines */ -#include "esp_loader_io.h" - -#define ESP_ADDR_BOOT_S3 0x0 -#define ESP_ADDR_BOOT 0x1000 -#define ESP_ADDR_PART 0x8000 -#define ESP_ADDR_NVS 0x9000 -#define ESP_ADDR_BOOT_APP0 0xE000 -#define ESP_ADDR_APP 0x10000 - -void wifi_marauder_flash_start_thread(WifiMarauderApp* app); -void wifi_marauder_flash_stop_thread(WifiMarauderApp* app); -void wifi_marauder_flash_handle_rx_data_cb(uint8_t* buf, size_t len, void* context); \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.c b/applications/external/wifi_marauder_companion/wifi_marauder_pcap.c deleted file mode 100644 index 73e3d98ea..000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "wifi_marauder_app_i.h" -#include "wifi_marauder_pcap.h" - -void wifi_marauder_get_prefix_from_sniff_cmd(char* dest, const char* command) { - int start, end, delta; - start = strlen("sniff"); - end = strcspn(command, " "); - delta = end - start; - strncpy(dest, command + start, end - start); - dest[delta] = '\0'; -} - -void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) { - int end; - end = strcspn(command, " "); - strncpy(dest, command, end); - dest[end] = '\0'; -} - -void wifi_marauder_create_pcap_file(WifiMarauderApp* app) { - char prefix[10]; - char capture_file_path[100]; - wifi_marauder_get_prefix_from_sniff_cmd(prefix, app->selected_tx_string); - - int i = 0; - do { - snprintf( - capture_file_path, - sizeof(capture_file_path), - "%s/%s_%d.pcap", - MARAUDER_APP_FOLDER_PCAPS, - prefix, - i); - i++; - } while(storage_file_exists(app->storage, capture_file_path)); - - if(!storage_file_open(app->capture_file, capture_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { - dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file"); - } -} - -void wifi_marauder_create_log_file(WifiMarauderApp* app) { - char prefix[10]; - char log_file_path[100]; - wifi_marauder_get_prefix_from_cmd(prefix, app->selected_tx_string); - - int i = 0; - do { - snprintf( - log_file_path, - sizeof(log_file_path), - "%s/%s_%d.log", - MARAUDER_APP_FOLDER_LOGS, - prefix, - i); - i++; - } while(storage_file_exists(app->storage, log_file_path)); - - if(!storage_file_open(app->log_file, log_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { - dialog_message_show_storage_error(app->dialogs, "Cannot open log file"); - } else { - strcpy(app->log_file_path, log_file_path); - } -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.h b/applications/external/wifi_marauder_companion/wifi_marauder_pcap.h deleted file mode 100644 index 94f6282f3..000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "furi_hal.h" - -/** - * Creates a PCAP file to store incoming packets. - * The file name will have a prefix according to the type of scan being performed by the application (Eg: raw_0.pcap) - * - * @param app Application context - */ -void wifi_marauder_create_pcap_file(WifiMarauderApp* app); - -/** - * Creates a log file to store text from console output. - * The file name will have a prefix according to the command being performed by the application (Eg: scanap_0.log) - * - * @param app Application context - */ -// same as wifi_marauder_create_pcap_file, but for log files (to save console text output) -void wifi_marauder_create_log_file(WifiMarauderApp* app); From c3f7a0d12802cabb04878638f16e837deef992f1 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 29 Jul 2023 05:52:40 +0300 Subject: [PATCH 7/7] update changelog --- CHANGELOG.md | 10 ++++------ .../scenes/wifi_marauder_scene_start.c | 8 +------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf018c3d9..8aad209a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,8 @@ ## New changes -* Plugins: **22+ plugins was fixed (UI update issues) in extra pack and in base firmware pack** -* Plugins: Spectrum Analyzer - Modulation switching (hold OK) (by @ALEEF02 | PR #557) -* Plugins: BadBT -> Temp fix for macOS -* Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator) -> + added fix for UI update too -* Infrared: Add Play / Pause in universal projector remote -* Infrared: Update Universal remote assets (by @amec0e) +* SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX +* Plugins: Update ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder) +* Plugins: Update ESP32-CAM -> Camera Suite [(by CodyTolene)](https://github.com/CodyTolene/Flipper-Zero-Camera-Suite) -> (PR #562 by @CodyTolene) +* OFW: Fix fbtenv restore ---- diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c index 6ce66b1a4..6e6be90df 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c @@ -111,13 +111,7 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { TOGGLE_ARGS, FOCUS_CONSOLE_END, NO_TIP}, - {"LED", - {"hex", "pattern"}, - 2, - {"led -s", "led -p"}, - INPUT_ARGS, - FOCUS_CONSOLE_END, - NO_TIP}, + {"LED", {"hex", "pattern"}, 2, {"led -s", "led -p"}, INPUT_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Settings", {"display", "restore", "ForcePMKID", "ForceProbe", "SavePCAP", "EnableLED", "other"}, 7,