[FL-1857] New USB stack (#735)

* libusb_stm32 USB stack test
* USB: Add dual CDC mode
* USB HID demo, added libusb_stm32 as submodule
* Target F6/F7: remomve unused ll_usb

Co-authored-by: n.minaylov <n.minaylov@flipperdevices.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2021-10-06 12:24:09 +03:00
committed by GitHub
parent 42e553bad5
commit e0c1928fde
49 changed files with 2387 additions and 2120 deletions

5
applications/applications.c Executable file → Normal file
View File

@@ -33,6 +33,7 @@ extern int32_t storage_test_app(void* p);
extern int32_t subghz_app(void* p);
extern int32_t vibro_test_app(void* p);
extern int32_t bt_debug_app(void* p);
extern int32_t usb_test_app(void* p);
// Plugins
extern int32_t music_player_app(void* p);
@@ -210,6 +211,10 @@ const FlipperApplication FLIPPER_DEBUG_APPS[] = {
{.app = accessor_app, .name = "Accessor", .stack_size = 4096, .icon = &A_Plugins_14},
#endif
#ifdef APP_USB_TEST
{.app = usb_test_app, .name = "USB Test", .stack_size = 1024, .icon = &A_Plugins_14},
#endif
#ifdef APP_UNIT_TESTS
{.app = flipper_test_app, .name = "Unit Tests", .stack_size = 1024, .icon = &A_Plugins_14},
#endif

View File

@@ -43,6 +43,7 @@ APP_KEYPAD_TEST = 1
APP_SD_TEST = 1
APP_UNIT_TESTS = 0
APP_VIBRO_DEMO = 1
APP_USB_TEST = 1
endif
@@ -121,6 +122,14 @@ SRV_GUI = 1
endif
APP_USB_TEST ?= 0
ifeq ($(APP_USB_TEST), 1)
CFLAGS += -DAPP_USB_TEST
SRV_INPUT = 1
SRV_GUI = 1
endif
APP_KEYPAD_TEST ?= 0
ifeq ($(APP_KEYPAD_TEST), 1)
CFLAGS += -DAPP_KEYPAD_TEST

View File

@@ -0,0 +1,102 @@
#include <furi.h>
#include <furi-hal.h>
#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;
} UsbTestApp;
typedef enum {
UsbTestSubmenuIndexEnable,
UsbTestSubmenuIndexDisable,
UsbTestSubmenuIndexVcpSingle,
UsbTestSubmenuIndexVcpDual,
UsbTestSubmenuIndexHid,
UsbTestSubmenuIndexHidU2F,
} SubmenuIndex;
void usb_test_submenu_callback(void* context, uint32_t index) {
furi_assert(context);
//UsbTestApp* app = context;
if(index == UsbTestSubmenuIndexEnable) {
furi_hal_usb_enable();
} else if(index == UsbTestSubmenuIndexDisable) {
furi_hal_usb_disable();
} else if(index == UsbTestSubmenuIndexVcpSingle) {
furi_hal_usb_set_config(UsbModeVcpSingle);
} else if(index == UsbTestSubmenuIndexVcpDual) {
furi_hal_usb_set_config(UsbModeVcpDual);
} else if(index == UsbTestSubmenuIndexHid) {
furi_hal_usb_set_config(UsbModeHid);
} else if(index == UsbTestSubmenuIndexHidU2F) {
//furi_hal_usb_set_config(UsbModeU2F);
}
}
uint32_t usb_test_exit(void* context) {
return VIEW_NONE;
}
UsbTestApp* usb_test_app_alloc() {
UsbTestApp* app = furi_alloc(sizeof(UsbTestApp));
// 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);
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);
submenu_add_item(
app->submenu, "TODO: HID U2F", UsbTestSubmenuIndexHidU2F, usb_test_submenu_callback, app);
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) {
UsbTestApp* app = usb_test_app_alloc();
view_dispatcher_run(app->view_dispatcher);
usb_test_app_free(app);
return 0;
}