Merge pull request #1382 from uestczyh222/master

[Coponents][USB device]add class register interface
This commit is contained in:
ZYH 2018-04-24 14:34:40 +08:00 committed by GitHub
commit 2bd7a0e864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 69 deletions

View File

@ -213,6 +213,13 @@ struct udevice
};
typedef struct udevice* udevice_t;
struct udclass
{
rt_list_t list;
ufunction_t (*rt_usbd_function_create)(udevice_t device);
};
typedef struct udclass* udclass_t;
enum udev_msg_type
{
USB_MSG_SETUP_NOTIFY,
@ -248,6 +255,7 @@ struct udev_msg
};
typedef struct udev_msg* udev_msg_t;
int rt_usbd_class_list_init(void);
udevice_t rt_usbd_device_new(void);
uconfig_t rt_usbd_config_new(void);
ufunction_t rt_usbd_function_new(udevice_t device, udev_desc_t dev_desc,
@ -266,6 +274,7 @@ rt_err_t rt_usbd_device_set_qualifier(udevice_t device, struct usb_qualifier_des
rt_err_t rt_usbd_device_set_os_comp_id_desc(udevice_t device, usb_os_comp_id_desc_t os_comp_id_desc);
rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg);
rt_err_t rt_usbd_config_add_function(uconfig_t cfg, ufunction_t func);
rt_err_t rt_usbd_class_register(udclass_t udclass);
rt_err_t rt_usbd_function_add_interface(ufunction_t func, uintf_t intf);
rt_err_t rt_usbd_interface_add_altsetting(uintf_t intf, ualtsetting_t setting);
rt_err_t rt_usbd_altsetting_add_endpoint(ualtsetting_t setting, uep_t ep);
@ -283,10 +292,12 @@ rt_size_t rt_usbd_ep0_write(udevice_t device, void *buffer, rt_size_t size);
rt_size_t rt_usbd_ep0_read(udevice_t device, void *buffer, rt_size_t size,
rt_err_t (*rx_ind)(udevice_t device, rt_size_t size));
ufunction_t rt_usbd_function_mstorage_create(udevice_t device);
ufunction_t rt_usbd_function_cdc_create(udevice_t device);
ufunction_t rt_usbd_function_rndis_create(udevice_t device);
ufunction_t rt_usbd_function_dap_create(udevice_t device);
int rt_usbd_vcom_class_register(void);
int rt_usbd_ecm_class_register(void);
int rt_usbd_hid_class_register(void);
int rt_usbd_msc_class_register(void);
int rt_usbd_rndis_class_register(void);
int rt_usbd_winusb_class_register(void);
#ifdef RT_USB_DEVICE_COMPOSITE
rt_err_t rt_usbd_function_set_iad(ufunction_t func, uiad_desc_t iad_desc);

View File

@ -934,6 +934,16 @@ static void rt_usb_vcom_init(struct ufunction *func)
result = rt_thread_startup(&vcom_thread);
RT_ASSERT(result == RT_EOK);
}
struct udclass vcom_class =
{
.rt_usbd_function_create = rt_usbd_function_cdc_create
};
int rt_usbd_vcom_class_register(void)
{
rt_usbd_class_register(&vcom_class);
return 0;
}
INIT_PREV_EXPORT(rt_usbd_vcom_class_register);
#endif

View File

@ -604,3 +604,15 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device)
return cdc;
}
struct udclass ecm_class =
{
.rt_usbd_function_create = rt_usbd_function_ecm_create
};
int rt_usbd_ecm_class_register(void)
{
rt_usbd_class_register(&ecm_class);
return 0;
}
INIT_PREV_EXPORT(rt_usbd_ecm_class_register);

View File

@ -674,5 +674,15 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device)
rt_usb_hid_init(func);
return func;
}
struct udclass hid_class =
{
.rt_usbd_function_create = rt_usbd_function_hid_create
};
int rt_usbd_hid_class_register(void)
{
rt_usbd_class_register(&hid_class);
return 0;
}
INIT_PREV_EXPORT(rt_usbd_hid_class_register);
#endif /* RT_USB_DEVICE_HID */

View File

@ -1114,5 +1114,16 @@ ufunction_t rt_usbd_function_mstorage_create(udevice_t device)
return func;
}
struct udclass msc_class =
{
.rt_usbd_function_create = rt_usbd_function_mstorage_create
};
int rt_usbd_msc_class_register(void)
{
rt_usbd_class_register(&msc_class);
return 0;
}
INIT_PREV_EXPORT(rt_usbd_msc_class_register);
#endif

View File

@ -1325,3 +1325,15 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device)
return cdc;
}
struct udclass rndis_class =
{
.rt_usbd_function_create = rt_usbd_function_rndis_create
};
int rt_usbd_rndis_class_register(void)
{
rt_usbd_class_register(&rndis_class);
return 0;
}
INIT_PREV_EXPORT(rt_usbd_rndis_class_register);

View File

@ -320,3 +320,14 @@ ufunction_t rt_usbd_function_winusb_create(udevice_t device)
return func;
}
struct udclass winusb_class =
{
.rt_usbd_function_create = rt_usbd_function_winusb_create
};
int rt_usbd_winusb_class_register(void)
{
rt_usbd_class_register(&winusb_class);
return 0;
}
INIT_PREV_EXPORT(rt_usbd_winusb_class_register);

View File

@ -84,6 +84,19 @@ struct usb_os_comp_id_descriptor usb_comp_id_desc =
USB_DYNAMIC,
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
static rt_list_t class_list;
int rt_usbd_class_list_init(void)
{
rt_list_init(&class_list);
return 0;
}
INIT_BOARD_EXPORT(rt_usbd_class_list_init);
rt_err_t rt_usbd_class_register(udclass_t udclass)
{
rt_list_insert_before(&class_list,&udclass->list);
return RT_EOK;
}
rt_err_t rt_usb_device_init(void)
{
@ -91,6 +104,8 @@ rt_err_t rt_usb_device_init(void)
udevice_t udevice;
uconfig_t cfg;
ufunction_t func;
rt_list_t *i;
udclass_t udclass;
/* create and startup usb device thread */
rt_usbd_core_init();
@ -111,79 +126,25 @@ rt_err_t rt_usb_device_init(void)
/* create a configuration object */
cfg = rt_usbd_config_new();
rt_usbd_device_set_os_comp_id_desc(udevice,&usb_comp_id_desc);
rt_usbd_device_set_os_comp_id_desc(udevice, &usb_comp_id_desc);
#ifdef RT_USB_DEVICE_MSTORAGE
for(i = class_list.next; i!= &class_list; i = i->next)
{
extern ufunction_t rt_usbd_function_mstorage_create(udevice_t device);
/* create a mass storage function object */
func = rt_usbd_function_mstorage_create(udevice);
/* get a class creater */
udclass = rt_list_entry(i, struct udclass, list);
/* create a function object */
func = udclass->rt_usbd_function_create(udevice);
/* add the function to the configuration */
rt_usbd_config_add_function(cfg, func);
}
#endif
#ifdef RT_USB_DEVICE_CDC
{
extern ufunction_t rt_usbd_function_cdc_create(udevice_t device);
/* create a cdc function object */
func = rt_usbd_function_cdc_create(udevice);
/* add the function to the configuration */
rt_usbd_config_add_function(cfg, func);
}
#endif
#ifdef RT_USB_DEVICE_HID
{
extern ufunction_t rt_usbd_function_hid_create(udevice_t device);
/* create a cdc function object */
func = rt_usbd_function_hid_create(udevice);
/* add the function to the configuration */
rt_usbd_config_add_function(cfg, func);
}
#endif
#ifdef RT_USB_DEVICE_RNDIS
{
extern ufunction_t rt_usbd_function_rndis_create(udevice_t device);
/* create a rndis function object */
func = rt_usbd_function_rndis_create(udevice);
/* add the function to the configuration */
rt_usbd_config_add_function(cfg, func);
}
#endif
#ifdef RT_USB_DEVICE_ECM
{
extern ufunction_t rt_usbd_function_ecm_create(udevice_t device);
/* create a rndis function object */
func = rt_usbd_function_ecm_create(udevice);
/* add the function to the configuration */
rt_usbd_config_add_function(cfg, func);
}
#endif
#ifdef RT_USB_DEVICE_WINUSB
{
extern ufunction_t rt_usbd_function_winusb_create(udevice_t device);
/* create a rndis function object */
func = rt_usbd_function_winusb_create(udevice);
/* add the function to the configuration */
rt_usbd_config_add_function(cfg, func);
}
#endif
/* set device descriptor to the device */
#ifdef RT_USB_DEVICE_COMPOSITE
rt_usbd_device_set_descriptor(udevice, &compsit_desc);
rt_usbd_device_set_string(udevice, ustring);
rt_usbd_device_set_qualifier(udevice, &dev_qualifier);
if(udevice->dcd->device_is_hs)
{
rt_usbd_device_set_qualifier(udevice, &dev_qualifier);
}
#else
rt_usbd_device_set_descriptor(udevice, func->dev_desc);
#endif