3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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>
39 #include "../HighLevel/StdDescriptors.h"
40 #include "../HighLevel/Events.h"
41 #include "../HighLevel/StdRequestType.h"
44 /* Enable C linkage for C++ Compilers: */
45 #if defined(__cplusplus)
49 /* Public Interface - May be used in end-application: */
50 /* Global Variables: */
51 /** Indicates the currently set configuration number of the device. USB devices may have several
52 * different configurations which the host can select between; this indicates the currently selected
53 * value, or 0 if no configuration has been selected.
55 * If a device has only one single configuration, the token USE_SINGLE_DEVICE_CONFIGURATION may be
56 * defined in the project makefile and passed to the compiler using the -D switch. This optimize for
57 * a single configuration, saving a small amount of space in the resulting compiled binary.
59 * \note This variable should be treated as read-only in the user application, and never manually
62 * \ingroup Group_Device
64 extern uint8_t USB_ConfigurationNumber
;
66 /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this
67 * flag is cleared, the device should not issue remote wakeup events to the host.
69 * \note This variable should be treated as read-only in the user application, and never manually
72 * \ingroup Group_Device
74 extern bool USB_RemoteWakeupEnabled
;
76 /** Indicates if the device is currently being powered by its own power supply, rather than being
77 * powered by the host's USB supply. This flag should remain cleared if the device does not
78 * support self powered mode, as indicated in the device descriptors.
80 * \ingroup Group_Device
82 extern bool USB_CurrentlySelfPowered
;
84 /* Throwable Events: */
85 /** This module raises the USB_UnhandledControlPacket event when a request to the default control
86 * endpoint has been received, but the library does not implement an internal handler for it.
88 * \see Events.h for more information on this event.
90 RAISES_EVENT(USB_UnhandledControlPacket
);
92 /** This module raises the USB_ConfigurationChanged event when the host issues a REQ_SetConfiguration
93 * device request, to change the currently selected configuration number.
95 * \see Events.h for more information on this event.
97 RAISES_EVENT(USB_ConfigurationChanged
);
99 /** This module raises the USB_DeviceEnumerationComplete event when the host has completed its
100 * enumeration of the device (i.e. when a REQ_SetConfiguration request changes the current configuration
101 * number from 0 to a non-zero value).
103 * \see Events.h for more information on this event.
105 RAISES_EVENT(USB_DeviceEnumerationComplete
);
107 /* Private Interface - For use in library only: */
108 #if !defined(__DOXYGEN__)
109 #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)
110 #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
113 /* Function Prototypes: */
114 void USB_Device_ProcessControlPacket(void);
116 #if defined(INCLUDE_FROM_DEVCHAPTER9_C)
117 static void USB_Device_SetAddress(void);
118 static void USB_Device_SetConfiguration(void);
119 static void USB_Device_GetConfiguration(void);
120 static void USB_Device_GetDescriptor(void);
121 static void USB_Device_GetStatus(const uint8_t bmRequestType
);
122 #if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)
123 static void USB_Device_ClearSetFeature(const uint8_t bRequest
, const uint8_t bmRequestType
);
128 /* Disable C linkage for C++ Compilers: */
129 #if defined(__cplusplus)