mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-08-20 21:29:42 +08:00
add ADK protocol implement & format code style
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2219 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,10 +17,10 @@ if GetDepend('RT_USB_CLASS_MASS_STORAGE'):
|
||||
src += Glob('class/mass.c')
|
||||
src += Glob('udev/udisk.c')
|
||||
|
||||
if GetDepend('RT_USING_CLASS_HID'):
|
||||
if GetDepend('RT_USB_CLASS_HID'):
|
||||
src += Glob('class/hid.c')
|
||||
|
||||
if GetDepend('RT_USING_HID_MOUSE'):
|
||||
if GetDepend('RT_USB_HID_MOUSE'):
|
||||
src += Glob('udev/umouse.c')
|
||||
|
||||
if GetDepend('RT_USB_HID_KEYBOARD'):
|
||||
|
||||
@@ -20,52 +20,157 @@
|
||||
|
||||
static struct uclass_driver adk_driver;
|
||||
|
||||
rt_err_t rt_usb_adk_read(uifinst_t ifinst, rt_uint8_t *buffer,
|
||||
rt_size_t size)
|
||||
/**
|
||||
* This function will do USB_REQ_GET_PROTOCOL request to set idle period to the usb adk device
|
||||
*
|
||||
* @param ifinst the interface instance.
|
||||
* @duration the idle period of requesting data.
|
||||
* @report_id the report id
|
||||
*
|
||||
* @return the error code, RT_EOK on successfully.
|
||||
*/
|
||||
rt_err_t rt_usb_adk_get_protocol(uifinst_t ifinst, rt_uint16_t *protocol)
|
||||
{
|
||||
uadkinst_t adkinst;
|
||||
rt_size_t length;
|
||||
struct ureqest setup;
|
||||
uinst_t uinst;
|
||||
int timeout = 100;
|
||||
|
||||
/* parameter check */
|
||||
RT_ASSERT(ifinst != RT_NULL);
|
||||
RT_ASSERT(ifinst->uinst != RT_NULL);
|
||||
|
||||
RT_ASSERT(buffer != RT_NULL);
|
||||
uinst = ifinst->uinst;
|
||||
|
||||
if(ifinst == RT_NULL)
|
||||
{
|
||||
rt_kprintf("the interface is not available\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
/* get storage instance from the interface instance */
|
||||
adkinst = (uadkinst_t)ifinst->user_data;
|
||||
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_VENDOR |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_GET_PROTOCOL;
|
||||
setup.index = 0;
|
||||
setup.length = 2;
|
||||
setup.value = 0;
|
||||
|
||||
/* send the cbw */
|
||||
length = rt_usb_hcd_bulk_xfer(ifinst->uinst->hcd, adkinst->pipe_in,
|
||||
buffer, size, 300);
|
||||
|
||||
return length;
|
||||
if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, (void*)protocol, 2,
|
||||
timeout) == 0) return RT_EOK;
|
||||
else return -RT_FALSE;
|
||||
}
|
||||
|
||||
rt_err_t rt_usb_adk_write(uifinst_t ifinst, rt_uint8_t *buffer,
|
||||
rt_size_t size)
|
||||
/**
|
||||
* This function will do USB_REQ_SEND_STRING request to set idle period to the usb adk device
|
||||
*
|
||||
* @param ifinst the interface instance.
|
||||
* @duration the idle period of requesting data.
|
||||
* @report_id the report id
|
||||
*
|
||||
* @return the error code, RT_EOK on successfully.
|
||||
*/
|
||||
rt_err_t rt_usb_adk_send_string(uifinst_t ifinst, rt_uint16_t index,
|
||||
const char* str)
|
||||
{
|
||||
uadkinst_t adkinst;
|
||||
rt_size_t length;
|
||||
struct ureqest setup;
|
||||
uinst_t uinst;
|
||||
int timeout = 100;
|
||||
|
||||
/* parameter check */
|
||||
RT_ASSERT(ifinst != RT_NULL);
|
||||
RT_ASSERT(ifinst->uinst != RT_NULL);
|
||||
|
||||
RT_ASSERT(buffer != RT_NULL);
|
||||
uinst = ifinst->uinst;
|
||||
|
||||
if(ifinst == RT_NULL)
|
||||
{
|
||||
rt_kprintf("the interface is not available\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
/* get storage instance from the interface instance */
|
||||
adkinst = (uadkinst_t)ifinst->user_data;
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_VENDOR |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_SEND_STRING;
|
||||
setup.index = index;
|
||||
setup.length = rt_strlen(str) + 1;
|
||||
setup.value = 0;
|
||||
|
||||
/* send the cbw */
|
||||
length = rt_usb_hcd_bulk_xfer(ifinst->uinst->hcd, adkinst->pipe_out,
|
||||
buffer, size, 300);
|
||||
|
||||
return length;
|
||||
if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, (void*)str,
|
||||
rt_strlen(str) + 1, timeout) == 0) return RT_EOK;
|
||||
else return -RT_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will do USB_REQ_START request to set idle period to the usb adk device
|
||||
*
|
||||
* @param ifinst the interface instance.
|
||||
* @duration the idle period of requesting data.
|
||||
* @report_id the report id
|
||||
*
|
||||
* @return the error code, RT_EOK on successfully.
|
||||
*/
|
||||
rt_err_t rt_usb_adk_start(uifinst_t ifinst)
|
||||
{
|
||||
struct ureqest setup;
|
||||
uinst_t uinst;
|
||||
int timeout = 100;
|
||||
|
||||
/* parameter check */
|
||||
RT_ASSERT(ifinst != RT_NULL);
|
||||
RT_ASSERT(ifinst->uinst != RT_NULL);
|
||||
|
||||
uinst = ifinst->uinst;
|
||||
|
||||
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_VENDOR |
|
||||
USB_REQ_TYPE_DEVICE;
|
||||
setup.request = USB_REQ_START;
|
||||
setup.index = 0;
|
||||
setup.length = 0;
|
||||
setup.value = 0;
|
||||
|
||||
if(rt_usb_hcd_control_xfer(uinst->hcd, uinst, &setup, RT_NULL, 0,
|
||||
timeout) == 0) return RT_EOK;
|
||||
else return -RT_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will read data from usb adk device
|
||||
*
|
||||
* @param ifinst the interface instance.
|
||||
*
|
||||
* @return the error code, RT_EOK on successfully.
|
||||
*/
|
||||
static rt_size_t rt_usb_adk_read(rt_device_t device, rt_off_t pos, void* buffer,
|
||||
rt_size_t size)
|
||||
{
|
||||
uadkinst_t adkinst;
|
||||
rt_size_t length;
|
||||
uifinst_t ifinst;
|
||||
|
||||
/* check parameter */
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
RT_ASSERT(buffer != RT_NULL);
|
||||
|
||||
ifinst = (uifinst_t)device->user_data;
|
||||
adkinst = (uadkinst_t)ifinst->user_data;
|
||||
|
||||
length = rt_usb_hcd_bulk_xfer(ifinst->uinst->hcd, adkinst->pipe_in,
|
||||
buffer, size, 300);
|
||||
|
||||
return length;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will write data to usb adk device
|
||||
*
|
||||
* @param ifinst the interface instance.
|
||||
*
|
||||
* @return the error code, RT_EOK on successfully.
|
||||
*/
|
||||
static rt_size_t rt_usb_adk_write (rt_device_t device, rt_off_t pos, const void* buffer,
|
||||
rt_size_t size)
|
||||
{
|
||||
uadkinst_t adkinst;
|
||||
rt_size_t length;
|
||||
uifinst_t ifinst;
|
||||
|
||||
RT_ASSERT(buffer != RT_NULL);
|
||||
|
||||
ifinst = (uifinst_t)device->user_data;
|
||||
adkinst = (uadkinst_t)ifinst->user_data;
|
||||
|
||||
length = rt_usb_hcd_bulk_xfer(ifinst->uinst->hcd, adkinst->pipe_out,
|
||||
(void*)buffer, size, 300);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,68 +183,127 @@ rt_err_t rt_usb_adk_write(uifinst_t ifinst, rt_uint8_t *buffer,
|
||||
*/
|
||||
static rt_err_t rt_usb_adk_run(void* arg)
|
||||
{
|
||||
int i = 0;
|
||||
uadkinst_t adkinst;
|
||||
uifinst_t ifinst = (uifinst_t)arg;
|
||||
rt_err_t ret;
|
||||
|
||||
/* parameter check */
|
||||
if(ifinst == RT_NULL)
|
||||
{
|
||||
rt_kprintf("the interface is not available\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
int i = 0;
|
||||
uadkinst_t adkinst;
|
||||
uifinst_t ifinst = (uifinst_t)arg;
|
||||
udev_desc_t dev_desc;
|
||||
rt_uint16_t protocol;
|
||||
rt_err_t ret;
|
||||
|
||||
/* parameter check */
|
||||
if(ifinst == RT_NULL)
|
||||
{
|
||||
rt_kprintf("the interface is not available\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB,("rt_usb_adk_run\n"));
|
||||
|
||||
adkinst = rt_malloc(sizeof(struct uadkinst));
|
||||
RT_ASSERT(adkinst != RT_NULL);
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB,("rt_usb_adk_run\n"));
|
||||
|
||||
/* initilize the data structure */
|
||||
rt_memset(adkinst, 0, sizeof(struct uadkinst));
|
||||
ifinst->user_data = (void*)adkinst;
|
||||
if(ifinst->intf_desc->bInterfaceSubClass != 0xFF) return -RT_ERROR;
|
||||
|
||||
dev_desc = &ifinst->uinst->dev_desc;
|
||||
if(dev_desc->idVendor == USB_ACCESSORY_VENDOR_ID &&
|
||||
(dev_desc->idProduct == USB_ACCESSORY_PRODUCT_ID ||
|
||||
dev_desc->idProduct == USB_ACCESSORY_ADB_PRODUCT_ID))
|
||||
{
|
||||
rt_kprintf("found android accessory device\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("switch device\n");
|
||||
|
||||
if((ret = rt_usb_adk_get_protocol(ifinst, &protocol)) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("rt_usb_adk_get_protocol failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
for(i=0; i<ifinst->intf_desc->bNumEndpoints; i++)
|
||||
{
|
||||
uep_desc_t ep_desc;
|
||||
|
||||
/* get endpoint descriptor from interface descriptor */
|
||||
rt_usb_get_endpoint_descriptor(ifinst->intf_desc, i, &ep_desc);
|
||||
if(ep_desc == RT_NULL)
|
||||
{
|
||||
rt_kprintf("rt_usb_get_endpoint_descriptor error\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* the endpoint type of adk class should be BULK */
|
||||
if((ep_desc->bmAttributes & USB_EP_ATTR_TYPE_MASK) != USB_EP_ATTR_BULK)
|
||||
continue;
|
||||
|
||||
/* allocate pipes according to the endpoint type */
|
||||
if(ep_desc->bEndpointAddress & USB_DIR_IN)
|
||||
{
|
||||
/* allocate an in pipe for the adk instance */
|
||||
ret = rt_usb_hcd_alloc_pipe(ifinst->uinst->hcd, &adkinst->pipe_in,
|
||||
ifinst, ep_desc, RT_NULL);
|
||||
if(ret != RT_EOK) return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* allocate an output pipe for the adk instance */
|
||||
ret = rt_usb_hcd_alloc_pipe(ifinst->uinst->hcd, &adkinst->pipe_out,
|
||||
ifinst, ep_desc, RT_NULL);
|
||||
if(ret != RT_EOK) return ret;
|
||||
}
|
||||
}
|
||||
if(protocol != 1)
|
||||
{
|
||||
rt_kprintf("read protocol failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* check pipes infomation */
|
||||
if(adkinst->pipe_in == RT_NULL || adkinst->pipe_out == RT_NULL)
|
||||
{
|
||||
rt_kprintf("pipe error, unsupported device\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
rt_usb_adk_send_string(ifinst, ACCESSORY_STRING_MANUFACTURER, "Real Thread, Inc");
|
||||
rt_usb_adk_send_string(ifinst, ACCESSORY_STRING_MODEL, "ART");
|
||||
rt_usb_adk_send_string(ifinst, ACCESSORY_STRING_DESCRIPTION, "Arduino like board");
|
||||
rt_usb_adk_send_string(ifinst, ACCESSORY_STRING_VERSION, "1.0");
|
||||
rt_usb_adk_send_string(ifinst, ACCESSORY_STRING_VERSION, "www.rt-thread.org");
|
||||
rt_usb_adk_send_string(ifinst, ACCESSORY_STRING_SERIAL, "00000012345678");
|
||||
|
||||
return RT_EOK;
|
||||
if((ret = rt_usb_adk_start(ifinst)) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("rt_usb_adk_start failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
adkinst = rt_malloc(sizeof(struct uadkinst));
|
||||
RT_ASSERT(adkinst != RT_NULL);
|
||||
|
||||
/* initilize the data structure */
|
||||
rt_memset(adkinst, 0, sizeof(struct uadkinst));
|
||||
ifinst->user_data = (void*)adkinst;
|
||||
|
||||
for(i=0; i<ifinst->intf_desc->bNumEndpoints; i++)
|
||||
{
|
||||
uep_desc_t ep_desc;
|
||||
|
||||
/* get endpoint descriptor from interface descriptor */
|
||||
rt_usb_get_endpoint_descriptor(ifinst->intf_desc, i, &ep_desc);
|
||||
if(ep_desc == RT_NULL)
|
||||
{
|
||||
rt_kprintf("rt_usb_get_endpoint_descriptor error\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* the endpoint type of adk class should be BULK */
|
||||
if((ep_desc->bmAttributes & USB_EP_ATTR_TYPE_MASK) != USB_EP_ATTR_BULK)
|
||||
continue;
|
||||
|
||||
/* allocate pipes according to the endpoint type */
|
||||
if(ep_desc->bEndpointAddress & USB_DIR_IN)
|
||||
{
|
||||
/* allocate an in pipe for the adk instance */
|
||||
ret = rt_usb_hcd_alloc_pipe(ifinst->uinst->hcd, &adkinst->pipe_in,
|
||||
ifinst, ep_desc, RT_NULL);
|
||||
if(ret != RT_EOK) return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* allocate an output pipe for the adk instance */
|
||||
ret = rt_usb_hcd_alloc_pipe(ifinst->uinst->hcd, &adkinst->pipe_out,
|
||||
ifinst, ep_desc, RT_NULL);
|
||||
if(ret != RT_EOK) return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* check pipes infomation */
|
||||
if(adkinst->pipe_in == RT_NULL || adkinst->pipe_out == RT_NULL)
|
||||
{
|
||||
rt_kprintf("pipe error, unsupported device\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* set configuration */
|
||||
ret = rt_usb_set_configure(ifinst->uinst, 1);
|
||||
if(ret != RT_EOK) return ret;
|
||||
|
||||
/* register adk device */
|
||||
adkinst->device.type = RT_Device_Class_Char;
|
||||
adkinst->device.init = RT_NULL;
|
||||
adkinst->device.open = RT_NULL;
|
||||
adkinst->device.close = RT_NULL;
|
||||
adkinst->device.read = rt_usb_adk_read;
|
||||
adkinst->device.write = rt_usb_adk_write;
|
||||
adkinst->device.control = RT_NULL;
|
||||
adkinst->device.user_data = (void*)ifinst;
|
||||
|
||||
rt_device_register(&adkinst->device, "adkdev", RT_DEVICE_FLAG_RDWR);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,25 +316,36 @@ static rt_err_t rt_usb_adk_run(void* arg)
|
||||
*/
|
||||
static rt_err_t rt_usb_adk_stop(void* arg)
|
||||
{
|
||||
uadkinst_t adkinst;
|
||||
uifinst_t ifinst = (uifinst_t)arg;
|
||||
uadkinst_t adkinst;
|
||||
uifinst_t ifinst = (uifinst_t)arg;
|
||||
|
||||
RT_ASSERT(ifinst != RT_NULL);
|
||||
RT_ASSERT(ifinst != RT_NULL);
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usb_adk_stop\n"));
|
||||
RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usb_adk_stop\n"));
|
||||
|
||||
adkinst = (uadkinst_t)ifinst->user_data;
|
||||
adkinst = (uadkinst_t)ifinst->user_data;
|
||||
if(adkinst == RT_NULL)
|
||||
{
|
||||
rt_free(ifinst);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
if(adkinst->pipe_in != RT_NULL)
|
||||
rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_in);
|
||||
|
||||
if(adkinst->pipe_in != RT_NULL)
|
||||
rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_in);
|
||||
if(adkinst->pipe_out != RT_NULL)
|
||||
rt_usb_hcd_free_pipe(ifinst->uinst->hcd, adkinst->pipe_out);
|
||||
|
||||
/* free adk instance */
|
||||
if(adkinst != RT_NULL) rt_free(adkinst);
|
||||
|
||||
/* free interface instance */
|
||||
if(ifinst != RT_NULL) rt_free(ifinst);
|
||||
/* unregister adk device */
|
||||
rt_device_unregister(&adkinst->device);
|
||||
|
||||
return RT_EOK;
|
||||
/* free adk instance */
|
||||
if(adkinst != RT_NULL) rt_free(adkinst);
|
||||
|
||||
/* free interface instance */
|
||||
rt_free(ifinst);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,12 +356,12 @@ static rt_err_t rt_usb_adk_stop(void* arg)
|
||||
*/
|
||||
ucd_t rt_usb_class_driver_adk(void)
|
||||
{
|
||||
adk_driver.class_code = USB_CLASS_ADK;
|
||||
|
||||
adk_driver.run = rt_usb_adk_run;
|
||||
adk_driver.stop = rt_usb_adk_stop;
|
||||
adk_driver.class_code = USB_CLASS_ADK;
|
||||
|
||||
adk_driver.run = rt_usb_adk_run;
|
||||
adk_driver.stop = rt_usb_adk_stop;
|
||||
|
||||
return &adk_driver;
|
||||
return &adk_driver;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,12 +19,29 @@
|
||||
|
||||
struct uadkinst
|
||||
{
|
||||
upipe_t pipe_in;
|
||||
upipe_t pipe_out;
|
||||
};
|
||||
upipe_t pipe_in;
|
||||
upipe_t pipe_out;
|
||||
|
||||
struct rt_device device;
|
||||
};
|
||||
typedef struct uadkinst* uadkinst_t;
|
||||
|
||||
#define USB_CLASS_ADK 0xff
|
||||
#define USB_ACCESSORY_VENDOR_ID 0x18D1
|
||||
#define USB_ACCESSORY_PRODUCT_ID 0x2D00
|
||||
#define USB_ACCESSORY_ADB_PRODUCT_ID 0x2D01
|
||||
|
||||
#define ACCESSORY_STRING_MANUFACTURER 0
|
||||
#define ACCESSORY_STRING_MODEL 1
|
||||
#define ACCESSORY_STRING_DESCRIPTION 2
|
||||
#define ACCESSORY_STRING_VERSION 3
|
||||
#define ACCESSORY_STRING_URI 4
|
||||
#define ACCESSORY_STRING_SERIAL 5
|
||||
|
||||
#define USB_REQ_GET_PROTOCOL 51
|
||||
#define USB_REQ_SEND_STRING 52
|
||||
#define USB_REQ_START 53
|
||||
|
||||
#define USB_CLASS_ADK 0xff
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,9 +25,9 @@ static rt_list_t _driver_list;
|
||||
*/
|
||||
rt_err_t rt_usb_class_driver_init(void)
|
||||
{
|
||||
rt_list_init(&_driver_list);
|
||||
rt_list_init(&_driver_list);
|
||||
|
||||
return RT_EOK;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,14 +40,14 @@ rt_err_t rt_usb_class_driver_init(void)
|
||||
|
||||
rt_err_t rt_usb_class_driver_register(ucd_t drv)
|
||||
{
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
|
||||
if (drv == RT_NULL) return -RT_ERROR;
|
||||
if (drv == RT_NULL) return -RT_ERROR;
|
||||
|
||||
/* insert class driver into driver list */
|
||||
rt_list_insert_after(&_driver_list, &(drv->list));
|
||||
|
||||
return RT_EOK;
|
||||
/* insert class driver into driver list */
|
||||
rt_list_insert_after(&_driver_list, &(drv->list));
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,12 +59,12 @@ rt_err_t rt_usb_class_driver_register(ucd_t drv)
|
||||
*/
|
||||
rt_err_t rt_usb_class_driver_unregister(ucd_t drv)
|
||||
{
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
|
||||
/* remove class driver from driver list */
|
||||
rt_list_remove(&(drv->list));
|
||||
/* remove class driver from driver list */
|
||||
rt_list_remove(&(drv->list));
|
||||
|
||||
return RT_EOK;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,12 +77,12 @@ rt_err_t rt_usb_class_driver_unregister(ucd_t drv)
|
||||
*/
|
||||
rt_err_t rt_usb_class_driver_run(ucd_t drv, void* args)
|
||||
{
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
|
||||
if(drv->run != RT_NULL)
|
||||
drv->run(args);
|
||||
if(drv->run != RT_NULL)
|
||||
drv->run(args);
|
||||
|
||||
return RT_EOK;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +95,12 @@ rt_err_t rt_usb_class_driver_run(ucd_t drv, void* args)
|
||||
*/
|
||||
rt_err_t rt_usb_class_driver_stop(ucd_t drv, void* args)
|
||||
{
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
RT_ASSERT(drv != RT_NULL);
|
||||
|
||||
if(drv->stop != RT_NULL)
|
||||
drv->stop(args);
|
||||
if(drv->stop != RT_NULL)
|
||||
drv->stop(args);
|
||||
|
||||
return RT_EOK;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,32 +114,32 @@ rt_err_t rt_usb_class_driver_stop(ucd_t drv, void* args)
|
||||
*/
|
||||
ucd_t rt_usb_class_driver_find(int class_code, int subclass_code)
|
||||
{
|
||||
struct rt_list_node *node;
|
||||
struct rt_list_node *node;
|
||||
|
||||
/* enter critical */
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
rt_enter_critical();
|
||||
/* enter critical */
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
rt_enter_critical();
|
||||
|
||||
/* try to find driver object */
|
||||
for (node = _driver_list.next; node != &_driver_list; node = node->next)
|
||||
{
|
||||
ucd_t drv =
|
||||
(ucd_t)rt_list_entry(node, struct uclass_driver, list);
|
||||
if (drv->class_code == class_code)
|
||||
{
|
||||
/* leave critical */
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
rt_exit_critical();
|
||||
/* try to find driver object */
|
||||
for (node = _driver_list.next; node != &_driver_list; node = node->next)
|
||||
{
|
||||
ucd_t drv =
|
||||
(ucd_t)rt_list_entry(node, struct uclass_driver, list);
|
||||
if (drv->class_code == class_code)
|
||||
{
|
||||
/* leave critical */
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
rt_exit_critical();
|
||||
|
||||
return drv;
|
||||
}
|
||||
}
|
||||
return drv;
|
||||
}
|
||||
}
|
||||
|
||||
/* leave critical */
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
rt_exit_critical();
|
||||
/* leave critical */
|
||||
if (rt_thread_self() != RT_NULL)
|
||||
rt_exit_critical();
|
||||
|
||||
/* not found */
|
||||
return RT_NULL;
|
||||
/* not found */
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user