博文
USB 设备的枚举过程 (2006-05-22 13:34:00)
摘要:USB 设备枚举的数据传输过程
以下是一个程序枚举数据传输的全过程:
(1) 主机检测到有设备插上,总线复位
当设备与主机连接时,主机就会检测到一个连接条件,并且D+的数据线被拉至Vse以上2.5微秒(30个全速数据比特周期),主机就开始进行总线复位。
(2) 主机读取设备描述符
主机使用默认地址(地址0)读取设备描述符,在这里主机使用地址0对设备的设备描述符进行读取。由于PDIUSBD12的端点0的缓冲区只有16个字节,所以单片机就先发送16个字节的设备描述符。当主机接收到这16个字节的字符后,就认为真正有设备连接了,即发送1个0字节的数据包到设备作为状态应答。
(3) 地址分配
在地址分配阶段里,主机分配给设备一个地址。在以后的通信里设备就只对这个地址的信息作出应答。
(4) 主机从新的地址获取设备描述符
分配好了设备地址后,主机就从新的地址获取设备描述符。由于受PDIUSBD12芯片的限制,设备分2次把设备描述符经过端点0发送出去,第一次发送16个字节,第2次发送2个字节。最后主机发送0字节的数据包作为状态应答。
(5) 主机读取配置描述符
主机读取完设备描述符后就读取设备的配置描述符
(6) 读取描述符集合
主机除了读取设备描述符和配置描述符外,还要读取接口描述符和端口描述符。在这里主机使用再次读取配置的方法来读取配置描述符、接口描述符和端点描述符的集合。
(7) 设置配置
主机读取完描述符后,就需要对设备进行配置,使得设备从地址状态进入配置状态。
(8) 读取配置状态
主机设置完配置以后,设备即可使用。主机有时会对设备的配置状态进行读取。
(9) 读取接口状态
在配置完成后,主机会对接口的状态进行读取,这和读取配置一样也是可选的。 ......
USB驱动基础(2006-05-16 15:07:00)
摘要:DriverWorks supports development of drivers that are USB clients, i.e., drivers that need to send requests over a USB to some device.
From the client driver's perspective, any USB device is conceptually comprised of three classes of components:
Logical Device. This is the logical component with which the USB bus driver communicates in order to configure and control the device. It corresponds to the default control pipe or "endpoint 0" as described in the USB specification. All USB devices support a common set of functions accessible via commands to the Logical Device layer of the USB protocol stack. These functions include access to the device descriptor and setting the configuration.
Class KUsbLowerDevice abstracts this functionality. By instancing this class, a device driver creates an interface to the upper edge of the system USB bus driver.
Interfaces. All USB devices have one or more interfaces. An interface is a grouping of the device's endpoints which provides a part......
Pointers, handles, and null(2005-12-14 15:25:00)
摘要:Standard C++ supports pointer types and null pointer constants. C++/CLI adds handle types and null values. 20
To help integrate handles, and to have a universal null, C++/CLI defines the keyword nullptr. This 21
keyword represents a literal having the null type. nullptr is referred to as the null value constant. (No 22
instances of the null type can ever be created, and the only way to obtain a null value constant is via this 23
keyword.) 24
The definition of null pointer constant (which Standard C++ requires to be a compile-time expression that 25
evaluates to zero) has been extended to include nullptr. The null value constant can be implicitly 26
converted to any pointer or handle type, in which case it becomes a null pointer value or null value, 27
respectively. This allows nullptr to be used in relational, equality, conditional, and assignment 28
expressions, among others. 29
Object^ obj1 = nullptr; // handle obj1 has the null value 30
String^ str1 ......
The Common Language Runtime(2005-12-08 11:05:00)
摘要:COM led to a lot of great software and some very useful systems over the years. However, during its lifespan, the problems we just discussed emerged time and again (and we haven’t even mentioned the problems with DCOM). The initial impetus behind COM was the question “How can we compose already-compiled binary software that was developed using different languages and tools?” The answer was “Build reliable, predictable bridges between separate components.” COM concentrated on a well-established boundary—the one between the client and the object. COM makes sure the boundary is well-defined and named so there’s no ambiguity between the client and the object.
It eventually became evident that the boundary between the client and the object didn’t necessarily have to exist at all. What if a runtime environment were available that dissolved the boundary between the client and the object? That’s what the common language runtime is all about—erasing the boundaries between components. The commo......
为应用程序添加闪屏(splash)功能(2005-11-03 10:26:00)
摘要:创建一个启动窗口,用来显示应用程序的相关信息
为了使该启动窗口再最早时刻被显示,启动窗口最好的位置可以放到InitInstance()中。
步骤:
1、创建一个从CWnd派生的启动窗口类,为方便可以用Class wizard
2、为该类添加Create()成员函数,用来显示相关信息。
void CSplashWnd::Create(UINT nID)
{
m_bitmap.LoadBitmapEx(nID,FALSE);
//make the window at center
int x=(::GetSysytemMetrics(SM_CYSCREEN)-mbitmap.m_Width)/2;
int y=(::GetSystemMetrics(SM_CYSCREEN)-m_bitmap.m_Height)/2;
CRect rect(x,y,x+m_bitmap.m_Width,y+m_bitmap.m_Height);
CreateEx(0,AfxRegisterWndClass ,0),"",
......
Handle command line option(2005-11-02 11:01:00)
摘要:An MFC application can use member function ParseParam() of class CCommandLineInfo to handle some standard flags. For add our's flag with other flags support,we should derive our class and overlaid ParseParam().
1、create a new CCommandLineInfo class
(1) in the new class, add new member variables for new flags.
(2) overlaid base class member function ParseParam()
(3) ParseParam() implement
(4) more information about CCommandLineInfo list at the end of this article
2、Add the new command class in application
(1) To find ParseCommandLine() in application, and replace CCommandLineInfo by new class
(2) To make these option aviable in whole application, embed cmdInfo to application and access its member variable.
&nb......
设定程序窗口初始信息(2005-11-02 09:39:00)
摘要:1、在AppWizard中更改Windos Style 来改变窗口初始是否最大化、最小化,以及是否允许更改。
2、更方便的改变可以在PreCreateWindow()中,用代码实现,如
(1)//centern window at a certain percentage of full screen
#define PRCTG 50/100 //define percentage
int xSize =::GetSystemMetrics(SM_CSSCREEN);// more information of the function see MSDN
int ySize=::GetSystemMetrics(SM_CYSCREEN);
cs.cx=xSize*PRCTG;//resize the window
cs.cy=ySize*PRCTG;
&......