00001 /* ---------------------------------------------------------------------------- 00002 * ATMEL Microcontroller Software Support 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2008, 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 /** \addtogroup usbd_composite_cdchid 00031 *@{ 00032 */ 00033 /*--------------------------------------------------------------------------- 00034 * Headers 00035 *---------------------------------------------------------------------------*/ 00036 00037 #include <USBLib_Trace.h> 00038 00039 #include <CDCHIDDDriver.h> 00040 #include <CDCDSerial.h> 00041 #include <HIDDKeyboard.h> 00042 00043 /*--------------------------------------------------------------------------- 00044 * Defines 00045 *---------------------------------------------------------------------------*/ 00046 00047 /*--------------------------------------------------------------------------- 00048 * Types 00049 *---------------------------------------------------------------------------*/ 00050 00051 /*--------------------------------------------------------------------------- 00052 * Internal variables 00053 *---------------------------------------------------------------------------*/ 00054 00055 /*--------------------------------------------------------------------------- 00056 * Internal functions 00057 *---------------------------------------------------------------------------*/ 00058 00059 /*--------------------------------------------------------------------------- 00060 * Exported functions 00061 *---------------------------------------------------------------------------*/ 00062 00063 /** 00064 * Initializes the USB device composite device driver. 00065 */ 00066 void CDCHIDDDriver_Initialize(const USBDDriverDescriptors *pDescriptors) 00067 { 00068 USBDDriver *pUsbd = USBD_GetDriver(); 00069 00070 /* Initialize the standard USB driver */ 00071 USBDDriver_Initialize(pUsbd, 00072 pDescriptors, 00073 0); 00074 00075 /* CDC */ 00076 CDCDSerial_Initialize(pUsbd, CDCHIDDDriverDescriptors_CDC_INTERFACE); 00077 /* HID */ 00078 HIDDKeyboard_Initialize(pUsbd, CDCHIDDDriverDescriptors_HID_INTERFACE); 00079 00080 /* Initialize the USB driver */ 00081 USBD_Init(); 00082 } 00083 00084 /** 00085 * Invoked whenever the configuration value of a device is changed by the host 00086 * \param cfgnum Configuration number. 00087 */ 00088 void CDCHIDDDriver_ConfigurationChangedHandler(uint8_t cfgnum) 00089 { 00090 USBDDriver *pUsbd = USBD_GetDriver(); 00091 USBConfigurationDescriptor *pDesc; 00092 if (cfgnum > 0) { 00093 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum); 00094 /* CDC */ 00095 CDCDSerial_ConfigureFunction((USBGenericDescriptor*)pDesc, 00096 pDesc->wTotalLength); 00097 /* HID */ 00098 HIDDKeyboard_ConfigureFunction((USBGenericDescriptor*)pDesc, 00099 pDesc->wTotalLength); 00100 } 00101 } 00102 00103 /** 00104 * Handles composite-specific USB requests sent by the host, and forwards 00105 * standard ones to the USB device driver. 00106 * \param request Pointer to a USBGenericRequest instance. 00107 */ 00108 void CDCHIDDDriver_RequestHandler(const USBGenericRequest *request) 00109 { 00110 USBDDriver *pUsbd = USBD_GetDriver(); 00111 00112 TRACE_INFO_WP("NewReq "); 00113 00114 if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS) 00115 return; 00116 00117 if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS) 00118 return; 00119 00120 USBDDriver_RequestHandler(pUsbd, request); 00121 } 00122 00123 /** 00124 * Starts a remote wake-up sequence if the host has explicitely enabled it 00125 * by sending the appropriate SET_FEATURE request. 00126 */ 00127 void CDCHIDDDriver_RemoteWakeUp(void) 00128 { 00129 USBDDriver *pUsbd = USBD_GetDriver(); 00130 00131 /* Remote wake-up has been enabled */ 00132 if (USBDDriver_IsRemoteWakeUpEnabled(pUsbd)) { 00133 00134 USBD_RemoteWakeUp(); 00135 } 00136 } 00137 00138 /**@}*/