From fb361363f5faef27123df677d0d77199237fc02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20=C3=85gren?= Date: Thu, 3 Apr 2025 13:33:46 +0200 Subject: [PATCH] testapp: Add commands to test dynamic usb enpdoints --- hw/application_fpga/fw/testapp/main.c | 47 ++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/hw/application_fpga/fw/testapp/main.c b/hw/application_fpga/fw/testapp/main.c index 58298eb..465b37b 100644 --- a/hw/application_fpga/fw/testapp/main.c +++ b/hw/application_fpga/fw/testapp/main.c @@ -210,22 +210,59 @@ int main(void) } puts(IO_CDC, "\r\n"); + uint8_t select_ep_cmd[2] = { 1, 0 }; + uint8_t ep = IO_CDC; + puts(IO_CDC, "Now echoing what you type...Type + to reset device\r\n"); for (;;) { - if (readselect(IO_CDC, &endpoint, &available) < 0) { + if (readselect(ep, &endpoint, &available) < 0) { // readselect failed! I/O broken? Just redblink. assert(1 == 2); } - if (read(IO_CDC, &in, 1, 1) < 0) { + if (read(ep, &in, 1, 1) < 0) { // read failed! I/O broken? Just redblink. assert(1 == 2); } - if (in == '+') { + switch (in) { + case '+': syscall(TK1_SYSCALL_RESET, 0); + break; + case 'F': + puts(ep, "\r\nEnabling FIDO HID\r\n"); + select_ep_cmd[1] |= IO_FIDO; + write(IO_CH552, select_ep_cmd, sizeof(select_ep_cmd)); + break; + case 'f': + puts(ep, "\r\nDisabling FIDO HID\r\n"); + select_ep_cmd[1] &= ~IO_FIDO; + write(IO_CH552, select_ep_cmd, sizeof(select_ep_cmd)); + break; + case 'D': + puts(ep, "\r\nEnabling DEBUG HID\r\n"); + select_ep_cmd[1] |= IO_DEBUG; + write(IO_CH552, select_ep_cmd, sizeof(select_ep_cmd)); + break; + case 'd': + puts(ep, "\r\nDisabling DEBUG HID\r\n"); + select_ep_cmd[1] &= ~IO_DEBUG; + write(IO_CH552, select_ep_cmd, sizeof(select_ep_cmd)); + break; + case 's': + puts(IO_DEBUG, "This was sent to the DEBUG HID\n"); + break; + case 'e': + puts(ep, "Switching to CDC\r\n"); + ep = IO_CDC; + break; + case 'E': + puts(ep, "Switching to DEBUG\r\n"); + ep = IO_DEBUG; + break; + default: + write(ep, &in, 1); + break; } - - write(IO_CDC, &in, 1); } }