commit
da1414ff27
|
@ -12,8 +12,8 @@
|
|||
* 2012-10-01 Yi Qiu first version
|
||||
*/
|
||||
|
||||
#ifndef __RT_USB_COMMON_H__
|
||||
#define __RT_USB_COMMON_H__
|
||||
#ifndef __USB_COMMON_H__
|
||||
#define __USB_COMMON_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -320,26 +320,14 @@ struct ureqest
|
|||
};
|
||||
typedef struct ureqest* ureq_t;
|
||||
|
||||
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;
|
||||
#define MIN(a, b) (a < b ? a : b)
|
||||
#define MAX(a, b) (a > b ? a : b)
|
||||
|
||||
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;
|
||||
/*
|
||||
* the define related to mass storage
|
||||
*/
|
||||
#define USBREQ_GET_MAX_LUN 0xfe
|
||||
#define USBREQ_MASS_STORAGE_RESET 0xff
|
||||
|
||||
#define SIZEOF_CSW 0x0d
|
||||
#define SIZEOF_CBW 0x1f
|
||||
|
@ -363,12 +351,6 @@ typedef struct ustorage_csw* ustorage_csw_t;
|
|||
#define CSW_SIGNATURE 0x53425355
|
||||
#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()
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -19,10 +19,19 @@
|
|||
#include <rtthread.h>
|
||||
#include "usb_common.h"
|
||||
|
||||
#define CONTROL_SEND_STATUS 0x00
|
||||
#define CONTROL_RECEIVE_STATUS 0x01
|
||||
/* Vendor ID */
|
||||
#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_VERSION 0x0200 /* USB 2.0 */
|
||||
|
||||
|
@ -42,6 +51,7 @@ struct udcd_ops
|
|||
rt_err_t (*ep_stop)(struct uendpoint* ep);
|
||||
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_err_t (*send_status)(void);
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t dcd_send_status(udcd_t dcd)
|
||||
{
|
||||
RT_ASSERT(dcd != RT_NULL);
|
||||
|
||||
return dcd->ops->send_status();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#ifndef __CDC_H__
|
||||
#define __CDC_H__
|
||||
|
||||
#define USB_CDC_PRODUCT_ID 0x5740 /* Product ID */
|
||||
#define USB_CDC_BUFSIZE 0x40
|
||||
|
||||
#define USB_CDC_CLASS_COMM 0x02
|
||||
|
|
|
@ -39,8 +39,8 @@ static struct udevice_descriptor dev_desc =
|
|||
0x00, //bDeviceSubClass;
|
||||
0x00, //bDeviceProtocol;
|
||||
0x40, //bMaxPacketSize0;
|
||||
USB_VENDOR_ID, //idVendor;
|
||||
USB_CDC_PRODUCT_ID, //idProduct;
|
||||
_VENDOR_ID, //idVendor;
|
||||
_PRODUCT_ID, //idProduct;
|
||||
USB_BCD_DEVICE, //bcdDevice;
|
||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||
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);
|
||||
break;
|
||||
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;
|
||||
case CDC_SEND_BREAK:
|
||||
break;
|
||||
|
@ -588,4 +588,3 @@ void rt_usb_vcom_init(void)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ static struct udevice_descriptor dev_desc =
|
|||
0x00, //bDeviceSubClass;
|
||||
0x00, //bDeviceProtocol;
|
||||
0x40, //bMaxPacketSize0;
|
||||
USB_VENDOR_ID, //idVendor;
|
||||
USB_MASS_STORAGE_PRODUCT_ID,//idProduct;
|
||||
_VENDOR_ID, //idVendor;
|
||||
_PRODUCT_ID, //idProduct;
|
||||
USB_BCD_DEVICE, //bcdDevice;
|
||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||
|
|
|
@ -18,13 +18,29 @@
|
|||
|
||||
#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)
|
||||
|
||||
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 uinterface_descriptor intf_desc;
|
||||
|
|
|
@ -325,7 +325,7 @@ static rt_err_t _set_config(struct udevice* device, ureq_t setup)
|
|||
}
|
||||
|
||||
/* issue status stage */
|
||||
rt_device_control((rt_device_t)device->dcd, CONTROL_SEND_STATUS, RT_NULL);
|
||||
dcd_send_status(device->dcd);
|
||||
|
||||
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);
|
||||
|
||||
/* issue status stage */
|
||||
rt_device_control((rt_device_t)device->dcd, CONTROL_SEND_STATUS, RT_NULL);
|
||||
dcd_send_status(device->dcd);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
@ -1318,4 +1318,3 @@ rt_err_t rt_usbd_core_init(void)
|
|||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <rtdevice.h>
|
||||
#include <rtservice.h>
|
||||
|
||||
#ifdef RT_USING_USB_DEVICE
|
||||
|
||||
const static char* ustring[] =
|
||||
{
|
||||
"Language",
|
||||
|
@ -36,8 +38,8 @@ static struct udevice_descriptor compsit_desc =
|
|||
0x02, //bDeviceSubClass;
|
||||
0x01, //bDeviceProtocol;
|
||||
0x40, //bMaxPacketSize0;
|
||||
USB_VENDOR_ID, //idVendor;
|
||||
0xbacf, //idProduct;
|
||||
_VENDOR_ID, //idVendor;
|
||||
_PRODUCT_ID, //idProduct;
|
||||
USB_BCD_DEVICE, //bcdDevice;
|
||||
USB_STRING_MANU_INDEX, //iManufacturer;
|
||||
USB_STRING_PRODUCT_INDEX, //iProduct;
|
||||
|
@ -115,3 +117,4 @@ rt_err_t rt_usb_device_init(const char* udc_name)
|
|||
return RT_EOK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue