2 * @brief USB Device definitions for the LPC18xx microcontrollers
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 /** @ingroup Group_Device
\r
33 * @defgroup Group_Device_LPC18xx Device Definitions and General Functions (LPC18xx)
\r
34 * @brief Device Definitions and General Functions for the LPC architecture.
\r
36 * Functions, macros, variables, enums and types related to usb device.
\r
41 #ifndef __USBDEVICE_LPC18XX_H__
\r
42 #define __USBDEVICE_LPC18XX_H__
\r
45 #include "../../../../../Common/Common.h"
\r
46 #include "../../USBController.h"
\r
47 #include "../../StdDescriptors.h"
\r
48 #include "../../USBInterrupt.h"
\r
49 #include "../../HAL/HAL.h"
\r
51 #if defined(USB_DEVICE_ROM_DRIVER)
\r
52 #include "../USBRom/usbd_rom_api.h"
\r
55 /* Enable C linkage for C++ Compilers: */
\r
56 #if defined(__cplusplus)
\r
60 /* Preprocessor Checks: */
\r
61 #if !defined(__INCLUDE_FROM_USB_DRIVER)
\r
62 #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
\r
65 #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
\r
66 #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
\r
69 /* Public Interface - May be used in end-application: */
\r
72 /** Mask for the Options parameter of the @ref USB_Init() function. This indicates that the
\r
73 * USB interface should be initialized in full speed (12Mb/s) mode.
\r
75 #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
\r
77 #if (!defined(NO_INTERNAL_SERIAL) && defined(__DOXYGEN__))
\r
78 /** String descriptor index for the device's unique serial number string descriptor within the device.
\r
79 * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
\r
80 * number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
\r
81 * a unique serial number internally, and setting the device descriptors serial number string index to this value
\r
82 * will cause it to use the internal serial number.
\r
84 * On unsupported devices, this will evaluate to @ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
\r
85 * number for the device.
\r
87 #define USE_INTERNAL_SERIAL 0xDC
\r
89 /** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
\r
92 #define INTERNAL_SERIAL_LENGTH_BITS 80
\r
94 /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
\r
97 #define INTERNAL_SERIAL_START_ADDRESS 0x0E
\r
99 #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
\r
101 #define INTERNAL_SERIAL_LENGTH_BITS 0
\r
102 #define INTERNAL_SERIAL_START_ADDRESS 0
\r
105 /* Function Prototypes: */
\r
107 * @brief Sends a Remote Wakeup request to the host. This signals to the host that the device should
\r
108 * be taken out of suspended mode, and communications should resume.
\r
110 * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
\r
111 * host computer when the host has suspended all USB devices to enter a low power state.
\r
113 * @note This macro should only be used if the device has indicated to the host that it
\r
114 * supports the Remote Wakeup feature in the device descriptors, and should only be
\r
115 * issued if the host is currently allowing remote wakeup events from the device (i.e.,
\r
116 * the @ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
\r
117 * compile time option is used, this macro is unavailable.
\r
120 * @note The USB clock must be running for this function to operate. If the stack is initialized with
\r
121 * the @ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
\r
122 * before attempting to call this function.
\r
124 * \see @ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
\r
127 void USB_Device_SendRemoteWakeup(void);
\r
129 /* Inline Functions: */
\r
131 * @brief Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
\r
132 * the frame number is incremented by one.
\r
133 * @param corenum : ID Number of USB Core to be processed.
\r
134 * @return Current frame number.
\r
136 static inline uint16_t USB_Device_GetFrameNumber(uint8_t corenum) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
\r
138 static inline uint16_t USB_Device_GetFrameNumber(uint8_t corenum)
\r
140 return USB_REG(corenum)->FRINDEX_D;
\r
143 #if !defined(NO_SOF_EVENTS)
\r
145 * @brief Enables the device mode Start Of Frame events. When enabled, this causes the
\r
146 * @ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
\r
147 * at the start of each USB frame when enumerated in device mode.
\r
149 * @note Not available when the \c NO_SOF_EVENTS compile time token is defined.
\r
152 static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
\r
154 static inline void USB_Device_EnableSOFEvents(void)
\r
158 * @brief Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
\r
159 * @ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
\r
161 * @note Not available when the \c NO_SOF_EVENTS compile time token is defined.
\r
164 static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
\r
166 static inline void USB_Device_DisableSOFEvents(void)
\r
171 /* Private Interface - For use in library only: */
\r
172 #if !defined(__DOXYGEN__)
\r
173 /* Inline Functions: */
\r
174 #if defined(USB_DEVICE_OPT_LOWSPEED)
\r
175 static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
\r
177 static inline void USB_Device_SetLowSpeed(void)
\r
179 // UDCON |= (1 << LSM);
\r
182 static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
\r
184 static inline void USB_Device_SetFullSpeed(void)
\r
186 // UDCON &= ~(1 << LSM);
\r
192 * @brief Set current USB device address.
\r
193 * @param corenum : ID Number of USB Core to be processed.
\r
194 * @param Address : new USB device address.
\r
197 static inline void USB_Device_SetDeviceAddress(uint8_t corenum, const uint8_t Address) ATTR_ALWAYS_INLINE;
\r
199 static inline void USB_Device_SetDeviceAddress(uint8_t corenum, const uint8_t Address)
\r
201 USB_REG(corenum)->DEVICEADDR = USBDEV_ADDR(Address);
\r
202 USB_REG(corenum)->DEVICEADDR |= USBDEV_ADDR_AD;
\r
206 * @brief Get status of USB address whether it is set or not.
\r
207 * @return true if set
\r
210 static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
\r
212 static inline bool USB_Device_IsAddressSet(void)
\r
214 return true; /* temporarily */
\r
217 #if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
\r
218 static inline void USB_Device_GetSerialString(uint16_t *const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
\r
220 static inline void USB_Device_GetSerialString(uint16_t *const UnicodeString)
\r
222 uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
\r
223 GlobalInterruptDisable();
\r
225 uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
\r
227 for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) {
\r
228 uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);
\r
230 if (SerialCharNum & 0x01) {
\r
235 SerialByte &= 0x0F;
\r
237 UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
\r
238 (('A' - 10) + SerialByte) : ('0' + SerialByte));
\r
241 SetGlobalInterruptMask(CurrentGlobalInt);
\r
248 /* Disable C linkage for C++ Compilers: */
\r
249 #if defined(__cplusplus)
\r