LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Device_LPC18xx.h
Go to the documentation of this file.
1 /*
2  * @brief USB Device definitions for the LPC18xx microcontrollers
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
41 #ifndef __USBDEVICE_LPC18XX_H__
42 #define __USBDEVICE_LPC18XX_H__
43 
44 /* Includes: */
45  #include "../../../../../Common/Common.h"
46  #include "../../USBController.h"
47  #include "../../StdDescriptors.h"
48  #include "../../USBInterrupt.h"
49  #include "../../HAL/HAL.h"
50 
51  #if defined(USB_DEVICE_ROM_DRIVER)
52  #include "../USBRom/usbd_rom_api.h"
53  #endif
54 
55 /* Enable C linkage for C++ Compilers: */
56  #if defined(__cplusplus)
57 extern "C" {
58  #endif
59 
60 /* Preprocessor Checks: */
61  #if !defined(__INCLUDE_FROM_USB_DRIVER)
62  #error Do not include this file directly. Include lpcroot/libraries/LPCUSBlib/Drivers/USB/USB.h instead.
63  #endif
64 
65  #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
66  #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
67  #endif
68 
69 /* Public Interface - May be used in end-application: */
70 /* Macros: */
71 
75  #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
76 
77  #if (!defined(NO_INTERNAL_SERIAL) && defined(__DOXYGEN__))
78 
87  #define USE_INTERNAL_SERIAL 0xDC
88 
92  #define INTERNAL_SERIAL_LENGTH_BITS 80
93 
97  #define INTERNAL_SERIAL_START_ADDRESS 0x0E
98  #else
99  #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
100 
101  #define INTERNAL_SERIAL_LENGTH_BITS 0
102  #define INTERNAL_SERIAL_START_ADDRESS 0
103  #endif
104 
105 /* Function Prototypes: */
127 void USB_Device_SendRemoteWakeup(void);
128 
129 /* Inline Functions: */
136 static inline uint16_t USB_Device_GetFrameNumber(uint8_t corenum) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
137 
138 static inline uint16_t USB_Device_GetFrameNumber(uint8_t corenum)
139 {
140  return USB_REG(corenum)->FRINDEX_D;
141 }
142 
143  #if !defined(NO_SOF_EVENTS)
144 
152 static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
153 
154 static inline void USB_Device_EnableSOFEvents(void)
155 {}
156 
164 static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
165 
166 static inline void USB_Device_DisableSOFEvents(void)
167 {}
168 
169  #endif
170 
171 /* Private Interface - For use in library only: */
172  #if !defined(__DOXYGEN__)
173 /* Inline Functions: */
174  #if defined(USB_DEVICE_OPT_LOWSPEED)
175 static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
176 
177 static inline void USB_Device_SetLowSpeed(void)
178 {
179  // UDCON |= (1 << LSM);
180 }
181 
182 static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
183 
184 static inline void USB_Device_SetFullSpeed(void)
185 {
186  // UDCON &= ~(1 << LSM);
187 }
188 
189  #endif
190 
197 static inline void USB_Device_SetDeviceAddress(uint8_t corenum, const uint8_t Address) ATTR_ALWAYS_INLINE;
198 
199 static inline void USB_Device_SetDeviceAddress(uint8_t corenum, const uint8_t Address)
200 {
201  USB_REG(corenum)->DEVICEADDR = USBDEV_ADDR(Address);
202  USB_REG(corenum)->DEVICEADDR |= USBDEV_ADDR_AD;
203 }
204 
210 static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
211 
212 static inline bool USB_Device_IsAddressSet(void)
213 {
214  return true; /* temporarily */
215 }
216 
217  #if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
218 static inline void USB_Device_GetSerialString(uint16_t *const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
219 
220 static inline void USB_Device_GetSerialString(uint16_t *const UnicodeString)
221 {
222  uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
224 
225  uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
226 
227  for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) {
228  uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);
229 
230  if (SerialCharNum & 0x01) {
231  SerialByte >>= 4;
232  SigReadAddress++;
233  }
234 
235  SerialByte &= 0x0F;
236 
237  UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
238  (('A' - 10) + SerialByte) : ('0' + SerialByte));
239  }
240 
241  SetGlobalInterruptMask(CurrentGlobalInt);
242 }
243 
244  #endif
245 
246  #endif
247 
248 /* Disable C linkage for C++ Compilers: */
249  #if defined(__cplusplus)
250 }
251  #endif
252 
253 #endif
254