CY8CKIT-046 PSoC® 4 L-Series Pioneer Kit Guide, Doc. #: 002-03344 Rev. *D
43
Code Examples
4. After successful driver installation (indicated by the blue LED turning ON), the CapSense Ges-
ture Pad is available as a USB mouse/keyboard. The gestures captured in
can be per-
formed to send the corresponding mouse/keyboard functionality to the PC.
5. In addition to USB mouse, the CapSense Gesture Pad can also be used to control RGB LED
color and brightness.
(column 4) lists the supported RGB LED color control gestures.
4.7
USB Audio
4.7.1
Project Description
This code example demonstrates the capability of PSoC 4200L to provide a high-quality audio play-
back and recording interface to a Windows or Mac PC. The example uses the PSoC 4200L USB to
implement an asynchronous USB Audio Class v1.0 compliant device. The PSoC 4 L-Series Pioneer
Kit has a standard 3.5-mm TRRS audio jack onboard and an audio codec to convert digital audio
stream into analog and vice-versa. These components along with PSoC 4200L implement the com-
plete USB Audio interface.
In addition, the CapSense Gesture Pad is used to provide the volume and media control options
required to control audio streaming. The example uses DMA to stream the audio data from USB
(PC) to the onboard audio codec through an I2S interface. The codec supports stereo audio-out and
stereo audio-in. However, the audio jack supports only mono audio-in. Therefore, the interface
implements a single channel stereo audio-out with mono audio-in. Note that the USB Audio IN end-
point is implemented as stereo to make the implementation easy. The same audio-in data (mono
data) is replicated on both the stereo channels in the USB Audio IN endpoint. Because the interface
is implemented using the standard USB Audio device class, no special drivers are required to sup-
port hardware in Windows and Mac OS. To learn more about the USB Audio 1.0 device class, refer
to the
USB Audio devices class v1.0 specification
The core of the implementation lies in the data transfer between the USB and I2S interface. The
USB to I2S dataflow has multiple stages for streaming as both data rates are different. Audio data
packets from the USB arrive once every millisecond whereas the I2S is a fixed stream of data at the
configured audio rate. Any breaks in the streaming data from I2S will manifest either as audible pops
in the audio or degradation in the quality of the audio. The PSoC implementation handles this such
that the audio quality is maintained without any audible pops.
The example supports 24-bit stereo audio at 48 kHz and 44.1 kHz audio rates. This means the
device supports two audio channels (stereo left and stereo right). Audio samples in each channel are
24 bits or 3 bytes wide and the number of stereo audio samples (6 bytes) transferred per second can
be 48000 or 44100. For a stereo audio output, two channels are required - left and right. Because
the audio codec supports stereo audio-in and stereo audio-out, the firmware implements the same –
stereo audio-in and stereo audio-out. To generate the stereo audio-in from a mono audio micro-
phone, the mono data is replicated on both channels. To transfer the stereo audio samples at 48 kHz
(48000 samples per second), we need to send/receive 48 samples per USB transaction (per milli-
second). Each sample contains two channel data and each channel’s data is 3 bytes wide. As a
result, to implement 48 kHz stereo audio over USB, we need to transfer 288 (48 × 2 × 3) bytes every
USB transaction. The data transferred per transaction is referred as a packet. Similarly for the
44.1 kHz sample rate, we need to transfer 264 bytes for nine transactions and 270 bytes every tenth
transaction (this averages out to 2646 sample every 10 ms, which is 44.1 kHz stereo audio).
To implement one stereo audio-out channel and one stereo audio-in channel, we will require two
USB endpoints (refer to
AN57294 - USB 101: An Introduction to Universal Serial Bus 2.0
on endpoints) – one for audio-out and one for audio-in. The buffer size of these USB endpoints is
derived from the maximum audio rate supported and the type of audio device implemented (syn-
chronous, asynchronous, or adaptive). The example implements an asynchronous audio device at a