Basic knowledge of USB driver development under Windows CE

Source: Internet
Author: User

 

With the popularization of USB devices, the driver development tasks put in front of developers are getting heavier and heavier. Especially for some embedded developers, because the operating systems used by the devices are different, the corresponding hardware interfaces are also different, making it even harder to develop USB drivers. Windows CE is a powerful embedded operating system launched by Microsoft. Many manufacturers have adopted this operating system in China. This article takes Windows CE as an example, this section briefly introduces how to develop USB drivers for Windows CE.

 

First of all to be familiar with some of the basic concepts of USB, of course, it is best to read the USB 1.1 protocol again, (of course, the 2.0 protocol has been available) can be downloaded on the http://www.usb.org, I remember there seems to be a Chinese version, the translation can also, some on the http://www.driverdevolep.com, the specific location is not clear, the Chinese version of the Protocol can be quickly doubled, understand some basic concepts, but it is better to look at the English version to find out some key things.

I will not introduce the basic USB protocol here. I assume that you are familiar with some basic concepts of USB devices and have some knowledge about winows ce development.

 

Windows ce usb system software is divided into two layers: USB client device driver and underlying Windows CE implementation function layer. The USB device driver is mainly responsible for configuring the device and communicating with the device by using the underlying interface provided by the system. The underlying function is composed of two parts: the usbd module and the HCD module. HCd is responsible for the underlying processing, and the usbd module implements higher usbd function interfaces. USB device drivers mainly use usbd interface functions to deal with their peripheral devices.

USB driver mainly deals with usbd, so we must have a detailed understanding of the functions provided by usbd.

The main transmission functions are:

 

 

Abourttransfer issuecontroltransfer

Closetransfer issueinterruptransfer

Getisochresult issueisochtransfer

Gettransferstatus istransfercomplete

Issuebulktransfer issuevendortransfer

The main functions used to enable and disable the communication channel between usbd and USB devices include:

Abortpipetransfers closepipe

Isdefaultpipehalted ispipehalted

Openpipe resetdefaultpipe

Resetpipe

The corresponding packaging function interfaces include:

Getframelength getframenumber releaseframelengthcontrol

Setframelength takeframelengthcontrol

Obtain the device configuration function:

Clearfeature setdescriptor

Getdescriptor setfeature

Getinterface setinterface

Getstatus syncframe

Multi-task functions related to the implementation of interaction with USB:

Findinterface registerclientdeviceid

Getdeviceinfo registerclientsettings

Getusbdversion registernotificationroutine

Loadgenericinterfacedriver translatestringdescr

Openclientregisterkey unregisternotificationroutine

The following describes how to write a USB driver for Windows CE. Net:

● Stream interface functions

This type of driver mainly presents streaming function interfaces, including xxx_init, xxx_deinit, xxx_open, xxx_close, xxx_open, xxx_close, xxx_read, xxx_write, xxx_seek, xxx_iocontrol, xxx_powerup, xxx_powerdown, etc, note that the preceding interfaces must be output, and XXX must contain three characters. Otherwise, an error occurs. However, these drivers are not loaded through the device management interface. Therefore, you must manually call the registerdevice () and deregisterdevice () functions to load and uninstall the drivers. Users can operate such devices as standard files. They can deal with drivers by calling corresponding file operations.

● Use the existing window Ce. NET application interface

This type of device mainly uses Windows CE. net, such as USB mass storage disk, which uses the existing Windows CE. the file system interface that can be installed in. NET is displayed to the available file system. For users, it is transparent and users only feel that they are operating on a folder.

● Create an API specified by the user specified to a specific usbd

This method does not require any restrictions when usbd presents the device. It is mainly used to provide APIs to users, which is generally not common.

Functions that must be output by the USB driver include:

 

● Usbdeviecattach

When a USB device is connected to a computer, the usbd module calls this function. This function is mainly used to initialize a USB device, obtain information about the USB device, configure the USB device, and apply for required resources.

● Usbinstalldriver

It is mainly used to create a driver to load the required registry information, such as read/write timeout and device name.

● Usbuninstalldriver

It is mainly used to release the resources occupied by the driver and delete the Registry created by the usbinstalldriver function.

The above three function interfaces are required by all USB drivers and are indispensable.

In addition, it is important to configure the registry of the driver for the USB device. the General Registry of the driver for the USB device is configured under HKEY_LOCAL_MACHINE/Drivers/USB/loadclients, the sub-keys of each driver are in the group1_id/group2_id/group3_id/drivername format. If the registry information matches the information of the USB device, usbd loads the driver. Otherwise, the sub-keys of the device should be composed of suppliers, devices, and protocols.

 

For example, if you have a PDA device that has a USB interface, its vendor ID is assumed to be 0x0888, and the device ID is 0x0999. No special protocol is used, then, the load registry should be written as follows:

[HKEY_LOCAL_MACHINE/Drivers/USB/loadclients/2184_2457/default/PDA]

"DLL" = "pdausb. dll"

Note that the Registry is identified by a decimal value. Note the decimal and hexadecimal conversion.

For another example, the USB mouse is a standard HID device. Its Protocol is: interfaceclasscode is 3 (hid class) and interfacesubclasscode is 1 (pilot interface class ), interfaceprotocolcode is 2 (mouse Protocol Class), so its registration is as follows:

[HKEY_LOCAL_MACHINE/Drivers/USB/loadclients/default/3_1_2/usbmouse]

"DLL" = "usbmouse. dll"

So far, we can see that driver development is nothing more than two things. One is dealing with hardware, and the other is dealing with the operating system. For example, if we need to develop a USB mouse driver, we need to know how the USB mouse hardware sends data? How can we get mouse control events in the operating system? In fact, the USB mouse is interrupted by pipe, which is used to transmit the data generated by the mouse. In windwos ce, an interface function is called mouse_event (), which is used to generate mouse events, however, it does not care about specific hardware. Even when we call this function in an application, we can simulate the mouse. The corresponding keybd_event () is used to generate Keyboard Events, once you understand this, it is much easier to do. You just need to convert the corresponding data and call mouse_event.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.