Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
8fd0a7f9
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8fd0a7f9
编写于
2月 16, 2014
作者:
qiuyiuestc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update USB Device Stack to support more device controllers;
Pass USB CV test verification; Code cleanup;
上级
db02f562
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
2172 addition
and
1034 deletion
+2172
-1034
components/drivers/include/drivers/usb_common.h
components/drivers/include/drivers/usb_common.h
+48
-15
components/drivers/include/drivers/usb_device.h
components/drivers/include/drivers/usb_device.h
+205
-112
components/drivers/usb/usbdevice/SConscript
components/drivers/usb/usbdevice/SConscript
+0
-3
components/drivers/usb/usbdevice/class/cdc_vcom.c
components/drivers/usb/usbdevice/class/cdc_vcom.c
+301
-256
components/drivers/usb/usbdevice/class/mstorage.c
components/drivers/usb/usbdevice/class/mstorage.c
+755
-300
components/drivers/usb/usbdevice/class/mstorage.h
components/drivers/usb/usbdevice/class/mstorage.h
+0
-7
components/drivers/usb/usbdevice/core/core.c
components/drivers/usb/usbdevice/core/core.c
+831
-311
components/drivers/usb/usbdevice/core/usbdevice.c
components/drivers/usb/usbdevice/core/usbdevice.c
+32
-30
未找到文件。
components/drivers/include/drivers/usb_common.h
浏览文件 @
8fd0a7f9
...
...
@@ -20,6 +20,7 @@
* Change Logs:
* Date Author Notes
* 2012-10-01 Yi Qiu first version
* 2013-04-26 aozima add DEVICEQUALIFIER support.
*/
#ifndef __USB_COMMON_H__
...
...
@@ -148,13 +149,22 @@ extern "C" {
#define USB_EPNO_MASK 0x7f
#define USB_DIR_OUT 0x00
#define USB_DIR_IN 0x80
#define USB_DIR_INOUT 0x40
#define USB_DIR_MASK 0x80
#define ID_UNASSIGNED 0
#define ID_ASSIGNED 1
#define RH_GET_PORT_STATUS 0
#define RH_SET_PORT_STATUS 1
#define RH_CLEAR_PORT_FEATURE 2
#define RH_SET_PORT_FEATURE 3
#define USB_BUS_POWERED 0
#define USB_SELF_POWERED 1
#define USB_REMOTE_WAKEUP 1
#define USB_EP_HALT 0
/*
* Port feature numbers
*/
...
...
@@ -205,6 +215,7 @@ extern "C" {
#define USB_EP_ATTR(attr) (attr & USB_EP_ATTR_TYPE_MASK)
#define USB_EP_DESC_NUM(addr) (addr & USB_EP_DESC_NUM_MASK)
#define USB_EP_DIR(addr) ((addr & USB_DIR_MASK)>>7)
#define uswap_32(x) \
((((x) & 0xff000000) >> 24) | \
...
...
@@ -239,7 +250,7 @@ struct usb_descriptor
};
typedef
struct
usb_descriptor
*
udesc_t
;
struct
udevice_descriptor
struct
udevice_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
type
;
...
...
@@ -258,7 +269,7 @@ struct udevice_descriptor
};
typedef
struct
udevice_descriptor
*
udev_desc_t
;
struct
uconfig_descriptor
struct
uconfig_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
type
;
...
...
@@ -272,7 +283,7 @@ struct uconfig_descriptor
};
typedef
struct
uconfig_descriptor
*
ucfg_desc_t
;
struct
uinterface_descriptor
struct
uinterface_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
type
;
...
...
@@ -287,7 +298,7 @@ struct uinterface_descriptor
typedef
struct
uinterface_descriptor
*
uintf_desc_t
;
/* Interface Association Descriptor (IAD) */
struct
uiad_descriptor
struct
uiad_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
bDescriptorType
;
...
...
@@ -300,7 +311,7 @@ struct uiad_descriptor
};
typedef
struct
uiad_descriptor
*
uiad_desc_t
;
struct
uendpoint_descriptor
struct
uendpoint_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
type
;
...
...
@@ -311,7 +322,7 @@ struct uendpoint_descriptor
};
typedef
struct
uendpoint_descriptor
*
uep_desc_t
;
struct
ustring_descriptor
struct
ustring_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
type
;
...
...
@@ -319,19 +330,34 @@ struct ustring_descriptor
};
typedef
struct
ustring_descriptor
*
ustr_desc_t
;
struct
uhub_descriptor
struct
uhub_descriptor
{
rt_uint8_t
length
;
rt_uint8_t
type
;
rt_uint8_t
num_ports
;
rt_uint16_t
characteristics
;
rt_uint16_t
characteristics
;
rt_uint8_t
pwron_to_good
;
/* power on to power good */
rt_uint8_t
current
;
rt_uint8_t
current
;
rt_uint8_t
removable
[
8
];
rt_uint8_t
pwr_ctl
[
8
];
};
typedef
struct
uhub_descriptor
*
uhub_desc_t
;
/* USB_DESC_TYPE_DEVICEQUALIFIER: Device Qualifier descriptor */
struct
usb_qualifier_descriptor
{
rt_uint8_t
bLength
;
rt_uint8_t
bDescriptorType
;
rt_uint16_t
bcdUSB
;
// TODO: big-endian.
rt_uint8_t
bDeviceClass
;
rt_uint8_t
bDeviceSubClass
;
rt_uint8_t
bDeviceProtocol
;
rt_uint8_t
bMaxPacketSize0
;
rt_uint8_t
bNumConfigurations
;
rt_uint8_t
bRESERVED
;
}
__attribute__
((
packed
));
struct
uhid_descriptor
{
rt_uint8_t
bLength
;
...
...
@@ -352,15 +378,17 @@ struct ureqest
rt_uint8_t
request_type
;
rt_uint8_t
request
;
rt_uint16_t
value
;
rt_uint16_t
index
;
rt_uint16_t
index
;
rt_uint16_t
length
;
};
typedef
struct
ureqest
*
ureq_t
;
#ifndef MIN
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#endif
/*
/*
* the define related to mass storage
*/
#define USBREQ_GET_MAX_LUN 0xfe
...
...
@@ -368,6 +396,11 @@ typedef struct ureqest* ureq_t;
#define SIZEOF_CSW 0x0d
#define SIZEOF_CBW 0x1f
#define SIZEOF_INQUIRY_CMD 0x24
#define SIZEOF_MODE_SENSE_6 0x4
#define SIZEOF_READ_CAPACITIES 0xc
#define SIZEOF_READ_CAPACITY 0x8
#define SIZEOF_REQUEST_SENSE 0x12
#define CBWFLAGS_DIR_M 0x80
#define CBWFLAGS_DIR_IN 0x80
...
...
@@ -376,7 +409,7 @@ typedef struct ureqest* ureq_t;
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_REQUEST_SENSE 0x03
#define SCSI_INQUIRY_CMD 0x12
#define SCSI_ALLOW_
MEDIUM_REMOVAL
0x1e
#define SCSI_ALLOW_
REMOVAL
0x1e
#define SCSI_MODE_SENSE_6 0x1a
#define SCSI_START_STOP 0x1b
#define SCSI_READ_CAPACITIES 0x23
...
...
@@ -389,7 +422,7 @@ typedef struct ureqest* ureq_t;
#define CSW_SIGNATURE 0x53425355
#define CBW_TAG_VALUE 0x12345678
struct
ustorage_cbw
struct
ustorage_cbw
{
rt_uint32_t
signature
;
rt_uint32_t
tag
;
...
...
@@ -401,11 +434,11 @@ struct ustorage_cbw
};
typedef
struct
ustorage_cbw
*
ustorage_cbw_t
;
struct
ustorage_csw
struct
ustorage_csw
{
rt_uint32_t
signature
;
rt_uint32_t
tag
;
rt_
u
int32_t
data_reside
;
rt_int32_t
data_reside
;
rt_uint8_t
status
;
};
typedef
struct
ustorage_csw
*
ustorage_csw_t
;
...
...
components/drivers/include/drivers/usb_device.h
浏览文件 @
8fd0a7f9
...
...
@@ -20,7 +20,8 @@
* Change Logs:
* Date Author Notes
* 2012-10-01 Yi Qiu first version
* 2012-12-12 heyuanjie87 change endpoint and class handler
* 2012-12-12 heyuanjie87 change endpoint and function handler
* 2013-04-26 aozima add DEVICEQUALIFIER support.
*/
#ifndef __USB_DEVICE_H__
...
...
@@ -31,59 +32,115 @@
/* Vendor ID */
#ifdef USB_VENDOR_ID
#define _VENDOR_ID USB_VENDOR_ID
#define _VENDOR_ID
USB_VENDOR_ID
#else
#define _VENDOR_ID 0x0EFF
#define _VENDOR_ID
0x0EFF
#endif
/* Product ID */
#ifdef USB_PRODUCT_ID
#define _PRODUCT_ID USB_PRODUCT_ID
#define _PRODUCT_ID
USB_PRODUCT_ID
#else
#define _PRODUCT_ID 0x0001
#define _PRODUCT_ID
0x0001
#endif
#define USB_BCD_DEVICE 0x0200
/* USB Specification Release Number in Binary-Coded Decimal */
#define USB_BCD_VERSION 0x0200
/* USB 2.0 */
struct
uclass
;
#define USB_BCD_DEVICE 0x0200
/* USB Specification Release Number in Binary-Coded Decimal */
#define USB_BCD_VERSION 0x0200
/* USB 2.0 */
#define EP0_IN_ADDR 0x80
#define EP0_OUT_ADDR 0x00
#define EP_HANDLER(ep, func, size) RT_ASSERT(ep != RT_NULL); ep->handler(func, size)
#define EP_ADDRESS(ep) ep->ep_desc->bEndpointAddress
#define EP_MAXPACKET(ep) ep->ep_desc->wMaxPacketSize
#define FUNC_ENABLE(func) do{ \
if(func->ops->enable != RT_NULL && \
func->enabled == RT_FALSE) \
{ \
if(func->ops->enable(func) == RT_EOK) \
func->enabled = RT_TRUE; \
} \
}while(0)
#define FUNC_DISABLE(func) do{ \
if(func->ops->disable != RT_NULL && \
func->enabled == RT_TRUE) \
{ \
func->enabled = RT_FALSE; \
func->ops->disable(func); \
} \
}while(0)
struct
ufunction
;
struct
udevice
;
struct
uendpoint
;
typedef
enum
{
/* request to read full count */
UIO_REQUEST_READ_FULL
,
/* request to read any count */
UIO_REQUEST_READ_BEST
,
/* request to write full count */
UIO_REQUEST_WRITE
,
}
UIO_REQUEST_TYPE
;
struct
udcd_ops
{
rt_err_t
(
*
set_address
)(
rt_uint8_t
value
);
rt_err_t
(
*
clear_feature
)(
rt_uint16_t
value
,
rt_uint16_t
index
);
rt_err_t
(
*
set_feature
)(
rt_uint16_t
value
,
rt_uint16_t
index
);
rt_err_t
(
*
ep_alloc
)(
struct
uendpoint
*
ep
);
rt_err_t
(
*
ep_free
)(
struct
uendpoint
*
ep
);
rt_err_t
(
*
ep_stall
)(
struct
uendpoint
*
ep
);
rt_err_t
(
*
ep_run
)(
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_size_t
(
*
ep_write
)(
struct
uendpoint
*
ep
,
void
*
buffer
,
rt_size_t
size
);
rt_err_t
(
*
send_status
)(
void
);
rt_err_t
(
*
set_address
)(
rt_uint8_t
address
);
rt_err_t
(
*
set_config
)(
rt_uint8_t
address
);
rt_err_t
(
*
ep_set_stall
)(
rt_uint8_t
address
);
rt_err_t
(
*
ep_clear_stall
)(
rt_uint8_t
address
);
rt_err_t
(
*
ep_enable
)(
struct
uendpoint
*
ep
);
rt_err_t
(
*
ep_disable
)(
struct
uendpoint
*
ep
);
rt_size_t
(
*
ep_read_prepare
)(
rt_uint8_t
address
,
void
*
buffer
,
rt_size_t
size
);
rt_size_t
(
*
ep_read
)(
rt_uint8_t
address
,
void
*
buffer
);
rt_size_t
(
*
ep_write
)(
rt_uint8_t
address
,
void
*
buffer
,
rt_size_t
size
);
rt_err_t
(
*
ep0_send_status
)(
void
);
rt_err_t
(
*
suspend
)(
void
);
rt_err_t
(
*
wakeup
)(
void
);
};
struct
udc
d
struct
ep_i
d
{
struct
rt_device
parent
;
struct
udcd_ops
*
ops
;
struct
rt_completion
completion
;
rt_uint8_t
addr
;
rt_uint8_t
type
;
rt_uint8_t
dir
;
rt_uint8_t
maxpacket
;
rt_uint8_t
status
;
};
typedef
struct
udcd
*
udcd_t
;
typedef
rt_err_t
(
*
udep_handler_t
)(
struct
u
device
*
device
,
struct
uclass
*
cls
,
rt_size_t
size
);
typedef
rt_err_t
(
*
udep_handler_t
)(
struct
u
function
*
func
,
rt_size_t
size
);
struct
u
endpoin
t
struct
u
io_reques
t
{
rt_list_t
list
;
UIO_REQUEST_TYPE
req_type
;
rt_uint8_t
*
buffer
;
rt_size_t
size
;
rt_size_t
remain_size
;
};
typedef
struct
uio_request
*
uio_request_t
;
struct
uendpoint
{
rt_list_t
list
;
uep_desc_t
ep_desc
;
rt_list_t
request_list
;
struct
uio_request
request
;
rt_uint8_t
*
buffer
;
rt_bool_t
stalled
;
struct
ep_id
*
id
;
udep_handler_t
handler
;
rt_
bool_t
is_stall
;
rt_
err_t
(
*
rx_indicate
)(
struct
udevice
*
dev
,
rt_size_t
size
)
;
};
typedef
struct
uendpoint
*
uep_t
;
struct
udcd
{
struct
rt_device
parent
;
const
struct
udcd_ops
*
ops
;
struct
uendpoint
ep0
;
struct
ep_id
*
ep_pool
;
};
typedef
struct
udcd
*
udcd_t
;
struct
ualtsetting
{
rt_list_t
list
;
...
...
@@ -94,7 +151,7 @@ struct ualtsetting
};
typedef
struct
ualtsetting
*
ualtsetting_t
;
typedef
rt_err_t
(
*
uintf_handler_t
)(
struct
u
device
*
device
,
struct
uclass
*
cls
,
ureq_t
setup
);
typedef
rt_err_t
(
*
uintf_handler_t
)(
struct
u
function
*
func
,
ureq_t
setup
);
struct
uinterface
{
...
...
@@ -106,32 +163,32 @@ struct uinterface
};
typedef
struct
uinterface
*
uintf_t
;
struct
u
class
_ops
struct
u
function
_ops
{
rt_err_t
(
*
run
)(
struct
udevice
*
device
,
struct
uclass
*
cls
);
rt_err_t
(
*
stop
)(
struct
udevice
*
device
,
struct
uclass
*
cls
);
rt_err_t
(
*
sof_handler
)(
struct
u
device
*
device
,
struct
uclass
*
cls
);
rt_err_t
(
*
enable
)(
struct
ufunction
*
func
);
rt_err_t
(
*
disable
)(
struct
ufunction
*
func
);
rt_err_t
(
*
sof_handler
)(
struct
u
function
*
func
);
};
typedef
struct
u
class_ops
*
uclass
_ops_t
;
typedef
struct
u
function_ops
*
ufunction
_ops_t
;
struct
u
class
struct
u
function
{
rt_list_t
list
;
uclass_ops_t
ops
;
void
*
eps
;
ufunction_ops_t
ops
;
struct
udevice
*
device
;
udev_desc_t
dev_desc
;
void
*
user_data
;
rt_bool_t
enabled
;
rt_list_t
intf_list
;
};
typedef
struct
u
class
*
uclass
_t
;
typedef
struct
u
function
*
ufunction
_t
;
struct
uconfig
{
rt_list_t
list
;
struct
uconfig_descriptor
cfg_desc
;
rt_list_t
cls
_list
;
rt_list_t
func
_list
;
};
typedef
struct
uconfig
*
uconfig_t
;
...
...
@@ -139,6 +196,8 @@ struct udevice
{
rt_list_t
list
;
struct
udevice_descriptor
dev_desc
;
struct
usb_qualifier_descriptor
*
dev_qualifier
;
const
char
**
str
;
udevice_state_t
state
;
...
...
@@ -154,8 +213,11 @@ enum udev_msg_type
{
USB_MSG_SETUP_NOTIFY
,
USB_MSG_DATA_NOTIFY
,
USB_MSG_EP0_OUT
,
USB_MSG_EP_CLEAR_FEATURE
,
USB_MSG_SOF
,
USB_MSG_RESET
,
USB_MSG_PLUG_IN
,
/* 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
...
...
@@ -164,153 +226,184 @@ enum udev_msg_type
};
typedef
enum
udev_msg_type
udev_msg_type
;
struct
ep_msg
{
rt_size_t
size
;
rt_uint8_t
ep_addr
;
};
struct
udev_msg
{
udev_msg_type
type
;
udcd_t
dcd
;
union
{
struct
{
rt_size_t
size
;
rt_uint8_t
ep_addr
;
}
ep_msg
;
struct
{
rt_uint32_t
*
packet
;
}
setup_msg
;
struct
ep_msg
ep_msg
;
struct
ureqest
setup
;
}
content
;
};
typedef
struct
udev_msg
*
udev_msg_t
;
udevice_t
rt_usbd_device_create
(
void
);
uconfig_t
rt_usbd_config_create
(
void
);
uclass_t
rt_usbd_class_create
(
udevice_t
device
,
udev_desc_t
dev_desc
,
uclass_ops_t
ops
);
uintf_t
rt_usbd_interface_create
(
udevice_t
device
,
uintf_handler_t
handler
);
uep_t
rt_usbd_endpoint_create
(
uep_desc_t
ep_desc
,
udep_handler_t
handler
);
ualtsetting_t
rt_usbd_altsetting_create
(
rt_size_t
desc_size
);
udevice_t
rt_usbd_device_new
(
void
);
uconfig_t
rt_usbd_config_new
(
void
);
ufunction_t
rt_usbd_function_new
(
udevice_t
device
,
udev_desc_t
dev_desc
,
ufunction_ops_t
ops
);
uintf_t
rt_usbd_interface_new
(
udevice_t
device
,
uintf_handler_t
handler
);
uep_t
rt_usbd_endpoint_new
(
uep_desc_t
ep_desc
,
udep_handler_t
handler
);
ualtsetting_t
rt_usbd_altsetting_new
(
rt_size_t
desc_size
);
rt_err_t
rt_usbd_core_init
(
void
);
rt_err_t
rt_usb_device_init
(
const
char
*
udc_name
);
rt_err_t
rt_usbd_post_event
(
struct
udev_msg
*
msg
,
rt_size_t
size
);
rt_err_t
rt_usbd_free_device
(
udevice_t
device
);
rt_err_t
rt_usb_device_init
(
void
);
rt_err_t
rt_usbd_event_signal
(
struct
udev_msg
*
msg
);
rt_err_t
rt_usbd_device_set_controller
(
udevice_t
device
,
udcd_t
dcd
);
rt_err_t
rt_usbd_device_set_descriptor
(
udevice_t
device
,
udev_desc_t
dev_desc
);
rt_err_t
rt_usbd_device_set_string
(
udevice_t
device
,
const
char
**
ustring
);
rt_err_t
rt_usbd_device_set_qualifier
(
udevice_t
device
,
struct
usb_qualifier_descriptor
*
qualifier
);
rt_err_t
rt_usbd_device_add_config
(
udevice_t
device
,
uconfig_t
cfg
);
rt_err_t
rt_usbd_config_add_
class
(
uconfig_t
cfg
,
uclass_t
cls
);
rt_err_t
rt_usbd_
class_add_interface
(
uclass_t
cls
,
uintf_t
intf
);
rt_err_t
rt_usbd_config_add_
function
(
uconfig_t
cfg
,
ufunction_t
func
);
rt_err_t
rt_usbd_
function_add_interface
(
ufunction_t
func
,
uintf_t
intf
);
rt_err_t
rt_usbd_interface_add_altsetting
(
uintf_t
intf
,
ualtsetting_t
setting
);
rt_err_t
rt_usbd_altsetting_add_endpoint
(
ualtsetting_t
setting
,
uep_t
ep
);
rt_err_t
rt_usbd_altsetting_config_descriptor
(
ualtsetting_t
setting
,
const
void
*
desc
,
rt_off_t
intf_pos
);
rt_err_t
rt_usbd_altsetting_config_descriptor
(
ualtsetting_t
setting
,
const
void
*
desc
,
rt_off_t
intf_pos
);
rt_err_t
rt_usbd_set_config
(
udevice_t
device
,
rt_uint8_t
value
);
rt_err_t
rt_usbd_set_altsetting
(
uintf_t
intf
,
rt_uint8_t
value
);
udevice_t
rt_usbd_find_device
(
udcd_t
dcd
);
uconfig_t
rt_usbd_find_config
(
udevice_t
device
,
rt_uint8_t
value
);
uintf_t
rt_usbd_find_interface
(
udevice_t
device
,
rt_uint8_t
value
,
uclass_t
*
pcls
);
uep_t
rt_usbd_find_endpoint
(
udevice_t
device
,
uclass_t
*
pcls
,
rt_uint8_t
ep_addr
);
u
class_t
rt_usbd_class
_mstorage_create
(
udevice_t
device
);
u
class_t
rt_usbd_class
_cdc_create
(
udevice_t
device
);
u
class_t
rt_usbd_class
_rndis_create
(
udevice_t
device
);
u
class_t
rt_usbd_class
_dap_create
(
udevice_t
device
);
uintf_t
rt_usbd_find_interface
(
udevice_t
device
,
rt_uint8_t
value
,
ufunction_t
*
pfunc
);
uep_t
rt_usbd_find_endpoint
(
udevice_t
device
,
ufunction_t
*
pfunc
,
rt_uint8_t
ep_addr
);
rt_size_t
rt_usbd_io_request
(
udevice_t
device
,
uep_t
ep
,
uio_request_t
req
);
rt_size_t
rt_usbd_ep0_write
(
udevice_t
device
,
void
*
buffer
,
rt_size_t
size
);
rt_size_t
rt_usbd_ep0_read
(
udevice_t
device
,
void
*
buffer
,
rt_size_t
size
,
rt_err_t
(
*
rx_ind
)(
udevice_t
device
,
rt_size_t
size
)
);
u
function_t
rt_usbd_function
_mstorage_create
(
udevice_t
device
);
u
function_t
rt_usbd_function
_cdc_create
(
udevice_t
device
);
u
function_t
rt_usbd_function
_rndis_create
(
udevice_t
device
);
u
function_t
rt_usbd_function
_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
);
rt_err_t
rt_usbd_
function_set_iad
(
ufunction_t
func
,
uiad_desc_t
iad_desc
);
#endif
rt_inline
rt_err_t
dcd_set_address
(
udcd_t
dcd
,
rt_uint8_t
value
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
return
dcd
->
ops
->
set_address
(
value
);
}
rt_inline
rt_err_t
dcd_clear_feature
(
udcd_t
dcd
,
rt_uint16_t
value
,
rt_uint16_t
index
)
rt_err_t
rt_usbd_set_feature
(
udevice_t
device
,
rt_uint16_t
value
,
rt_uint16_t
index
);
rt_err_t
rt_usbd_clear_feature
(
udevice_t
device
,
rt_uint16_t
value
,
rt_uint16_t
index
);
rt_err_t
rt_usbd_ep_set_stall
(
udevice_t
device
,
uep_t
ep
);
rt_err_t
rt_usbd_ep_clear_stall
(
udevice_t
device
,
uep_t
ep
);
rt_err_t
rt_usbd_ep0_set_stall
(
udevice_t
device
);
rt_err_t
rt_usbd_ep0_clear_stall
(
udevice_t
device
);
rt_err_t
rt_usbd_ep0_setup_handler
(
udcd_t
dcd
,
struct
ureqest
*
setup
);
rt_err_t
rt_usbd_ep0_in_handler
(
udcd_t
dcd
);
rt_err_t
rt_usbd_ep0_out_handler
(
udcd_t
dcd
,
rt_size_t
size
);
rt_err_t
rt_usbd_ep_in_handler
(
udcd_t
dcd
,
rt_uint8_t
address
);
rt_err_t
rt_usbd_ep_out_handler
(
udcd_t
dcd
,
rt_uint8_t
address
,
rt_size_t
size
);
rt_err_t
rt_usbd_reset_handler
(
udcd_t
dcd
);
rt_err_t
rt_usbd_connect_handler
(
udcd_t
dcd
);
rt_err_t
rt_usbd_disconnect_handler
(
udcd_t
dcd
);
rt_err_t
rt_usbd_sof_handler
(
udcd_t
dcd
);
rt_inline
rt_err_t
dcd_set_address
(
udcd_t
dcd
,
rt_uint8_t
address
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
set_address
!=
RT_NULL
);
return
dcd
->
ops
->
clear_feature
(
value
,
index
);
return
dcd
->
ops
->
set_address
(
address
);
}
rt_inline
rt_err_t
dcd_set_feature
(
udcd_t
dcd
,
rt_uint8_t
value
,
rt_uint16_t
index
)
rt_inline
rt_err_t
dcd_set_config
(
udcd_t
dcd
,
rt_uint8_t
address
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
set_config
!=
RT_NULL
);
return
dcd
->
ops
->
set_
feature
(
value
,
index
);
return
dcd
->
ops
->
set_
config
(
address
);
}
rt_inline
rt_err_t
dcd_ep_
stall
(
udcd_t
dcd
,
uep_t
ep
)
rt_inline
rt_err_t
dcd_ep_
enable
(
udcd_t
dcd
,
uep_t
ep
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
ep_enable
!=
RT_NULL
);
return
dcd
->
ops
->
ep_
stall
(
ep
);
return
dcd
->
ops
->
ep_
enable
(
ep
);
}
rt_inline
rt_
uint8_t
dcd_ep_alloc
(
udcd_t
dcd
,
uep_t
ep
)
rt_inline
rt_
err_t
dcd_ep_disable
(
udcd_t
dcd
,
uep_t
ep
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
ep_disable
!=
RT_NULL
);
return
dcd
->
ops
->
ep_
alloc
(
ep
);
return
dcd
->
ops
->
ep_
disable
(
ep
);
}
rt_inline
rt_err_t
dcd_ep_free
(
udcd_t
dcd
,
uep_t
ep
)
rt_inline
rt_size_t
dcd_ep_read_prepare
(
udcd_t
dcd
,
rt_uint8_t
address
,
void
*
buffer
,
rt_size_t
size
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
return
dcd
->
ops
->
ep_free
(
ep
);
if
(
dcd
->
ops
->
ep_read_prepare
!=
RT_NULL
)
{
return
dcd
->
ops
->
ep_read_prepare
(
address
,
buffer
,
size
);
}
else
{
return
0
;
}
}
rt_inline
rt_
err_t
dcd_ep_run
(
udcd_t
dcd
,
uep_t
ep
)
rt_inline
rt_
size_t
dcd_ep_read
(
udcd_t
dcd
,
rt_uint8_t
address
,
void
*
buffer
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
return
dcd
->
ops
->
ep_run
(
ep
);
if
(
dcd
->
ops
->
ep_read
!=
RT_NULL
)
{
return
dcd
->
ops
->
ep_read
(
address
,
buffer
);
}
else
{
return
0
;
}
}
rt_inline
rt_err_t
dcd_ep_stop
(
udcd_t
dcd
,
uep_t
ep
)
rt_inline
rt_size_t
dcd_ep_write
(
udcd_t
dcd
,
rt_uint8_t
address
,
void
*
buffer
,
rt_size_t
size
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
ep_write
!=
RT_NULL
);
return
dcd
->
ops
->
ep_
stop
(
ep
);
return
dcd
->
ops
->
ep_
write
(
address
,
buffer
,
size
);
}
rt_inline
rt_err_t
dcd_ep_read
(
udcd_t
dcd
,
uep_t
ep
,
void
*
buffer
,
rt_size_t
size
)
rt_inline
rt_err_t
dcd_ep0_send_status
(
udcd_t
dcd
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
ep0_send_status
!=
RT_NULL
);
return
dcd
->
ops
->
ep
_read
(
ep
,
buffer
,
size
);
return
dcd
->
ops
->
ep
0_send_status
(
);
}
rt_inline
rt_size_t
dcd_ep_write
(
udcd_t
dcd
,
uep_t
ep
,
void
*
buffer
,
rt_size_t
size
)
{
rt_inline
rt_err_t
dcd_ep_set_stall
(
udcd_t
dcd
,
rt_uint8_t
address
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
ep_set_stall
!=
RT_NULL
);
return
dcd
->
ops
->
ep_
write
(
ep
,
buffer
,
size
);
return
dcd
->
ops
->
ep_
set_stall
(
address
);
}
rt_inline
rt_err_t
dcd_
send_status
(
udcd_t
dcd
)
rt_inline
rt_err_t
dcd_
ep_clear_stall
(
udcd_t
dcd
,
rt_uint8_t
address
)
{
RT_ASSERT
(
dcd
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
!=
RT_NULL
);
RT_ASSERT
(
dcd
->
ops
->
ep_clear_stall
!=
RT_NULL
);
return
dcd
->
ops
->
send_status
(
);
return
dcd
->
ops
->
ep_clear_stall
(
address
);
}
#endif
components/drivers/usb/usbdevice/SConscript
浏览文件 @
8fd0a7f9
...
...
@@ -13,9 +13,6 @@ if GetDepend('RT_USB_DEVICE_CDC'):
if
GetDepend
(
'RT_USB_DEVICE_MSTORAGE'
):
src
+=
Glob
(
'class/mstorage.c'
)
if
GetDepend
(
'RT_USB_DEVICE_RNDIS'
):
src
+=
Glob
(
'class/rndis.c'
)
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'DeviceDrivers'
,
src
,
depend
=
[
'RT_USING_USB_DEVICE'
],
CPPPATH
=
CPPPATH
)
...
...
components/drivers/usb/usbdevice/class/cdc_vcom.c
浏览文件 @
8fd0a7f9
此差异已折叠。
点击以展开。
components/drivers/usb/usbdevice/class/mstorage.c
浏览文件 @
8fd0a7f9
此差异已折叠。
点击以展开。
components/drivers/usb/usbdevice/class/mstorage.h
浏览文件 @
8fd0a7f9
...
...
@@ -59,13 +59,6 @@ struct request_sense_data
rt_uint8_t
Reserved4
[
4
];
}
request_sense_data_t
;
struct
mass_eps
{
uep_t
ep_in
;
uep_t
ep_out
;
};
typedef
struct
mass_eps
*
mass_eps_t
;
#pragma pack()
#endif
components/drivers/usb/usbdevice/core/core.c
浏览文件 @
8fd0a7f9
此差异已折叠。
点击以展开。
components/drivers/usb/usbdevice/core/usbdevice.c
浏览文件 @
8fd0a7f9
...
...
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*
* Change Logs:
* Date Author Notes
* 2012-10-02 Yi Qiu first version
...
...
@@ -28,13 +28,15 @@
#ifdef RT_USING_USB_DEVICE
#define USB_DEVICE_CONTROLLER_NAME "usbd"
#ifdef RT_USB_DEVICE_COMPOSITE
const
static
char
*
ustring
[]
=
{
"Language"
,
"RT-Thread Team."
,
"RTT Composite Device"
,
"
1.1.0
"
,
"
320219198301
"
,
"Configuration"
,
"Interface"
,
};
...
...
@@ -60,54 +62,54 @@ static struct udevice_descriptor compsit_desc =
};
#endif
rt_err_t
rt_usb_device_init
(
const
char
*
udc_name
)
rt_err_t
rt_usb_device_init
(
void
)
{
rt_device_t
udc
;
udevice_t
udevice
;
uconfig_t
cfg
;
uclass_t
cls
;
ufunction_t
func
;
/* create and startup usb device thread */
rt_usbd_core_init
();
RT_ASSERT
(
udc_name
!=
RT_NULL
);
/* create a device object */
udevice
=
rt_usbd_device_new
();
udc
=
rt_device_find
(
udc_name
);
udc
=
rt_device_find
(
USB_DEVICE_CONTROLLER_NAME
);
if
(
udc
==
RT_NULL
)
{
rt_kprintf
(
"can't find usb device controller %s
\n
"
,
udc_name
);
rt_kprintf
(
"can't find usb device controller %s
\n
"
,
USB_DEVICE_CONTROLLER_NAME
);
return
-
RT_ERROR
;
}
/* create and startup usb device thread */
rt_usbd_core_init
();
/* create a device object */
udevice
=
rt_usbd_device_create
();
/* set usb controller driver to the device */
rt_usbd_device_set_controller
(
udevice
,
(
udcd_t
)
udc
);
/* create a configuration object */
cfg
=
rt_usbd_config_
create
();
cfg
=
rt_usbd_config_
new
();
#ifdef RT_USB_DEVICE_MSTORAGE
/* create a mass storage
class
object */
cls
=
rt_usbd_class
_mstorage_create
(
udevice
);
/* create a mass storage
function
object */
func
=
rt_usbd_function
_mstorage_create
(
udevice
);
/* add the
class
to the configuration */
rt_usbd_config_add_
class
(
cfg
,
cls
);
/* add the
function
to the configuration */
rt_usbd_config_add_
function
(
cfg
,
func
);
#endif
#ifdef RT_USB_DEVICE_CDC
/* create a cdc
class
object */
cls
=
rt_usbd_class
_cdc_create
(
udevice
);
/* create a cdc
function
object */
func
=
rt_usbd_function
_cdc_create
(
udevice
);
/* add the
class
to the configuration */
rt_usbd_config_add_
class
(
cfg
,
cls
);
/* add the
function
to the configuration */
rt_usbd_config_add_
function
(
cfg
,
func
);
#endif
#ifdef RT_USB_DEVICE_RNDIS
/* create a rndis
class
object */
cls
=
rt_usbd_class
_rndis_create
(
udevice
);
/* create a rndis
function
object */
func
=
rt_usbd_function
_rndis_create
(
udevice
);
/* add the
class
to the configuration */
rt_usbd_config_add_
class
(
cfg
,
cls
);
/* add the
function
to the configuration */
rt_usbd_config_add_
function
(
cfg
,
func
);
#endif
/* set device descriptor to the device */
...
...
@@ -115,18 +117,18 @@ rt_err_t rt_usb_device_init(const char* udc_name)
rt_usbd_device_set_descriptor
(
udevice
,
&
compsit_desc
);
rt_usbd_device_set_string
(
udevice
,
ustring
);
#else
rt_usbd_device_set_descriptor
(
udevice
,
cls
->
dev_desc
);
rt_usbd_device_set_descriptor
(
udevice
,
func
->
dev_desc
);
#endif
/* add the configuration to the device */
rt_usbd_device_add_config
(
udevice
,
cfg
);
/* set default configuration to 1 */
rt_usbd_set_config
(
udevice
,
1
);
/* initialize usb device controller */
rt_device_init
(
udc
);
/* set default configuration to 1 */
rt_usbd_set_config
(
udevice
,
1
);
return
RT_EOK
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录