USB Composite
- group USB_Composite
USB composite device consists of mutiple configurations, which then each consist multiple interfaces.
This module offers fundamental components to realize USB composite device which include multiple USB classes, such as USB Audio & HID.
How to init USB device & configuration
- Example
T_USB_DEVICE_DESC demo_usb_dev_desc = { ...init... }; T_USB_CONFIG_DESC demo_usb_cfg_desc = { ...init... }; usb_composite_dev_init(&demo_usb_dev_desc); usb_composite_dev_cfg_add(&demo_usb_cfg_desc); //if string index of demo_usb_dev_desc/demo_usb_cfg_desc is not zero usb_composite_dev_string_add(language, string index, string);
How to realize USB interfaces
The core interface information is defined in T_USB_INTERFACE. It is mainly to initialize T_USB_INTERFACE to realize an interface.
- Example
#include "usb_spec20.h" T_USB_INTERFACE_DESC std_if_desc_hs = { ...init... }; (Class interface descriptor type) class_if_desc_hs = { ...init... }; T_USB_ENDPOINT_DESC std_endpoint_desc_hs = { ...init... }; (Class endpoint descriptor type) class_endpoint_desc_hs = { ...init... }; T_USB_INTERFACE_DESC std_if_desc_fs = { ...init... }; (Class interface descriptor type) class_if_desc_fs = { ...init... }; T_USB_ENDPOINT_DESC std_endpoint_desc_fs = { ...init... }; (Class endpoint descriptor type) class_endpoint_desc_fs = { ...init... }; T_USB_DESC_HDR* demo_if_descs_hs[] = { (T_USB_DESC_HDR*)&std_if_desc_hs, (T_USB_DESC_HDR*)&class_if_desc_hs, (T_USB_DESC_HDR*)&std_endpoint_desc_hs, (T_USB_DESC_HDR*)&class_endpoint_desc_hs, NULL, }; T_USB_DESC_HDR* demo_if_descs_fs[] = { (T_USB_DESC_HDR*)&std_if_desc_fs, (T_USB_DESC_HDR*)&class_if_desc_fs, (T_USB_DESC_HDR*)&std_endpoint_desc_fs, (T_USB_DESC_HDR*)&class_endpoint_desc_fs, NULL, }; int demo_if_ctrl_request_proc(T_USB_INTERFACE *interface, T_USB_DEVICE_REQUEST *ctrl_request, T_HAL_USB_REQUEST_BLOCK *ctrl_urb) { //Process class specific control request } int demo_if_alt_get(T_USB_INTERFACE *interface, T_HAL_USB_REQUEST_BLOCK *ctrl_urb) { //Process GET_ALT request } int demo_if_alt_set(T_USB_INTERFACE *interface, T_HAL_USB_REQUEST_BLOCK *ctrl_urb, uint8_t alt) { //Process SET_ALT request } int demo_if_create(T_USB_INTERFACE *interface) { //Init interface related resource, such as endpoints } int demo_if_release(T_USB_INTERFACE *interface) { //Deinit interface related resource initialized in \ref demo_if_create } int demo_if_suspend(T_USB_INTERFACE *interface) { //Process suspend } int demo_if_resume(T_USB_INTERFACE *interface) { //Process resume } T_USB_INTERFACE usb_if = { .if_num = 0, .descs_fs = demo_if_descs_fs, .descs_hs = demo_if_descs_hs, .ctrl_request_proc = demo_if_ctrl_request_proc, .alt_get = demo_if_alt_get, .alt_set = demo_if_alt_set, .suspend = demo_if_suspend, .resume = demo_if_resume, .create = demo_if_create, .release = demo_if_release, }; usb_composite_dev_interface_add(&usb_if, cfg val);
Definitions
Typedefs
-
typedef struct _usb_ep T_USB_EP
USB Composite device APIs & definitions.
USB endpoint structure, it's the item of list eps in T_USB_INTERFACE
- Param p_next:
point to next endpoint of list eps in T_USB_INTERFACE
- Param addr:
endpoint address
- Param desc:
endpoint descriptor
- Param ep_handle:
endpoint handle
-
typedef struct _usb_interface T_USB_INTERFACE
Core structure to realize interface.
- Param if_num:
interface number, NOTE: the value may be changed in usb_composite_dev_interface_add
- Param descs_fs:
full speed interface descriptors
- Param descs_hs:
high speed interface descriptors
- Param eps:
endpoint list belongs to the interface
- Param ctrl_request_proc:
callback to process class specific requests
- Param alt_get:
callback to process GET_ALT request
- Param alt_set:
callback to process SET_ALT request
- Param create:
callback to initialize interface, that will be called in usb_composite_dev_interface_add
.
And if_num in the input parameter interface may be changed, the interface MUST change bInterfaceNumber
in the interface descriptor to the actual interface number.- Param release:
callback to release interface related resource
- Param priv:
private data
Functions
-
uint8_t usb_composite_dev_ep0_mps_get(void)
Get ep0 maxpacket size.
- 返回:
uint8_t Get ep0 maxpacket size
-
int usb_composite_dev_string_add(uint16_t language, uint8_t id, const char *s)
Add string to USB composite device.
- Example
Please refer to How to init USB device & configuration
- 参数:
language -- language of target string
id -- id of target string, it's the value of string index in the according descriptor
s -- string
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_string_remove(uint16_t language, uint8_t id, const char *s)
Remove string from USB composite device.
- 参数:
language -- language of target string
id -- id of target string, it's the value of string index in the according descriptor
s -- string
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_cfg_add(T_USB_CONFIG_DESC *cfg_desc)
Add configuration to USB composite device.
- Example
Please refer to How to init USB device & configuration
- 参数:
cfg_desc -- configuration descriptor
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_cfg_remove(T_USB_CONFIG_DESC *cfg_desc)
Remove configuration from USB composite device.
- Example
Please refer to How to init USB device & configuration
- 参数:
cfg_desc -- configuration descriptor
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_interface_add(T_USB_INTERFACE *interface, uint8_t cfg_val)
Add interface to target configuration.
- Example
Please refer to How to realize USB interfaces
- 参数:
interface -- refer to How to realize USB interfaces
cfg_val -- configuration value the interface belongs to
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_interface_remove(T_USB_INTERFACE *interface, uint8_t cfg_val)
Remove interface from target configuration.
- 参数:
interface -- refer to How to realize USB interfaces
cfg_val -- configuration value the interface belongs to
- 返回:
int result, refer to rtl_errno.h
-
T_HAL_USB_SPEED usb_composite_dev_enum_speed_get(void)
get enum speed, it's the actual running speed after speed enum
- 返回:
T_HAL_USB_SPEED
-
int usb_composite_dev_remote_wakeup(bool force)
Remote wakeup.
- 参数:
force -- if true, device will always do remote wakeup regardless of SET_FEATURE request.
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_init(T_USB_DEVICE_DESC *dev_desc)
init USB composite device
- Example
Please refer to How to init USB device & configuration
- 参数:
dev_desc -- device descriptor
- 返回:
int result, refer to rtl_errno.h
-
int usb_composite_dev_deinit(void)
deinit USB composite device
-
struct _usb_ep
- #include <usb_composite_dev.h>
USB Composite device APIs & definitions.
USB endpoint structure, it's the item of list eps in T_USB_INTERFACE
- Param p_next:
point to next endpoint of list eps in T_USB_INTERFACE
- Param addr:
endpoint address
- Param desc:
endpoint descriptor
- Param ep_handle:
endpoint handle
-
struct _usb_interface
- #include <usb_composite_dev.h>
Core structure to realize interface.
- Param if_num:
interface number, NOTE: the value may be changed in usb_composite_dev_interface_add
- Param descs_fs:
full speed interface descriptors
- Param descs_hs:
high speed interface descriptors
- Param eps:
endpoint list belongs to the interface
- Param ctrl_request_proc:
callback to process class specific requests
- Param alt_get:
callback to process GET_ALT request
- Param alt_set:
callback to process SET_ALT request
- Param create:
callback to initialize interface, that will be called in usb_composite_dev_interface_add
.
And
if_numin the input parameter interface may be changed, the interface MUST change bInterfaceNumber
in the interface descriptor to the actual interface number.
- Param release:
callback to release interface related resource
- Param priv:
private data
Public Members
-
uint8_t if_num
-
struct usb_descriptor_header **descs_fs
-
struct usb_descriptor_header **descs_hs
-
T_USB_UTILS_LIST eps
-
int (*ctrl_request_proc)(struct _usb_interface *interface, T_USB_DEVICE_REQUEST *ctrl_request, T_HAL_USB_REQUEST_BLOCK *ctrl_urb)
-
int (*alt_get)(struct _usb_interface *interface, T_HAL_USB_REQUEST_BLOCK *ctrl_urb)
-
int (*alt_set)(struct _usb_interface *interface, T_HAL_USB_REQUEST_BLOCK *ctrl_urb, uint8_t alt)
-
int (*suspend)(struct _usb_interface *interface)
-
int (*resume)(struct _usb_interface *interface)
-
int (*create)(struct _usb_interface *interface)
-
int (*release)(struct _usb_interface *interface)
-
void *priv