2021-10-06 09:24:09 +00:00
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-12-21 12:16:25 +00:00
|
|
|
|
2021-10-06 09:24:09 +00:00
|
|
|
#include <gui/view.h>
|
|
|
|
#include <gui/view_dispatcher.h>
|
|
|
|
#include <gui/modules/submenu.h>
|
|
|
|
#include <gui/gui.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Gui* gui;
|
|
|
|
ViewDispatcher* view_dispatcher;
|
|
|
|
Submenu* submenu;
|
2022-03-23 13:35:25 +00:00
|
|
|
FuriHalUsbHidConfig hid_cfg;
|
2021-10-06 09:24:09 +00:00
|
|
|
} UsbTestApp;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
UsbTestSubmenuIndexEnable,
|
|
|
|
UsbTestSubmenuIndexDisable,
|
2022-01-21 16:55:44 +00:00
|
|
|
UsbTestSubmenuIndexRestart,
|
2021-10-06 09:24:09 +00:00
|
|
|
UsbTestSubmenuIndexVcpSingle,
|
|
|
|
UsbTestSubmenuIndexVcpDual,
|
|
|
|
UsbTestSubmenuIndexHid,
|
2022-03-23 13:35:25 +00:00
|
|
|
UsbTestSubmenuIndexHidWithParams,
|
2021-10-06 09:24:09 +00:00
|
|
|
UsbTestSubmenuIndexHidU2F,
|
|
|
|
} SubmenuIndex;
|
|
|
|
|
|
|
|
void usb_test_submenu_callback(void* context, uint32_t index) {
|
|
|
|
furi_assert(context);
|
2022-03-23 13:35:25 +00:00
|
|
|
UsbTestApp* app = context;
|
2021-10-06 09:24:09 +00:00
|
|
|
if(index == UsbTestSubmenuIndexEnable) {
|
|
|
|
furi_hal_usb_enable();
|
|
|
|
} else if(index == UsbTestSubmenuIndexDisable) {
|
|
|
|
furi_hal_usb_disable();
|
2022-01-21 16:55:44 +00:00
|
|
|
} else if(index == UsbTestSubmenuIndexRestart) {
|
|
|
|
furi_hal_usb_reinit();
|
2021-10-06 09:24:09 +00:00
|
|
|
} else if(index == UsbTestSubmenuIndexVcpSingle) {
|
2022-03-23 13:35:25 +00:00
|
|
|
furi_hal_usb_set_config(&usb_cdc_single, NULL);
|
2021-10-06 09:24:09 +00:00
|
|
|
} else if(index == UsbTestSubmenuIndexVcpDual) {
|
2022-03-23 13:35:25 +00:00
|
|
|
furi_hal_usb_set_config(&usb_cdc_dual, NULL);
|
2021-10-06 09:24:09 +00:00
|
|
|
} else if(index == UsbTestSubmenuIndexHid) {
|
2022-03-23 13:35:25 +00:00
|
|
|
furi_hal_usb_set_config(&usb_hid, NULL);
|
|
|
|
} else if(index == UsbTestSubmenuIndexHidWithParams) {
|
|
|
|
app->hid_cfg.vid = 0x1234;
|
|
|
|
app->hid_cfg.pid = 0xabcd;
|
2022-06-09 07:09:52 +00:00
|
|
|
strlcpy(app->hid_cfg.manuf, "WEN", sizeof(app->hid_cfg.manuf));
|
|
|
|
strlcpy(app->hid_cfg.product, "FLIP", sizeof(app->hid_cfg.product));
|
2022-03-23 13:35:25 +00:00
|
|
|
furi_hal_usb_set_config(&usb_hid, &app->hid_cfg);
|
2021-10-06 09:24:09 +00:00
|
|
|
} else if(index == UsbTestSubmenuIndexHidU2F) {
|
2022-03-23 13:35:25 +00:00
|
|
|
furi_hal_usb_set_config(&usb_hid_u2f, NULL);
|
2021-10-06 09:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t usb_test_exit(void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-10-06 09:24:09 +00:00
|
|
|
return VIEW_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbTestApp* usb_test_app_alloc() {
|
2022-02-18 19:53:46 +00:00
|
|
|
UsbTestApp* app = malloc(sizeof(UsbTestApp));
|
2021-10-06 09:24:09 +00:00
|
|
|
|
|
|
|
// Gui
|
|
|
|
app->gui = furi_record_open("gui");
|
|
|
|
|
|
|
|
// View dispatcher
|
|
|
|
app->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
view_dispatcher_enable_queue(app->view_dispatcher);
|
|
|
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
|
|
|
|
|
|
|
// Views
|
|
|
|
app->submenu = submenu_alloc();
|
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "Enable", UsbTestSubmenuIndexEnable, usb_test_submenu_callback, app);
|
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "Disable", UsbTestSubmenuIndexDisable, usb_test_submenu_callback, app);
|
2022-01-21 16:55:44 +00:00
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "Restart", UsbTestSubmenuIndexRestart, usb_test_submenu_callback, app);
|
2021-10-06 09:24:09 +00:00
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "Single VCP", UsbTestSubmenuIndexVcpSingle, usb_test_submenu_callback, app);
|
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "Dual VCP", UsbTestSubmenuIndexVcpDual, usb_test_submenu_callback, app);
|
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "HID KB+Mouse", UsbTestSubmenuIndexHid, usb_test_submenu_callback, app);
|
2022-03-23 13:35:25 +00:00
|
|
|
submenu_add_item(
|
|
|
|
app->submenu,
|
|
|
|
"HID KB+Mouse custom ID",
|
|
|
|
UsbTestSubmenuIndexHidWithParams,
|
|
|
|
usb_test_submenu_callback,
|
|
|
|
app);
|
2021-10-06 09:24:09 +00:00
|
|
|
submenu_add_item(
|
2021-12-22 20:04:08 +00:00
|
|
|
app->submenu, "HID U2F", UsbTestSubmenuIndexHidU2F, usb_test_submenu_callback, app);
|
2021-10-06 09:24:09 +00:00
|
|
|
view_set_previous_callback(submenu_get_view(app->submenu), usb_test_exit);
|
|
|
|
view_dispatcher_add_view(app->view_dispatcher, 0, submenu_get_view(app->submenu));
|
|
|
|
|
|
|
|
// Switch to menu
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, 0);
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_test_app_free(UsbTestApp* app) {
|
|
|
|
furi_assert(app);
|
|
|
|
|
|
|
|
// Free views
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, 0);
|
|
|
|
submenu_free(app->submenu);
|
|
|
|
view_dispatcher_free(app->view_dispatcher);
|
|
|
|
|
|
|
|
// Close gui record
|
|
|
|
furi_record_close("gui");
|
|
|
|
app->gui = NULL;
|
|
|
|
|
|
|
|
// Free rest
|
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t usb_test_app(void* p) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(p);
|
2021-10-06 09:24:09 +00:00
|
|
|
UsbTestApp* app = usb_test_app_alloc();
|
|
|
|
|
|
|
|
view_dispatcher_run(app->view_dispatcher);
|
|
|
|
|
|
|
|
usb_test_app_free(app);
|
|
|
|
return 0;
|
|
|
|
}
|