FTDI Community

General Category => Discussion - Software => Topic started by: kaspro on December 30, 2020, 04:07:08 AM

Title: FT90X USB Question: Handling Multiple Keyboard Endpoints (BOOT, NKRO, etc.)
Post by: kaspro on December 30, 2020, 04:07:08 AM
I'm making a Keyboard-to-Controller adapter using the FT908. Pretty simple design: You plug a keyboard into one end, and the other end plugs into a Nintendo Switch. From there, you can use your keyboard as a controller.

Right now I'm trying to handle the USB keyboard inputs and this harder than I expected.

Right now I'm using a Corsair K65. It has 3 endpoints and I need to listen to them all simultaneously:

I also made a video of me going through the keyboard and asking questions: https://photos.app.goo.gl/7j98istA1GyRfbjE6

The two questions I have:

I've attached the USB HID data of my keyboard (interfaces, endpoints, etc.) Hope this helps someone answer my question 🙏
Title: Re: FT90X USB Question: Handling Multiple Keyboard Endpoints (BOOT, NKRO, etc.)
Post by: FTDI Community on January 06, 2021, 04:45:53 PM
Hello,

If there are 3 endpoints to monitor then the USBH_transfer_async is good way to do it.

You pass in a unique ID (one for each endpoint) and a callback function (the parameters are in the ft900_usbh.h header file).

typedef int8_t (*USBH_callback)(uint32_t id, int8_t status, size_t len, uint8_t *buffer);

There are no examples but it is the same as USBH_transfer except that you get your buffer filled and your callback called during the USBH_Process call. The ID will be used to differentiate the endpoints.

Best Regards,
FTDI Community
Title: Re: FT90X USB Question: Handling Multiple Keyboard Endpoints (BOOT, NKRO, etc.)
Post by: kaspro on January 06, 2021, 06:08:54 PM
Hello,

If there are 3 endpoints to monitor then the USBH_transfer_async is good way to do it.

You pass in a unique ID (one for each endpoint) and a callback function (the parameters are in the ft900_usbh.h header file).

typedef int8_t (*USBH_callback)(uint32_t id, int8_t status, size_t len, uint8_t *buffer);

There are no examples but it is the same as USBH_transfer except that you get your buffer filled and your callback called during the USBH_Process call. The ID will be used to differentiate the endpoints.

Best Regards,
FTDI Community

Thank you so much! I actually solved & nailed the async transfer function (it's working great!)

Right now I'm just trying to figure out how to get the HID Interface Report Descriptors so I can do some parsing on the device. They look like this:

Code: [Select]
Interface 0 HID Report Descriptor Keyboard
Item Tag (Value) Raw Data
Usage Page (Generic Desktop) 05 01
Usage (Keyboard) 09 06
Collection (Application) A1 01
    Usage Page (Keyboard/Keypad) 05 07
    Usage Minimum (Keyboard Left Control) 19 E0
    Usage Maximum (Keyboard Right GUI) 29 E7
    Logical Minimum (0) 15 00
    Logical Maximum (1) 25 01
    Report Size (1) 75 01
    Report Count (8) 95 08
    Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
    Input (Cnst,Ary,Abs) 81 01
    Usage Minimum (Undefined) 19 00
    Usage Maximum 2A FF 00
    Logical Minimum (0) 15 00
    Logical Maximum (255) 26 FF 00
    Report Size (8) 75 08
    Report Count (6) 95 06
    Input (Data,Ary,Abs) 81 00
    Usage Page (LEDs) 05 08
    Usage Minimum (Num Lock) 19 01
    Usage Maximum (Scroll Lock) 29 03
    Logical Minimum (0) 15 00
    Logical Maximum (1) 25 01
    Report Size (1) 75 01
    Report Count (3) 95 03
    Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02
    Report Count (5) 95 05
    Output (Cnst,Ary,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 01
End Collection C0

I'd ideally parse this information for all "Usage (Keyboard)" so I know what I'm receiving, even from the weirdest of keyboards.
Title: Re: FT90X USB Question: Handling Multiple Keyboard Endpoints (BOOT, NKRO, etc.)
Post by: FTDI Community on January 08, 2021, 04:38:50 PM
Hello,

The following function should help:

USBH_device_get_descriptor(hDev, USB_DESCRIPTOR_TYPE_REPORT, index, offset, buffer)

USB_DESCRIPTOR_TYPE_REPORT comes from ft900_usb_hid.h.

Best Regards,
FTDI Community