Merge pull request #1382 from uestczyh222/master
[Coponents][USB device]add class register interface
This commit is contained in:
commit
2bd7a0e864
|
@ -213,6 +213,13 @@ struct udevice
|
||||||
};
|
};
|
||||||
typedef struct udevice* udevice_t;
|
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
|
enum udev_msg_type
|
||||||
{
|
{
|
||||||
USB_MSG_SETUP_NOTIFY,
|
USB_MSG_SETUP_NOTIFY,
|
||||||
|
@ -248,6 +255,7 @@ struct udev_msg
|
||||||
};
|
};
|
||||||
typedef struct udev_msg* udev_msg_t;
|
typedef struct udev_msg* udev_msg_t;
|
||||||
|
|
||||||
|
int rt_usbd_class_list_init(void);
|
||||||
udevice_t rt_usbd_device_new(void);
|
udevice_t rt_usbd_device_new(void);
|
||||||
uconfig_t rt_usbd_config_new(void);
|
uconfig_t rt_usbd_config_new(void);
|
||||||
ufunction_t rt_usbd_function_new(udevice_t device, udev_desc_t dev_desc,
|
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_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_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_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_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_interface_add_altsetting(uintf_t intf, ualtsetting_t setting);
|
||||||
rt_err_t rt_usbd_altsetting_add_endpoint(ualtsetting_t setting, uep_t ep);
|
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_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));
|
rt_err_t (*rx_ind)(udevice_t device, rt_size_t size));
|
||||||
|
|
||||||
ufunction_t rt_usbd_function_mstorage_create(udevice_t device);
|
int rt_usbd_vcom_class_register(void);
|
||||||
ufunction_t rt_usbd_function_cdc_create(udevice_t device);
|
int rt_usbd_ecm_class_register(void);
|
||||||
ufunction_t rt_usbd_function_rndis_create(udevice_t device);
|
int rt_usbd_hid_class_register(void);
|
||||||
ufunction_t rt_usbd_function_dap_create(udevice_t device);
|
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
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
rt_err_t rt_usbd_function_set_iad(ufunction_t func, uiad_desc_t iad_desc);
|
rt_err_t rt_usbd_function_set_iad(ufunction_t func, uiad_desc_t iad_desc);
|
||||||
|
|
|
@ -934,6 +934,16 @@ static void rt_usb_vcom_init(struct ufunction *func)
|
||||||
result = rt_thread_startup(&vcom_thread);
|
result = rt_thread_startup(&vcom_thread);
|
||||||
RT_ASSERT(result == RT_EOK);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -604,3 +604,15 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device)
|
||||||
|
|
||||||
return cdc;
|
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);
|
||||||
|
|
|
@ -674,5 +674,15 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device)
|
||||||
rt_usb_hid_init(func);
|
rt_usb_hid_init(func);
|
||||||
return 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 */
|
#endif /* RT_USB_DEVICE_HID */
|
||||||
|
|
|
@ -1114,5 +1114,16 @@ ufunction_t rt_usbd_function_mstorage_create(udevice_t device)
|
||||||
|
|
||||||
return func;
|
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
|
#endif
|
||||||
|
|
|
@ -1325,3 +1325,15 @@ ufunction_t rt_usbd_function_rndis_create(udevice_t device)
|
||||||
|
|
||||||
return cdc;
|
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);
|
|
@ -320,3 +320,14 @@ ufunction_t rt_usbd_function_winusb_create(udevice_t device)
|
||||||
return func;
|
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);
|
||||||
|
|
|
@ -84,6 +84,19 @@ struct usb_os_comp_id_descriptor usb_comp_id_desc =
|
||||||
USB_DYNAMIC,
|
USB_DYNAMIC,
|
||||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
{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)
|
rt_err_t rt_usb_device_init(void)
|
||||||
{
|
{
|
||||||
|
@ -91,6 +104,8 @@ rt_err_t rt_usb_device_init(void)
|
||||||
udevice_t udevice;
|
udevice_t udevice;
|
||||||
uconfig_t cfg;
|
uconfig_t cfg;
|
||||||
ufunction_t func;
|
ufunction_t func;
|
||||||
|
rt_list_t *i;
|
||||||
|
udclass_t udclass;
|
||||||
|
|
||||||
/* create and startup usb device thread */
|
/* create and startup usb device thread */
|
||||||
rt_usbd_core_init();
|
rt_usbd_core_init();
|
||||||
|
@ -111,79 +126,25 @@ rt_err_t rt_usb_device_init(void)
|
||||||
/* create a configuration object */
|
/* create a configuration object */
|
||||||
cfg = rt_usbd_config_new();
|
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);
|
/* get a class creater */
|
||||||
/* create a mass storage function object */
|
udclass = rt_list_entry(i, struct udclass, list);
|
||||||
func = rt_usbd_function_mstorage_create(udevice);
|
/* create a function object */
|
||||||
|
func = udclass->rt_usbd_function_create(udevice);
|
||||||
/* add the function to the configuration */
|
/* add the function to the configuration */
|
||||||
rt_usbd_config_add_function(cfg, func);
|
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 */
|
/* set device descriptor to the device */
|
||||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||||
rt_usbd_device_set_descriptor(udevice, &compsit_desc);
|
rt_usbd_device_set_descriptor(udevice, &compsit_desc);
|
||||||
rt_usbd_device_set_string(udevice, ustring);
|
rt_usbd_device_set_string(udevice, ustring);
|
||||||
|
if(udevice->dcd->device_is_hs)
|
||||||
|
{
|
||||||
rt_usbd_device_set_qualifier(udevice, &dev_qualifier);
|
rt_usbd_device_set_qualifier(udevice, &dev_qualifier);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
rt_usbd_device_set_descriptor(udevice, func->dev_desc);
|
rt_usbd_device_set_descriptor(udevice, func->dev_desc);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue