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 
  31 #ifndef __DEVCHAPTER9_H__ 
  32 #define __DEVCHAPTER9_H__ 
  36                 #include <avr/pgmspace.h> 
  37                 #include <avr/eeprom.h> 
  40                 #include "../HighLevel/StdDescriptors.h" 
  41                 #include "../HighLevel/Events.h" 
  42                 #include "../HighLevel/StdRequestType.h" 
  43                 #include "../HighLevel/USBTask.h" 
  46         /* Enable C linkage for C++ Compilers: */ 
  47                 #if defined(__cplusplus) 
  51         /* Public Interface - May be used in end-application: */ 
  53                         #if defined(USE_SINGLE_DEVICE_CONFIGURATION) 
  54                                 #define FIXED_NUM_CONFIGURATIONS           1 
  58                         #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) 
  59                                 /** Enum for the possible descriptor memory spaces, for the MemoryAddressSpace of the 
  60                                  *  \ref CALLBACK_USB_GetDescriptor() function. This can be used when none of the USE_*_DESCRIPTORS 
  61                                  *  compile time options are used, to indicate in which memory space the descriptor is stored. 
  63                                  *  \ingroup Group_Device 
  65                                 enum USB_DescriptorMemorySpaces_t
 
  67                                         MEMSPACE_FLASH    
= 0, /**< Indicates the requested descriptor is located in FLASH memory */ 
  68                                         MEMSPACE_EEPROM   
= 1, /**< Indicates the requested descriptor is located in EEPROM memory */ 
  69                                         MEMSPACE_RAM      
= 2, /**< Indicates the requested descriptor is located in RAM memory */ 
  73                 /* Global Variables: */ 
  74                         /** Indicates the currently set configuration number of the device. USB devices may have several 
  75                          *  different configurations which the host can select between; this indicates the currently selected 
  76                          *  value, or 0 if no configuration has been selected. 
  78                          *  \note This variable should be treated as read-only in the user application, and never manually 
  81                          *  \ingroup Group_Device 
  83                         extern uint8_t USB_ConfigurationNumber
; 
  85                         #if !defined(NO_DEVICE_REMOTE_WAKEUP) 
  86                                 /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this 
  87                                  *  flag is cleared, the device should not issue remote wakeup events to the host. 
  89                                  *  \note This variable should be treated as read-only in the user application, and never manually 
  92                                  *  \note To reduce FLASH usage of the compiled applications where Remote Wakeup is not supported, 
  93                                  *        this global and the underlying management code can be disabled by defining the  
  94                                  *        NO_DEVICE_REMOTE_WAKEUP token in the project makefile and passing it to the compiler via 
  97                                  *  \ingroup Group_Device 
  99                                 extern bool USB_RemoteWakeupEnabled
; 
 102                         #if !defined(NO_DEVICE_SELF_POWER) 
 103                                 /** Indicates if the device is currently being powered by its own power supply, rather than being 
 104                                  *  powered by the host's USB supply. This flag should remain cleared if the device does not 
 105                                  *  support self powered mode, as indicated in the device descriptors. 
 107                                  *  \ingroup Group_Device 
 109                                 extern bool USB_CurrentlySelfPowered
; 
 112         /* Private Interface - For use in library only: */ 
 113         #if !defined(__DOXYGEN__) 
 114                 #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) 
 115                         #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. 
 116                 #elif defined(USE_RAM_DESCRIPTORS) && defined(USE_FLASH_DESCRIPTORS) 
 117                         #error USE_RAM_DESCRIPTORS and USE_FLASH_DESCRIPTORS are mutually exclusive. 
 118                 #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) 
 119                         #error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. 
 120                 #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS) 
 121                         #error Only one of the USE_*_DESCRIPTORS modes should be selected. 
 124                 /* Function Prototypes: */ 
 125                         void USB_Device_ProcessControlRequest(void); 
 127                         #if defined(INCLUDE_FROM_DEVCHAPTER9_C) 
 128                                 static void USB_Device_SetAddress(void); 
 129                                 static void USB_Device_SetConfiguration(void); 
 130                                 static void USB_Device_GetConfiguration(void); 
 131                                 static void USB_Device_GetDescriptor(void); 
 132                                 static void USB_Device_GetStatus(void); 
 133                                 static void USB_Device_ClearSetFeature(void); 
 135                                 #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 136                                         static char USB_Device_NibbleToASCII(uint8_t Nibble
) ATTR_ALWAYS_INLINE
; 
 137                                         static void USB_Device_GetInternalSerialDescriptor(void); 
 142         /* Disable C linkage for C++ Compilers: */ 
 143                 #if defined(__cplusplus)