2 * @brief Common USB Host definitions for all architectures
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
33 /** @ingroup Group_USB
\r
34 * @defgroup Group_Host Host Management
\r
35 * @brief USB Host management definitions for USB host mode.
\r
37 * USB Host mode related macros and enums. This module contains macros and enums which are used when
\r
38 * the USB controller is initialized in host mode.
\r
43 #ifndef __USBHOST_H__
\r
44 #define __USBHOST_H__
\r
47 #include "../../../Common/Common.h"
\r
48 #include "USBMode.h"
\r
50 /* Enable C linkage for C++ Compilers: */
\r
51 #if defined(__cplusplus)
\r
55 /* Preprocessor Checks: */
\r
56 #if !defined(__INCLUDE_FROM_USB_DRIVER)
\r
57 #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
\r
60 /* Public Interface - May be used in end-application: */
\r
62 /** Enum for the various states of the USB Host state machine.
\r
64 * For information on each possible USB host state, refer to the USB 2.0 specification.
\r
65 * Several of the USB host states are broken up further into multiple smaller sub-states,
\r
66 * so that they can be internally implemented inside the library in an efficient manner.
\r
68 * @see @ref USB_HostState, which stores the current host state machine state.
\r
70 enum USB_Host_States_t
\r
72 HOST_STATE_WaitForDevice = 0, /**< This state indicates that the stack is waiting for an interval
\r
73 * to elapse before continuing with the next step of the device
\r
74 * enumeration process.
\r
76 HOST_STATE_Unattached = 1, /**< This state indicates that the host state machine is waiting for
\r
77 * a device to be attached so that it can start the enumeration process.
\r
79 HOST_STATE_Powered = 2, /**< This state indicates that a device has been attached, and the
\r
80 * library's internals are being configured to begin the enumeration
\r
83 HOST_STATE_Powered_WaitForDeviceSettle = 3, /**< This state indicates that the stack is waiting for the initial
\r
84 * settling period to elapse before beginning the enumeration process.
\r
86 HOST_STATE_Powered_WaitForConnect = 4, /**< This state indicates that the stack is waiting for a connection event
\r
87 * from the USB controller to indicate a valid USB device has been attached
\r
88 * to the bus and is ready to be enumerated.
\r
90 HOST_STATE_Powered_DoReset = 5, /**< This state indicates that a valid USB device has been attached, and that
\r
91 * it will now be reset to ensure it is ready for enumeration.
\r
93 HOST_STATE_Powered_ConfigPipe = 6, /**< This state indicates that the attached device is currently powered and
\r
94 * reset, and that the control pipe is now being configured by the stack.
\r
96 HOST_STATE_Default = 7, /**< This state indicates that the stack is currently retrieving the control
\r
97 * endpoint's size from the device, so that the control pipe can be altered
\r
100 HOST_STATE_Default_PostReset = 8, /**< This state indicates that the control pipe is being reconfigured to match
\r
101 * the retrieved control endpoint size from the device, and the device's USB
\r
102 * bus address is being set.
\r
104 HOST_STATE_Default_PostAddressSet = 9, /**< This state indicates that the device's address has now been set, and the
\r
105 * stack is has now completed the device enumeration process. This state causes
\r
106 * the stack to change the current USB device address to that set for the
\r
107 * connected device, before progressing to the @ref HOST_STATE_Addressed state
\r
108 * ready for use in the user application.
\r
110 HOST_STATE_Addressed = 10, /**< Indicates that the device has been enumerated and addressed, and is now waiting
\r
111 * for the user application to configure the device ready for use.
\r
113 HOST_STATE_Configured = 11, /**< Indicates that the device has been configured into a valid device configuration,
\r
114 * ready for general use by the user application.
\r
118 #include "StdDescriptors.h"
\r
120 #include "USBInterrupt.h"
\r
123 /** Indicates the fixed USB device address which any attached device is enumerated to when in
\r
124 * host mode. As only one USB device may be attached to the LPC in host mode at any one time
\r
125 * and that the address used is not important (other than the fact that it is non-zero), a
\r
126 * fixed value is specified by the library.
\r
128 #define USB_HOST_DEVICEADDRESS 1
\r
130 #if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
\r
131 /** Constant for the maximum software timeout period of sent USB control transactions to an attached
\r
132 * device. If a device fails to respond to a sent control request within this period, the
\r
133 * library will return a timeout error code.
\r
135 * This value may be overridden in the user project makefile as the value of the
\r
136 * @ref USB_HOST_TIMEOUT_MS token, and passed to the compiler using the -D switch.
\r
138 #define USB_HOST_TIMEOUT_MS 1000
\r
141 #if !defined(HOST_DEVICE_SETTLE_DELAY_MS) || defined(__DOXYGEN__)
\r
142 /** Constant for the delay in milliseconds after a device is connected before the library
\r
143 * will start the enumeration process. Some devices require a delay of up to 5 seconds
\r
144 * after connection before the enumeration process can start or incorrect operation will
\r
147 * The default delay value may be overridden in the user project makefile by defining the
\r
148 * \c HOST_DEVICE_SETTLE_DELAY_MS token to the required delay in milliseconds, and passed to the
\r
149 * compiler using the -D switch.
\r
151 #define HOST_DEVICE_SETTLE_DELAY_MS 1000
\r
154 /** Enum for the error codes for the @ref EVENT_USB_Host_HostError() event.
\r
156 * @see @ref Group_Events for more information on this event.
\r
158 enum USB_Host_ErrorCodes_t {
\r
159 HOST_ERROR_VBusVoltageDip = 0, /**< VBUS voltage dipped to an unacceptable level. This
\r
160 * error may be the result of an attached device drawing
\r
161 * too much current from the VBUS line, or due to the
\r
162 * LPC's power source being unable to supply sufficient
\r
167 /** Enum for the error codes for the @ref EVENT_USB_Host_DeviceEnumerationFailed() event.
\r
169 * @see @ref Group_Events for more information on this event.
\r
171 enum USB_Host_EnumerationErrorCodes_t {
\r
172 HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
\r
173 * ErrorCode parameter value for the @ref EVENT_USB_Host_DeviceEnumerationFailed()
\r
176 HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
\r
177 * to complete successfully, due to a timeout or other
\r
180 HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines
\r
181 * indicating the attachment of a device.
\r
183 HOST_ENUMERROR_ControlError = 3, /**< One of the enumeration control requests failed to
\r
184 * complete successfully.
\r
186 HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to
\r
187 * configure correctly.
\r
192 * @brief Get current active host core number
\r
193 * @return Active USB host core number
\r
195 uint8_t USB_Host_GetActiveHost(void);
\r
197 /** Array stores pre-set size of control pipe of all available USB cores
\r
199 extern uint8_t USB_Host_ControlPipeSize[MAX_USB_CORE];
\r
201 /* Inline Functions: */
\r
202 #if !defined(NO_SOF_EVENTS)
\r
205 * @brief Enables the host mode Start Of Frame events. When enabled, this causes the
\r
206 * @ref EVENT_USB_Host_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
\r
207 * at the start of each USB frame when a device is enumerated while in host mode.
\r
209 * @note Not available when the \c NO_SOF_EVENTS compile time token is defined.
\r
212 static inline void USB_Host_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
\r
214 static inline void USB_Host_EnableSOFEvents(void)
\r
218 * @brief Disables the host mode Start Of Frame events. When disabled, this stops the firing of the
\r
219 * @ref EVENT_USB_Host_StartOfFrame() event when enumerated in host mode.
\r
221 * @note Not available when the NO_SOF_EVENTS compile time token is defined.
\r
224 static inline void USB_Host_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
\r
226 static inline void USB_Host_DisableSOFEvents(void)
\r
232 * @brief Resets the USB bus, including the endpoints in any attached device and pipes on the LPC host.
\r
233 * USB bus resets leave the default control pipe configured (if already configured).
\r
235 * If the USB bus has been suspended prior to issuing a bus reset, the attached device will be
\r
236 * woken up automatically and the bus resumed after the reset has been correctly issued.
\r
239 static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE;
\r
241 static inline void USB_Host_ResetBus(void)
\r
245 * @brief Determines if a previously issued bus reset (via the @ref USB_Host_ResetBus() macro) has
\r
247 * @return Boolean \c true if no bus reset is currently being sent, \c false otherwise.
\r
249 static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
251 static inline bool USB_Host_IsBusResetComplete(void)
\r
257 * @brief Resumes USB communications with an attached and enumerated device, by resuming the transmission
\r
258 * of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the
\r
259 * host and attached device may occur.
\r
262 static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE;
\r
264 static inline void USB_Host_ResumeBus(void)
\r
268 * @brief Suspends the USB bus, preventing any communications from occurring between the host and attached
\r
269 * device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
\r
270 * messages to the device.
\r
273 static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;
\r
275 static inline void USB_Host_SuspendBus(void)
\r
279 * @brief Determines if the USB bus has been suspended via the use of the @ref USB_Host_SuspendBus() macro,
\r
280 * false otherwise. While suspended, no USB communications can occur until the bus is resumed,
\r
281 * except for the Remote Wakeup event from the device if supported.
\r
283 * @return Boolean \c true if the bus is currently suspended, \c false otherwise.
\r
285 static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
287 static inline bool USB_Host_IsBusSuspended(void)
\r
293 * @brief Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or
\r
294 * false if the attached device is enumerated in Low Speed mode (1.5Mb/s).
\r
296 * @return Boolean \c true if the attached device is enumerated in Full Speed mode, \c false otherwise.
\r
298 static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
300 static inline bool USB_Host_IsDeviceFullSpeed(void)
\r
302 return true; // implement later when needed
\r
306 * @brief Determines if the attached device is currently issuing a Remote Wakeup request, requesting
\r
307 * that the host resume the USB bus and wake up the device, false otherwise.
\r
309 * @return Boolean \c true if the attached device has sent a Remote Wakeup request, \c false otherwise.
\r
311 static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
313 static inline bool USB_Host_IsRemoteWakeupSent(void)
\r
318 /** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
\r
319 static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE;
\r
321 static inline void USB_Host_ClearRemoteWakeupSent(void)
\r
324 /** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
\r
325 * a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to
\r
328 static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE;
\r
330 static inline void USB_Host_ResumeFromWakeupRequest(void)
\r
334 * @brief Determines if a resume from Remote Wakeup request is currently being sent to an attached
\r
337 * @return Boolean \c true if no resume request is currently being sent, \c false otherwise.
\r
339 static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
\r
341 static inline bool USB_Host_IsResumeFromWakeupRequestSent(void)
\r
346 /* Private Interface - For use in library only: */
\r
347 #if !defined(__DOXYGEN__)
\r
349 static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE;
\r
351 static inline void USB_Host_HostMode_On(void)
\r
354 static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE;
\r
356 static inline void USB_Host_HostMode_Off(void)
\r
359 static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE;
\r
361 static inline void USB_Host_VBUS_Auto_Enable(void)
\r
364 static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE;
\r
366 static inline void USB_Host_VBUS_Manual_Enable(void)
\r
369 static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE;
\r
371 static inline void USB_Host_VBUS_Auto_On(void)
\r
374 static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE;
\r
376 static inline void USB_Host_VBUS_Manual_On(void)
\r
379 static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE;
\r
381 static inline void USB_Host_VBUS_Auto_Off(void)
\r
384 static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE;
\r
386 static inline void USB_Host_VBUS_Manual_Off(void)
\r
389 static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
\r
391 static inline void USB_Host_SetDeviceAddress(const uint8_t Address)
\r
395 /** Enum defines error codes returned by \ref USB_Host_WaitMS()
\r
397 enum USB_Host_WaitMSErrorCodes_t {
\r
398 HOST_WAITERROR_Successful = 0,
\r
399 HOST_WAITERROR_DeviceDisconnect = 1,
\r
400 HOST_WAITERROR_PipeError = 2,
\r
401 HOST_WAITERROR_SetupStalled = 3,
\r
404 /* Function Prototypes: */
\r
406 * @brief Perform enumeration process
\r
408 * @param corenum: active USB port number
\r
411 void USB_Host_ProcessNextHostState(uint8_t corenum);
\r
414 * @brief A delay function use in host
\r
415 * @note This function currently is not inplemented
\r
416 * @return always return HOST_WAITERROR_Successful \ref USB_Host_WaitMSErrorCodes_t
\r
418 uint8_t USB_Host_WaitMS(uint8_t MS);
\r
421 * @brief Returns the current USB frame number, when in host mode. Every millisecond the USB bus is active (i.e. not suspended)
\r
422 * the frame number is incremented by one.
\r
423 * @return Current frame number on active USB port
\r
425 uint16_t USB_Host_GetFrameNumber(void);
\r
427 #if defined(__INCLUDE_FROM_HOST_C)
\r
428 // static void USB_Host_ResetDevice(void);
\r
433 /* Disable C linkage for C++ Compilers: */
\r
434 #if defined(__cplusplus)
\r