diff options
author | Harald Welte <laforge@gnumonks.org> | 2011-07-04 20:52:54 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-07-04 20:52:54 +0200 |
commit | 044ad7c3987460ede48ff27afd6bdb0ca05a0432 (patch) | |
tree | 924818cdb0d39ca08aec540d18da7bd406eaae8c /usb/common |
import at91lib from at91lib_20100901_softpack_1_9_v_1_0_svn_v1501120100901_softpack_1_9_v_1_0_svn_v15011
it's sad to see that atmel doesn't publish their svn repo or has
a centralized location or even puts proper version/release info
into the library itself
Diffstat (limited to 'usb/common')
78 files changed, 7079 insertions, 0 deletions
diff --git a/usb/common/audio/AUDControlInterfaceDescriptor.h b/usb/common/audio/AUDControlInterfaceDescriptor.h new file mode 100644 index 0000000..ada2f1e --- /dev/null +++ b/usb/common/audio/AUDControlInterfaceDescriptor.h @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definitions for using USB %audio control interfaces.
+///
+/// !!!Usage
+///
+/// -# When declaring a standard USB interface descriptor for an %audio control
+/// interface, use the "USB Audio control interface codes" constants.
+//------------------------------------------------------------------------------
+
+#ifndef AUDCONTROLINTERFACEDESCRIPTOR_H
+#define AUDCONTROLINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio control interface codes"
+///
+/// This page lists the class, subclass and protocol codes that a USB Audio
+/// Control interface descriptor should display.
+///
+/// !Codes
+/// - AUDControlInterfaceDescriptor_CLASS
+/// - AUDControlInterfaceDescriptor_SUBCLASS
+/// - AUDControlInterfaceDescriptor_PROTOCOL
+
+/// Class code for an audio control interface.
+#define AUDControlInterfaceDescriptor_CLASS 0x01
+
+/// Subclass code for an audio control interface.
+#define AUDControlInterfaceDescriptor_SUBCLASS 0x01
+
+/// Protocol code for an audio control interface.
+#define AUDControlInterfaceDescriptor_PROTOCOL 0x00
+//------------------------------------------------------------------------------
+
+#endif //#ifndef AUDCONTROLINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDDataEndpointDescriptor.h b/usb/common/audio/AUDDataEndpointDescriptor.h new file mode 100644 index 0000000..5963546 --- /dev/null +++ b/usb/common/audio/AUDDataEndpointDescriptor.h @@ -0,0 +1,104 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definition of the USB audio-specific data endpoint descriptor.
+///
+/// !!!Usage
+///
+/// -# Declare an AUDDataEndpointDescriptor instance as part of the
+/// configuration descriptors of a USB %audio %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDDATAENDPOINTDESCRIPTOR_H
+#define AUDDATAENDPOINTDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+/// Descriptor subtype for an Audio data endpoint.
+#define AUDDataEndpointDescriptor_SUBTYPE 0x01
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio Lock delay units"
+///
+/// This page lists the valid lock delay unit types.
+///
+/// !Units
+/// - AUDDataEndpointDescriptor_MILLISECONDS
+/// - AUDDataEndpointDescriptor_PCMSAMPLES
+
+/// Lock delay is expressed in milliseconds.
+#define AUDDataEndpointDescriptor_MILLISECONDS 1
+
+/// Lock delay is expressed in decoded PCM samples.
+#define AUDDataEndpointDescriptor_PCMSAMPLES 2
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Gives additional information about an USB endpoint used to transmit audio
+/// data to or from the host.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_ENDPOINT).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDDataEndpointDescriptor_SUBTYPE).
+ unsigned char bDescriptorSubType;
+ /// Indicates available controls and requirement on packet sizes.
+ unsigned char bmAttributes;
+ /// Indicates the units of the wLockDelay fields.
+ /// \sa "USB Audio Lock delay units"
+ unsigned char bLockDelayUnits;
+ /// Time it takes for the endpoint to lock its internal clock circuitry.
+ unsigned short wLockDelay;
+
+} __attribute__ ((packed)) AUDDataEndpointDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDDATAENDPOINTDESCRIPTOR_H
diff --git a/usb/common/audio/AUDDeviceDescriptor.h b/usb/common/audio/AUDDeviceDescriptor.h new file mode 100644 index 0000000..f33523a --- /dev/null +++ b/usb/common/audio/AUDDeviceDescriptor.h @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Fields values for an USB Audio %device descriptor.
+///
+/// !!!Usage
+///
+/// -# When declaring the %device descriptor of a USB %audio %device, use
+/// "USB Audio device descriptor values" defined here.
+//------------------------------------------------------------------------------
+
+#ifndef AUDDEVICEDESCRIPTOR_H
+#define AUDDEVICEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio device descriptor values"
+///
+/// This page lists the class, subclass & protocol codes that a USB audio
+/// device should display in its device descriptor.
+///
+/// !Codes
+/// - AUDDeviceDescriptor_CLASS
+/// - AUDDeviceDescriptor_SUBCLASS
+/// - AUDDeviceDescriptor_PROTOCOL
+
+/// Class code for a USB audio device.
+#define AUDDeviceDescriptor_CLASS 0x00
+
+/// Subclass code for a USB audio device.
+#define AUDDeviceDescriptor_SUBCLASS 0x00
+
+/// Protocol code for a USB audio device.
+#define AUDDeviceDescriptor_PROTOCOL 0x00
+//------------------------------------------------------------------------------
+
+#endif //#ifndef AUDDEVICEDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDEndpointDescriptor.h b/usb/common/audio/AUDEndpointDescriptor.h new file mode 100644 index 0000000..9dce6ab --- /dev/null +++ b/usb/common/audio/AUDEndpointDescriptor.h @@ -0,0 +1,86 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Re-definition of the standard USB endpoint descriptor with two additional
+/// fields. This is required by the USB audio 1.00 specification.
+///
+/// !!!Usage
+///
+/// -# Declare an AUDEndpointDescriptor instance as part of the configuration
+/// descriptors of an USB %audio %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDENDPOINTDESCRIPTOR_H
+#define AUDENDPOINTDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Modified endpoint descriptor with two additional fields, with are
+/// USB audio specific.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of the descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (USBGenericDescriptor_ENDPOINT).
+ unsigned char bDescriptorType;
+ /// Address and direction of the endpoint.
+ unsigned char bEndpointAddress;
+ /// Endpoint type and additional characteristics (for isochronous endpoints).
+ unsigned char bmAttributes;
+ /// Maximum packet size (in bytes) of the endpoint.
+ unsigned short wMaxPacketSize;
+ /// Polling rate of the endpoint.
+ unsigned char bInterval;
+ /// Refresh rate for a feedback endpoint.
+ unsigned char bRefresh;
+ /// Address of the associated feedback endpoint if any.
+ unsigned char bSyncAddress;
+
+} __attribute__ ((packed)) AUDEndpointDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDENDPOINTDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDFeatureUnitDescriptor.h b/usb/common/audio/AUDFeatureUnitDescriptor.h new file mode 100644 index 0000000..a1ba45f --- /dev/null +++ b/usb/common/audio/AUDFeatureUnitDescriptor.h @@ -0,0 +1,116 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Class for manipulating USB %audio feature unit descriptor.
+///
+/// !!!Usage
+///
+/// -# Declare an AUDFeatureUnitDescriptor instance as part of the
+/// configuration descriptors returned by a USB %audio %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDFEATUREUNITDESCRIPTOR_H
+#define AUDFEATUREUNITDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio Channel controls"
+///
+/// This page lists the available controls for each channel of the audio
+/// interface. Each channel can have any control combination; simply perform
+/// a bitwise OR ('|') to combine several values.
+///
+/// !Controls
+/// -# AUDFeatureUnitDescriptor_MUTE
+/// -# AUDFeatureUnitDescriptor_VOLUME
+/// -# AUDFeatureUnitDescriptor_BASS
+/// -# AUDFeatureUnitDescriptor_MID
+/// -# AUDFeatureUnitDescriptor_TREBLE
+
+/// Channel mute control.
+#define AUDFeatureUnitDescriptor_MUTE (1 << 0)
+
+/// Channel volume control.
+#define AUDFeatureUnitDescriptor_VOLUME (1 << 1)
+
+/// Channel bass control.
+#define AUDFeatureUnitDescriptor_BASS (1 << 2)
+
+/// Channel middle control.
+#define AUDFeatureUnitDescriptor_MID (1 << 3)
+
+/// Channel treble control.
+#define AUDFeatureUnitDescriptor_TREBLE (1 << 4)
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Describes available controls for each channel of the unit or terminal
+/// it is connected to. This type must be augmented with the relevant number
+/// of bmaControls fields and the iFeature field.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDGenericDescriptor_FEATURE).
+ unsigned char bDescriptorSubType;
+ /// Identifier of this feature unit.
+ unsigned char bUnitID;
+ /// Identifier of the unit or terminal this feature unit is connected to.
+ unsigned char bSourceID;
+ /// Size in bytes of a channel controls field.
+ unsigned char bControlSize;
+
+} __attribute__ ((packed)) AUDFeatureUnitDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDFEATUREUNITDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDFeatureUnitRequest.c b/usb/common/audio/AUDFeatureUnitRequest.c new file mode 100644 index 0000000..bc6c642 --- /dev/null +++ b/usb/common/audio/AUDFeatureUnitRequest.c @@ -0,0 +1,60 @@ +/* ----------------------------------------------------------------------------
+ * 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 "AUDFeatureUnitRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the control selector value indicating the target of a Feature Unit
+/// request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \sa "USB Audio Control selector values"
+//------------------------------------------------------------------------------
+unsigned char AUDFeatureUnitRequest_GetControl(const USBGenericRequest *request)
+{
+ return ((USBGenericRequest_GetValue(request) >> 8) & 0xFF);
+}
+
+//------------------------------------------------------------------------------
+/// Returns the channel number of a Feature unit which should be altered by the
+/// given request.
+/// \param request Pointer to a USBGenericRequest instance.
+//------------------------------------------------------------------------------
+unsigned char AUDFeatureUnitRequest_GetChannel(const USBGenericRequest *request)
+{
+ return (USBGenericRequest_GetValue(request) & 0xFF);
+}
+
diff --git a/usb/common/audio/AUDFeatureUnitRequest.h b/usb/common/audio/AUDFeatureUnitRequest.h new file mode 100644 index 0000000..289f598 --- /dev/null +++ b/usb/common/audio/AUDFeatureUnitRequest.h @@ -0,0 +1,81 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definitions of constants and methods for using USB %audio requests
+/// targetted at a Feature unit.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# Use AUDFeatureUnitRequest_GetControl to determine which control
+/// shall be tweaked following a host request.
+// -# Use AUDFeatureUnitRequest_GetChannel to identify the channel which
+// will have its control altered.
+//------------------------------------------------------------------------------
+
+#ifndef AUDFEATUREUNITREQUEST_H
+#define AUDFEATUREUNITREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+
+//------------------------------------------------------------------------------
+// Constants
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio Control selector values"
+///
+/// This page lists the available control selectors for a Feature Unit request.
+///
+/// !Controls
+/// - AUDFeatureUnitRequest_MUTE
+
+/// Mute control selector.
+#define AUDFeatureUnitRequest_MUTE 0x01
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+extern unsigned char AUDFeatureUnitRequest_GetControl(
+ const USBGenericRequest *request);
+extern unsigned char AUDFeatureUnitRequest_GetChannel(
+ const USBGenericRequest *request);
+
+#endif //#ifndef AUDFEATUREUNITREQUEST_H
+
diff --git a/usb/common/audio/AUDFormatTypeOneDescriptor.h b/usb/common/audio/AUDFormatTypeOneDescriptor.h new file mode 100644 index 0000000..0aa6b63 --- /dev/null +++ b/usb/common/audio/AUDFormatTypeOneDescriptor.h @@ -0,0 +1,101 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definitions for using USB %audio format type I descriptors.
+///
+/// !!!Usage
+///
+/// -# Declare an instance of AUDFormatTypeOneDescriptor as part of the
+/// configuration descriptors of an audio device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDFORMATTYPEONEDESCRIPTOR_H
+#define AUDFORMATTYPEONEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+/// Format type for a format type I descriptor.
+#define AUDFormatTypeOneDescriptor_FORMATTYPEONE 0x01
+
+/// AUDFormatTypeOneDescriptor_PCM - PCM format.
+#define AUDFormatTypeOneDescriptor_PCM 0x0001
+
+/// Indicates the sampling frequency can have any value in the provided range.
+#define AUDFormatTypeOneDescriptor_CONTINUOUS 0
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Describes an audio data stream that is constructed on a sample-by-sample
+/// basis. This type must be augmented with either the continuous sampling
+/// frequency range (if bSamFreqType = <AUDFormatTypeOneDescriptor_CONTINUOUS>)
+/// or with an array containing the possible discrete frequencies.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDStreamingInterfaceDescriptor_FORMATTYPE).
+ unsigned char bDescriptorSubType;
+ /// Format type (AUDFormatTypeOneDescriptor_FORMATTYPEONE).
+ unsigned char bFormatType;
+ /// Number of physical channels in the audio stream.
+ unsigned char bNrChannels;
+ /// Number of bytes occupied by one audio subframe.
+ unsigned char bSubFrameSize;
+ /// Number of bits effectively used in an audio subframe.
+ unsigned char bBitResolution;
+ /// Number of supported discrete sampling frequencies, or
+ /// AUDFormatTypeOneDescriptor_CONTINUOUS.
+ unsigned char bSamFreqType;
+
+} __attribute__ ((packed)) AUDFormatTypeOneDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDFORMATTYPEONEDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDGenericDescriptor.h b/usb/common/audio/AUDGenericDescriptor.h new file mode 100644 index 0000000..8758a92 --- /dev/null +++ b/usb/common/audio/AUDGenericDescriptor.h @@ -0,0 +1,121 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Constants for manipulating USB audio-specific descriptors.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# When declaring an Audio-specific descriptor, use the descriptor types
+/// and subtypes defined in this unit (see "USB Audio descriptor types"
+/// and "USB Audio descriptor subtypes").
+//------------------------------------------------------------------------------
+
+#ifndef AUDGENERICDESCRIPTOR_H
+#define AUDGENERICDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio descriptor types"
+///
+/// This page lists the available types for USB audio-specific descriptors.
+///
+/// !Types
+/// - AUDGenericDescriptor_DEVICE
+/// - AUDGenericDescriptor_CONFIGURATION
+/// - AUDGenericDescriptor_STRING
+/// - AUDGenericDescriptor_INTERFACE
+/// - AUDGenericDescriptor_ENDPOINT
+
+/// Descriptor gives detail about the whole device.
+#define AUDGenericDescriptor_DEVICE 0x21
+
+/// Descriptor gives detail about a configuration.
+#define AUDGenericDescriptor_CONFIGURATION 0x22
+
+/// Descriptor gives detail about a string.
+#define AUDGenericDescriptor_STRING 0x23
+
+/// Descriptor gives detail about an interface.
+#define AUDGenericDescriptor_INTERFACE 0x24
+
+/// Descriptor gives detail about an endpoint.
+#define AUDGenericDescriptor_ENDPOINT 0x25
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio descriptor subtypes"
+///
+/// This page lists the possible subtypes for USB audio-specific descriptors.
+///
+/// !Subtypes
+/// - AUDGenericDescriptor_HEADER
+/// - AUDGenericDescriptor_INPUTTERMINAL
+/// - AUDGenericDescriptor_OUTPUTTERMINAL
+/// - AUDGenericDescriptor_MIXERUNIT
+/// - AUDGenericDescriptor_SELECTORUNIT
+/// - AUDGenericDescriptor_FEATUREUNIT
+/// - AUDGenericDescriptor_PROCESSINGUNIT
+/// - AUDGenericDescriptor_EXTENSIONUNIT
+
+/// Header descriptor subtype.
+#define AUDGenericDescriptor_HEADER 0x01
+
+/// Input terminal descriptor subtype.
+#define AUDGenericDescriptor_INPUTTERMINAL 0x02
+
+/// Output terminal descriptor subtype.
+#define AUDGenericDescriptor_OUTPUTTERMINAL 0x03
+
+/// Mixer unit descriptor subtype.
+#define AUDGenericDescriptor_MIXERUNIT 0x04
+
+/// Selector unit descriptor subtype.
+#define AUDGenericDescriptor_SELECTORUNIT 0x05
+
+/// Feature unit descriptor subtype.
+#define AUDGenericDescriptor_FEATUREUNIT 0x06
+
+/// Processing unit descriptor subtype.
+#define AUDGenericDescriptor_PROCESSINGUNIT 0x07
+
+///Extension unit descriptor subtype.
+#define AUDGenericDescriptor_EXTENSIONUNIT 0x08
+//------------------------------------------------------------------------------
+
+#endif //#ifndef AUDGENERICDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDGenericRequest.c b/usb/common/audio/AUDGenericRequest.c new file mode 100644 index 0000000..c9c6e87 --- /dev/null +++ b/usb/common/audio/AUDGenericRequest.c @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------------------
+ * 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 "AUDGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the ID of the unit or terminal targetted by an USB audio request.
+/// \param request Pointer to a USBGenericRequest instance.
+//------------------------------------------------------------------------------
+unsigned char AUDGenericRequest_GetEntity(const USBGenericRequest *request)
+{
+ return ((USBGenericRequest_GetIndex(request) >> 8) & 0xFF);
+}
+
+//------------------------------------------------------------------------------
+/// Returns the ID of the interface targetted by an USB audio request.
+/// \param request Pointer to a USBGenericRequest instance.
+//------------------------------------------------------------------------------
+unsigned char AUDGenericRequest_GetInterface(const USBGenericRequest *request)
+{
+ return (USBGenericRequest_GetIndex(request) & 0xFF);
+}
+
diff --git a/usb/common/audio/AUDGenericRequest.h b/usb/common/audio/AUDGenericRequest.h new file mode 100644 index 0000000..b0b8527 --- /dev/null +++ b/usb/common/audio/AUDGenericRequest.h @@ -0,0 +1,94 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Constants for using USB %audio SETUP requests.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# After receiving an Audio request from the host, use
+/// AUDGenericRequest_GetEntity to determine the target Unit or Terminal.
+/// -# After receiving an Audio request from the host, use
+/// AUDGenericRequest_GetInterface to know which interface is referenced.
+//------------------------------------------------------------------------------
+
+#ifndef AUDGENERICREQUEST_H
+#define AUDGENERICREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio request codes"
+///
+/// This page lists the codes of the existing Audio requests.
+///
+/// !Requests
+/// - AUDGenericRequest_SETCUR
+/// - AUDGenericRequest_GETCUR
+
+/// SET_CUR request code.
+#define AUDGenericRequest_SETCUR 0x01
+
+/// GET_CUR request code.
+#define AUDGenericRequest_GETCUR 0x81
+
+/// GET_MIN request code.
+#define AUDGenericRequest_GETMIN 0x82
+
+/// GET_MAX request code.
+#define AUDGenericRequest_GETMAX 0x83
+
+/// GET_RES request code.
+#define AUDGenericRequest_GETRES 0x84
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char AUDGenericRequest_GetEntity(
+ const USBGenericRequest *request);
+extern unsigned char AUDGenericRequest_GetInterface(
+ const USBGenericRequest *request);
+
+#endif //#ifndef AUDGENERICREQUEST_H
+
diff --git a/usb/common/audio/AUDHeaderDescriptor.h b/usb/common/audio/AUDHeaderDescriptor.h new file mode 100644 index 0000000..ca30a0b --- /dev/null +++ b/usb/common/audio/AUDHeaderDescriptor.h @@ -0,0 +1,100 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Class for manipulating USB %audio header descriptors.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# Declare a AUDHeaderDescriptor as part of the configuration
+/// descriptors of the %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDHEADERDESCRIPTOR_H
+#define AUDHEADERDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio class releases"
+/// This page lists the existing versions of the Audio class specification.
+///
+///
+/// !Versions
+/// - AUDHeaderDescriptor_AUD1_00
+
+/// Indentifies the USB audio specification release 1.00.
+#define AUDHeaderDescriptor_AUD1_00 0x0100
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Groups the various audio interfaces to display one single function to
+/// the USB host. Subclass this structure to add a particular number of
+/// slave interface descriptors.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDGenericDescriptor_HEADER).
+ unsigned char bDescriptorSubType;
+ /// Audio class release number in BCD format
+ /// \sa "USB Audio class releases"
+ unsigned short bcdADC;
+ /// Length of all descriptors used to qualify the Audio Control interface.
+ unsigned short wTotalLength;
+ /// Number of Streaming interfaces contained in this collection.
+ unsigned char bInCollection;
+
+} __attribute__ ((packed)) AUDHeaderDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDHEADERDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDInputTerminalDescriptor.h b/usb/common/audio/AUDInputTerminalDescriptor.h new file mode 100644 index 0000000..e0895fb --- /dev/null +++ b/usb/common/audio/AUDInputTerminalDescriptor.h @@ -0,0 +1,139 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Class for manipulating input terminal descriptors.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# Declare an AUDInputTerminalDescriptor instance as part of the
+/// configuration of the %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDINPUTTERMINALDESCRIPTOR_H
+#define AUDINPUTTERMINALDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio Input terminal types"
+///
+/// This page lists the available types for an Input terminal.
+///
+/// !Types
+///
+/// - AUDInputTerminalDescriptor_USBSTREAMING
+/// - AUDInputTerminalDescriptor_MICROPHONE
+/// - AUDInputTerminalDescriptor_SPEAKERPHONE
+/// - AUDInputTerminalDescriptor_LINEIN
+
+/// A terminal receiving its data from a USB isochronous endpoint.
+#define AUDInputTerminalDescriptor_USBSTREAMING 0x0101
+/// A terminal sampling data from a microphone.
+#define AUDInputTerminalDescriptor_MICROPHONE 0x0201
+/// A terminal sampling data from a Handset In.
+#define AUDInputTerminalDescriptor_HANDSETIN 0x0401
+/// A terminal sampling data from a speakerphone
+#define AUDInputTerminalDescriptor_SPEAKERPHONE 0x0403
+/// A terminal sampling data from a Phone Line In.
+#define AUDInputTerminalDescriptor_LINEIN 0x0501
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio Channel spatial locations"
+///
+/// This page lists the possible spatial locations for audio channels.
+///
+/// !Locations
+///
+/// - AUDInputTerminalDescriptor_LEFTFRONT
+/// - AUDInputTerminalDescriptor_RIGHTFRONT
+/// - AUDInputTerminalDescriptor_CENTERFRONT
+
+/// Front left channel.
+#define AUDInputTerminalDescriptor_LEFTFRONT (1 << 0)
+
+/// Front right channel.
+#define AUDInputTerminalDescriptor_RIGHTFRONT (1 << 1)
+
+/// Front center channel.
+#define AUDInputTerminalDescriptor_CENTERFRONT (1 << 2)
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Describes an input of a USB audio device.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDGenericDescriptor_INPUTTERMINAL).
+ unsigned char bDescriptorSubType;
+ /// ID of the terminal in the audio function.
+ unsigned char bTerminalID;
+ /// Terminal type.
+ /// \sa "USB Audio Input terminal types"
+ unsigned short wTerminalType;
+ /// ID of the output terminal to which this input terminal is associated.
+ unsigned char bAssocTerminal;
+ /// Number of logical output channels in this terminal.
+ unsigned char bNrChannels;
+ /// Spatial configuration of the logical channels.
+ unsigned short wChannelConfig;
+ /// Index of a string descriptor for the first logical channel.
+ unsigned char iChannelNames;
+ /// Index of a string descriptor for this terminal.
+ unsigned char iTerminal;
+
+} __attribute__ ((packed)) AUDInputTerminalDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDINPUTTERMINALDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDOutputTerminalDescriptor.h b/usb/common/audio/AUDOutputTerminalDescriptor.h new file mode 100644 index 0000000..6ba3156 --- /dev/null +++ b/usb/common/audio/AUDOutputTerminalDescriptor.h @@ -0,0 +1,112 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definition of a class for using USB %audio output terminal descriptors.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# Declare a AUDOutputTerminalDescriptor instance as part of the
+/// configuration descriptors of a USB %audio %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDOUTPUTTERMINALDESCRIPTOR_H
+#define AUDOUTPUTTERMINALDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio Output terminal types"
+///
+/// This page lists the available types for an output terminal.
+///
+/// !Types
+/// - AUDOutputTerminalDescriptor_USBTREAMING
+/// - AUDOutputTerminalDescriptor_SPEAKER
+/// - AUDOutputTerminalDescriptor_HANDSETOUT
+/// - AUDOutputTerminalDescriptor_LINEOUT
+
+/// A terminal sending data through USB isochronous endpoint.
+#define AUDOutputTerminalDescriptor_USBTREAMING 0x0101
+/// A terminal sending data to a USB host through an Isochronous endpoint.
+#define AUDOutputTerminalDescriptor_SPEAKER 0x0301
+/// A terminal sending data to Handset Out.
+#define AUDOutputTerminalDescriptor_HANDSETOUT 0x0401
+/// A terminal sending data to Phone Line Out.
+#define AUDOutputTerminalDescriptor_LINEOUT 0x0501
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// \typedef AUDOutputTerminalDescriptor
+/// Describes an output of the USB audio function.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDGenericDescriptor_OUTPUTTERMINAL).
+ unsigned char bDescriptorSubType;
+ /// Identifier for this terminal.
+ unsigned char bTerminalID;
+ /// Terminal type.
+ /// \sa "USB Audio Output terminal types"
+ unsigned short wTerminalType;
+ /// Identifier of the associated input terminal.
+ unsigned char bAssocTerminal;
+ /// Identifier of the unit or terminal to which this terminal is connected.
+ unsigned char bSourceID;
+ /// Index of a string descriptor for this terminal.
+ unsigned char iTerminal;
+
+} __attribute__ ((packed)) AUDOutputTerminalDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDOUTPUTTERMINALDESCRIPTOR_H
+
diff --git a/usb/common/audio/AUDStreamingInterfaceDescriptor.h b/usb/common/audio/AUDStreamingInterfaceDescriptor.h new file mode 100644 index 0000000..80c9cfd --- /dev/null +++ b/usb/common/audio/AUDStreamingInterfaceDescriptor.h @@ -0,0 +1,129 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definition of a class for manipulating USB %audio streaming interface
+/// descriptors.
+///
+/// !!!Usage
+///
+/// - For a USB %device:
+/// -# Declare an AUDStreamingInterfaceDescriptor instance as part of the
+/// configuration descriptors returned by a USB %audio %device.
+//------------------------------------------------------------------------------
+
+#ifndef AUDSTREAMINGINTERFACEDESCRIPTOR_H
+#define AUDSTREAMINGINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio streaming interface codes"
+///
+/// This page lists the class, subclass and protocol codes that an Audio
+/// Streaming interface should display in its descriptor.
+///
+/// !Codes
+/// - AUDStreamingInterfaceDescriptor_CLASS
+/// - AUDStreamingInterfaceDescriptor_SUBCLASS
+/// - AUDStreamingInterfaceDescriptor_PROTOCOL
+
+/// Class code for an USB audio streaming interface.
+#define AUDStreamingInterfaceDescriptor_CLASS 0x01
+
+/// Subclass code for an audio streaming interface.
+#define AUDStreamingInterfaceDescriptor_SUBCLASS 0x02
+
+/// Protocol code for an audio streaming interface.
+#define AUDStreamingInterfaceDescriptor_PROTOCOL 0x00
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Audio streaming descriptor subtypes"
+///
+/// This page lists the possible subtypes for audio-specific descriptor appended
+/// to an Audio Streaming interface.
+///
+/// !Subtypes
+/// - AUDStreamingInterfaceDescriptor_GENERAL
+/// - AUDStreamingInterfaceDescriptor_FORMATTYPE
+/// - AUDStreamingInterfaceDescriptor_FORMATSPECIFIC
+
+/// General descriptor subtype.
+#define AUDStreamingInterfaceDescriptor_GENERAL 0x01
+
+/// Format type descriptor subtype.
+#define AUDStreamingInterfaceDescriptor_FORMATTYPE 0x02
+
+/// Format specific descriptor subtype.
+#define AUDStreamingInterfaceDescriptor_FORMATSPECIFIC 0x03
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Provides additional information about an audio streaming interface to
+/// the USB host.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (AUDGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (AUDStreamingInterfaceDescriptor_GENERAL).
+ unsigned char bDescriptorSubType;
+ /// Terminal ID to which the interface is connected.
+ unsigned char bTerminalLink;
+ /// Delay introduced by the data path, in number of frames.
+ unsigned char bDelay;
+ /// Audio data format used by this interface.
+ unsigned short wFormatTag;
+
+} __attribute__ ((packed)) AUDStreamingInterfaceDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef AUDSTREAMINGINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/audio/audio.dir b/usb/common/audio/audio.dir new file mode 100644 index 0000000..2bc574f --- /dev/null +++ b/usb/common/audio/audio.dir @@ -0,0 +1,40 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+/// !!!Purpose
+///
+/// This directory contains definitions, structures and funcions related to the
+/// USB Audio Class specification. They can be divided into two groups:
+/// - Audio-specific descriptors, prefixed with AUD and suffixed with
+/// Descriptor.
+/// - Audio-specific requests, prefixed with AUD and suffixed with Request.
+//------------------------------------------------------------------------------
+
diff --git a/usb/common/cdc/CDCAbstractControlManagementDescriptor.h b/usb/common/cdc/CDCAbstractControlManagementDescriptor.h new file mode 100644 index 0000000..943204c --- /dev/null +++ b/usb/common/cdc/CDCAbstractControlManagementDescriptor.h @@ -0,0 +1,104 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating CDC abstract control management
+ descriptors.
+
+ !!!Usage
+
+ Should be included in a list of USB configuration descriptors.
+*/
+
+#ifndef CDCABSTRACTCONTROLMANAGEMENTDESCRIPTOR_H
+#define CDCABSTRACTCONTROLMANAGEMENTDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC ACM Capabilities"
+/// This page lists the capabilities of the CDC ACM.
+///
+/// !Capabilities
+/// - CDCAbstractControlManagementDescriptor_COMMFEATURE
+/// - CDCAbstractControlManagementDescriptor_LINE
+/// - CDCAbstractControlManagementDescriptor_SENDBREAK
+/// - CDCAbstractControlManagementDescriptor_NETWORKCONNECTION
+
+/// Device supports the request combination of SetCommFeature, ClearCommFeature
+/// and GetCommFeature.
+#define CDCAbstractControlManagementDescriptor_COMMFEATURE (1 << 0)
+/// Device supports the request combination of SetLineCoding, GetLineCoding and
+/// SetControlLineState.
+#define CDCAbstractControlManagementDescriptor_LINE (1 << 1)
+/// Device supports the SendBreak request.
+#define CDCAbstractControlManagementDescriptor_SENDBREAK (1 << 2)
+/// Device supports the NetworkConnection notification.
+#define CDCAbstractControlManagementDescriptor_NETWORKCONNECTION (1 << 3)
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Describes the command supported by the communication interface class
+/// with the Abstract Control Model subclass code.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of this descriptor in bytes.
+ unsigned char bFunctionLength;
+ /// Descriptor type (CDCDescriptors_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (CDCDescriptors_ABSTRACTCONTROLMANAGEMENT).
+ unsigned char bDescriptorSubtype;
+ /// Configuration capabilities.
+ /// \sa "CDC ACM Capabilities".
+ unsigned char bmCapabilities;
+
+} __attribute__ ((packed)) CDCAbstractControlManagementDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef CDCABSTRACTCONTROLMANAGEMENTDESCRIPTOR_H
+
diff --git a/usb/common/cdc/CDCCallManagementDescriptor.h b/usb/common/cdc/CDCCallManagementDescriptor.h new file mode 100644 index 0000000..191ff61 --- /dev/null +++ b/usb/common/cdc/CDCCallManagementDescriptor.h @@ -0,0 +1,97 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for managing CDC call management descriptors.
+
+ !!!Usage
+
+ Should be included in a list of configuration descriptors for a USB
+ device.
+*/
+
+#ifndef CDCCALLMANAGEMENTDESCRIPTOR_H
+#define CDCCALLMANAGEMENTDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC CallManagement Capabilities"
+/// This page lists CDC CallManagement Capabilities.
+///
+/// !Capabilities
+/// - CDCCallManagementDescriptor_SELFCALLMANAGEMENT
+/// - CDCCallManagementDescriptor_DATACALLMANAGEMENT
+
+/// Device handles call management itself.
+#define CDCCallManagementDescriptor_SELFCALLMANAGEMENT (1 << 0)
+/// Device can exchange call management information over a Data class interface.
+#define CDCCallManagementDescriptor_DATACALLMANAGEMENT (1 << 1)
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Describes the processing of calls for the communication class interface.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of this descriptor in bytes.
+ unsigned char bFunctionLength;
+ /// Descriptor type (CDCDescriptors_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor sub-type (CDCDescriptors_CALLMANAGEMENT).
+ unsigned char bDescriptorSubtype;
+ /// Configuration capabilities ("CDC CallManagement Capabilities").
+ unsigned char bmCapabilities;
+ /// Interface number of the data class interface used for call management
+ /// (optional).
+ unsigned char bDataInterface;
+
+} __attribute__ ((packed)) CDCCallManagementDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef CDCCALLMANAGEMENTDESCRIPTOR_H
+
diff --git a/usb/common/cdc/CDCCommunicationInterfaceDescriptor.h b/usb/common/cdc/CDCCommunicationInterfaceDescriptor.h new file mode 100644 index 0000000..aa13915 --- /dev/null +++ b/usb/common/cdc/CDCCommunicationInterfaceDescriptor.h @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of several constants used when declaring a CDC communication
+ class interface descriptor.
+*/
+
+#ifndef CDCCOMMUNICATIONINTERFACEDESCRIPTOR_H
+#define CDCCOMMUNICATIONINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Communication Interface Values"
+/// This page lists the values for CDC Communication Interface Descriptor.
+///
+/// !Values
+/// - CDCCommunicationInterfaceDescriptor_CLASS
+/// - CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL
+/// - CDCCommunicationInterfaceDescriptor_NOPROTOCOL
+
+/// Interface class code for a CDC communication class interface.
+#define CDCCommunicationInterfaceDescriptor_CLASS 0x02
+/// Interface subclass code for an Abstract Control Model interface descriptor.
+#define CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL 0x02
+/// Interface protocol code when a CDC communication interface does not
+/// implemenent any particular protocol.
+#define CDCCommunicationInterfaceDescriptor_NOPROTOCOL 0x00
+//------------------------------------------------------------------------------
+
+#endif //#ifndef CDCCOMMUNICATIONINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/cdc/CDCDataInterfaceDescriptor.h b/usb/common/cdc/CDCDataInterfaceDescriptor.h new file mode 100644 index 0000000..640f8dc --- /dev/null +++ b/usb/common/cdc/CDCDataInterfaceDescriptor.h @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions of constants used when declaring a CDC data class interface
+ descriptor.
+*/
+
+#ifndef CDCDATAINTERFACEDESCRIPTOR_H
+#define CDCDATAINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Data Interface Values"
+/// This page lists the values for CDC Data Interface Descriptor.
+///
+/// !Values
+/// - CDCDataInterfaceDescriptor_CLASS
+/// - CDCDataInterfaceDescriptor_SUBCLASS
+/// - CDCDataInterfaceDescriptor_NOPROTOCOL
+
+/// Interface class code for a data class interface.
+#define CDCDataInterfaceDescriptor_CLASS 0x0A
+/// Interface subclass code for a data class interface.
+#define CDCDataInterfaceDescriptor_SUBCLASS 0x00
+/// Protocol code for a data class interface which does not implement any
+/// particular protocol.
+#define CDCDataInterfaceDescriptor_NOPROTOCOL 0x00
+//------------------------------------------------------------------------------
+
+#endif //#ifndef CDCDATAINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/cdc/CDCDeviceDescriptor.h b/usb/common/cdc/CDCDeviceDescriptor.h new file mode 100644 index 0000000..b1bc177 --- /dev/null +++ b/usb/common/cdc/CDCDeviceDescriptor.h @@ -0,0 +1,64 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of several constants used when declaring USB CDC device
+ descriptors.
+*/
+
+#ifndef CDCDEVICEDESCRIPTOR_H
+#define CDCDEVICEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Device Descriptor Values"
+/// This page lists the values for CDC Device Descriptor.
+///
+/// !Values
+/// - CDCDeviceDescriptor_CLASS
+/// - CDCDeviceDescriptor_SUBCLASS
+/// - CDCDeviceDescriptor_PROTOCOL
+
+/// Device class code when using the CDC class.
+#define CDCDeviceDescriptor_CLASS 0x02
+/// Device subclass code when using the CDC class.
+#define CDCDeviceDescriptor_SUBCLASS 0x00
+/// Device protocol code when using the CDC class.
+#define CDCDeviceDescriptor_PROTOCOL 0x00
+//------------------------------------------------------------------------------
+
+#endif //#ifndef CDCDEVICEDESCRIPTOR_H
+
diff --git a/usb/common/cdc/CDCGenericDescriptor.h b/usb/common/cdc/CDCGenericDescriptor.h new file mode 100644 index 0000000..3d93656 --- /dev/null +++ b/usb/common/cdc/CDCGenericDescriptor.h @@ -0,0 +1,91 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of several constants for declaring CDC descriptors.
+*/
+
+#ifndef CDCGENERICDESCRIPTOR_H
+#define CDCGENERICDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Specification Release Numbers"
+/// This page list the CDC Spec. Release Numbers.
+///
+/// !Numbers
+/// - CDCGenericDescriptor_CDC1_10
+
+/// Identify CDC specification version 1.10.
+#define CDCGenericDescriptor_CDC1_10 0x0110
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Descriptro Types"
+/// This page lists CDC descriptor types.
+///
+/// !Types
+/// - CDCGenericDescriptor_INTERFACE
+/// - CDCGenericDescriptor_ENDPOINT
+
+///Indicates that a CDC descriptor applies to an interface.
+#define CDCGenericDescriptor_INTERFACE 0x24
+/// Indicates that a CDC descriptor applies to an endpoint.
+#define CDCGenericDescriptor_ENDPOINT 0x25
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Descriptor Subtypes"
+/// This page lists CDC descriptor sub types
+///
+/// !Types
+/// - CDCGenericDescriptor_HEADER
+/// - CDCGenericDescriptor_CALLMANAGEMENT
+/// - CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT
+/// - CDCGenericDescriptor_UNION
+
+/// Header functional descriptor subtype.
+#define CDCGenericDescriptor_HEADER 0x00
+/// Call management functional descriptor subtype.
+#define CDCGenericDescriptor_CALLMANAGEMENT 0x01
+/// Abstract control management descriptor subtype.
+#define CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT 0x02
+/// Union descriptor subtype.
+#define CDCGenericDescriptor_UNION 0x06
+//------------------------------------------------------------------------------
+
+#endif //#ifndef CDCGENERICDESCRIPTOR_H
+
diff --git a/usb/common/cdc/CDCGenericRequest.h b/usb/common/cdc/CDCGenericRequest.h new file mode 100644 index 0000000..d6abd0b --- /dev/null +++ b/usb/common/cdc/CDCGenericRequest.h @@ -0,0 +1,63 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Various definitions used for characterizing USB CDC requests.
+*/
+
+#ifndef CDCGENERICREQUEST_H
+#define CDCGENERICREQUEST_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC Request Codes"
+/// This page lists USB CDC Request Codes.
+///
+/// !Codes
+/// - CDCGenericRequest_SETLINECODING
+/// - CDCGenericRequest_GETLINECODING
+/// - CDCGenericRequest_SETCONTROLLINESTATE
+
+/// SetLineCoding request code.
+#define CDCGenericRequest_SETLINECODING 0x20
+/// GetLineCoding request code.
+#define CDCGenericRequest_GETLINECODING 0x21
+/// SetControlLineState request code.
+#define CDCGenericRequest_SETCONTROLLINESTATE 0x22
+//------------------------------------------------------------------------------
+
+#endif //#ifndef CDCGENERICREQUEST_H
+
diff --git a/usb/common/cdc/CDCHeaderDescriptor.h b/usb/common/cdc/CDCHeaderDescriptor.h new file mode 100644 index 0000000..b04926f --- /dev/null +++ b/usb/common/cdc/CDCHeaderDescriptor.h @@ -0,0 +1,77 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of the CDCHeaderDescriptor class.
+
+ !!!Usage
+
+ Should be included in a USB configuration descriptor.
+*/
+
+#ifndef CDCHEADERDESCRIPTOR_H
+#define CDCHEADERDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Marks the beginning of the concatenated set of functional descriptors
+/// for the interface.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of this descriptor in bytes.
+ unsigned char bFunctionLength;
+ /// Descriptor type (CDCDescriptors_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor sub-type (CDCDescriptors_HEADER).
+ unsigned char bDescriptorSubtype;
+ /// USB CDC specification release number.
+ unsigned short bcdCDC;
+
+} __attribute__ ((packed)) CDCHeaderDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef CDCHEADERDESCRIPTOR_H
+
+
diff --git a/usb/common/cdc/CDCLineCoding.c b/usb/common/cdc/CDCLineCoding.c new file mode 100644 index 0000000..4223fec --- /dev/null +++ b/usb/common/cdc/CDCLineCoding.c @@ -0,0 +1,78 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: CDCLineCoding
+
+ About: Purpose
+ Implementation of the CDCLineCoding class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "CDCLineCoding.h"
+#include <utility/assert.h>
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Initializes the bitrate, number of stop bits, parity checking and
+/// number of data bits of a CDCLineCoding object.
+/// \param lineCoding Pointer to a CDCLineCoding instance.
+/// \param bitrate Bitrate of the virtual COM connection.
+/// \param stopbits Number of stop bits ("CDC LineCoding StopBits").
+/// \param parity Parity check type ("CDC LineCoding ParityChecking").
+/// \param databits Number of data bits.
+//------------------------------------------------------------------------------
+void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
+ unsigned int bitrate,
+ unsigned char stopbits,
+ unsigned char parity,
+ unsigned char databits)
+{
+ ASSERT(stopbits <= CDCLineCoding_TWOSTOPBITS,
+ "CDCLineCoding_Initialize: Invalid stopbits value (%d)\n\r",
+ stopbits);
+ ASSERT(parity <= CDCLineCoding_SPACEPARITY,
+ "CDCLineCoding_Initialize: Invalid parity value (%d)\n\r",
+ parity);
+ ASSERT(((databits >= 5) && (databits <= 8)) || (databits == 16),
+ "CDCLineCoding_Initialize: Invalid databits value (%d)\n\r",
+ databits);
+
+ lineCoding->dwDTERate = bitrate;
+ lineCoding->bCharFormat = stopbits;
+ lineCoding->bParityType = parity;
+ lineCoding->bDataBits = databits;
+}
+
diff --git a/usb/common/cdc/CDCLineCoding.h b/usb/common/cdc/CDCLineCoding.h new file mode 100644 index 0000000..dfe3c10 --- /dev/null +++ b/usb/common/cdc/CDCLineCoding.h @@ -0,0 +1,136 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Line coding structure used for by the CDC GetLineCoding and SetLineCoding
+ requests.
+
+ !!!Usage
+
+ -# Initialize a CDCLineCoding instance using CDCLineCoding_Initialize.
+ -# Send a CDCLineCoding object to the host in response to a GetLineCoding
+ request.
+ -# Receive a CDCLineCoding object from the host after a SetLineCoding
+ request.
+*/
+
+#ifndef CDCLINECODING_H
+#define CDCLINECODING_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC LineCoding StopBits"
+/// This page lists Stop Bits for CDC Line Coding.
+///
+/// !Stop bits
+/// - CDCLineCoding_ONESTOPBIT
+/// - CDCLineCoding_ONE5STOPBIT
+/// - CDCLineCoding_TWOSTOPBITS
+
+/// The transmission protocol uses one stop bit.
+#define CDCLineCoding_ONESTOPBIT 0
+/// The transmission protocol uses 1.5 stop bit.
+#define CDCLineCoding_ONE5STOPBIT 1
+/// The transmissin protocol uses two stop bits.
+#define CDCLineCoding_TWOSTOPBITS 2
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "CDC LineCoding ParityCheckings"
+/// This page lists Parity checkings for CDC Line Coding.
+///
+/// !Parity checking
+/// - CDCLineCoding_NOPARITY
+/// - CDCLineCoding_ODDPARITY
+/// - CDCLineCoding_EVENPARITY
+/// - CDCLineCoding_MARKPARITY
+/// - CDCLineCoding_SPACEPARITY
+
+/// No parity checking.
+#define CDCLineCoding_NOPARITY 0
+/// Odd parity checking.
+#define CDCLineCoding_ODDPARITY 1
+/// Even parity checking.
+#define CDCLineCoding_EVENPARITY 2
+/// Mark parity checking.
+#define CDCLineCoding_MARKPARITY 3
+/// Space parity checking.
+#define CDCLineCoding_SPACEPARITY 4
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Format of the data returned when a GetLineCoding request is received.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Data terminal rate in bits per second.
+ unsigned int dwDTERate;
+ /// Number of stop bits.
+ /// \sa "CDC LineCoding StopBits".
+ char bCharFormat;
+ /// Type of parity checking used.
+ /// \sa "CDC LineCoding ParityCheckings".
+ char bParityType;
+ /// Number of data bits (5, 6, 7, 8 or 16).
+ char bDataBits;
+
+} __attribute__ ((packed)) CDCLineCoding; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
+ unsigned int bitrate,
+ unsigned char stopbits,
+ unsigned char parity,
+ unsigned char databits);
+
+#endif //#ifndef CDCLINECODING_H
+
diff --git a/usb/common/cdc/CDCSetControlLineStateRequest.c b/usb/common/cdc/CDCSetControlLineStateRequest.c new file mode 100644 index 0000000..43079ca --- /dev/null +++ b/usb/common/cdc/CDCSetControlLineStateRequest.c @@ -0,0 +1,84 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/**
+ CDCSetControlLineStateRequest.c
+
+ !!!Purpose
+
+ Implementation of the CDCSetControlLineStateRequest class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "CDCSetControlLineStateRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Notifies if the given request indicates that the DTE signal is present.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return 1 if the DTE signal is present, otherwise 0.
+//------------------------------------------------------------------------------
+unsigned char CDCSetControlLineStateRequest_IsDtePresent(
+ const USBGenericRequest *request)
+{
+ if ((USBGenericRequest_GetValue(request) & 0x0001) != 0) {
+
+ return 1;
+ }
+ else {
+
+ return 0;
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Notifies if the given request indicates that the device carrier should
+/// be activated.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return 1 is the device should activate its carrier, 0 otherwise.
+//------------------------------------------------------------------------------
+unsigned char CDCSetControlLineStateRequest_ActivateCarrier(
+ const USBGenericRequest *request)
+{
+ if ((USBGenericRequest_GetValue(request) & 0x0002) != 0) {
+
+ return 1;
+ }
+ else {
+
+ return 0;
+ }
+}
+
diff --git a/usb/common/cdc/CDCSetControlLineStateRequest.h b/usb/common/cdc/CDCSetControlLineStateRequest.h new file mode 100644 index 0000000..5d6c661 --- /dev/null +++ b/usb/common/cdc/CDCSetControlLineStateRequest.h @@ -0,0 +1,59 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating SetControlLineState requests.
+*/
+
+#ifndef CDCSETCONTROLLINESTATE_H
+#define CDCSETCONTROLLINESTATE_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char CDCSetControlLineStateRequest_IsDtePresent(
+ const USBGenericRequest *request);
+
+
+extern unsigned char CDCSetControlLineStateRequest_ActivateCarrier(
+ const USBGenericRequest *request);
+
+#endif //#ifndef CDCSETCONTROLLINESTATE_H
+
diff --git a/usb/common/cdc/CDCUnionDescriptor.h b/usb/common/cdc/CDCUnionDescriptor.h new file mode 100644 index 0000000..0ba9eaa --- /dev/null +++ b/usb/common/cdc/CDCUnionDescriptor.h @@ -0,0 +1,79 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating CDC union descriptors.
+
+ !!!Usage
+
+ Should be included in the list of USB descriptor used for a device
+ configuration.
+*/
+
+#ifndef CDCUNIONDESCRIPTOR_H
+#define CDCUNIONDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Describes the relationship between a group of interfaces that can
+/// be considered to form a functional unit.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of the descriptor in bytes.
+ unsigned char bFunctionLength;
+ /// Descriptor type (CDCDescriptors_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Descriptor subtype (CDCDescriptors_UNION).
+ unsigned char bDescriptorSubtype;
+ /// Number of the master interface for this union.
+ unsigned char bMasterInterface;
+ /// Number of the first slave interface for this union.
+ unsigned char bSlaveInterface0;
+
+} __attribute__ ((packed)) CDCUnionDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef CDCUNIONDESCRIPTOR_H
+
diff --git a/usb/common/cdc/cdc.dir b/usb/common/cdc/cdc.dir new file mode 100644 index 0000000..8d9e99b --- /dev/null +++ b/usb/common/cdc/cdc.dir @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+/// !Purpose
+///
+/// This directory contains structures and definitions related to the USB CDC
+/// specification. They can be divided into two groups:
+/// - CDC-specific descriptors, prefixed with CDC and suffixed with Descriptor.
+/// - CDC-specific requests, prefixed with CDC and suffixed with Request.
+//------------------------------------------------------------------------------
+
diff --git a/usb/common/common.dir b/usb/common/common.dir new file mode 100644 index 0000000..239696c --- /dev/null +++ b/usb/common/common.dir @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+/// !!!Purpose
+///
+/// This directory containes highly re-usable code from USB standard and some
+/// classes specifications for general use.
+///
+/// !!!Contents
+/// This dircetory provides two sections of definitions:
+/// -# Definitions, structures and functions from USB specification,
+/// commonly used for all USB classes and projects.
+/// - core: for USB specification
+/// -# Definitions, structures and functions from class-specific
+/// specification commonly used for class related project ONLY.
+/// - cdc: for USB Communication Devie Class (CDC)
+/// - hid: for USB Humen Interface Device Class (HID)
+/// - massstorage: for USB Mass Storage Class (MS)
+/// - audio: for USB Audio Class (AUD)
+///
+/// For more information about what a particular group contains, please refer to
+/// its documentation page.
+///
+/// \note
+/// Depending on the project, not all the subdirectories will be available
+/// (i.e. the #cdc# directory will not be in non-CDC projects).
+//------------------------------------------------------------------------------
\ No newline at end of file diff --git a/usb/common/core/USBConfigurationDescriptor.c b/usb/common/core/USBConfigurationDescriptor.c new file mode 100644 index 0000000..503dceb --- /dev/null +++ b/usb/common/core/USBConfigurationDescriptor.c @@ -0,0 +1,162 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBConfigurationDescriptor implementation
+
+ About: Purpose
+ Implementation of the USBConfigurationDescriptor class.
+*/
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include "USBConfigurationDescriptor.h"
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Returns the total length of a configuration, i.e. including the
+/// descriptors following it.
+/// \param configuration Pointer to a USBConfigurationDescriptor instance.
+/// \return Total length (in bytes) of the configuration.
+//-----------------------------------------------------------------------------
+unsigned int USBConfigurationDescriptor_GetTotalLength(
+ const USBConfigurationDescriptor *configuration)
+{
+ return configuration->wTotalLength;
+}
+
+//-----------------------------------------------------------------------------
+/// Returns the number of interfaces in a configuration.
+/// \param configuration Pointer to a USBConfigurationDescriptor instance.
+/// \return Number of interfaces in configuration.
+//-----------------------------------------------------------------------------
+unsigned char USBConfigurationDescriptor_GetNumInterfaces(
+ const USBConfigurationDescriptor *configuration)
+{
+ return configuration->bNumInterfaces;
+}
+
+//-----------------------------------------------------------------------------
+/// Indicates if the device is self-powered when in a given configuration.
+/// \param configuration Pointer to a USBConfigurationDescriptor instance.
+/// \return 1 if the device is self-powered when in the given configuration;
+/// otherwise 0.
+//-----------------------------------------------------------------------------
+unsigned char USBConfigurationDescriptor_IsSelfPowered(
+ const USBConfigurationDescriptor *configuration)
+{
+ if ((configuration->bmAttributes & (1 << 6)) != 0) {
+
+ return 1;
+ }
+ else {
+
+ return 0;
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Parses the given Configuration descriptor (followed by relevant
+/// interface, endpoint and class-specific descriptors) into three arrays.
+/// *Each array must have its size equal or greater to the number of
+/// descriptors it stores plus one*. A null-value is inserted after the last
+/// descriptor of each type to indicate the array end.
+///
+/// Note that if the pointer to an array is null (0), nothing is stored in
+/// it.
+/// \param configuration Pointer to the start of the whole Configuration
+/// descriptor.
+/// \param interfaces Pointer to the Interface descriptor array.
+/// \param endpoints Pointer to the Endpoint descriptor array.
+/// \param others Pointer to the class-specific descriptor array.
+//-----------------------------------------------------------------------------
+void USBConfigurationDescriptor_Parse(
+ const USBConfigurationDescriptor *configuration,
+ USBInterfaceDescriptor **interfaces,
+ USBEndpointDescriptor **endpoints,
+ USBGenericDescriptor **others)
+{
+ // Get size of configuration to parse
+ int size = USBConfigurationDescriptor_GetTotalLength(configuration);
+ size -= sizeof(USBConfigurationDescriptor);
+
+ // Start parsing descriptors
+ USBGenericDescriptor *descriptor = (USBGenericDescriptor *) configuration;
+ while (size > 0) {
+
+ // Get next descriptor
+ descriptor = USBGenericDescriptor_GetNextDescriptor(descriptor);
+ size -= USBGenericDescriptor_GetLength(descriptor);
+
+ // Store descriptor in correponding array
+ if (USBGenericDescriptor_GetType(descriptor)
+ == USBGenericDescriptor_INTERFACE) {
+
+ if (interfaces) {
+
+ *interfaces = (USBInterfaceDescriptor *) descriptor;
+ interfaces++;
+ }
+ }
+ else if (USBGenericDescriptor_GetType(descriptor)
+ == USBGenericDescriptor_ENDPOINT) {
+
+ if (endpoints) {
+
+ *endpoints = (USBEndpointDescriptor *) descriptor;
+ endpoints++;
+ }
+ }
+ else if (others) {
+
+ *others = descriptor;
+ others++;
+ }
+ }
+
+ // Null-terminate arrays
+ if (interfaces) {
+
+ *interfaces = 0;
+ }
+ if (endpoints) {
+
+ *endpoints = 0;
+ }
+ if (others) {
+
+ *others = 0;
+ }
+}
+
diff --git a/usb/common/core/USBConfigurationDescriptor.h b/usb/common/core/USBConfigurationDescriptor.h new file mode 100644 index 0000000..150e656 --- /dev/null +++ b/usb/common/core/USBConfigurationDescriptor.h @@ -0,0 +1,150 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions and methods for USB configuration descriptor structures
+ described by the USB specification.
+
+ !!!Usage
+
+ -# Declare USBConfigurationDescriptor instance as a part
+ of the configuration descriptors of a USB device.
+ -# To get useful information (field values) from the defined USB device
+ configuration descriptor, use
+ - USBConfigurationDescriptor_GetTotalLength
+ - USBConfigurationDescriptor_GetNumInterfaces
+ - USBConfigurationDescriptor_IsSelfPowered
+ -# To pase the defined USB device configuration descriptor, use
+ - USBConfigurationDescriptor_Parse
+*/
+
+#ifndef USBCONFIGURATIONDESCRIPTOR_H
+#define USBCONFIGURATIONDESCRIPTOR_H
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include "USBGenericDescriptor.h"
+#include "USBInterfaceDescriptor.h"
+#include "USBEndpointDescriptor.h"
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// \page "USB device Attributes"
+///
+/// This page lists the codes of the usb attributes.
+///
+/// !Attributes
+/// - USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP
+/// - USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP
+/// - USBConfigurationDescriptor_BUSPOWERED_RWAKEUP
+/// - USBConfigurationDescriptor_SELFPOWERED_RWAKEUP
+/// - USBConfigurationDescriptor_POWER
+
+/// Device is bus-powered and not support remote wake-up.
+#define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
+/// Device is self-powered and not support remote wake-up.
+#define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
+/// Device is bus-powered and supports remote wake-up.
+#define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
+/// Device is self-powered and supports remote wake-up.
+#define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
+
+/// Calculates the value of the power consumption field given the value in mA.
+/// \param power The power consumption value in mA
+/// \return The value that should be set to the field in descriptor
+#define USBConfigurationDescriptor_POWER(power) (power / 2)
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Types
+//-----------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//-----------------------------------------------------------------------------
+/// USB standard configuration descriptor structure.
+//-----------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of the descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (USBDESC_CONFIGURATION of "USB Descriptor types").
+ unsigned char bDescriptorType;
+ /// Length of all descriptors returned along with this configuration
+ /// descriptor.
+ unsigned short wTotalLength;
+ /// Number of interfaces in this configuration.
+ unsigned char bNumInterfaces;
+ /// Value for selecting this configuration.
+ unsigned char bConfigurationValue;
+ /// Index of the configuration string descriptor.
+ unsigned char iConfiguration;
+ /// Configuration characteristics.
+ unsigned char bmAttributes;
+ /// Maximum power consumption of the device when in this configuration.
+ unsigned char bMaxPower;
+
+} __attribute__ ((packed)) USBConfigurationDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+extern unsigned int USBConfigurationDescriptor_GetTotalLength(
+ const USBConfigurationDescriptor *configuration);
+
+extern unsigned char USBConfigurationDescriptor_GetNumInterfaces(
+ const USBConfigurationDescriptor *configuration);
+
+extern unsigned char USBConfigurationDescriptor_IsSelfPowered(
+ const USBConfigurationDescriptor *configuration);
+
+extern void USBConfigurationDescriptor_Parse(
+ const USBConfigurationDescriptor *configuration,
+ USBInterfaceDescriptor **interfaces,
+ USBEndpointDescriptor **endpoints,
+ USBGenericDescriptor **others);
+
+#endif //#ifndef USBCONFIGURATIONDESCRIPTOR_H
+
diff --git a/usb/common/core/USBConfigurationOTG.c b/usb/common/core/USBConfigurationOTG.c new file mode 100644 index 0000000..c875790 --- /dev/null +++ b/usb/common/core/USBConfigurationOTG.c @@ -0,0 +1,51 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//-----------------------------------------------------------------------------
+// Includes
+//-----------------------------------------------------------------------------
+
+#include "USBConfigurationOTG.h"
+
+
+USBGenericOTGDescriptor *pOTGDescriptor;
+
+//-----------------------------------------------------------------------------
+// Internal functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// External functions
+//-----------------------------------------------------------------------------
+void OTG_Initialize(USBGenericOTGDescriptor *pOTGDesc)
+{
+ pOTGDescriptor = pOTGDesc;
+}
+
+
diff --git a/usb/common/core/USBConfigurationOTG.h b/usb/common/core/USBConfigurationOTG.h new file mode 100644 index 0000000..d0d3b05 --- /dev/null +++ b/usb/common/core/USBConfigurationOTG.h @@ -0,0 +1,118 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Methods and definitions for configuring OTG.
+///
+/// !Usage
+///
+/// -#
+/// -#
+///
+//------------------------------------------------------------------------------
+
+#ifndef USBCONFIGURATIONOTG_H
+#define USBCONFIGURATIONOTG_H
+
+#include <usb/otg/compiler.h>
+
+
+/// OTG specific configuration
+typedef struct {
+
+ /// USB MODE CONFIGURATION
+
+ /// ENABLE to activate the host software library support
+ /// Possible values ENABLE or DISABLE
+ unsigned char bOTGUsbHostFeature;
+
+ /// ENABLE to activate the device software library support
+ /// Possible values ENABLE or DISABLE
+ unsigned char bOTGUsbDeviceFeature;
+ /// OTG MODE CONFIGURATION
+ /// ENABLE to enable OTG module (support A- and B- Device roles)
+ /// Possible values ENABLE or DISABLE
+ unsigned char bOTGFeature;
+
+ /// For reduced host only allows to control VBUS generator with PIO PE.7
+ unsigned char bOTGSoftwareVbusCtrl;
+
+ /// Selects the messaging method for OTG No Silent Failure spec.
+ ///
+ /// A compliant OTG device must at least handle 3 Failure messages :
+ /// "Device No Response", "Unsupported Device" and "Unsupported Hub"
+ /// Functions must be defined for communicating messages to user (LCD display,
+ /// LEDs...)
+ /// The values available for this parameter are :
+ /// - OTGMSG_ALL : all messages (events and failures) are displayed
+ /// In this case, the following functions must be defined in user application firmware :
+ /// # "void Otg_messaging_init(void)", this function is called at start up to initialize the messaging peripheral
+ /// # "void Otg_output_failure_msg(U8)", displays the failure message choosen by ID number (see "usb_task.h")
+ /// # "void Otg_output_failure_clear(void)", clears the current failure message
+ /// # "void Otg_output_event_msg(U8)", displays the event message choosen by ID number
+ /// # "void Otg_output_event_clear(void)", clears the current event message
+ /// - OTGMSG_FAIL : only failure messages are displayed
+ /// In this case, the following functions must be defined in user application firmware :
+ /// # "void Otg_messaging_init(void)", this function is called at start up to initialize the messaging peripheral
+ /// # "void Otg_output_failure_msg(U8)", displays the failure message choosen by ID number (see "usb_task.h")
+ /// # "void Otg_output_failure_clear(void)", clears the current failure message
+ /// - OTGMSG_NONE : messages are not displayed (not OTG compliant device)
+ unsigned char bOTGMessagingOutput;
+
+ /// ENABLE to make the A-Device send a SetFeature(b_hnp_enable) just after a SRP
+ /// has been received
+ /// This feature must be ENABLE to pass the OTG compliance program
+ /// Possible values ENABLE or DISABLE
+ unsigned char bOTGEnableHNPAfterSRP;
+
+ /// Selects the SRP pulse for which the A Device will react and rise Vbus
+ /// The value is VBUS_PULSE or DATA_PULSE
+ unsigned char bOTGADevSRPReaction;
+
+} USBGenericOTGDescriptor;
+
+#define OTGMSG_NONE 0 // no messages displayed
+#define OTGMSG_FAIL 1 // only failure messages displayed
+#define OTGMSG_ALL 2 // all messages displayed
+
+#define VBUS_PULSE 1 // no more used
+#define DATA_PULSE 0
+
+
+extern USBGenericOTGDescriptor *pOTGDescriptor;
+
+extern void OTG_Initialize(USBGenericOTGDescriptor *pOTGDesc);
+
+
+#endif //#ifndef USBCONFIGURATIONOTG_H
+
diff --git a/usb/common/core/USBDeviceDescriptor.h b/usb/common/core/USBDeviceDescriptor.h new file mode 100644 index 0000000..ce8d199 --- /dev/null +++ b/usb/common/core/USBDeviceDescriptor.h @@ -0,0 +1,125 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Class for manipulating USB device descriptors.
+
+ !!!Usage
+
+ - Declare a USBDeviceDescriptor instance as the device descriptor of a
+ USB device.
+*/
+
+#ifndef USBDEVICEDESCRIPTOR_H
+#define USBDEVICEDESCRIPTOR_H
+
+#include <board.h>
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB release numbers"
+///
+/// This page lists the codes of USB release numbers.
+///
+/// !Code
+/// - USBDeviceDescriptor_USB2_00
+
+/// The device supports USB 2.00.
+#define USBDeviceDescriptor_USB2_00 0x0200
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// USB standard device descriptor structure.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of this descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (USBGenericDescriptor_DEVICE).
+ unsigned char bDescriptorType;
+ /// USB specification release number in BCD format.
+ unsigned short bcdUSB;
+ /// Device class code.
+ unsigned char bDeviceClass;
+ /// Device subclass code.
+ unsigned char bDeviceSubClass;
+ /// Device protocol code.
+ unsigned char bDeviceProtocol;
+ /// Maximum packet size of endpoint 0 (in bytes).
+ unsigned char bMaxPacketSize0;
+ /// Vendor ID.
+ unsigned short idVendor;
+ /// Product ID.
+ unsigned short idProduct;
+ /// Device release number in BCD format.
+ unsigned short bcdDevice;
+ /// Index of the manufacturer string descriptor.
+ unsigned char iManufacturer;
+ /// Index of the product string descriptor.
+ unsigned char iProduct;
+ /// Index of the serial number string descriptor.
+ unsigned char iSerialNumber;
+ /// Number of possible configurations for the device.
+ unsigned char bNumConfigurations;
+
+} __attribute__ ((packed)) USBDeviceDescriptor; // GCC
+
+#if defined(CHIP_USB_OTGHS)
+typedef struct {
+
+ /// Size of this descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (USBGenericDescriptor_OTG).
+ unsigned char bDescriptorType;
+ /// Attribute Fields D7…2: Reserved D1: HNP support D0: SRP support
+ unsigned char bmAttributes;
+
+} __attribute__ ((packed)) USBOtgDescriptor; // GCC
+#endif
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef USBDEVICEDESCRIPTOR_H
+
diff --git a/usb/common/core/USBDeviceQualifierDescriptor.h b/usb/common/core/USBDeviceQualifierDescriptor.h new file mode 100644 index 0000000..3728865 --- /dev/null +++ b/usb/common/core/USBDeviceQualifierDescriptor.h @@ -0,0 +1,89 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Class for manipulating USB device qualifier descriptors.
+
+ !!!Usage
+
+ - Declare a USBDeviceQualifierDescriptor instance as the device qualifier
+ descriptor of a USB device.
+*/
+
+#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
+#define USBDEVICEQUALIFIERDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Alternate device descriptor indicating the capabilities of the device
+/// in full-speed, if currently in high-speed; or in high-speed, if it is
+/// currently in full-speed. Only relevant for devices supporting the
+/// high-speed mode.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of the descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types").
+ unsigned char bDescriptorType;
+ /// USB specification release number (in BCD format).
+ unsigned short bcdUSB;
+ /// Device class code.
+ unsigned char bDeviceClass;
+ /// Device subclass code.
+ unsigned char bDeviceSubClass;
+ /// Device protocol code.
+ unsigned char bDeviceProtocol;
+ /// Maximum packet size of endpoint 0.
+ unsigned char bMaxPacketSize0;
+ /// Number of possible configurations for the device.
+ unsigned char bNumConfigurations;
+ /// Reserved.
+ unsigned char bReserved;
+
+} __attribute__ ((packed)) USBDeviceQualifierDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef USBDEVICEQUALIFIERDESCRIPTOR_H
+
diff --git a/usb/common/core/USBEndpointDescriptor.c b/usb/common/core/USBEndpointDescriptor.c new file mode 100644 index 0000000..6300ade --- /dev/null +++ b/usb/common/core/USBEndpointDescriptor.c @@ -0,0 +1,109 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBEndpointDescriptor implementation
+
+ About: Purpose
+ Implementation of the USBEndpointDescriptor class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBEndpointDescriptor.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the number of an endpoint given its descriptor.
+/// \param endpoint Pointer to a USBEndpointDescriptor instance.
+/// \return Endpoint number.
+//------------------------------------------------------------------------------
+unsigned char USBEndpointDescriptor_GetNumber(
+ const USBEndpointDescriptor *endpoint)
+{
+ return endpoint->bEndpointAddress & 0xF;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the direction of an endpoint given its descriptor.
+/// \param endpoint Pointer to a USBEndpointDescriptor instance.
+/// \return Endpoint direction (see <Endpoint directions>).
+//------------------------------------------------------------------------------
+unsigned char USBEndpointDescriptor_GetDirection(
+ const USBEndpointDescriptor *endpoint)
+{
+ if ((endpoint->bEndpointAddress & 0x80) != 0) {
+
+ return USBEndpointDescriptor_IN;
+ }
+ else {
+
+ return USBEndpointDescriptor_OUT;
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Returns the type of an endpoint given its descriptor.
+/// \param endpoint Pointer to a USBEndpointDescriptor instance.
+/// \return Endpoint type (see <Endpoint types>).
+//------------------------------------------------------------------------------
+unsigned char USBEndpointDescriptor_GetType(
+ const USBEndpointDescriptor *endpoint)
+{
+ return endpoint->bmAttributes & 0x3;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the maximum size of a packet (in bytes) on an endpoint given
+/// its descriptor.
+/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
+/// \return Maximum packet size of endpoint.
+//------------------------------------------------------------------------------
+unsigned short USBEndpointDescriptor_GetMaxPacketSize(
+ const USBEndpointDescriptor *endpoint)
+{
+ return endpoint->wMaxPacketSize;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the polling interval on an endpoint given its descriptor.
+/// \param endpoint - Pointer to a USBEndpointDescriptor instance.
+/// \return Polling interval of endpoint.
+//------------------------------------------------------------------------------
+unsigned char USBEndpointDescriptor_GetInterval(
+ const USBEndpointDescriptor *endpoint)
+{
+ return endpoint->bInterval;
+}
+
diff --git a/usb/common/core/USBEndpointDescriptor.h b/usb/common/core/USBEndpointDescriptor.h new file mode 100644 index 0000000..d49e028 --- /dev/null +++ b/usb/common/core/USBEndpointDescriptor.h @@ -0,0 +1,224 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for handling USB endpoint descriptors.
+
+ !!!Usage
+
+ -# Declare USBEndpointDescriptor instance as a part of the
+ configuration descriptors of a USB device.
+ -# To get useful information (field values) from the defined USB device
+ endpoint descriptor (to configure hardware for endpoints, etc), use
+ - USBEndpointDescriptor_GetNumber
+ - USBEndpointDescriptor_GetDirection
+ - USBEndpointDescriptor_GetType
+ - USBEndpointDescriptor_GetMaxPacketSize
+*/
+
+#ifndef USBENDPOINTDESCRIPTOR_H
+#define USBENDPOINTDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Endpoint definitions"
+///
+/// This page lists definitions and macro for endpoint descriptors.
+///
+/// - USB Endpoint directions
+/// - USBEndpointDescriptor_OUT
+/// - USBEndpointDescriptor_IN
+///
+/// - USB Endpoint types
+/// - USBEndpointDescriptor_CONTROL
+/// - USBEndpointDescriptor_ISOCHRONOUS
+/// - USBEndpointDescriptor_BULK
+/// - USBEndpointDescriptor_INTERRUPT
+///
+/// - USB Endpoint maximun sizes
+/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
+/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
+/// - USBEndpointDescriptor_MAXBULKSIZE_FS
+/// - USBEndpointDescriptor_MAXBULKSIZE_HS
+/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
+/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
+/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
+/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
+///
+/// - USB Endpoint address define
+/// - USBEndpointDescriptor_ADDRESS
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Endpoint directions"
+///
+/// This page lists definitions of USB endpoint directions.
+///
+/// !Directions
+/// - USBEndpointDescriptor_OUT
+/// - USBEndpointDescriptor_IN
+
+/// Endpoint receives data from the host.
+#define USBEndpointDescriptor_OUT 0
+/// Endpoint sends data to the host.
+#define USBEndpointDescriptor_IN 1
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Endpoint types"
+///
+/// This page lists definitions of USB endpoint types.
+///
+/// !Types
+/// - USBEndpointDescriptor_CONTROL
+/// - USBEndpointDescriptor_ISOCHRONOUS
+/// - USBEndpointDescriptor_BULK
+/// - USBEndpointDescriptor_INTERRUPT
+
+/// Control endpoint type.
+#define USBEndpointDescriptor_CONTROL 0
+/// Isochronous endpoint type.
+#define USBEndpointDescriptor_ISOCHRONOUS 1
+/// Bulk endpoint type.
+#define USBEndpointDescriptor_BULK 2
+/// Interrupt endpoint type.
+#define USBEndpointDescriptor_INTERRUPT 3
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Endpoint maximun sizes"
+///
+/// This page lists definitions of USB endpoint maximun sizes.
+///
+/// !Sizes
+/// - USBEndpointDescriptor_MAXCTRLSIZE_FS
+/// - USBEndpointDescriptor_MAXCTRLSIZE_HS
+/// - USBEndpointDescriptor_MAXBULKSIZE_FS
+/// - USBEndpointDescriptor_MAXBULKSIZE_HS
+/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_FS
+/// - USBEndpointDescriptor_MAXINTERRUPTSIZE_HS
+/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS
+/// - USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS
+
+/// Maximum size for a full-speed control endpoint.
+#define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
+/// Maximum size for a high-speed control endpoint.
+#define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
+/// Maximum size for a full-speed bulk endpoint.
+#define USBEndpointDescriptor_MAXBULKSIZE_FS 64
+/// Maximum size for a high-speed bulk endpoint.
+#define USBEndpointDescriptor_MAXBULKSIZE_HS 512
+/// Maximum size for a full-speed interrupt endpoint.
+#define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
+/// Maximum size for a high-speed interrupt endpoint.
+#define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
+/// Maximum size for a full-speed isochronous endpoint.
+#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
+/// Maximum size for a high-speed isochronous endpoint.
+#define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Endpoint address define"
+///
+/// This page lists macro for USB endpoint address definition.
+///
+/// !Macro
+/// - USBEndpointDescriptor_ADDRESS
+
+/// Calculates the address of an endpoint given its number and direction
+/// \param direction USB endpoint direction definition
+/// \param number USB endpoint number
+/// \return The value used to set the endpoint descriptor based on input number
+/// and direction
+#define USBEndpointDescriptor_ADDRESS(direction, number) \
+ (((direction & 0x01) << 7) | (number & 0xF))
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// USB standard endpoint descriptor structure.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of the descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (<USBGenericDescriptor_ENDPOINT>).
+ unsigned char bDescriptorType;
+ /// Address and direction of the endpoint.
+ unsigned char bEndpointAddress;
+ /// Endpoint type and additional characteristics (for isochronous endpoints).
+ unsigned char bmAttributes;
+ /// Maximum packet size (in bytes) of the endpoint.
+ unsigned short wMaxPacketSize;
+ /// Polling rate of the endpoint.
+ unsigned char bInterval;
+
+} __attribute__ ((packed)) USBEndpointDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBEndpointDescriptor_GetNumber(
+ const USBEndpointDescriptor *endpoint);
+
+extern unsigned char USBEndpointDescriptor_GetDirection(
+ const USBEndpointDescriptor *endpoint);
+
+extern unsigned char USBEndpointDescriptor_GetType(
+ const USBEndpointDescriptor *endpoint);
+
+extern unsigned short USBEndpointDescriptor_GetMaxPacketSize(
+ const USBEndpointDescriptor *endpoint);
+
+extern unsigned char USBEndpointDescriptor_GetInterval(
+ const USBEndpointDescriptor *endpoint);
+
+#endif //#ifndef USBENDPOINTDESCRIPTOR_H
+
diff --git a/usb/common/core/USBFeatureRequest.c b/usb/common/core/USBFeatureRequest.c new file mode 100644 index 0000000..1e0422a --- /dev/null +++ b/usb/common/core/USBFeatureRequest.c @@ -0,0 +1,70 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBFeatureRequest implementation
+
+ About: Purpose
+ Implementation of the USBFeatureRequest class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBFeatureRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the feature selector of a given CLEAR_FEATURE or SET_FEATURE
+/// request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Feature selector.
+//------------------------------------------------------------------------------
+unsigned char USBFeatureRequest_GetFeatureSelector(
+ const USBGenericRequest *request)
+{
+ return USBGenericRequest_GetValue(request);
+}
+
+//------------------------------------------------------------------------------
+/// Indicates the test that the device must undertake following a
+/// SET_FEATURE request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Test selector.
+//------------------------------------------------------------------------------
+unsigned char USBFeatureRequest_GetTestSelector(
+ const USBGenericRequest *request)
+{
+ return (USBGenericRequest_GetIndex(request) >> 8) & 0xFF;
+}
+
diff --git a/usb/common/core/USBFeatureRequest.h b/usb/common/core/USBFeatureRequest.h new file mode 100644 index 0000000..0454ffb --- /dev/null +++ b/usb/common/core/USBFeatureRequest.h @@ -0,0 +1,146 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating CLEAR_FEATURE and SET_FEATURE
+ requests.
+
+ !!!Usage
+
+ - To get USB feature request information (field values) from the
+ USBGenericRequest instance, use
+ - USBFeatureRequest_GetFeatureSelector
+ - USBFeatureRequest_GetTestSelector
+*/
+
+#ifndef USBFEATUREREQUEST_H
+#define USBFEATUREREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Feature Request definitions"
+///
+/// This page lists codes of USB Feature Request
+///
+/// - USB Feature selectors
+/// - USBFeatureRequest_ENDPOINTHALT
+/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
+/// - USBFeatureRequest_TESTMODE
+///
+/// - USB Test mode selectors
+/// - USBFeatureRequest_TESTJ
+/// - USBFeatureRequest_TESTK
+/// - USBFeatureRequest_TESTSE0NAK
+/// - USBFeatureRequest_TESTPACKET
+/// - USBFeatureRequest_TESTFORCEENABLE
+/// - USBFeatureRequest_TESTSENDZLP
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Feature selectors"
+///
+/// This page lists codes of USB feature selectors.
+///
+/// !Selectors
+/// - USBFeatureRequest_ENDPOINTHALT
+/// - USBFeatureRequest_DEVICEREMOTEWAKEUP
+/// - USBFeatureRequest_TESTMODE
+
+/// Halt feature of an endpoint.
+#define USBFeatureRequest_ENDPOINTHALT 0
+/// Remote wake-up feature of the device.
+#define USBFeatureRequest_DEVICEREMOTEWAKEUP 1
+/// Test mode of the device.
+#define USBFeatureRequest_TESTMODE 2
+/// OTG set feature
+#define USBFeatureRequest_OTG 0x0B
+//------------------------------------------------------------------------------
+
+/// On The Go Feature Selectors
+/// b_hnp_enable 3
+/// a_hnp_support 4
+/// a_alt_hnp_support 5
+#define USBFeatureRequest_OTG_B_HNP_ENABLE 3
+#define USBFeatureRequest_OTG_A_HNP_SUPPORT 4
+#define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5
+
+//------------------------------------------------------------------------------
+/// \page "USB Test mode selectors"
+///
+/// This page lists codes of USB high speed test mode selectors.
+///
+/// !Selectors
+/// - USBFeatureRequest_TESTJ
+/// - USBFeatureRequest_TESTK
+/// - USBFeatureRequest_TESTSE0NAK
+/// - USBFeatureRequest_TESTPACKET
+/// - USBFeatureRequest_TESTFORCEENABLE
+/// - USBFeatureRequest_TESTSENDZLP
+
+/// Tests the high-output drive level on the D+ line.
+#define USBFeatureRequest_TESTJ 1
+/// Tests the high-output drive level on the D- line.
+#define USBFeatureRequest_TESTK 2
+/// Tests the output impedance, low-level output voltage and loading
+/// characteristics.
+#define USBFeatureRequest_TESTSE0NAK 3
+/// Tests rise and fall times, eye patterns and jitter.
+#define USBFeatureRequest_TESTPACKET 4
+/// Tests the hub disconnect detection.
+#define USBFeatureRequest_TESTFORCEENABLE 5
+/// Send a ZLP in Test Mode.
+#define USBFeatureRequest_TESTSENDZLP 6
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBFeatureRequest_GetFeatureSelector(
+ const USBGenericRequest *request);
+
+
+extern unsigned char USBFeatureRequest_GetTestSelector(
+ const USBGenericRequest *request);
+
+#endif //#ifndef USBFEATUREREQUEST_H
+
diff --git a/usb/common/core/USBGenericDescriptor.c b/usb/common/core/USBGenericDescriptor.c new file mode 100644 index 0000000..99ed6f9 --- /dev/null +++ b/usb/common/core/USBGenericDescriptor.c @@ -0,0 +1,80 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBGenericDescriptor implementation
+
+ About: Purpose
+ Implementation of the USBGenericDescriptor class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericDescriptor.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the length of a descriptor.
+/// \param descriptor Pointer to a USBGenericDescriptor instance.
+/// \return Length of descriptor in bytes.
+//------------------------------------------------------------------------------
+unsigned int USBGenericDescriptor_GetLength(
+ const USBGenericDescriptor *descriptor)
+{
+ return descriptor->bLength;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the type of a descriptor.
+/// \param descriptor Pointer to a USBGenericDescriptor instance.
+/// \return Type of descriptor.
+//------------------------------------------------------------------------------
+unsigned char USBGenericDescriptor_GetType(
+ const USBGenericDescriptor *descriptor)
+{
+ return descriptor->bDescriptorType;
+}
+
+//------------------------------------------------------------------------------
+/// Returns a pointer to the descriptor right after the given one, when
+/// parsing a Configuration descriptor.
+/// \param descriptor - Pointer to a USBGenericDescriptor instance.
+/// \return Pointer to the next descriptor.
+//------------------------------------------------------------------------------
+USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
+ const USBGenericDescriptor *descriptor)
+{
+ return (USBGenericDescriptor *)
+ (((char *) descriptor) + USBGenericDescriptor_GetLength(descriptor));
+}
diff --git a/usb/common/core/USBGenericDescriptor.h b/usb/common/core/USBGenericDescriptor.h new file mode 100644 index 0000000..b1237ae --- /dev/null +++ b/usb/common/core/USBGenericDescriptor.h @@ -0,0 +1,133 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definition of a generic USB descriptor class.
+///
+/// !!!Usage
+///
+/// -# Declare or access USB descriptors by USBGenericDescriptor instance.
+/// -# To get usful information (field values) from the USB descriptors, use
+/// - USBGenericDescriptor_GetLength
+/// - USBGenericDescriptor_GetType
+/// -# To scan the descriptors, use
+/// - USBGenericDescriptor_GetNextDescriptor
+//------------------------------------------------------------------------------
+
+#ifndef USBGENERICDESCRIPTOR_H
+#define USBGENERICDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Descriptor types"
+///
+/// This page lists the codes of the usb descriptor types
+///
+/// !Types
+/// - USBGenericDescriptor_DEVICE
+/// - USBGenericDescriptor_CONFIGURATION
+/// - USBGenericDescriptor_STRING
+/// - USBGenericDescriptor_INTERFACE
+/// - USBGenericDescriptor_ENDPOINT
+/// - USBGenericDescriptor_DEVICEQUALIFIER
+/// - USBGenericDescriptor_OTHERSPEEDCONFIGURATION
+/// - USBGenericDescriptor_INTERFACEPOWER
+/// - USBGenericDescriptor_OTG
+/// - USBGenericDescriptor_DEBUG
+/// - USBGenericDescriptor_INTERFACEASSOCIATION
+
+/// Device descriptor type.
+#define USBGenericDescriptor_DEVICE 1
+/// Configuration descriptor type.
+#define USBGenericDescriptor_CONFIGURATION 2
+/// String descriptor type.
+#define USBGenericDescriptor_STRING 3
+/// Interface descriptor type.
+#define USBGenericDescriptor_INTERFACE 4
+/// Endpoint descriptor type.
+#define USBGenericDescriptor_ENDPOINT 5
+/// Device qualifier descriptor type.
+#define USBGenericDescriptor_DEVICEQUALIFIER 6
+/// Other speed configuration descriptor type.
+#define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
+/// Interface power descriptor type.
+#define USBGenericDescriptor_INTERFACEPOWER 8
+/// On-The-Go descriptor type.
+#define USBGenericDescriptor_OTG 9
+/// Debug descriptor type.
+#define USBGenericDescriptor_DEBUG 10
+/// Interface association descriptor type.
+#define USBGenericDescriptor_INTERFACEASSOCIATION 11
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+/// Holds the few fields shared by all USB descriptors.
+typedef struct {
+
+ /// Length of the descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type.
+ unsigned char bDescriptorType;
+
+} __attribute__ ((packed)) USBGenericDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned int USBGenericDescriptor_GetLength(
+ const USBGenericDescriptor *descriptor);
+
+extern unsigned char USBGenericDescriptor_GetType(
+ const USBGenericDescriptor *descriptor);
+
+extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
+ const USBGenericDescriptor *descriptor);
+
+#endif //#ifndef USBGENERICDESCRIPTOR_H
+
diff --git a/usb/common/core/USBGenericRequest.c b/usb/common/core/USBGenericRequest.c new file mode 100644 index 0000000..a3bbbfd --- /dev/null +++ b/usb/common/core/USBGenericRequest.c @@ -0,0 +1,138 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBGenericRequest implementation
+
+ About: Purpose
+ Implementation of the USBGenericRequest class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+/// Returns the type of the given request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return "USB Request Types"
+//------------------------------------------------------------------------------
+extern unsigned char USBGenericRequest_GetType(const USBGenericRequest *request)
+{
+ return ((request->bmRequestType >> 5) & 0x3);
+}
+
+//------------------------------------------------------------------------------
+/// Returns the request code of the given request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Request code.
+/// \sa "USB Request Codes"
+//------------------------------------------------------------------------------
+unsigned char USBGenericRequest_GetRequest(const USBGenericRequest *request)
+{
+ return request->bRequest;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the wValue field of the given request.
+/// \param request - Pointer to a USBGenericRequest instance.
+/// \return Request value.
+//------------------------------------------------------------------------------
+unsigned short USBGenericRequest_GetValue(const USBGenericRequest *request)
+{
+ return request->wValue;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the wIndex field of the given request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Request index;
+//------------------------------------------------------------------------------
+unsigned short USBGenericRequest_GetIndex(const USBGenericRequest *request)
+{
+ return request->wIndex;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the expected length of the data phase following a request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Length of data phase.
+//------------------------------------------------------------------------------
+unsigned short USBGenericRequest_GetLength(const USBGenericRequest *request)
+{
+ return request->wLength;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the endpoint number targetted by a given request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Endpoint number.
+//------------------------------------------------------------------------------
+unsigned char USBGenericRequest_GetEndpointNumber(
+ const USBGenericRequest *request)
+{
+ return USBGenericRequest_GetIndex(request) & 0xF;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the intended recipient of a given request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Request recipient.
+/// \sa "USB Request Recipients"
+//------------------------------------------------------------------------------
+unsigned char USBGenericRequest_GetRecipient(const USBGenericRequest *request)
+{
+ // Recipient is in bits [0..4] of the bmRequestType field
+ return request->bmRequestType & 0xF;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the direction of the data transfer following the given request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Transfer direction.
+/// \sa "USB Request Directions"
+//------------------------------------------------------------------------------
+unsigned char USBGenericRequest_GetDirection(const USBGenericRequest *request)
+{
+ // Transfer direction is located in bit D7 of the bmRequestType field
+ if ((request->bmRequestType & 0x80) != 0) {
+
+ return USBGenericRequest_IN;
+ }
+ else {
+
+ return USBGenericRequest_OUT;
+ }
+}
+
diff --git a/usb/common/core/USBGenericRequest.h b/usb/common/core/USBGenericRequest.h new file mode 100644 index 0000000..77f8ca5 --- /dev/null +++ b/usb/common/core/USBGenericRequest.h @@ -0,0 +1,244 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of the USBGenericRequest class and its methods.
+
+ !!!Usage
+
+ -# Declare or access USB requests by USBGenericRequest instance.
+ -# To get usful information (field values) from the USB requests, use
+ - USBGenericRequest_GetType
+ - USBGenericRequest_GetRequest
+ - USBGenericRequest_GetValue
+ - USBGenericRequest_GetIndex
+ - USBGenericRequest_GetLength
+ - USBGenericRequest_GetEndpointNumber
+ - USBGenericRequest_GetRecipient
+ - USBGenericRequest_GetDirection
+*/
+
+#ifndef USBGENERICREQUEST_H
+#define USBGENERICREQUEST_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Generic Request definitions"
+///
+/// This page lists the codes of USB generic request.
+///
+/// - USB Request codes
+/// - USBGenericRequest_GETSTATUS
+/// - USBGenericRequest_CLEARFEATURE
+/// - USBGenericRequest_SETFEATURE
+/// - USBGenericRequest_SETADDRESS
+/// - USBGenericRequest_GETDESCRIPTOR
+/// - USBGenericRequest_SETDESCRIPTOR
+/// - USBGenericRequest_GETCONFIGURATION
+/// - USBGenericRequest_SETCONFIGURATION
+/// - USBGenericRequest_GETINTERFACE
+/// - USBGenericRequest_SETINTERFACE
+/// - USBGenericRequest_SYNCHFRAME
+///
+/// - USB Request Recipients
+/// - USBGenericRequest_DEVICE
+/// - USBGenericRequest_INTERFACE
+/// - USBGenericRequest_ENDPOINT
+/// - USBGenericRequest_OTHER
+///
+/// - USB Request Types
+/// - USBGenericRequest_STANDARD
+/// - USBGenericRequest_CLASS
+/// - USBGenericRequest_VENDOR
+///
+/// - USB Request Directions
+/// - USBGenericRequest_IN
+/// - USBGenericRequest_OUT
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Request codes"
+///
+/// This page lists the USB generic request codes.
+///
+/// !Codes
+/// - USBGenericRequest_GETSTATUS
+/// - USBGenericRequest_CLEARFEATURE
+/// - USBGenericRequest_SETFEATURE
+/// - USBGenericRequest_SETADDRESS
+/// - USBGenericRequest_GETDESCRIPTOR
+/// - USBGenericRequest_SETDESCRIPTOR
+/// - USBGenericRequest_GETCONFIGURATION
+/// - USBGenericRequest_SETCONFIGURATION
+/// - USBGenericRequest_GETINTERFACE
+/// - USBGenericRequest_SETINTERFACE
+/// - USBGenericRequest_SYNCHFRAME
+
+/// GET_STATUS request code.
+#define USBGenericRequest_GETSTATUS 0
+/// CLEAR_FEATURE request code.
+#define USBGenericRequest_CLEARFEATURE 1
+/// SET_FEATURE request code.
+#define USBGenericRequest_SETFEATURE 3
+/// SET_ADDRESS request code.
+#define USBGenericRequest_SETADDRESS 5
+/// GET_DESCRIPTOR request code.
+#define USBGenericRequest_GETDESCRIPTOR 6
+/// SET_DESCRIPTOR request code.
+#define USBGenericRequest_SETDESCRIPTOR 7
+/// GET_CONFIGURATION request code.
+#define USBGenericRequest_GETCONFIGURATION 8
+/// SET_CONFIGURATION request code.
+#define USBGenericRequest_SETCONFIGURATION 9
+/// GET_INTERFACE request code.
+#define USBGenericRequest_GETINTERFACE 10
+/// SET_INTERFACE request code.
+#define USBGenericRequest_SETINTERFACE 11
+/// SYNCH_FRAME request code.
+#define USBGenericRequest_SYNCHFRAME 12
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Request Recipients"
+///
+/// This page lists codes of USB request recipients.
+///
+/// !Recipients
+/// - USBGenericRequest_DEVICE
+/// - USBGenericRequest_INTERFACE
+/// - USBGenericRequest_ENDPOINT
+/// - USBGenericRequest_OTHER
+
+/// Recipient is the whole device.
+#define USBGenericRequest_DEVICE 0
+/// Recipient is an interface.
+#define USBGenericRequest_INTERFACE 1
+/// Recipient is an endpoint.
+#define USBGenericRequest_ENDPOINT 2
+/// Recipient is another entity.
+#define USBGenericRequest_OTHER 3
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Request Types"
+///
+/// This page lists codes of USB request types.
+///
+/// !Types
+/// - USBGenericRequest_STANDARD
+/// - USBGenericRequest_CLASS
+/// - USBGenericRequest_VENDOR
+
+/// Request is standard.
+#define USBGenericRequest_STANDARD 0
+/// Request is class-specific.
+#define USBGenericRequest_CLASS 1
+/// Request is vendor-specific.
+#define USBGenericRequest_VENDOR 2
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB Request Directions"
+///
+/// This page lists codes of USB request directions.
+///
+/// !Directions
+/// - USBGenericRequest_IN
+/// - USBGenericRequest_OUT
+
+/// Transfer occurs from device to the host.
+#define USBGenericRequest_OUT 0
+/// Transfer occurs from the host to the device.
+#define USBGenericRequest_IN 1
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Generic USB SETUP request sent over Control endpoints.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Type of request
+ /// \sa "USB Request Recipients"
+ /// \sa "USB Request Types"
+ /// \sa "USB Request Directions"
+ unsigned char bmRequestType:8;
+ /// Request code
+ /// \sa "USB Request Codes"
+ unsigned char bRequest:8;
+ /// Request-specific value parameter.
+ unsigned short wValue:16;
+ /// Request-specific index parameter.
+ unsigned short wIndex:16;
+ /// Expected length (in bytes) of the data phase.
+ unsigned short wLength:16;
+
+} USBGenericRequest;
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBGenericRequest_GetType(
+ const USBGenericRequest *request);
+
+
+extern unsigned char USBGenericRequest_GetRequest(
+ const USBGenericRequest *request);
+
+extern unsigned short USBGenericRequest_GetValue(
+ const USBGenericRequest *request);
+
+extern unsigned short USBGenericRequest_GetIndex(
+ const USBGenericRequest *request);
+
+extern unsigned short USBGenericRequest_GetLength(
+ const USBGenericRequest *request);
+
+extern unsigned char USBGenericRequest_GetEndpointNumber(
+ const USBGenericRequest *request);
+
+extern unsigned char USBGenericRequest_GetRecipient(
+ const USBGenericRequest *request);
+
+extern unsigned char USBGenericRequest_GetDirection(
+ const USBGenericRequest *request);
+
+#endif //#ifndef USBGENERICREQUEST_H
+
diff --git a/usb/common/core/USBGetDescriptorRequest.c b/usb/common/core/USBGetDescriptorRequest.c new file mode 100644 index 0000000..2937929 --- /dev/null +++ b/usb/common/core/USBGetDescriptorRequest.c @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBGetDescriptorRequest implementation
+
+ About: Purpose
+ Implementation of the USBGetDescriptorRequest class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGetDescriptorRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the type of the descriptor requested by the host given the
+/// corresponding GET_DESCRIPTOR request.
+/// \param request Pointer to a USBGenericDescriptor instance.
+/// \return Type of the requested descriptor.
+//------------------------------------------------------------------------------
+unsigned char USBGetDescriptorRequest_GetDescriptorType(
+ const USBGenericRequest *request)
+{
+ // Requested descriptor type is in the high-byte of the wValue field
+ return (USBGenericRequest_GetValue(request) >> 8) & 0xFF;
+}
+
+//------------------------------------------------------------------------------
+/// Returns the index of the requested descriptor, given the corresponding
+/// GET_DESCRIPTOR request.
+/// \param request Pointer to a USBGenericDescriptor instance.
+/// \return Index of the requested descriptor.
+//------------------------------------------------------------------------------
+unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
+ const USBGenericRequest *request)
+{
+ // Requested descriptor index if in the low byte of the wValue field
+ return USBGenericRequest_GetValue(request) & 0xFF;
+}
+
diff --git a/usb/common/core/USBGetDescriptorRequest.h b/usb/common/core/USBGetDescriptorRequest.h new file mode 100644 index 0000000..43f6afd --- /dev/null +++ b/usb/common/core/USBGetDescriptorRequest.h @@ -0,0 +1,67 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of the USBGetDescriptorRequest class.
+
+ !!!Usage
+
+ - After a GET_DESCRIPTOR request has been received, retrive the useful
+ values with following functions:
+ - USBGetDescriptorRequest_GetDescriptorType: the descriptor type
+ - USBGetDescriptorRequest_GetDescriptorIndex: the index of the requested
+ descriptor
+
+*/
+
+#ifndef USBGETDESCRIPTORREQUEST_H
+#define USBGETDESCRIPTORREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBGetDescriptorRequest_GetDescriptorType(
+ const USBGenericRequest *request);
+
+extern unsigned char USBGetDescriptorRequest_GetDescriptorIndex(
+ const USBGenericRequest *request);
+
+#endif //#ifndef USBGETDESCRIPTORREQUEST_H
+
diff --git a/usb/common/core/USBInterfaceAssociationDescriptor.h b/usb/common/core/USBInterfaceAssociationDescriptor.h new file mode 100644 index 0000000..5f3dd21 --- /dev/null +++ b/usb/common/core/USBInterfaceAssociationDescriptor.h @@ -0,0 +1,86 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/**
+ * \page USBInterfaceAssociateDescriptor
+ * !!!Purpose
+ *
+ * Class for manipulating USB IAD descriptors.
+ *
+ * !!!Usage
+ *
+ * -# Test
+ */
+
+#ifndef USBDIADDESCRIPTOR_H
+#define USBDIADDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+/*
+ Type: USBDeviceDescriptor
+ USB standard device descriptor structure.
+
+ Variables:
+ bLength - Size of this descriptor in bytes.
+ bDescriptorType - Descriptor type (<USBGenericDescriptor_IAD>).
+ bFirstInterface - Interface number of the first interface that is
+ associated with this function.
+ bInterfaceCount - Number of contiguous interfaces that are
+ associated with this function.
+ bFunctionClass - Class code (assigned by USB-IF).
+ bFunctionSubClass - Subclass code (assigned by USB-IF).
+ bFunctionProtocol - Protocol code (assigned by USB-IF)
+ iFunction - Index of string descriptor describing this function.
+*/
+typedef struct {
+
+ unsigned char bLength;
+ unsigned char bDescriptorType;
+ unsigned char bFirstInterface;
+ unsigned char bInterfaceCount;
+ unsigned char bFunctionClass;
+ unsigned char bFunctionSubClass;
+ unsigned char bFunctionProtocol;
+ unsigned char iFunction;
+} __attribute__ ((packed)) USBInterfaceAssociationDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef USBDIADDESCRIPTOR_H
+
diff --git a/usb/common/core/USBInterfaceDescriptor.h b/usb/common/core/USBInterfaceDescriptor.h new file mode 100644 index 0000000..63910bf --- /dev/null +++ b/usb/common/core/USBInterfaceDescriptor.h @@ -0,0 +1,87 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating USB interface descriptors.
+
+ !!!Usage
+
+ - Declare USBInterfaceDescriptor instance as a part of the configuration
+ descriptors of a USB device.
+
+*/
+
+#ifndef USBINTERFACEDESCRIPTOR_H
+#define USBINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// USB standard interface descriptor structure.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of the descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (USBGenericDescriptor_INTERFACE).
+ unsigned char bDescriptorType;
+ /// Number of the interface in its configuration.
+ unsigned char bInterfaceNumber;
+ /// Value to select this alternate interface setting.
+ unsigned char bAlternateSetting;
+ /// Number of endpoints used by the inteface (excluding endpoint 0).
+ unsigned char bNumEndpoints;
+ /// Interface class code.
+ unsigned char bInterfaceClass;
+ /// Interface subclass code.
+ unsigned char bInterfaceSubClass;
+ /// Interface protocol code.
+ unsigned char bInterfaceProtocol;
+ /// Index of the interface string descriptor.
+ unsigned char iInterface;
+
+} __attribute__ ((packed)) USBInterfaceDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef USBINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/core/USBInterfaceRequest.c b/usb/common/core/USBInterfaceRequest.c new file mode 100644 index 0000000..61bf6ed --- /dev/null +++ b/usb/common/core/USBInterfaceRequest.c @@ -0,0 +1,69 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBInterfaceRequest
+
+ About: Purpose
+ Implementation of USBInterfaceRequest class methods.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBInterfaceRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Indicates which interface is targetted by a GET_INTERFACE or
+/// SET_INTERFACE request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Interface number.
+//------------------------------------------------------------------------------
+unsigned char USBInterfaceRequest_GetInterface(const USBGenericRequest *request)
+{
+ return (USBGenericRequest_GetIndex(request) & 0xFF);
+}
+
+//------------------------------------------------------------------------------
+/// Indicates the new alternate setting that the interface targetted by a
+/// SET_INTERFACE request should use.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return New active setting for the interface.
+//------------------------------------------------------------------------------
+unsigned char USBInterfaceRequest_GetAlternateSetting(
+ const USBGenericRequest *request)
+{
+ return (USBGenericRequest_GetValue(request) & 0xFF);
+}
+
diff --git a/usb/common/core/USBInterfaceRequest.h b/usb/common/core/USBInterfaceRequest.h new file mode 100644 index 0000000..bd4cddd --- /dev/null +++ b/usb/common/core/USBInterfaceRequest.h @@ -0,0 +1,68 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions for manipulating SET_INTERFACE and GET_INTERFACE request.
+
+ !!!Usage
+
+ -# After a SET_INTERFACE request has been received, retrieve the
+ target interface using USBInterfaceRequest_GetInterface and its
+ new alternate setting with USBInterfaceRequest_GetAlternateSetting.
+ -# After a GET_INTERFACE request has been received, retrieve the target
+ interface using USBInterfaceRequest_GetInterface.
+
+*/
+
+#ifndef USBINTERFACEREQUEST_H
+#define USBINTERFACEREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBInterfaceRequest_GetInterface(
+ const USBGenericRequest *request);
+
+
+extern unsigned char USBInterfaceRequest_GetAlternateSetting(
+ const USBGenericRequest *request);
+
+#endif //#ifndef USBINTERFACEREQUEST_H
+
diff --git a/usb/common/core/USBIrqHandler.c b/usb/common/core/USBIrqHandler.c new file mode 100644 index 0000000..386ebd2 --- /dev/null +++ b/usb/common/core/USBIrqHandler.c @@ -0,0 +1,62 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBIrqHandler implementation
+
+ About: Purpose
+ Implementation of the USB Interrupt Handler.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+#include <board.h>
+#include <usb/device/core/USBD.h>
+
+#include <exceptions.h>
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+/// Call Arbitrer, device and host interrupt handler.
+/// The IRQ functions are defined with weak and can be surcharged if needed.
+//------------------------------------------------------------------------------
+void USB_IrqHandler( void )
+{
+ // Most arbitrer interrupt
+ usb_general_interrupt();
+ // Device interrupt
+ USBD_IrqHandler();
+ // Host interrupt
+ usb_pipe_interrupt();
+}
+
+
diff --git a/usb/common/core/USBIrqHandler.h b/usb/common/core/USBIrqHandler.h new file mode 100644 index 0000000..77d2679 --- /dev/null +++ b/usb/common/core/USBIrqHandler.h @@ -0,0 +1,52 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Implementation of the USB Interrupt Handler.
+
+ !!!Usage
+
+ -# The IRQ functions are defined with weak and can be surcharged if needed.
+
+*/
+
+#ifndef USBIRQHANDLER_H
+#define USBIRQHANDLER_H
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+extern void USB_IrqHandler( void );
+
+#endif //#ifndef USBIRQHANDLER_H
+
diff --git a/usb/common/core/USBSetAddressRequest.c b/usb/common/core/USBSetAddressRequest.c new file mode 100644 index 0000000..0e82a7f --- /dev/null +++ b/usb/common/core/USBSetAddressRequest.c @@ -0,0 +1,56 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBSetAddressRequest implementation
+
+ About: Purpose
+ Implementation of the USBSetAddressRequest class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBSetAddressRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+/// Returns the address that the device must take in response to a
+/// SET_ADDRESS request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return New device address.
+//------------------------------------------------------------------------------
+unsigned char USBSetAddressRequest_GetAddress(const USBGenericRequest *request)
+{
+ return USBGenericRequest_GetValue(request) & 0x7F;
+}
+
diff --git a/usb/common/core/USBSetAddressRequest.h b/usb/common/core/USBSetAddressRequest.h new file mode 100644 index 0000000..78034c3 --- /dev/null +++ b/usb/common/core/USBSetAddressRequest.h @@ -0,0 +1,60 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating SET_ADDRESS USB requests.
+
+ !!!Usage
+
+ - After a SET_ADDRESS request has been received, retrive the new address
+ value with USBSetAddressRequest_GetAddress.
+*/
+
+#ifndef USBSETADDRESSREQUEST_H
+#define USBSETADDRESSREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBSetAddressRequest_GetAddress(
+ const USBGenericRequest *request);
+
+#endif //#ifndef USBSETADDRESSREQUEST_H
+
diff --git a/usb/common/core/USBSetConfigurationRequest.c b/usb/common/core/USBSetConfigurationRequest.c new file mode 100644 index 0000000..3aa747d --- /dev/null +++ b/usb/common/core/USBSetConfigurationRequest.c @@ -0,0 +1,58 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: USBSetConfigurationRequest implementation
+
+ About: Purpose
+ Implementation of the USBSetConfigurationRequest class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBSetConfigurationRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Returns the number of the configuration that should be set in response
+/// to the given SET_CONFIGURATION request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Number of the requested configuration.
+//------------------------------------------------------------------------------
+unsigned char USBSetConfigurationRequest_GetConfiguration(
+ const USBGenericRequest *request)
+{
+ return USBGenericRequest_GetValue(request);
+}
+
diff --git a/usb/common/core/USBSetConfigurationRequest.h b/usb/common/core/USBSetConfigurationRequest.h new file mode 100644 index 0000000..aa1fa17 --- /dev/null +++ b/usb/common/core/USBSetConfigurationRequest.h @@ -0,0 +1,61 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for the Set Configuration request.
+
+ !!!Usage
+
+ - After a SET_CONFIGURATION request has been received, retrive the new
+ configuration value with USBSetConfigurationRequest_GetConfiguration.
+
+*/
+
+#ifndef USBSETCONFIGURATIONREQUEST_H
+#define USBSETCONFIGURATIONREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "USBGenericRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char USBSetConfigurationRequest_GetConfiguration(
+ const USBGenericRequest *request);
+
+#endif //#ifndef USBSETCONFIGURATIONREQUEST_H
+
diff --git a/usb/common/core/USBStringDescriptor.h b/usb/common/core/USBStringDescriptor.h new file mode 100644 index 0000000..bcf4b83 --- /dev/null +++ b/usb/common/core/USBStringDescriptor.h @@ -0,0 +1,74 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definition of a class for manipulating String descriptors.
+//------------------------------------------------------------------------------
+
+#ifndef USBSTRINGDESCRIPTOR_H
+#define USBSTRINGDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "USB String Descriptor definitions"
+///
+/// This page lists the codes and macros for USB string descriptor definition.
+///
+/// !Language IDs
+/// - USBStringDescriptor_ENGLISH_US
+///
+/// !String Descriptor Length
+/// - USBStringDescriptor_LENGTH
+///
+/// !ASCII to UNICODE convertion
+/// - USBStringDescriptor_UNICODE
+
+/// Language ID for US english.
+#define USBStringDescriptor_ENGLISH_US 0x09, 0x04
+
+/// Calculates the length of a string descriptor given the number of ascii
+/// characters/language IDs in it.
+/// \param length The ascii format string length.
+/// \return The actual data length in bytes.
+#define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
+/// Converts an ascii character to its unicode representation.
+/// \param ascii The ASCII character to convert
+/// \return A 2-byte-array for the UNICODE based on given ASCII
+#define USBStringDescriptor_UNICODE(ascii) (ascii), 0
+//------------------------------------------------------------------------------
+
+#endif //#ifndef USBSTRINGDESCRIPTOR_H
+
diff --git a/usb/common/core/core.dir b/usb/common/core/core.dir new file mode 100644 index 0000000..7ac93c3 --- /dev/null +++ b/usb/common/core/core.dir @@ -0,0 +1,53 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+/// !!!Purpose
+///
+/// This directory contains definitions, structures and functions described by
+/// USB specification. They can be divided into two groups:
+/// - USB descriptors, prefixed with USB and suffixed with Descriptor.
+/// - USB requests, prefixed with USB and suffixed with Request.
+//------------------------------------------------------------------------------
+
+/**
+ \page "Standard USB Structures"
+
+ !!!Standard USB Structures
+
+ The following standard structures is implemented in the USB framework:
+ - Setup request data: USBGenericRequest
+ - Descriptor header: USBGenericDescriptor
+ - Device descriptor: USBDeviceDescriptor
+ - Configuration descriptor: USBConfigurationDescriptor
+ - Interface descriptor: USBInterfaceDescriptor
+ - %Endpoint descriptor: USBEndpointDescriptor
+ - Device_Qualifier descriptor: USBDeviceQualifierDescriptor
+*/
diff --git a/usb/common/hid/HIDButton.h b/usb/common/hid/HIDButton.h new file mode 100644 index 0000000..ea2557a --- /dev/null +++ b/usb/common/hid/HIDButton.h @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: HIDButton
+
+ About: Purpose
+ Definitions of constants and methods for the HID Button usage page.
+
+ About: Usage
+ 1 - Use the constants declared in this file when instanciating a
+ Report descriptor instance.
+ 2 - When implementing the functionality of an HID Mouse, use the
+ key codes defined here to indicate keys that are being pressed and
+ released.
+*/
+
+#ifndef _HIDBUTTON_H
+#define _HIDBUTTON_H
+
+//------------------------------------------------------------------------------
+// Constants
+//------------------------------------------------------------------------------
+
+/// Identifier for the HID button usage page
+#define HIDButton_PAGEID 0x09
+
+
+#endif
diff --git a/usb/common/hid/HIDDescriptor.h b/usb/common/hid/HIDDescriptor.h new file mode 100644 index 0000000..ae00102 --- /dev/null +++ b/usb/common/hid/HIDDescriptor.h @@ -0,0 +1,93 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Methods and definitions for manipulating a HID descriptor.
+*/
+
+#ifndef HIDDESCRIPTOR_H
+#define HIDDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Release Numbers"
+/// ...
+///
+/// !Numbers
+/// - HIDDescriptor_HID1_11
+
+/// Identifies version 1.11 of the HID specification.
+#define HIDDescriptor_HID1_11 0x0111
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// Identifies the length of type of subordinate descriptors of a HID
+/// device. This particular type only supports one subordinate descriptor.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// Size of descriptor in bytes.
+ unsigned char bLength;
+ /// Descriptor type (HIDGenericDescriptor_HID).
+ unsigned char bDescriptorType;
+ /// HID class specification release number in BCD format.
+ unsigned short bcdHID;
+ /// Country code of the device if it is localized.
+ unsigned char bCountryCode;
+ /// Number of subordinate descriptors.
+ unsigned char bNumDescriptors;
+ /// Type of the first subordinate descriptor.
+ unsigned char bDescriptorType0;
+ /// Size in bytes of the first subordinate descriptor.
+ unsigned short wDescriptorLength0;
+
+} __attribute__ ((packed)) HIDDescriptor; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+#endif //#ifndef HIDDESCRIPTOR_H
+
diff --git a/usb/common/hid/HIDDeviceDescriptor.h b/usb/common/hid/HIDDeviceDescriptor.h new file mode 100644 index 0000000..267c73e --- /dev/null +++ b/usb/common/hid/HIDDeviceDescriptor.h @@ -0,0 +1,68 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions used for declaring the device descriptor of a HID device.
+
+ !!!Usage
+
+ Use this constants when defining an instance of USBDeviceDescriptor for
+ an HID device.
+*/
+
+#ifndef HIDDEVICEDESCRIPTOR_H
+#define HIDDEVICEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Device Descriptor Codes"
+/// This page lists HID device class, subclass and protocol codes.
+///
+/// !Codes
+/// - HIDDeviceDescriptor_CLASS
+/// - HIDDeviceDescriptor_SUBCLASS
+/// - HIDDeviceDescriptor_PROTOCOL
+
+/// Class code for a HID device.
+#define HIDDeviceDescriptor_CLASS 0
+/// Subclass code for a HID device.
+#define HIDDeviceDescriptor_SUBCLASS 0
+/// Protocol code for a HID device.
+#define HIDDeviceDescriptor_PROTOCOL 0
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDDEVICEDESCRIPTOR_H
+
diff --git a/usb/common/hid/HIDGenericDescriptor.h b/usb/common/hid/HIDGenericDescriptor.h new file mode 100644 index 0000000..2324d53 --- /dev/null +++ b/usb/common/hid/HIDGenericDescriptor.h @@ -0,0 +1,63 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions for using HID-specific descriptors.
+*/
+
+#ifndef HIDGENERICDESCRIPTOR_H
+#define HIDGENERICDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Descriptors Types"
+/// ...
+///
+/// !Types
+/// - HIDGenericDescriptor_HID
+/// - HIDGenericDescriptor_REPORT
+/// - HIDGenericDescriptor_PHYSICAL
+
+/// HID descriptor type.
+#define HIDGenericDescriptor_HID 0x21
+/// Report descriptor type.
+#define HIDGenericDescriptor_REPORT 0x22
+/// Physical descriptor type.
+#define HIDGenericDescriptor_PHYSICAL 0x23
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDGENERICDESCRIPTOR_H
+
diff --git a/usb/common/hid/HIDGenericDesktop.h b/usb/common/hid/HIDGenericDesktop.h new file mode 100644 index 0000000..ac1165c --- /dev/null +++ b/usb/common/hid/HIDGenericDesktop.h @@ -0,0 +1,98 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Constants for using the HID generic desktop usage page.
+
+ !!!Usage
+
+ Use these constants when declaring a Report descriptor which references
+ the generic desktop page.
+*/
+
+#ifndef HIDGENERICDESKTOP_H
+#define HIDGENERICDESKTOP_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID GenericDesktop Page ID"
+/// ...
+///
+/// !ID
+/// - HIDGenericDesktop_PAGEID
+
+/// ID for the HID generic desktop usage page.
+#define HIDGenericDesktop_PAGEID 0x01
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID GenericDesktop Usages"
+/// ...
+///
+/// !Usages
+/// - HIDGenericDesktop_POINTER
+/// - HIDGenericDesktop_MOUSE
+/// - HIDGenericDesktop_JOYSTICK
+/// - HIDGenericDesktop_GAMEPAD
+/// - HIDGenericDesktop_KEYBOARD
+/// - HIDGenericDesktop_KEYPAD
+/// - HIDGenericDesktop_MULTIAXIS
+/// - HIDGenericDesktop_X
+/// - HIDGenericDesktop_Y
+
+/// Pointer usage ID.
+#define HIDGenericDesktop_POINTER 0x01
+/// Mouse usage ID.
+#define HIDGenericDesktop_MOUSE 0x02
+/// Joystick usage ID.
+#define HIDGenericDesktop_JOYSTICK 0x04
+/// Gamepad usage ID.
+#define HIDGenericDesktop_GAMEPAD 0x05
+/// Keyboard usage ID.
+#define HIDGenericDesktop_KEYBOARD 0x06
+/// Keypad usage ID.
+#define HIDGenericDesktop_KEYPAD 0x07
+/// Multi-axis controller usage ID.
+#define HIDGenericDesktop_MULTIAXIS 0x08
+
+/// Axis Usage X direction ID.
+#define HIDGenericDesktop_X 0x30
+/// Axis Usage Y direction ID.
+#define HIDGenericDesktop_Y 0x31
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDGENERICDESKTOP_H
+
diff --git a/usb/common/hid/HIDGenericRequest.h b/usb/common/hid/HIDGenericRequest.h new file mode 100644 index 0000000..356f498 --- /dev/null +++ b/usb/common/hid/HIDGenericRequest.h @@ -0,0 +1,75 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: HIDGenericRequest
+
+ About: Purpose
+ Definition of constants for using HID-specific requests.
+
+ About: Usage
+ When constructing or receiving an HID SETUP request, use the request
+ codes provided by this header file.
+*/
+
+#ifndef HIDGENERICREQUEST_H
+#define HIDGENERICREQUEST_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Request Codes"
+/// ...
+///
+/// !Codes
+/// - HIDGenericRequest_GETREPORT
+/// - HIDGenericRequest_GETIDLE
+/// - HIDGenericRequest_GETPROTOCOL
+/// - HIDGenericRequest_SETREPORT
+/// - HIDGenericRequest_SETIDLE
+/// - HIDGenericRequest_SETPROTOCOL
+
+/// GetReport request code.
+#define HIDGenericRequest_GETREPORT 0x01
+/// GetIdle request code.
+#define HIDGenericRequest_GETIDLE 0x02
+/// GetProtocol request code.
+#define HIDGenericRequest_GETPROTOCOL 0x03
+/// SetReport request code.
+#define HIDGenericRequest_SETREPORT 0x09
+/// SetIdle request code.
+#define HIDGenericRequest_SETIDLE 0x0A
+/// SetProtocol request code.
+#define HIDGenericRequest_SETPROTOCOL 0x0B
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDGENERICREQUEST_H
+
diff --git a/usb/common/hid/HIDIdleRequest.c b/usb/common/hid/HIDIdleRequest.c new file mode 100644 index 0000000..640f2d5 --- /dev/null +++ b/usb/common/hid/HIDIdleRequest.c @@ -0,0 +1,56 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: HIDIdleRequest implementation
+
+ About: Purpose
+ Implementation of the HIDIdleRequest methods.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "HIDIdleRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Retrieves the Idle rate (in milliseconds) indicated by a SET_IDLE
+/// request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return New idle rate for the report.
+//------------------------------------------------------------------------------
+unsigned char HIDIdleRequest_GetIdleRate(const USBGenericRequest *request)
+{
+ return ((USBGenericRequest_GetValue(request) >> 8) & 0xFF);
+}
diff --git a/usb/common/hid/HIDIdleRequest.h b/usb/common/hid/HIDIdleRequest.h new file mode 100644 index 0000000..1f9a361 --- /dev/null +++ b/usb/common/hid/HIDIdleRequest.h @@ -0,0 +1,68 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Methods and constants for manipulating HID-specific GET_IDLE and SET_IDLE
+ requests.
+
+ !!!Usage
+
+ -# Retrieve the idle rate indicated by a GET_IDLE or SET_IDLE request
+ with HIDIdleRequest_GetIdleRate.
+*/
+
+#ifndef HIDIDLEREQUEST_H
+#define HIDIDLEREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+/// Infinite idle rate.
+#define HIDIdleRequest_INFINITE 0
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char HIDIdleRequest_GetIdleRate(
+ const USBGenericRequest *request);
+
+#endif //#ifndef HIDIDLEREQUEST_H
+
diff --git a/usb/common/hid/HIDInterfaceDescriptor.h b/usb/common/hid/HIDInterfaceDescriptor.h new file mode 100644 index 0000000..4ef1bc7 --- /dev/null +++ b/usb/common/hid/HIDInterfaceDescriptor.h @@ -0,0 +1,77 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Constants used when declaring an HID interface.
+
+ !!!Usage
+
+ Use the constants defined here when declaring a USBInterfaceDescriptor
+ instance for a HID interface.
+*/
+
+#ifndef HIDINTERFACEDESCRIPTOR_H
+#define HIDINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Interface Descriptor Codes"
+/// This page lists HID Interface class, subclass and protocol codes.
+///
+/// !Codes
+/// - HIDInterfaceDescriptor_CLASS
+/// - HIDInterfaceDescriptor_SUBCLASS_NONE
+/// - HIDInterfaceDescriptor_SUBCLASS_BOOT
+/// - HIDInterfaceDescriptor_PROTOCOL_NONE
+/// - HIDInterfaceDescriptor_PROTOCOL_KEYBOARD
+/// - HIDInterfaceDescriptor_PROTOCOL_MOUSE
+
+/// HID interface class code.
+#define HIDInterfaceDescriptor_CLASS 0x03
+/// Indicates the interface does not implement a particular subclass.
+#define HIDInterfaceDescriptor_SUBCLASS_NONE 0x00
+/// Indicates the interface is compliant with the boot specification.
+#define HIDInterfaceDescriptor_SUBCLASS_BOOT 0x01
+/// Indicates the interface does not implement a particular protocol.
+#define HIDInterfaceDescriptor_PROTOCOL_NONE 0x00
+/// Indicates the interface supports the boot specification as a keyboard.
+#define HIDInterfaceDescriptor_PROTOCOL_KEYBOARD 0x01
+/// Indicates the interface supports the boot specification as a mouse.
+#define HIDInterfaceDescriptor_PROTOCOL_MOUSE 0x02
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/hid/HIDKeypad.c b/usb/common/hid/HIDKeypad.c new file mode 100644 index 0000000..19f533e --- /dev/null +++ b/usb/common/hid/HIDKeypad.c @@ -0,0 +1,56 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: HIDKeypad implementation
+
+ About: Purpose
+ Implementation of HID keypad usage page methods.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "HIDKeypad.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Indicates if the given key code is associated with a modified key.
+/// \param key Key code.
+/// \return 1 if the key code represents a modifier key; otherwise 0.
+//------------------------------------------------------------------------------
+unsigned char HIDKeypad_IsModifierKey(unsigned char key)
+{
+ return ((key >= HIDKeypad_LEFTCONTROL) && (key <= HIDKeypad_RIGHTGUI));
+}
+
diff --git a/usb/common/hid/HIDKeypad.h b/usb/common/hid/HIDKeypad.h new file mode 100644 index 0000000..06ad747 --- /dev/null +++ b/usb/common/hid/HIDKeypad.h @@ -0,0 +1,276 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions of constants and methods for the HID keypad usage page.
+
+ !!!Usage
+
+ -# Use the constants declared in this file when instanciating a
+ Report descriptor instance.
+ -# When implementing the functionality of an HID keyboard, use the
+ key codes defined here to indicate keys that are being pressed and
+ released.
+*/
+
+#ifndef HIDKEYPAD_H
+#define HIDKEYPAD_H
+
+//------------------------------------------------------------------------------
+// Constants
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Keypad Page ID"
+/// This page lists HID Keypad page ID.
+///
+/// !ID
+/// - HIDKeypad_PAGEID
+
+/// Identifier for the HID keypad usage page
+#define HIDKeypad_PAGEID 0x07
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Alphabetic Keys"
+/// ...
+///
+/// !Keys
+/// - HIDKeypad_A
+/// - HIDKeypad_B
+/// - HIDKeypad_C
+/// - HIDKeypad_D
+/// - HIDKeypad_E
+/// - HIDKeypad_F
+/// - HIDKeypad_G
+/// - HIDKeypad_H
+/// - HIDKeypad_I
+/// - HIDKeypad_J
+/// - HIDKeypad_K
+/// - HIDKeypad_L
+/// - HIDKeypad_M
+/// - HIDKeypad_N
+/// - HIDKeypad_O
+/// - HIDKeypad_P
+/// - HIDKeypad_Q
+/// - HIDKeypad_R
+/// - HIDKeypad_S
+/// - HIDKeypad_T
+/// - HIDKeypad_U
+/// - HIDKeypad_V
+/// - HIDKeypad_W
+/// - HIDKeypad_X
+/// - HIDKeypad_Y
+/// - HIDKeypad_Z
+
+/// Key code for 'a' and 'A'.
+#define HIDKeypad_A 4
+/// Key code for 'b' and 'B'.
+#define HIDKeypad_B 5
+/// Key code for 'c' and 'C'.
+#define HIDKeypad_C 6
+/// Key code for 'd' and 'D'.
+#define HIDKeypad_D 7
+/// Key code for 'e' and 'E'.
+#define HIDKeypad_E 8
+/// Key code for 'f' and 'F'.
+#define HIDKeypad_F 9
+/// Key code for 'g' and 'G'.
+#define HIDKeypad_G 10
+/// Key code for 'h' and 'H'.
+#define HIDKeypad_H 11
+/// Key code for 'i' and 'I'.
+#define HIDKeypad_I 12
+/// Key code for 'j' and 'J'.
+#define HIDKeypad_J 13
+/// Key code for 'k' and 'K'.
+#define HIDKeypad_K 14
+/// Key code for 'l' and 'L'.
+#define HIDKeypad_L 15
+/// Key code for 'm' and 'M'.
+#define HIDKeypad_M 16
+/// Key code for 'n' and 'N'.
+#define HIDKeypad_N 17
+/// Key code for 'o' and 'O'.
+#define HIDKeypad_O 18
+/// Key code for 'p' and 'P'.
+#define HIDKeypad_P 19
+/// Key code for 'q' and 'Q'.
+#define HIDKeypad_Q 20
+/// Key code for 'r' and 'R'.
+#define HIDKeypad_R 21
+/// Key code for 's' and 'S'.
+#define HIDKeypad_S 22
+/// Key code for 't' and 'T'.
+#define HIDKeypad_T 23
+/// Key code for 'u' and 'U'.
+#define HIDKeypad_U 24
+/// Key code for 'v' and 'V'.
+#define HIDKeypad_V 25
+/// Key code for 'w' and 'W'.
+#define HIDKeypad_W 26
+/// Key code for 'x' and 'X'.
+#define HIDKeypad_X 27
+/// Key code for 'y' and 'Y'.
+#define HIDKeypad_Y 28
+/// Key code for 'z' and 'Z'.
+#define HIDKeypad_Z 29
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Numeric Keys"
+/// ...
+///
+/// !Keys
+/// - HIDKeypad_1
+/// - HIDKeypad_2
+/// - HIDKeypad_3
+/// - HIDKeypad_4
+/// - HIDKeypad_5
+/// - HIDKeypad_6
+/// - HIDKeypad_7
+/// - HIDKeypad_8
+/// - HIDKeypad_9
+/// - HIDKeypad_0
+
+/// Key code for '1' and '!'.
+#define HIDKeypad_1 30
+/// Key code for '2' and '@'.
+#define HIDKeypad_2 31
+/// Key code for '3' and '#'.
+#define HIDKeypad_3 32
+/// Key code for '4' and '$'.
+#define HIDKeypad_4 33
+/// Key code for '5' and '%'.
+#define HIDKeypad_5 34
+/// Key code for '6' and '^'.
+#define HIDKeypad_6 35
+/// Key code for '7' and '&'.
+#define HIDKeypad_7 36
+/// Key code for '8' and '*'.
+#define HIDKeypad_8 37
+/// Key code for '9' and '('.
+#define HIDKeypad_9 38
+/// Key code for '0' and ')'.
+#define HIDKeypad_0 39
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Special Keys"
+/// ...
+///
+/// !Keys
+/// - HIDKeypad_ENTER
+/// - HIDKeypad_ESCAPE
+/// - HIDKeypad_BACKSPACE
+/// - HIDKeypad_TAB
+/// - HIDKeypad_SPACEBAR
+/// - HIDKeypad_PRINTSCREEN
+/// - HIDKeypad_SCROLLLOCK
+/// - HIDKeypad_NUMLOCK
+
+/// Enter key code.
+#define HIDKeypad_ENTER 40
+/// Escape key code.
+#define HIDKeypad_ESCAPE 41
+/// Backspace key code.
+#define HIDKeypad_BACKSPACE 42
+/// Tab key code.
+#define HIDKeypad_TAB 43
+/// Spacebar key code.
+#define HIDKeypad_SPACEBAR 44
+/// Printscreen key code.
+#define HIDKeypad_PRINTSCREEN 70
+/// Scroll lock key code.
+#define HIDKeypad_SCROLLLOCK 71
+/// Num lock key code.
+#define HIDKeypad_NUMLOCK 83
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Modified Keys"
+/// ...
+///
+/// !Keys
+/// - HIDKeypad_LEFTCONTROL
+/// - HIDKeypad_LEFTSHIFT
+/// - HIDKeypad_LEFTALT
+/// - HIDKeypad_LEFTGUI
+/// - HIDKeypad_RIGHTCONTROL
+/// - HIDKeypad_RIGHTSHIFT
+/// - HIDKeypad_RIGHTALT
+/// - HIDKeypad_RIGHTGUI
+
+/// Key code for the left 'Control' key.
+#define HIDKeypad_LEFTCONTROL 224
+/// Key code for the left 'Shift' key.
+#define HIDKeypad_LEFTSHIFT 225
+/// Key code for the left 'Alt' key.
+#define HIDKeypad_LEFTALT 226
+/// Key code for the left 'GUI' (e.g. Windows) key.
+#define HIDKeypad_LEFTGUI 227
+/// Key code for the right 'Control' key.
+#define HIDKeypad_RIGHTCONTROL 228
+/// Key code for the right 'Shift' key.
+#define HIDKeypad_RIGHTSHIFT 229
+/// Key code for the right 'Alt' key.
+#define HIDKeypad_RIGHTALT 230
+/// Key code for the right 'GUI' key.
+#define HIDKeypad_RIGHTGUI 231
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Error Codes"
+/// ...
+///
+/// !Codes
+/// - HIDKeypad_ERRORROLLOVER
+/// - HIDKeypad_POSTFAIL
+/// - HIDKeypad_ERRORUNDEFINED
+
+/// Indicates that too many keys have been pressed at the same time.
+#define HIDKeypad_ERRORROLLOVER 1
+/// ?
+#define HIDKeypad_POSTFAIL 2
+/// Indicates an undefined error.
+#define HIDKeypad_ERRORUNDEFINED 3
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char HIDKeypad_IsModifierKey(unsigned char key);
+
+#endif //#ifndef HIDKEYPAD_H
+
diff --git a/usb/common/hid/HIDLeds.h b/usb/common/hid/HIDLeds.h new file mode 100644 index 0000000..22ee54d --- /dev/null +++ b/usb/common/hid/HIDLeds.h @@ -0,0 +1,79 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition for the HID LEDs usage page.
+
+ !!!Usage
+
+ Uses the constants defined in this header file when declaring a Report
+ descriptor which references the LEDs usage page.
+*/
+
+#ifndef HIDLEDS_H
+#define HIDLEDS_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID LEDs Page ID"
+/// This page lists the page ID of the HID LEDs usage page.
+///
+/// !ID
+/// - HIDLeds_PAGEID
+
+/// ID of the HID LEDs usage page.
+#define HIDLeds_PAGEID 0x08
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID LEDs Usages"
+/// This page lists the Usages of the HID LEDs.
+///
+/// !Usages
+/// - HIDLeds_NUMLOCK
+/// - HIDLeds_CAPSLOCK
+/// - HIDLeds_SCROLLLOCK
+
+/// Num lock LED usage.
+#define HIDLeds_NUMLOCK 0x01
+/// Caps lock LED usage.
+#define HIDLeds_CAPSLOCK 0x02
+/// Scroll lock LED usage.
+#define HIDLeds_SCROLLLOCK 0x03
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDLEDS_H
+
diff --git a/usb/common/hid/HIDReport.h b/usb/common/hid/HIDReport.h new file mode 100644 index 0000000..ec02ded --- /dev/null +++ b/usb/common/hid/HIDReport.h @@ -0,0 +1,231 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definitions used when declaring an HID report descriptor.
+
+ !!!Usage
+
+ Use the definitions provided here when declaring a report descriptor,
+ which shall be an unsigned char array.
+*/
+
+#ifndef HIDREPORT_H
+#define HIDREPORT_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Main Item Tags"
+/// This page lists the Main Item Tags defined for HID %device.
+/// ( HID Spec. 6.2.2 )
+///
+/// !Tags
+/// - HIDReport_INPUT
+/// - HIDReport_OUPUT
+/// - HIDReport_FEATURE
+/// - HIDReport_COLLECTION
+/// - HIDReport_ENDCOLLECTION
+
+/// Input item.
+#define HIDReport_INPUT 0x80
+/// Output item.
+#define HIDReport_OUTPUT 0x90
+/// Feature item.
+#define HIDReport_FEATURE 0xB0
+/// Collection item.
+#define HIDReport_COLLECTION 0xA0
+/// End of collection item.
+#define HIDReport_ENDCOLLECTION 0xC0
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Items for Data Fields"
+/// This page lists defintions for HID Input, Output and Feature items that
+/// are used to create the data fields within a report.
+/// ( HID Spec. 6.2.2.5 )
+///
+/// !Items
+/// - HIDReport_CONSTANT
+/// - HIDReport_VARIABLE
+/// - HIDReport_RELATIVE
+/// - HIDReport_WRAP
+/// - HIDReport_NONLINEAR
+/// - HIDReport_NOPREFERRED
+/// - HIDReport_NULLSTATE
+/// - HIDReport_VOLATILE
+/// - HIDReport_BUFFEREDBYTES
+
+/// The report value is constant (vs. variable).
+#define HIDReport_CONSTANT (1 << 0)
+/// Data reported is a variable (vs. array).
+#define HIDReport_VARIABLE (1 << 1)
+/// Data is relative (vs. absolute).
+#define HIDReport_RELATIVE (1 << 2)
+/// Value rolls over when it reach a maximum/minimum.
+#define HIDReport_WRAP (1 << 3)
+/// Indicates that the data reported has been processed and is no longuer
+/// linear with the original measurements.
+#define HIDReport_NONLINEAR (1 << 4)
+/// Device has no preferred state to which it automatically returns.
+#define HIDReport_NOPREFERRED (1 << 5)
+/// Device has a null state, in which it does not report meaningful
+/// information.
+#define HIDReport_NULLSTATE (1 << 6)
+/// Indicates data can change without the host intervention.
+#define HIDReport_VOLATILE (1 << 7)
+/// Indicates the device produces a fixed-length stream of bytes.
+#define HIDReport_BUFFEREDBYTES (1 << 8)
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Collection Items"
+/// This page lists definitions for HID Collection Items.
+/// ( HID Spec. 6.2.2.6 )
+///
+/// !Items
+/// - HIDReport_COLLECTION_PHYSICAL
+/// - HIDReport_COLLECTION_APPLICATION
+/// - HIDReport_COLLECTION_LOGICAL
+/// - HIDReport_COLLECTION_REPORT
+/// - HIDReport_COLLECTION_NAMEDARRAY
+/// - HIDReport_COLLECTION_USAGESWITCH
+/// - HIDReport_COLLECTION_USAGEMODIFIER
+
+/// Physical collection.
+#define HIDReport_COLLECTION_PHYSICAL 0x00
+/// Application collection.
+#define HIDReport_COLLECTION_APPLICATION 0x01
+/// Logical collection.
+#define HIDReport_COLLECTION_LOGICAL 0x02
+/// Report collection.
+#define HIDReport_COLLECTION_REPORT 0x03
+/// Named array collection.
+#define HIDReport_COLLECTION_NAMEDARRAY 0x04
+/// Usage switch collection.
+#define HIDReport_COLLECTION_USAGESWITCH 0x05
+/// Usage modifier collection
+#define HIDReport_COLLECTION_USAGEMODIFIER 0x06
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Global Items"
+/// This page lists HID Global Items.
+/// ( HID Spec. 6.2.2.7 )
+///
+/// !Items
+/// - HIDReport_GLOBAL_USAGEPAGE
+/// - HIDReport_GLOBAL_LOGICALMINIMUM
+/// - HIDReport_GLOBAL_LOGICALMAXIMUM
+/// - HIDReport_GLOBAL_PHYSICALMINIMUM
+/// - HIDReport_GLOBAL_PHYSICALMAXIMUM
+/// - HIDReport_GLOBAL_UNITEXPONENT
+/// - HIDReport_GLOBAL_UNIT
+/// - HIDReport_GLOBAL_REPORTSIZE
+/// - HIDReport_GLOBAL_REPORTID
+/// - HIDReport_GLOBAL_REPORTCOUNT
+/// - HIDReport_GLOBAL_PUSH
+/// - HIDReport_GLOBAL_POP
+
+/// Current usage page.
+#define HIDReport_GLOBAL_USAGEPAGE 0x04
+/// Minimum value that a variable or array item will report.
+#define HIDReport_GLOBAL_LOGICALMINIMUM 0x14
+/// Maximum value that a variable or array item will report.
+#define HIDReport_GLOBAL_LOGICALMAXIMUM 0x24
+/// Minimum value for the physical extent of a variable item.
+#define HIDReport_GLOBAL_PHYSICALMINIMUM 0x34
+/// Maximum value for the physical extent of a variable item.
+#define HIDReport_GLOBAL_PHYSICALMAXIMUM 0x44
+/// Value of the unit exponent in base 10.
+#define HIDReport_GLOBAL_UNITEXPONENT 0x54
+/// Unit values.
+#define HIDReport_GLOBAL_UNIT 0x64
+/// Size of the report fields in bits.
+#define HIDReport_GLOBAL_REPORTSIZE 0x74
+/// Specifies the report ID.
+#define HIDReport_GLOBAL_REPORTID 0x84
+/// Number of data fields for an item.
+#define HIDReport_GLOBAL_REPORTCOUNT 0x94
+/// Places a copy of the global item state table on the stack.
+#define HIDReport_GLOBAL_PUSH 0xA4
+/// Replaces the item state table with the top structure from the stack.
+#define HIDReport_GLOBAL_POP 0xB4
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Local Items"
+/// This page lists definitions for HID Local Items.
+///
+/// !Items
+/// - HIDReport_LOCAL_USAGE
+/// - HIDReport_LOCAL_USAGEMINIMUM
+/// - HIDReport_LOCAL_USAGEMAXIMUM
+/// - HIDReport_LOCAL_DESIGNATORINDEX
+/// - HIDReport_LOCAL_DESIGNATORMINIMUM
+/// - HIDReport_LOCAL_DESIGNATORMAXIMUM
+/// - HIDReport_LOCAL_STRINGINDEX
+/// - HIDReport_LOCAL_STRINGMINIMUM
+/// - HIDReport_LOCAL_STRINGMAXIMUM
+/// - HIDReport_LOCAL_DELIMITER
+
+/// Suggested usage for an item or collection.
+#define HIDReport_LOCAL_USAGE 0x08
+/// Defines the starting usage associated with an array or bitmap.
+#define HIDReport_LOCAL_USAGEMINIMUM 0x18
+/// Defines the ending usage associated with an array or bitmap.
+#define HIDReport_LOCAL_USAGEMAXIMUM 0x28
+/// Determines the body part used for a control.
+#define HIDReport_LOCAL_DESIGNATORINDEX 0x38
+/// Defines the index of the starting designator associated with an array or
+/// bitmap.
+#define HIDReport_LOCAL_DESIGNATORMINIMUM 0x48
+/// Defines the index of the ending designator associated with an array or
+/// bitmap.
+#define HIDReport_LOCAL_DESIGNATORMAXIMUM 0x58
+/// String index for a string descriptor.
+#define HIDReport_LOCAL_STRINGINDEX 0x78
+/// Specifies the first string index when assigning a group of sequential
+/// strings to controls in an array or bitmap.
+#define HIDReport_LOCAL_STRINGMINIMUM 0x88
+/// Specifies the last string index when assigning a group of sequential
+/// strings to controls in an array or bitmap.
+#define HIDReport_LOCAL_STRINGMAXIMUM 0x98
+/// Defines the beginning or end of a set of local items.
+#define HIDReport_LOCAL_DELIMITER 0xA8
+//------------------------------------------------------------------------------
+
+#endif //#ifndef HIDREPORT_H
+
diff --git a/usb/common/hid/HIDReportRequest.c b/usb/common/hid/HIDReportRequest.c new file mode 100644 index 0000000..3e9d2e8 --- /dev/null +++ b/usb/common/hid/HIDReportRequest.c @@ -0,0 +1,68 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: HIDReportRequest implementation
+
+ About: Purpose
+ Implementation of the HIDReportRequest methods.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "HIDReportRequest.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Indicates the type of report targetted by a SET_REPORT or GET_REPORT
+/// request.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Requested report type (see "HID Report Types").
+//------------------------------------------------------------------------------
+unsigned char HIDReportRequest_GetReportType(const USBGenericRequest *request)
+{
+ return ((USBGenericRequest_GetValue(request) >> 8) & 0xFF);
+}
+
+//------------------------------------------------------------------------------
+/// Indicates the ID of the report targetted by a SET_REPORT or GET_REPORT
+/// request. This value should be 0 if report IDs are not used.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return Requested report ID.
+//------------------------------------------------------------------------------
+unsigned char HIDReportRequest_GetReportId(const USBGenericRequest *request)
+{
+ return (USBGenericRequest_GetValue(request) & 0xFF);
+}
+
diff --git a/usb/common/hid/HIDReportRequest.h b/usb/common/hid/HIDReportRequest.h new file mode 100644 index 0000000..75ea379 --- /dev/null +++ b/usb/common/hid/HIDReportRequest.h @@ -0,0 +1,86 @@ +/* ----------------------------------------------------------------------------
+ * 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
+
+ Definition of a class for manipulating HID-specific GET_REPORT and
+ SET_REPORT requests.
+
+ !!!Usage
+
+ -# Receive a GET_REPORT or SET_REPORT request from the host.
+ -# Retrieve the report type using HIDReportRequest_GetReportType.
+ -# Retrieve the report ID using HIDReportRequest_GetReportId.
+*/
+
+#ifndef HIDREPORTREQUEST_H
+#define HIDREPORTREQUEST_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Report Types"
+/// This page lists the types for USB HID Reports.
+///
+/// !Types
+/// - HIDReportRequest_INPUT
+/// - HIDReportRequest_OUTPUT
+/// - HIDReportRequest_FEATURE
+
+/// Input report.
+#define HIDReportRequest_INPUT 1
+/// Output report.
+#define HIDReportRequest_OUTPUT 2
+/// Feature report.
+#define HIDReportRequest_FEATURE 3
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned char HIDReportRequest_GetReportType(
+ const USBGenericRequest *request);
+
+extern unsigned char HIDReportRequest_GetReportId(
+ const USBGenericRequest *request);
+
+#endif //#ifndef HIDREPORTREQUEST_H
+
diff --git a/usb/common/hid/hid.dir b/usb/common/hid/hid.dir new file mode 100644 index 0000000..d46589b --- /dev/null +++ b/usb/common/hid/hid.dir @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+/// !Purpose
+///
+/// This directory contains structures and definitions related to the USB HID
+/// specification. They can be divided into two groups:
+/// - HID-specific descriptors, prefixed with HID and suffixed with Descriptor.
+/// - HID-specific requests, prefixed with HID and suffixed with Request.
+//------------------------------------------------------------------------------
+
diff --git a/usb/common/massstorage/MSDeviceDescriptor.h b/usb/common/massstorage/MSDeviceDescriptor.h new file mode 100644 index 0000000..9f4f700 --- /dev/null +++ b/usb/common/massstorage/MSDeviceDescriptor.h @@ -0,0 +1,73 @@ +/* ----------------------------------------------------------------------------
+ * 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 constants for using Device Descriptors with a Mass Storage
+/// driver.
+///
+/// !Usage
+///
+/// - For a USB device:
+/// -# When declaring a USBDeviceDescriptor instance, use the Mass Storage
+/// codes defined in this file (see "MS device codes").
+//------------------------------------------------------------------------------
+
+#ifndef MSDEVICEDESCRIPTOR_H
+#define MSDEVICEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "MS device codes"
+/// This page lists the class, subclass & protocol codes used by a device with
+/// a Mass Storage driver.
+///
+/// !Codes
+///
+/// - MSDeviceDescriptor_CLASS
+/// - MSDeviceDescriptor_SUBCLASS
+/// - MSDeviceDescriptor_PROTOCOL
+
+/// Class code for a Mass Storage device.
+#define MSDeviceDescriptor_CLASS 0
+
+/// Subclass code for a Mass Storage device.
+#define MSDeviceDescriptor_SUBCLASS 0
+
+/// Protocol code for a Mass Storage device.
+#define MSDeviceDescriptor_PROTOCOL 0
+//------------------------------------------------------------------------------
+
+#endif //#ifndef MSDEVICEDESCRIPTOR_H
+
diff --git a/usb/common/massstorage/MSInterfaceDescriptor.h b/usb/common/massstorage/MSInterfaceDescriptor.h new file mode 100644 index 0000000..e51dba6 --- /dev/null +++ b/usb/common/massstorage/MSInterfaceDescriptor.h @@ -0,0 +1,75 @@ +/* ----------------------------------------------------------------------------
+ * 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
+///
+/// Definition of several constants used when manipulating Mass Storage interface
+/// descriptors.
+///
+/// !Usage
+///
+/// - For a USB device:
+/// -# When declaring an interface descriptor for a Mass Storage device, use
+/// the class, subclass and protocol codes defined here (see
+/// "MS interface codes").
+//------------------------------------------------------------------------------
+
+#ifndef MSINTERFACEDESCRIPTOR_H
+#define MSINTERFACEDESCRIPTOR_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "MS interface codes"
+/// This page lists the available class, subclass & protocol codes for a Mass
+/// Storage interface.
+///
+/// !Codes
+///
+/// - MSInterfaceDescriptor_CLASS
+/// - MSInterfaceDescriptor_SCSI
+/// - MSInterfaceDescriptor_BULKONLY
+
+/// Class code for a Mass Storage interface.
+#define MSInterfaceDescriptor_CLASS 0x08
+
+/// Subclass code for a Mass Storage interface using the SCSI protocol.
+#define MSInterfaceDescriptor_SCSI 0x06
+
+/// Protocol code for a Mass Storage interface using Bulk-Only Transport.
+#define MSInterfaceDescriptor_BULKONLY 0x50
+//------------------------------------------------------------------------------
+
+
+#endif //#ifndef MSINTERFACEDESCRIPTOR_H
+
diff --git a/usb/common/massstorage/massstorage.dir b/usb/common/massstorage/massstorage.dir new file mode 100644 index 0000000..f9474f1 --- /dev/null +++ b/usb/common/massstorage/massstorage.dir @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+/// !Purpose
+///
+/// This directory contains structures and definitions related to the USB mass
+/// storage specification.
+/// - Mass-storage-specific descriptors, prefixed with MS and suffixed with
+/// Descriptor.
+//------------------------------------------------------------------------------
+
|