不再为你的usb设备编写驱动

【blog.csdn.net/lanmanck】

曾几何时我们找工作还发现有个驱动工程师职位,月薪也不低,没接触过的人代码压根看不懂。

今天可好了,如果不太追求差异化,不用驱动也能让系统与USB设备通信了,Linux就不说了,libusb很好用,现在说下windows的。

Winusb是从XP-SP2起微软提供的一个类似libusb与usb设备通信的中间件,通过它我们就不需要再费奏折的研究和编写USB驱动了。这是几篇资源,先列出来,后面会专门转载一篇详细的blog文,以便有个彻底的认识,不过是E文的,要看仔细点。

资源:

1、libusb介绍:

2、Jan的使用博客:,以及它的详细介绍:

3、微软教你如何安装inf:

4、另一个哥们写的.net-winusb控件和源码:?treeviewPath=[o]+Open-Source\WinUSB+Component

5、微软官方描述:

6、微软教你如何通信:

7、一个哥们做的stm32通信,,要翻墙:

好了,转帖一个winusb的e文介绍,还是老外写的专业点:

Explore USB with WinUSB

This article originally appeared in Nuts & Volts.

If you’re developing a device that needs to talk to a PC, the chances are good that USB will be involved. For each USB device, the PC assigns a software driver. Windows provides drivers for devices that fit into defined USB classes such as human interface, printer, or mass storage. If your device doesn’t fit a defined class, Microsoft’s WinUSB driver is an option.

In this article, I’ll show how to program and access WinUSB devices. The WinUSB driver requires a PC with Windows XP SP2 or later, including Windows Vista and Windows 7.

A Transfer Type for Every Purpose

Every USB data transfer is between a PC or other USB host computer and a device endpoint. A device endpoint is a buffer that stores received data or data to transmit. Every device must support endpoint zero, which is bidirectional. Additional, optional endpoint addresses each have a number (1-15) and a direction (IN or OUT).

Even though endpoints reside on devices, the USB specification defines endpoint direction from the view of the host PC. An IN endpoint sends data to the PC, and an OUT endpoint receives data from the PC. This naming convention can be confusing when writing code for the device side!

One reason why USB is so versatile is its support for four transfer types, each with different strengths. WinUSB supports control, bulk, and interrupt transfers. Control transfers use endpoint zero. The other transfer types can use endpoints one and higher.

Control transfers provide a structured way to send requests and data and receive responses. Control transfers are the only type that can pass information in both directions in a single transfer. After device attachment, in a process called enumeration, the host computer uses control transfers to learn about the device.

WinUSB devices can also use control transfers to send and receive data in vendor-defined requests. For example, you can define a request to set or read a switch, send data to configure device operation, or receive a sensor reading.

A control transfer has two or three stages. To learn about a newly attached device, the host computer uses control transfers to request data structures called descriptors from the device. In the Setup stage, the host sends the request. In the Data stage, the device sends the requested descriptor. In the Status stage, the host acknowledges receiving the descriptor. A host can also use control transfers to send information to a device in the Data stage, with the device acknowledging in the Status stage. Some requests have no Data stage.

A USB host reserves a portion of the bus bandwidth for control transfers: 10% for low- and full-speed endpoints and 20% for high-speed endpoints. If the bus isn’t busy, control transfers can use more than the reserved bandwidth. But all devices must share the bus, so on a busy bus, a control transfer may have to wait.

The other transfer types don’t have multiple stages and can transfer data for any purpose. On an otherwise idle bus, bulk transfers are the fastest. But bulk transfers have no guaranteed bandwidth, so on a busy bus, bulk transfers must wait. Common uses for bulk transfers are printers and scanners, where quick transfers are nice but not essential.

For interrupt transfers, the host guarantees a maximum interval between requests for data from IN endpoints or sending data to OUT endpoints. Common uses for interrupt transfers are mice and keyboards, which need to transfer user input quickly to the host computer.

Isochronous transfers have a guaranteed transfer rate but unlike the other transfer types, isochronous transfers don’t use acknowledgements, and the receiver has no defined way to request re-transmitting corrupted data. Common uses for isochronous transfers are streaming audio and video, where users won’t notice or will tolerate a few corrupted or missing packets. WinUSB doesn’t support isochronous transfers.

Using the USB Framework

My example code is for Microchip Technology’s PIC18F4550 microcontroller and MPLAB C18 compiler. I tested the code on Microchip’s PICDEM FS-USB development board. A complete WinUSB project for the PIC along with companion Visual Basic and Visual C# applications are available from my website.

My PIC code uses Microchip’s free USB Framework, which is a set of source-code modules that handle low-level USB communications. Using the Framework can save much time and trouble.

年轻是我们唯一拥有权利去编织梦想的时光

不再为你的usb设备编写驱动

相关文章:

你感兴趣的文章:

标签云: