SAMV71 Xplained Ultra Software Package 1.5

HIDDKeyboardInputReport.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /** \file
00031  *  Implementation of the HIDDKeyboardInputReport class.
00032  */
00033 
00034 /** \addtogroup usbd_hid_key
00035  *@{
00036  */
00037 
00038 /*------------------------------------------------------------------------------
00039  *         Headers
00040  *------------------------------------------------------------------------------*/
00041 
00042 #include <HIDDKeyboard.h>
00043 #include <USBLib_Trace.h>
00044 
00045 /*------------------------------------------------------------------------------
00046  *         Exported functions
00047  *------------------------------------------------------------------------------*/
00048 
00049 /**
00050  * Initializes a keyboard input report instance.
00051  * \param report Pointer to a HIDDKeyboardInputReport instance.
00052  */
00053 void HIDDKeyboardInputReport_Initialize(HIDDKeyboardInputReport *report)
00054 {
00055     uint32_t i;
00056 
00057     report->bmModifierKeys = 0;
00058 
00059     for (i = 0; i < HIDDKeyboardInputReport_MAXKEYPRESSES; i++)
00060         report->pressedKeys[i] = 0;
00061 }
00062 
00063 /**
00064  * Reports a standard key as being pressed.
00065  * \param report Pointer to a HIDDKeyboardInputReport instance.
00066  * \param key Key code of the standard key.
00067  */
00068 void HIDDKeyboardInputReport_PressStandardKey(HIDDKeyboardInputReport *report,
00069         uint8_t key)
00070 {
00071     /* Find first available slot */
00072     uint32_t i = 0;
00073     uint8_t found = 0;
00074 
00075     while ((i < HIDDKeyboardInputReport_MAXKEYPRESSES) && !found) {
00076 
00077         /* Free slot: no key referenced (code = 0) or ErrorRollOver */
00078         if ((report->pressedKeys[i] == 0)
00079             || (report->pressedKeys[i] == HIDKeypad_ERRORROLLOVER)) {
00080 
00081             found = 1;
00082             report->pressedKeys[i] = key;
00083         }
00084 
00085         i++;
00086     }
00087 
00088     /* Report ErrorRollOver in all fields if too many keys are pressed */
00089     if (!found) {
00090 
00091         for (i = 0; i < HIDDKeyboardInputReport_MAXKEYPRESSES; i++)
00092 
00093             report->pressedKeys[i] = HIDKeypad_ERRORROLLOVER;
00094     }
00095 }
00096 
00097 /**
00098  * Reports a standard key as not being pressed anymore.
00099  * \param report Pointer to a HIDDKeyboardInputReport instance.
00100  * \param key Key code of the standard key
00101  */
00102 void HIDDKeyboardInputReport_ReleaseStandardKey(HIDDKeyboardInputReport *report,
00103         uint8_t key)
00104 {
00105     /* Look for key in array */
00106     uint32_t i = 0;
00107     uint8_t found = 0;
00108 
00109     while ((i < HIDDKeyboardInputReport_MAXKEYPRESSES) && !found) {
00110 
00111         if (report->pressedKeys[i] == key) {
00112 
00113             found = 1;
00114             report->pressedKeys[i] = 0;
00115         }
00116 
00117         i++;
00118     }
00119 }
00120 
00121 /**
00122  * Reports a modifier key as being currently pressed.
00123  * \param report Pointer to a HIDDKeyboardInputReport instance.
00124  * \param key Key code of the modifier key.
00125  */
00126 void HIDDKeyboardInputReport_PressModifierKey(HIDDKeyboardInputReport *report,
00127         uint8_t key)
00128 {
00129     /* Set corresponding bit */
00130     uint8_t bit = key - HIDDKeyboardDescriptors_FIRSTMODIFIERKEY;
00131     report->bmModifierKeys |= 1 << bit;
00132 }
00133 
00134 /**
00135  * Reports a modifier key as not being pressed anymore.
00136  * \param report Pointer to a HIDDKeyboardInputReport instance.
00137  * \param key Key code of the modifier key.
00138  */
00139 void HIDDKeyboardInputReport_ReleaseModifierKey(HIDDKeyboardInputReport *report,
00140         uint8_t key)
00141 {
00142     /* Clear corresponding bit */
00143     uint8_t bit = key - HIDDKeyboardDescriptors_FIRSTMODIFIERKEY;
00144     report->bmModifierKeys &= ~(1 << bit);
00145 }
00146 
00147 /**@}*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines