USB Complete
В этой книге вы найдете все, что нужно чтобы сделать драйвер USB, USB устройство, WDM driver и как устанавливать
USB драйвер, HUB device, HID driver и другие драйвера. This book is for you if you want to know how to design a USB peripheral, or if you want to know
how to communicate with USB peripherals from the applications you write. These are some of questions the book answers:
• What is USB and how do peripherals use it to communicate with PCs? There's a lot to the USB interface. Learning about it can be daunting at first. This book's focus is on the
practical knowledge you'll need to complete your project.
• How do I choose a USB controller chip for my peripheral design? Every USB peripheral must contain an intelligent controller. There are dozens of controller chips designed for
use in USB peripherals. In this book, I compare popular chip families and offer tips on how to decide, based on both your projects needs and your own background and preferences.
• How do applications communicate with USB peripherals? To communicate with a USB peripheral, a PC needs two things: a device driver that knows how to communicate with the
PC's USB drivers and an application that knows how to talk to the device driver. Some peripherals can use drivers that are built into Windows. Others may require a custom driver.
This book will show you when you can use Windows' built-in drivers and how to communicate with devices from Visual Basic and Visual C++ applications. You'll also find out what's
involved in writing a device driver and what tools can help to speed up the process...
Detect Devices
On power-up, the hubs make the host aware of all attached USB devices. In a process called enumeration, the host assigns an address and requests additional information from each device.
After power-up, whenever a device is removed or attached, the host learns of the event and enumerates any newly attached device and removes any detached device from the devices available to applications...
Exchange Data with the Host
All of the above tasks support the main job of the device's USB port, which is to exchange data with the host. After the device is configured,
it must respond to requests to send and receive data...
...a full-speed transfer can move up to 1023 bytes in each 1-millisecond frame. A high-speed transfer can move up to 3072 bytes in each 125-microsecond microframe. Isochronous transfers have no error correcting, however...
Elements in the USB's Link
A USB peripheral needs all of the following:
• A controller chip with a USB interface;
Tools for Developing
To develop a USB peripheral, you need the following tools:
Return to Top
Steps in Developing a Project
For a project of any size, you'll want to create the project a piece at a time, in modules, and get each piece working before moving on to the next.
In writing the firmware, you can begin by writing just enough code to enable Windows to detect and enumerate the device. When that's working, you can move on to exchanging small
blocks of data with applications. From there you can add specific code for your application. The steps in project development include ...
Inside USB Transfers
To design and program a USB device, you need to know a certain amount about the inner workings of the interface.
This is true even though the hardware and system software handle many of the details automatically.
This and the next three chapters are a tutorial on how USB transfers data. This chapter has essentials that apply to all transfers.
The following chapters cover the four transfer types supported by USB, the enumeration process, and the standard requests used in control transfers.
You don't need to know every bit of this information to get a project up and running, but I've found that understanding something about how the transfers work helps in deciding
which transfer types to use, in writing the firmware for the controller chip, and in tracking down the inevitable bugs that show up when you try out your circuits and code.
The USB interface is complicated, and much of what you need to know is interwoven with everything else. This makes it hard to know where to start. In general, I begin with the big
picture and work down to the details. Unavoidably, some of the things I refer to aren't explained in detail until...
Enumeration Steps
During the enumeration process, a device moves through four of the six device states defined by the specification: Powered, Default, Address, and...
Descriptor Types and Contents
Descriptors are data structures, or formatted blocks of information, that enable the host to learn about a device.
Each descriptor contains information about either the device as a whole or an element in the device.
All USB peripherals must respond to requests for the standard USB descriptors. This means that the peripheral must do two things: store the information in the descriptors,
and respond to requests for the descriptors in the expected format.
Return to Top
Chip Choices
When it's time to select a USB controller for a project, the good news is that there are plenty of chips to choose from.
The downside is that there are so many that deciding which chip to use in a project can be overwhelming at first.
As with any project involving embedded controllers, the decision depends on what functions the chip has to perform, cost, availability, and ease of development.
Ease of development depends on the availability and quality of development tools, device-driver software for the host, and sample code, plus your experience with the device's
architecture and instruction set or language compiler.
This chapter is a guide to selecting a USB controller. It includes a tutorial about what you need to consider and descriptions of a sampling of chips with a range of abilities.
The chips covered include inexpensive ones with simple architectures and basic USB support as well as more full-featured, high-end chips.
Programming in C++
How the Host Communicates
A USB peripheral is of no use if its host PC doesn't know how to communicate with it. Under Windows, any communication with a USB peripheral must pass through a device
driver that knows how to communicate both with the system's USB drivers and with the applications that access the device.
This chapter explains how Windows applications communicate with USB devices and explores the options for device drivers.
Insulating Applications from the Details
A device driver insulates applications from having to know details about the physical connections, signals, and protocols required to
communicate with a device. Applications are the programs that users run, including everything from popular word processors and databases to special-purpose applications that
support custom hardware.
Applications written in Visual Basic, C/C++, and Delphi can call API functions...
Return to Top
The Win32 Driver Model
USB device drivers for Windows must conform to the Win32 Driver Model defined by Microsoft for use under
Windows 98 and later, including Windows 2000 and Me. These drivers are known as WDM drivers and ...
Writing a Custom Driver
If you don't have experience writing device drivers, creating a WDM driver is not a trivial task. It requires an investment in tools,
expertise in C programming, and a fair amount of knowledge about how Windows communicates with hardware and applications. On the positive side, writing a USB driver is
easier than writing a driver for a device that connects to the ISA bus. Plus, a variety of products can help to simplify and speed up the process.
Creating INF Files
If you need to create an INF file for a device, Microsoft provides several tools to help in creating the file and ensuring that it has
all of the required sections in the correct format. This section describes the tools and also gives some tips that can come in handy when you're experimenting with INFs.
Human Interface Devices: Firmware Basics
The human interface device (HID) class was one of the first USB classes to be supported under Windows. On PCs running
Windows 98 or later, applications can communicate with HIDs using the drivers built into the operating system. For this reason, USB devices that fit into the HID class are
some of the easiest to get up and running. This chapter shows how to determine whether a peripheral will fit into the human-interface class, explains the firmware requirements
that define a device as a HID and enable it to exchange data with its host, and introduces the six HID-specific control requests. The next three chapters describe the reports that
HIDs use to exchange information and how to access HIDs from applications.
Human Interface Devices: Host Application Primer
Chapter 13 and Chapter 14 described human-interface-device communications from the device's perspective and the report format
that HIDs use to exchange data with the host. This chapter introduces the Windows functions that applications can use to communicate with HIDs. Applications may use any
programming language that can call API functions. Chapter 16 has example code in Visual Basic and Visual C++. Much of the information in this chapter applies to communicating
with any USB device, not just HIDs.
Hubs: the Link between Devices and the Host
Every USB device must connect to a hub. As Chapter 2 explained, a hub is an intelligent device that provides attachment points for
devices and manages each device's connection to the bus. Devices that plug directly into a PC connect to the root hub. Other devices connect to external hubs downstream from
the root hub. A hub's two main jobs are managing its devices' connections and passing traffic to and from the host. Managing the connections includes helping to get newly attached
devices up and communicating and blocking communications from misbehaving devices so they don't interfere with other devices' use of the bus. The hub's role in passing traffic to
and from the host depends on the speed of the host, device, and the hubs between them. A hub may...
Return to Top
The Electrical Interface 
All of the protocols and program code in the world are no use if the signals don't make it down the cable in good shape. The electrical
interface plays an important part in making USB a reliable way to transfer information.
From a practical point of view, if you're using compliant cables and components, you don't need to know much about the electrical interface. You can just use the products you have
and trust that the hardware designers have done their job. But if you're designing USB transceivers or cables, printed-circuit boards with USB interfaces, or a protocol analyzer that
must unobtrusively monitor the bus, you do need to understand the electrical interface and how it applies to your project.
This chapter presents the essentials about the electrical interface of the USB's drivers and receivers and details about the cables that carry the signals...
|