USB composite device structures
The USB composite device structures are defined in the USB stack code. The structures describe the class and are consistent with the descriptor. They are also used in single function examples.
usb_device_class_config_list_struct_t
This structure is required for the composite device and relays device callback, class callback, interface numbers, and endpoint numbers of each interface to the class driver. The structure should be placed in the “composite.c” file.
This is an example for a composite device MSD + CDC:
usb_device_class_config_list_struct_t g_compositeDeviceConfigList =
{
.config = g_compositeDevice,
.deviceCallback = USB_DeviceCallback,
.count = 2,
};
The variable “count” holds the number of classes included in the composite device. Because the composite device MSD+CDC includes two classes, the value of variable “count” is 2.
The type of “config” is usb_device_class_config_struct_t. See subsequent sections for more information.
Parent topic:USB composite device structures
usb_device_class_config_struct_t
This structure is required for the composite device and provides information about each class. The structure should be placed in the “composite.c” file.
This is an example for the composite device MSD + CDC:
usb_device_class_config_struct_t g_compositeDevice[2] =
{
{
.classCallback = USB_DeviceCdcVcomCallback,
.classHandle = (class_handle_t)NULL,
.classInfomation = &g_UsbDeviceCdcVcomConfig,
},
{
.classCallback = USB_DeviceMscCallback,
.classHandle = (class_handle_t)NULL,
.classInfomation = &g_mscDiskClass,
}
};
classCallback is the callback function pointer of each class.
classHandle is the class handle. This value is NULL and updated by the USB_DeviceClassInit function.
The type of classInfomationis usb_device_class_struct_t, including the configuration count, class type, and the interface list for this class.
Parent topic:USB composite device structures
usb_device_class_struct_t
This structure is required for each class including the class type, supported configuration count, and interface list for each configuration. The structure should be placed in the “usb_device_descriptor.c” file.
This is an example for MSD in the composite MSD + CDC device example.
usb_device_class_struct_t g_mscDiskClass =
{
.interfaceList = g_mscDiskInterfaceList,
.type = kUSB_DeviceClassTypeMsc,
.configurations = USB_DEVICE_CONFIGURATION_COUNT,
};
interfaceList is the interface list pointer, which points to the type usb_device_interface_list_t. It includes detailed interface information about the class including interface count, alternate setting count for each interface, and ep count, ep type, and ep direction for each alternate setting. See subsequent sections for more information.
Type represents the type of each class included in the composite device. For example, the type of MSD class is kUSB_DeviceClassTypeMsc.
Configurations member indicates the count of the class supported.
Parent topic:USB composite device structures
usb_device_interface_list_t
This structure is required for the composite device and provides information about each class. The structure should be placed in the “usb_device_descriptor.c” file.
This is an example for MSC in the composite MSC + CDC device example.
usb_device_interface_list_t g_mscDiskInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] =
{
{
.count = USB_MSC_DISK_INTERFACE_COUNT,
.interfaces = g_mscDiskInterfaces,
},
};
Count indicates the interface count this class supports in each configuration.
Interfaces member indicates the interface list for each configuration.
Parent topic:USB composite device structures
usb_device_interfaces_struct_t
This structure provides alternate setting interface information about each interface. All structures should be placed in the “usb_device_descriptor.c” file.
Prototype:
typedef struct _usb_device_interfaces_struct
{
uint8_t classCode;
uint8_t subclassCode;
uint8_t protocolCode;
uint8_t interfaceNumber;
usb_device_interface_struct_t* interface;
uint8_t count;
} usb_device_interfaces_struct_t;
Description:
classCode: The class code for this interface.
subclassCode: The subclass code for this interface.
protocolCode: The protocol code for this interface.
interfaceNumber: Interface index in the interface descriptor.
interface: Includes detailed information about the current interface. For details, see subsequent chapters.
count: Number of interfaces in the current interface.
This is an example for the composite device MSD + CDC:
MSD:
usb_device_interfaces_struct_t g_mscDiskInterfaces[USB_MSC_DISK_INTERFACE_COUNT] =
{
{
USB_MSC_DISK_CLASS,
USB_MSC_DISK_SUBCLASS,
USB_MSC_DISK_PROTOCOL,
USB_MSC_DISK_INTERFACE_INDEX,
g_mscDiskInterface,
sizeof(g_mscDiskInterface) / sizeof(usb_device_interface_struct_t),
}
};
USB_MSC_DISK_INTERFACE_INDEX
is the interface index of this interface in a current configuration. In other words, in the interface descriptor, the interface number is USB_MSC_DISK_INTERFACE_INDEX
.
“g_mscDiskInterface”
is the interface detailed information structure. See usb_device_interface_struct_t section for more information.
CDC:
usb_device_interfaces_struct_t g_cdcVcomInterfaces[USB_CDC_VCOM_INTERFACE_COUNT] =
{
{
USB_CDC_VCOM_CIC_CLASS,
USB_CDC_VCOM_CIC_SUBCLASS,
USB_CDC_VCOM_CIC_PROTOCOL,
USB_CDC_VCOM_CIC_INTERFACE_INDEX,
g_cdcVcomCicInterface, sizeof(g_cdcVcomCicInterface) / sizeof(usb_device_interface_struct_t)
},
{
USB_CDC_VCOM_DIC_CLASS,
USB_CDC_VCOM_DIC_SUBCLASS,
USB_CDC_VCOM_DIC_PROTOCOL,
USB_CDC_VCOM_DIC_INTERFACE_INDEX,
g_cdcVcomDicInterface, sizeof(g_cdcVcomDicInterface) / sizeof(usb_device_interface_struct_t)
},
};
USB_CDC_VCOM_CIC_INTERFACE_INDEX
is the interface index of the control interface in a current configuration. In other words, in the interface descriptor, the interface number is USB_CDC_VCOM_CIC_INTERFACE_INDEX.
USB_CDC_VCOM_DIC_INTERFACE_INDEX
is the interface index of the data interface in a current configuration. In other words, in the interface descriptor, the interface number is USB_CDC_VCOM_DIC_INTERFACE_INDEX
.
“g_cdcVcomCicInterface”
is the control interface structure with detailed information. See usb_device_interface_struct_t section for more information.
“g_cdcVcomDicInterface”
is the data interface structure with detailed information. See usb_device_interface_struct_t section for more information.
Parent topic:USB composite device structures
usb_device_interface_struct_t
This structure provides information about each alternate setting interface for the current interface. All structures should be placed in the “usb_device_descriptor.c” file.
Prototype:
typedef struct _usb_device_interface_struct
{
uint8_t alternateSetting;
usb_device_endpoint_list_t endpointList;
void* classSpecific;
} usb_device_interface_struct_t;
Description:
alternateSetting: The alternate value of this interface.
endpointList: endpoint list structure. See the usb_device_endpoint_list_t structure.
classSpecific: The class-specific structure pointer.
Prototype:
typedef struct _usb_device_endpoint_list
{
uint8_t count;
usb_device_endpoint_struct_t* endpoint;
} usb_device_endpoint_list_t;
Description:
count: Number of endpoints in the current interface.
endpoint: Endpoint information structure.
This is an example for the composite device MSD + CDC:
MSD:
usb_device_interface_struct_t g_mscDiskInterface[] =
{
{
0,
{
USB_MSC_DISK_ENDPOINT_COUNT,
g_mscDiskEndpoints,
},
},
};
Number “0” holds the alternate setting value of the MSD interface.
USB_MSC_DISK_ENDPOINT_COUNT is the endpoint number for MSD interface when the alternate setting is 0.
“g_mscDiskEndpoints”
is the endpoint detailed information structure. See usb_device_endpoint_struct_t section for more information.
CDC:
For control interface:
/* Define interface for communication class */
usb_device_interface_struct_t g_cdcVcomCicInterface[] =
{
{
0,
{
USB_CDC_VCOM_CIC_ENDPOINT_COUNT,
g_cdcVcomCicEndpoints,
},
}
};
Number “0” holds the alternate setting value of the CDC control interface.
USB_CDC_VCOM_CIC_ENDPOINT_COUNT is the endpoint number for control interface when the alternate setting is 0.
“g_cdcVcomCicEndpoints"
is the endpoint detailed information structure. See usb_device_endpoint_struct_t section for more information.
For data interface:
/* Define interface for data class */
usb_device_interface_struct_t g_cdcVcomDicInterface[] =
{
{
0,
{
USB_CDC_VCOM_DIC_ENDPOINT_COUNT,
g_cdcVcomDicEndpoints,
},
}
};
Number “0” holds the alternate setting value of the CDC data interface.
USB_CDC_VCOM_DIC_ENDPOINT_COUNT is the endpoint number for control interface when the alternate setting is 0.
“g_cdcVcomDicEndpoints”
is the endpoint detailed information structure. See usb_device_endpoint_struct_t section for more information.
Parent topic:USB composite device structures
usb_device_endpoint_struct_t
This structure is required for the composite device and provides ep information. All structures should be placed in the “usb_device_descriptor.c” file.
Prototype:
typedef struct _usb_device_endpoint_struct
{
uint8_t endpointAddress; /*! endpoint address*/
uint8_t transferType; /*! endpoint transfer type*/
uint16_t maxPacketSize; /*! endpoint max packet size */
} usb_device_endpoint_struct_t;
Description:
endpointAddress: Endpoint address (b7, 0 – USB_OUT, 1 – USB_IN).
transferType: The transfer type of this endpoint.
maxPacketSize: The maximum packet size of this endpoint.
This is an example for the composite device MSD + CDC:
MSD:
usb_device_endpoint_struct_t g_mscDiskEndpoints[USB_MSC_DISK_ENDPOINT_COUNT] =
{
{
USB_MSC_DISK_BULK_IN_ENDPOINT | (USB_IN << 7U),
USB_ENDPOINT_BULK,
FS_MSC_DISK_BULK_IN_PACKET_SIZE,
},
{
USB_MSC_DISK_BULK_OUT_ENDPOINT | (USB_OUT << 7U),
USB_ENDPOINT_BULK,
FS_MSC_DISK_BULK_OUT_PACKET_SIZE,
}
};
CDC:
This is CDC class control interface endpoint information.
/* Define endpoint for communication class */
usb_device_endpoint_struct_t g_cdcVcomCicEndpoints[USB_CDC_VCOM_CIC_ENDPOINT_COUNT] =
{
{
USB_CDC_VCOM_CIC_INTERRUPT_IN_ENDPOINT | (USB_IN << 7U),
USB_ENDPOINT_INTERRUPT,
HS_CDC_VCOM_BULK_IN_PACKET_SIZE,
},
};
This is the CDC class data interface endpoint information.
/* Define endpoint for data class */
usb_device_endpoint_struct_t g_cdcVcomDicEndpoints[USB_CDC_VCOM_DIC_ENDPOINT_COUNT] =
{
{
USB_CDC_VCOM_DIC_BULK_IN_ENDPOINT | (USB_IN << 7U),
USB_ENDPOINT_BULK,
FS_CDC_VCOM_BULK_IN_PACKET_SIZE,
},
{
USB_CDC_VCOM_DIC_BULK_OUT_ENDPOINT | (USB_OUT << 7U),
USB_ENDPOINT_BULK,
FS_CDC_VCOM_BULK_OUT_PACKET_SIZE,
},
};
Parent topic:USB composite device structures