SAMV71 Xplained Ultra Software Package 1.5

CDCHIDDDriver.c

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 /** \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 
00093     if (cfgnum > 0) {
00094         pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
00095         /* CDC */
00096         CDCDSerial_ConfigureFunction((USBGenericDescriptor *)pDesc,
00097                                      pDesc->wTotalLength);
00098         /* HID */
00099         HIDDKeyboard_ConfigureFunction((USBGenericDescriptor *)pDesc,
00100                                        pDesc->wTotalLength);
00101     }
00102 }
00103 
00104 /**
00105  * Handles composite-specific USB requests sent by the host, and forwards
00106  * standard ones to the USB device driver.
00107  * \param request Pointer to a USBGenericRequest instance.
00108  */
00109 void CDCHIDDDriver_RequestHandler(const USBGenericRequest *request)
00110 {
00111     USBDDriver *pUsbd = USBD_GetDriver();
00112 
00113     TRACE_INFO_WP("NewReq ");
00114 
00115     if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS)
00116         return;
00117 
00118     if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS)
00119         return;
00120 
00121     USBDDriver_RequestHandler(pUsbd, request);
00122 }
00123 
00124 /**
00125  * Starts a remote wake-up sequence if the host has explicitely enabled it
00126  * by sending the appropriate SET_FEATURE request.
00127  */
00128 void CDCHIDDDriver_RemoteWakeUp(void)
00129 {
00130     USBDDriver *pUsbd = USBD_GetDriver();
00131 
00132     /* Remote wake-up has been enabled */
00133     if (USBDDriver_IsRemoteWakeUpEnabled(pUsbd))
00134 
00135         USBD_RemoteWakeUp();
00136 }
00137 
00138 /**@}*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines