i
i
i
i
i
i
i
i
17.5. Interfacing Custom VR Hardware with the Applications 497
your own device driver for Windows or Linux. Of course, it is possible to
do both—see [8] and [13]—but for all but the highest-speed interfaces, the
universal serial bus (USB) will do the job. With a bit of clever programming,
one can fool Windows into believing that it already has all the drivers it n eeds
and is dealing with a joystick. Interfacing to a PC via USB could be the
subject of several books in itself, so here we will only give an outline view of
the hardware and explain how an application program written in C/C++ can
read and write directly to a USB device.
17.5.1 A Brief Look at USB
The USB interface uses a serial protocol, and the h ardware connections con-
sist of four wires: +5V power and ground and two data lines called D+
and D−. The interface, depending on how it is configured, can be low,
full or high speed. Low-speed transfers operate at 1.5 Mbits/s, full-speed at
12 Mbits/s and high-speed 480 Mbits/s. However, in addition to data, the
bus has to carry control, status and error-checking signals, thus making the
actual data rates lower than these values. Therefore, the maximum data rates
are only 800 bytes per second for low speed, 1.2 megabits per second for full
speed and 53 megabits per second for high speed. The USB Implementers Fo-
rum
3
provides a comprehensive set of documentation on USB and has many
links to other useful resources.
There are four types of data transfers possible, each suited to different
applications, which may or may not be available to low-speed devices. These
transfers are control, bulk, interrupt and isochronous. Devices such as key-
boards, mice and joysticks are low-speed devices, and use interrupt data trans-
fer. The maximum possible transfer of data for this combination is 8 bytes
per 10 milliseconds.
When a peripheral device is connected to a PC via USB, a process called
enumeration takes place. During enumeration, the device’s interface must
send several pieces of information called descriptors to the PC. The descriptors
are sets of data that completely describe the USB device’s capabilities and
how the device will be used. A class of USB devices falls into a category
called human interface devices (HIDs), not surprisingly because these devices
interact directly with people. Examples of HIDs are keyboards, mice and
joysticks. Using the HID protocol, an application program can detect when
someone moves a joystick, or the PC might send a force-feedback effect that
the user can feel.
3
http://www.usb.org/.