summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-07-31 10:22:41 +0200
committerHarald Welte <laforge@gnumonks.org>2011-07-31 10:25:11 +0200
commitaf8603411cc2c927de581bef0b9213b0a7b77cc1 (patch)
tree1ef72986cd9913674346c00e606b5ca094c12424
parent63d587cf2ef26b5737f9293d03c86ffd183d5a04 (diff)
import usb-device-composide-cdchid-project
-rw-r--r--at91lib/usb/common/cdc/CDCAbstractControlManagementDescriptor.h104
-rw-r--r--at91lib/usb/common/cdc/CDCCallManagementDescriptor.h97
-rw-r--r--at91lib/usb/common/cdc/CDCCommunicationInterfaceDescriptor.h65
-rw-r--r--at91lib/usb/common/cdc/CDCDataInterfaceDescriptor.h65
-rw-r--r--at91lib/usb/common/cdc/CDCDeviceDescriptor.h64
-rw-r--r--at91lib/usb/common/cdc/CDCGenericDescriptor.h91
-rw-r--r--at91lib/usb/common/cdc/CDCGenericRequest.h63
-rw-r--r--at91lib/usb/common/cdc/CDCHeaderDescriptor.h77
-rw-r--r--at91lib/usb/common/cdc/CDCLineCoding.c78
-rw-r--r--at91lib/usb/common/cdc/CDCLineCoding.h136
-rw-r--r--at91lib/usb/common/cdc/CDCSetControlLineStateRequest.c84
-rw-r--r--at91lib/usb/common/cdc/CDCSetControlLineStateRequest.h59
-rw-r--r--at91lib/usb/common/cdc/CDCUnionDescriptor.h79
-rw-r--r--at91lib/usb/common/core/USBInterfaceAssociationDescriptor.h86
-rw-r--r--at91lib/usb/common/hid/HIDDescriptor.h93
-rw-r--r--at91lib/usb/common/hid/HIDDeviceDescriptor.h68
-rw-r--r--at91lib/usb/common/hid/HIDGenericDescriptor.h63
-rw-r--r--at91lib/usb/common/hid/HIDGenericDesktop.h98
-rw-r--r--at91lib/usb/common/hid/HIDGenericRequest.h75
-rw-r--r--at91lib/usb/common/hid/HIDIdleRequest.c56
-rw-r--r--at91lib/usb/common/hid/HIDIdleRequest.h68
-rw-r--r--at91lib/usb/common/hid/HIDInterfaceDescriptor.h77
-rw-r--r--at91lib/usb/common/hid/HIDKeypad.c56
-rw-r--r--at91lib/usb/common/hid/HIDKeypad.h276
-rw-r--r--at91lib/usb/common/hid/HIDLeds.h79
-rw-r--r--at91lib/usb/common/hid/HIDReport.h231
-rw-r--r--at91lib/usb/common/hid/HIDReportRequest.c68
-rw-r--r--at91lib/usb/common/hid/HIDReportRequest.h86
-rw-r--r--at91lib/usb/device/composite/CDCDFunctionDriver.c346
-rw-r--r--at91lib/usb/device/composite/CDCDFunctionDriver.h99
-rw-r--r--at91lib/usb/device/composite/CDCDFunctionDriverDescriptors.h58
-rw-r--r--at91lib/usb/device/composite/COMPOSITEDDriver.c276
-rw-r--r--at91lib/usb/device/composite/COMPOSITEDDriver.h91
-rw-r--r--at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.c954
-rw-r--r--at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.h61
-rw-r--r--at91lib/usb/device/composite/HIDDFunctionDriver.c466
-rw-r--r--at91lib/usb/device/composite/HIDDFunctionDriver.h61
-rw-r--r--at91lib/usb/device/composite/HIDDFunctionDriverDescriptors.h84
-rw-r--r--at91lib/usb/device/composite/drv/CompositeCDCSerial.inf57
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardCallbacks.h57
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardDriver.h75
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardDriverDescriptors.h114
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.c164
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.h149
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.c94
-rw-r--r--at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.h96
-rw-r--r--usb-device-composite-cdchid-project/Makefile173
-rw-r--r--usb-device-composite-cdchid-project/bin/.empty0
-rw-r--r--usb-device-composite-cdchid-project/main.c1011
-rw-r--r--usb-device-composite-cdchid-project/obj/.empty0
50 files changed, 7028 insertions, 0 deletions
diff --git a/at91lib/usb/common/cdc/CDCAbstractControlManagementDescriptor.h b/at91lib/usb/common/cdc/CDCAbstractControlManagementDescriptor.h
new file mode 100644
index 0000000..943204c
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCCallManagementDescriptor.h b/at91lib/usb/common/cdc/CDCCallManagementDescriptor.h
new file mode 100644
index 0000000..191ff61
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCCommunicationInterfaceDescriptor.h b/at91lib/usb/common/cdc/CDCCommunicationInterfaceDescriptor.h
new file mode 100644
index 0000000..aa13915
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCDataInterfaceDescriptor.h b/at91lib/usb/common/cdc/CDCDataInterfaceDescriptor.h
new file mode 100644
index 0000000..640f8dc
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCDeviceDescriptor.h b/at91lib/usb/common/cdc/CDCDeviceDescriptor.h
new file mode 100644
index 0000000..b1bc177
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCGenericDescriptor.h b/at91lib/usb/common/cdc/CDCGenericDescriptor.h
new file mode 100644
index 0000000..3d93656
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCGenericRequest.h b/at91lib/usb/common/cdc/CDCGenericRequest.h
new file mode 100644
index 0000000..d6abd0b
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCHeaderDescriptor.h b/at91lib/usb/common/cdc/CDCHeaderDescriptor.h
new file mode 100644
index 0000000..b04926f
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCLineCoding.c b/at91lib/usb/common/cdc/CDCLineCoding.c
new file mode 100644
index 0000000..4223fec
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCLineCoding.h b/at91lib/usb/common/cdc/CDCLineCoding.h
new file mode 100644
index 0000000..dfe3c10
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCSetControlLineStateRequest.c b/at91lib/usb/common/cdc/CDCSetControlLineStateRequest.c
new file mode 100644
index 0000000..43079ca
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCSetControlLineStateRequest.h b/at91lib/usb/common/cdc/CDCSetControlLineStateRequest.h
new file mode 100644
index 0000000..5d6c661
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/cdc/CDCUnionDescriptor.h b/at91lib/usb/common/cdc/CDCUnionDescriptor.h
new file mode 100644
index 0000000..0ba9eaa
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/core/USBInterfaceAssociationDescriptor.h b/at91lib/usb/common/core/USBInterfaceAssociationDescriptor.h
new file mode 100644
index 0000000..5f3dd21
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDDescriptor.h b/at91lib/usb/common/hid/HIDDescriptor.h
new file mode 100644
index 0000000..ae00102
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDDeviceDescriptor.h b/at91lib/usb/common/hid/HIDDeviceDescriptor.h
new file mode 100644
index 0000000..267c73e
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDGenericDescriptor.h b/at91lib/usb/common/hid/HIDGenericDescriptor.h
new file mode 100644
index 0000000..2324d53
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDGenericDesktop.h b/at91lib/usb/common/hid/HIDGenericDesktop.h
new file mode 100644
index 0000000..ac1165c
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDGenericRequest.h b/at91lib/usb/common/hid/HIDGenericRequest.h
new file mode 100644
index 0000000..356f498
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDIdleRequest.c b/at91lib/usb/common/hid/HIDIdleRequest.c
new file mode 100644
index 0000000..640f2d5
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDIdleRequest.h b/at91lib/usb/common/hid/HIDIdleRequest.h
new file mode 100644
index 0000000..1f9a361
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDInterfaceDescriptor.h b/at91lib/usb/common/hid/HIDInterfaceDescriptor.h
new file mode 100644
index 0000000..4ef1bc7
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDKeypad.c b/at91lib/usb/common/hid/HIDKeypad.c
new file mode 100644
index 0000000..19f533e
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDKeypad.h b/at91lib/usb/common/hid/HIDKeypad.h
new file mode 100644
index 0000000..06ad747
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDLeds.h b/at91lib/usb/common/hid/HIDLeds.h
new file mode 100644
index 0000000..22ee54d
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDReport.h b/at91lib/usb/common/hid/HIDReport.h
new file mode 100644
index 0000000..ec02ded
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDReportRequest.c b/at91lib/usb/common/hid/HIDReportRequest.c
new file mode 100644
index 0000000..3e9d2e8
--- /dev/null
+++ b/at91lib/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/at91lib/usb/common/hid/HIDReportRequest.h b/at91lib/usb/common/hid/HIDReportRequest.h
new file mode 100644
index 0000000..75ea379
--- /dev/null
+++ b/at91lib/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/at91lib/usb/device/composite/CDCDFunctionDriver.c b/at91lib/usb/device/composite/CDCDFunctionDriver.c
new file mode 100644
index 0000000..a68f5be
--- /dev/null
+++ b/at91lib/usb/device/composite/CDCDFunctionDriver.c
@@ -0,0 +1,346 @@
+/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+#if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+// GENERAL
+#include <utility/trace.h>
+#include <utility/assert.h>
+// USB
+#include <usb/device/core/USBD.h>
+// CDC
+#include <usb/common/cdc/CDCLineCoding.h>
+#include <usb/common/cdc/CDCGenericRequest.h>
+#include <usb/common/cdc/CDCSetControlLineStateRequest.h>
+
+#include "CDCDFunctionDriver.h"
+#include "CDCDFunctionDriverDescriptors.h"
+
+//-----------------------------------------------------------------------------
+// Defines
+//-----------------------------------------------------------------------------
+
+/// Number of serial ports supported
+#if defined(usb_CDCCDC)
+#define CDCD_PORT_NUM 2
+#else
+#define CDCD_PORT_NUM 1
+#endif
+
+//-----------------------------------------------------------------------------
+// Types
+//-----------------------------------------------------------------------------
+
+/// CDC Serial port struct
+typedef struct {
+
+ CDCLineCoding lineCoding;
+ unsigned char isCarrierActivated;
+ unsigned char epDataIn;
+ unsigned char epDataOut;
+ unsigned short serialState;
+
+} CDCDSerialPort;
+
+//-----------------------------------------------------------------------------
+// Internal variables
+//-----------------------------------------------------------------------------
+
+/// CDCDSerialPort instance
+static CDCDSerialPort cdcdSerial[CDCD_PORT_NUM];
+
+//-----------------------------------------------------------------------------
+// Internal functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Callback function which should be invoked after the data of a
+/// SetLineCoding request has been retrieved. Sends a zero-length packet
+/// to the host for acknowledging the request.
+//-----------------------------------------------------------------------------
+static void CDCD_SetLineCodingCallback()
+{
+ USBD_Write(0, 0, 0, 0, 0);
+}
+
+//-----------------------------------------------------------------------------
+/// Return the port index that host send this request for.
+//-----------------------------------------------------------------------------
+static char CDCD_GetSerialPort(const USBGenericRequest *request)
+{
+ if (request->wIndex == CDCD_Descriptors_INTERFACENUM0 + 1) return 0;
+ #if CDCD_PORT_NUM > 1
+ else if (request->wIndex == CDCD_Descriptors_INTERFACENUM1 + 1) return 1;
+ #endif
+ return 0xFF;
+}
+
+//-----------------------------------------------------------------------------
+/// Receives new line coding information from the USB host.
+/// \param request Pointer to a USBGenericRequest instance.
+//-----------------------------------------------------------------------------
+static void CDCD_SetLineCoding(const USBGenericRequest *request)
+{
+ unsigned char serial;
+ serial = CDCD_GetSerialPort(request);
+
+ TRACE_INFO_WP("sLineCoding_%d ", serial);
+
+ USBD_Read(0,
+ (void *) &(cdcdSerial[serial].lineCoding),
+ sizeof(CDCLineCoding),
+ (TransferCallback) CDCD_SetLineCodingCallback,
+ 0);
+}
+
+//-----------------------------------------------------------------------------
+/// Sends the current line coding information to the host through Control
+/// endpoint 0.
+/// \param request Pointer to a USBGenericRequest instance.
+//-----------------------------------------------------------------------------
+static void CDCD_GetLineCoding(const USBGenericRequest *request)
+{
+ unsigned char serial;
+ serial = CDCD_GetSerialPort(request);
+
+ TRACE_INFO_WP("gLineCoding_%d ", serial);
+
+ USBD_Write(0,
+ (void *) &(cdcdSerial[serial].lineCoding),
+ sizeof(CDCLineCoding),
+ 0,
+ 0);
+}
+
+//-----------------------------------------------------------------------------
+/// Changes the state of the serial driver according to the information
+/// sent by the host via a SetControlLineState request, and acknowledges
+/// the request with a zero-length packet.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \param activateCarrier The active carrier state to set.
+/// \param isDTEPresent The DTE status.
+//-----------------------------------------------------------------------------
+static void CDCD_SetControlLineState(const USBGenericRequest *request,
+ unsigned char activateCarrier,
+ unsigned char isDTEPresent)
+{
+ unsigned char serial;
+ serial = CDCD_GetSerialPort(request);
+
+ TRACE_INFO_WP(
+ "sControlLineState_%d(%d, %d) ",
+ serial,
+ activateCarrier,
+ isDTEPresent);
+
+ cdcdSerial[serial].isCarrierActivated = activateCarrier;
+ USBD_Write(0, 0, 0, 0, 0);
+}
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Initializes the USB device CDC serial function driver.
+//-----------------------------------------------------------------------------
+void CDCDFunctionDriver_Initialize()
+{
+ unsigned char serial;
+
+ TRACE_INFO("CDCDFunctionDriver_Initialize\n\r");
+
+ for (serial = 0; serial < CDCD_PORT_NUM; serial ++) {
+
+ CDCDSerialPort * pSerial = &cdcdSerial[serial];
+
+ // Initialize Abstract Control Model attributes
+ CDCLineCoding_Initialize(&(pSerial->lineCoding),
+ 115200,
+ CDCLineCoding_ONESTOPBIT,
+ CDCLineCoding_NOPARITY,
+ 8);
+ pSerial->isCarrierActivated = 0;
+ pSerial->serialState = 0;
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Handles CDC/ACM-specific USB requests sent by the host
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return 0 if the request is Unsupported, 1 if the request handled.
+//-----------------------------------------------------------------------------
+unsigned char CDCDFunctionDriver_RequestHandler(
+ const USBGenericRequest *request)
+{
+ switch (USBGenericRequest_GetRequest(request)) {
+
+ case CDCGenericRequest_SETLINECODING:
+
+ CDCD_SetLineCoding(request);
+ break;
+
+ case CDCGenericRequest_GETLINECODING:
+
+ CDCD_GetLineCoding(request);
+ break;
+
+ case CDCGenericRequest_SETCONTROLLINESTATE:
+
+ CDCD_SetControlLineState(request,
+ CDCSetControlLineStateRequest_ActivateCarrier(request),
+ CDCSetControlLineStateRequest_IsDtePresent(request));
+
+ break;
+
+ // Unsupported request
+ default:
+ return 0;
+
+ }
+ return 1;
+}
+
+//-----------------------------------------------------------------------------
+/// Receives data from the host through the virtual COM port created by
+/// the CDC function serial driver. This function behaves like <USBD_Read>.
+/// \param Port Port index to receive.
+/// \param Pointer to the data buffer to send.
+/// \param Size of the data buffer in bytes.
+/// \param callback Optional callback function to invoke when the transfer
+/// finishes.
+/// \param argument Optional argument to the callback function.
+/// \return <USBD_STATUS_SUCCESS> if the read operation started normally;
+/// otherwise, the corresponding error code.
+//-----------------------------------------------------------------------------
+unsigned char CDCDSerialDriver_Read(unsigned char port,
+ void *data,
+ unsigned int size,
+ TransferCallback callback,
+ void *argument)
+{
+ unsigned char ep = CDCD_Descriptors_DATAOUT0;
+
+ #if CDCD_PORT_NUM > 1
+ ep = (port == 0) ?
+ CDCD_Descriptors_DATAOUT0 : CDCD_Descriptors_DATAOUT1;
+ #endif
+
+ return USBD_Read(ep,
+ data,
+ size,
+ callback,
+ argument);
+}
+
+//-----------------------------------------------------------------------------
+/// Sends a data buffer through the virtual COM port created by the CDC
+/// function serial driver. This function behaves exactly like <USBD_Write>.
+/// \param port Port index to receive.
+/// \param data - Pointer to the data buffer to send.
+/// \param size - Size of the data buffer in bytes.
+/// \param callback - Optional callback function to invoke when the transfer
+/// finishes.
+/// \param argument - Optional argument to the callback function.
+/// \return <USBD_STATUS_SUCCESS> if the write operation started normally;
+/// otherwise, the corresponding error code.
+//-----------------------------------------------------------------------------
+unsigned char CDCDSerialDriver_Write(unsigned char port,
+ void *data,
+ unsigned int size,
+ TransferCallback callback,
+ void *argument)
+{
+ unsigned char ep = CDCD_Descriptors_DATAIN0;
+
+ #if CDCD_PORT_NUM > 1
+ ep = (port == 0) ?
+ CDCD_Descriptors_DATAIN0 : CDCD_Descriptors_DATAIN1;
+ #endif
+
+ return USBD_Write(ep,
+ data,
+ size,
+ callback,
+ argument);
+}
+
+//------------------------------------------------------------------------------
+/// Returns the current status of the RS-232 line.
+/// \param port The port number that checked.
+//------------------------------------------------------------------------------
+unsigned short CDCDSerialDriver_GetSerialState(unsigned char port)
+{
+ return cdcdSerial[port].serialState;
+}
+
+//------------------------------------------------------------------------------
+/// Sets the current serial state of the device to the given value.
+/// \param port The port number that the port state should be changed.
+/// \param serialState New device state.
+//------------------------------------------------------------------------------
+void CDCDSerialDriver_SetSerialState(unsigned char port,
+ unsigned short serialState)
+{
+ CDCDSerialPort * pPort;
+ unsigned char ep = 0;
+
+ ASSERT((serialState & 0xFF80) == 0,
+ "CDCDSerialDriver_SetSerialState: Bits D7-D15 are reserved!\n\r");
+
+ // If new state is different from previous one, send a notification to the
+ // host
+ pPort = &cdcdSerial[port];
+ if (pPort->serialState != serialState) {
+
+ #if CDCD_PORT_NUM > 1
+ ep = (port == 0) ?
+ CDCD_Descriptors_NOTIFICATION0 : CDCD_Descriptors_NOTIFICATION1;
+ #endif
+
+ pPort->serialState = serialState;
+ USBD_Write(ep,
+ &(pPort->serialState),
+ 2,
+ 0,
+ 0);
+
+ // Reset one-time flags
+ pPort->serialState &= ~(CDCD_STATE_OVERRUN
+ | CDCD_STATE_PARITY
+ | CDCD_STATE_FRAMING
+ | CDCD_STATE_RINGSIGNAL
+ | CDCD_STATE_BREAK);
+ }
+}
+#endif // (CDC defined)
+
diff --git a/at91lib/usb/device/composite/CDCDFunctionDriver.h b/at91lib/usb/device/composite/CDCDFunctionDriver.h
new file mode 100644
index 0000000..8acbca5
--- /dev/null
+++ b/at91lib/usb/device/composite/CDCDFunctionDriver.h
@@ -0,0 +1,99 @@
+/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+#ifndef CDCDFUNCTIONDRIVER_H
+#define CDCDFUNCTIONDRIVER_H
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include <usb/device/core/USBD.h>
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+
+/// Indicates the receiver carrier signal is present.
+#define CDCD_STATE_RXDRIVER (1 << 0)
+/// Indicates the transmission carrier signal is present.
+#define CDCD_STATE_TXCARRIER (1 << 1)
+/// Indicates a break has been detected.
+#define CDCD_STATE_BREAK (1 << 2)
+/// Indicates a ring signal has been detected.
+#define CDCD_STATE_RINGSIGNAL (1 << 3)
+/// Indicates a framing error has occured.
+#define CDCD_STATE_FRAMING (1 << 4)
+/// Indicates a parity error has occured.
+#define CDCD_STATE_PARITY (1 << 5)
+/// Indicates a data overrun error has occured.
+#define CDCD_STATE_OVERRUN (1 << 6)
+
+//-----------------------------------------------------------------------------
+// Structs
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Callbacks
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+//- Function API for composite device
+extern void CDCDFunctionDriver_Initialize();
+
+extern unsigned char CDCDFunctionDriver_RequestHandler(
+ const USBGenericRequest * request);
+
+//- CDC Serial Port API
+extern unsigned char CDCDSerialDriver_Write(
+ unsigned char port,
+ void *data,
+ unsigned int size,
+ TransferCallback callback,
+ void *argument);
+
+extern unsigned char CDCDSerialDriver_Read(
+ unsigned char port,
+ void *data,
+ unsigned int size,
+ TransferCallback callback,
+ void *argument);
+
+extern unsigned short CDCDSerialDriver_GetSerialState(unsigned char port);
+
+extern void CDCDSerialDriver_SetSerialState(
+ unsigned char port,
+ unsigned short serialState);
+
+
+#endif // #define CDCDFUNCTIONDRIVER_H
+
diff --git a/at91lib/usb/device/composite/CDCDFunctionDriverDescriptors.h b/at91lib/usb/device/composite/CDCDFunctionDriverDescriptors.h
new file mode 100644
index 0000000..54d3e64
--- /dev/null
+++ b/at91lib/usb/device/composite/CDCDFunctionDriverDescriptors.h
@@ -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.
+ * ----------------------------------------------------------------------------
+ */
+
+#ifndef CDCDFUNCTIONDRIVERDESCRIPTORS_H
+#define CDCDFUNCTIONDRIVERDESCRIPTORS_H
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include <board.h>
+#include <usb/device/core/USBDDriverDescriptors.h>
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+
+/// EPs used in CDC/ACM Function.
+#if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+#define CDCD_Descriptors_INTERFACENUM0 0
+#define CDCD_Descriptors_NOTIFICATION0 3
+#define CDCD_Descriptors_DATAIN0 2
+#define CDCD_Descriptors_DATAOUT0 1
+#endif
+#if defined(usb_CDCCDC)
+#define CDCD_Descriptors_INTERFACENUM1 2
+#define CDCD_Descriptors_NOTIFICATION1 6
+#define CDCD_Descriptors_DATAIN1 5
+#define CDCD_Descriptors_DATAOUT1 4
+#endif
+
+#endif // #define CDCFUNCTIONDRIVERDESCRIPTORS_H
diff --git a/at91lib/usb/device/composite/COMPOSITEDDriver.c b/at91lib/usb/device/composite/COMPOSITEDDriver.c
new file mode 100644
index 0000000..d454764
--- /dev/null
+++ b/at91lib/usb/device/composite/COMPOSITEDDriver.c
@@ -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.
+ * ----------------------------------------------------------------------------
+ */
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+// GENERAL
+#include <utility/trace.h>
+#include <utility/assert.h>
+#include <utility/led.h>
+
+// USB
+#include <usb/device/core/USBD.h>
+#include <usb/device/core/USBDDriver.h>
+
+//- HID
+#if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ #include <usb/device/hid-keyboard/HIDDKeyboardDriver.h>
+ #include <usb/device/hid-keyboard/HIDDKeyboardDriverDescriptors.h>
+ #include <usb/device/hid-keyboard/HIDDKeyboardCallbacks.h>
+ #include <usb/device/hid-keyboard/HIDDKeyboardInputReport.h>
+ #include <usb/device/hid-keyboard/HIDDKeyboardOutputReport.h>
+
+ #include <usb/common/hid/HIDGenericDescriptor.h>
+ #include <usb/common/hid/HIDDescriptor.h>
+ #include <usb/common/hid/HIDGenericRequest.h>
+ #include <usb/common/hid/HIDReportRequest.h>
+ #include <usb/common/hid/HIDIdleRequest.h>
+ #include <usb/common/hid/HIDKeypad.h>
+#endif // (HID defined)
+
+//- MSD
+#if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+#endif
+
+//- COMPOSITE
+#include "COMPOSITEDDriver.h"
+#include "COMPOSITEDDriverDescriptors.h"
+
+//-----------------------------------------------------------------------------
+// Defines
+//-----------------------------------------------------------------------------
+
+/// Interface setting spaces (4 byte aligned)
+#define NUM_INTERFACES ((COMPOSITEDDriverDescriptors_NUMINTERFACE+3)&0xFC)
+
+//-----------------------------------------------------------------------------
+// Types
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Internal variables
+//-----------------------------------------------------------------------------
+
+/// USBDDriver instance
+static USBDDriver usbdDriver;
+
+/// Array for storing the current setting of each interface
+static unsigned char compositedDriverInterfaces[NUM_INTERFACES];
+
+//-----------------------------------------------------------------------------
+// Internal functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Optional RequestReceived() callback re-implementation
+//-----------------------------------------------------------------------------
+#if !defined(NOAUTOCALLBACK)
+
+void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
+{
+ COMPOSITEDDriver_RequestHandler(request);
+}
+
+#endif
+
+//-----------------------------------------------------------------------------
+/// Invoked whenever the active setting of an interface is changed by the
+/// host. Changes the status of the third LED accordingly.
+/// \param interface Interface number.
+/// \param setting Newly active setting.
+//-----------------------------------------------------------------------------
+void USBDDriverCallbacks_InterfaceSettingChanged(unsigned char interface,
+ unsigned char setting)
+{
+ // AUDIO
+ #if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ AUDDFunctionCallbacks_InterfaceSettingChanged(interface, setting);
+ #endif
+}
+
+//-----------------------------------------------------------------------------
+// ConfigurationChanged() callback re-implementation
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Invoked whenever the configuration value of a device is changed by the host
+/// \param cfgnum Configuration number.
+//-----------------------------------------------------------------------------
+void USBDDriverCallbacks_ConfigurationChanged(unsigned char cfgnum)
+{
+ // HID
+ #if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ HIDDFunctionCallbacks_ConfigurationChanged(cfgnum);
+ #endif
+}
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Initializes the USB device composite device driver.
+//-----------------------------------------------------------------------------
+void COMPOSITEDDriver_Initialize()
+{
+ // CDC
+ #if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+ CDCDFunctionDriver_Initialize();
+ #endif
+
+ // AUDIO
+ #if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ AUDDFunctionDriver_Initialize();
+ #endif
+
+ // HID
+ #if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ HIDDFunctionDriver_Initialize(&usbdDriver);
+ #endif
+
+ // MSD
+ #if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ // Function driver initialize is put to main() for additional LUN list
+ #endif
+
+ // Initialize the standard USB driver
+ USBDDriver_Initialize(&usbdDriver,
+ &compositedDriverDescriptors,
+ compositedDriverInterfaces);
+
+ // Initialize the USB driver
+ USBD_Init();
+}
+
+//-----------------------------------------------------------------------------
+/// Handles composite-specific USB requests sent by the host, and forwards
+/// standard ones to the USB device driver.
+/// \param request Pointer to a USBGenericRequest instance.
+//-----------------------------------------------------------------------------
+void COMPOSITEDDriver_RequestHandler(const USBGenericRequest *request)
+{
+ // Check if this is a class request
+ if (USBGenericRequest_GetType(request) == USBGenericRequest_CLASS) {
+
+ unsigned char rc = 0;
+
+ // AUDIO class request
+ #if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ if (rc == 0) {
+
+ rc = AUDDFunctionDriver_RequestHandler(request);
+ }
+ #endif
+
+ // CDC class request
+ #if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCMSD) || defined(usb_CDCCDC)
+ if (rc == 0) {
+
+ rc = CDCDFunctionDriver_RequestHandler(request);
+ }
+ #endif
+
+ // MSD class request
+ #if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ if (rc == 0) {
+
+ rc = MSDDFunctionDriver_RequestHandler(request);
+ }
+ #endif
+
+ // HID class request
+ #if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ if (rc == 0) {
+
+ rc = HIDDFunctionDriver_RequestHandler(request);
+ }
+ #endif
+
+ if (!rc) {
+
+ TRACE_WARNING(
+ "COMPOSITEDDriver_RequestHandler: Unsupported request (%d)\n\r",
+ USBGenericRequest_GetRequest(request));
+ USBD_Stall(0);
+ }
+
+ }
+ // Check if this is a standard request
+ else if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) {
+
+ unsigned char rc = 0;
+
+ #if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ rc = HIDDFunctionDriver_RequestHandler(request);
+ #endif
+
+ #if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ if (rc == 0) {
+
+ rc = MSDDFunctionDriver_RequestHandler(request);
+ }
+ #endif
+
+ // Forward request to the standard handler
+ if (rc == 0) {
+
+ USBDDriver_RequestHandler(&(usbdDriver), request);
+ }
+ }
+ // Unsupported request type
+ else {
+
+ TRACE_WARNING(
+ "COMPOSITEDDriver_RequestHandler: Unsupported request type (%d)\n\r",
+ USBGenericRequest_GetType(request));
+ USBD_Stall(0);
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Starts a remote wake-up sequence if the host has explicitely enabled it
+/// by sending the appropriate SET_FEATURE request.
+//-----------------------------------------------------------------------------
+void COMPOSITEDDriver_RemoteWakeUp(void)
+{
+ // Remote wake-up has been enabled
+ if (USBDDriver_IsRemoteWakeUpEnabled(&usbdDriver)) {
+
+ USBD_RemoteWakeUp();
+ }
+ // Remote wake-up NOT enabled
+ else {
+
+ TRACE_WARNING("COMPOSITEDDriver_RemoteWakeUp: not enabled\n\r");
+ }
+}
+
+
diff --git a/at91lib/usb/device/composite/COMPOSITEDDriver.h b/at91lib/usb/device/composite/COMPOSITEDDriver.h
new file mode 100644
index 0000000..3b7f72b
--- /dev/null
+++ b/at91lib/usb/device/composite/COMPOSITEDDriver.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
+///
+/// Definitions and methods for USB composite device implement.
+///
+/// !Usage
+///
+/// -# Initialize USB function specified driver ( for MSD currently )
+/// - MSDDFunctionDriver_Initialize
+///
+/// -# Initialize USB composite driver and USB driver
+/// - COMPOSITEDDriver_Initialize
+///
+/// -# Handle and dispach USB requests
+/// - COMPOSITEDDriver_RequestHandler
+///
+/// -# Try starting a remote wake-up sequence
+/// - COMPOSITEDDriver_RemoteWakeUp
+//-----------------------------------------------------------------------------
+
+#ifndef COMPOSITEDDRIVER_H
+#define COMPOSITEDDRIVER_H
+
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+#include <usb/device/core/USBD.h>
+
+#if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+ #include "CDCDFunctionDriver.h"
+#endif
+
+#if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ #include "AUDDFunctionDriver.h"
+#endif
+
+#if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ #include "HIDDFunctionDriver.h"
+#endif
+
+#if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ #include "MSDDFunctionDriver.h"
+#endif
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+// -COMPOSITE
+extern void COMPOSITEDDriver_Initialize();
+
+extern void COMPOSITEDDriver_RequestHandler(const USBGenericRequest *request);
+
+extern void COMPOSITEDDriver_RemoteWakeUp(void);
+
+#endif //#ifndef COMPOSITEDDRIVER_H
+
diff --git a/at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.c b/at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.c
new file mode 100644
index 0000000..1769769
--- /dev/null
+++ b/at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.c
@@ -0,0 +1,954 @@
+/* ----------------------------------------------------------------------------
+ * 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 "COMPOSITEDDriver.h"
+#include "COMPOSITEDDriverDescriptors.h"
+#include <board.h>
+
+//- USB Generic
+#include <usb/common/core/USBGenericDescriptor.h>
+#include <usb/common/core/USBConfigurationDescriptor.h>
+#include <usb/common/core/USBInterfaceAssociationDescriptor.h>
+#include <usb/common/core/USBEndpointDescriptor.h>
+#include <usb/common/core/USBStringDescriptor.h>
+#include <usb/common/core/USBGenericRequest.h>
+
+//- CDC
+#if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+ #include <usb/common/cdc/CDCGenericDescriptor.h>
+ #include <usb/common/cdc/CDCDeviceDescriptor.h>
+ #include <usb/common/cdc/CDCCommunicationInterfaceDescriptor.h>
+ #include <usb/common/cdc/CDCDataInterfaceDescriptor.h>
+ #include <usb/common/cdc/CDCHeaderDescriptor.h>
+ #include <usb/common/cdc/CDCCallManagementDescriptor.h>
+ #include <usb/common/cdc/CDCAbstractControlManagementDescriptor.h>
+ #include <usb/common/cdc/CDCUnionDescriptor.h>
+ #include "CDCDFunctionDriverDescriptors.h"
+#endif // (CDC defined)
+
+//- HID
+#if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ #include <usb/device/hid-keyboard/HIDDKeyboardInputReport.h>
+ #include <usb/device/hid-keyboard/HIDDKeyboardOutputReport.h>
+ #include <usb/common/hid/HIDGenericDescriptor.h>
+ #include <usb/common/hid/HIDDeviceDescriptor.h>
+ #include <usb/common/hid/HIDInterfaceDescriptor.h>
+ #include <usb/common/hid/HIDDescriptor.h>
+ #include <usb/common/hid/HIDReport.h>
+ #include <usb/common/hid/HIDGenericDesktop.h>
+ #include <usb/common/hid/HIDLeds.h>
+ #include <usb/common/hid/HIDKeypad.h>
+ #include "HIDDFunctionDriverDescriptors.h"
+#endif // (HID defined)
+
+//- AUDIO
+#if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ #include <usb/common/audio/AUDGenericDescriptor.h>
+ #include <usb/common/audio/AUDDeviceDescriptor.h>
+ #include <usb/common/audio/AUDControlInterfaceDescriptor.h>
+ #include <usb/common/audio/AUDStreamingInterfaceDescriptor.h>
+ #include <usb/common/audio/AUDEndpointDescriptor.h>
+ #include <usb/common/audio/AUDDataEndpointDescriptor.h>
+ #include <usb/common/audio/AUDFormatTypeOneDescriptor.h>
+ #include <usb/common/audio/AUDHeaderDescriptor.h>
+ #include <usb/common/audio/AUDFeatureUnitDescriptor.h>
+ #include <usb/common/audio/AUDInputTerminalDescriptor.h>
+ #include <usb/common/audio/AUDOutputTerminalDescriptor.h>
+ #include "AUDDFunctionDriverDescriptors.h"
+#endif // (AUDIO defined)
+
+//- MSD
+#if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ #include <usb/common/massstorage/MSDeviceDescriptor.h>
+ #include <usb/common/massstorage/MSInterfaceDescriptor.h>
+ #include "MSDDFunctionDriverDescriptors.h"
+#endif // (MSD defined)
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+
+/// Device product ID.
+#if defined(usb_CDCHID)
+#define COMPOSITEDDriverDescriptors_PRODUCTID 0x6130
+#elif defined(usb_CDCAUDIO)
+#define COMPOSITEDDriverDescriptors_PRODUCTID 0x6131
+#elif defined(usb_CDCMSD)
+#define COMPOSITEDDriverDescriptors_PRODUCTID 0x6132
+#elif defined(usb_CDCCDC)
+#define COMPOSITEDDriverDescriptors_PRODUCTID 0x6133
+#elif defined(usb_HIDAUDIO)
+#define COMPOSITEDDriverDescriptors_PRODUCTID 0x6134
+#elif defined(usb_HIDMSD)
+#define COMPOSITEDDriverDescriptors_PRODUCTID 0x6135
+#else
+#error COMPOSITE Device Classes not defined!
+#endif
+
+/// Device vendor ID (Atmel).
+#define COMPOSITEDDriverDescriptors_VENDORID 0x03EB
+
+/// Device release number.
+#define COMPOSITEDDriverDescriptors_RELEASE 0x0003
+
+//-----------------------------------------------------------------------------
+// Macros
+//-----------------------------------------------------------------------------
+
+/// Returns the minimum between two values.
+#define MIN(a, b) ((a < b) ? a : b)
+
+//-----------------------------------------------------------------------------
+// Internal structures
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Audio control header descriptor with one slave interface.
+//-----------------------------------------------------------------------------
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//- AUDIO
+#if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+typedef struct {
+
+ /// Header descriptor.
+ AUDHeaderDescriptor header;
+ /// Id of the first grouped interface.
+ unsigned char bInterface0;
+
+} __attribute__ ((packed)) AUDHeaderDescriptor1; // GCC
+
+//-----------------------------------------------------------------------------
+/// Feature unit descriptor with 3 channel controls (master, right, left).
+//-----------------------------------------------------------------------------
+typedef struct {
+
+ /// Feature unit descriptor.
+ AUDFeatureUnitDescriptor feature;
+ /// Available controls for each channel.
+ unsigned char bmaControls[3];
+ /// Index of a string descriptor for the feature unit.
+ unsigned char iFeature;
+
+} __attribute__ ((packed)) AUDFeatureUnitDescriptor3; // GCC
+
+//-----------------------------------------------------------------------------
+/// List of descriptors for detailling the audio control interface of a
+/// device using a USB audio speaker driver.
+//-----------------------------------------------------------------------------
+typedef struct {
+
+ /// Header descriptor (with one slave interface).
+ AUDHeaderDescriptor1 header;
+ /// Input terminal descriptor.
+ AUDInputTerminalDescriptor input;
+ /// Output terminal descriptor.
+ AUDOutputTerminalDescriptor output;
+ /// Feature unit descriptor.
+ AUDFeatureUnitDescriptor3 feature;
+
+} __attribute__ ((packed)) AUDDSpeakerDriverAudioControlDescriptors; // GCC
+
+//-----------------------------------------------------------------------------
+/// Format type I descriptor with one discrete sampling frequency.
+//-----------------------------------------------------------------------------
+typedef struct {
+
+ /// Format type I descriptor.
+ AUDFormatTypeOneDescriptor formatType;
+ /// Sampling frequency in Hz.
+ unsigned char tSamFreq[3];
+
+} __attribute__ ((packed)) AUDFormatTypeOneDescriptor1; // GCC
+#endif // (AUDIO defined)
+
+//-----------------------------------------------------------------------------
+/// Configuration descriptor list for a device implementing a composite driver.
+//-----------------------------------------------------------------------------
+typedef struct {
+
+ /// Standard configuration descriptor.
+ USBConfigurationDescriptor configuration;
+
+ #if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+ /// --- CDC 0
+ /// IAD 0
+ USBInterfaceAssociationDescriptor cdcIAD0;
+ /// Communication interface descriptor
+ USBInterfaceDescriptor cdcCommunication0;
+ /// CDC header functional descriptor.
+ CDCHeaderDescriptor cdcHeader0;
+ /// CDC call management functional descriptor.
+ CDCCallManagementDescriptor cdcCallManagement0;
+ /// CDC abstract control management functional descriptor.
+ CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
+ /// CDC union functional descriptor (with one slave interface).
+ CDCUnionDescriptor cdcUnion0;
+ /// Notification endpoint descriptor.
+ USBEndpointDescriptor cdcNotification0;
+ /// Data interface descriptor.
+ USBInterfaceDescriptor cdcData0;
+ /// Data OUT endpoint descriptor.
+ USBEndpointDescriptor cdcDataOut0;
+ /// Data IN endpoint descriptor.
+ USBEndpointDescriptor cdcDataIn0;
+ #endif // (CDC defined)
+
+ #if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ /// --- HID
+ USBInterfaceDescriptor hidInterface;
+ HIDDescriptor hid;
+ USBEndpointDescriptor hidInterruptIn;
+ USBEndpointDescriptor hidInterruptOut;
+ #endif // (HID defined)
+
+ #if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ /// --- AUDIO
+ /// IAD 1
+ USBInterfaceAssociationDescriptor audIAD;
+ /// Audio control interface.
+ USBInterfaceDescriptor audInterface;
+ /// Descriptors for the audio control interface.
+ AUDDSpeakerDriverAudioControlDescriptors audControl;
+ /// -- AUDIO out
+ /// Streaming out interface descriptor (with no endpoint, required).
+ USBInterfaceDescriptor audStreamingOutNoIsochronous;
+ /// Streaming out interface descriptor.
+ USBInterfaceDescriptor audStreamingOut;
+ /// Audio class descriptor for the streaming out interface.
+ AUDStreamingInterfaceDescriptor audStreamingOutClass;
+ /// Stream format descriptor.
+ AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
+ /// Streaming out endpoint descriptor.
+ AUDEndpointDescriptor audStreamingOutEndpoint;
+ /// Audio class descriptor for the streaming out endpoint.
+ AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
+ #endif // (AUDIO defined)
+
+ #if defined(usb_CDCCDC)
+ /// --- CDC 1
+ /// IAD 1
+ USBInterfaceAssociationDescriptor cdcIAD1;
+ /// Communication interface descriptor
+ USBInterfaceDescriptor cdcCommunication1;
+ /// CDC header functional descriptor.
+ CDCHeaderDescriptor cdcHeader1;
+ /// CDC call management functional descriptor.
+ CDCCallManagementDescriptor cdcCallManagement1;
+ /// CDC abstract control management functional descriptor.
+ CDCAbstractControlManagementDescriptor cdcAbstractControlManagement1;
+ /// CDC union functional descriptor (with one slave interface).
+ CDCUnionDescriptor cdcUnion1;
+ /// Notification endpoint descriptor.
+ USBEndpointDescriptor cdcNotification1;
+ /// Data interface descriptor.
+ USBInterfaceDescriptor cdcData1;
+ /// Data OUT endpoint descriptor.
+ USBEndpointDescriptor cdcDataOut1;
+ /// Data IN endpoint descriptor.
+ USBEndpointDescriptor cdcDataIn1;
+ #endif // (Another CDC defined)
+
+ #if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ /// --- MSD
+ /// Mass storage interface descriptor.
+ USBInterfaceDescriptor msdInterface;
+ /// Bulk-out endpoint descriptor.
+ USBEndpointDescriptor msdBulkOut;
+ /// Bulk-in endpoint descriptor.
+ USBEndpointDescriptor msdBulkIn;
+ #endif // (MSD defined)
+
+} __attribute__ ((packed)) CompositeDriverConfigurationDescriptors;
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+// Exported variables
+//------------------------------------------------------------------------------
+
+/// Standard USB device descriptor for the composite device driver
+const USBDeviceDescriptor deviceDescriptor = {
+
+ sizeof(USBDeviceDescriptor),
+ USBGenericDescriptor_DEVICE,
+ USBDeviceDescriptor_USB2_00,
+ #if defined(usb_HIDMSD)
+ 0x00,
+ 0x00,
+ 0x00,
+ #else
+ 0xEF,// MI
+ 0x02,//
+ 0x01,//
+ #endif
+ BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
+ COMPOSITEDDriverDescriptors_VENDORID,
+ COMPOSITEDDriverDescriptors_PRODUCTID,
+ COMPOSITEDDriverDescriptors_RELEASE,
+ 0, // No string descriptor for manufacturer
+ 1, // Index of product string descriptor is #1
+ 0, // No string descriptor for serial number
+ 1 // Device has 1 possible configuration
+};
+
+#if defined(BOARD_USB_UDPHS)
+
+/// USB device qualifier descriptor.
+const USBDeviceQualifierDescriptor qualifierDescriptor = {
+
+ sizeof(USBDeviceQualifierDescriptor),
+ USBGenericDescriptor_DEVICEQUALIFIER,
+ USBDeviceDescriptor_USB2_00,
+ #if defined(usb_HIDMSD)
+ 0x00,
+ 0x00,
+ 0x00,
+ #else
+ 0xEF,// MI
+ 0x02,//
+ 0x01,//
+ #endif
+ BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
+ 1, // Device has one possible configuration
+ 0 // Reserved
+};
+
+#endif
+
+/// USB configuration descriptors for the composite device driver
+const CompositeDriverConfigurationDescriptors configurationDescriptors = {
+
+ // Standard configuration descriptor
+ {
+ sizeof(USBConfigurationDescriptor),
+ USBGenericDescriptor_CONFIGURATION,
+ sizeof(CompositeDriverConfigurationDescriptors),
+ COMPOSITEDDriverDescriptors_NUMINTERFACE,
+ 1, // This is configuration #1
+ 0, // No string descriptor for this configuration
+ BOARD_USB_BMATTRIBUTES,
+ USBConfigurationDescriptor_POWER(100)
+ },
+
+ #if defined(usb_CDCAUDIO) || defined(usb_CDCHID) || defined(usb_CDCCDC) || defined(usb_CDCMSD)
+ // CDC
+ // IAD for CDC/ACM port
+ {
+ sizeof(USBInterfaceAssociationDescriptor),
+ USBGenericDescriptor_INTERFACEASSOCIATION,
+ CDCD_Descriptors_INTERFACENUM0,
+ 2,
+ CDCCommunicationInterfaceDescriptor_CLASS,
+ CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
+ CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Communication class interface standard descriptor
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ CDCD_Descriptors_INTERFACENUM0, // This is interface #0
+ 0, // This is alternate setting #0 for this interface
+ 1, // This interface uses 1 endpoint
+ CDCCommunicationInterfaceDescriptor_CLASS,
+ CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
+ CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Class-specific header functional descriptor
+ {
+ sizeof(CDCHeaderDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_HEADER,
+ CDCGenericDescriptor_CDC1_10
+ },
+ // Class-specific call management functional descriptor
+ {
+ sizeof(CDCCallManagementDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_CALLMANAGEMENT,
+ CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
+ CDCD_Descriptors_INTERFACENUM0 + 1 // No associated data interface
+ },
+ // Class-specific abstract control management functional descriptor
+ {
+ sizeof(CDCAbstractControlManagementDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
+ CDCAbstractControlManagementDescriptor_LINE
+ },
+ // Class-specific union functional descriptor with one slave interface
+ {
+ sizeof(CDCUnionDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_UNION,
+ CDCD_Descriptors_INTERFACENUM0, // Number of master interface is #0
+ CDCD_Descriptors_INTERFACENUM0 + 1 // First slave interface is #1
+ },
+ // Notification endpoint standard descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
+ CDCD_Descriptors_NOTIFICATION0),
+ USBEndpointDescriptor_INTERRUPT,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_NOTIFICATION0),
+ USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
+ 10 // Endpoint is polled every 10ms
+ },
+ // Data class interface standard descriptor
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ CDCD_Descriptors_INTERFACENUM0 + 1, // This is interface #1
+ 0, // This is alternate setting #0 for this interface
+ 2, // This interface uses 2 endpoints
+ CDCDataInterfaceDescriptor_CLASS,
+ CDCDataInterfaceDescriptor_SUBCLASS,
+ CDCDataInterfaceDescriptor_NOPROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Bulk-OUT endpoint standard descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
+ CDCD_Descriptors_DATAOUT0),
+ USBEndpointDescriptor_BULK,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAOUT0),
+ USBEndpointDescriptor_MAXBULKSIZE_FS),
+ 0 // Must be 0 for full-speed bulk endpoints
+ },
+ // Bulk-IN endpoint descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
+ CDCD_Descriptors_DATAIN0),
+ USBEndpointDescriptor_BULK,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAIN0),
+ USBEndpointDescriptor_MAXBULKSIZE_FS),
+ 0 // Must be 0 for full-speed bulk endpoints
+ },
+ #endif // (CDC defined)
+
+ #if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+ // Interface descriptor
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ HIDD_Descriptors_INTERFACENUM,
+ 0, // This is alternate setting #0
+ 2, // Two endpoints used
+ HIDInterfaceDescriptor_CLASS,
+ HIDInterfaceDescriptor_SUBCLASS_NONE,
+ HIDInterfaceDescriptor_PROTOCOL_NONE,
+ 0 // No associated string descriptor
+ },
+ // HID descriptor
+ {
+ sizeof(HIDDescriptor),
+ HIDGenericDescriptor_HID,
+ HIDDescriptor_HID1_11,
+ 0, // Device is not localized, no country code
+ 1, // One HID-specific descriptor (apart from this one)
+ HIDGenericDescriptor_REPORT,
+ HIDD_Descriptors_REPORTSIZE
+ },
+ // Interrupt IN endpoint descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(
+ USBEndpointDescriptor_IN,
+ HIDD_Descriptors_INTERRUPTIN),
+ USBEndpointDescriptor_INTERRUPT,
+ sizeof(HIDDKeyboardInputReport),
+ HIDD_Descriptors_INTERRUPTIN_POLLING
+ },
+ // Interrupt OUT endpoint descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(
+ USBEndpointDescriptor_OUT,
+ HIDD_Descriptors_INTERRUPTOUT),
+ USBEndpointDescriptor_INTERRUPT,
+ sizeof(HIDDKeyboardOutputReport),
+ HIDD_Descriptors_INTERRUPTIN_POLLING
+ },
+ #endif // (HID defined)
+
+ #if defined(usb_CDCAUDIO) || defined(usb_HIDAUDIO)
+ // AUDIO
+ // IAD for AUDIO function
+ {
+ sizeof(USBInterfaceAssociationDescriptor),
+ USBGenericDescriptor_INTERFACEASSOCIATION,
+ AUDD_Descriptors_INTERFACE,
+ 2,
+ AUDControlInterfaceDescriptor_CLASS,
+ AUDControlInterfaceDescriptor_SUBCLASS,
+ AUDControlInterfaceDescriptor_PROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Audio control interface standard descriptor
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ AUDD_Descriptors_CONTROL,
+ 0, // This is alternate setting #0
+ 0, // This interface uses no endpoint
+ AUDControlInterfaceDescriptor_CLASS,
+ AUDControlInterfaceDescriptor_SUBCLASS,
+ AUDControlInterfaceDescriptor_PROTOCOL,
+ 0 // No string descriptor
+ },
+ // Audio control interface descriptors
+ {
+ // Header descriptor
+ {
+ {
+ sizeof(AUDHeaderDescriptor1),
+ AUDGenericDescriptor_INTERFACE,
+ AUDGenericDescriptor_HEADER,
+ AUDHeaderDescriptor_AUD1_00,
+ sizeof(AUDDSpeakerDriverAudioControlDescriptors),
+ 1 // One streaming interface
+ },
+ AUDD_Descriptors_STREAMING
+ },
+ // Input terminal descriptor
+ {
+ sizeof(AUDInputTerminalDescriptor),
+ AUDGenericDescriptor_INTERFACE,
+ AUDGenericDescriptor_INPUTTERMINAL,
+ AUDD_Descriptors_INPUTTERMINAL,
+ AUDInputTerminalDescriptor_USBSTREAMING,
+ AUDD_Descriptors_OUTPUTTERMINAL,
+ AUDD_NUMCHANNELS,
+ AUDInputTerminalDescriptor_LEFTFRONT
+ | AUDInputTerminalDescriptor_RIGHTFRONT,
+ 0, // No string descriptor for channels
+ 0 // No string descriptor for input terminal
+ },
+ // Output terminal descriptor
+ {
+ sizeof(AUDOutputTerminalDescriptor),
+ AUDGenericDescriptor_INTERFACE,
+ AUDGenericDescriptor_OUTPUTTERMINAL,
+ AUDD_Descriptors_OUTPUTTERMINAL,
+ AUDOutputTerminalDescriptor_SPEAKER,
+ AUDD_Descriptors_INPUTTERMINAL,
+ AUDD_Descriptors_FEATUREUNIT,
+ 0 // No string descriptor
+ },
+ // Feature unit descriptor
+ {
+ {
+ sizeof(AUDFeatureUnitDescriptor3),
+ AUDGenericDescriptor_INTERFACE,
+ AUDGenericDescriptor_FEATUREUNIT,
+ AUDD_Descriptors_FEATUREUNIT,
+ AUDD_Descriptors_INPUTTERMINAL,
+ 1, // 1 byte per channel for controls
+ },
+ {
+ AUDFeatureUnitDescriptor_MUTE, // Master channel controls
+ 0, // Right channel controls
+ 0 // Left channel controls
+ },
+ 0 // No string descriptor
+ }
+ },
+ // Audio streaming interface with 0 endpoints
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ AUDD_Descriptors_STREAMING,
+ 0, // This is alternate setting #0
+ 0, // This interface uses no endpoints
+ AUDStreamingInterfaceDescriptor_CLASS,
+ AUDStreamingInterfaceDescriptor_SUBCLASS,
+ AUDStreamingInterfaceDescriptor_PROTOCOL,
+ 0 // No string descriptor
+ },
+ // Audio streaming interface with data endpoint
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ AUDD_Descriptors_STREAMING,
+ 1, // This is alternate setting #1
+ 1, // This interface uses 1 endpoint
+ AUDStreamingInterfaceDescriptor_CLASS,
+ AUDStreamingInterfaceDescriptor_SUBCLASS,
+ AUDStreamingInterfaceDescriptor_PROTOCOL,
+ 0 // No string descriptor
+ },
+ // Audio streaming class-specific descriptor
+ {
+ sizeof(AUDStreamingInterfaceDescriptor),
+ AUDGenericDescriptor_INTERFACE,
+ AUDStreamingInterfaceDescriptor_GENERAL,
+ AUDD_Descriptors_INPUTTERMINAL,
+ 0, // No internal delay because of data path
+ AUDFormatTypeOneDescriptor_PCM
+ },
+ // Format type I descriptor
+ {
+ {
+ sizeof(AUDFormatTypeOneDescriptor1),
+ AUDGenericDescriptor_INTERFACE,
+ AUDStreamingInterfaceDescriptor_FORMATTYPE,
+ AUDFormatTypeOneDescriptor_FORMATTYPEONE,
+ AUDD_NUMCHANNELS,
+ AUDD_BYTESPERSAMPLE,
+ AUDD_BYTESPERSAMPLE*8,
+ 1 // One discrete frequency supported
+ },
+ {
+ AUDD_SAMPLERATE & 0xFF,
+ (AUDD_SAMPLERATE >> 8) & 0xFF,
+ (AUDD_SAMPLERATE >> 16) & 0xFF
+ }
+ },
+ // Audio streaming endpoint standard descriptor
+ {
+ sizeof(AUDEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(
+ USBEndpointDescriptor_OUT,
+ AUDD_Descriptors_DATAOUT),
+ USBEndpointDescriptor_ISOCHRONOUS,
+ BOARD_USB_ENDPOINTS_MAXPACKETSIZE(AUDD_Descriptors_DATAOUT),
+ 1, // Polling interval = 2^(x-1) milliseconds (1 ms)
+ 0, // This is not a synchronization endpoint
+ 0 // No associated synchronization endpoint
+ },
+ // Audio streaming endpoint class-specific descriptor
+ {
+ sizeof(AUDDataEndpointDescriptor),
+ AUDGenericDescriptor_ENDPOINT,
+ AUDDataEndpointDescriptor_SUBTYPE,
+ 0, // No attributes
+ 0, // Endpoint is not synchronized
+ 0 // Endpoint is not synchronized
+ },
+ #endif // (AUDIO defined)
+
+ #if defined(usb_CDCCDC)
+ // CDC 1
+ // IAD for CDC/ACM port 1
+ {
+ sizeof(USBInterfaceAssociationDescriptor),
+ USBGenericDescriptor_INTERFACEASSOCIATION,
+ CDCD_Descriptors_INTERFACENUM1,
+ 2,
+ CDCCommunicationInterfaceDescriptor_CLASS,
+ CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
+ CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Communication class interface standard descriptor
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ CDCD_Descriptors_INTERFACENUM1, // This is interface #2
+ 0, // This is alternate setting #0 for this interface
+ 1, // This interface uses 1 endpoint
+ CDCCommunicationInterfaceDescriptor_CLASS,
+ CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
+ CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Class-specific header functional descriptor
+ {
+ sizeof(CDCHeaderDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_HEADER,
+ CDCGenericDescriptor_CDC1_10
+ },
+ // Class-specific call management functional descriptor
+ {
+ sizeof(CDCCallManagementDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_CALLMANAGEMENT,
+ CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
+ CDCD_Descriptors_INTERFACENUM1 + 1 // No associated data interface
+ },
+ // Class-specific abstract control management functional descriptor
+ {
+ sizeof(CDCAbstractControlManagementDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
+ CDCAbstractControlManagementDescriptor_LINE
+ },
+ // Class-specific union functional descriptor with one slave interface
+ {
+ sizeof(CDCUnionDescriptor),
+ CDCGenericDescriptor_INTERFACE,
+ CDCGenericDescriptor_UNION,
+ CDCD_Descriptors_INTERFACENUM1, // Number of master interface is #2
+ CDCD_Descriptors_INTERFACENUM1+1 // First slave interface is #3
+ },
+ // Notification endpoint standard descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
+ CDCD_Descriptors_NOTIFICATION1),
+ USBEndpointDescriptor_INTERRUPT,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_NOTIFICATION1),
+ USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
+ 10 // Endpoint is polled every 10ms
+ },
+ // Data class interface standard descriptor
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ CDCD_Descriptors_INTERFACENUM1 + 1, // This is interface #3
+ 0, // This is alternate setting #0 for this interface
+ 2, // This interface uses 2 endpoints
+ CDCDataInterfaceDescriptor_CLASS,
+ CDCDataInterfaceDescriptor_SUBCLASS,
+ CDCDataInterfaceDescriptor_NOPROTOCOL,
+ 0 // No string descriptor for this interface
+ },
+ // Bulk-OUT endpoint standard descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
+ CDCD_Descriptors_DATAOUT1),
+ USBEndpointDescriptor_BULK,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAOUT1),
+ USBEndpointDescriptor_MAXBULKSIZE_FS),
+ 0 // Must be 0 for full-speed bulk endpoints
+ },
+ // Bulk-IN endpoint descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
+ CDCD_Descriptors_DATAIN1),
+ USBEndpointDescriptor_BULK,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAIN1),
+ USBEndpointDescriptor_MAXBULKSIZE_FS),
+ 0 // Must be 0 for full-speed bulk endpoints
+ },
+ #endif // (2 CDCs defined)
+
+ #if defined(usb_CDCMSD) || defined(usb_HIDMSD)
+ // Mass Storage interface descriptor.
+ {
+ sizeof(USBInterfaceDescriptor),
+ USBGenericDescriptor_INTERFACE,
+ MSDD_Descriptors_INTERFACENUM,
+ 0, // This is alternate setting #0.
+ 2, // Interface uses two endpoints.
+ MSInterfaceDescriptor_CLASS,
+ MSInterfaceDescriptor_SCSI,
+ MSInterfaceDescriptor_BULKONLY,
+ 0 // No string descriptor for interface.
+ },
+ // Bulk-OUT endpoint descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(
+ USBEndpointDescriptor_OUT,
+ MSDD_Descriptors_BULKOUT),
+ USBEndpointDescriptor_BULK,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(MSDD_Descriptors_BULKOUT),
+ USBEndpointDescriptor_MAXBULKSIZE_FS),
+ 0 // No string descriptor for endpoint.
+ },
+ // Bulk-IN endpoint descriptor
+ {
+ sizeof(USBEndpointDescriptor),
+ USBGenericDescriptor_ENDPOINT,
+ USBEndpointDescriptor_ADDRESS(
+ USBEndpointDescriptor_IN,
+ MSDD_Descriptors_BULKIN),
+ USBEndpointDescriptor_BULK,
+ MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(MSDD_Descriptors_BULKIN),
+ USBEndpointDescriptor_MAXBULKSIZE_FS),
+ 0 // No string descriptor for endpoint.
+ },
+ #endif // (MSD defined)
+
+};
+
+/// String descriptor with the supported languages.
+const unsigned char languageIdDescriptor[] = {
+
+ USBStringDescriptor_LENGTH(1),
+ USBGenericDescriptor_STRING,
+ USBStringDescriptor_ENGLISH_US
+};
+
+/// Manufacturer name.
+const unsigned char manufacturerDescriptor[] = {
+
+ USBStringDescriptor_LENGTH(5),
+ USBGenericDescriptor_STRING,
+ USBStringDescriptor_UNICODE('A'),
+ USBStringDescriptor_UNICODE('t'),
+ USBStringDescriptor_UNICODE('m'),
+ USBStringDescriptor_UNICODE('e'),
+ USBStringDescriptor_UNICODE('l')
+};
+
+/// Product name.
+const unsigned char productDescriptor[] = {
+
+ USBStringDescriptor_LENGTH(14),
+ USBGenericDescriptor_STRING,
+ USBStringDescriptor_UNICODE('C'),
+ USBStringDescriptor_UNICODE('o'),
+ USBStringDescriptor_UNICODE('m'),
+ USBStringDescriptor_UNICODE('p'),
+ USBStringDescriptor_UNICODE('o'),
+ USBStringDescriptor_UNICODE('s'),
+ USBStringDescriptor_UNICODE('i'),
+ USBStringDescriptor_UNICODE('t'),
+ USBStringDescriptor_UNICODE('e'),
+ USBStringDescriptor_UNICODE(' '),
+ USBStringDescriptor_UNICODE('D'),
+ USBStringDescriptor_UNICODE('e'),
+ USBStringDescriptor_UNICODE('m'),
+ USBStringDescriptor_UNICODE('o')
+};
+
+/// Product serial number.
+const unsigned char serialNumberDescriptor[] = {
+
+ USBStringDescriptor_LENGTH(4),
+ USBGenericDescriptor_STRING,
+ USBStringDescriptor_UNICODE('0'),
+ USBStringDescriptor_UNICODE('1'),
+ USBStringDescriptor_UNICODE('2'),
+ USBStringDescriptor_UNICODE('3')
+};
+
+/// Array of pointers to the four string descriptors.
+const unsigned char *stringDescriptors[] = {
+
+ languageIdDescriptor,
+ manufacturerDescriptor,
+ productDescriptor,
+ serialNumberDescriptor,
+};
+
+//------------------------------------------------------------------------------
+// Exported variables
+//------------------------------------------------------------------------------
+
+/// List of descriptors required by an USB audio speaker device driver.
+const USBDDriverDescriptors compositedDriverDescriptors = {
+
+ &deviceDescriptor,
+ (const USBConfigurationDescriptor *) &configurationDescriptors,
+#ifdef BOARD_USB_UDPHS
+ &qualifierDescriptor,
+ (const USBConfigurationDescriptor *) &configurationDescriptors,
+ &deviceDescriptor,
+ (const USBConfigurationDescriptor *) &configurationDescriptors,
+ &qualifierDescriptor,
+ (const USBConfigurationDescriptor *) &configurationDescriptors,
+#else
+ 0, 0, 0, 0, 0, 0,
+#endif
+ stringDescriptors,
+ 4 // Number of string descriptors
+};
+
+#if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+/// Report descriptor used by the driver.
+const unsigned char hiddReportDescriptor[] = {
+
+ HIDReport_GLOBAL_USAGEPAGE + 1, HIDGenericDesktop_PAGEID,
+ HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_KEYBOARD,
+ HIDReport_COLLECTION + 1, HIDReport_COLLECTION_APPLICATION,
+
+ // Input report: modifier keys
+ HIDReport_GLOBAL_REPORTSIZE + 1, 1,
+ HIDReport_GLOBAL_REPORTCOUNT + 1, 8,
+ HIDReport_GLOBAL_USAGEPAGE + 1, HIDKeypad_PAGEID,
+ HIDReport_LOCAL_USAGEMINIMUM + 1,
+ HIDD_Descriptors_FIRSTMODIFIERKEY,
+ HIDReport_LOCAL_USAGEMAXIMUM + 1,
+ HIDD_Descriptors_LASTMODIFIERKEY,
+ HIDReport_GLOBAL_LOGICALMINIMUM + 1, 0,
+ HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 1,
+ HIDReport_INPUT + 1, HIDReport_VARIABLE,
+
+ // Input report: standard keys
+ HIDReport_GLOBAL_REPORTCOUNT + 1, 3,
+ HIDReport_GLOBAL_REPORTSIZE + 1, 8,
+ HIDReport_GLOBAL_LOGICALMINIMUM + 1,
+ HIDD_Descriptors_FIRSTSTANDARDKEY,
+ HIDReport_GLOBAL_LOGICALMAXIMUM + 1,
+ HIDD_Descriptors_LASTSTANDARDKEY,
+ HIDReport_GLOBAL_USAGEPAGE + 1, HIDKeypad_PAGEID,
+ HIDReport_LOCAL_USAGEMINIMUM + 1,
+ HIDD_Descriptors_FIRSTSTANDARDKEY,
+ HIDReport_LOCAL_USAGEMAXIMUM + 1,
+ HIDD_Descriptors_LASTSTANDARDKEY,
+ HIDReport_INPUT + 1, 0 /* Data array */,
+
+ // Output report: LEDs
+ HIDReport_GLOBAL_REPORTCOUNT + 1, 3,
+ HIDReport_GLOBAL_REPORTSIZE + 1, 1,
+ HIDReport_GLOBAL_USAGEPAGE + 1, HIDLeds_PAGEID,
+ HIDReport_GLOBAL_LOGICALMINIMUM + 1, 0,
+ HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 1,
+ HIDReport_LOCAL_USAGEMINIMUM + 1, HIDLeds_NUMLOCK,
+ HIDReport_LOCAL_USAGEMAXIMUM + 1, HIDLeds_SCROLLLOCK,
+ HIDReport_OUTPUT + 1, HIDReport_VARIABLE,
+
+ // Output report: padding
+ HIDReport_GLOBAL_REPORTCOUNT + 1, 1,
+ HIDReport_GLOBAL_REPORTSIZE + 1, 5,
+ HIDReport_OUTPUT + 1, HIDReport_CONSTANT,
+
+ HIDReport_ENDCOLLECTION
+};
+#endif // (HID defined)
+
diff --git a/at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.h b/at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.h
new file mode 100644
index 0000000..c82f9bc
--- /dev/null
+++ b/at91lib/usb/device/composite/COMPOSITEDDriverDescriptors.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.
+ * ----------------------------------------------------------------------------
+ */
+
+#ifndef COMPOSITEDDRIVERDESCRIPTORS_H
+#define COMPOSITEDDRIVERDESCRIPTORS_H
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include <board.h>
+#include <usb/device/core/USBDDriverDescriptors.h>
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+
+/// Number of interfaces of the device
+#if defined(usb_CDCAUDIO) || defined(usb_CDCCDC)
+ #define COMPOSITEDDriverDescriptors_NUMINTERFACE 4
+#elif defined(usb_CDCHID) || defined(usb_CDCMSD) || defined(usb_HIDAUDIO)
+ #define COMPOSITEDDriverDescriptors_NUMINTERFACE 3
+#elif defined(usb_HIDMSD)
+ #define COMPOSITEDDriverDescriptors_NUMINTERFACE 2
+#else
+ #error USB Composite class not defined.
+#endif
+
+//-----------------------------------------------------------------------------
+// Exported variables
+//-----------------------------------------------------------------------------
+
+extern const USBDDriverDescriptors compositedDriverDescriptors;
+
+#endif //#ifndef COMPOSITEDDRIVERDESCRIPTORS_H
diff --git a/at91lib/usb/device/composite/HIDDFunctionDriver.c b/at91lib/usb/device/composite/HIDDFunctionDriver.c
new file mode 100644
index 0000000..1ba89a8
--- /dev/null
+++ b/at91lib/usb/device/composite/HIDDFunctionDriver.c
@@ -0,0 +1,466 @@
+/* ----------------------------------------------------------------------------
+ * 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.
+ * ----------------------------------------------------------------------------
+ */
+
+#if defined(usb_CDCHID) || defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+// GENERAL
+#include <utility/trace.h>
+#include <utility/assert.h>
+// USB
+#include <usb/device/core/USBD.h>
+#include <usb/common/core/USBGetDescriptorRequest.h>
+#include <usb/device/core/USBDDriver.h>
+// HID
+#include <usb/device/hid-keyboard/HIDDKeyboardDriver.h>
+#include <usb/device/hid-keyboard/HIDDKeyboardDriverDescriptors.h>
+#include <usb/device/hid-keyboard/HIDDKeyboardCallbacks.h>
+#include <usb/device/hid-keyboard/HIDDKeyboardInputReport.h>
+#include <usb/device/hid-keyboard/HIDDKeyboardOutputReport.h>
+#include <usb/common/hid/HIDGenericDescriptor.h>
+#include <usb/common/hid/HIDDescriptor.h>
+#include <usb/common/hid/HIDGenericRequest.h>
+#include <usb/common/hid/HIDReportRequest.h>
+#include <usb/common/hid/HIDIdleRequest.h>
+#include <usb/common/hid/HIDKeypad.h>
+
+#include "HIDDFunctionDriver.h"
+#include "HIDDFunctionDriverDescriptors.h"
+
+//-----------------------------------------------------------------------------
+// Internal types
+//-----------------------------------------------------------------------------
+
+/// Driver structure for an HID device implementing keyboard functionalities.
+typedef struct {
+
+ /// Pointer to USB device driver instance
+ USBDDriver * pUsbdDriver;
+ /// Idle rate (in milliseconds) of the input report
+ unsigned char inputReportIdleRate;
+ /// Input report instance.
+ HIDDKeyboardInputReport inputReport;
+ /// Output report instance.
+ HIDDKeyboardOutputReport outputReport;
+
+} HIDDKeyboardDriver;
+
+//-----------------------------------------------------------------------------
+// Internal variables
+//-----------------------------------------------------------------------------
+
+/// Static instance of the HID keyboard device driver.
+static HIDDKeyboardDriver hiddKeyboardDriver;
+
+//-----------------------------------------------------------------------------
+// Internal functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Returns the descriptor requested by the host.
+/// \param type Descriptor type.
+/// \param length Maximum number of bytes to send.
+/// \return 1 if the request has been handled by this function, otherwise 0.
+//-----------------------------------------------------------------------------
+static unsigned char HIDD_GetDescriptor(unsigned char type,
+ unsigned char length)
+{
+ const USBConfigurationDescriptor *pConfiguration;
+ HIDDescriptor *hidDescriptor;
+
+ switch (type) {
+
+ case HIDGenericDescriptor_REPORT:
+ TRACE_INFO_WP("Report ");
+
+ // Adjust length and send report descriptor
+ if (length > HIDD_Descriptors_REPORTSIZE) {
+
+ length = HIDD_Descriptors_REPORTSIZE;
+ }
+ USBD_Write(0, &hiddReportDescriptor, length, 0, 0);
+ break;
+
+ case HIDGenericDescriptor_HID:
+ TRACE_INFO_WP("HID ");
+
+ // Configuration descriptor is different depending on speed
+ if (USBD_IsHighSpeed()) {
+
+ pConfiguration = hiddKeyboardDriver
+ .pUsbdDriver->pDescriptors->pHsConfiguration;
+ }
+ else {
+
+ pConfiguration = hiddKeyboardDriver
+ .pUsbdDriver->pDescriptors->pFsConfiguration;
+ }
+
+ // Parse the device configuration to get the HID descriptor
+ USBConfigurationDescriptor_Parse(pConfiguration,
+ 0,
+ 0,
+ (USBGenericDescriptor **) &hidDescriptor);
+
+ // Adjust length and send HID descriptor
+ if (length > sizeof(HIDDescriptor)) {
+
+ length = sizeof(HIDDescriptor);
+ }
+ USBD_Write(0, hidDescriptor, length, 0, 0);
+ break;
+
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
+//-----------------------------------------------------------------------------
+/// Sends the current Idle rate of the input report to the host.
+//-----------------------------------------------------------------------------
+static void HIDD_GetIdle()
+{
+ TRACE_INFO_WP("gIdle ");
+
+ USBD_Write(0, &(hiddKeyboardDriver.inputReportIdleRate), 1, 0, 0);
+}
+
+//-----------------------------------------------------------------------------
+/// Retrieves the new idle rate of the input report from the USB host.
+/// \param idleRate New input report idle rate.
+//-----------------------------------------------------------------------------
+static void HIDD_SetIdle(unsigned char idleRate)
+{
+ TRACE_INFO_WP("sIdle(%d) ", idleRate);
+
+ hiddKeyboardDriver.inputReportIdleRate = idleRate;
+ USBD_Write(0, 0, 0, 0, 0);
+}
+
+//-----------------------------------------------------------------------------
+/// Sends the requested report to the host.
+/// \param type Report type.
+/// \param length Maximum number of bytes to send.
+//-----------------------------------------------------------------------------
+static void HIDD_GetReport(unsigned char type,
+ unsigned short length)
+{
+ TRACE_INFO_WP("gReport ");
+
+ // Check report type
+ switch (type) {
+
+ case HIDReportRequest_INPUT:
+ TRACE_INFO_WP("In ");
+
+ // Adjust size and send report
+ if (length > sizeof(HIDDKeyboardInputReport)) {
+
+ length = sizeof(HIDDKeyboardInputReport);
+ }
+ USBD_Write(0, // Endpoint #0
+ &(hiddKeyboardDriver.inputReport),
+ length,
+ 0, // No callback
+ 0);
+ break;
+
+ case HIDReportRequest_OUTPUT:
+ TRACE_INFO_WP("Out ");
+
+ // Adjust size and send report
+ if (length > sizeof(HIDDKeyboardOutputReport)) {
+
+ length = sizeof(HIDDKeyboardOutputReport);
+ }
+ USBD_Write(0, // Endpoint #0
+ &(hiddKeyboardDriver.outputReport),
+ length,
+ 0, // No callback
+ 0);
+ break;
+
+ default:
+ USBD_Stall(0);
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Callback invoked when an output report has been received from the host.
+/// Forward the new status of the LEDs to the user program via the
+//-----------------------------------------------------------------------------
+static void HIDD_ReportReceived()
+{
+ TRACE_INFO_WP("oReport ");
+
+ // Trigger callback
+ HIDDKeyboardCallbacks_LedsChanged(
+ HIDDKeyboardOutputReport_GetNumLockStatus(
+ &(hiddKeyboardDriver.outputReport)),
+ HIDDKeyboardOutputReport_GetCapsLockStatus(
+ &(hiddKeyboardDriver.outputReport)),
+ HIDDKeyboardOutputReport_GetScrollLockStatus(
+ &(hiddKeyboardDriver.outputReport)));
+
+ // Restart transfer
+ USBD_Read(HIDD_Descriptors_INTERRUPTOUT,
+ &(hiddKeyboardDriver.outputReport),
+ sizeof(HIDDKeyboardOutputReport),
+ (TransferCallback) HIDD_ReportReceived,
+ 0); // No argument for callback function
+}
+
+//-----------------------------------------------------------------------------
+/// Retrieves the new value of a report from the host and saves it.
+/// \param type Report type.
+/// \param length Report length.
+//-----------------------------------------------------------------------------
+static void HIDD_SetReport(unsigned char type,
+ unsigned short length)
+{
+ TRACE_INFO_WP("sReport ");
+
+ // Check report type
+ switch (type) {
+
+ case HIDReportRequest_INPUT:
+ // SET_REPORT requests on input reports are ignored
+ USBD_Stall(0);
+ break;
+
+ case HIDReportRequest_OUTPUT:
+ // Check report length
+ if (length != sizeof(HIDDKeyboardOutputReport)) {
+
+ USBD_Stall(0);
+ }
+ else {
+
+ USBD_Read(0, // Endpoint #0
+ &(hiddKeyboardDriver.outputReport),
+ length,
+ (TransferCallback) HIDD_ReportReceived,
+ 0); // No argument to the callback function
+ }
+ break;
+
+ default:
+ USBD_Stall(0);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Initializes an USB HID keyboard function driver.
+/// \param pUsbdDriver Pointer to the USB driver instance.
+//-----------------------------------------------------------------------------
+void HIDDFunctionDriver_Initialize(USBDDriver * pUsbdDriver)
+{
+ hiddKeyboardDriver.inputReportIdleRate = 0;
+ HIDDKeyboardInputReport_Initialize(&(hiddKeyboardDriver.inputReport));
+ HIDDKeyboardOutputReport_Initialize(&(hiddKeyboardDriver.outputReport));
+
+ hiddKeyboardDriver.pUsbdDriver = pUsbdDriver;
+}
+
+//-----------------------------------------------------------------------------
+/// Handles HID-specific SETUP request sent by the host.
+/// \param request Pointer to a USBGenericRequest instance.
+/// \return 0 if the request is Unsupported, 1 if the request handled.
+//-----------------------------------------------------------------------------
+unsigned char HIDDFunctionDriver_RequestHandler(
+ const USBGenericRequest *request)
+{
+ TRACE_INFO_WP("NewReq ");
+
+ // Check if this is a standard request
+ if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) {
+
+ // This is a standard request
+ switch (USBGenericRequest_GetRequest(request)) {
+
+ case USBGenericRequest_GETDESCRIPTOR:
+ // Check if this is a HID descriptor, otherwise forward it to
+ // the standard driver
+ if (!HIDD_GetDescriptor(
+ USBGetDescriptorRequest_GetDescriptorType(request),
+ USBGenericRequest_GetLength(request))) {
+
+ USBDDriver_RequestHandler(hiddKeyboardDriver.pUsbdDriver,
+ request);
+ }
+ break;
+
+ default:
+ return 0;
+ }
+ }
+ // Check if this is a class request
+ else if (USBGenericRequest_GetType(request) == USBGenericRequest_CLASS) {
+
+ // This is a class-specific request
+ switch (USBGenericRequest_GetRequest(request)) {
+
+ case HIDGenericRequest_GETIDLE:
+ HIDD_GetIdle();
+ break;
+
+ case HIDGenericRequest_SETIDLE:
+ HIDD_SetIdle(HIDIdleRequest_GetIdleRate(request));
+ break;
+
+ case HIDGenericRequest_GETREPORT:
+ HIDD_GetReport(
+ HIDReportRequest_GetReportType(request),
+ USBGenericRequest_GetLength(request));
+ break;
+
+ case HIDGenericRequest_SETREPORT:
+ HIDD_SetReport(
+ HIDReportRequest_GetReportType(request),
+ USBGenericRequest_GetLength(request));
+ break;
+
+ default:
+ return 0;
+ }
+ }
+ return 1;
+}
+
+//-----------------------------------------------------------------------------
+/// Invoked whenever the configuration of the device is changed by the host.
+/// \param cfgnum Newly configuration number.
+//-----------------------------------------------------------------------------
+void HIDDFunctionCallbacks_ConfigurationChanged(unsigned char cfgnum)
+{
+ if (cfgnum > 0) {
+
+ // Start receiving output reports
+ USBD_Read(HIDD_Descriptors_INTERRUPTOUT,
+ &(hiddKeyboardDriver.outputReport),
+ sizeof(HIDDKeyboardOutputReport),
+ (TransferCallback) HIDD_ReportReceived,
+ 0); // No argument for callback function
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Reports a change in which keys are currently pressed or release to the
+/// host.
+/// \param pressedKeys Pointer to an array of key codes indicating keys that
+/// have been pressed since the last call to
+/// <HIDDKeyboardDriver_ChangeKeys>.
+/// \param pressedKeysSize Number of key codes in the pressedKeys array.
+/// \param releasedKeys Pointer to an array of key codes indicates keys that
+/// have been released since the last call to
+/// <HIDDKeyboardDriver_ChangeKeys>.
+/// \param releasedKeysSize Number of key codes in the releasedKeys array.
+/// \return <USBD_STATUS_SUCCESS> if the report has been sent to the host;
+/// otherwise an error code.
+//-----------------------------------------------------------------------------
+unsigned char HIDDKeyboardDriver_ChangeKeys(unsigned char *pressedKeys,
+ unsigned char pressedKeysSize,
+ unsigned char *releasedKeys,
+ unsigned char releasedKeysSize)
+{
+ // Press keys
+ while (pressedKeysSize > 0) {
+
+ // Check if this is a standard or modifier key
+ if (HIDKeypad_IsModifierKey(*pressedKeys)) {
+
+ // Set the corresponding bit in the input report
+ HIDDKeyboardInputReport_PressModifierKey(
+ &(hiddKeyboardDriver.inputReport),
+ *pressedKeys);
+ }
+ else {
+
+ HIDDKeyboardInputReport_PressStandardKey(
+ &(hiddKeyboardDriver.inputReport),
+ *pressedKeys);
+ }
+
+ pressedKeysSize--;
+ pressedKeys++;
+ }
+
+ // Release keys
+ while (releasedKeysSize > 0) {
+
+ // Check if this is a standard or modifier key
+ if (HIDKeypad_IsModifierKey(*releasedKeys)) {
+
+ // Set the corresponding bit in the input report
+ HIDDKeyboardInputReport_ReleaseModifierKey(
+ &(hiddKeyboardDriver.inputReport),
+ *releasedKeys);
+ }
+ else {
+
+ HIDDKeyboardInputReport_ReleaseStandardKey(
+ &(hiddKeyboardDriver.inputReport),
+ *releasedKeys);
+ }
+
+ releasedKeysSize--;
+ releasedKeys++;
+ }
+
+ // Send input report through the interrupt IN endpoint
+ return USBD_Write(HIDD_Descriptors_INTERRUPTIN,
+ &(hiddKeyboardDriver.inputReport),
+ sizeof(HIDDKeyboardInputReport),
+ 0,
+ 0);
+}
+
+//-----------------------------------------------------------------------------
+/// Starts a remote wake-up sequence if the host has explicitely enabled it
+/// by sending the appropriate SET_FEATURE request.
+//-----------------------------------------------------------------------------
+void HIDDKeyboardDriver_RemoteWakeUp(void)
+{
+ // Remote wake-up has been enabled
+ if (USBDDriver_IsRemoteWakeUpEnabled(hiddKeyboardDriver.pUsbdDriver)) {
+
+ USBD_RemoteWakeUp();
+ }
+}
+
+#endif
+
diff --git a/at91lib/usb/device/composite/HIDDFunctionDriver.h b/at91lib/usb/device/composite/HIDDFunctionDriver.h
new file mode 100644
index 0000000..a2c38ae
--- /dev/null
+++ b/at91lib/usb/device/composite/HIDDFunctionDriver.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.
+ * ----------------------------------------------------------------------------
+ */
+
+#ifndef HIDDFUNCTIONDRIVER_H
+#define HIDDFUNCTIONDRIVER_H
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include <usb/device/core/USBDDriver.h>
+#include <usb/common/core/USBGenericRequest.h>
+
+//-----------------------------------------------------------------------------
+// Exported functions
+//-----------------------------------------------------------------------------
+
+//- Function API for composite device
+extern void HIDDFunctionDriver_Initialize(USBDDriver * pUsbdDriver);
+
+extern unsigned char HIDDFunctionDriver_RequestHandler(
+ const USBGenericRequest *request);
+
+extern void HIDDFunctionCallbacks_ConfigurationChanged(unsigned char cfgnum);
+
+//- HID Keyboard API
+extern unsigned char HIDDKeyboardDriver_ChangeKeys(
+ unsigned char *pressedKeys,
+ unsigned char pressedKeysSize,
+ unsigned char *releasedKeys,
+ unsigned char releasedKeysSize);
+
+extern void HIDDKeyboardDriver_RemoteWakeUp(void);
+
+#endif // #define HIDDFUNCTIONDRIVER_H
diff --git a/at91lib/usb/device/composite/HIDDFunctionDriverDescriptors.h b/at91lib/usb/device/composite/HIDDFunctionDriverDescriptors.h
new file mode 100644
index 0000000..b1e91a3
--- /dev/null
+++ b/at91lib/usb/device/composite/HIDDFunctionDriverDescriptors.h
@@ -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.
+ * ----------------------------------------------------------------------------
+ */
+
+#ifndef HIDDFUNCTIONDRIVERDESCRIPTORS_H
+#define HIDDFUNCTIONDRIVERDESCRIPTORS_H
+
+//-----------------------------------------------------------------------------
+// Headers
+//-----------------------------------------------------------------------------
+
+#include <usb/device/core/USBDDriverDescriptors.h>
+#include <usb/common/hid/HIDKeypad.h>
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+
+//- Interface & Endpoints
+/// Interface Number.
+/// Interrupt IN endpoint number.
+/// Interrupt OUT endpoint number.
+/// Interrupt IN endpoint polling rate (in milliseconds).
+/// Interrupt OUT endpoint polling rate (in milliseconds).
+#if defined(usb_CDCHID)
+#define HIDD_Descriptors_INTERFACENUM 2
+#define HIDD_Descriptors_INTERRUPTIN 4
+#define HIDD_Descriptors_INTERRUPTOUT 5
+#elif defined(usb_HIDAUDIO) || defined(usb_HIDMSD)
+#define HIDD_Descriptors_INTERFACENUM 0
+#define HIDD_Descriptors_INTERRUPTIN 1
+#define HIDD_Descriptors_INTERRUPTOUT 2
+#endif
+#define HIDD_Descriptors_INTERRUPTIN_POLLING 10
+#define HIDD_Descriptors_INTERRUPTOUT_POLLING 10
+
+//- Keypad keys
+/// Key code of the first accepted modifier key.
+#define HIDD_Descriptors_FIRSTMODIFIERKEY HIDKeypad_LEFTCONTROL
+/// Key code of the last accepted modifier key.
+#define HIDD_Descriptors_LASTMODIFIERKEY HIDKeypad_RIGHTGUI
+/// Key code of the first accepted standard key.
+#define HIDD_Descriptors_FIRSTSTANDARDKEY 0
+/// Key code of the last accepted standard key.
+#define HIDD_Descriptors_LASTSTANDARDKEY HIDKeypad_NUMLOCK
+
+//- Report descriptor
+/// Size of the report descriptor in bytes.
+#define HIDD_Descriptors_REPORTSIZE 61
+
+//-----------------------------------------------------------------------------
+// Exported variables
+//-----------------------------------------------------------------------------
+
+/// Report descriptor used by the driver.
+extern const unsigned char hiddReportDescriptor[];
+
+#endif // #define HIDDFUNCTIONDRIVERDESCRIPTORS_H
+
diff --git a/at91lib/usb/device/composite/drv/CompositeCDCSerial.inf b/at91lib/usb/device/composite/drv/CompositeCDCSerial.inf
new file mode 100644
index 0000000..973a14b
--- /dev/null
+++ b/at91lib/usb/device/composite/drv/CompositeCDCSerial.inf
@@ -0,0 +1,57 @@
+; $Id: 6119.inf,v 1.1.2.1 2006/12/05 08:33:25 danielru Exp $
+
+[Version] ; Version section
+Signature="$Chicago$" ; All Windows versions
+Class=Ports ; This is a serial port driver
+ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} ; Associated GUID
+Provider=%ATMEL% ; Driver is provided by ATMEL
+DriverVer=09/12/2006,1.1.1.5 ; Driver version 1.1.1.5 published on 23 February 2007
+
+[DestinationDirs] ; DestinationDirs section
+DefaultDestDir=12 ; Default install directory is \drivers or \IOSubSys
+
+[Manufacturer] ; Manufacturer section
+%ATMEL%=AtmelMfg ; Only one manufacturer (ATMEL), models section is named
+ ; AtmelMfg
+
+[AtmelMfg] ; Models section corresponding to ATMEL
+%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6130&MI_00 ; Identifies a device with ATMEL Vendor ID (03EBh) and
+ ; Product ID equal to 6130h. Corresponding Install section
+ ; is named USBtoSer.Install ( CDCHID )
+%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6131&MI_00 ; Identifies a device with ATMEL Vendor ID (03EBh) and
+ ; Product ID equal to 6131h. Corresponding Install section
+ ; is named USBtoSer.Install ( CDCAUDIO )
+%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6132&MI_00 ; Identifies a device with ATMEL Vendor ID (03EBh) and
+ ; Product ID equal to 6132h. Corresponding Install section
+ ; is named USBtoSer.Install ( CDCMSD )
+%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6133&MI_00 ; Identifies a device with ATMEL Vendor ID (03EBh) and
+ ; Product ID equal to 6133h. Corresponding Install section
+ ; is named USBtoSer.Install ( CDCCDC )
+%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6133&MI_02 ; Identifies a device with ATMEL Vendor ID (03EBh) and
+ ; Product ID equal to 6133h. Corresponding Install section
+ ; is named USBtoSer.Install ( CDCCDC )
+
+[USBtoSer.Install] ; Install section
+include=mdmcpq.inf
+CopyFiles=FakeModemCopyFileSection
+AddReg=USBtoSer.AddReg ; Registry keys to add are listed in USBtoSer.AddReg
+
+[USBtoSer.AddReg] ; AddReg section
+HKR,,DevLoader,,*ntkern ;
+HKR,,NTMPDriver,,usbser.sys
+HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
+
+[USBtoSer.Install.Services] ; Services section
+AddService=usbser,0x00000002,USBtoSer.AddService ; Assign usbser as the PnP driver for the device
+
+[USBtoSer.AddService] ; Service install section
+DisplayName=%USBSer% ; Name of the serial driver
+ServiceType=1 ; Service kernel driver
+StartType=3 ; Driver is started by the PnP manager
+ErrorControl=1 ; Warn about errors
+ServiceBinary=%12%\usbser.sys ; Driver filename
+
+[Strings] ; Strings section
+ATMEL="ATMEL Corp." ; String value for the ATMEL symbol
+USBtoSerialConverter="AT91 USB to Serial Converter" ; String value for the USBtoSerialConverter symbol
+USBSer="USB Composite Serial Driver" ; String value for the USBSer symbol \ No newline at end of file
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardCallbacks.h b/at91lib/usb/device/hid-keyboard/HIDDKeyboardCallbacks.h
new file mode 100644
index 0000000..6bbfaea
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardCallbacks.h
@@ -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.
+ * ----------------------------------------------------------------------------
+ */
+
+/**
+ \unit HIDDKeyboardCallbacks
+
+ !!!Purpose
+
+ Definitions of callbacks used by the HID keyboard device driver to
+ notify the application of events.
+
+ !!!Usage
+
+ -# Re-implement any number of these callbacks anywhere in the program;
+ they will be called automatically by the driver when the related
+ event occurs.
+*/
+
+#ifndef HIDDKEYBOARDCALLBACKS_H
+#define HIDDKEYBOARDCALLBACKS_H
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern void HIDDKeyboardCallbacks_LedsChanged(unsigned char numLockStatus,
+ unsigned char capsLockStatus,
+ unsigned char scrollLockStatus);
+
+#endif //#ifndef HIDDKEYBOARDCALLBACKS_H
+
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardDriver.h b/at91lib/usb/device/hid-keyboard/HIDDKeyboardDriver.h
new file mode 100644
index 0000000..42dc0a2
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardDriver.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 HIDDKeyboardDriver
+
+ !!!Purpose
+
+ Definition of methods for using a HID keyboard device driver.
+
+ !!!Usage
+
+ -# Re-implement the USBDCallbacks_RequestReceived callback to forward
+ requests to HIDDKeyboardDriver_RequestHandler. This is done
+ automatically unless the NOAUTOCALLBACK symbol is defined during
+ compilation.
+ -# Initialize the driver using HIDDKeyboardDriver_Initialize. The
+ USB driver is automatically initialized by this method.
+ -# Call the HIDDKeyboardDriver_ChangeKeys method when one or more
+ keys are pressed/released.
+*/
+
+#ifndef HIDDKEYBOARDDRIVER_H
+#define HIDDKEYBOARDDRIVER_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/common/core/USBGenericRequest.h>
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern void HIDDKeyboardDriver_Initialize();
+
+extern void HIDDKeyboardDriver_RequestHandler(const USBGenericRequest *request);
+
+extern unsigned char HIDDKeyboardDriver_ChangeKeys(
+ unsigned char *pressedKeys,
+ unsigned char pressedKeysSize,
+ unsigned char *releasedKeys,
+ unsigned char releasedKeysSize);
+
+extern void HIDDKeyboardDriver_RemoteWakeUp(void);
+
+#endif //#ifndef HIDDKEYBOARDDRIVER_H
+
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardDriverDescriptors.h b/at91lib/usb/device/hid-keyboard/HIDDKeyboardDriverDescriptors.h
new file mode 100644
index 0000000..9a2dc2f
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardDriverDescriptors.h
@@ -0,0 +1,114 @@
+/* ----------------------------------------------------------------------------
+ * 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 HIDDKeyboardDriverDescriptors
+
+ !!!Purpose
+
+ Definitions of the descriptors required by the HID device keyboard
+ driver.
+
+ !!!Usage
+
+ -# Use the hiddKeyboardDriverDescriptors variable to initialize a
+ USBDDriver instance.
+ -# Send hiddReportDescriptor to the host when a GET_DESCRIPTOR request
+ for the report descriptor is received.
+*/
+
+#ifndef HIDDKEYBOARDDRIVERDESCRIPTORS_H
+#define HIDDKEYBOARDDRIVERDESCRIPTORS_H
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <usb/device/core/USBDDriverDescriptors.h>
+#include <usb/common/hid/HIDKeypad.h>
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Endpoints"
+/// This page lists endpoint addresses and polling settings.
+///
+/// !Endpoints
+/// - HIDDKeyboardDriverDescriptors_INTERRUPTIN
+/// - HIDDKeyboardDriverDescriptors_INTERRUPTOUT
+///
+/// !Polling Rates
+/// - HIDDKeyboardDriverDescriptors_INTERRUPTIN_POLLING
+/// - HIDDKeyboardDriverDescriptors_INTERRUPTOUT_POLLING
+
+/// Interrupt IN endpoint number.
+#define HIDDKeyboardDriverDescriptors_INTERRUPTIN 1
+/// Interrupt IN endpoint polling rate (in milliseconds).
+#define HIDDKeyboardDriverDescriptors_INTERRUPTIN_POLLING 10
+/// Interrupt OUT endpoint number.
+#define HIDDKeyboardDriverDescriptors_INTERRUPTOUT 2
+/// Interrupt OUT endpoint polling rate (in milliseconds).
+#define HIDDKeyboardDriverDescriptors_INTERRUPTOUT_POLLING 10
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// \page "HID Keypad keys"
+/// This page lists definition for HID keypad keys.
+///
+/// !Keys
+/// - HIDDKeyboardDriverDescriptors_FIRSTMODIFIERKEY
+/// - HIDDKeyboardDriverDescriptors_LASTMODIFIERKEY
+/// - HIDDKeyboardDriverDescriptors_FIRSTSTANDARDKEY
+/// - HIDDKeyboardDriverDescriptors_LASTSTANDARDKEY
+
+/// Key code of the first accepted modifier key.
+#define HIDDKeyboardDriverDescriptors_FIRSTMODIFIERKEY HIDKeypad_LEFTCONTROL
+/// Key code of the last accepted modifier key.
+#define HIDDKeyboardDriverDescriptors_LASTMODIFIERKEY HIDKeypad_RIGHTGUI
+/// Key code of the first accepted standard key.
+#define HIDDKeyboardDriverDescriptors_FIRSTSTANDARDKEY 0
+/// Key code of the last accepted standard key.
+#define HIDDKeyboardDriverDescriptors_LASTSTANDARDKEY HIDKeypad_NUMLOCK
+//------------------------------------------------------------------------------
+
+/// Size of the report descriptor in bytes.
+#define HIDDKeyboardDriverDescriptors_REPORTSIZE 61
+
+//------------------------------------------------------------------------------
+// Exported variables
+//------------------------------------------------------------------------------
+
+extern USBDDriverDescriptors hiddKeyboardDriverDescriptors;
+
+extern const unsigned char hiddReportDescriptor[];
+
+#endif //#ifndef HIDDKEYBOARDDRIVERDESCRIPTORS_H
+
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.c b/at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.c
new file mode 100644
index 0000000..3257bdb
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.c
@@ -0,0 +1,164 @@
+/* ----------------------------------------------------------------------------
+ * 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: HIDDKeyboardInputReport implementation
+
+ About: Purpose
+ Implementation of the HIDDKeyboardInputReport class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "HIDDKeyboardInputReport.h"
+#include "HIDDKeyboardDriverDescriptors.h"
+#include <utility/assert.h>
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Initializes a keyboard input report instance.
+/// \param report Pointer to a HIDDKeyboardInputReport instance.
+//------------------------------------------------------------------------------
+void HIDDKeyboardInputReport_Initialize(HIDDKeyboardInputReport *report)
+{
+ unsigned int i;
+
+ report->bmModifierKeys = 0;
+ for (i = 0; i < HIDDKeyboardInputReport_MAXKEYPRESSES; i++) {
+
+ report->pressedKeys[i] = 0;
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Reports a standard key as being pressed.
+/// \param report Pointer to a HIDDKeyboardInputReport instance.
+/// \param key Key code of the standard key.
+//------------------------------------------------------------------------------
+void HIDDKeyboardInputReport_PressStandardKey(HIDDKeyboardInputReport *report,
+ unsigned char key)
+{
+ ASSERT(key <= HIDDKeyboardDriverDescriptors_LASTSTANDARDKEY,
+ "Invalid standard key code (%d)\n\r",
+ key);
+
+ // Find first available slot
+ unsigned int i = 0;
+ unsigned char found = 0;
+ while ((i < HIDDKeyboardInputReport_MAXKEYPRESSES) && !found) {
+
+ // Free slot: no key referenced (code = 0) or ErrorRollOver
+ if ((report->pressedKeys[i] == 0)
+ || (report->pressedKeys[i] == HIDKeypad_ERRORROLLOVER)) {
+
+ found = 1;
+ report->pressedKeys[i] = key;
+ }
+
+ i++;
+ }
+
+ // Report ErrorRollOver in all fields if too many keys are pressed
+ if (!found) {
+
+ for (i=0; i < HIDDKeyboardInputReport_MAXKEYPRESSES; i++) {
+
+ report->pressedKeys[i] = HIDKeypad_ERRORROLLOVER;
+ }
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Reports a standard key as not being pressed anymore.
+/// \param report Pointer to a HIDDKeyboardInputReport instance.
+/// \param key Key code of the standard key
+//------------------------------------------------------------------------------
+void HIDDKeyboardInputReport_ReleaseStandardKey(HIDDKeyboardInputReport *report,
+ unsigned char key)
+{
+ ASSERT(key <= HIDDKeyboardDriverDescriptors_LASTSTANDARDKEY,
+ "Invalid standard key code (%d)\n\r",
+ key);
+
+ // Look for key in array
+ unsigned int i = 0;
+ unsigned char found = 0;
+ while ((i < HIDDKeyboardInputReport_MAXKEYPRESSES) && !found) {
+
+ if (report->pressedKeys[i] == key) {
+
+ found = 1;
+ report->pressedKeys[i] = 0;
+ }
+
+ i++;
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Reports a modifier key as being currently pressed.
+/// \param report Pointer to a HIDDKeyboardInputReport instance.
+/// \param key Key code of the modifier key.
+//------------------------------------------------------------------------------
+void HIDDKeyboardInputReport_PressModifierKey(HIDDKeyboardInputReport *report,
+ unsigned char key)
+{
+ ASSERT((key >= HIDDKeyboardDriverDescriptors_FIRSTMODIFIERKEY)
+ && (key <= HIDDKeyboardDriverDescriptors_LASTMODIFIERKEY),
+ "Invalid standard key code (%d)\n\r",
+ key);
+
+ // Set corresponding bit
+ unsigned char bit = key - HIDDKeyboardDriverDescriptors_FIRSTMODIFIERKEY;
+ report->bmModifierKeys |= 1 << bit;
+}
+
+//------------------------------------------------------------------------------
+/// Reports a modifier key as not being pressed anymore.
+/// \param report Pointer to a HIDDKeyboardInputReport instance.
+/// \param key Key code of the modifier key.
+//------------------------------------------------------------------------------
+void HIDDKeyboardInputReport_ReleaseModifierKey(HIDDKeyboardInputReport *report,
+ unsigned char key)
+{
+ ASSERT((key >= HIDDKeyboardDriverDescriptors_FIRSTMODIFIERKEY)
+ && (key <= HIDDKeyboardDriverDescriptors_LASTMODIFIERKEY),
+ "Invalid standard key code (%d)\n\r",
+ key);
+
+ // Clear corresponding bit
+ unsigned char bit = key - HIDDKeyboardDriverDescriptors_FIRSTMODIFIERKEY;
+ report->bmModifierKeys &= ~(1 << bit);
+}
+
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.h b/at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.h
new file mode 100644
index 0000000..7eeafd8
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardInputReport.h
@@ -0,0 +1,149 @@
+/* ----------------------------------------------------------------------------
+ * ATMEL Microcontroller Software Support
+ * ----------------------------------------------------------------------------
+ * Copyright (c) 2008, Atmel Corporation
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the disclaimer below.
+ *
+ * Atmel's name may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
+ * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ----------------------------------------------------------------------------
+ */
+
+/**
+ \unit HIDDKeyboardInputReport.h
+
+ !!!Purpose
+
+ Class for manipulating HID keyboard input reports.
+
+ !!!Usage
+
+ -# Initialize a newly created input report with
+ HIDDKeyboardInputReport_Initialize.
+ -# Change the standard keys that are pressed and released using
+ HIDDKeyboardInputReport_PressStandardKey and
+ HIDDKeyboardInputReport_ReleaseStandardKey.
+ -# Change the modifier keys that are currently pressed and released
+ using HIDDKeyboardInputReport_PressModifierKey and
+ HIDDKeyboardInputReport_ReleaseModifierKey.
+*/
+
+#ifndef HIDDKEYBOARDINPUTREPORT_H
+#define HIDDKEYBOARDINPUTREPORT_H
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+/// Maximum number of simultaneous key presses.
+#define HIDDKeyboardInputReport_MAXKEYPRESSES 3
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// HID input report structure used by the keyboard driver to notify the
+/// host of pressed keys.
+///
+/// The first byte is used to report the state of modifier keys. The
+/// other three contains the keycodes of the currently pressed keys.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ /// State of modifier keys.
+ unsigned char bmModifierKeys:8;
+ /// Key codes of pressed keys.
+ unsigned char pressedKeys[HIDDKeyboardInputReport_MAXKEYPRESSES];
+
+} __attribute__ ((packed)) HIDDKeyboardInputReport; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+/*
+ Function: HIDDKeyboardInputReport_Initialize
+ Initializes a keyboard input report instance.
+
+ Parameters:
+ report - Pointer to a HIDDKeyboardInputReport instance.
+*/
+extern void HIDDKeyboardInputReport_Initialize(HIDDKeyboardInputReport *report);
+
+/*
+ Function: HIDDKeyboardInputReport_PressStandardKey
+ Reports a standard key as being pressed.
+
+ Parameters:
+ report - Pointer to a HIDDKeyboardInputReport instance.
+ key - Key code of the standard key.
+*/
+extern void HIDDKeyboardInputReport_PressStandardKey(
+ HIDDKeyboardInputReport *report,
+ unsigned char key);
+
+/*
+ Function: HIDDKeyboardInputReport_ReleaseStandardKey
+ Reports a standard key as not being pressed anymore.
+
+ Parameters:
+ report - Pointer to a HIDDKeyboardInputReport instance.
+ key - Key code of the standard key
+*/
+extern void HIDDKeyboardInputReport_ReleaseStandardKey(
+ HIDDKeyboardInputReport *report,
+ unsigned char key);
+
+/*
+ Function: HIDDKeyboardInputReport_PressModifierKey
+ Reports a modifier key as being currently pressed.
+
+ Parameters:
+ report - Pointer to a HIDDKeyboardInputReport instance.
+ key - Key code of the modifier key.
+*/
+extern void HIDDKeyboardInputReport_PressModifierKey(
+ HIDDKeyboardInputReport *report,
+ unsigned char key);
+
+/*
+ Function: HIDDKeyboardInputReport_ReleaseModifierKey
+ Reports a modifier key as not being pressed anymore.
+
+ Parameters:
+ report - Pointer to a HIDDKeyboardInputReport instance.
+ key - Key code of the modifier key.
+*/
+extern void HIDDKeyboardInputReport_ReleaseModifierKey(
+ HIDDKeyboardInputReport *report,
+ unsigned char key);
+
+#endif //#ifndef HIDDKEYBOARDINPUTREPORT_H
+
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.c b/at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.c
new file mode 100644
index 0000000..f79d7ac
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.c
@@ -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.
+ * ----------------------------------------------------------------------------
+ */
+
+/*
+ Title: HIDDKeyboardOutputReport implementation
+
+ About: Purpose
+ Implementation of the HIDDKeyboardOutputReport class.
+*/
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include "HIDDKeyboardOutputReport.h"
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Initializes a keyboard output report.
+/// \param report Pointer to a HIDDKeyboardOutputReport instance.
+//------------------------------------------------------------------------------
+void HIDDKeyboardOutputReport_Initialize(HIDDKeyboardOutputReport *report)
+{
+ report->numLockStatus = 0;
+ report->capsLockStatus = 0;
+ report->scrollLockStatus = 0;
+ report->padding = 0;
+}
+
+//------------------------------------------------------------------------------
+/// Indicates the current status of the num. lock LED according to the
+/// given report.
+/// \param report Pointer to a HIDDKeyboardOutputReport instance.
+/// \return 1 if the num. lock LED is light on; otherwise 0.
+//------------------------------------------------------------------------------
+unsigned char HIDDKeyboardOutputReport_GetNumLockStatus(
+ const HIDDKeyboardOutputReport *report)
+{
+ return report->numLockStatus;
+}
+
+//------------------------------------------------------------------------------
+/// Indicates the current status of the caps lock LED according to the
+/// given report.
+/// \param report Pointer to a HIDDKeyboardOutputReport instance.
+/// \return 1 if the caps lock LED is light on; otherwise 0.
+//------------------------------------------------------------------------------
+unsigned char HIDDKeyboardOutputReport_GetCapsLockStatus(
+ const HIDDKeyboardOutputReport *report)
+{
+ return report->capsLockStatus;
+}
+
+//------------------------------------------------------------------------------
+/// Indicates the current status of the scroll lock LED according to the
+/// given report.
+/// \param report Pointer to a HIDDKeyboardOutputReport instance.
+/// \return 1 if the scroll lock LED is light on; otherwise 0.
+//------------------------------------------------------------------------------
+unsigned char HIDDKeyboardOutputReport_GetScrollLockStatus(
+ const HIDDKeyboardOutputReport *report)
+{
+ return report->scrollLockStatus;
+}
+
diff --git a/at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.h b/at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.h
new file mode 100644
index 0000000..760df1b
--- /dev/null
+++ b/at91lib/usb/device/hid-keyboard/HIDDKeyboardOutputReport.h
@@ -0,0 +1,96 @@
+/* ----------------------------------------------------------------------------
+ * 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 HIDDKeyboardOutputReport
+
+ !!!Purpose
+
+ Definition of a class for manipulating HID keyboard output reports.
+
+ !!!Usage
+
+ -# Initialize a newly-created output report instance with
+ HIDDKeyboardOutputReport_Initialize.
+ -# Retrieve the status of the three LEDs using
+ HIDDKeyboardOutputReport_GetNumLockStatus,
+ HIDDKeyboardOutputReport_GetCapsLockStatus and
+ HIDDKeyboardOutputReport_GetScrollLockStatus.
+*/
+
+#ifndef HIDKEYBOARDOUTPUTREPORT_H
+#define HIDKEYBOARDOUTPUTREPORT_H
+
+//------------------------------------------------------------------------------
+// Types
+//------------------------------------------------------------------------------
+
+#ifdef __ICCARM__ // IAR
+#pragma pack(1) // IAR
+#define __attribute__(...) // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+/// HID output report structure used by the host to control the state of
+/// the keyboard LEDs.
+///
+/// Only the first three bits are relevant, the other 5 are used as
+/// padding bits.
+//------------------------------------------------------------------------------
+typedef struct {
+
+ unsigned char numLockStatus:1, /// State of the num. lock LED.
+ capsLockStatus:1, /// State of the caps lock LED.
+ scrollLockStatus:1, /// State of the scroll lock LED.
+ padding:5; /// Padding bits.
+
+} __attribute__ ((packed)) HIDDKeyboardOutputReport; // GCC
+
+#ifdef __ICCARM__ // IAR
+#pragma pack() // IAR
+#endif // IAR
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern void HIDDKeyboardOutputReport_Initialize(
+ HIDDKeyboardOutputReport *report);
+
+extern unsigned char HIDDKeyboardOutputReport_GetNumLockStatus(
+ const HIDDKeyboardOutputReport *report);
+
+extern unsigned char HIDDKeyboardOutputReport_GetCapsLockStatus(
+ const HIDDKeyboardOutputReport *report);
+
+extern unsigned char HIDDKeyboardOutputReport_GetScrollLockStatus(
+ const HIDDKeyboardOutputReport *report);
+
+#endif //#ifndef HIDKEYBOARDOUTPUTREPORT_H
+
diff --git a/usb-device-composite-cdchid-project/Makefile b/usb-device-composite-cdchid-project/Makefile
new file mode 100644
index 0000000..349c787
--- /dev/null
+++ b/usb-device-composite-cdchid-project/Makefile
@@ -0,0 +1,173 @@
+# ----------------------------------------------------------------------------
+# ATMEL Microcontroller Software Support
+# ----------------------------------------------------------------------------
+# Copyright (c) 2008, Atmel Corporation
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the disclaimer below.
+#
+# Atmel's name may not be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
+# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# ----------------------------------------------------------------------------
+
+# Makefile for compiling the USB COMPOSITE project
+
+#-------------------------------------------------------------------------------
+# User-modifiable options
+#-------------------------------------------------------------------------------
+
+# Chip & board used for compilation
+# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
+CHIP = at91sam7se512
+BOARD = at91sam7se-ek
+
+# Trace level used for compilation
+# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
+# TRACE_LEVEL_DEBUG 5
+# TRACE_LEVEL_INFO 4
+# TRACE_LEVEL_WARNING 3
+# TRACE_LEVEL_ERROR 2
+# TRACE_LEVEL_FATAL 1
+# TRACE_LEVEL_NO_TRACE 0
+TRACE_LEVEL = 3
+
+# Optimization level, put in comment for debugging
+OPTIMIZATION = -Os
+
+# AT91 library directory
+AT91LIB = ../at91lib
+
+# Output file basename
+OUTPUT = usb-device-composite-cdchid-project-$(usb_CLASS)-$(BOARD)-$(CHIP)
+
+# Compile for all memories available on the board (this sets $(MEMORIES))
+include $(AT91LIB)/boards/$(BOARD)/board.mak
+
+# Output directories
+BIN = bin
+OBJ = obj
+
+#-------------------------------------------------------------------------------
+# Tools
+#-------------------------------------------------------------------------------
+
+# Tool suffix when cross-compiling
+CROSS_COMPILE = arm-none-eabi-
+
+# Compilation tools
+CC = $(CROSS_COMPILE)gcc
+SIZE = $(CROSS_COMPILE)size
+OBJCOPY = $(CROSS_COMPILE)objcopy
+
+# Flags
+INCLUDES = -I$(AT91LIB)/boards/$(BOARD) -I$(AT91LIB)/peripherals
+INCLUDES += -I$(AT91LIB)/components -I$(AT91LIB)/usb/device -I$(AT91LIB)
+
+CFLAGS = -Wall -mlong-calls -ffunction-sections
+CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
+CFLAGS += -Dusb_CDCHID
+ASFLAGS = -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
+LDFLAGS = -g $(OPTIMIZATION) -nostartfiles -Wl,--gc-sections
+
+#-------------------------------------------------------------------------------
+# Files
+#-------------------------------------------------------------------------------
+
+# Directories where source files can be found
+USB = $(AT91LIB)/usb
+UTILITY = $(AT91LIB)/utility
+PERIPH = $(AT91LIB)/peripherals
+BOARDS = $(AT91LIB)/boards
+COMP = $(AT91LIB)/components
+MEM = $(AT91LIB)/memories
+
+VPATH += $(MEM)
+VPATH += $(USB)/device/hid-keyboard $(USB)/common/hid
+VPATH += $(USB)/device/composite
+VPATH += $(USB)/device/core $(USB)/common/core
+VPATH += $(USB)/common/cdc
+VPATH += $(UTILITY)
+VPATH += $(PERIPH)/dbgu $(PERIPH)/aic $(PERIPH)/usart $(PERIPH)/pio $(PERIPH)/pmc
+VPATH += $(PERIPH)/cp15 $(PERIPH)/pit
+VPATH += $(BOARDS)/$(BOARD) $(BOARDS)/$(BOARD)/$(CHIP)
+
+# Objects built from C source files
+C_OBJECTS = main.o
+C_OBJECTS += COMPOSITEDDriver.o COMPOSITEDDriverDescriptors.o
+C_OBJECTS += CDCSetControlLineStateRequest.o CDCLineCoding.o
+C_OBJECTS += CDCDFunctionDriver.o
+C_OBJECTS += HIDIdleRequest.o HIDReportRequest.o HIDKeypad.o
+C_OBJECTS += HIDDKeyboardInputReport.o HIDDKeyboardOutputReport.o
+C_OBJECTS += HIDDFunctionDriver.o
+C_OBJECTS += USBD_OTGHS.o USBD_UDP.o USBD_UDPHS.o USBDDriver.o
+C_OBJECTS += USBDCallbacks_Initialized.o
+C_OBJECTS += USBDCallbacks_Reset.o
+#C_OBJECTS += USBDCallbacks_Resumed.o
+#C_OBJECTS += USBDCallbacks_Suspended.o
+#C_OBJECTS += USBDDriverCb_CfgChanged.o
+#C_OBJECTS += USBDDriverCb_IfSettingChanged.o
+C_OBJECTS += USBSetAddressRequest.o USBGenericDescriptor.o USBInterfaceRequest.o
+C_OBJECTS += USBGenericRequest.o USBGetDescriptorRequest.o
+C_OBJECTS += USBSetConfigurationRequest.o USBFeatureRequest.o
+C_OBJECTS += USBEndpointDescriptor.o USBConfigurationDescriptor.o
+C_OBJECTS += led.o string.o stdio.o
+C_OBJECTS += aic.o dbgu.o usart.o pio.o pio_it.o pmc.o cp15.o pit.o
+C_OBJECTS += board_memories.o board_lowlevel.o
+
+# Objects built from Assembly source files
+ASM_OBJECTS = board_cstartup.o
+ASM_OBJECTS += cp15_asm.o
+
+# Append OBJ and BIN directories to output filename
+OUTPUT := $(BIN)/$(OUTPUT)
+
+#-------------------------------------------------------------------------------
+# Rules
+#-------------------------------------------------------------------------------
+
+all: $(BIN) $(OBJ) $(MEMORIES)
+
+$(BIN) $(OBJ):
+ mkdir $@
+
+define RULES
+C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
+ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
+
+$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
+ $(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/$$@.lds" -o $(OUTPUT)-$$@.elf $$^
+ $(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
+ $(SIZE) $$^ $(OUTPUT)-$$@.elf
+
+$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
+ $(CC) $(CFLAGS) -D$(1) -c -o $$@ $$<
+
+$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
+ $(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<
+
+debug_$(1): $(1)
+ perl ../resources/gdb/debug.pl $(OUTPUT)-$(1).elf
+
+endef
+
+$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))
+
+clean:
+ -rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf
+
diff --git a/usb-device-composite-cdchid-project/bin/.empty b/usb-device-composite-cdchid-project/bin/.empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/usb-device-composite-cdchid-project/bin/.empty
diff --git a/usb-device-composite-cdchid-project/main.c b/usb-device-composite-cdchid-project/main.c
new file mode 100644
index 0000000..9d8a06c
--- /dev/null
+++ b/usb-device-composite-cdchid-project/main.c
@@ -0,0 +1,1011 @@
+/* ----------------------------------------------------------------------------
+ * 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 "USB COMPOSITE CDC+HID project"
+///
+/// !!!Purpose
+///
+/// The USB COMPOSITE Project will help you to get familiar with the
+/// USB Device Port(UDP)interface and also some of the other interfaces in
+/// AT91SAM microcontrollers. Also it can help you to be familiar with the USB
+/// Framework that is used for rapid development of USB-compliant class
+/// drivers such as USB Communication Device class (CDC), and how to combine
+/// two USB functions to a single composite device (such as CDC + MSD).
+///
+/// You can find following information depends on your needs:
+/// - Sample usage of USB Device Framework.
+/// - USB COMPOSITE device and functions driver development based on the AT91
+/// USB Device Framework and other re-usable class driver code.
+/// - USB enumerate sequence, the standard and class-specific descriptors and
+/// requests handling.
+/// - The initialize sequence and usage of UDP interface.
+///
+/// !See
+/// - pio: Pin configurations and peripheral configure.
+/// - memories: Storage Media interface for MSD
+/// - ssc: SSC interface driver
+/// - "dac-at73c213": I2S codec at73c213 driver
+/// - usb: USB Device Framework, USB CDC driver and UDP interface driver
+/// - "AT91 USB device framework"
+/// - "USBD API"
+/// - "composite"
+/// - "USB COMPOSITE Device"
+/// - "hid-keyboard"
+/// - "USB HID Keyboard"
+/// - "cdc-serial"
+/// - "USB CDC Serial Device"
+/// - projects:
+/// - "usb-device-hid-keyboard-project"
+/// - "usb-device-cdc-serial-project"
+///
+/// !!!Requirements
+///
+/// This package can be used with some of Atmel evaluation kits that have UDP
+/// interface, depending on the functions included.
+///
+/// The current supported board list:
+/// - at91sam7s-ek (exclude at91sam7s32)
+/// - at91sam7x-ek
+/// - at91sam7xc-ek
+/// - at91sam7a3-ek
+/// - at91sam7se-ek
+/// - at91sam9260-ek
+/// - at91sam9263-ek
+///
+/// !!!Windows Driver Update
+///
+/// The composite device is generally supported by Microsoft windows, but some
+/// patches are needed for muti-interface functions such as CDC & Audio. The
+/// example composite devices are tested under windows XP (SP3). For CDC
+/// serial port, additional windows driver file (CompositeCDCSerial.inf) can
+/// be found at at91lib\usb\device\composite\drv.
+///
+/// The following is alternate update to fix the composite device support
+/// on windows XP:
+///
+/// !!Install Windows Service Pack 3 (SP3)
+///
+/// All the fixes for USB generic driver are included in window XP service pack
+/// 3. It can be found at
+/// http://technet.microsoft.com/zh-cn/windows/bb794714(en-us).aspx .
+///
+/// !!Install Windows Hot Fixes
+///
+/// Two hot fixes are necessary for window to recognize the composite device
+/// correctly:
+///
+/// -# http://support.microsoft.com/kb/814560
+/// -# http://support.microsoft.com/kb/918365
+///
+/// !!!Description
+///
+/// When an EK running this program connected to a host (PC for example), with
+/// USB cable, host will notice the attachment of a USB %device. No %device
+/// driver offered for the %device now.
+///
+/// !!!Usage
+///
+/// -# Build the program and download it inside the evaluation board. Please
+/// refer to the
+/// <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6224.pdf">
+/// SAM-BA User Guide</a>, the
+/// <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6310.pdf">
+/// GNU-Based Software Development</a> application note or to the
+/// <a href="ftp://ftp.iar.se/WWWfiles/arm/Guides/EWARM_UserGuide.ENU.pdf">
+/// IAR EWARM User Guide</a>, depending on your chosen solution.
+/// -# On the computer, open and configure a terminal application
+/// (e.g. HyperTerminal on Microsoft Windows) with these settings:
+/// - 115200 bauds
+/// - 8 bits of data
+/// - No parity
+/// - 1 stop bit
+/// - No flow control
+/// -# Start the application.
+/// -# In the terminal window, the following text should appear:
+/// \code
+/// -- USB Composite Device Project xxx --
+/// -- AT91xxxxxx-xx
+/// -- Compiled: xxx xx xxxx xx:xx:xx --
+/// \endcode
+/// -# When connecting USB cable to windows, the LED blinks, and the host
+/// reports a new USB %device attachment.
+/// -# For the windows driver installation and the test functions, please
+/// refer to "USB CDC serial converter" &
+/// "USB HID Keyboard Project".
+/// -# You can use the inf file
+/// at91lib\\usb\\device\\composite\\drv\\CompositeCDCSerial.inf
+/// to install the CDC serial port.
+///
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// \unit
+///
+/// !Purpose
+///
+/// This file contains all the specific code for the
+/// usb-device-composite-cdchid-project
+///
+/// !Contents
+///
+/// The code can be roughly broken down as follows:
+/// - Configuration functions
+/// - VBus_Configure
+/// - PIO configurations in start of main
+/// - Interrupt handlers
+/// - ISR_Vbus
+/// - Callback functions
+/// - USBDCallbacks_RequestReceived
+/// - The main function, which implements the program behavior
+///
+/// Please refer to the list of functions in the #Overview# tab of this unit
+/// for more detailed information.
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+
+#include <board.h>
+#include <pio/pio.h>
+#include <pio/pio_it.h>
+#include <aic/aic.h>
+#include <usart/usart.h>
+#include <utility/trace.h>
+#include <pit/pit.h>
+#include <usb/common/core/USBConfigurationDescriptor.h>
+#include <usb/common/hid/HIDKeypad.h>
+#include <utility/led.h>
+#include <pmc/pmc.h>
+
+#include <usb/device/composite/COMPOSITEDDriver.h>
+
+#include <string.h>
+
+//-----------------------------------------------------------------------------
+// Definitions
+//-----------------------------------------------------------------------------
+#ifndef AT91C_ID_TC0
+#if defined(AT91C_ID_TC012)
+ #define AT91C_ID_TC0 AT91C_ID_TC012
+#elif defined(AT91C_ID_TC)
+ #define AT91C_ID_TC0 AT91C_ID_TC
+#else
+ #error Pb define ID_TC
+#endif
+#endif
+
+/// Master clock frequency in Hz
+#define MCK BOARD_MCK
+
+/// Number of keys used in the example.
+#define NUM_KEYS 4
+
+/// Number of non-modifiers keys.
+#define NUM_NORMAL_KEYS 3
+
+/// Number of modifier keys.
+#define NUM_MODIFIER_KEYS (NUM_KEYS - NUM_NORMAL_KEYS)
+
+/// Num lock LED index.
+#define LED_NUMLOCK USBD_LEDOTHER
+
+/// Delay for pushbutton debouncing (ms)
+#define DEBOUNCE_TIME 10
+
+/// PIT period value (useconds)
+#define PIT_PERIOD 1000
+
+/// Size in bytes of the buffer used for reading data from the USB & USART
+#define DATABUFFERSIZE BOARD_USB_ENDPOINTS_MAXPACKETSIZE(2)
+
+/// Use for power management
+#define STATE_IDLE 0
+/// The USB device is in suspend state
+#define STATE_SUSPEND 4
+/// The USB device is in resume state
+#define STATE_RESUME 5
+
+//-----------------------------------------------------------------------------
+// Internal variables
+//-----------------------------------------------------------------------------
+/// State of USB, for suspend and resume
+unsigned char USBState = STATE_IDLE;
+
+//- CDC
+/// List of pins that must be configured for use by the application.
+static const Pin pinsUsart[] = {PIN_USART0_TXD, PIN_USART0_RXD};
+
+/// Double-buffer for storing incoming USART data.
+static unsigned char usartBuffers[2][DATABUFFERSIZE];
+
+/// Current USART buffer index.
+static unsigned char usartCurrentBuffer = 0;
+
+/// Buffer for storing incoming USB data.
+static unsigned char usbSerialBuffer0[DATABUFFERSIZE];
+//static unsigned char usbSerialBuffer1[DATABUFFERSIZE];
+
+//- HID
+/// List of pinsPushButtons to configure for the applicatino.
+static Pin pinsPushButtons[] = {PINS_PUSHBUTTONS};
+
+/// Array of key codes produced by each button.
+static unsigned char keyCodes[NUM_KEYS] = {
+ HIDKeypad_A,
+ HIDKeypad_NUMLOCK,
+ HIDKeypad_9,
+ HIDKeypad_RIGHTSHIFT
+};
+
+/// Current status (pressed or not) for each key.
+static unsigned char keyStatus[NUM_KEYS];
+
+//------------------------------------------------------------------------------
+// Remote wake-up support (optional)
+//------------------------------------------------------------------------------
+#if (BOARD_USB_BMATTRIBUTES == USBConfigurationDescriptor_BUSPOWERED_RWAKEUP) \
+ || (BOARD_USB_BMATTRIBUTES == USBConfigurationDescriptor_SELFPOWERED_RWAKEUP)
+
+#define WAKEUP_CONFIGURE() ConfigureWakeUp()
+
+/// Button for Wake-UP the USB device.
+static const Pin pinWakeUp = PIN_PUSHBUTTON_1;
+
+//------------------------------------------------------------------------------
+/// Interrupt service routine for the PIT. Debounces the wake-up pin input.
+//------------------------------------------------------------------------------
+static void ISR_Pit(void)
+{
+ static unsigned long debounceCounter = DEBOUNCE_TIME;
+ unsigned long pisr = 0;
+
+ // Read the PISR
+ pisr = PIT_GetStatus() & AT91C_PITC_PITS;
+
+ if (pisr != 0) {
+
+ // Read the PIVR. It acknowledges the IT
+ PIT_GetPIVR();
+ }
+
+ // Button released
+ if (PIO_Get(&pinWakeUp)) {
+
+ debounceCounter = DEBOUNCE_TIME;
+ }
+ // Button still pressed
+ else {
+
+ debounceCounter--;
+ }
+
+ // End of debounce time
+ if (debounceCounter == 0) {
+
+ debounceCounter = DEBOUNCE_TIME;
+ PIT_DisableIT();
+ AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITEN;
+ COMPOSITEDDriver_RemoteWakeUp();
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Configures the PIT to generate 1ms ticks.
+//------------------------------------------------------------------------------
+static void ConfigurePit(void)
+{
+ // Initialize and enable the PIT
+ PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000);
+
+ // Disable the interrupt on the interrupt controller
+ AIC_DisableIT(AT91C_ID_SYS);
+
+ // Configure the AIC for PIT interrupts
+ AIC_ConfigureIT(AT91C_ID_SYS, 0, ISR_Pit);
+
+ // Enable the interrupt on the interrupt controller
+ AIC_EnableIT(AT91C_ID_SYS);
+
+ // Enable the interrupt on the pit
+ PIT_EnableIT();
+
+ // Enable the pit
+ PIT_Enable();
+}
+
+//------------------------------------------------------------------------------
+/// Interrupt service routine for the remote wake-up pin. Starts the debouncing
+/// sequence.
+//------------------------------------------------------------------------------
+static void WakeUpHandler(const Pin *pin)
+{
+ TRACE_DEBUG("Wake-up handler\n\r");
+
+ // Check current level on the remote wake-up pin
+ if (!PIO_Get(&pinWakeUp)) {
+
+ ConfigurePit();
+ }
+}
+
+//------------------------------------------------------------------------------
+/// Configures the wake-up pin to generate interrupts.
+//------------------------------------------------------------------------------
+static void ConfigureWakeUp(void)
+{
+ TRACE_INFO("Wake-up configuration\n\r");
+
+ // Configure PIO
+ PIO_Configure(&pinWakeUp, 1);
+ PIO_ConfigureIt(&pinWakeUp, WakeUpHandler);
+ PIO_EnableIt(&pinWakeUp);
+}
+
+#else
+ #define WAKEUP_CONFIGURE()
+#endif
+
+//-----------------------------------------------------------------------------
+// VBus monitoring (optional)
+//-----------------------------------------------------------------------------
+#if defined(PIN_USB_VBUS)
+
+#define VBUS_CONFIGURE() VBus_Configure()
+
+/// VBus pin instance.
+static const Pin pinVbus = PIN_USB_VBUS;
+
+//-----------------------------------------------------------------------------
+/// Handles interrupts coming from PIO controllers.
+//-----------------------------------------------------------------------------
+static void ISR_Vbus(const Pin *pPin)
+{
+ TRACE_INFO("VBUS ");
+
+ // Check current level on VBus
+ if (PIO_Get(&pinVbus)) {
+
+ TRACE_INFO("conn\n\r");
+ USBD_Connect();
+ }
+ else {
+
+ TRACE_INFO("discon\n\r");
+ USBD_Disconnect();
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Configures the VBus pin to trigger an interrupt when the level on that pin
+/// changes.
+//-----------------------------------------------------------------------------
+static void VBus_Configure( void )
+{
+ TRACE_INFO("VBus configuration\n\r");
+
+ // Configure PIO
+ PIO_Configure(&pinVbus, 1);
+ PIO_ConfigureIt(&pinVbus, ISR_Vbus);
+ PIO_EnableIt(&pinVbus);
+
+ // Check current level on VBus
+ if (PIO_Get(&pinVbus)) {
+
+ // if VBUS present, force the connect
+ TRACE_INFO("conn\n\r");
+ USBD_Connect();
+ }
+ else {
+ USBD_Disconnect();
+ }
+}
+
+#else
+ #define VBUS_CONFIGURE() USBD_Connect()
+#endif //#if defined(PIN_USB_VBUS)
+
+#if defined (CP15_PRESENT)
+//------------------------------------------------------------------------------
+/// Put the CPU in 32kHz, disable PLL, main oscillator
+/// Put voltage regulator in standby mode
+//------------------------------------------------------------------------------
+void LowPowerMode(void)
+{
+ PMC_CPUInIdleMode();
+}
+//------------------------------------------------------------------------------
+/// Put voltage regulator in normal mode
+/// Return the CPU to normal speed 48MHz, enable PLL, main oscillator
+//------------------------------------------------------------------------------
+void NormalPowerMode(void)
+{
+}
+
+#elif defined(at91sam7a3)
+//------------------------------------------------------------------------------
+/// Put the CPU in 32kHz, disable PLL, main oscillator
+//------------------------------------------------------------------------------
+void LowPowerMode(void)
+{
+ // MCK=48MHz to MCK=32kHz
+ // MCK = SLCK/2 : change source first from 48 000 000 to 18. / 2 = 9M
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=SLCK : then change prescaler
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // disable PLL
+ AT91C_BASE_PMC->PMC_PLLR = 0;
+ // Disable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = 0;
+
+ PMC_DisableProcessorClock();
+}
+//------------------------------------------------------------------------------
+/// Return the CPU to normal speed 48MHz, enable PLL, main oscillator
+//------------------------------------------------------------------------------
+void NormalPowerMode(void)
+{
+ // MCK=32kHz to MCK=48MHz
+ // enable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = (( (AT91C_CKGR_OSCOUNT & (0x06 <<8)) | AT91C_CKGR_MOSCEN ));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS ) );
+
+ // enable PLL@96MHz
+ AT91C_BASE_PMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x0E) |
+ (AT91C_CKGR_PLLCOUNT & (28<<8)) |
+ (AT91C_CKGR_MUL & (0x48<<16)));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK ) );
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
+ // MCK=SLCK/2 : change prescaler first
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=PLLCK/2 : then change source
+ AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK ;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+}
+
+#elif defined (at91sam7se)
+//------------------------------------------------------------------------------
+/// Put the CPU in 32kHz, disable PLL, main oscillator
+/// Put voltage regulator in standby mode
+//------------------------------------------------------------------------------
+void LowPowerMode(void)
+{
+ // MCK=48MHz to MCK=32kHz
+ // MCK = SLCK/2 : change source first from 48 000 000 to 18. / 2 = 9M
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=SLCK : then change prescaler
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // disable PLL
+ AT91C_BASE_PMC->PMC_PLLR = 0;
+ // Disable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = 0;
+
+ // Voltage regulator in standby mode : Enable VREG Low Power Mode
+ AT91C_BASE_VREG->VREG_MR |= AT91C_VREG_PSTDBY;
+
+ PMC_DisableProcessorClock();
+}
+//------------------------------------------------------------------------------
+/// Put voltage regulator in normal mode
+/// Return the CPU to normal speed 48MHz, enable PLL, main oscillator
+//------------------------------------------------------------------------------
+void NormalPowerMode(void)
+{
+ // Voltage regulator in normal mode : Disable VREG Low Power Mode
+ AT91C_BASE_VREG->VREG_MR &= ~AT91C_VREG_PSTDBY;
+
+ // MCK=32kHz to MCK=48MHz
+ // enable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = (( (AT91C_CKGR_OSCOUNT & (0x06 <<8)) | AT91C_CKGR_MOSCEN ));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS ) );
+
+ // enable PLL@96MHz
+ AT91C_BASE_PMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x0E) |
+ (AT91C_CKGR_PLLCOUNT & (28<<8)) |
+ (AT91C_CKGR_MUL & (0x48<<16)));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK ) );
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
+ // MCK=SLCK/2 : change prescaler first
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=PLLCK/2 : then change source
+ AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK ;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+}
+
+#elif defined (at91sam7s)
+//------------------------------------------------------------------------------
+/// Put the CPU in 32kHz, disable PLL, main oscillator
+/// Put voltage regulator in standby mode
+//------------------------------------------------------------------------------
+void LowPowerMode(void)
+{
+ // MCK=48MHz to MCK=32kHz
+ // MCK = SLCK/2 : change source first from 48 000 000 to 18. / 2 = 9M
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=SLCK : then change prescaler
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // disable PLL
+ AT91C_BASE_PMC->PMC_PLLR = 0;
+ // Disable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = 0;
+
+ // Voltage regulator in standby mode : Enable VREG Low Power Mode
+ AT91C_BASE_VREG->VREG_MR |= AT91C_VREG_PSTDBY;
+
+ PMC_DisableProcessorClock();
+}
+
+//------------------------------------------------------------------------------
+/// Put voltage regulator in normal mode
+/// Return the CPU to normal speed 48MHz, enable PLL, main oscillator
+//------------------------------------------------------------------------------
+void NormalPowerMode(void)
+{
+ // Voltage regulator in normal mode : Disable VREG Low Power Mode
+ AT91C_BASE_VREG->VREG_MR &= ~AT91C_VREG_PSTDBY;
+
+ // MCK=32kHz to MCK=48MHz
+ // enable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = (( (AT91C_CKGR_OSCOUNT & (0x06 <<8)) | AT91C_CKGR_MOSCEN ));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS ) );
+
+ // enable PLL@96MHz
+ AT91C_BASE_PMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x0E) |
+ (AT91C_CKGR_PLLCOUNT & (28<<8)) |
+ (AT91C_CKGR_MUL & (0x48<<16)));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK ) );
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
+ // MCK=SLCK/2 : change prescaler first
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=PLLCK/2 : then change source
+ AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK ;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+
+}
+
+#elif defined (at91sam7x) || defined (at91sam7xc)
+//------------------------------------------------------------------------------
+/// Put the CPU in 32kHz, disable PLL, main oscillator
+/// Put voltage regulator in standby mode
+//------------------------------------------------------------------------------
+void LowPowerMode(void)
+{
+ // MCK=48MHz to MCK=32kHz
+ // MCK = SLCK/2 : change source first from 48 000 000 to 18. / 2 = 9M
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=SLCK : then change prescaler
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // disable PLL
+ AT91C_BASE_PMC->PMC_PLLR = 0;
+ // Disable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = 0;
+
+ // Voltage regulator in standby mode : Enable VREG Low Power Mode
+ AT91C_BASE_VREG->VREG_MR |= AT91C_VREG_PSTDBY;
+
+ PMC_DisableProcessorClock();
+}
+
+//------------------------------------------------------------------------------
+/// Put voltage regulator in normal mode
+/// Return the CPU to normal speed 48MHz, enable PLL, main oscillator
+//------------------------------------------------------------------------------
+void NormalPowerMode(void)
+{
+ // Voltage regulator in normal mode : Disable VREG Low Power Mode
+ AT91C_BASE_VREG->VREG_MR &= ~AT91C_VREG_PSTDBY;
+
+ // MCK=32kHz to MCK=48MHz
+ // enable Main Oscillator
+ AT91C_BASE_PMC->PMC_MOR = (( (AT91C_CKGR_OSCOUNT & (0x06 <<8)) | AT91C_CKGR_MOSCEN ));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS ) );
+
+ // enable PLL@96MHz
+ AT91C_BASE_PMC->PMC_PLLR = ((AT91C_CKGR_DIV & 0x0E) |
+ (AT91C_CKGR_PLLCOUNT & (28<<8)) |
+ (AT91C_CKGR_MUL & (0x48<<16)));
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK ) );
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
+ // MCK=SLCK/2 : change prescaler first
+ AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+ // MCK=PLLCK/2 : then change source
+ AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK ;
+ while( !( AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY ) );
+}
+
+#endif
+
+//------------------------------------------------------------------------------
+// Callbacks re-implementation
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+/// Invoked when the USB device leaves the Suspended state. By default,
+/// configures the LEDs.
+//------------------------------------------------------------------------------
+void USBDCallbacks_Resumed(void)
+{
+ // Initialize LEDs
+ LED_Configure(USBD_LEDPOWER);
+ LED_Set(USBD_LEDPOWER);
+ LED_Configure(USBD_LEDUSB);
+ LED_Clear(USBD_LEDUSB);
+ USBState = STATE_RESUME;
+}
+
+//------------------------------------------------------------------------------
+/// Invoked when the USB device gets suspended. By default, turns off all LEDs.
+//------------------------------------------------------------------------------
+void USBDCallbacks_Suspended(void)
+{
+ // Turn off LEDs
+ LED_Clear(USBD_LEDPOWER);
+ LED_Clear(USBD_LEDUSB);
+ USBState = STATE_SUSPEND;
+}
+
+
+
+//-----------------------------------------------------------------------------
+// Internal functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Handles interrupts coming from Timer #0.
+//-----------------------------------------------------------------------------
+static void ISR_Timer0()
+{
+ unsigned char size;
+ unsigned int status = AT91C_BASE_TC0->TC_SR;
+
+ if ((status & AT91C_TC_CPCS) != 0) {
+
+ // Flush PDC buffer
+ size = DATABUFFERSIZE - AT91C_BASE_US0->US_RCR;
+ if (size == 0) {
+
+ AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
+ return;
+ }
+ AT91C_BASE_US0->US_RCR = 0;
+
+ // Send current buffer through the USB
+ while (CDCDSerialDriver_Write(0, usartBuffers[usartCurrentBuffer],
+ size, 0, 0) != USBD_STATUS_SUCCESS);
+
+ // Restart read on buffer
+ USART_ReadBuffer(AT91C_BASE_US0,
+ usartBuffers[usartCurrentBuffer],
+ DATABUFFERSIZE);
+ usartCurrentBuffer = 1 - usartCurrentBuffer;
+ AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Callback invoked when data has been received on the USB.
+//-----------------------------------------------------------------------------
+static void UsbDataReceived0(unsigned int unused,
+ unsigned char status,
+ unsigned int received,
+ unsigned int remaining)
+{
+ // Check that data has been received successfully
+ if (status == USBD_STATUS_SUCCESS) {
+
+ // Send data through USART
+ while (!USART_WriteBuffer(AT91C_BASE_US0, usbSerialBuffer0, received));
+ AT91C_BASE_US0->US_IER = AT91C_US_TXBUFE;
+
+ // Check if bytes have been discarded
+ if ((received == DATABUFFERSIZE) && (remaining > 0)) {
+
+ TRACE_WARNING(
+ "UsbDataReceived: %u bytes discarded\n\r",
+ remaining);
+ }
+ }
+ else {
+
+ TRACE_WARNING("UsbDataReceived: Transfer error\n\r");
+ }
+}
+
+//-----------------------------------------------------------------------------
+/// Handles interrupts coming from USART #0.
+//-----------------------------------------------------------------------------
+static void ISR_Usart0()
+{
+ unsigned int status = AT91C_BASE_US0->US_CSR;
+ unsigned short serialState;
+
+ // If USB device is not configured, do nothing
+ if (USBD_GetState() != USBD_STATE_CONFIGURED) {
+
+ AT91C_BASE_US0->US_IDR = 0xFFFFFFFF;
+ return;
+ }
+
+ // Buffer has been read successfully
+ if ((status & AT91C_US_ENDRX) != 0) {
+
+ // Disable timer
+ AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
+
+ // Send buffer through the USBSerial0
+ while (CDCDSerialDriver_Write(0, usartBuffers[usartCurrentBuffer],
+ DATABUFFERSIZE, 0, 0) != USBD_STATUS_SUCCESS);
+
+ // Restart read on buffer
+ USART_ReadBuffer(AT91C_BASE_US0,
+ usartBuffers[usartCurrentBuffer],
+ DATABUFFERSIZE);
+ usartCurrentBuffer = 1 - usartCurrentBuffer;
+
+ // Restart timer
+ AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
+ }
+
+ // Buffer has been sent
+ if ((status & AT91C_US_TXBUFE) != 0) {
+
+ // Restart USB read
+ CDCDSerialDriver_Read(0, usbSerialBuffer0,
+ DATABUFFERSIZE,
+ (TransferCallback) UsbDataReceived0,
+ 0);
+ AT91C_BASE_US0->US_IDR = AT91C_US_TXBUFE;
+ }
+
+ // Errors
+ serialState = CDCDSerialDriver_GetSerialState(0);
+
+ // Overrun
+ if ((status & AT91C_US_OVER) != 0) {
+
+ TRACE_WARNING("ISR_Usart0: Overrun\n\r");
+ serialState |= CDCD_STATE_OVERRUN;
+ }
+
+ // Framing error
+ if ((status & AT91C_US_FRAME) != 0) {
+
+ TRACE_WARNING("ISR_Usart0: Framing error\n\r");
+ serialState |= CDCD_STATE_FRAMING;
+ }
+
+ CDCDSerialDriver_SetSerialState(0, serialState);
+}
+
+//-----------------------------------------------------------------------------
+/// Invoked when the status of the keyboard LEDs changes. Turns the num. lock
+/// LED on or off.
+/// \param numLockStatus Indicates the current status of the num. lock key.
+/// \param capsLockStatus Indicates the current status of the caps lock key.
+/// \param scrollLockStatus Indicates the current status of the scroll lock key
+//-----------------------------------------------------------------------------
+void HIDDKeyboardCallbacks_LedsChanged(
+ unsigned char numLockStatus,
+ unsigned char capsLockStatus,
+ unsigned char scrollLockStatus)
+{
+ // Num. lock
+ if (numLockStatus) {
+
+ LED_Set(LED_NUMLOCK);
+ }
+ else {
+
+ LED_Clear(LED_NUMLOCK);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Internal functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Monitor keyboard buttons & Update key status in HID driver
+//-----------------------------------------------------------------------------
+static void HIDDKeyboardProcessKeys(void)
+{
+ unsigned int i;
+ unsigned char pressedKeys[NUM_KEYS];
+ unsigned char pressedKeysSize = 0;
+ unsigned char releasedKeys[NUM_KEYS];
+ unsigned char releasedKeysSize = 0;
+
+ // Monitor buttons
+ for (i=0; i < PIO_LISTSIZE(pinsPushButtons); i++) {
+
+ // Check if button state has changed
+ unsigned char isButtonPressed = PIO_Get(&(pinsPushButtons[i]));
+ if (isButtonPressed != keyStatus[i]) {
+
+ // Update button state
+ if (!isButtonPressed) {
+
+ // Key has been pressed
+ TRACE_INFO("-I- Key %u has been pressed\n\r", i);
+ keyStatus[i] = 0;
+ pressedKeys[pressedKeysSize] = keyCodes[i];
+ pressedKeysSize++;
+ HIDDKeyboardDriver_RemoteWakeUp();
+ }
+ else {
+
+ // Key has been released
+ TRACE_INFO("-I- Key %u has been released\n\r", i);
+ keyStatus[i] = 1;
+ releasedKeys[releasedKeysSize] = keyCodes[i];
+ releasedKeysSize++;
+ }
+ }
+ }
+
+ // Update key status in the HID driver if necessary
+ if ((pressedKeysSize != 0) || (releasedKeysSize != 0)) {
+
+ unsigned char status;
+
+ do {
+
+ status = HIDDKeyboardDriver_ChangeKeys(pressedKeys,
+ pressedKeysSize,
+ releasedKeys,
+ releasedKeysSize);
+ }
+ while (status != USBD_STATUS_SUCCESS);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Exported function
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Main
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+/// Initializes drivers and start the USB composite device.
+//-----------------------------------------------------------------------------
+int main()
+{
+ TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
+ printf("-- USB Composite Device Project %s --\n\r", SOFTPACK_VERSION);
+ printf("-- %s\n\r", BOARD_NAME);
+ printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
+
+ // If they are present, configure Vbus & Wake-up pins
+ PIO_InitializeInterrupts(0);
+
+ // ----- HID Function Initialize
+ // Initialize key statuses and configure push buttons
+ PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons));
+ memset(keyStatus, 1, NUM_KEYS);
+
+ // Configure LEDs
+ LED_Configure(LED_NUMLOCK);
+
+ // ----- CDC Function Initialize
+ // Configure USART
+ PIO_Configure(pinsUsart, PIO_LISTSIZE(pinsUsart));
+ AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US0;
+ AT91C_BASE_US0->US_IDR = 0xFFFFFFFF;
+ USART_Configure(AT91C_BASE_US0,
+ USART_MODE_ASYNCHRONOUS,
+ 115200,
+ MCK);
+ USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
+ USART_SetReceiverEnabled(AT91C_BASE_US0, 1);
+ AIC_ConfigureIT(AT91C_ID_US0, 0, ISR_Usart0);
+ AIC_EnableIT(AT91C_ID_US0);
+
+ // Configure timer 0
+ AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0);
+ AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
+ AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF;
+ AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK
+ | AT91C_TC_CPCSTOP
+ | AT91C_TC_CPCDIS
+ | AT91C_TC_WAVESEL_UP_AUTO
+ | AT91C_TC_WAVE;
+ AT91C_BASE_TC0->TC_RC = 0x00FF;
+ AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
+ AIC_ConfigureIT(AT91C_ID_TC0, 0, ISR_Timer0);
+ AIC_EnableIT(AT91C_ID_TC0);
+
+ // USB COMPOSITE driver initialization
+ COMPOSITEDDriver_Initialize();
+
+ WAKEUP_CONFIGURE();
+
+ // connect if needed
+ VBUS_CONFIGURE();
+
+ // Driver loop
+ while (1) {
+
+ // Device is not configured
+ if (USBD_GetState() < USBD_STATE_CONFIGURED) {
+
+ // Connect pull-up, wait for configuration
+ USBD_Connect();
+ while (USBD_GetState() < USBD_STATE_CONFIGURED);
+
+ // Start receiving data on the USART
+ usartCurrentBuffer = 0;
+ USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[0], DATABUFFERSIZE);
+ USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[1], DATABUFFERSIZE);
+ AT91C_BASE_US0->US_IER = AT91C_US_ENDRX
+ | AT91C_US_FRAME
+ | AT91C_US_OVER;
+ AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
+
+ // Start receiving data on the USB
+ CDCDSerialDriver_Read(0, usbSerialBuffer0,
+ DATABUFFERSIZE,
+ (TransferCallback) UsbDataReceived0,
+ 0);
+ }
+ else {
+
+ HIDDKeyboardProcessKeys();
+ }
+ if( USBState == STATE_SUSPEND ) {
+ TRACE_DEBUG("suspend !\n\r");
+ LowPowerMode();
+ USBState = STATE_IDLE;
+ }
+ if( USBState == STATE_RESUME ) {
+ // Return in normal MODE
+ TRACE_DEBUG("resume !\n\r");
+ NormalPowerMode();
+ USBState = STATE_IDLE;
+ }
+ }
+}
+
diff --git a/usb-device-composite-cdchid-project/obj/.empty b/usb-device-composite-cdchid-project/obj/.empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/usb-device-composite-cdchid-project/obj/.empty
personal git repositories of Harald Welte. Your mileage may vary