Removed two-step endpoint/pipe bank clear and switch sequence for smaller, faster...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / DevChapter9.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 * \brief USB device standard request management.
33 *
34 * This file contains the function prototypes neccesary for the processing of incomming standard control requests
35 * when the library is in USB device mode.
36 *
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.
39 */
40
41 #ifndef __DEVCHAPTER9_H__
42 #define __DEVCHAPTER9_H__
43
44 /* Includes: */
45 #include <avr/io.h>
46 #include <avr/pgmspace.h>
47 #include <avr/eeprom.h>
48 #include <avr/boot.h>
49
50 #include "../HighLevel/StdDescriptors.h"
51 #include "../HighLevel/Events.h"
52 #include "../HighLevel/StdRequestType.h"
53 #include "../HighLevel/USBTask.h"
54 #include "LowLevel.h"
55
56 /* Enable C linkage for C++ Compilers: */
57 #if defined(__cplusplus)
58 extern "C" {
59 #endif
60
61 /* Preprocessor Checks: */
62 #if !defined(__INCLUDE_FROM_USB_DRIVER)
63 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
64 #endif
65
66 /* Public Interface - May be used in end-application: */
67 /* Macros: */
68 #if defined(USE_SINGLE_DEVICE_CONFIGURATION)
69 #define FIXED_NUM_CONFIGURATIONS 1
70 #endif
71
72 /* Enums: */
73 #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)
74 /** Enum for the possible descriptor memory spaces, for the MemoryAddressSpace of the
75 * \ref CALLBACK_USB_GetDescriptor() function. This can be used when none of the USE_*_DESCRIPTORS
76 * compile time options are used, to indicate in which memory space the descriptor is stored.
77 *
78 * \ingroup Group_Device
79 */
80 enum USB_DescriptorMemorySpaces_t
81 {
82 MEMSPACE_FLASH = 0, /**< Indicates the requested descriptor is located in FLASH memory */
83 MEMSPACE_EEPROM = 1, /**< Indicates the requested descriptor is located in EEPROM memory */
84 MEMSPACE_RAM = 2, /**< Indicates the requested descriptor is located in RAM memory */
85 };
86 #endif
87
88 /* Global Variables: */
89 /** Indicates the currently set configuration number of the device. USB devices may have several
90 * different configurations which the host can select between; this indicates the currently selected
91 * value, or 0 if no configuration has been selected.
92 *
93 * \note This variable should be treated as read-only in the user application, and never manually
94 * changed in value.
95 *
96 * \ingroup Group_Device
97 */
98 extern uint8_t USB_ConfigurationNumber;
99
100 #if !defined(NO_DEVICE_REMOTE_WAKEUP)
101 /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this
102 * flag is cleared, the device should not issue remote wakeup events to the host.
103 *
104 * \note This variable should be treated as read-only in the user application, and never manually
105 * changed in value.
106 * \n\n
107 *
108 * \note To reduce FLASH usage of the compiled applications where Remote Wakeup is not supported,
109 * this global and the underlying management code can be disabled by defining the
110 * NO_DEVICE_REMOTE_WAKEUP token in the project makefile and passing it to the compiler via
111 * the -D switch.
112 *
113 * \ingroup Group_Device
114 */
115 extern bool USB_RemoteWakeupEnabled;
116 #endif
117
118 #if !defined(NO_DEVICE_SELF_POWER)
119 /** Indicates if the device is currently being powered by its own power supply, rather than being
120 * powered by the host's USB supply. This flag should remain cleared if the device does not
121 * support self powered mode, as indicated in the device descriptors.
122 *
123 * \ingroup Group_Device
124 */
125 extern bool USB_CurrentlySelfPowered;
126 #endif
127
128 /* Private Interface - For use in library only: */
129 #if !defined(__DOXYGEN__)
130 #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)
131 #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
132 #elif defined(USE_RAM_DESCRIPTORS) && defined(USE_FLASH_DESCRIPTORS)
133 #error USE_RAM_DESCRIPTORS and USE_FLASH_DESCRIPTORS are mutually exclusive.
134 #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)
135 #error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
136 #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS)
137 #error Only one of the USE_*_DESCRIPTORS modes should be selected.
138 #endif
139
140 /* Function Prototypes: */
141 void USB_Device_ProcessControlRequest(void);
142
143 #if defined(__INCLUDE_FROM_DEVCHAPTER9_C)
144 static void USB_Device_SetAddress(void);
145 static void USB_Device_SetConfiguration(void);
146 static void USB_Device_GetConfiguration(void);
147 static void USB_Device_GetDescriptor(void);
148 static void USB_Device_GetStatus(void);
149 static void USB_Device_ClearSetFeature(void);
150
151 #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
152 static char USB_Device_NibbleToASCII(uint8_t Nibble) ATTR_ALWAYS_INLINE;
153 static void USB_Device_GetInternalSerialDescriptor(void);
154 #endif
155 #endif
156 #endif
157
158 /* Disable C linkage for C++ Compilers: */
159 #if defined(__cplusplus)
160 }
161 #endif
162
163 #endif