Merge pull request #90 from heyuanjie87/ForPullRequest
For pull request
This commit is contained in:
commit
e822f87b1a
|
@ -207,6 +207,18 @@ extern "C" {
|
|||
(((rt_uint16_t)(*(((rt_uint8_t *)(x)) + 1))) << 8))
|
||||
|
||||
typedef void (*func_callback)(void *context);
|
||||
typedef enum
|
||||
{
|
||||
USB_STATE_NOTATTACHED = 0,
|
||||
USB_STATE_ATTACHED,
|
||||
USB_STATE_POWERED,
|
||||
USB_STATE_RECONNECTING,
|
||||
USB_STATE_UNAUTHENTICATED,
|
||||
USB_STATE_DEFAULT,
|
||||
USB_STATE_ADDRESS,
|
||||
USB_STATE_CONFIGURED,
|
||||
USB_STATE_SUSPENDED
|
||||
}udevice_state_t;
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
|
@ -310,6 +322,21 @@ struct uhub_descriptor
|
|||
};
|
||||
typedef struct uhub_descriptor* uhub_desc_t;
|
||||
|
||||
struct uhid_descriptor
|
||||
{
|
||||
rt_uint8_t bLength;
|
||||
rt_uint8_t type;
|
||||
rt_uint16_t bcdHID;
|
||||
rt_uint8_t bCountryCode;
|
||||
rt_uint8_t bNumDescriptors;
|
||||
struct hid_descriptor_list
|
||||
{
|
||||
rt_uint8_t type;
|
||||
rt_uint16_t wLength;
|
||||
}Descriptor[1];
|
||||
};
|
||||
typedef struct uhid_descriptor* uhid_desc_t;
|
||||
|
||||
struct ureqest
|
||||
{
|
||||
rt_uint8_t request_type;
|
||||
|
|
|
@ -131,6 +131,7 @@ struct udevice
|
|||
struct udevice_descriptor dev_desc;
|
||||
const char** str;
|
||||
|
||||
udevice_state_t state;
|
||||
rt_list_t cfg_list;
|
||||
uconfig_t curr_cfg;
|
||||
rt_uint8_t nr_intf;
|
||||
|
@ -198,6 +199,7 @@ uep_t rt_usbd_find_endpoint(udevice_t device, uclass_t* pcls, rt_uint8_t ep_addr
|
|||
uclass_t rt_usbd_class_mstorage_create(udevice_t device);
|
||||
uclass_t rt_usbd_class_cdc_create(udevice_t device);
|
||||
uclass_t rt_usbd_class_rndis_create(udevice_t device);
|
||||
uclass_t rt_usbd_class_dap_create(udevice_t device);
|
||||
|
||||
#ifdef RT_USB_DEVICE_COMPOSITE
|
||||
rt_err_t rt_usbd_class_set_iad(uclass_t cls, uiad_desc_t iad_desc);
|
||||
|
|
|
@ -199,6 +199,12 @@ static rt_err_t _get_interface(struct udevice* device, ureq_t setup)
|
|||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("_get_interface\n"));
|
||||
|
||||
if (device->state != USB_STATE_CONFIGURED)
|
||||
{
|
||||
dcd_ep_stall(device->dcd, 0);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* find the specified interface and its alternate setting */
|
||||
intf = rt_usbd_find_interface(device, setup->index & 0xFF, RT_NULL);
|
||||
value = intf->curr_setting->intf_desc->bAlternateSetting;
|
||||
|
@ -230,6 +236,12 @@ static rt_err_t _set_interface(struct udevice* device, ureq_t setup)
|
|||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("_set_interface\n"));
|
||||
|
||||
if (device->state != USB_STATE_CONFIGURED)
|
||||
{
|
||||
dcd_ep_stall(device->dcd, 0);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* find the specified interface */
|
||||
intf = rt_usbd_find_interface(device, setup->index & 0xFF, RT_NULL);
|
||||
|
||||
|
@ -267,9 +279,15 @@ static rt_err_t _get_config(struct udevice* device, ureq_t setup)
|
|||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("_get_config\n"));
|
||||
|
||||
if (device->state == USB_STATE_CONFIGURED)
|
||||
{
|
||||
/* get current configuration */
|
||||
value = device->curr_cfg->cfg_desc.bConfigurationValue;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
/* write the current configuration to endpoint 0 */
|
||||
dcd_ep_write(device->dcd, 0, &value, 1);
|
||||
|
||||
|
@ -298,6 +316,20 @@ static rt_err_t _set_config(struct udevice* device, ureq_t setup)
|
|||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("_set_config\n"));
|
||||
|
||||
if (setup->value > device->dev_desc.bNumConfigurations)
|
||||
{
|
||||
dcd_ep_stall(device->dcd, 0);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
if (setup->value == 0)
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("address state\n"));
|
||||
device->state = USB_STATE_ADDRESS;
|
||||
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
/* set current configuration */
|
||||
rt_usbd_set_config(device, setup->value);
|
||||
cfg = device->curr_cfg;
|
||||
|
@ -324,6 +356,9 @@ static rt_err_t _set_config(struct udevice* device, ureq_t setup)
|
|||
cls->ops->run(device, cls);
|
||||
}
|
||||
|
||||
device->state = USB_STATE_CONFIGURED;
|
||||
|
||||
_exit:
|
||||
/* issue status stage */
|
||||
dcd_send_status(device->dcd);
|
||||
|
||||
|
@ -349,6 +384,8 @@ static rt_err_t _set_address(struct udevice* device, ureq_t setup)
|
|||
/* set address in device control driver */
|
||||
dcd_set_address(device->dcd, setup->value);
|
||||
|
||||
device->state = USB_STATE_ADDRESS;
|
||||
|
||||
/* issue status stage */
|
||||
dcd_send_status(device->dcd);
|
||||
|
||||
|
@ -382,7 +419,9 @@ static rt_err_t _request_interface(struct udevice* device, ureq_t setup)
|
|||
ret = intf->handler(device, cls, setup);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -RT_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue