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 * 00033 * \section Purpose 00034 * 00035 * USB Device Driver class definition. 00036 * 00037 * \section Usage 00038 * 00039 * -# Instantiate a USBDDriver object and initialize it using 00040 * USBDDriver_Initialize. 00041 * -# When a USB SETUP request is received, forward it to the standard 00042 * driver using USBDDriver_RequestHandler. 00043 * -# Check the Remote Wakeup setting via USBDDriver_IsRemoteWakeUpEnabled. 00044 */ 00045 00046 #ifndef USBDDRIVER_H 00047 #define USBDDRIVER_H 00048 00049 /** \addtogroup usbd_interface 00050 *@{ 00051 */ 00052 00053 /*------------------------------------------------------------------------------ 00054 * Headers 00055 *------------------------------------------------------------------------------*/ 00056 00057 /* These headers were introduced in C99 by working group 00058 * ISO/IEC JTC1/SC22/WG14. 00059 */ 00060 #include <stdbool.h> 00061 #include <stdint.h> 00062 #include <stdio.h> 00063 00064 #include <USBRequests.h> 00065 #include <USBDescriptors.h> 00066 #include <USBLib_Types.h> 00067 00068 /*------------------------------------------------------------------------------ 00069 * Types 00070 *------------------------------------------------------------------------------*/ 00071 00072 /** 00073 * \typedef USBDDriverDescriptors 00074 * \brief List of all descriptors used by a USB device driver. Each descriptor 00075 * can be provided in two versions: full-speed and high-speed. Devices 00076 * which are not high-speed capable do not need to provided high-speed 00077 * descriptors and the full-speed qualifier & other speed descriptors. 00078 */ 00079 typedef struct _USBDDriverDescriptors { 00080 00081 /** Pointer to the full-speed device descriptor */ 00082 const USBDeviceDescriptor *pFsDevice; 00083 /** Pointer to the full-speed configuration descriptor */ 00084 const USBConfigurationDescriptor *pFsConfiguration; 00085 /** Pointer to the full-speed qualifier descriptor */ 00086 const USBDeviceQualifierDescriptor *pFsQualifier; 00087 /** Pointer to the full-speed other speed configuration descriptor */ 00088 const USBConfigurationDescriptor *pFsOtherSpeed; 00089 /** Pointer to the high-speed device descriptor */ 00090 const USBDeviceDescriptor *pHsDevice; 00091 /** Pointer to the high-speed configuration descriptor */ 00092 const USBConfigurationDescriptor *pHsConfiguration; 00093 /** Pointer to the high-speed qualifier descriptor */ 00094 const USBDeviceQualifierDescriptor *pHsQualifier; 00095 /** Pointer to the high-speed other speed configuration descriptor */ 00096 const USBConfigurationDescriptor *pHsOtherSpeed; 00097 /** Pointer to the list of string descriptors */ 00098 const uint8_t **pStrings; 00099 /** Number of string descriptors in list */ 00100 uint8_t numStrings; 00101 00102 } USBDDriverDescriptors; 00103 00104 /** 00105 * \typedef USBDDriver 00106 * \brief USB device driver structure, holding a list of descriptors identifying 00107 * the device as well as the driver current state. 00108 */ 00109 typedef struct _USBDDriver { 00110 00111 /** List of descriptors used by the device. */ 00112 const USBDDriverDescriptors *pDescriptors; 00113 /** Current setting for each interface. */ 00114 uint8_t *pInterfaces; 00115 /** Current configuration number (0 -> device is not configured). */ 00116 uint8_t cfgnum; 00117 /** Indicates if remote wake up has been enabled by the host. */ 00118 uint8_t isRemoteWakeUpEnabled; 00119 /** Features supported by OTG */ 00120 uint8_t otg_features_supported; 00121 } USBDDriver; 00122 00123 /*------------------------------------------------------------------------------ 00124 * Exported functions 00125 *------------------------------------------------------------------------------*/ 00126 00127 extern USBDDriver *USBD_GetDriver(void); 00128 extern void USBDDriver_Initialize( 00129 USBDDriver *pDriver, 00130 const USBDDriverDescriptors *pDescriptors, 00131 uint8_t *pInterfaces); 00132 extern USBConfigurationDescriptor* USBDDriver_GetCfgDescriptors( 00133 USBDDriver * pDriver, 00134 uint8_t cfgNum); 00135 extern void USBDDriver_RequestHandler( 00136 USBDDriver *pDriver, 00137 const USBGenericRequest *pRequest); 00138 extern uint8_t USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver); 00139 extern uint8_t USBDDriver_returnOTGFeatures(const USBDDriver *pDriver); 00140 extern void USBDDriver_clearOTGFeatures(USBDDriver *pDriver); 00141 00142 extern void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum); 00143 extern void USBDDriverCallbacks_InterfaceSettingChanged(uint8_t interface, 00144 uint8_t setting); 00145 00146 /**@}*/ 00147 00148 #endif /*#ifndef USBDDRIVER_H*/ 00149