From 8aa4eb792457375f156bea1807fd3e495b7df8cc Mon Sep 17 00:00:00 2001 From: heyuanjie87 Date: Thu, 23 May 2013 12:33:22 +0800 Subject: [PATCH] make Host can halt endpoints --- .../drivers/include/drivers/usb_device.h | 12 +++--- components/drivers/usb/usbdevice/core/core.c | 38 +++++++++++++++---- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/components/drivers/include/drivers/usb_device.h b/components/drivers/include/drivers/usb_device.h index 99e89b74c5..95dd962a3a 100644 --- a/components/drivers/include/drivers/usb_device.h +++ b/components/drivers/include/drivers/usb_device.h @@ -42,8 +42,8 @@ struct uendpoint; struct udcd_ops { rt_err_t (*set_address)(rt_uint8_t value); - rt_err_t (*clear_feature)(rt_uint8_t value); - rt_err_t (*set_feature)(rt_uint8_t value); + rt_err_t (*clear_feature)(rt_uint16_t value, rt_uint16_t index); + rt_err_t (*set_feature)(rt_uint16_t value, rt_uint16_t index); rt_err_t (*ep_alloc)(struct uendpoint* ep); rt_err_t (*ep_free)(struct uendpoint* ep); rt_err_t (*ep_stall)(struct uendpoint* ep); @@ -212,18 +212,18 @@ rt_inline rt_err_t dcd_set_address(udcd_t dcd, rt_uint8_t value) return dcd->ops->set_address(value); } -rt_inline rt_err_t dcd_clear_feature(udcd_t dcd, rt_uint8_t value) +rt_inline rt_err_t dcd_clear_feature(udcd_t dcd, rt_uint16_t value, rt_uint16_t index) { RT_ASSERT(dcd != RT_NULL); - return dcd->ops->clear_feature(value); + return dcd->ops->clear_feature(value, index); } -rt_inline rt_err_t dcd_set_feature(udcd_t dcd, rt_uint8_t value) +rt_inline rt_err_t dcd_set_feature(udcd_t dcd, rt_uint8_t value, rt_uint16_t index) { RT_ASSERT(dcd != RT_NULL); - return dcd->ops->set_feature(value); + return dcd->ops->set_feature(value, index); } rt_inline rt_err_t dcd_ep_stall(udcd_t dcd, uep_t ep) diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index 0982f86cc0..f228a1a2bf 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/components/drivers/usb/usbdevice/core/core.c @@ -256,7 +256,8 @@ static rt_err_t _set_interface(struct udevice* device, ureq_t setup) dcd_ep_stop(device->dcd, ep); dcd_ep_run(device->dcd, ep); } - + dcd_send_status(device->dcd); + return RT_EOK; } @@ -454,10 +455,11 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) dcd_ep_write(device->dcd, 0, &value, 2); break; case USB_REQ_CLEAR_FEATURE: - dcd_clear_feature(dcd, setup->value); + dcd_clear_feature(dcd, setup->value, setup->index); + dcd_send_status(dcd); break; case USB_REQ_SET_FEATURE: - dcd_set_feature(dcd, setup->value); + dcd_set_feature(dcd, setup->value, setup->index); break; case USB_REQ_SET_ADDRESS: _set_address(device, setup); @@ -504,15 +506,35 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) switch(setup->request) { case USB_REQ_GET_STATUS: + { /* TODO */ + uep_t ep; + + ep = rt_usbd_find_endpoint(device, RT_NULL, setup->index); + value = ep->is_stall; dcd_ep_write(dcd, 0, &value, 2); - break; + } + break; case USB_REQ_CLEAR_FEATURE: - dcd_clear_feature(dcd, setup->value); - break; + { + uep_t ep; + + ep = rt_usbd_find_endpoint(device, RT_NULL, setup->index); + ep->is_stall = 0; + dcd_clear_feature(dcd, setup->value, setup->index); + dcd_send_status(dcd); + } + break; case USB_REQ_SET_FEATURE: - dcd_set_feature(dcd, setup->value); - break; + { + uep_t ep; + + ep = rt_usbd_find_endpoint(device, RT_NULL, setup->index); + ep->is_stall = 1; + dcd_set_feature(dcd, setup->value, setup->index); + dcd_send_status(dcd); + } + break; case USB_REQ_SYNCH_FRAME: break; default: