3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this  
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in  
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting  
  17   documentation, and that the name of the author not be used in  
  18   advertising or publicity pertaining to distribution of the  
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  32  *  \brief USB device standard request management. 
  34  *  This file contains the function prototypes necessary for the processing of incoming standard control requests 
  35  *  when the library is in USB device mode. 
  37  *  \note This file should not be included directly. It is automatically included as needed by the USB driver 
  38  *        dispatch header located in LUFA/Drivers/USB/USB.h. 
  41 #ifndef __DEVCHAPTER9_H__ 
  42 #define __DEVCHAPTER9_H__ 
  46                 #include <avr/pgmspace.h> 
  47                 #include <avr/eeprom.h> 
  49                 #include <util/atomic.h> 
  51                 #include "../HighLevel/StdDescriptors.h" 
  52                 #include "../HighLevel/Events.h" 
  53                 #include "../HighLevel/StdRequestType.h" 
  54                 #include "../HighLevel/USBTask.h" 
  57         /* Enable C linkage for C++ Compilers: */ 
  58                 #if defined(__cplusplus) 
  62         /* Preprocessor Checks: */ 
  63                 #if !defined(__INCLUDE_FROM_USB_DRIVER) 
  64                         #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 
  67         /* Public Interface - May be used in end-application: */ 
  69                         #if defined(USE_SINGLE_DEVICE_CONFIGURATION) 
  70                                 #define FIXED_NUM_CONFIGURATIONS           1 
  74                         #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) 
  75                                 /** Enum for the possible descriptor memory spaces, for the MemoryAddressSpace of the 
  76                                  *  \ref CALLBACK_USB_GetDescriptor() function. This can be used when none of the USE_*_DESCRIPTORS 
  77                                  *  compile time options are used, to indicate in which memory space the descriptor is stored. 
  79                                  *  \ingroup Group_Device 
  81                                 enum USB_DescriptorMemorySpaces_t
 
  83                                         MEMSPACE_FLASH    
= 0, /**< Indicates the requested descriptor is located in FLASH memory. */ 
  84                                         MEMSPACE_EEPROM   
= 1, /**< Indicates the requested descriptor is located in EEPROM memory. */ 
  85                                         MEMSPACE_RAM      
= 2, /**< Indicates the requested descriptor is located in RAM memory. */ 
  89                 /* Global Variables: */ 
  90                         /** Indicates the currently set configuration number of the device. USB devices may have several 
  91                          *  different configurations which the host can select between; this indicates the currently selected 
  92                          *  value, or 0 if no configuration has been selected. 
  94                          *  \note This variable should be treated as read-only in the user application, and never manually 
  97                          *  \ingroup Group_Device 
  99                         extern uint8_t USB_ConfigurationNumber
; 
 101                         #if !defined(NO_DEVICE_REMOTE_WAKEUP) 
 102                                 /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this 
 103                                  *  flag is cleared, the device should not issue remote wakeup events to the host. 
 105                                  *  \note This variable should be treated as read-only in the user application, and never manually 
 109                                  *  \note To reduce FLASH usage of the compiled applications where Remote Wakeup is not supported, 
 110                                  *        this global and the underlying management code can be disabled by defining the  
 111                                  *        NO_DEVICE_REMOTE_WAKEUP token in the project makefile and passing it to the compiler via 
 114                                  *  \ingroup Group_Device 
 116                                 extern bool USB_RemoteWakeupEnabled
; 
 119                         #if !defined(NO_DEVICE_SELF_POWER) 
 120                                 /** Indicates if the device is currently being powered by its own power supply, rather than being 
 121                                  *  powered by the host's USB supply. This flag should remain cleared if the device does not 
 122                                  *  support self powered mode, as indicated in the device descriptors. 
 124                                  *  \ingroup Group_Device 
 126                                 extern bool USB_CurrentlySelfPowered
; 
 129         /* Private Interface - For use in library only: */ 
 130         #if !defined(__DOXYGEN__) 
 131                 #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) 
 132                         #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. 
 133                 #elif defined(USE_RAM_DESCRIPTORS) && defined(USE_FLASH_DESCRIPTORS) 
 134                         #error USE_RAM_DESCRIPTORS and USE_FLASH_DESCRIPTORS are mutually exclusive. 
 135                 #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) 
 136                         #error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. 
 137                 #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS) 
 138                         #error Only one of the USE_*_DESCRIPTORS modes should be selected. 
 141                 /* Function Prototypes: */ 
 142                         void USB_Device_ProcessControlRequest(void); 
 144                         #if defined(__INCLUDE_FROM_DEVCHAPTER9_C) 
 145                                 static void USB_Device_SetAddress(void); 
 146                                 static void USB_Device_SetConfiguration(void); 
 147                                 static void USB_Device_GetConfiguration(void); 
 148                                 static void USB_Device_GetDescriptor(void); 
 149                                 static void USB_Device_GetStatus(void); 
 150                                 static void USB_Device_ClearSetFeature(void); 
 152                                 #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) 
 153                                         static char USB_Device_NibbleToASCII(uint8_t Nibble
) ATTR_ALWAYS_INLINE
; 
 154                                         static void USB_Device_GetInternalSerialDescriptor(void); 
 159         /* Disable C linkage for C++ Compilers: */ 
 160                 #if defined(__cplusplus)