Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1 | /* ---------------------------------------------------------------------------- |
| 2 | * ATMEL Microcontroller Software Support |
| 3 | * ---------------------------------------------------------------------------- |
| 4 | * Copyright (c) 2008, Atmel Corporation |
| 5 | * |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * - Redistributions of source code must retain the above copyright notice, |
| 12 | * this list of conditions and the disclaimer below. |
| 13 | * |
| 14 | * Atmel's name may not be used to endorse or promote products derived from |
| 15 | * this software without specific prior written permission. |
| 16 | * |
| 17 | * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 23 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * ---------------------------------------------------------------------------- |
| 28 | */ |
| 29 | |
| 30 | /** \file |
| 31 | * \addtogroup usbd_hid_key |
| 32 | *@{ |
| 33 | * Implement a USB device that only have HID Keyboard Function. |
| 34 | */ |
| 35 | |
| 36 | /*------------------------------------------------------------------------------ |
| 37 | * Headers |
| 38 | *------------------------------------------------------------------------------*/ |
| 39 | |
| 40 | #include <HIDDKeyboardDriver.h> |
| 41 | #include <HIDDFunction.h> |
| 42 | |
| 43 | #include <USBLib_Trace.h> |
| 44 | |
| 45 | #include <USBRequests.h> |
| 46 | #include <HIDDescriptors.h> |
| 47 | #include <HIDRequests.h> |
| 48 | #include <HIDReports.h> |
| 49 | #include <HIDUsages.h> |
| 50 | |
| 51 | #include <USBD.h> |
| 52 | #include <USBD_HAL.h> |
| 53 | #include <USBDDriver.h> |
| 54 | |
| 55 | /*------------------------------------------------------------------------------ |
| 56 | * Internal types |
| 57 | *------------------------------------------------------------------------------*/ |
| 58 | |
| 59 | /*------------------------------------------------------------------------------ |
| 60 | * Internal variables |
| 61 | *------------------------------------------------------------------------------*/ |
| 62 | |
| 63 | /*------------------------------------------------------------------------------ |
| 64 | * Internal functions |
| 65 | *------------------------------------------------------------------------------*/ |
| 66 | |
| 67 | /*------------------------------------------------------------------------------ |
| 68 | * Exported functions |
| 69 | *------------------------------------------------------------------------------*/ |
| 70 | |
| 71 | /** |
| 72 | * Initializes the HID keyboard device driver. |
| 73 | */ |
| 74 | void HIDDKeyboardDriver_Initialize(const USBDDriverDescriptors *pDescriptors) |
| 75 | { |
| 76 | USBDDriver *pUsbd = USBD_GetDriver(); |
| 77 | USBDDriver_Initialize(pUsbd, pDescriptors, 0); |
| 78 | HIDDKeyboard_Initialize(pUsbd, 0); |
| 79 | USBD_Init(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Handles configureation changed event. |
| 84 | * \param cfgnum New configuration number |
| 85 | */ |
| 86 | void HIDDKeyboardDriver_ConfigurationChangedHandler(uint8_t cfgnum) |
| 87 | { |
| 88 | USBDDriver *pUsbd = USBD_GetDriver(); |
| 89 | const USBDDriverDescriptors * pDescriptors = pUsbd->pDescriptors; |
| 90 | USBConfigurationDescriptor *pDesc; |
| 91 | |
| 92 | if (cfgnum > 0) { |
| 93 | if (USBD_HAL_IsHighSpeed() && pDescriptors->pHsConfiguration) |
| 94 | pDesc = (USBConfigurationDescriptor*)pDescriptors->pHsConfiguration; |
| 95 | else |
Christina Quast | 49ba6bc | 2015-02-20 14:35:36 +0100 | [diff] [blame] | 96 | pDesc = (USBConfigurationDescriptor*)pDescriptors->pFsConfiguration[0]; |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 97 | HIDDKeyboard_ConfigureFunction((USBGenericDescriptor*)pDesc, |
| 98 | pDesc->wTotalLength); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Handles HID-specific SETUP request sent by the host. |
| 104 | * \param request Pointer to a USBGenericRequest instance. |
| 105 | */ |
| 106 | void HIDDKeyboardDriver_RequestHandler(const USBGenericRequest *request) |
| 107 | { |
| 108 | USBDDriver *pUsbd = USBD_GetDriver(); |
| 109 | |
| 110 | TRACE_INFO_WP("NewReq "); |
| 111 | |
| 112 | /* Process HID requests */ |
| 113 | if (USBRC_SUCCESS == HIDDKeyboard_RequestHandler(request)) { |
| 114 | return; |
| 115 | } |
| 116 | /* Process STD requests */ |
| 117 | else { |
| 118 | USBDDriver_RequestHandler(pUsbd, request); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /**@}*/ |
| 123 | |