1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #15752 from aabadie/pr/tests/usbus_hid_cleanup

tests/usbus_hid: uncrustify and cleanup Makefile
This commit is contained in:
Alexandre Abadie 2021-01-12 18:52:32 +01:00 committed by GitHub
commit 703c33fd3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 41 deletions

View File

@ -6,7 +6,7 @@ USEMODULE += usbus_hid
DISABLE_MODULE += auto_init_usbus DISABLE_MODULE += auto_init_usbus
USB_VID ?= ${USB_VID_TESTING} USB_VID ?= $(USB_VID_TESTING)
USB_PID ?= ${USB_PID_TESTING} USB_PID ?= $(USB_PID_TESTING)
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -24,62 +24,66 @@
#include "usb/usbus/hid.h" #include "usb/usbus/hid.h"
/* /*
this descriptor is used, because the basic usb_hid interface was developed in this descriptor is used, because the basic usb_hid interface was developed in
conjunction with FIDO2. Descriptor is taken from CTAP2 specification conjunction with FIDO2. Descriptor is taken from CTAP2 specification
(version 20190130) section 8.1.8.2 (version 20190130) section 8.1.8.2
*/ */
static uint8_t report_desc_ctap[] = { static uint8_t report_desc_ctap[] = {
0x06, 0xD0, 0xF1, /* HID_UsagePage ( FIDO_USAGE_PAGE ) */ 0x06, 0xD0, 0xF1, /* HID_UsagePage ( FIDO_USAGE_PAGE ) */
0x09, 0x01, /* HID_Usage ( FIDO_USAGE_CTAPHID ) */ 0x09, 0x01, /* HID_Usage ( FIDO_USAGE_CTAPHID ) */
0xA1, 0x01, /* HID_Collection ( HID_Application ) */ 0xA1, 0x01, /* HID_Collection ( HID_Application ) */
0x09, 0x20, /* HID_Usage ( FIDO_USAGE_DATA_IN ) */ 0x09, 0x20, /* HID_Usage ( FIDO_USAGE_DATA_IN ) */
0x15, 0x00, /* HID_LogicalMin ( 0 ) */ 0x15, 0x00, /* HID_LogicalMin ( 0 ) */
0x26, 0xFF, 0x00, /* HID_LogicalMaxS ( 0xff ) */ 0x26, 0xFF, 0x00, /* HID_LogicalMaxS ( 0xff ) */
0x75, 0x08, /* HID_ReportSize ( 8 ) */ 0x75, 0x08, /* HID_ReportSize ( 8 ) */
0x95, 0x40, /* HID_ReportCount ( HID_INPUT_REPORT_BYTES ) */ 0x95, 0x40, /* HID_ReportCount ( HID_INPUT_REPORT_BYTES ) */
0x81, 0x02, /* HID_Input ( HID_Data | HID_Absolute | HID_Variable ) */ 0x81, 0x02, /* HID_Input ( HID_Data | HID_Absolute | HID_Variable ) */
0x09, 0x21, /* HID_Usage ( FIDO_USAGE_DATA_OUT ) */ 0x09, 0x21, /* HID_Usage ( FIDO_USAGE_DATA_OUT ) */
0x15, 0x00, /* HID_LogicalMin ( 0 ) */ 0x15, 0x00, /* HID_LogicalMin ( 0 ) */
0x26, 0xFF, 0x00, /* HID_LogicalMaxS ( 0xff ) */ 0x26, 0xFF, 0x00, /* HID_LogicalMaxS ( 0xff ) */
0x75, 0x08, /* HID_ReportSize ( 8 ) */ 0x75, 0x08, /* HID_ReportSize ( 8 ) */
0x95, 0x40, /* HID_ReportCount ( HID_OUTPUT_REPORT_BYTES ) */ 0x95, 0x40, /* HID_ReportCount ( HID_OUTPUT_REPORT_BYTES ) */
0x91, 0x02, /* HID_Output ( HID_Data | HID_Absolute | HID_Variable ) */ 0x91, 0x02, /* HID_Output ( HID_Data | HID_Absolute | HID_Variable ) */
0xC0, /* HID_EndCollection */ 0xC0, /* HID_EndCollection */
}; };
static usbus_t usbus; static usbus_t usbus;
static char _stack[USBUS_STACKSIZE]; static char _stack[USBUS_STACKSIZE];
void usb_hid_io_init(usbus_t* usbus, uint8_t* report_desc, void usb_hid_io_init(usbus_t *usbus, uint8_t *report_desc,
size_t report_desc_size); size_t report_desc_size);
ssize_t usb_hid_io_read(void* buffer, size_t len); ssize_t usb_hid_io_read(void *buffer, size_t len);
void init(void) void init(void)
{ {
usbdev_t *usbdev = usbdev_get_ctx(0); usbdev_t *usbdev = usbdev_get_ctx(0);
usbus_init(&usbus, usbdev);
usb_hid_io_init(&usbus, report_desc_ctap, sizeof(report_desc_ctap)); usbus_init(&usbus, usbdev);
usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus); usb_hid_io_init(&usbus, report_desc_ctap, sizeof(report_desc_ctap));
usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus);
} }
int main(void) int main(void)
{ {
/* sleep to wait for Pyterm attaching in order to see puts messages */ /* sleep to wait for Pyterm attaching in order to see puts messages */
xtimer_sleep(3); xtimer_sleep(3);
init(); init();
puts("RIOT USB HID echo test"); puts("RIOT USB HID echo test");
puts("Write input to the hidraw device under /dev/hidrawX, and see if it gets echoed here"); puts(
"Write input to the hidraw device under /dev/hidrawX, and see if it gets echoed here");
uint8_t buffer[CONFIG_USBUS_HID_INTERRUPT_EP_SIZE]; uint8_t buffer[CONFIG_USBUS_HID_INTERRUPT_EP_SIZE];
for (;;) {
ssize_t len = usb_hid_io_read(buffer, CONFIG_USBUS_HID_INTERRUPT_EP_SIZE);
printf("Msg received via USB HID: "); for (;;) {
for (int i = 0; i < len; i++) { ssize_t len =
putc(buffer[i], stdout); usb_hid_io_read(buffer, CONFIG_USBUS_HID_INTERRUPT_EP_SIZE);
printf("Msg received via USB HID: ");
for (int i = 0; i < len; i++) {
putc(buffer[i], stdout);
}
printf("\n");
} }
printf("\n");
}
} }