[FL-2315] USB Mode switch lock (#1036)

* usb mode switch lock
* lock_mutex removed
* Wait for session termination in rpc_cli, lock badusb and u2f if rpc session is opened

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2022-03-24 18:45:03 +03:00
committed by GitHub
parent eafeefb843
commit 38e92cf789
20 changed files with 216 additions and 43 deletions

View File

@@ -2,3 +2,4 @@ ADD_SCENE(gpio, start, Start)
ADD_SCENE(gpio, test, Test)
ADD_SCENE(gpio, usb_uart, UsbUart)
ADD_SCENE(gpio, usb_uart_cfg, UsbUartCfg)
ADD_SCENE(gpio, usb_uart_close_rpc, UsbUartCloseRpc)

View File

@@ -1,5 +1,6 @@
#include "../gpio_app_i.h"
#include "furi_hal_power.h"
#include "furi_hal_usb.h"
enum GpioItem {
GpioItemUsbUart,
@@ -86,7 +87,11 @@ bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(app->scene_manager, GpioSceneTest);
} else if(event.event == GpioStartEventUsbUart) {
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemUsbUart);
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
if(!furi_hal_usb_is_locked()) {
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
} else {
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCloseRpc);
}
}
consumed = true;
}

View File

@@ -31,7 +31,7 @@ void gpio_scene_usb_uart_on_enter(void* context) {
usb_uart_get_state(app->usb_uart_bridge, &scene_usb_uart->state);
gpio_usb_uart_set_callback(app->gpio_usb_uart, gpio_scene_usb_uart_callback, app);
scene_manager_set_scene_state(app->scene_manager, GpioAppViewUsbUart, 0);
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 0);
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUart);
notification_message(app->notifications, &sequence_display_lock);
}
@@ -39,8 +39,8 @@ void gpio_scene_usb_uart_on_enter(void* context) {
bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
GpioApp* app = context;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, GpioAppViewUsbUart, 1);
scene_manager_next_scene(app->scene_manager, GpioAppViewUsbUartCfg);
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 1);
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg);
return true;
} else if(event.type == SceneManagerEventTypeTick) {
uint32_t tx_cnt_last = scene_usb_uart->state.tx_cnt;
@@ -58,7 +58,7 @@ bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
void gpio_scene_usb_uart_on_exit(void* context) {
GpioApp* app = context;
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart);
if(prev_state == 0) {
usb_uart_disable(app->usb_uart_bridge);
free(scene_usb_uart);

View File

@@ -0,0 +1,53 @@
#include "../gpio_app_i.h"
#include "../gpio_custom_event.h"
static void gpio_scene_usb_uart_close_rpc_event_callback(
GuiButtonType result,
InputType type,
void* context) {
furi_assert(context);
GpioApp* app = context;
if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(app->view_dispatcher, GpioCustomEventErrorBack);
}
}
void gpio_scene_usb_uart_close_rpc_on_enter(void* context) {
GpioApp* app = context;
widget_add_string_multiline_element(
app->widget,
63,
10,
AlignCenter,
AlignTop,
FontSecondary,
"Disconnect from\ncompanion app\nto use this function");
widget_add_button_element(
app->widget, GuiButtonTypeLeft, "Back", gpio_scene_usb_uart_close_rpc_event_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUartCloseRpc);
}
bool gpio_scene_usb_uart_close_rpc_on_event(void* context, SceneManagerEvent event) {
GpioApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GpioCustomEventErrorBack) {
if(!scene_manager_previous_scene(app->scene_manager)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
consumed = true;
}
}
return consumed;
}
void gpio_scene_usb_uart_close_rpc_on_exit(void* context) {
GpioApp* app = context;
widget_reset(app->widget);
}