mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-05-28 01:51:00 +08:00
Merge pull request #100 from grissiom/usb-plug
usb: add USB_MSG_PLUG_OUT event
This commit is contained in:
@@ -146,6 +146,11 @@ enum udev_msg_type
|
|||||||
USB_MSG_DATA_NOTIFY,
|
USB_MSG_DATA_NOTIFY,
|
||||||
USB_MSG_SOF,
|
USB_MSG_SOF,
|
||||||
USB_MSG_RESET,
|
USB_MSG_RESET,
|
||||||
|
/* we don't need to add a "PLUG_IN" event because after the cable is
|
||||||
|
* plugged in(before any SETUP) the classed have nothing to do. If the host
|
||||||
|
* is ready, it will send RESET and we will have USB_MSG_RESET. So, a RESET
|
||||||
|
* should reset and run the class while plug_in is not. */
|
||||||
|
USB_MSG_PLUG_OUT,
|
||||||
};
|
};
|
||||||
typedef enum udev_msg_type udev_msg_type;
|
typedef enum udev_msg_type udev_msg_type;
|
||||||
|
|
||||||
|
|||||||
@@ -666,6 +666,60 @@ rt_err_t _sof_notify(udevice_t device)
|
|||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will stop all class.
|
||||||
|
*
|
||||||
|
* @param device the usb device object.
|
||||||
|
*
|
||||||
|
* @return RT_EOK.
|
||||||
|
*/
|
||||||
|
rt_err_t _stop_notify(udevice_t device)
|
||||||
|
{
|
||||||
|
struct rt_list_node *i;
|
||||||
|
uclass_t cls;
|
||||||
|
|
||||||
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
|
/* to notity every class that sof event comes */
|
||||||
|
for (i = device->curr_cfg->cls_list.next;
|
||||||
|
i != &device->curr_cfg->cls_list;
|
||||||
|
i = i->next)
|
||||||
|
{
|
||||||
|
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
||||||
|
if(cls->ops->stop != RT_NULL)
|
||||||
|
cls->ops->stop(device, cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will run all class.
|
||||||
|
*
|
||||||
|
* @param device the usb device object.
|
||||||
|
*
|
||||||
|
* @return RT_EOK.
|
||||||
|
*/
|
||||||
|
rt_err_t _run_notify(udevice_t device)
|
||||||
|
{
|
||||||
|
struct rt_list_node *i;
|
||||||
|
uclass_t cls;
|
||||||
|
|
||||||
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
|
/* to notity every class that sof event comes */
|
||||||
|
for (i = device->curr_cfg->cls_list.next;
|
||||||
|
i != &device->curr_cfg->cls_list;
|
||||||
|
i = i->next)
|
||||||
|
{
|
||||||
|
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
||||||
|
if(cls->ops->run != RT_NULL)
|
||||||
|
cls->ops->run(device, cls);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will reset all class.
|
* This function will reset all class.
|
||||||
*
|
*
|
||||||
@@ -680,17 +734,8 @@ rt_err_t _reset_notify(udevice_t device)
|
|||||||
|
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
/* to notity every class that sof event comes */
|
_stop_notify();
|
||||||
for (i=device->curr_cfg->cls_list.next;
|
_run_notify();
|
||||||
i!=&device->curr_cfg->cls_list; i=i->next)
|
|
||||||
{
|
|
||||||
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
|
||||||
if(cls->ops->stop != RT_NULL)
|
|
||||||
cls->ops->stop(device, cls);
|
|
||||||
|
|
||||||
if(cls->ops->run != RT_NULL)
|
|
||||||
cls->ops->run(device, cls);
|
|
||||||
}
|
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
@@ -1402,6 +1447,10 @@ static void rt_usbd_thread_entry(void* parameter)
|
|||||||
_sof_notify(device);
|
_sof_notify(device);
|
||||||
break;
|
break;
|
||||||
case USB_MSG_DATA_NOTIFY:
|
case USB_MSG_DATA_NOTIFY:
|
||||||
|
/* some buggy drivers will have USB_MSG_DATA_NOTIFY before the core
|
||||||
|
* got configured. */
|
||||||
|
if (device->state != USB_STATE_CONFIGURED)
|
||||||
|
break;
|
||||||
ep = rt_usbd_find_endpoint(device, &cls, msg.content.ep_msg.ep_addr);
|
ep = rt_usbd_find_endpoint(device, &cls, msg.content.ep_msg.ep_addr);
|
||||||
if(ep != RT_NULL)
|
if(ep != RT_NULL)
|
||||||
ep->handler(device, cls, msg.content.ep_msg.size);
|
ep->handler(device, cls, msg.content.ep_msg.size);
|
||||||
@@ -1415,6 +1464,9 @@ static void rt_usbd_thread_entry(void* parameter)
|
|||||||
if (device->state == USB_STATE_ADDRESS)
|
if (device->state == USB_STATE_ADDRESS)
|
||||||
_reset_notify(device);
|
_reset_notify(device);
|
||||||
break;
|
break;
|
||||||
|
case USB_MSG_PLUG_OUT:
|
||||||
|
_stop_notify(device);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
rt_kprintf("unknown msg type\n");
|
rt_kprintf("unknown msg type\n");
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user