Przeglądaj źródła

upload UART_Terminal to github

cool4uma 3 lat temu
rodzic
commit
4db3bb8a2b

+ 13 - 0
application.fam

@@ -0,0 +1,13 @@
+App(
+    appid="uart_terminal",
+    name="UART_Terminal",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="uart_terminal_app",
+    cdefines=["APP_UART_TERMINAL"],
+    requires=["gui"],
+    stack_size=1 * 1024,
+    order=90,
+    fap_icon="uart_terminal.png",
+    fap_category="GPIO",
+    fap_icon_assets="assets",
+)

BIN
assets/KeyBackspaceSelected_16x9.png


BIN
assets/KeyBackspace_16x9.png


BIN
assets/KeySaveSelected_24x11.png


BIN
assets/KeySave_24x11.png


BIN
assets/WarningDolphin_45x42.png


+ 30 - 0
scenes/uart_terminal_scene.c

@@ -0,0 +1,30 @@
+#include "uart_terminal_scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const uart_terminal_scene_on_enter_handlers[])(void*) = {
+#include "uart_terminal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const uart_terminal_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "uart_terminal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const uart_terminal_scene_on_exit_handlers[])(void* context) = {
+#include "uart_terminal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers uart_terminal_scene_handlers = {
+    .on_enter_handlers = uart_terminal_scene_on_enter_handlers,
+    .on_event_handlers = uart_terminal_scene_on_event_handlers,
+    .on_exit_handlers = uart_terminal_scene_on_exit_handlers,
+    .scene_num = UART_TerminalSceneNum,
+};

+ 29 - 0
scenes/uart_terminal_scene.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) UART_TerminalScene##id,
+typedef enum {
+#include "uart_terminal_scene_config.h"
+    UART_TerminalSceneNum,
+} UART_TerminalScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers uart_terminal_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
+#include "uart_terminal_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(prefix, name, id) \
+    bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "uart_terminal_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
+#include "uart_terminal_scene_config.h"
+#undef ADD_SCENE

+ 3 - 0
scenes/uart_terminal_scene_config.h

@@ -0,0 +1,3 @@
+ADD_SCENE(uart_terminal, start, Start)
+ADD_SCENE(uart_terminal, console_output, ConsoleOutput)
+ADD_SCENE(uart_terminal, text_input, UART_TextInput)

+ 93 - 0
scenes/uart_terminal_scene_console_output.c

@@ -0,0 +1,93 @@
+#include "../uart_terminal_app_i.h"
+
+void uart_terminal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+
+    // If text box store gets too big, then truncate it
+    app->text_box_store_strlen += len;
+    if(app->text_box_store_strlen >= UART_TERMINAL_TEXT_BOX_STORE_SIZE - 1) {
+        furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
+        app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
+    }
+
+    // Null-terminate buf and append to text box store
+    buf[len] = '\0';
+    furi_string_cat_printf(app->text_box_store, "%s", buf);
+
+    view_dispatcher_send_custom_event(
+        app->view_dispatcher, UART_TerminalEventRefreshConsoleOutput);
+}
+
+void uart_terminal_scene_console_output_on_enter(void* context) {
+    UART_TerminalApp* app = context;
+
+    TextBox* text_box = app->text_box;
+    text_box_reset(app->text_box);
+    text_box_set_font(text_box, TextBoxFontText);
+    if(app->focus_console_start) {
+        text_box_set_focus(text_box, TextBoxFocusStart);
+    } else {
+        text_box_set_focus(text_box, TextBoxFocusEnd);
+    }
+    if(app->is_command) {
+        furi_string_reset(app->text_box_store);
+        app->text_box_store_strlen = 0;
+        if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
+            const char* help_msg =
+                "UART terminal for Flipper\n\nI'm in github: cool4uma\n\nThis app is a modified\nWiFi Marauder companion,\nThanks 0xchocolate(github)\nfor great code and app.\n\n";
+            furi_string_cat_str(app->text_box_store, help_msg);
+            app->text_box_store_strlen += strlen(help_msg);
+        }
+
+        if(app->show_stopscan_tip) {
+            const char* help_msg = "Press BACK to return\n";
+            furi_string_cat_str(app->text_box_store, help_msg);
+            app->text_box_store_strlen += strlen(help_msg);
+        }
+    }
+
+    // Set starting text - for "View Log", this will just be what was already in the text box store
+    text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
+
+    scene_manager_set_scene_state(app->scene_manager, UART_TerminalSceneConsoleOutput, 0);
+    view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewConsoleOutput);
+
+    // Register callback to receive data
+    uart_terminal_uart_set_handle_rx_data_cb(
+        app->uart, uart_terminal_console_output_handle_rx_data_cb); // setup callback for rx thread
+
+    // Send command with newline '\n'
+    if(app->is_command && app->selected_tx_string) {
+        uart_terminal_uart_tx(
+            (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
+        uart_terminal_uart_tx((uint8_t*)("\n"), 1);
+    }
+}
+
+bool uart_terminal_scene_console_output_on_event(void* context, SceneManagerEvent event) {
+    UART_TerminalApp* app = context;
+
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeTick) {
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void uart_terminal_scene_console_output_on_exit(void* context) {
+    UART_TerminalApp* app = context;
+
+    // Unregister rx callback
+    uart_terminal_uart_set_handle_rx_data_cb(app->uart, NULL);
+
+    // Automatically stop the scan when exiting view
+    if(app->is_command) {
+        uart_terminal_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n"));
+    }
+}

+ 133 - 0
scenes/uart_terminal_scene_start.c

@@ -0,0 +1,133 @@
+//** Includes sniffbt and sniffskim for compatible ESP32-WROOM hardware.
+//uart_terminal_app_i.h also changed **//
+#include "../uart_terminal_app_i.h"
+
+// For each command, define whether additional arguments are needed
+// (enabling text input to fill them out), and whether the console
+// text box should focus at the start of the output or the end
+typedef enum { NO_ARGS = 0, INPUT_ARGS, TOGGLE_ARGS } InputArgs;
+
+typedef enum { FOCUS_CONSOLE_END = 0, FOCUS_CONSOLE_START, FOCUS_CONSOLE_TOGGLE } FocusConsole;
+
+#define SHOW_STOPSCAN_TIP (true)
+#define NO_TIP (false)
+
+#define MAX_OPTIONS (9)
+typedef struct {
+    const char* item_string;
+    const char* options_menu[MAX_OPTIONS];
+    int num_options_menu;
+    const char* actual_commands[MAX_OPTIONS];
+    InputArgs needs_keyboard;
+    FocusConsole focus_console;
+    bool show_stopscan_tip;
+} UART_TerminalItem;
+
+// NUM_MENU_ITEMS defined in uart_terminal_app_i.h - if you add an entry here, increment it!
+const UART_TerminalItem items[NUM_MENU_ITEMS] = {
+    {"Console",
+     {"9600", "19200", "57600", "115200"},
+     4,
+     {"", ""},
+     NO_ARGS,
+     FOCUS_CONSOLE_TOGGLE,
+     NO_TIP},
+    {"Send command", {""}, 1, {""}, INPUT_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},
+};
+
+static void uart_terminal_scene_start_var_list_enter_callback(void* context, uint32_t index) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+
+    furi_assert(index < NUM_MENU_ITEMS);
+    const UART_TerminalItem* item = &items[index];
+
+    const int selected_option_index = app->selected_option_index[index];
+    furi_assert(selected_option_index < item->num_options_menu);
+    app->selected_tx_string = item->actual_commands[selected_option_index];
+    app->is_command = (1 <= index);
+    app->is_custom_tx_string = false;
+    app->selected_menu_index = index;
+    app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE) ?
+                                   (selected_option_index == 0) :
+                                   item->focus_console;
+    app->show_stopscan_tip = item->show_stopscan_tip;
+
+    bool needs_keyboard = (item->needs_keyboard == TOGGLE_ARGS) ? (selected_option_index != 0) :
+                                                                  item->needs_keyboard;
+    if(needs_keyboard) {
+        view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartKeyboard);
+    } else {
+        view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartConsole);
+    }
+}
+
+static void uart_terminal_scene_start_var_list_change_callback(VariableItem* item) {
+    furi_assert(item);
+
+    UART_TerminalApp* app = variable_item_get_context(item);
+    furi_assert(app);
+
+    const UART_TerminalItem* menu_item = &items[app->selected_menu_index];
+    uint8_t item_index = variable_item_get_current_value_index(item);
+    furi_assert(item_index < menu_item->num_options_menu);
+    variable_item_set_current_value_text(item, menu_item->options_menu[item_index]);
+    app->selected_option_index[app->selected_menu_index] = item_index;
+}
+
+void uart_terminal_scene_start_on_enter(void* context) {
+    UART_TerminalApp* app = context;
+    VariableItemList* var_item_list = app->var_item_list;
+
+    variable_item_list_set_enter_callback(
+        var_item_list, uart_terminal_scene_start_var_list_enter_callback, app);
+
+    VariableItem* item;
+    for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
+        item = variable_item_list_add(
+            var_item_list,
+            items[i].item_string,
+            items[i].num_options_menu,
+            uart_terminal_scene_start_var_list_change_callback,
+            app);
+        variable_item_set_current_value_index(item, app->selected_option_index[i]);
+        variable_item_set_current_value_text(
+            item, items[i].options_menu[app->selected_option_index[i]]);
+    }
+
+    variable_item_list_set_selected_item(
+        var_item_list, scene_manager_get_scene_state(app->scene_manager, UART_TerminalSceneStart));
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewVarItemList);
+}
+
+bool uart_terminal_scene_start_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UART_TerminalApp* app = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UART_TerminalEventStartKeyboard) {
+            scene_manager_set_scene_state(
+                app->scene_manager, UART_TerminalSceneStart, app->selected_menu_index);
+            scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewTextInput);
+        } else if(event.event == UART_TerminalEventStartConsole) {
+            scene_manager_set_scene_state(
+                app->scene_manager, UART_TerminalSceneStart, app->selected_menu_index);
+            scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
+        }
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeTick) {
+        app->selected_menu_index = variable_item_list_get_selected_item_index(app->var_item_list);
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void uart_terminal_scene_start_on_exit(void* context) {
+    UART_TerminalApp* app = context;
+    variable_item_list_reset(app->var_item_list);
+}

+ 60 - 0
scenes/uart_terminal_scene_text_input.c

@@ -0,0 +1,60 @@
+#include "../uart_terminal_app_i.h"
+
+void uart_terminal_scene_text_input_callback(void* context) {
+    UART_TerminalApp* app = context;
+
+    view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartConsole);
+}
+
+void uart_terminal_scene_text_input_on_enter(void* context) {
+    UART_TerminalApp* app = context;
+
+    if(false == app->is_custom_tx_string) {
+        // Fill text input with selected string so that user can add to it
+        size_t length = strlen(app->selected_tx_string);
+        furi_assert(length < UART_TERMINAL_TEXT_INPUT_STORE_SIZE);
+        bzero(app->text_input_store, UART_TERMINAL_TEXT_INPUT_STORE_SIZE);
+        strncpy(app->text_input_store, app->selected_tx_string, length);
+
+        // Add space - because flipper keyboard currently doesn't have a space
+        app->text_input_store[length] = ' ';
+        app->text_input_store[length + 1] = '\0';
+        app->is_custom_tx_string = true;
+    }
+
+    // Setup view
+    UART_TextInput* text_input = app->text_input;
+    // Add help message to header
+    uart_text_input_set_header_text(text_input, "Send command to UART");
+    uart_text_input_set_result_callback(
+        text_input,
+        uart_terminal_scene_text_input_callback,
+        app,
+        app->text_input_store,
+        UART_TERMINAL_TEXT_INPUT_STORE_SIZE,
+        false);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
+}
+
+bool uart_terminal_scene_text_input_on_event(void* context, SceneManagerEvent event) {
+    UART_TerminalApp* app = context;
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == UART_TerminalEventStartConsole) {
+            // Point to custom string to send
+            app->selected_tx_string = app->text_input_store;
+            scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
+            consumed = true;
+        }
+    }
+
+    return consumed;
+}
+
+void uart_terminal_scene_text_input_on_exit(void* context) {
+    UART_TerminalApp* app = context;
+
+    uart_text_input_reset(app->text_input);
+}

BIN
uart_terminal.png


+ 104 - 0
uart_terminal_app.c

@@ -0,0 +1,104 @@
+#include "uart_terminal_app_i.h"
+
+#include <furi.h>
+#include <furi_hal.h>
+
+static bool uart_terminal_app_custom_event_callback(void* context, uint32_t event) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+    return scene_manager_handle_custom_event(app->scene_manager, event);
+}
+
+static bool uart_terminal_app_back_event_callback(void* context) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+    return scene_manager_handle_back_event(app->scene_manager);
+}
+
+static void uart_terminal_app_tick_event_callback(void* context) {
+    furi_assert(context);
+    UART_TerminalApp* app = context;
+    scene_manager_handle_tick_event(app->scene_manager);
+}
+
+UART_TerminalApp* uart_terminal_app_alloc() {
+    UART_TerminalApp* app = malloc(sizeof(UART_TerminalApp));
+
+    app->gui = furi_record_open(RECORD_GUI);
+
+    app->view_dispatcher = view_dispatcher_alloc();
+    app->scene_manager = scene_manager_alloc(&uart_terminal_scene_handlers, app);
+    view_dispatcher_enable_queue(app->view_dispatcher);
+    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+
+    view_dispatcher_set_custom_event_callback(
+        app->view_dispatcher, uart_terminal_app_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        app->view_dispatcher, uart_terminal_app_back_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        app->view_dispatcher, uart_terminal_app_tick_event_callback, 100);
+
+    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
+
+    app->var_item_list = variable_item_list_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        UART_TerminalAppViewVarItemList,
+        variable_item_list_get_view(app->var_item_list));
+
+    for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
+        app->selected_option_index[i] = 0;
+    }
+
+    app->text_box = text_box_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher, UART_TerminalAppViewConsoleOutput, text_box_get_view(app->text_box));
+    app->text_box_store = furi_string_alloc();
+    furi_string_reserve(app->text_box_store, UART_TERMINAL_TEXT_BOX_STORE_SIZE);
+
+    app->text_input = uart_text_input_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher,
+        UART_TerminalAppViewTextInput,
+        uart_text_input_get_view(app->text_input));
+
+    scene_manager_next_scene(app->scene_manager, UART_TerminalSceneStart);
+
+    return app;
+}
+
+void uart_terminal_app_free(UART_TerminalApp* app) {
+    furi_assert(app);
+
+    // Views
+    view_dispatcher_remove_view(app->view_dispatcher, UART_TerminalAppViewVarItemList);
+    view_dispatcher_remove_view(app->view_dispatcher, UART_TerminalAppViewConsoleOutput);
+    view_dispatcher_remove_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
+    text_box_free(app->text_box);
+    furi_string_free(app->text_box_store);
+    uart_text_input_free(app->text_input);
+
+    // View dispatcher
+    view_dispatcher_free(app->view_dispatcher);
+    scene_manager_free(app->scene_manager);
+
+    uart_terminal_uart_free(app->uart);
+
+    // Close records
+    furi_record_close(RECORD_GUI);
+
+    free(app);
+}
+
+int32_t uart_terminal_app(void* p) {
+    UNUSED(p);
+    UART_TerminalApp* uart_terminal_app = uart_terminal_app_alloc();
+
+    uart_terminal_app->uart = uart_terminal_uart_init(uart_terminal_app);
+
+    view_dispatcher_run(uart_terminal_app->view_dispatcher);
+
+    uart_terminal_app_free(uart_terminal_app);
+
+    return 0;
+}

+ 11 - 0
uart_terminal_app.h

@@ -0,0 +1,11 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct UART_TerminalApp UART_TerminalApp;
+
+#ifdef __cplusplus
+}
+#endif

+ 72 - 0
uart_terminal_app_i.h

@@ -0,0 +1,72 @@
+//** Includes sniffbt and sniffskim for compatible ESP32-WROOM hardware.
+// uart_terminal_scene_start.c also changed **//
+#pragma once
+
+#include "uart_terminal_app.h"
+#include "scenes/uart_terminal_scene.h"
+#include "uart_terminal_custom_event.h"
+#include "uart_terminal_uart.h"
+
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/scene_manager.h>
+#include <gui/modules/text_box.h>
+//#include <gui/modules/text_input.h>
+#include <gui/modules/variable_item_list.h>
+#include "uart_text_input.h"
+
+#define NUM_MENU_ITEMS (4)
+
+#define UART_TERMINAL_TEXT_BOX_STORE_SIZE (4096)
+#define UART_TERMINAL_TEXT_INPUT_STORE_SIZE (512)
+
+struct UART_TerminalApp {
+    Gui* gui;
+    ViewDispatcher* view_dispatcher;
+    SceneManager* scene_manager;
+
+    char text_input_store[UART_TERMINAL_TEXT_INPUT_STORE_SIZE + 1];
+    FuriString* text_box_store;
+    size_t text_box_store_strlen;
+    TextBox* text_box;
+    UART_TextInput* text_input;
+    //Widget* widget;
+
+    VariableItemList* var_item_list;
+
+    UART_TerminalUart* uart;
+    int selected_menu_index;
+    int selected_option_index[NUM_MENU_ITEMS];
+    const char* selected_tx_string;
+    bool is_command;
+    bool is_custom_tx_string;
+    bool focus_console_start;
+    bool show_stopscan_tip;
+};
+
+// Supported commands:
+// https://github.com/justcallmekoko/ESP32Marauder/wiki/cli
+//   Scan
+//    -> If list is empty, then start a new scanap. (Tap any button to stop.)
+//    -> If there's a list, provide option to rescan and dump list of targets to select.
+//    -> Press BACK to go back to top-level.
+//   Attack
+//    -> Beacon
+//    -> Deauth
+//    -> Probe
+//    -> Rickroll
+//   Sniff
+//    -> Beacon
+//    -> Deauth
+//    -> ESP
+//    -> PMKID
+//    -> Pwnagotchi
+//   Channel
+//   Update
+//   Reboot
+
+typedef enum {
+    UART_TerminalAppViewVarItemList,
+    UART_TerminalAppViewConsoleOutput,
+    UART_TerminalAppViewTextInput,
+} UART_TerminalAppView;

+ 7 - 0
uart_terminal_custom_event.h

@@ -0,0 +1,7 @@
+#pragma once
+
+typedef enum {
+    UART_TerminalEventRefreshConsoleOutput = 0,
+    UART_TerminalEventStartConsole,
+    UART_TerminalEventStartKeyboard,
+} UART_TerminalCustomEvent;

+ 94 - 0
uart_terminal_uart.c

@@ -0,0 +1,94 @@
+#include "uart_terminal_app_i.h"
+#include "uart_terminal_uart.h"
+
+#define UART_CH (FuriHalUartIdUSART1)
+#define BAUDRATE (115200)
+
+struct UART_TerminalUart {
+    UART_TerminalApp* app;
+    FuriThread* rx_thread;
+    FuriStreamBuffer* rx_stream;
+    uint8_t rx_buf[RX_BUF_SIZE + 1];
+    void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context);
+};
+
+typedef enum {
+    WorkerEvtStop = (1 << 0),
+    WorkerEvtRxDone = (1 << 1),
+} WorkerEvtFlags;
+
+void uart_terminal_uart_set_handle_rx_data_cb(
+    UART_TerminalUart* uart,
+    void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context)) {
+    furi_assert(uart);
+    uart->handle_rx_data_cb = handle_rx_data_cb;
+}
+
+#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
+
+void uart_terminal_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
+    UART_TerminalUart* uart = (UART_TerminalUart*)context;
+
+    if(ev == UartIrqEventRXNE) {
+        furi_stream_buffer_send(uart->rx_stream, &data, 1, 0);
+        furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtRxDone);
+    }
+}
+
+static int32_t uart_worker(void* context) {
+    UART_TerminalUart* uart = (void*)context;
+
+    uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
+
+    while(1) {
+        uint32_t events =
+            furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
+        furi_check((events & FuriFlagError) == 0);
+        if(events & WorkerEvtStop) break;
+        if(events & WorkerEvtRxDone) {
+            size_t len = furi_stream_buffer_receive(uart->rx_stream, uart->rx_buf, RX_BUF_SIZE, 0);
+            if(len > 0) {
+                if(uart->handle_rx_data_cb) uart->handle_rx_data_cb(uart->rx_buf, len, uart->app);
+            }
+        }
+    }
+
+    furi_stream_buffer_free(uart->rx_stream);
+
+    return 0;
+}
+
+void uart_terminal_uart_tx(uint8_t* data, size_t len) {
+    furi_hal_uart_tx(UART_CH, data, len);
+}
+
+UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) {
+    UART_TerminalUart* uart = malloc(sizeof(UART_TerminalUart));
+
+    furi_hal_console_disable();
+    furi_hal_uart_set_br(UART_CH, BAUDRATE);
+    furi_hal_uart_set_irq_cb(UART_CH, uart_terminal_uart_on_irq_cb, uart);
+
+    uart->app = app;
+    uart->rx_thread = furi_thread_alloc();
+    furi_thread_set_name(uart->rx_thread, "UART_TerminalUartRxThread");
+    furi_thread_set_stack_size(uart->rx_thread, 1024);
+    furi_thread_set_context(uart->rx_thread, uart);
+    furi_thread_set_callback(uart->rx_thread, uart_worker);
+
+    furi_thread_start(uart->rx_thread);
+    return uart;
+}
+
+void uart_terminal_uart_free(UART_TerminalUart* uart) {
+    furi_assert(uart);
+
+    furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
+    furi_thread_join(uart->rx_thread);
+    furi_thread_free(uart->rx_thread);
+
+    furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
+    furi_hal_console_enable();
+
+    free(uart);
+}

+ 14 - 0
uart_terminal_uart.h

@@ -0,0 +1,14 @@
+#pragma once
+
+#include "furi_hal.h"
+
+#define RX_BUF_SIZE (320)
+
+typedef struct UART_TerminalUart UART_TerminalUart;
+
+void uart_terminal_uart_set_handle_rx_data_cb(
+    UART_TerminalUart* uart,
+    void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
+void uart_terminal_uart_tx(uint8_t* data, size_t len);
+UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app);
+void uart_terminal_uart_free(UART_TerminalUart* uart);

+ 57 - 0
uart_validators.c

@@ -0,0 +1,57 @@
+#include <furi.h>
+#include "uart_validators.h"
+#include <storage/storage.h>
+
+struct ValidatorIsFile {
+    char* app_path_folder;
+    const char* app_extension;
+    char* current_name;
+};
+
+bool validator_is_file_callback(const char* text, FuriString* error, void* context) {
+    furi_assert(context);
+    ValidatorIsFile* instance = context;
+
+    if(instance->current_name != NULL) {
+        if(strcmp(instance->current_name, text) == 0) {
+            return true;
+        }
+    }
+
+    bool ret = true;
+    FuriString* path = furi_string_alloc_printf(
+        "%s/%s%s", instance->app_path_folder, text, instance->app_extension);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK) {
+        ret = false;
+        furi_string_printf(error, "This name\nexists!\nChoose\nanother one.");
+    } else {
+        ret = true;
+    }
+    furi_string_free(path);
+    furi_record_close(RECORD_STORAGE);
+
+    return ret;
+}
+
+ValidatorIsFile* validator_is_file_alloc_init(
+    const char* app_path_folder,
+    const char* app_extension,
+    const char* current_name) {
+    ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
+
+    instance->app_path_folder = strdup(app_path_folder);
+    instance->app_extension = app_extension;
+    if(current_name != NULL) {
+        instance->current_name = strdup(current_name);
+    }
+
+    return instance;
+}
+
+void validator_is_file_free(ValidatorIsFile* instance) {
+    furi_assert(instance);
+    free(instance->app_path_folder);
+    free(instance->current_name);
+    free(instance);
+}

+ 21 - 0
uart_validators.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include <core/common_defines.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef struct ValidatorIsFile ValidatorIsFile;
+
+ValidatorIsFile* validator_is_file_alloc_init(
+    const char* app_path_folder,
+    const char* app_extension,
+    const char* current_name);
+
+void validator_is_file_free(ValidatorIsFile* instance);
+
+bool validator_is_file_callback(const char* text, FuriString* error, void* context);
+
+#ifdef __cplusplus
+}
+#endif