From 8ed7d596716686883b5baaba60d7f764791c904e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 1 Dec 2011 22:54:21 +0100 Subject: initial checkin of non-complete 'fast usb audio source' test program the idea is to explore how various OSs USB-Audio drivers react if you present them with an audio device of 512kHz or 1MHz sampling freq. --- usb-fast-audio-source/AUDDFastSourceDescriptors.c | 1455 +++++++++++++++++++++ usb-fast-audio-source/AUDDFastSourceDescriptors.h | 149 +++ usb-fast-audio-source/Makefile | 239 ++++ usb-fast-audio-source/bin/.empty_dir | 0 usb-fast-audio-source/fast_source.c | 140 ++ usb-fast-audio-source/fast_source.h | 18 + usb-fast-audio-source/main.c | 340 +++++ usb-fast-audio-source/obj/.empty_dir | 0 8 files changed, 2341 insertions(+) create mode 100644 usb-fast-audio-source/AUDDFastSourceDescriptors.c create mode 100644 usb-fast-audio-source/AUDDFastSourceDescriptors.h create mode 100644 usb-fast-audio-source/Makefile create mode 100644 usb-fast-audio-source/bin/.empty_dir create mode 100644 usb-fast-audio-source/fast_source.c create mode 100644 usb-fast-audio-source/fast_source.h create mode 100644 usb-fast-audio-source/main.c create mode 100644 usb-fast-audio-source/obj/.empty_dir (limited to 'usb-fast-audio-source') diff --git a/usb-fast-audio-source/AUDDFastSourceDescriptors.c b/usb-fast-audio-source/AUDDFastSourceDescriptors.c new file mode 100644 index 0000000..e117de8 --- /dev/null +++ b/usb-fast-audio-source/AUDDFastSourceDescriptors.c @@ -0,0 +1,1455 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "AUDDFastSourceDescriptors.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "Audio Loop Record Device Codes" +/// +/// This page lists the %device IDs and release number of the USB Audio Loop Record +/// %device. +/// +/// !Codes +/// - AUDDLoopRecDriverDescriptors_VENDORID +/// - AUDDLoopRecDriverDescriptors_PRODUCTID +/// - AUDDLoopRecDriverDescriptors_RELEASE + +/// Device vendor ID. +#define AUDDLoopRecDriverDescriptors_VENDORID 0x16C0 +/// Device product ID. +#define AUDDLoopRecDriverDescriptors_PRODUCTID 0x0763 +/// Device release number in BCD format. +#define AUDDLoopRecDriverDescriptors_RELEASE 0x0100 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Internal types +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Audio control header descriptor with one slave interface. +//------------------------------------------------------------------------------ +#ifdef __ICCARM__ // IAR +#pragma pack(1) // IAR +#define __attribute__(...) // IAR +#endif // IAR + +//------------------------------------------------------------------------------ +/// Header descriptor with 1 interface. +//------------------------------------------------------------------------------ +typedef struct { + + /// Header descriptor. + AUDHeaderDescriptor header; + /// Id of the first grouped interface - Speaker. + unsigned char bInterface0; + /// Id of the second grouped interface - Speakerphone. + unsigned char bInterface1; + +} __attribute__ ((packed)) AUDHeaderDescriptor2; // GCC + +//------------------------------------------------------------------------------ +/// Feature unit descriptor with 3 channel controls (master, right, left). +//------------------------------------------------------------------------------ +typedef struct { + + /// Feature unit descriptor. + AUDFeatureUnitDescriptor feature; + /// Available controls for each channel. + unsigned char bmaControls[3]; + /// Index of a string descriptor for the feature unit. + unsigned char iFeature; + +} __attribute__ ((packed)) AUDFeatureUnitDescriptor3; // GCC + +//------------------------------------------------------------------------------ +/// List of descriptors for detailling the audio control interface of a +/// device using a USB Audio Loop Recorder driver. +//------------------------------------------------------------------------------ +typedef struct { + + /// Header descriptor (with one slave interface). + AUDHeaderDescriptor2 header; + /// Input terminal descriptor. + AUDInputTerminalDescriptor inputLoopRec; + /// Output terminal descriptor. + AUDOutputTerminalDescriptor outputLoopRec; + /// Feature unit descriptor - LoopRec. + AUDFeatureUnitDescriptor3 featureLoopRec; + /// Input terminal descriptor. + AUDInputTerminalDescriptor inputRec; + /// Output terminal descriptor. + AUDOutputTerminalDescriptor outputRec; + /// Feature unit descriptor - LoopRecphone. + AUDFeatureUnitDescriptor3 featureRec; + +} __attribute__ ((packed)) AUDDLoopRecDriverAudioControlDescriptors; // GCC + +//------------------------------------------------------------------------------ +/// Format type I descriptor with one discrete sampling frequency. +//------------------------------------------------------------------------------ +typedef struct { + + /// Format type I descriptor. + AUDFormatTypeOneDescriptor formatType; + /// Sampling frequency in Hz. + unsigned char tSamFreq[3]; + +} __attribute__ ((packed)) AUDFormatTypeOneDescriptor1; // GCC + +//------------------------------------------------------------------------------ +/// Holds a list of descriptors returned as part of the configuration of +/// a USB Audio Loop Record device. +//------------------------------------------------------------------------------ +typedef struct { + + /// Standard configuration. + USBConfigurationDescriptor configuration; + /// Audio control interface. + USBInterfaceDescriptor control; + /// Descriptors for the audio control interface. + AUDDLoopRecDriverAudioControlDescriptors controlDescriptors; + //- AUDIO OUT + /// Streaming out interface descriptor (with no endpoint, required). + USBInterfaceDescriptor streamingOutNoIsochronous; + /// Streaming out interface descriptor. + USBInterfaceDescriptor streamingOut; + /// Audio class descriptor for the streaming out interface. + AUDStreamingInterfaceDescriptor streamingOutClass; + /// Stream format descriptor. + AUDFormatTypeOneDescriptor1 streamingOutFormatType; + /// Streaming out endpoint descriptor. + AUDEndpointDescriptor streamingOutEndpoint; + /// Audio class descriptor for the streaming out endpoint. + AUDDataEndpointDescriptor streamingOutDataEndpoint; + //- AUDIO IN + /// Streaming in interface descriptor (with no endpoint, required). + USBInterfaceDescriptor streamingInNoIsochronous; + /// Streaming in interface descriptor. + USBInterfaceDescriptor streamingIn; + /// Audio class descriptor for the streaming in interface. + AUDStreamingInterfaceDescriptor streamingInClass; + /// Stream format descriptor. + AUDFormatTypeOneDescriptor1 streamingInFormatType; + /// Streaming in endpoint descriptor. + AUDEndpointDescriptor streamingInEndpoint; + /// Audio class descriptor for the streaming in endpoint. + AUDDataEndpointDescriptor streamingInDataEndpoint; + +} __attribute__ ((packed)) AUDDLoopRecDriverConfigurationDescriptors; // GCC + +#ifdef __ICCARM__ // IAR +#pragma pack() // IAR +#endif // IAR + +//------------------------------------------------------------------------------ +// Exported variables +//------------------------------------------------------------------------------ + +/// Device descriptor for a USB Audio Loop Record driver. +const USBDeviceDescriptor deviceDescriptor = { + + sizeof(USBDeviceDescriptor), + USBGenericDescriptor_DEVICE, + USBDeviceDescriptor_USB2_00, + AUDDeviceDescriptor_CLASS, + AUDDeviceDescriptor_SUBCLASS, + AUDDeviceDescriptor_PROTOCOL, + CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0), + AUDDLoopRecDriverDescriptors_VENDORID, + AUDDLoopRecDriverDescriptors_PRODUCTID, + AUDDLoopRecDriverDescriptors_RELEASE, + 1, // Manufacturer string descriptor index + 2, // Product string descriptor index + 3, // Index of serial number string descriptor + 1 // One possible configuration +}; + +#if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS) + +/// USB device qualifier descriptor. +const USBDeviceQualifierDescriptor qualifierDescriptor = { + + sizeof(USBDeviceQualifierDescriptor), + USBGenericDescriptor_DEVICEQUALIFIER, + USBDeviceDescriptor_USB2_00, + AUDDeviceDescriptor_CLASS, + AUDDeviceDescriptor_SUBCLASS, + AUDDeviceDescriptor_PROTOCOL, + CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0), + 1, // Device has one possible configuration + 0 // Reserved +}; + +/// HS Configuration descriptors for a USB Audio Loop Record driver. +const AUDDLoopRecDriverConfigurationDescriptors hsConfigurationDescriptors = { + + // Configuration descriptor + { + sizeof(USBConfigurationDescriptor), + USBGenericDescriptor_CONFIGURATION, + sizeof(AUDDLoopRecDriverConfigurationDescriptors), + 3, // This configuration has 3 interfaces + 1, // This is configuration #1 + 0, // No string descriptor + BOARD_USB_BMATTRIBUTES, + USBConfigurationDescriptor_POWER(100) + }, + // Audio control interface standard descriptor + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_CONTROL, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoint + AUDControlInterfaceDescriptor_CLASS, + AUDControlInterfaceDescriptor_SUBCLASS, + AUDControlInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio control interface descriptors + { + // Header descriptor + { + { + sizeof(AUDHeaderDescriptor2), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_HEADER, + AUDHeaderDescriptor_AUD1_00, + sizeof(AUDDLoopRecDriverAudioControlDescriptors), + 2 // Two streaming interface + }, + AUDDLoopRecDriverDescriptors_STREAMING, + AUDDLoopRecDriverDescriptors_STREAMINGIN + }, + // Input terminal descriptor ( speaker ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDInputTerminalDescriptor_USBSTREAMING, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speaker ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDOutputTerminalDescriptor_SPEAKER, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + 0 // No string descriptor + }, + // Feature unit descriptor ( speaker ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 1, // 1 byte per channel for controls + }, + { + AUDFeatureUnitDescriptor_MUTE, // Master channel controls + 0, // Right channel controls + 0 // Left channel controls + }, + 0 // No string descriptor + }, + // Input terminal descriptor ( speakerphone ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDInputTerminalDescriptor_SPEAKERPHONE, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speakerphone ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDOutputTerminalDescriptor_USBTREAMING, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + 0 // No string descriptor + }, + // Feature unit descriptor ( speakerphone ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + 1 + }, + { + AUDFeatureUnitDescriptor_MUTE, // Mic controls + 0, + 0 + }, + 0 // No string descriptor + } + }, + // - AUIDO OUT + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_OUT, + AUDDLoopRecDriverDescriptors_DATAOUT), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_HS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + }, + //- AUDIO IN + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_IN, + AUDDLoopRecDriverDescriptors_DATAIN), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_HS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + } +}; + +/// HS Other Speed Configuration descriptors for a USB Audio Loop Record driver. +const AUDDLoopRecDriverConfigurationDescriptors + fsOtherSpeedConfigurationDescriptors = { + + // Configuration descriptor + { + sizeof(USBConfigurationDescriptor), + USBGenericDescriptor_OTHERSPEEDCONFIGURATION, + sizeof(AUDDLoopRecDriverConfigurationDescriptors), + 3, // This configuration has 3 interfaces + 1, // This is configuration #1 + 0, // No string descriptor + BOARD_USB_BMATTRIBUTES, + USBConfigurationDescriptor_POWER(100) + }, + // Audio control interface standard descriptor + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_CONTROL, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoint + AUDControlInterfaceDescriptor_CLASS, + AUDControlInterfaceDescriptor_SUBCLASS, + AUDControlInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio control interface descriptors + { + // Header descriptor + { + { + sizeof(AUDHeaderDescriptor2), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_HEADER, + AUDHeaderDescriptor_AUD1_00, + sizeof(AUDDLoopRecDriverAudioControlDescriptors), + 2 // Two streaming interface + }, + AUDDLoopRecDriverDescriptors_STREAMING, + AUDDLoopRecDriverDescriptors_STREAMINGIN + }, + // Input terminal descriptor ( speaker ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDInputTerminalDescriptor_USBSTREAMING, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speaker ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDOutputTerminalDescriptor_SPEAKER, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + 0 // No string descriptor + }, + // Feature unit descriptor ( speaker ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 1, // 1 byte per channel for controls + }, + { + AUDFeatureUnitDescriptor_MUTE, // Master channel controls + 0, // Right channel controls + 0 // Left channel controls + }, + 0 // No string descriptor + }, + // Input terminal descriptor ( speakerphone ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDInputTerminalDescriptor_SPEAKERPHONE, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speakerphone ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDOutputTerminalDescriptor_USBTREAMING, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + 0 // No string descriptor + }, + // Feature unit descriptor ( speakerphone ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + 1 + }, + { + AUDFeatureUnitDescriptor_MUTE, // Mic controls + 0, + 0 + }, + 0 // No string descriptor + } + }, + // - AUIDO OUT + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_OUT, + AUDDLoopRecDriverDescriptors_DATAOUT), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_HS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + }, + //- AUDIO IN + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_IN, + AUDDLoopRecDriverDescriptors_DATAIN), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_HS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + } +}; + +/// HS Other Speed Configuration descriptors. +const AUDDLoopRecDriverConfigurationDescriptors + hsOtherSpeedConfigurationDescriptors = { + + // Configuration descriptor + { + sizeof(USBConfigurationDescriptor), + USBGenericDescriptor_OTHERSPEEDCONFIGURATION, + sizeof(AUDDLoopRecDriverConfigurationDescriptors), + 3, // This configuration has 3 interfaces + 1, // This is configuration #1 + 0, // No string descriptor + BOARD_USB_BMATTRIBUTES, + USBConfigurationDescriptor_POWER(100) + }, + // Audio control interface standard descriptor + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_CONTROL, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoint + AUDControlInterfaceDescriptor_CLASS, + AUDControlInterfaceDescriptor_SUBCLASS, + AUDControlInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio control interface descriptors + { + // Header descriptor + { + { + sizeof(AUDHeaderDescriptor2), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_HEADER, + AUDHeaderDescriptor_AUD1_00, + sizeof(AUDDLoopRecDriverAudioControlDescriptors), + 2 // Two streaming interface + }, + AUDDLoopRecDriverDescriptors_STREAMING, + AUDDLoopRecDriverDescriptors_STREAMINGIN + }, + // Input terminal descriptor ( speaker ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDInputTerminalDescriptor_USBSTREAMING, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speaker ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDOutputTerminalDescriptor_SPEAKER, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + 0 // No string descriptor + }, + // Feature unit descriptor ( speaker ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 1, // 1 byte per channel for controls + }, + { + AUDFeatureUnitDescriptor_MUTE, // Master channel controls + 0, // Right channel controls + 0 // Left channel controls + }, + 0 // No string descriptor + }, + // Input terminal descriptor ( speakerphone ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDInputTerminalDescriptor_SPEAKERPHONE, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speakerphone ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDOutputTerminalDescriptor_USBTREAMING, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + 0 // No string descriptor + }, + // Feature unit descriptor ( speakerphone ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + 1 + }, + { + AUDFeatureUnitDescriptor_MUTE, // Mic controls + 0, + 0 + }, + 0 // No string descriptor + } + }, + // - AUIDO OUT + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_OUT, + AUDDLoopRecDriverDescriptors_DATAOUT), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_FS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + }, + //- AUDIO IN + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_IN, + AUDDLoopRecDriverDescriptors_DATAIN), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_FS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + } +}; + +#endif // defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS) + +/// FS Configuration descriptors for a USB Audio Loop Record driver. +const AUDDLoopRecDriverConfigurationDescriptors fsConfigurationDescriptors = { + + // Configuration descriptor + { + sizeof(USBConfigurationDescriptor), + USBGenericDescriptor_CONFIGURATION, + sizeof(AUDDLoopRecDriverConfigurationDescriptors), + 3, // This configuration has 3 interfaces + 1, // This is configuration #1 + 0, // No string descriptor + BOARD_USB_BMATTRIBUTES, + USBConfigurationDescriptor_POWER(100) + }, + // Audio control interface standard descriptor + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_CONTROL, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoint + AUDControlInterfaceDescriptor_CLASS, + AUDControlInterfaceDescriptor_SUBCLASS, + AUDControlInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio control interface descriptors + { + // Header descriptor + { + { + sizeof(AUDHeaderDescriptor2), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_HEADER, + AUDHeaderDescriptor_AUD1_00, + sizeof(AUDDLoopRecDriverAudioControlDescriptors), + 2 // Two streaming interface + }, + AUDDLoopRecDriverDescriptors_STREAMING, + AUDDLoopRecDriverDescriptors_STREAMINGIN + }, + // Input terminal descriptor ( speaker ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDInputTerminalDescriptor_USBSTREAMING, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speaker ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL, + AUDOutputTerminalDescriptor_SPEAKER, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + 0 // No string descriptor + }, + // Feature unit descriptor ( speaker ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 1, // 1 byte per channel for controls + }, + { + AUDFeatureUnitDescriptor_MUTE, // Master channel controls + 0, // Right channel controls + 0 // Left channel controls + }, + 0 // No string descriptor + }, + // Input terminal descriptor ( speakerphone ) + { + sizeof(AUDInputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_INPUTTERMINAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDInputTerminalDescriptor_SPEAKERPHONE, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDDLoopRecDriver_NUMCHANNELS, + #if AUDDLoopRecDriver_NUMCHANNELS > 1 + AUDInputTerminalDescriptor_LEFTFRONT + | AUDInputTerminalDescriptor_RIGHTFRONT, + #else + 0, // Mono sets no position bits. + #endif + 0, // No string descriptor for channels + 0 // No string descriptor for input terminal + }, + // Output terminal descriptor ( speakerphone ) + { + sizeof(AUDOutputTerminalDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_OUTPUTTERMINAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + AUDOutputTerminalDescriptor_USBTREAMING, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + 0 // No string descriptor + }, + // Feature unit descriptor ( speakerphone ) + { + { + sizeof(AUDFeatureUnitDescriptor3), + AUDGenericDescriptor_INTERFACE, + AUDGenericDescriptor_FEATUREUNIT, + AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC, + 1 + }, + { + AUDFeatureUnitDescriptor_MUTE, // Mic controls + 0, + 0 + }, + 0 // No string descriptor + } + }, + // - AUIDO OUT + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMING, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_INPUTTERMINAL, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_OUT, + AUDDLoopRecDriverDescriptors_DATAOUT), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_FS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + }, + //- AUDIO IN + // Audio streaming interface with 0 endpoints + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 0, // This is alternate setting #0 + 0, // This interface uses no endpoints + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming interface with data endpoint + { + sizeof(USBInterfaceDescriptor), + USBGenericDescriptor_INTERFACE, + AUDDLoopRecDriverDescriptors_STREAMINGIN, + 1, // This is alternate setting #1 + 1, // This interface uses 1 endpoint + AUDStreamingInterfaceDescriptor_CLASS, + AUDStreamingInterfaceDescriptor_SUBCLASS, + AUDStreamingInterfaceDescriptor_PROTOCOL, + 0 // No string descriptor + }, + // Audio streaming class-specific descriptor + { + sizeof(AUDStreamingInterfaceDescriptor), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_GENERAL, + AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC, + 0, // No internal delay because of data path + AUDFormatTypeOneDescriptor_PCM + }, + // Format type I descriptor + { + { + sizeof(AUDFormatTypeOneDescriptor1), + AUDGenericDescriptor_INTERFACE, + AUDStreamingInterfaceDescriptor_FORMATTYPE, + AUDFormatTypeOneDescriptor_FORMATTYPEONE, + AUDDLoopRecDriver_NUMCHANNELS, + AUDDLoopRecDriver_BYTESPERSAMPLE, + AUDDLoopRecDriver_BYTESPERSAMPLE*8, + 1 // One discrete frequency supported + }, + { + AUDDLoopRecDriver_SAMPLERATE & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 8) & 0xFF, + (AUDDLoopRecDriver_SAMPLERATE >> 16) & 0xFF + } + }, + // Audio streaming endpoint standard descriptor + { + sizeof(AUDEndpointDescriptor), + USBGenericDescriptor_ENDPOINT, + USBEndpointDescriptor_ADDRESS( + USBEndpointDescriptor_IN, + AUDDLoopRecDriverDescriptors_DATAIN), + USBEndpointDescriptor_ISOCHRONOUS, + AUDDLoopRecDriver_BYTESPERFRAME, + AUDDLoopRecDriverDescriptors_FS_INTERVAL, // Polling interval = 1 ms + 0, // This is not a synchronization endpoint + 0 // No associated synchronization endpoint + }, + // Audio streaming endpoint class-specific descriptor + { + sizeof(AUDDataEndpointDescriptor), + AUDGenericDescriptor_ENDPOINT, + AUDDataEndpointDescriptor_SUBTYPE, + 0, // No attributes + 0, // Endpoint is not synchronized + 0 // Endpoint is not synchronized + } +}; + +/// String descriptor with the supported languages. +const unsigned char languageIdDescriptor[] = { + + USBStringDescriptor_LENGTH(1), + USBGenericDescriptor_STRING, + USBStringDescriptor_ENGLISH_US +}; + +/// Manufacturer name. +const unsigned char manufacturerDescriptor[] = { + + USBStringDescriptor_LENGTH(8), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('s'), + USBStringDescriptor_UNICODE('y'), + USBStringDescriptor_UNICODE('s'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('c'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('m'), +}; + +/// Product name. +const unsigned char productDescriptor[] = { + + USBStringDescriptor_LENGTH(7), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('O'), + USBStringDescriptor_UNICODE('s'), + USBStringDescriptor_UNICODE('m'), + USBStringDescriptor_UNICODE('o'), + USBStringDescriptor_UNICODE('S'), + USBStringDescriptor_UNICODE('D'), + USBStringDescriptor_UNICODE('R'), +}; + +/// Product serial number. +const unsigned char serialNumberDescriptor[] = { + + USBStringDescriptor_LENGTH(4), + USBGenericDescriptor_STRING, + USBStringDescriptor_UNICODE('0'), + USBStringDescriptor_UNICODE('1'), + USBStringDescriptor_UNICODE('2'), + USBStringDescriptor_UNICODE('3') +}; + +/// Array of pointers to the four string descriptors. +const unsigned char *stringDescriptors[] = { + + languageIdDescriptor, + manufacturerDescriptor, + productDescriptor, + serialNumberDescriptor, +}; + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +/// List of descriptors required by an USB Audio Loop Recorder device driver. +const USBDDriverDescriptors auddFastSourceDriverDescriptors = { + + &deviceDescriptor, + (const USBConfigurationDescriptor *) &fsConfigurationDescriptors, +#if defined (CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS) + &qualifierDescriptor, + (const USBConfigurationDescriptor *) &fsOtherSpeedConfigurationDescriptors, + &deviceDescriptor, + (const USBConfigurationDescriptor *) &hsConfigurationDescriptors, + &qualifierDescriptor, + (const USBConfigurationDescriptor *) &hsOtherSpeedConfigurationDescriptors, +#else + 0, 0, 0, 0, 0, 0, +#endif + stringDescriptors, + 4 // Number of string descriptors +}; + diff --git a/usb-fast-audio-source/AUDDFastSourceDescriptors.h b/usb-fast-audio-source/AUDDFastSourceDescriptors.h new file mode 100644 index 0000000..ab25f49 --- /dev/null +++ b/usb-fast-audio-source/AUDDFastSourceDescriptors.h @@ -0,0 +1,149 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +/** + \unit + + !!!Purpose + + Declaration of the descriptors required by a USB audio speaker driver. + + !!!Usage + + -# Initialize a USBDDriver instance using the + auddSpeakerDriverDescriptors list. +*/ + +#ifndef AUDDLOOPRECDESCRIPTORS_H +#define AUDDLOOPRECDESCRIPTORS_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "Audio Speaker Endpoint Numbers" +/// +/// This page lists the endpoint number settings for USB Audio Speaker device. +/// +/// !Endpoints +/// - AUDDLoopRecDriverDescriptors_DATAOUT +/// - AUDDLoopRecDriverDescriptors_DATAIN +/// - AUDDLoopRecDriverDescriptors_HS_INTERVAL +/// - AUDDLoopRecDriverDescriptors_FS_INTERVAL + +#if defined(at91sam7s) || defined(at91sam9xe) + /// Data out endpoint number, size 64B. + #define AUDDLoopRecDriverDescriptors_DATAOUT 0x01 + /// Data in endpoint number, size 64B + #define AUDDLoopRecDriverDescriptors_DATAIN 0x02 +#elif defined(CHIP_USB_UDP) + /// Data out endpoint number, size 192B. + #define AUDDLoopRecDriverDescriptors_DATAOUT 0x04 + /// Data in endpoint number, size 192B. + #define AUDDLoopRecDriverDescriptors_DATAIN 0x05 +#elif defined(at91sam9m10ek) || defined(at91sam9m10ekes) + /// Data out endpoint number, size 192B. + #define AUDDLoopRecDriverDescriptors_DATAOUT 0x01 + /// Data in endpoint number, size 192B + #define AUDDLoopRecDriverDescriptors_DATAIN 0x06 +#else + /// Data out endpoint number, size 192B. + #define AUDDLoopRecDriverDescriptors_DATAOUT 0x05 + /// Data in endpoint number, size 192B + #define AUDDLoopRecDriverDescriptors_DATAIN 0x06 +#endif + +/// Endpoint polling interval 2^(x-1) * 125us +#define AUDDLoopRecDriverDescriptors_HS_INTERVAL 0x04 +/// Endpoint polling interval 2^(x-1) * ms +#define AUDDLoopRecDriverDescriptors_FS_INTERVAL 0x01 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "Audio Speaker Interface IDs" +/// +/// This page lists the interface numbers for USB Audio Speaker device. +/// +/// !Interfaces +/// - AUDDLoopRecDriverDescriptors_CONTROL +/// - AUDDLoopRecDriverDescriptors_STREAMING +/// - AUDDLoopRecDriverDescriptors_STREAMINGIN + +/// Audio control interface ID. +#define AUDDLoopRecDriverDescriptors_CONTROL 0 +/// Audio streaming interface ID (OUT, for playback). +#define AUDDLoopRecDriverDescriptors_STREAMING 1 +/// Audio streaming interface ID (IN, for record). +#define AUDDLoopRecDriverDescriptors_STREAMINGIN 2 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// \page "Audio Speaker Entity IDs" +/// +/// This page lists the entity IDs for USB Audio Speaker device. +/// +/// !Entities +/// - AUDDLoopRecDriverDescriptors_INPUTTERMINAL +/// - AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL +/// - AUDDLoopRecDriverDescriptors_FEATUREUNIT +/// - AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC +/// - AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC +/// - AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC + +/// Playback input terminal ID. +#define AUDDLoopRecDriverDescriptors_INPUTTERMINAL 0 +/// Playback output terminal ID. +#define AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL 1 +/// Playback feature unit ID. +#define AUDDLoopRecDriverDescriptors_FEATUREUNIT 2 +/// Record input terminal ID. +#define AUDDLoopRecDriverDescriptors_INPUTTERMINAL_REC 3 +/// Record output terminal ID. +#define AUDDLoopRecDriverDescriptors_OUTPUTTERMINAL_REC 4 +/// Record feature unit ID +#define AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC 5 +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exported variables +//------------------------------------------------------------------------------ + +extern const USBDDriverDescriptors auddLoopRecDriverDescriptors; + +#endif //#ifndef AUDDLOOPRECDESCRIPTORS_H + diff --git a/usb-fast-audio-source/Makefile b/usb-fast-audio-source/Makefile new file mode 100644 index 0000000..38ea27d --- /dev/null +++ b/usb-fast-audio-source/Makefile @@ -0,0 +1,239 @@ +# ---------------------------------------------------------------------------- +# ATMEL Microcontroller Software Support +# ---------------------------------------------------------------------------- +# Copyright (c) 2008, Atmel Corporation +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# +# Atmel's name may not be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ---------------------------------------------------------------------------- + +# Makefile for compiling the usb-device-core-project project + +#------------------------------------------------------------------------------- +# User-modifiable options +#------------------------------------------------------------------------------- + +# Chip & board used for compilation +# (can be overriden by adding CHIP=chip and BOARD=board to the command-line) +CHIP = at91sam3u4 +BOARD = at91sam3u-ek + +# Trace level used for compilation +# (can be overriden by adding TRACE_LEVEL=#number to the command-line) +# TRACE_LEVEL_DEBUG 5 +# TRACE_LEVEL_INFO 4 +# TRACE_LEVEL_WARNING 3 +# TRACE_LEVEL_ERROR 2 +# TRACE_LEVEL_FATAL 1 +# TRACE_LEVEL_NO_TRACE 0 +TRACE_LEVEL = 5 + +# Optimization level, put in comment for debugging +OPTIMIZATION = -Os + +# AT91 library directory +AT91LIB = ../../at91lib + +# External library +EXT_LIBS= ../external_libs + +# Output file basename +OUTPUT = usb-fast-source-$(BOARD)-$(CHIP) + +# Compile with chip specific features +include $(AT91LIB)/boards/$(BOARD)/$(CHIP)/chip.mak + +# Compile for all memories available on the board (this sets $(MEMORIES)) +include $(AT91LIB)/boards/$(BOARD)/board.mak + +# Output directories +BIN = bin +OBJ = obj + +#------------------------------------------------------------------------------- +# Tools +#------------------------------------------------------------------------------- + +# Tool suffix when cross-compiling +CROSS_COMPILE = arm-none-eabi- + +# Compilation tools +CC = $(CROSS_COMPILE)gcc +SIZE = $(CROSS_COMPILE)size +STRIP = $(CROSS_COMPILE)strip +OBJCOPY = $(CROSS_COMPILE)objcopy + +# Flags +INCLUDES += -I$(AT91LIB)/boards/$(BOARD) +INCLUDES += -I$(AT91LIB)/peripherals +INCLUDES += -I$(AT91LIB)/components +INCLUDES += -I$(AT91LIB)/drivers +INCLUDES += -I$(AT91LIB) +INCLUDES += -I$(EXT_LIBS) +INCLUDES += -I$(EXT_LIBS)/cmsis +INCLUDES += -I. + +ifeq ($(CHIP_CORE), cortexm3) +TARGET_OPTS = -mcpu=cortex-m3 -mthumb +else +TARGET_OPTS = +endif + +CFLAGS += $(TARGET_OPTS) +CFLAGS += -Wall -mlong-calls -ffunction-sections +CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) +ASFLAGS = $(TARGET_OPTS) -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__ +LDFLAGS = -g $(OPTIMIZATION) -nostartfiles $(TARGET_OPTS) -Wl,--gc-sections + +#------------------------------------------------------------------------------- +# Files +#------------------------------------------------------------------------------- + +# Directories where source files can be found +PERIPH = $(AT91LIB)/peripherals +BOARDS = $(AT91LIB)/boards +UTILITY = $(AT91LIB)/utility +COMP = $(AT91LIB)/components +DRIVER = $(AT91LIB)/drivers +USB = $(AT91LIB)/usb + +VPATH += $(UTILITY) +VPATH += $(PERIPH)/dbgu +VPATH += $(PERIPH)/pio +VPATH += $(PERIPH)/irq +VPATH += $(PERIPH)/ssc +VPATH += $(PERIPH)/twi +VPATH += $(PERIPH)/pmc +VPATH += $(PERIPH)/cp15 +VPATH += $(BOARDS)/$(BOARD) +VPATH += $(BOARDS)/$(BOARD)/$(CHIP) +VPATH += $(DRIVER)/twi +VPATH += $(PERIPH)/mci +VPATH += $(PERIPH)/dma +VPATH += $(DRIVER)/dmad +VPATH += $(EXT_LIBS)/cmsis + +VPATH += $(USB)/device/core +VPATH += $(USB)/common/core +VPATH += $(USB)/common/audio + +# Objects built from C source files +C_OBJECTS += main.o +C_OBJECTS += USBD_UDPHS.o +C_OBJECTS += USBDDriver.o +C_OBJECTS += USBDCallbacks_Initialized.o +C_OBJECTS += USBDCallbacks_Reset.o +#C_OBJECTS += USBDCallbacks_Resumed.o +#C_OBJECTS += USBDCallbacks_Suspended.o +C_OBJECTS += USBDDriverCb_CfgChanged.o +#C_OBJECTS += USBDDriverCb_IfSettingChanged.o +C_OBJECTS += USBInterfaceRequest.o +C_OBJECTS += USBFeatureRequest.o +C_OBJECTS += USBGenericRequest.o +C_OBJECTS += USBGetDescriptorRequest.o +C_OBJECTS += USBSetAddressRequest.o +C_OBJECTS += USBSetConfigurationRequest.o +C_OBJECTS += USBGenericDescriptor.o +C_OBJECTS += USBConfigurationDescriptor.o +C_OBJECTS += USBEndpointDescriptor.o +C_OBJECTS += dbgu.o +C_OBJECTS += pio.o +C_OBJECTS += pio_it.o +C_OBJECTS += ssc.o +C_OBJECTS += twi.o +C_OBJECTS += pmc.o +C_OBJECTS += led.o +C_OBJECTS += twid.o +C_OBJECTS += string.o +C_OBJECTS += stdio.o +C_OBJECTS += math.o +C_OBJECTS += trace.o +C_OBJECTS += board_memories.o +C_OBJECTS += board_lowlevel.o + +C_OBJECTS += AUDGenericRequest.o AUDFeatureUnitRequest.o + +C_OBJECTS += AUDDFastSourceDescriptors.o fast_source.o + + +# Objects for different chips +ifeq ($(CHIP_CORE), cortexm3) +C_OBJECTS += nvic.o +C_OBJECTS += exceptions.o +C_OBJECTS += board_cstartup_gnu.o +C_OBJECTS += core_cm3.o +else +C_OBJECTS += aic.o +C_OBJECTS += cp15.o +endif + +ifeq ($(CHIP_IP_MCI), MCI_DMA) +C_OBJECTS += dmad.o +C_OBJECTS += dma.o +C_OBJECTS += mci_hs.o +else +C_OBJECTS += mci.o +endif + +# Objects built from Assembly source files +ifneq ($(CHIP_CORE), cortexm3) +ASM_OBJECTS += board_cstartup.o +ASM_OBJECTS += cp15_asm.o +endif + +# Append OBJ and BIN directories to output filename +OUTPUT := $(BIN)/$(OUTPUT) + +#------------------------------------------------------------------------------- +# Rules +#------------------------------------------------------------------------------- + +all: $(BIN) $(OBJ) $(MEMORIES) + +$(BIN) $(OBJ): + mkdir $@ + +define RULES +C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS)) +ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS)) + +$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1)) + $(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/$$@.lds" -o $(OUTPUT)-$$@.elf $$^ + $(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin + $(SIZE) $$^ $(OUTPUT)-$$@.elf + +$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN) + $(CC) $(CFLAGS) -D$(1) -c -o $$@ $$< + +$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN) + $(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$< + +debug_$(1): $(1) + perl ../resources/gdb/debug.pl $(OUTPUT)-$(1).elf + +endef + +$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY)))) + +clean: + -rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf + diff --git a/usb-fast-audio-source/bin/.empty_dir b/usb-fast-audio-source/bin/.empty_dir new file mode 100644 index 0000000..e69de29 diff --git a/usb-fast-audio-source/fast_source.c b/usb-fast-audio-source/fast_source.c new file mode 100644 index 0000000..7d20c7e --- /dev/null +++ b/usb-fast-audio-source/fast_source.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +extern const USBDDriverDescriptors auddFastSourceDriverDescriptors; +static unsigned char driver_interfaces[3]; +static USBDDriver fast_source_driver; + +/* callback */ +void USBDCallbacks_RequestReceived(const USBGenericRequest *request) +{ + fastsource_req_hdlr(request); +} + +void USBDDriverCallbacks_InterfaceSettingChanged(unsigned char interface, + unsigned char setting) +{ + if ((interface == AUDDLoopRecDriverDescriptors_STREAMING) + && (setting == 0)) + LED_Clear(USBD_LEDOTHER); + else + LED_Set(USBD_LEDOTHER); +} + +static void fastsource_get_feat_cur_val(uint8_t entity, uint8_t channel, + uint8_t control, uint8_t length) +{ + /* FIXME */ + USBD_Stall(0); +} + +static void fastsource_set_feat_cur_val(uint8_t entity, uint8_t channel, + uint8_t control, uint8_t length) +{ + /* FIXME */ + USBD_Stall(0); +} + +void fastsource_req_hdlr(const USBGenericRequest *request) +{ + unsigned char entity; + unsigned char interface; + + switch (USBGenericRequest_GetType(request)) { + case USBGenericRequest_STANDARD: + USBDDriver_RequestHandler(&fast_source_driver, request); + return; + case USBGenericRequest_CLASS: + /* continue below */ + break; + default: + TRACE_WARNING("Unsupported request type %u\n\r", + USBGenericRequest_GetType(request)); + USBD_Stall(0); + return; + } + + switch (USBGenericRequest_GetRequest(request)) { + case AUDGenericRequest_SETCUR: + entity = AUDGenericRequest_GetEntity(request); + interface = AUDGenericRequest_GetInterface(request); + if (((entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT) || + (entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC)) && + (interface == AUDDLoopRecDriverDescriptors_CONTROL)) { + fastsource_set_feat_cur_val(entity, + AUDFeatureUnitRequest_GetChannel(request), + AUDFeatureUnitRequest_GetControl(request), + USBGenericRequest_GetLength(request)); + } else { + TRACE_WARNING("Unsupported entity/interface combination 0x%04x\n\r", + USBGenericRequest_GetIndex(request)); + USBD_Stall(0); + } + break; + case AUDGenericRequest_GETCUR: + entity = AUDGenericRequest_GetEntity(request); + interface = AUDGenericRequest_GetInterface(request); + if (((entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT) || + (entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC)) && + (interface == AUDDLoopRecDriverDescriptors_CONTROL)) { + fastsource_get_feat_cur_val(entity, + AUDFeatureUnitRequest_GetChannel(request), + AUDFeatureUnitRequest_GetControl(request), + USBGenericRequest_GetLength(request)); + } else { + TRACE_WARNING("Unsupported entity/interface combination 0x%04x\n\r", + USBGenericRequest_GetIndex(request)); + USBD_Stall(0); + } + break; + default: + TRACE_WARNING("Unsupported request %u\n\r", + USBGenericRequest_GetIndex(request)); + USBD_Stall(0); + break; + } +} + +void fastsource_init(void) +{ + USBDDriver_Initialize(&fast_source_driver, &auddFastSourceDriverDescriptors, + driver_interfaces); + + USBD_Init(); +} + +const uint8_t test_data[2048]; + +static void wr_compl_cb(void *arg, unsigned char status, unsigned int transferred, + unsigned int remain) +{ + uint8_t epnr = (uint8_t) arg; + + if (status == 0 && remain == 0) { + fastsource_start(epnr); + } else { + printf("Err: EP%u wr_compl, status 0x%02u, xfr %u, remain %u\r\n", + epnr, status, transferred, remain); + } +} + +void fastsource_start(uint8_t epnr) +{ + USBD_Write(epnr, &test_data, sizeof(test_data), wr_compl_cb, (void *) epnr); +} + + diff --git a/usb-fast-audio-source/fast_source.h b/usb-fast-audio-source/fast_source.h new file mode 100644 index 0000000..1fc0b2b --- /dev/null +++ b/usb-fast-audio-source/fast_source.h @@ -0,0 +1,18 @@ + +#include + +#define AUDDLoopRecDriver_SAMPLERATE 512000 +#define AUDDLoopRecDriver_NUMCHANNELS 2 +#define AUDDLoopRecDriver_BYTESPERSAMPLE 2 + +#define AUDDLoopRecDriver_SAMPLESPERFRAME (AUDDLoopRecDriver_SAMPLERATE / 16384 \ + * AUDDLoopRecDriver_NUMCHANNELS) + +#define AUDDLoopRecDriver_BYTESPERFRAME (AUDDLoopRecDriver_SAMPLESPERFRAME * \ + AUDDLoopRecDriver_BYTESPERSAMPLE) + +#include + +void fastsource_init(void); +void fastsource_start(uint8_t epnr); +void fastsource_req_hdlr(const USBGenericRequest *request); diff --git a/usb-fast-audio-source/main.c b/usb-fast-audio-source/main.c new file mode 100644 index 0000000..57808a1 --- /dev/null +++ b/usb-fast-audio-source/main.c @@ -0,0 +1,340 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2009, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ +/** + * \file + * + * This file contains all the specific code for the + * usb_fast_source example. + */ + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +/*---------------------------------------------------------------------------- + * Definitions + *----------------------------------------------------------------------------*/ + +#if 0 +/** Number of available audio buffers. */ +#define BUFFER_NUMBER 8 +/** Size of one buffer in bytes. */ +#define BUFFER_SIZE (AUDDLoopRecDriver_BYTESPERFRAME*2) +#endif + +/// Use for power management +#define STATE_IDLE 0 +/// The USB device is in suspend state +#define STATE_SUSPEND 4 +/// The USB device is in resume state +#define STATE_RESUME 5 + +//------------------------------------------------------------------------------ +// Internal variables +//------------------------------------------------------------------------------ +/// State of USB, for suspend and resume +unsigned char USBState = STATE_IDLE; + +#if 0 +/** Data buffers for receiving audio frames from the USB host. */ +static uint8_t buffers[BUFFER_NUMBER][BUFFER_SIZE]; +/** Number of samples stored in each data buffer. */ +static uint32_t bufferSizes[BUFFER_NUMBER]; +/** Next buffer in which USB data can be stored. */ +static uint32_t inBufferIndex = 0; +/** Number of buffers that can be sent to the DAC. */ +static volatile uint32_t numBuffersToSend = 0; +#endif + +/** Current state of the playback stream interface. */ +static volatile uint8_t isPlyActive = 0; +/** Current state of the record stream interface. */ +static volatile uint8_t isRecActive = 0; + +/*---------------------------------------------------------------------------- + * VBus monitoring (optional) + *----------------------------------------------------------------------------*/ + +/** VBus pin instance. */ +static const Pin pinVbus = PIN_USB_VBUS; + +/** + * Handles interrupts coming from PIO controllers. + */ +static void ISR_Vbus(const Pin *pPin) +{ + /* Check current level on VBus */ + if (PIO_Get(&pinVbus)) + { + TRACE_INFO("VBUS conn\n\r"); + USBD_Connect(); + } + else + { + TRACE_INFO("VBUS discon\n\r"); + USBD_Disconnect(); + } +} + +/** + * Configures the VBus pin to trigger an interrupt when the level on that pin + * changes. + */ +static void VBus_Configure( void ) +{ + /* Configure PIO */ + PIO_Configure(&pinVbus, 1); + PIO_ConfigureIt(&pinVbus, ISR_Vbus); + PIO_EnableIt(&pinVbus); + + /* Check current level on VBus */ + if (PIO_Get(&pinVbus)) + { + /* if VBUS present, force the connect */ + USBD_Connect(); + } + else + { + TRACE_INFO("discon\n\r"); + USBD_Disconnect(); + } +} + +/*---------------------------------------------------------------------------- + * USB Power Control + *----------------------------------------------------------------------------*/ + +#ifdef PIN_USB_POWER_ENA +/** Power Enable A (MicroAB Socket) pin instance. */ +static const Pin pinPOnA = PIN_USB_POWER_ENA; +#endif +#ifdef PIN_USB_POWER_ENB +/** Power Enable B (A Socket) pin instance. */ +static const Pin pinPOnB = PIN_USB_POWER_ENB; +#endif +#ifdef PIN_USB_POWER_ENC +/** Power Enable C (A Socket) pin instance. */ +static const Pin pinPOnC = PIN_USB_POWER_ENC; +#endif +/** + * Configures the Power Enable pin to disable self power. + */ +static void USBPower_Configure( void ) +{ + #ifdef PIN_USB_POWER_ENA + PIO_Configure(&pinPOnA, 1); + #endif + #ifdef PIN_USB_POWER_ENB + PIO_Configure(&pinPOnB, 1); + #endif + #ifdef PIN_USB_POWER_ENC + PIO_Configure(&pinPOnC, 1); + #endif +} + +/*---------------------------------------------------------------------------- + * Internal functions + *----------------------------------------------------------------------------*/ + +#if 0 +/** + * Invoked when a frame has been received. + */ +static void FrameReceived(uint32_t unused, + uint8_t status, + uint32_t transferred, + uint32_t remaining) +{ + if (status == USBD_STATUS_SUCCESS) + { + /* Loopback! add this buffer to write list */ + if (!isRecActive) {} + else + { + AUDDLoopRecDriver_Write(buffers[inBufferIndex], + AUDDLoopRecDriver_BYTESPERFRAME, + NULL, 0); + } + + /* Update input status data */ + bufferSizes[inBufferIndex] = transferred + / AUDDLoopRecDriver_BYTESPERSAMPLE; + inBufferIndex = (inBufferIndex + 1) % BUFFER_NUMBER; + numBuffersToSend++; + + } + else if (status == USBD_STATUS_ABORTED) + { + /* Error , ABORT, add NULL buffer */ + bufferSizes[inBufferIndex] = 0; + inBufferIndex = (inBufferIndex + 1) % BUFFER_NUMBER; + numBuffersToSend++; + } + else + { + /* Packet is discarded */ + } + + /* Receive next packet */ + AUDDLoopRecDriver_Read(buffers[inBufferIndex], + AUDDLoopRecDriver_BYTESPERFRAME, + (TransferCallback) FrameReceived, + 0); // No optional argument +} +#endif + +/*---------------------------------------------------------------------------- + * Callbacks re-implementation + *----------------------------------------------------------------------------*/ + +//------------------------------------------------------------------------------ +/// Invoked when the USB device leaves the Suspended state. By default, +/// configures the LEDs. +//------------------------------------------------------------------------------ +void USBDCallbacks_Resumed(void) +{ + // Initialize LEDs + LED_Configure(USBD_LEDPOWER); + LED_Set(USBD_LEDPOWER); + LED_Configure(USBD_LEDUSB); + LED_Clear(USBD_LEDUSB); + USBState = STATE_RESUME; +} + +//------------------------------------------------------------------------------ +/// Invoked when the USB device gets suspended. By default, turns off all LEDs. +//------------------------------------------------------------------------------ +void USBDCallbacks_Suspended(void) +{ + // Turn off LEDs + LED_Clear(USBD_LEDPOWER); + LED_Clear(USBD_LEDUSB); + USBState = STATE_SUSPEND; +} + + + +/*---------------------------------------------------------------------------- + * Exported functions + *----------------------------------------------------------------------------*/ + +extern void USBD_IrqHandler(void); +/** + * \brief usb_audio_looprec Application entry point. + * + * Starts the driver and waits for an audio input stream to forward to the DAC. + */ +int main(void) +{ + volatile uint8_t usbConn = 0; + volatile uint8_t plyOn = 0, recOn = 0; + + printf("-- USB Device Fast Audio Source %s --\n\r", SOFTPACK_VERSION); + printf("-- %s\n\r", BOARD_NAME); + printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); + + /* If they are present, configure Vbus & Wake-up pins */ + PIO_InitializeInterrupts(0); + + /* Initialize all USB power (off) */ + USBPower_Configure(); + + /* Audio STREAM LED */ + LED_Configure(USBD_LEDOTHER); + + /* USB audio driver initialization */ + fastsource_init(); + + /* connect if needed */ + VBus_Configure(); + + fastsource_start(0x86); + + /* Infinite loop */ + while (1) + { + if (USBD_GetState() < USBD_STATE_CONFIGURED) + { + usbConn = 0; + continue; + } + if (plyOn) + { + if (isPlyActive == 0) + { + printf("plyE "); + plyOn = 0; + } + } + else if (isPlyActive) + { +#if 0 + /* Try to Start Reading the incoming audio stream */ + AUDDLoopRecDriver_Read(buffers[inBufferIndex], + AUDDLoopRecDriver_BYTESPERFRAME, + (TransferCallback) FrameReceived, + 0); // No optional argument + + printf("plyS "); + plyOn = 1; +#endif + } + if (recOn) + { + if (isRecActive == 0) + { + printf("recE "); + recOn = 0; + } + } + else if (isRecActive) + { + printf("recS "); + recOn = 1; + } + } +} +/** \endcond */ diff --git a/usb-fast-audio-source/obj/.empty_dir b/usb-fast-audio-source/obj/.empty_dir new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3