]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Core/Events.h
Merge commit 'a074364c3731d66b56d988c8a6c960a83ea0e0a1' as 'tmk_core'
[tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Core / Events.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 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 Event management definitions.
33 * \copydetails Group_Events
34 *
35 * \note This file should not be included directly. It is automatically included as needed by the USB driver
36 * dispatch header located in LUFA/Drivers/USB/USB.h.
37 */
38
39 /** \ingroup Group_USB
40 * \defgroup Group_Events USB Events
41 * \brief USB Event management definitions.
42 *
43 * This module contains macros and functions relating to the management of library events, which are small
44 * pieces of code similar to ISRs which are run when a given condition is met. Each event can be fired from
45 * multiple places in the user or library code, which may or may not be inside an ISR, thus each handler
46 * should be written to be as small and fast as possible to prevent possible problems.
47 *
48 * Events can be hooked by the user application by declaring a handler function with the same name and parameters
49 * listed here. If an event with no user-associated handler is fired within the library, it by default maps to an
50 * internal empty stub function.
51 *
52 * Each event must only have one associated event handler, but can be raised by multiple sources by calling the
53 * event handler function (with any required event parameters).
54 *
55 * @{
56 */
57
58 #ifndef __USBEVENTS_H__
59 #define __USBEVENTS_H__
60
61 /* Includes: */
62 #include "../../../Common/Common.h"
63 #include "USBMode.h"
64
65 /* Enable C linkage for C++ Compilers: */
66 #if defined(__cplusplus)
67 extern "C" {
68 #endif
69
70 /* Preprocessor Checks: */
71 #if !defined(__INCLUDE_FROM_USB_DRIVER)
72 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
73 #endif
74
75 /* Public Interface - May be used in end-application: */
76 /* Pseudo-Functions for Doxygen: */
77 #if !defined(__INCLUDE_FROM_EVENTS_C) || defined(__DOXYGEN__)
78 /** Event for USB mode pin level change. This event fires when the USB interface is set to dual role
79 * mode, and the UID pin level has changed to indicate a new mode (device or host). This event fires
80 * before the mode is switched to the newly indicated mode but after the \ref EVENT_USB_Device_Disconnect
81 * event has fired (if disconnected before the role change).
82 *
83 * \note This event only exists on microcontrollers that support dual role USB modes.
84 * \n\n
85 *
86 * \note This event does not exist if the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY tokens have been supplied
87 * to the compiler (see \ref Group_USBManagement documentation).
88 */
89 void EVENT_USB_UIDChange(void);
90
91 /** Event for USB host error. This event fires when a hardware fault has occurred whilst the USB
92 * interface is in host mode.
93 *
94 * \param[in] ErrorCode Error code indicating the failure reason, a value in \ref USB_Host_ErrorCodes_t.
95 *
96 * \note This event only exists on microcontrollers that supports USB host mode.
97 * \n\n
98 *
99 * \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
100 * \ref Group_USBManagement documentation).
101 */
102 void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
103
104 /** Event for USB device attachment. This event fires when a the USB interface is in host mode, and
105 * a USB device has been connected to the USB interface. This is interrupt driven, thus fires before
106 * the standard \ref EVENT_USB_Device_Connect() event and so can be used to programmatically start the USB
107 * management task to reduce CPU consumption.
108 *
109 * \note This event only exists on microcontrollers that supports USB host mode.
110 * \n\n
111 *
112 * \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
113 * \ref Group_USBManagement documentation).
114 *
115 * \see \ref USB_USBTask() for more information on the USB management task and reducing CPU usage.
116 */
117 void EVENT_USB_Host_DeviceAttached(void);
118
119 /** Event for USB device removal. This event fires when a the USB interface is in host mode, and
120 * a USB device has been removed the USB interface whether or not it has been enumerated. This
121 * can be used to programmatically stop the USB management task to reduce CPU consumption.
122 *
123 * \note This event only exists on microcontrollers that supports USB host mode.
124 * \n\n
125 *
126 * \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
127 * \ref Group_USBManagement documentation).
128 *
129 * \see \ref USB_USBTask() for more information on the USB management task and reducing CPU usage.
130 */
131 void EVENT_USB_Host_DeviceUnattached(void);
132
133 /** Event for USB device enumeration failure. This event fires when a the USB interface is
134 * in host mode, and an attached USB device has failed to enumerate completely.
135 *
136 * \param[in] ErrorCode Error code indicating the failure reason, a value in
137 * \ref USB_Host_EnumerationErrorCodes_t.
138 *
139 * \param[in] SubErrorCode Sub error code indicating the reason for failure - for example, if the
140 * ErrorCode parameter indicates a control error, this will give the error
141 * code returned by the \ref USB_Host_SendControlRequest() function.
142 *
143 * \note This event only exists on microcontrollers that supports USB host mode.
144 * \n\n
145 *
146 * \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
147 * \ref Group_USBManagement documentation).
148 */
149 void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
150 const uint8_t SubErrorCode);
151
152 /** Event for USB device enumeration completion. This event fires when a the USB interface is
153 * in host mode and an attached USB device has been completely enumerated and is ready to be
154 * controlled by the user application.
155 *
156 * This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
157 * 1 second) when a transaction is waiting to be processed by the device will prevent break communications
158 * and cause the host to reset the USB bus.
159 */
160 void EVENT_USB_Host_DeviceEnumerationComplete(void);
161
162 /** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB
163 * frame, once per millisecond, and is synchronized to the USB bus. This can be used as an accurate
164 * millisecond timer source when the USB bus is not suspended while in host mode.
165 *
166 * This event is time-critical; it is run once per millisecond and thus long handlers will significantly
167 * degrade device performance. This event should only be enabled when needed to reduce device wake-ups.
168 *
169 * \note This event is not normally active - it must be manually enabled and disabled via the
170 * \ref USB_Host_EnableSOFEvents() and \ref USB_Host_DisableSOFEvents() commands after enumeration of
171 * a USB device.
172 * \n\n
173 *
174 * \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
175 * \ref Group_USBManagement documentation).
176 */
177 void EVENT_USB_Host_StartOfFrame(void);
178
179 /** Event for USB device connection. This event fires when the microcontroller is in USB Device mode
180 * and the device is connected to a USB host, beginning the enumeration process measured by a rising
181 * level on the microcontroller's VBUS sense pin.
182 *
183 * This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
184 * two seconds) will prevent the device from enumerating correctly.
185 *
186 * \attention This event may fire multiple times during device enumeration on the microcontrollers with limited USB controllers
187 * if \c NO_LIMITED_CONTROLLER_CONNECT is not defined.
188 *
189 * \note For the microcontrollers with limited USB controller functionality, VBUS sensing is not available.
190 * this means that the current connection state is derived from the bus suspension and wake up events by default,
191 * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
192 * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behavior turned off by
193 * passing the \c NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
194 * and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
195 * \n\n
196 *
197 * \see \ref Group_USBManagement for more information on the USB management task and reducing CPU usage.
198 */
199 void EVENT_USB_Device_Connect(void);
200
201 /** Event for USB device disconnection. This event fires when the microcontroller is in USB Device mode and the device is
202 * disconnected from a host, measured by a falling level on the microcontroller's VBUS sense pin.
203 *
204 * \attention This event may fire multiple times during device enumeration on the microcontrollers with limited USB controllers
205 * if \c NO_LIMITED_CONTROLLER_CONNECT is not defined.
206 *
207 * \note For the microcontrollers with limited USB controllers, VBUS sense is not available to the USB controller.
208 * this means that the current connection state is derived from the bus suspension and wake up events by default,
209 * which is not always accurate (host may suspend the bus while still connected). If the actual connection state
210 * needs to be determined, VBUS should be routed to an external pin, and the auto-detect behavior turned off by
211 * passing the \c NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
212 * and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
213 * \n\n
214 *
215 * \see \ref Group_USBManagement for more information on the USB management task and reducing CPU usage.
216 */
217 void EVENT_USB_Device_Disconnect(void);
218
219 /** Event for control requests. This event fires when a the USB host issues a control request
220 * to the mandatory device control endpoint (of address 0). This may either be a standard
221 * request that the library may have a handler code for internally, or a class specific request
222 * issued to the device which must be handled appropriately. If a request is not processed in the
223 * user application via this event, it will be passed to the library for processing internally
224 * if a suitable handler exists.
225 *
226 * This event is time-critical; each packet within the request transaction must be acknowledged or
227 * sent within 50ms or the host will abort the transfer.
228 *
229 * The library internally handles all standard control requests with the exceptions of SYNC FRAME,
230 * SET DESCRIPTOR and SET INTERFACE. These and all other non-standard control requests will be left
231 * for the user to process via this event if desired. If not handled in the user application or by
232 * the library internally, unknown requests are automatically STALLed.
233 *
234 * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
235 * \ref Group_USBManagement documentation).
236 * \n\n
237 *
238 * \note Requests should be handled in the same manner as described in the USB 2.0 Specification,
239 * or appropriate class specification. In all instances, the library has already read the
240 * request SETUP parameters into the \ref USB_ControlRequest structure which should then be used
241 * by the application to determine how to handle the issued request.
242 */
243 void EVENT_USB_Device_ControlRequest(void);
244
245 /** Event for USB configuration number changed. This event fires when a the USB host changes the
246 * selected configuration number while in device mode. This event should be hooked in device
247 * applications to create the endpoints and configure the device for the selected configuration.
248 *
249 * This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
250 * one second) will prevent the device from enumerating correctly.
251 *
252 * This event fires after the value of \ref USB_Device_ConfigurationNumber has been changed.
253 *
254 * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
255 * \ref Group_USBManagement documentation).
256 */
257 void EVENT_USB_Device_ConfigurationChanged(void);
258
259 /** Event for USB suspend. This event fires when a the USB host suspends the device by halting its
260 * transmission of Start Of Frame pulses to the device. This is generally hooked in order to move
261 * the device over to a low power state until the host wakes up the device. If the USB interface is
262 * enumerated with the \ref USB_OPT_AUTO_PLL option set, the library will automatically suspend the
263 * USB PLL before the event is fired to save power.
264 *
265 * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
266 * \ref Group_USBManagement documentation).
267 * \n\n
268 *
269 * \note This event does not exist on the microcontrollers with limited USB VBUS sensing abilities
270 * when the \c NO_LIMITED_CONTROLLER_CONNECT compile time token is not set - see
271 * \ref EVENT_USB_Device_Disconnect.
272 *
273 * \see \ref EVENT_USB_Device_WakeUp() event for accompanying Wake Up event.
274 */
275 void EVENT_USB_Device_Suspend(void);
276
277 /** Event for USB wake up. This event fires when a the USB interface is suspended while in device
278 * mode, and the host wakes up the device by supplying Start Of Frame pulses. This is generally
279 * hooked to pull the user application out of a low power state and back into normal operating
280 * mode. If the USB interface is enumerated with the \ref USB_OPT_AUTO_PLL option set, the library
281 * will automatically restart the USB PLL before the event is fired.
282 *
283 * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
284 * \ref Group_USBManagement documentation).
285 * \n\n
286 *
287 * \note This event does not exist on the microcontrollers with limited USB VBUS sensing abilities
288 * when the \c NO_LIMITED_CONTROLLER_CONNECT compile time token is not set - see
289 * \ref EVENT_USB_Device_Disconnect.
290 *
291 * \see \ref EVENT_USB_Device_Suspend() event for accompanying Suspend event.
292 */
293 void EVENT_USB_Device_WakeUp(void);
294
295 /** Event for USB interface reset. This event fires when the USB interface is in device mode, and
296 * a the USB host requests that the device reset its interface. This event fires after the control
297 * endpoint has been automatically configured by the library.
298 *
299 * This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
300 * two seconds) will prevent the device from enumerating correctly.
301 *
302 * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
303 * \ref Group_USBManagement documentation).
304 */
305 void EVENT_USB_Device_Reset(void);
306
307 /** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB
308 * frame, once per millisecond, and is synchronized to the USB bus. This can be used as an accurate
309 * millisecond timer source when the USB bus is enumerated in device mode to a USB host.
310 *
311 * This event is time-critical; it is run once per millisecond and thus long handlers will significantly
312 * degrade device performance. This event should only be enabled when needed to reduce device wake-ups.
313 *
314 * \pre This event is not normally active - it must be manually enabled and disabled via the
315 * \ref USB_Device_EnableSOFEvents() and \ref USB_Device_DisableSOFEvents() commands after enumeration.
316 * \n\n
317 *
318 * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
319 * \ref Group_USBManagement documentation).
320 */
321 void EVENT_USB_Device_StartOfFrame(void);
322 #endif
323
324 /* Private Interface - For use in library only: */
325 #if !defined(__DOXYGEN__)
326 /* Function Prototypes: */
327 #if defined(__INCLUDE_FROM_EVENTS_C)
328 void USB_Event_Stub(void) ATTR_CONST;
329
330 #if defined(USB_CAN_BE_BOTH)
331 void EVENT_USB_UIDChange(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
332 #endif
333
334 #if defined(USB_CAN_BE_HOST)
335 void EVENT_USB_Host_HostError(const uint8_t ErrorCode) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
336 void EVENT_USB_Host_DeviceAttached(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
337 void EVENT_USB_Host_DeviceUnattached(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
338 void EVENT_USB_Host_DeviceEnumerationComplete(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
339 void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
340 const uint8_t SubErrorCode)
341 ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
342 void EVENT_USB_Host_StartOfFrame(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
343 #endif
344
345 #if defined(USB_CAN_BE_DEVICE)
346 void EVENT_USB_Device_Connect(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
347 void EVENT_USB_Device_Disconnect(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
348 void EVENT_USB_Device_ControlRequest(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
349 void EVENT_USB_Device_ConfigurationChanged(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
350 void EVENT_USB_Device_Suspend(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
351 void EVENT_USB_Device_WakeUp(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
352 void EVENT_USB_Device_Reset(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
353 void EVENT_USB_Device_StartOfFrame(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
354 #endif
355 #endif
356 #endif
357
358 /* Disable C linkage for C++ Compilers: */
359 #if defined(__cplusplus)
360 }
361 #endif
362
363 #endif
364
365 /** @} */
366
Imprint / Impressum