summaryrefslogtreecommitdiff
path: root/at91lib/usb/device/hid-keyboard
diff options
context:
space:
mode:
Diffstat (limited to 'at91lib/usb/device/hid-keyboard')
-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
7 files changed, 749 insertions, 0 deletions
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
+
personal git repositories of Harald Welte. Your mileage may vary