Skip to content

Commit efded63

Browse files
nminaylovskotopesDrZlo13
authored
USB-UART: New GUI (#826)
* USB-UART: new gui * Furi: use furi_console for logging instead of printf. * CDC: calling open/close callbacks on interface change * fix vcp_tx block on disconnect * USB mode set by struct pointer * FuriHal: proper event sequence on vcp reconnect * disable debug prints * HAL: add context to UART IRQ's * Context usage in UART IRQ and CDC callbacks * USB-UART: geting rid of baudrate limitations * FuriHal: remove struct pollutant in usb api. Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
1 parent a5052a0 commit efded63

37 files changed

+1345
-862
lines changed

applications/debug_tools/bad_usb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ int32_t bad_usb_app(void* p) {
285285
furi_check(app->event_queue);
286286
ViewPort* view_port = view_port_alloc();
287287

288-
UsbMode usb_mode_prev = furi_hal_usb_get_config();
289-
furi_hal_usb_set_config(UsbModeHid);
288+
UsbInterface* usb_mode_prev = furi_hal_usb_get_config();
289+
furi_hal_usb_set_config(&usb_hid);
290290

291291
view_port_draw_callback_set(view_port, bad_usb_render_callback, app);
292292
view_port_input_callback_set(view_port, bad_usb_input_callback, app->event_queue);

applications/debug_tools/usb_mouse.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ int32_t usb_mouse_app(void* p) {
4141
furi_check(event_queue);
4242
ViewPort* view_port = view_port_alloc();
4343

44-
UsbMode usb_mode_prev = furi_hal_usb_get_config();
45-
furi_hal_usb_set_config(UsbModeHid);
44+
UsbInterface* usb_mode_prev = furi_hal_usb_get_config();
45+
furi_hal_usb_set_config(&usb_hid);
4646

4747
view_port_draw_callback_set(view_port, usb_mouse_render_callback, NULL);
4848
view_port_input_callback_set(view_port, usb_mouse_input_callback, event_queue);

applications/debug_tools/usb_test.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ void usb_test_submenu_callback(void* context, uint32_t index) {
2929
} else if(index == UsbTestSubmenuIndexDisable) {
3030
furi_hal_usb_disable();
3131
} else if(index == UsbTestSubmenuIndexVcpSingle) {
32-
furi_hal_usb_set_config(UsbModeVcpSingle);
32+
furi_hal_usb_set_config(&usb_cdc_single);
3333
} else if(index == UsbTestSubmenuIndexVcpDual) {
34-
furi_hal_usb_set_config(UsbModeVcpDual);
34+
furi_hal_usb_set_config(&usb_cdc_dual);
3535
} else if(index == UsbTestSubmenuIndexHid) {
36-
furi_hal_usb_set_config(UsbModeHid);
36+
furi_hal_usb_set_config(&usb_hid);
3737
} else if(index == UsbTestSubmenuIndexHidU2F) {
3838
//furi_hal_usb_set_config(UsbModeU2F);
3939
}

applications/gpio/gpio_app.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ static bool gpio_app_back_event_callback(void* context) {
1515
return scene_manager_handle_back_event(app->scene_manager);
1616
}
1717

18+
static void gpio_app_tick_event_callback(void* context) {
19+
furi_assert(context);
20+
GpioApp* app = context;
21+
scene_manager_handle_tick_event(app->scene_manager);
22+
}
23+
1824
GpioApp* gpio_app_alloc() {
1925
GpioApp* app = furi_alloc(sizeof(GpioApp));
2026

2127
app->gui = furi_record_open("gui");
22-
app->notifications = furi_record_open("notification");
2328

2429
app->view_dispatcher = view_dispatcher_alloc();
2530
app->scene_manager = scene_manager_alloc(&gpio_scene_handlers, app);
@@ -30,9 +35,13 @@ GpioApp* gpio_app_alloc() {
3035
app->view_dispatcher, gpio_app_custom_event_callback);
3136
view_dispatcher_set_navigation_event_callback(
3237
app->view_dispatcher, gpio_app_back_event_callback);
38+
view_dispatcher_set_tick_event_callback(
39+
app->view_dispatcher, gpio_app_tick_event_callback, 100);
3340

3441
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
3542

43+
app->notifications = furi_record_open("notification");
44+
3645
app->var_item_list = variable_item_list_alloc();
3746
view_dispatcher_add_view(
3847
app->view_dispatcher,
@@ -42,8 +51,14 @@ GpioApp* gpio_app_alloc() {
4251
view_dispatcher_add_view(
4352
app->view_dispatcher, GpioAppViewGpioTest, gpio_test_get_view(app->gpio_test));
4453

54+
app->gpio_usb_uart = gpio_usb_uart_alloc();
4555
view_dispatcher_add_view(
46-
app->view_dispatcher, GpioAppViewUsbUart, variable_item_list_get_view(app->var_item_list));
56+
app->view_dispatcher, GpioAppViewUsbUart, gpio_usb_uart_get_view(app->gpio_usb_uart));
57+
58+
view_dispatcher_add_view(
59+
app->view_dispatcher,
60+
GpioAppViewUsbUartCfg,
61+
variable_item_list_get_view(app->var_item_list));
4762

4863
scene_manager_next_scene(app->scene_manager, GpioSceneStart);
4964

@@ -55,10 +70,12 @@ void gpio_app_free(GpioApp* app) {
5570

5671
// Views
5772
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewVarItemList);
58-
variable_item_list_free(app->var_item_list);
5973
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewGpioTest);
6074
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUart);
75+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCfg);
76+
variable_item_list_free(app->var_item_list);
6177
gpio_test_free(app->gpio_test);
78+
gpio_usb_uart_free(app->gpio_usb_uart);
6279

6380
// View dispatcher
6481
view_dispatcher_free(app->view_dispatcher);

applications/gpio/gpio_app_i.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "gpio_app.h"
44
#include "gpio_item.h"
55
#include "scenes/gpio_scene.h"
6+
#include "gpio_custom_event.h"
7+
#include "usb_uart_bridge.h"
68

79
#include <gui/gui.h>
810
#include <gui/view_dispatcher.h>
@@ -11,27 +13,23 @@
1113
#include <notification/notification-messages.h>
1214
#include <gui/modules/variable-item-list.h>
1315
#include "views/gpio_test.h"
14-
15-
#define GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF (0UL)
16-
#define GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON (1UL)
17-
#define GPIO_SCENE_START_CUSTOM_EVENT_TEST (2UL)
18-
#define GPIO_SCENE_START_CUSTOM_EVENT_USB_UART (3UL)
19-
20-
#define GPIO_SCENE_USB_UART_CUSTOM_EVENT_ENABLE (4UL)
21-
#define GPIO_SCENE_USB_UART_CUSTOM_EVENT_DISABLE (5UL)
16+
#include "views/gpio_usb_uart.h"
2217

2318
struct GpioApp {
2419
Gui* gui;
20+
NotificationApp* notifications;
2521
ViewDispatcher* view_dispatcher;
2622
SceneManager* scene_manager;
27-
NotificationApp* notifications;
2823

2924
VariableItemList* var_item_list;
3025
GpioTest* gpio_test;
26+
GpioUsbUart* gpio_usb_uart;
27+
UsbUartBridge* usb_uart_bridge;
3128
};
3229

3330
typedef enum {
3431
GpioAppViewVarItemList,
3532
GpioAppViewGpioTest,
3633
GpioAppViewUsbUart,
34+
GpioAppViewUsbUartCfg,
3735
} GpioAppView;

applications/gpio/gpio_custom_event.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
typedef enum {
4+
GpioStartEventOtgOff = 0,
5+
GpioStartEventOtgOn,
6+
GpioStartEventManualConrol,
7+
GpioStartEventUsbUart,
8+
9+
GpioUsbUartEventConfig,
10+
} GpioCustomEvent;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ADD_SCENE(gpio, start, Start)
22
ADD_SCENE(gpio, test, Test)
33
ADD_SCENE(gpio, usb_uart, UsbUart)
4+
ADD_SCENE(gpio, usb_uart_cfg, UsbUartCfg)

applications/gpio/scenes/gpio_scene_start.c

+17-18
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include "furi-hal-power.h"
33

44
enum GpioItem {
5-
GpioItemOtg,
6-
GpioItemTest,
75
GpioItemUsbUart,
6+
GpioItemTest,
7+
GpioItemOtg,
88
};
99

1010
enum GpioOtg {
@@ -22,11 +22,9 @@ static void gpio_scene_start_var_list_enter_callback(void* context, uint32_t ind
2222
furi_assert(context);
2323
GpioApp* app = context;
2424
if(index == GpioItemTest) {
25-
view_dispatcher_send_custom_event(
26-
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_TEST);
25+
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventManualConrol);
2726
} else if(index == GpioItemUsbUart) {
28-
view_dispatcher_send_custom_event(
29-
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_USB_UART);
27+
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventUsbUart);
3028
}
3129
}
3230

@@ -36,11 +34,9 @@ static void gpio_scene_start_var_list_change_callback(VariableItem* item) {
3634

3735
variable_item_set_current_value_text(item, gpio_otg_text[index]);
3836
if(index == GpioOtgOff) {
39-
view_dispatcher_send_custom_event(
40-
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF);
37+
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventOtgOff);
4138
} else if(index == GpioOtgOn) {
42-
view_dispatcher_send_custom_event(
43-
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON);
39+
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventOtgOn);
4440
}
4541
}
4642

@@ -51,6 +47,11 @@ void gpio_scene_start_on_enter(void* context) {
5147
VariableItem* item;
5248
variable_item_list_set_enter_callback(
5349
var_item_list, gpio_scene_start_var_list_enter_callback, app);
50+
51+
variable_item_list_add(var_item_list, "USB-UART bridge", 0, NULL, NULL);
52+
53+
variable_item_list_add(var_item_list, "GPIO manual control", 0, NULL, NULL);
54+
5455
item = variable_item_list_add(
5556
var_item_list,
5657
"5V on GPIO",
@@ -64,8 +65,6 @@ void gpio_scene_start_on_enter(void* context) {
6465
variable_item_set_current_value_index(item, GpioOtgOff);
6566
variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOff]);
6667
}
67-
variable_item_list_add(var_item_list, "GPIO tester", 0, NULL, NULL);
68-
variable_item_list_add(var_item_list, "USB-UART bridge", 0, NULL, NULL);
6968

7069
variable_item_list_set_selected_item(
7170
var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioSceneStart));
@@ -78,15 +77,15 @@ bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) {
7877
bool consumed = false;
7978

8079
if(event.type == SceneManagerEventTypeCustom) {
81-
if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON) {
80+
if(event.event == GpioStartEventOtgOn) {
8281
furi_hal_power_enable_otg();
83-
} else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF) {
82+
} else if(event.event == GpioStartEventOtgOff) {
8483
furi_hal_power_disable_otg();
85-
} else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_TEST) {
86-
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, 1);
84+
} else if(event.event == GpioStartEventManualConrol) {
85+
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemTest);
8786
scene_manager_next_scene(app->scene_manager, GpioSceneTest);
88-
} else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_USB_UART) {
89-
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, 2);
87+
} else if(event.event == GpioStartEventUsbUart) {
88+
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemUsbUart);
9089
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
9190
}
9291
consumed = true;

0 commit comments

Comments
 (0)