This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

2 HIDs in one composite USB code

I need to write 2HIds in one composite device in STM32 microcontrollers.One for pointer mouse operation and other one for keypad operation.So i wish to know is it possible to do so?If yes will I need to write 2 separate report descriptors.I am using 2 interfaces and 2 ENDPOINTS (enp1 and enp2). Please help...

Parents
  • Two HID "device" on single USB device

    There are two ways,
    a) Multi-TLCs (Top-Level Collections) on single HID
    b) HID + HID interfaces on composite device

    a) is easier than b), when you have base code of both.

    In Multi-TLCs method, the major modification is applied just to the report descriptor.

    a-1) Report descriptor
    When you start with keyboard example,
    - Insert "REPORT ID (1)" before the keyboard report descriptor
    - Append "REPORT ID (2)" after the keyboard report descriptor
    - Append mouse report descriptor, as is

    Report descriptor
    - REPORT ID (1)   0x85, 0x01
    - - full-contents of keyboard report descriptor
    - REPORT ID (2)   0x85, 0x02
    - - full-contents of mouse report descriptor
    

    Of course, the size of report descriptor increases by the appendage.
    Tune the constant (#define) of the report descriptor size,
    referred at HID interface, and Get_Descriptor( HID_REPORT ) process.

    a-2) Report ID
    As the one-byte report ID is attached before each input/output report,

    - wMaxPacketSize field of the interrupt IN/OUT endpoint descriptors should be tuned to fit to this report size. Usually, "standard" keyboard puts 8 bytes input report (1 modifier, 1 constant, 6 key index array), at least 9 bytes (+1 byte report ID) is required.

        /******************** Descriptor of Joystick Mouse endpoint ********************/
        /* 27 */
        0x07,          /*bLength: Endpoint Descriptor size*/
        USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
    
        0x81,          /*bEndpointAddress: Endpoint Address (IN)*/
        0x03,          /*bmAttributes: Interrupt endpoint*/
        0x04,          /*wMaxPacketSize: 4 Byte max */      // <------ 9 bytes
        0x00,
        0x20,          /*bInterval: Polling Interval (32 ms)*/  // <---- 1ms is better
    

    The interrupt IN endpoint is shared by keyboard and mouse.
    The keyboard code puts an input report with one-byte report ID (1).
    - 1 (report ID), keyboard input report follows.

    The mouse code puts an input report with one-byte report ID (2).
    - 2 (report ID), mouse input report follows.

    That's all

    Tsuneo

Reply
  • Two HID "device" on single USB device

    There are two ways,
    a) Multi-TLCs (Top-Level Collections) on single HID
    b) HID + HID interfaces on composite device

    a) is easier than b), when you have base code of both.

    In Multi-TLCs method, the major modification is applied just to the report descriptor.

    a-1) Report descriptor
    When you start with keyboard example,
    - Insert "REPORT ID (1)" before the keyboard report descriptor
    - Append "REPORT ID (2)" after the keyboard report descriptor
    - Append mouse report descriptor, as is

    Report descriptor
    - REPORT ID (1)   0x85, 0x01
    - - full-contents of keyboard report descriptor
    - REPORT ID (2)   0x85, 0x02
    - - full-contents of mouse report descriptor
    

    Of course, the size of report descriptor increases by the appendage.
    Tune the constant (#define) of the report descriptor size,
    referred at HID interface, and Get_Descriptor( HID_REPORT ) process.

    a-2) Report ID
    As the one-byte report ID is attached before each input/output report,

    - wMaxPacketSize field of the interrupt IN/OUT endpoint descriptors should be tuned to fit to this report size. Usually, "standard" keyboard puts 8 bytes input report (1 modifier, 1 constant, 6 key index array), at least 9 bytes (+1 byte report ID) is required.

        /******************** Descriptor of Joystick Mouse endpoint ********************/
        /* 27 */
        0x07,          /*bLength: Endpoint Descriptor size*/
        USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
    
        0x81,          /*bEndpointAddress: Endpoint Address (IN)*/
        0x03,          /*bmAttributes: Interrupt endpoint*/
        0x04,          /*wMaxPacketSize: 4 Byte max */      // <------ 9 bytes
        0x00,
        0x20,          /*bInterval: Polling Interval (32 ms)*/  // <---- 1ms is better
    

    The interrupt IN endpoint is shared by keyboard and mouse.
    The keyboard code puts an input report with one-byte report ID (1).
    - 1 (report ID), keyboard input report follows.

    The mouse code puts an input report with one-byte report ID (2).
    - 2 (report ID), mouse input report follows.

    That's all

    Tsuneo

Children