Microchip® Advanced Software Framework

HID Generic in a Composite Device

A USB Composite Device is a USB Device which uses more than one USB class.

In this use case, the "USB HID Generic (Composite Device)" module is used to create a USB composite device. Thus, this USB module can be associated with another "Composite Device" module, like "USB MSC (Composite Device)".

Also, you can refer to application note AVR4902 ASF - USB Composite Device.

Setup steps

For the setup code of this use case to work, the Basic Use Case must be followed.

Usage steps

Example code

Content of conf_usb.h:

#define USB_DEVICE_EP_CTRL_SIZE 64
#define USB_DEVICE_NB_INTERFACE (X+1)
#define USB_DEVICE_MAX_EP (X+2)
#define UDI_HID_GENERIC_EP_IN (1 | USB_EP_DIR_IN)
#define UDI_HID_GENERIC_EP_OUT (2 | USB_EP_DIR_OUT)
#define UDI_HID_GENERIC_IFACE_NUMBER X
#define UDI_COMPOSITE_DESC_T \
udi_hid_generic_desc_t udi_hid_generic; \
...
#define UDI_COMPOSITE_DESC_FS \
.udi_hid_generic = UDI_HID_GENERIC_DESC, \
...
#define UDI_COMPOSITE_DESC_HS \
.udi_hid_generic = UDI_HID_GENERIC_DESC, \
...
#define UDI_COMPOSITE_API \
&udi_api_hid_generic, \
...

Workflow

  1. Ensure that conf_usb.h is available and contains the following parameters required for a USB composite device configuration:
    // Endpoint control size, This must be:
    // - 8 for low speed
    // - 8, 16, 32 or 64 for full speed device (8 is recommended to save RAM)
    // - 64 for a high speed device
    #define USB_DEVICE_EP_CTRL_SIZE 64
    // Total Number of interfaces on this USB device.
    // Add 1 for HID generic.
    #define USB_DEVICE_NB_INTERFACE (X+1)
    // Total number of endpoints on this USB device.
    // This must include each endpoint for each interface.
    // Add 1 for HID generic.
    #define USB_DEVICE_MAX_EP (X+2)
  2. Ensure that conf_usb.h contains the description of composite device:
    // The endpoint number chosen by you for the generic.
    // The endpoint number starting from 1.
    #define UDI_HID_GENERIC_EP_IN (1 | USB_EP_DIR_IN)
    #define UDI_HID_GENERIC_EP_OUT (2 | USB_EP_DIR_OUT)
    // The interface index of an interface starting from 0
    #define UDI_HID_GENERIC_IFACE_NUMBER X
  3. Ensure that conf_usb.h contains the following parameters required for a USB composite device configuration:

    // USB Interfaces descriptor structure
    #define UDI_COMPOSITE_DESC_T \
    ...
    udi_hid_generic_desc_t udi_hid_generic; \
    ...
    // USB Interfaces descriptor value for Full Speed
    ...
    .udi_hid_generic = UDI_HID_GENERIC_DESC, \
    ...
    // USB Interfaces descriptor value for High Speed
    ...
    .udi_hid_generic = UDI_HID_GENERIC_DESC, \
    ...
    // USB Interface APIs
    ...
    ...
    Note
    The descriptors order given in the four lists above must be the same as the order defined by all interface indexes. The interface index orders are defined through UDI_X_IFACE_NUMBER defines.

    A USB Composite Device is a USB Device which uses more than one USB class.

    In this use case, the "USB HID Generic (Composite Device)" module is used to create a USB composite device. Thus, this USB module can be associated with another "Composite Device" module, like "USB MSC (Composite Device)".

    Also, you can refer to application note AVR4902 ASF - USB Composite Device.

Setup steps

For the setup code of this use case to work, the basic use case must be followed.

Usage steps

Example code

Content of conf_usb.h:

#define USB_DEVICE_EP_CTRL_SIZE 64
#define USB_DEVICE_NB_INTERFACE (X+1)
#define USB_DEVICE_MAX_EP (X+2)
#define UDI_HID_GENERIC_EP_IN (1 | USB_EP_DIR_IN)
#define UDI_HID_GENERIC_EP_OUT (2 | USB_EP_DIR_OUT)
#define UDI_HID_GENERIC_IFACE_NUMBER X
#define UDI_COMPOSITE_DESC_T \
udi_hid_generic_desc_t udi_hid_generic; \
...
#define UDI_COMPOSITE_DESC_FS \
.udi_hid_generic = UDI_HID_GENERIC_DESC, \
...
#define UDI_COMPOSITE_DESC_HS \
.udi_hid_generic = UDI_HID_GENERIC_DESC, \
...
#define UDI_COMPOSITE_API \
&udi_api_hid_generic, \
...

Workflow

  1. Ensure that conf_usb.h is available and contains the following parameters required for a USB composite device configuration:
    • // Endpoint control size, This must be:
      // - 8 for low speed
      // - 8, 16, 32 or 64 for full speed device (8 is recommended to save RAM)
      // - 64 for a high speed device
      #define USB_DEVICE_EP_CTRL_SIZE 64
      // Total Number of interfaces on this USB device.
      // Add 1 for HID generic.
      #define USB_DEVICE_NB_INTERFACE (X+1)
      // Total number of endpoints on this USB device.
      // This must include each endpoint for each interface.
      // Add 1 for HID generic.
      #define USB_DEVICE_MAX_EP (X+2)
  2. Ensure that conf_usb.h contains the description of composite device:
    • // The endpoint number chosen by you for the generic.
      // The endpoint number starting from 1.
      #define UDI_HID_GENERIC_EP_IN (1 | USB_EP_DIR_IN)
      #define UDI_HID_GENERIC_EP_OUT (2 | USB_EP_DIR_OUT)
      // The interface index of an interface starting from 0
      #define UDI_HID_GENERIC_IFACE_NUMBER X
  3. Ensure that conf_usb.h contains the following parameters required for a USB composite device configuration:
    • // USB Interfaces descriptor structure
      #define UDI_COMPOSITE_DESC_T \
      ...
      udi_hid_generic_desc_t udi_hid_generic; \
      ...
      // USB Interfaces descriptor value for Full Speed
      #define UDI_COMPOSITE_DESC_FS \
      ...
      .udi_hid_generic = UDI_HID_GENERIC_DESC, \
      ...
      // USB Interfaces descriptor value for High Speed
      #define UDI_COMPOSITE_DESC_HS \
      ...
      .udi_hid_generic = UDI_HID_GENERIC_DESC, \
      ...
      // USB Interface APIs
      #define UDI_COMPOSITE_API \
      ...
      ...
    • Note
      The descriptors order given in the four lists above must be the same as the order defined by all interface indexes. The interface index orders are defined through UDI_X_IFACE_NUMBER defines.