SAMV71 Xplained Ultra Software Package 1.4

HIDDKeyboard.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  * \file
00032  * Definition of methods for using a HID keyboard function.
00033  */
00034 
00035 #ifndef HIDDKEYBOARD_H
00036 #define HIDDKEYBOARD_H
00037 
00038 /** \addtogroup usbd_hid_key
00039  *@{
00040  */
00041 
00042 /*------------------------------------------------------------------------------
00043  *         Headers
00044  *------------------------------------------------------------------------------*/
00045 
00046 #include "USBDescriptors.h"
00047 #include "USBRequests.h"
00048 
00049 #include "HIDDescriptors.h"
00050 #include "USBDDriver.h"
00051 
00052 /*------------------------------------------------------------------------------
00053  *         Definitions
00054  *------------------------------------------------------------------------------*/
00055 
00056 /** \addtogroup usbd_hid_kbd_desc HIDD Keyboard Driver Definitions
00057  *  @{
00058  */
00059 
00060 /** Maximum number of simultaneous key presses. */
00061 #define HIDDKeyboardInputReport_MAXKEYPRESSES           3
00062 
00063 /** \addtogroup usbd_hid_kbd_keys HID Keypad keys
00064  *      @{
00065  * This page lists definition for HID keypad keys.
00066  *
00067  * \section Keys
00068  * - HIDDKeyboardDescriptors_FIRSTMODIFIERKEY
00069  * - HIDDKeyboardDescriptors_LASTMODIFIERKEY
00070  * - HIDDKeyboardDescriptors_FIRSTSTANDARDKEY
00071  * - HIDDKeyboardDescriptors_LASTSTANDARDKEY
00072  */
00073 /** Key code of the first accepted modifier key */
00074 #define HIDDKeyboardDescriptors_FIRSTMODIFIERKEY  HIDKeypad_LEFTCONTROL
00075 /** Key code of the last accepted modifier key */
00076 #define HIDDKeyboardDescriptors_LASTMODIFIERKEY   HIDKeypad_RIGHTGUI
00077 /** Key code of the first accepted standard key */
00078 #define HIDDKeyboardDescriptors_FIRSTSTANDARDKEY  0
00079 /** Key code of the last accepted standard key */
00080 #define HIDDKeyboardDescriptors_LASTSTANDARDKEY   HIDKeypad_NUMLOCK
00081 /**      @}*/
00082 
00083 /** \addtogroup usbd_hid_kbd_polling HID Keyboard Default Polling Rates
00084  *      @{
00085  */
00086 /** Default HID interrupt IN endpoint polling rate FS (16ms). */
00087 #define HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_FS     16
00088 /** Default HID interrupt IN endpoint polling rate HS (16ms). */
00089 #define HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_HS     8
00090 /** Default interrupt OUT endpoint polling rate FS (16ms). */
00091 #define HIDDKeyboardDescriptors_INTERRUPTOUT_POLLING_FS    16
00092 /** Default interrupt OUT endpoint polling rate HS (16ms). */
00093 #define HIDDKeyboardDescriptors_INTERRUPTOUT_POLLING_HS    8
00094 /**     @}*/
00095 
00096 /** Size of the report descriptor in bytes */
00097 #define HIDDKeyboard_REPORTDESCRIPTORSIZE                   61
00098 
00099 /** @}*/
00100 
00101 /*------------------------------------------------------------------------------
00102  *         Types
00103  *------------------------------------------------------------------------------*/
00104 #pragma pack(1)
00105 #if defined   ( __CC_ARM   ) /* Keil ¦̀Vision 4 */
00106 #elif defined ( __ICCARM__ ) /* IAR Ewarm */
00107 #define __attribute__(...)
00108 #define __packed__  packed
00109 #elif defined (  __GNUC__  ) /* GCC CS3 */
00110 #define __packed__  aligned(1)
00111 #endif
00112 
00113 /**
00114  * \typedef HIDDKeyboardOutputReport
00115  * \brief HID output report structure used by the host to control the state of
00116  *        the keyboard LEDs.
00117  *
00118  * Only the first three bits are relevant, the other 5 are used as
00119  * padding bits.
00120  */
00121 typedef struct _HIDDKeyboardOutputReport {
00122 
00123     uint8_t numLockStatus:1,      /** State of the num. lock LED. */
00124                   capsLockStatus:1,     /** State of the caps lock LED. */
00125                   scrollLockStatus:1,   /** State of the scroll lock LED. */
00126                   padding:5;            /** Padding bits. */
00127 
00128 } __attribute__ ((__packed__)) HIDDKeyboardOutputReport; /* GCC */
00129 
00130 /**
00131  * \typedef HIDDKeyboardInputReport
00132  * \brief HID input report structure used by the keyboard driver to notify the
00133  *        host of pressed keys.
00134  *
00135  * The first byte is used to report the state of modifier keys. The
00136  * other three contains the keycodes of the currently pressed keys.
00137  */
00138 typedef struct _HIDDKeyboardInputReport {
00139 
00140     /** State of modifier keys. */
00141     uint8_t bmModifierKeys:8;
00142     /** Key codes of pressed keys. */
00143     uint8_t pressedKeys[HIDDKeyboardInputReport_MAXKEYPRESSES];
00144 } __attribute__ ((__packed__)) HIDDKeyboardInputReport; /* GCC */
00145 
00146 
00147 /**
00148  * \typedef HIDDKeyboardDriverConfigurationDescriptors
00149  * \brief List of descriptors that make up the configuration descriptors of a
00150  *        device using the HID keyboard driver.
00151  */
00152 typedef struct _HIDDKeyboardDriverConfigurationDescriptors {
00153 
00154     /** Configuration descriptor. */
00155     USBConfigurationDescriptor configuration;
00156     /** Interface descriptor. */
00157     USBInterfaceDescriptor interface;
00158     /** HID descriptor. */
00159     HIDDescriptor1 hid;
00160     /** Interrupt IN endpoint descriptor. */
00161     USBEndpointDescriptor interruptIn;
00162     /** Interrupt OUT endpoint descriptor. */
00163     USBEndpointDescriptor interruptOut;
00164 
00165 } __attribute__ ((__packed__)) HIDDKeyboardDriverConfigurationDescriptors;
00166 
00167 #pragma pack()
00168 
00169 /*------------------------------------------------------------------------------
00170  *         Exported functions
00171  *------------------------------------------------------------------------------*/
00172 
00173 extern void HIDDKeyboard_Initialize(USBDDriver * pUsbd,uint8_t bInterfaceNb);
00174 
00175 extern void HIDDKeyboard_ConfigureFunction(
00176     USBGenericDescriptor * pDescriptors,
00177     uint16_t wLength);
00178 
00179 extern uint32_t HIDDKeyboard_RequestHandler(
00180     const USBGenericRequest *request);
00181 
00182 extern uint32_t HIDDKeyboard_ChangeKeys(
00183     uint8_t *pressedKeys,
00184     uint8_t pressedKeysSize,
00185     uint8_t *releasedKeys,
00186     uint8_t releasedKeysSize);
00187 
00188 extern void HIDDKeyboard_RemoteWakeUp(void);
00189 
00190 extern void HIDDKeyboardCallbacks_LedsChanged(
00191     uint8_t numLockStatus,
00192     uint8_t capsLockStatus,
00193     uint8_t scrollLockStatus);
00194 
00195 
00196 extern void HIDDKeyboardInputReport_Initialize(HIDDKeyboardInputReport *report);
00197 
00198 extern void HIDDKeyboardInputReport_PressStandardKey(
00199     HIDDKeyboardInputReport *report,
00200     uint8_t key);
00201 
00202 extern void HIDDKeyboardInputReport_ReleaseStandardKey(
00203     HIDDKeyboardInputReport *report,
00204     uint8_t key);
00205 
00206 extern void HIDDKeyboardInputReport_PressModifierKey(
00207     HIDDKeyboardInputReport *report,
00208     uint8_t key);
00209 
00210 extern void HIDDKeyboardInputReport_ReleaseModifierKey(
00211     HIDDKeyboardInputReport *report,
00212     uint8_t key);
00213 
00214 
00215 extern void HIDDKeyboardOutputReport_Initialize(
00216     HIDDKeyboardOutputReport *report);
00217 
00218 extern uint8_t HIDDKeyboardOutputReport_GetNumLockStatus(
00219     const HIDDKeyboardOutputReport *report);
00220 
00221 extern uint8_t HIDDKeyboardOutputReport_GetCapsLockStatus(
00222     const HIDDKeyboardOutputReport *report);
00223 
00224 extern uint8_t HIDDKeyboardOutputReport_GetScrollLockStatus(
00225     const HIDDKeyboardOutputReport *report);
00226 
00227 /**@}*/
00228 
00229 #endif /*#ifndef HIDDKEYBOARD_H*/
00230 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines