Are there any USBUS HID Examples

Hi,

I am trying to implement a basic usb device which will include both a cdc endpoint and hid endpoint, however was wandering if there are any example of usb and hid devices implementaions, i am running on an nucleo wb55 for development purposes and so far my main.c is attached bellow however line 76 usbus_hid_submit(&hid, buffer, sizeof(buffer)); results in errors when trying to compile,

more specifically: errors in format /Applications/ARM/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: DWARF error: section .debug_str is larger than its filesize! (0x80d9e vs 0x55e08) with varying values at the end of each line

followed by /Users/elliot/Documents/code/riot-tests/LED/bin/p-nucleo-wb55/application_test_app//main.o:/Users/elliot/Documents/code/riot-tests/LED/main.c:97: undefined reference to 'usbus_hid_submit' something which should be included from #include "usb/usbus/hid.h"

Anyone able to shed light on what error i have made here or wether there are some good hid example for riot-os for example as the device acting as a keyboard?

Regards Elliot

main.c:

#include "usb/usbus.h"
#include "usb/usbus/hid.h"
#include "xtimer.h"

static usbus_t usbus;
static usbus_hid_device_t hid;
static char _stack[USBUS_STACKSIZE];

static const uint8_t  keyboard_hid_report[] = {

    0x05, 0x01,  // Usage Page (Generic Desktop)
    0x09, 0x06,  // Usage (Keyboard)
    0xA1, 0x01,  // Collection (Application)
    0x85, 1,  // Report ID
    // Modifiers (8 bits)
    0x05, 0x07,  //   Usage Page (Keyboard/Keypad)
    0x19, 0xE0,  //   Usage Minimum (Keyboard Left Control)
    0x29, 0xE7,  //   Usage Maximum (Keyboard Right GUI)
    0x15, 0x00,  //   Logical Minimum (0)
    0x25, 0x01,  //   Logical Maximum (1)
    0x95, 0x08,  //   Report Count (8)
    0x75, 0x01,  //   Report Size (1)
    0x81, 0x02,  //   Input (Data, Variable, Absolute)
    // Reserved (1 byte)
    0x95, 0x01,  //   Report Count (1)
    0x75, 0x08,  //   Report Size (8)
    0x81, 0x03,  //   Input (Constant)
    // Keycodes (6 bytes)
    0x05, 0x07,        //   Usage Page (Keyboard/Keypad)
    0x19, 0x00,        //   Usage Minimum (0)
    0x29, 0xFF,        //   Usage Maximum (255)
    0x15, 0x00,        //   Logical Minimum (0)
    0x26, 0xFF, 0x00,  //   Logical Maximum (255)
    0x95, 0x06,        //   Report Count (6)
    0x75, 0x08,        //   Report Size (8)
    0x81, 0x00,        //   Input (Data, Array, Absolute)

    // Status LEDs (5 bits)
    0x05, 0x08,  //   Usage Page (LED)
    0x19, 0x01,  //   Usage Minimum (Num Lock)
    0x29, 0x05,  //   Usage Maximum (Kana)
    0x95, 0x05,  //   Report Count (5)
    0x75, 0x01,  //   Report Size (1)
    0x91, 0x02,  //   Output (Data, Variable, Absolute)
    // LED padding (3 bits)
    0x95, 0x01,  //   Report Count (1)
    0x75, 0x03,  //   Report Size (3)
    0x91, 0x03,  //   Output (Constant)
    0xC0,        // End Collection

};
void kbhidcb(usbus_hid_device_t *hid, uint8_t *data, size_t len){
    printf("%d, %u, %u", hid->report_desc_size, data[0], len);
}



int main(void)
{
        /* Get driver context */
    usbdev_t *usbdev = usbdev_get_ctx(0);

    /* Initialize basic usbus struct, don't start the thread yet */
    usbus_init(&usbus, usbdev);

    usbus_hid_init(&usbus, &hid, kbhidcb, keyboard_hid_report, sizeof(keyboard_hid_report));


    /* Finally initialize USBUS thread */
    usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus);
    xtimer_sleep(5);
    uint8_t buffer[CONFIG_USBUS_HID_INTERRUPT_EP_SIZE];
    buffer[0] = 0x01;
    buffer[1] = 0x25;

    usbus_hid_submit(&hid, buffer, sizeof(buffer));


    return 0;
}

Makefile:

    # name of your application
APPLICATION = test_app

# If no BOARD is found in the environment, use this default:
BOARD = p-nucleo-wb55

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../riot

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

# Use a peripheral timer for the delay, if available
USEMODULE += USBUS
USEMODULE += usbus_hid
USEMODULE += xtimer

USB_VID=${USB_VID_TESTING} 
USB_PID=${USB_PID_TESTING}

include $(RIOTBASE)/Makefile.include

Did you have a look at the tests/usbus_hid application ?

i did explore the example in test however it uses the hid_io.h driver instead of hid.h, so is not much great deal of help, hid.h permits multiple endpoints and appears to be non-blocking unlike hid.h which appears more suitable from the docs in my usecase

It seems that the function that you are trying to use is not implemented, there’s only the definition in hid.h. It was like this from the start (see https://github.com/RIOT-OS/RIOT/pull/14629).

It seems that hid_io can also be used async. See https://github.com/RIOT-OS/RIOT/pull/16689 but I’m not sure that fits your use case.