commit
da1414ff27
@ -9,11 +9,11 @@
|
|||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-10-01 Yi Qiu first version
|
* 2012-10-01 Yi Qiu first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __RT_USB_COMMON_H__
|
#ifndef __USB_COMMON_H__
|
||||||
#define __RT_USB_COMMON_H__
|
#define __USB_COMMON_H__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -320,26 +320,14 @@ struct ureqest
|
|||||||
};
|
};
|
||||||
typedef struct ureqest* ureq_t;
|
typedef struct ureqest* ureq_t;
|
||||||
|
|
||||||
struct ustorage_cbw
|
#define MIN(a, b) (a < b ? a : b)
|
||||||
{
|
#define MAX(a, b) (a > b ? a : b)
|
||||||
rt_uint32_t signature;
|
|
||||||
rt_uint32_t tag;
|
|
||||||
rt_uint32_t xfer_len;
|
|
||||||
rt_uint8_t dflags;
|
|
||||||
rt_uint8_t lun;
|
|
||||||
rt_uint8_t cb_len;
|
|
||||||
rt_uint8_t cb[16];
|
|
||||||
};
|
|
||||||
typedef struct ustorage_cbw* ustorage_cbw_t;
|
|
||||||
|
|
||||||
struct ustorage_csw
|
/*
|
||||||
{
|
* the define related to mass storage
|
||||||
rt_uint32_t signature;
|
*/
|
||||||
rt_uint32_t tag;
|
#define USBREQ_GET_MAX_LUN 0xfe
|
||||||
rt_uint32_t data_reside;
|
#define USBREQ_MASS_STORAGE_RESET 0xff
|
||||||
rt_uint8_t status;
|
|
||||||
};
|
|
||||||
typedef struct ustorage_csw* ustorage_csw_t;
|
|
||||||
|
|
||||||
#define SIZEOF_CSW 0x0d
|
#define SIZEOF_CSW 0x0d
|
||||||
#define SIZEOF_CBW 0x1f
|
#define SIZEOF_CBW 0x1f
|
||||||
@ -363,12 +351,6 @@ typedef struct ustorage_csw* ustorage_csw_t;
|
|||||||
#define CSW_SIGNATURE 0x53425355
|
#define CSW_SIGNATURE 0x53425355
|
||||||
#define CBW_TAG_VALUE 0x12345678
|
#define CBW_TAG_VALUE 0x12345678
|
||||||
|
|
||||||
#define USBREQ_GET_MAX_LUN 0xfe
|
|
||||||
#define USBREQ_MASS_STORAGE_RESET 0xff
|
|
||||||
|
|
||||||
#define MIN(a, b) (a < b ? a : b)
|
|
||||||
#define MAX(a, b) (a > b ? a : b)
|
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -19,10 +19,19 @@
|
|||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "usb_common.h"
|
#include "usb_common.h"
|
||||||
|
|
||||||
#define CONTROL_SEND_STATUS 0x00
|
/* Vendor ID */
|
||||||
#define CONTROL_RECEIVE_STATUS 0x01
|
#ifdef USB_VENDOR_ID
|
||||||
|
#define USB_VENDOR_ID _VENDOR_ID
|
||||||
|
#else
|
||||||
|
#define _VENDOR_ID 0x0EFF
|
||||||
|
#endif
|
||||||
|
/* Product ID */
|
||||||
|
#ifdef USB_PRODUCT_ID
|
||||||
|
#define USB_PRODUCT_ID _PRODUCT_ID
|
||||||
|
#else
|
||||||
|
#define _PRODUCT_ID 0x0001
|
||||||
|
#endif
|
||||||
|
|
||||||
#define USB_VENDOR_ID 0x0483 /* Vendor ID */
|
|
||||||
#define USB_BCD_DEVICE 0x0200 /* USB Specification Release Number in Binary-Coded Decimal */
|
#define USB_BCD_DEVICE 0x0200 /* USB Specification Release Number in Binary-Coded Decimal */
|
||||||
#define USB_BCD_VERSION 0x0200 /* USB 2.0 */
|
#define USB_BCD_VERSION 0x0200 /* USB 2.0 */
|
||||||
|
|
||||||
@ -42,6 +51,7 @@ struct udcd_ops
|
|||||||
rt_err_t (*ep_stop)(struct uendpoint* ep);
|
rt_err_t (*ep_stop)(struct uendpoint* ep);
|
||||||
rt_err_t (*ep_read)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
rt_err_t (*ep_read)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
||||||
rt_size_t (*ep_write)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
rt_size_t (*ep_write)(struct uendpoint* ep, void *buffer, rt_size_t size);
|
||||||
|
rt_err_t (*send_status)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct udcd
|
struct udcd
|
||||||
@ -264,4 +274,11 @@ rt_inline rt_size_t dcd_ep_write(udcd_t dcd, uep_t ep, void *buffer,
|
|||||||
return dcd->ops->ep_write(ep, buffer, size);
|
return dcd->ops->ep_write(ep, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rt_inline rt_err_t dcd_send_status(udcd_t dcd)
|
||||||
|
{
|
||||||
|
RT_ASSERT(dcd != RT_NULL);
|
||||||
|
|
||||||
|
return dcd->ops->send_status();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#ifndef __CDC_H__
|
#ifndef __CDC_H__
|
||||||
#define __CDC_H__
|
#define __CDC_H__
|
||||||
|
|
||||||
#define USB_CDC_PRODUCT_ID 0x5740 /* Product ID */
|
|
||||||
#define USB_CDC_BUFSIZE 0x40
|
#define USB_CDC_BUFSIZE 0x40
|
||||||
|
|
||||||
#define USB_CDC_CLASS_COMM 0x02
|
#define USB_CDC_CLASS_COMM 0x02
|
||||||
|
@ -39,8 +39,8 @@ static struct udevice_descriptor dev_desc =
|
|||||||
0x00, //bDeviceSubClass;
|
0x00, //bDeviceSubClass;
|
||||||
0x00, //bDeviceProtocol;
|
0x00, //bDeviceProtocol;
|
||||||
0x40, //bMaxPacketSize0;
|
0x40, //bMaxPacketSize0;
|
||||||
USB_VENDOR_ID, //idVendor;
|
_VENDOR_ID, //idVendor;
|
||||||
USB_CDC_PRODUCT_ID, //idProduct;
|
_PRODUCT_ID, //idProduct;
|
||||||
USB_BCD_DEVICE, //bcdDevice;
|
USB_BCD_DEVICE, //bcdDevice;
|
||||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||||
@ -300,7 +300,7 @@ static rt_err_t _interface_handler(udevice_t device, uclass_t cls, ureq_t setup)
|
|||||||
_cdc_get_line_coding(device, setup);
|
_cdc_get_line_coding(device, setup);
|
||||||
break;
|
break;
|
||||||
case CDC_SET_CONTROL_LINE_STATE:
|
case CDC_SET_CONTROL_LINE_STATE:
|
||||||
rt_device_control((rt_device_t)device->dcd, CONTROL_SEND_STATUS, RT_NULL);
|
dcd_send_status(device->dcd);
|
||||||
break;
|
break;
|
||||||
case CDC_SEND_BREAK:
|
case CDC_SEND_BREAK:
|
||||||
break;
|
break;
|
||||||
@ -588,4 +588,3 @@ void rt_usb_vcom_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ static struct udevice_descriptor dev_desc =
|
|||||||
0x00, //bDeviceSubClass;
|
0x00, //bDeviceSubClass;
|
||||||
0x00, //bDeviceProtocol;
|
0x00, //bDeviceProtocol;
|
||||||
0x40, //bMaxPacketSize0;
|
0x40, //bMaxPacketSize0;
|
||||||
USB_VENDOR_ID, //idVendor;
|
_VENDOR_ID, //idVendor;
|
||||||
USB_MASS_STORAGE_PRODUCT_ID,//idProduct;
|
_PRODUCT_ID, //idProduct;
|
||||||
USB_BCD_DEVICE, //bcdDevice;
|
USB_BCD_DEVICE, //bcdDevice;
|
||||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||||
|
@ -18,13 +18,29 @@
|
|||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#define USBREQ_GET_MAX_LUN 0xfe
|
|
||||||
#define USBREQ_MASS_STORAGE_RESET 0xff
|
|
||||||
|
|
||||||
#define USB_MASS_STORAGE_PRODUCT_ID 0x1000 /* Product ID */
|
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
|
struct ustorage_cbw
|
||||||
|
{
|
||||||
|
rt_uint32_t signature;
|
||||||
|
rt_uint32_t tag;
|
||||||
|
rt_uint32_t xfer_len;
|
||||||
|
rt_uint8_t dflags;
|
||||||
|
rt_uint8_t lun;
|
||||||
|
rt_uint8_t cb_len;
|
||||||
|
rt_uint8_t cb[16];
|
||||||
|
};
|
||||||
|
typedef struct ustorage_cbw* ustorage_cbw_t;
|
||||||
|
|
||||||
|
struct ustorage_csw
|
||||||
|
{
|
||||||
|
rt_uint32_t signature;
|
||||||
|
rt_uint32_t tag;
|
||||||
|
rt_uint32_t data_reside;
|
||||||
|
rt_uint8_t status;
|
||||||
|
};
|
||||||
|
typedef struct ustorage_csw* ustorage_csw_t;
|
||||||
|
|
||||||
struct umass_descriptor
|
struct umass_descriptor
|
||||||
{
|
{
|
||||||
struct uinterface_descriptor intf_desc;
|
struct uinterface_descriptor intf_desc;
|
||||||
|
@ -39,11 +39,11 @@ static rt_err_t _get_device_descriptor(struct udevice* device, ureq_t setup)
|
|||||||
|
|
||||||
/* device descriptor length should less than USB_DESC_LENGTH_DEVICE*/
|
/* device descriptor length should less than USB_DESC_LENGTH_DEVICE*/
|
||||||
size = (setup->length > USB_DESC_LENGTH_DEVICE) ?
|
size = (setup->length > USB_DESC_LENGTH_DEVICE) ?
|
||||||
USB_DESC_LENGTH_DEVICE : setup->length;
|
USB_DESC_LENGTH_DEVICE : setup->length;
|
||||||
|
|
||||||
/* send device descriptor to endpoint 0 */
|
/* send device descriptor to endpoint 0 */
|
||||||
dcd_ep_write(device->dcd, 0, (rt_uint8_t*)&device->dev_desc,
|
dcd_ep_write(device->dcd, 0, (rt_uint8_t*)&device->dev_desc,
|
||||||
size);
|
size);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ static rt_err_t _get_config_descriptor(struct udevice* device, ureq_t setup)
|
|||||||
|
|
||||||
cfg_desc = &device->curr_cfg->cfg_desc;
|
cfg_desc = &device->curr_cfg->cfg_desc;
|
||||||
size = (setup->length > cfg_desc->wTotalLength) ?
|
size = (setup->length > cfg_desc->wTotalLength) ?
|
||||||
cfg_desc->wTotalLength : setup->length;
|
cfg_desc->wTotalLength : setup->length;
|
||||||
|
|
||||||
/* send configuration descriptor to endpoint 0 */
|
/* send configuration descriptor to endpoint 0 */
|
||||||
dcd_ep_write(device->dcd, 0, (rt_uint8_t*)cfg_desc, size);
|
dcd_ep_write(device->dcd, 0, (rt_uint8_t*)cfg_desc, size);
|
||||||
@ -325,7 +325,7 @@ static rt_err_t _set_config(struct udevice* device, ureq_t setup)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* issue status stage */
|
/* issue status stage */
|
||||||
rt_device_control((rt_device_t)device->dcd, CONTROL_SEND_STATUS, RT_NULL);
|
dcd_send_status(device->dcd);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ static rt_err_t _set_address(struct udevice* device, ureq_t setup)
|
|||||||
dcd_set_address(device->dcd, setup->value);
|
dcd_set_address(device->dcd, setup->value);
|
||||||
|
|
||||||
/* issue status stage */
|
/* issue status stage */
|
||||||
rt_device_control((rt_device_t)device->dcd, CONTROL_SEND_STATUS, RT_NULL);
|
dcd_send_status(device->dcd);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ rt_err_t _sof_notify(udevice_t device)
|
|||||||
|
|
||||||
/* to notity every class that sof event comes */
|
/* to notity every class that sof event comes */
|
||||||
for (i=device->curr_cfg->cls_list.next;
|
for (i=device->curr_cfg->cls_list.next;
|
||||||
i!=&device->curr_cfg->cls_list; i=i->next)
|
i!=&device->curr_cfg->cls_list; i=i->next)
|
||||||
{
|
{
|
||||||
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
||||||
if(cls->ops->sof_handler != RT_NULL)
|
if(cls->ops->sof_handler != RT_NULL)
|
||||||
@ -787,7 +787,7 @@ rt_err_t rt_usbd_altsetting_config_descriptor(ualtsetting_t setting, const void*
|
|||||||
* @return an usb class object on success, RT_NULL on fail.
|
* @return an usb class object on success, RT_NULL on fail.
|
||||||
*/
|
*/
|
||||||
uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
|
uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
|
||||||
uclass_ops_t ops)
|
uclass_ops_t ops)
|
||||||
{
|
{
|
||||||
uclass_t cls;
|
uclass_t cls;
|
||||||
|
|
||||||
@ -923,7 +923,7 @@ uintf_t rt_usbd_find_interface(udevice_t device, rt_uint8_t value, uclass_t *pcl
|
|||||||
|
|
||||||
/* search an interface in the current configuration */
|
/* search an interface in the current configuration */
|
||||||
for (i=device->curr_cfg->cls_list.next;
|
for (i=device->curr_cfg->cls_list.next;
|
||||||
i!=&device->curr_cfg->cls_list; i=i->next)
|
i!=&device->curr_cfg->cls_list; i=i->next)
|
||||||
{
|
{
|
||||||
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
||||||
for(j=cls->intf_list.next; j!=&cls->intf_list; j=j->next)
|
for(j=cls->intf_list.next; j!=&cls->intf_list; j=j->next)
|
||||||
@ -999,14 +999,14 @@ uep_t rt_usbd_find_endpoint(udevice_t device, uclass_t* pcls, rt_uint8_t ep_addr
|
|||||||
|
|
||||||
/* search a endpoint in the current configuration */
|
/* search a endpoint in the current configuration */
|
||||||
for (i=device->curr_cfg->cls_list.next;
|
for (i=device->curr_cfg->cls_list.next;
|
||||||
i!=&device->curr_cfg->cls_list; i=i->next)
|
i!=&device->curr_cfg->cls_list; i=i->next)
|
||||||
{
|
{
|
||||||
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
cls = (uclass_t)rt_list_entry(i, struct uclass, list);
|
||||||
for(j=cls->intf_list.next; j!=&cls->intf_list; j=j->next)
|
for(j=cls->intf_list.next; j!=&cls->intf_list; j=j->next)
|
||||||
{
|
{
|
||||||
intf = (uintf_t)rt_list_entry(j, struct uinterface, list);
|
intf = (uintf_t)rt_list_entry(j, struct uinterface, list);
|
||||||
for(k=intf->curr_setting->ep_list.next;
|
for(k=intf->curr_setting->ep_list.next;
|
||||||
k!=&intf->curr_setting->ep_list; k=k->next)
|
k!=&intf->curr_setting->ep_list; k=k->next)
|
||||||
{
|
{
|
||||||
ep = (uep_t)rt_list_entry(k, struct uendpoint, list);
|
ep = (uep_t)rt_list_entry(k, struct uendpoint, list);
|
||||||
if(ep->ep_desc->bEndpointAddress == ep_addr)
|
if(ep->ep_desc->bEndpointAddress == ep_addr)
|
||||||
@ -1059,7 +1059,7 @@ rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg)
|
|||||||
|
|
||||||
/* allocate address for every endpoint in the interface alternate setting */
|
/* allocate address for every endpoint in the interface alternate setting */
|
||||||
for(k=intf->curr_setting->ep_list.next;
|
for(k=intf->curr_setting->ep_list.next;
|
||||||
k!=&intf->curr_setting->ep_list; k=k->next)
|
k!=&intf->curr_setting->ep_list; k=k->next)
|
||||||
{
|
{
|
||||||
ep = (uep_t)rt_list_entry(k, struct uendpoint, list);
|
ep = (uep_t)rt_list_entry(k, struct uendpoint, list);
|
||||||
dcd_ep_alloc(device->dcd, ep);
|
dcd_ep_alloc(device->dcd, ep);
|
||||||
@ -1067,8 +1067,8 @@ rt_err_t rt_usbd_device_add_config(udevice_t device, uconfig_t cfg)
|
|||||||
|
|
||||||
/* construct complete configuration descriptor */
|
/* construct complete configuration descriptor */
|
||||||
rt_memcpy((void*)&cfg->cfg_desc.data[cfg->cfg_desc.wTotalLength -
|
rt_memcpy((void*)&cfg->cfg_desc.data[cfg->cfg_desc.wTotalLength -
|
||||||
USB_DESC_LENGTH_CONFIG], (void*)intf->curr_setting->desc,
|
USB_DESC_LENGTH_CONFIG], (void*)intf->curr_setting->desc,
|
||||||
intf->curr_setting->desc_size);
|
intf->curr_setting->desc_size);
|
||||||
cfg->cfg_desc.wTotalLength += intf->curr_setting->desc_size;
|
cfg->cfg_desc.wTotalLength += intf->curr_setting->desc_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1245,7 +1245,7 @@ static void rt_usbd_thread_entry(void* parameter)
|
|||||||
|
|
||||||
/* receive message */
|
/* receive message */
|
||||||
if(rt_mq_recv(usb_mq, &msg, sizeof(struct udev_msg), RT_WAITING_FOREVER)
|
if(rt_mq_recv(usb_mq, &msg, sizeof(struct udev_msg), RT_WAITING_FOREVER)
|
||||||
!= RT_EOK ) continue;
|
!= RT_EOK ) continue;
|
||||||
|
|
||||||
switch (msg.type)
|
switch (msg.type)
|
||||||
{
|
{
|
||||||
@ -1309,7 +1309,7 @@ rt_err_t rt_usbd_core_init(void)
|
|||||||
|
|
||||||
/* create usb device thread */
|
/* create usb device thread */
|
||||||
thread = rt_thread_create("usbd", rt_usbd_thread_entry, RT_NULL,
|
thread = rt_thread_create("usbd", rt_usbd_thread_entry, RT_NULL,
|
||||||
2048, 8, 20);
|
2048, 8, 20);
|
||||||
if(thread != RT_NULL)
|
if(thread != RT_NULL)
|
||||||
{
|
{
|
||||||
/* startup usb device thread */
|
/* startup usb device thread */
|
||||||
@ -1318,4 +1318,3 @@ rt_err_t rt_usbd_core_init(void)
|
|||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,15 @@
|
|||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-10-02 Yi Qiu first version
|
* 2012-10-02 Yi Qiu first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
#include <rtservice.h>
|
#include <rtservice.h>
|
||||||
|
|
||||||
|
#ifdef RT_USING_USB_DEVICE
|
||||||
|
|
||||||
const static char* ustring[] =
|
const static char* ustring[] =
|
||||||
{
|
{
|
||||||
"Language",
|
"Language",
|
||||||
@ -36,8 +38,8 @@ static struct udevice_descriptor compsit_desc =
|
|||||||
0x02, //bDeviceSubClass;
|
0x02, //bDeviceSubClass;
|
||||||
0x01, //bDeviceProtocol;
|
0x01, //bDeviceProtocol;
|
||||||
0x40, //bMaxPacketSize0;
|
0x40, //bMaxPacketSize0;
|
||||||
USB_VENDOR_ID, //idVendor;
|
_VENDOR_ID, //idVendor;
|
||||||
0xbacf, //idProduct;
|
_PRODUCT_ID, //idProduct;
|
||||||
USB_BCD_DEVICE, //bcdDevice;
|
USB_BCD_DEVICE, //bcdDevice;
|
||||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||||
@ -115,3 +117,4 @@ rt_err_t rt_usb_device_init(const char* udc_name)
|
|||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user