USB HID Class(Case Study)

USB HID Class
The HID class consists of devices that are used by humans to control the operation of systems e.g. Keyboard, Mouse, Trackballs and Joy Sticks. HID classes are identified by a device as belonging to one of a finite number of classes (HID Class). A USB/HID class device uses a corresponding HID class to retrieve and route all the data. The routing and retrieval of data is accomplished by examining the descriptors of the device and that it provides which is depicted in the following figure;

The HID class device descriptors identify which other HID class descriptors are present and indicate their sizes e.g. Report and Physical descriptors. The HID does not have a human interface. The device just needs to be able to function within the limits of major abilities and limits of HID class devices

All data exchanged resides in fixed length structure called reports. The host sends and receives data by sending and requesting reports in a control or interrupts transfers. The report format is flexible and can handle just about any type of data.

A HID must have interrupt IN end point for sending input reports

A HID can have at most one interrupt IN endpoint and one interrupt out endpoint. A device that requires more interrupt endpoints can be a composite device with multiple HID interfaces.The Interrupt IN end point enables the HID to send information to the host at unpredictable time’s e.g There is no way for the host computer to know when a user will press a key on the board.

The rate of data exchange is limited. A low speed interrupt end point, a maximum data transfer rate of 800 bytes/sec.  For full speed points, the maximum is 64 KB/s. High Speed endpoints support faster rates.The USB specification allows for the connection of maximum of 127 peripheral devices to the system either on the same port or on different ports.
Descriptors
The following  is the detail of descriptors used in USB HID class;
Device Descriptor
Describes the number of configurations supported by the device and specifies vendor information and device class.
Configuration Descriptor
Specify one/ more interface and define certain attributes associated with this configuration.
Interface Descriptor
Defines the number of endpoints related to the interface along with information needed by host software to determine how end points should be accessed.
String Descriptor
Optional descriptors consisting of a Unicode string that provide human readable information which can be displayed on host side device.
HID Class Descriptor
The HID class descriptors identify additional descriptors for HID communication. The class description has seven or more fields depending on the number of additional descriptors.
Report Descriptor
A report descriptor defines the format and use of the data in the HID reports. If the device is a mouse; the data reports mouse movements and button clicks. If the device is a relay controller, the data specifies which relay to open and close. The descriptor format is flexible enough for use with the devices with varied functions.

Case Study(USB Mouse)
The following is the details of descriptors used for USB mouse as Case Study;
Device Descriptor

 


Configuration Descriptor

Interface Descriptor

HID Descriptor

End Point Descriptor

Report Descriptor

 

Advertisements

ALSA Audio Driver

ALSA Audio Driver
The below figure shows audio connection on a PC compatible system; the audio controller on the south bridge, together with an external codec, interfaces with analog audio circuitry.

Figure: Audio in a PC environment

An audio codec converts digital audio data to analog sound signals for playing via speakers and performs the reverse operation for recording via a microphone. Other common audio inputs and outputs that interface with a codec include headsets, earphone, hand free, line in and line Out. A codec offers mixer functionality that connects it to a combination of these audio outputs and inputs and controls the volume gain associated with audio signal.

Digital data is obtained by sampling audio analog signals at specific bit rates using a technique called pulse code modulation (PCM). CD quality is for example sound sampled at 44.1 KHz, using 16 bits to hold each sample. A codec is responsible for recording audio by sampling at supported PCM bit rates and for playing audio originally sampled at different bit rates.

Linux Sound Sub System
Advanced Linux Sound Architecture (ALSA) is the sound sub system in 2.6 Kernel. Open Sound System (OSS), the sound layer in the 2.4 layer is now obsolete and depreciated.
The following figure shows the Linux sound sub system;

Figure: Linux Sound Sub System (ALSA)

1). The following /dev/snd/* device nodes are created and managed by the ALSA core. /dev/snd/controlC0 is a control node that application uses for controlling volume gain and such. /dev/snd/pcmC0D0P is a play back device. /dev/snd/pcmD0C is a recording device.
2). Audio controller drivers specific to the controller hardware . To drive the audio controller present in the intel ICH south bridge chipsets e.g. use the snd_intel8x0 driver.
3). Audio codec interface that assist communication between controllers and codecs for AC’ 97 codec used the snd_ac97_codec and ac97_bus modules.
4). The nodes /dev/adsp and /dev/mixer allow OSS application to run unchanged over ALSA. The OSS /dev/dsp node maps to ALSA nodes /dev/snd/pcmC0D0; /dev/adsp corresponds to /dev/snd/pcmC0D1* and /dev/mixer associates with /dev/snd/ControlC0.
5). Procfs and sysfc interface implementations for accessing info via /proc/aSound and /Sys/class/sound.

6). The user space ALSA library alsa-lib which provides the libSound.so object. The library passes the job of the ALSA application programming by offering several canned routines to access ALSA drivers.

Tools and Links
1). http://tldp.org/HOWTO/Sound-HOWTO/
Answers of FAQ pertaining to Linux
2). http://sourceforge.net/projects/mad/files
MadPlay is a software MP3 decoder and player that are both ALSA and OSS aware.
3). http://rawrec.sourceforge.net
It is used for basic playback and recording.

Data Structure and API
The figures show the list of data structure and API used in developing the ALSA driver.

Figure: Summary of data structures

Figure: Summary of ALSA driver API