diff options
| author | uestczyh222 <[email protected]> | 2017-12-13 15:58:11 +0800 |
|---|---|---|
| committer | uestczyh222 <[email protected]> | 2017-12-13 15:58:11 +0800 |
| commit | b42fc9640862e668a3ca420c655e42cea54ccefb (patch) | |
| tree | 47ba601c9a7851ea8e02d8486a0e40e033722cc3 /components/drivers/include | |
| parent | dcb0f280b491f5e0ff57373c7ec2936a1fba24e6 (diff) | |
[host first]
Diffstat (limited to 'components/drivers/include')
| -rw-r--r-- | components/drivers/include/drivers/usb_host.h | 105 |
1 files changed, 31 insertions, 74 deletions
diff --git a/components/drivers/include/drivers/usb_host.h b/components/drivers/include/drivers/usb_host.h index 0e6c21432b..a79254c9b7 100644 --- a/components/drivers/include/drivers/usb_host.h +++ b/components/drivers/include/drivers/usb_host.h @@ -37,14 +37,17 @@ extern "C" { #define USB_HUB_PORT_NUM 0x04 #define SIZEOF_USB_REQUEST 0x08 -#define DEV_STATUS_IDLE 0x00 -#define DEV_STATUS_BUSY 0x01 -#define DEV_STATUS_ERROR 0x02 +#define DEV_STATUS_IDLE 0x00 +#define DEV_STATUS_BUSY 0x01 +#define DEV_STATUS_ERROR 0x02 #define UPIPE_STATUS_OK 0x00 #define UPIPE_STATUS_STALL 0x01 #define UPIPE_STATUS_ERROR 0x02 +#define USBH_PID_SETUP 0x00 +#define USBH_PID_DATA 0x01 + struct uhcd; struct uintf; struct uhub; @@ -74,10 +77,15 @@ typedef struct uprotocal* uprotocal_t; struct uinstance { + struct rt_device parent; + struct udevice_descriptor dev_desc; ucfg_desc_t cfg_desc; struct uhcd *hcd; + upipe_t pipe_ep0_out; + upipe_t pipe_ep0_in; + rt_uint8_t status; rt_uint8_t type; rt_uint8_t index; @@ -86,12 +94,12 @@ struct uinstance rt_uint8_t max_packet_size; rt_uint8_t port; - struct uhub* parent; - struct uintf* intf[USB_MAX_INTERFACE]; + struct uhub* parent_hub; + struct uhintf* intf[USB_MAX_INTERFACE]; }; typedef struct uinstance* uinst_t; -struct uintf +struct uhintf { struct uinstance* device; uintf_desc_t intf_desc; @@ -102,9 +110,10 @@ struct uintf struct upipe { + rt_uint8_t pipe_index; rt_uint32_t status; struct uendpoint_descriptor ep; - struct uintf* intf; + struct uhintf* intf; func_callback callback; void* user_data; }; @@ -127,23 +136,16 @@ typedef struct uhub* uhub_t; struct uhcd_ops { - int (*ctl_xfer)(struct uinstance* inst, ureq_t setup, void* buffer, int nbytes, - int timeout); - int (*bulk_xfer)(upipe_t pipe, void* buffer, int nbytes, int timeout); - int (*int_xfer)(upipe_t pipe, void* buffer, int nbytes, int timeout); - int (*iso_xfer)(upipe_t pipe, void* buffer, int nbytes, int timeout); - - rt_err_t (*alloc_pipe)(struct upipe** pipe, struct uintf* intf, uep_desc_t ep, - func_callback callback); - rt_err_t (*free_pipe)(upipe_t pipe); - rt_err_t (*hub_ctrl)(rt_uint16_t port, rt_uint8_t cmd, void *args); + int (*pipe_xfer) (upipe_t pipe, rt_uint8_t token, void* buffer, int nbytes, int timeout); + rt_err_t (*alloc_pipe) (struct upipe* pipe, uep_desc_t ep); + rt_err_t (*free_pipe) (upipe_t pipe); }; - +typedef struct uhcd_ops* uhcd_ops_t; struct uhcd { struct rt_device parent; - struct uhcd_ops* ops; - struct uhub* roothub; + uhcd_ops_t ops; + uhub_t roothub; }; typedef struct uhcd* uhcd_t; @@ -177,16 +179,13 @@ void rt_usbh_hub_init(void); struct uinstance* rt_usbh_alloc_instance(void); rt_err_t rt_usbh_attatch_instance(struct uinstance* device); rt_err_t rt_usbh_detach_instance(struct uinstance* device); -rt_err_t rt_usbh_get_descriptor(struct uinstance* device, rt_uint8_t type, void* buffer, - int nbytes); +rt_err_t rt_usbh_get_descriptor(struct uinstance* device, rt_uint8_t type, void* buffer, int nbytes); rt_err_t rt_usbh_set_configure(struct uinstance* device, int config); rt_err_t rt_usbh_set_address(struct uinstance* device); rt_err_t rt_usbh_set_interface(struct uinstance* device, int intf); rt_err_t rt_usbh_clear_feature(struct uinstance* device, int endpoint, int feature); -rt_err_t rt_usbh_get_interface_descriptor(ucfg_desc_t cfg_desc, int num, - uintf_desc_t* intf_desc); -rt_err_t rt_usbh_get_endpoint_descriptor(uintf_desc_t intf_desc, int num, - uep_desc_t* ep_desc); +rt_err_t rt_usbh_get_interface_descriptor(ucfg_desc_t cfg_desc, int num, uintf_desc_t* intf_desc); +rt_err_t rt_usbh_get_endpoint_descriptor(uintf_desc_t intf_desc, int num, uep_desc_t* ep_desc); /* usb class driver interface */ rt_err_t rt_usbh_class_driver_init(void); @@ -197,19 +196,10 @@ rt_err_t rt_usbh_class_driver_disable(ucd_t drv, void* args); ucd_t rt_usbh_class_driver_find(int class_code, int subclass_code); /* usb class driver implement */ -ucd_t rt_usbh_class_driver_hid(void); ucd_t rt_usbh_class_driver_hub(void); ucd_t rt_usbh_class_driver_storage(void); -ucd_t rt_usbh_class_driver_adk(void); -/* usb hid protocal implement */ -uprotocal_t rt_usbh_hid_protocal_kbd(void); -uprotocal_t rt_usbh_hid_protocal_mouse(void); -/* usb adk class driver interface */ -rt_err_t rt_usbh_adk_set_string(const char* manufacturer, const char* model, - const char* description, const char* version, const char* uri, - const char* serial); /* usb hub interface */ rt_err_t rt_usbh_hub_get_descriptor(struct uinstance* device, rt_uint8_t *buffer, @@ -225,57 +215,24 @@ rt_err_t rt_usbh_hub_reset_port(uhub_t uhub, rt_uint16_t port); rt_err_t rt_usbh_event_signal(struct uhost_msg* msg); /* usb host controller driver interface */ -rt_inline rt_err_t rt_usb_hcd_alloc_pipe(uhcd_t hcd, upipe_t* pipe, - struct uintf* intf, uep_desc_t ep, func_callback callback) +rt_inline rt_err_t rt_usb_hcd_alloc_pipe(uhcd_t hcd, upipe_t pipe, uep_desc_t ep) { - if(intf == RT_NULL) return -RT_EIO; - - return hcd->ops->alloc_pipe(pipe, intf, ep, callback); + return hcd->ops->alloc_pipe(pipe, ep); } rt_inline rt_err_t rt_usb_hcd_free_pipe(uhcd_t hcd, upipe_t pipe) { RT_ASSERT(pipe != RT_NULL); - return hcd->ops->free_pipe(pipe); } -rt_inline int rt_usb_hcd_bulk_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, - int nbytes, int timeout) +rt_inline int rt_usb_hcd_pipe_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, int nbytes, int timeout) { - if(pipe == RT_NULL) return -1; - if(pipe->intf == RT_NULL) return -1; - if(pipe->intf->device == RT_NULL) return -1; - if(pipe->intf->device->status == DEV_STATUS_IDLE) - return -1; - - return hcd->ops->bulk_xfer(pipe, buffer, nbytes, timeout); + return hcd->ops->pipe_xfer(pipe, USBH_PID_DATA, buffer, nbytes, timeout); } - -rt_inline int rt_usb_hcd_control_xfer(uhcd_t hcd, struct uinstance* device, ureq_t setup, - void* buffer, int nbytes, int timeout) +rt_inline int rt_usb_hcd_setup_xfer(uhcd_t hcd, upipe_t pipe, ureq_t setup, int timeout) { - if(device->status == DEV_STATUS_IDLE) return -1; - - return hcd->ops->ctl_xfer(device, setup, buffer, nbytes, timeout); -} - -rt_inline int rt_usb_hcd_int_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, - int nbytes, int timeout) -{ - if(pipe == RT_NULL) return -1; - if(pipe->intf == RT_NULL) return -1; - if(pipe->intf->device == RT_NULL) return -1; - if(pipe->intf->device->status == DEV_STATUS_IDLE) - return -1; - - return hcd->ops->int_xfer(pipe, buffer, nbytes, timeout); -} - -rt_inline rt_err_t rt_usb_hcd_hub_control(uhcd_t hcd, rt_uint16_t port, - rt_uint8_t cmd, void *args) -{ - return hcd->ops->hub_ctrl(port, cmd, args); + return hcd->ops->pipe_xfer(pipe, USBH_PID_SETUP, (void *)setup, 8, timeout); } #ifdef __cplusplus |
