#include <usb/usb.h>
#include <usb/lpcusb.h>
+#ifdef MACH_LPC17XX
+ #include <LPC17xx.h>
+ #include <lpcUSB.h>
+ #ifndef PINSEL1
+ #define PINSEL1 (PINCON->PINSEL1)
+ #define PINSEL3 (PINCON->PINSEL3)
+ #define PINSEL4 (PINCON->PINSEL4)
+ #endif
+ #ifndef PCONP
+ #define PCONP (SC->PCONP)
+ #endif
+#endif
+
+#ifndef USB_VBUS_PIN_USED
+#define USB_VBUS_PIN_USED 1
+#endif
+
unsigned int lpc_ep2addr(unsigned int ep_num)
{
unsigned int val;
void lpc_usb_hw_init (void)
{
+#if defined(INC_LPC214x_H) || defined(MACH_LPC21XX)
PINSEL1 &= ~0xC000C000;
// PINSEL1 |= 0x40004000; /* Select USB Link, VBUS */
PINSEL1 |= 0x80000000; /* Select USB Link, VBUS */
PLLFEED48 = 0x55; /* Feed Sequence 2 */
USBDevIntEn = USBDevInt_DEV_STAT; /* Enable Device Status Interrupt */
+#endif /* MACH_LPC21XX */
+
+#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX)
+ /**
+ ** ** ATTENTION **
+ ** USB clock (48MHz) should be set up externally before calling this fn
+ ** by setting USBCLKCFG (eg. USBCLKCFG = 5 for f_cco=288MHz).
+ ** If some of the pins shared with USB device are to be used for
+ ** different purpose, following PINSELs must be changed after retutn
+ ** from this fn.
+ **/
+
+ /* set up USB pins */
+ PINSEL1 = (PINSEL1 & ~(0x3<<26)) | (0x1<<26); /* USB_D+,- @ P0.29,30 */
+ PINSEL4 = (PINSEL4 & ~(0x3<<18)) | (0x1<<18); /* USB_CONNECT @ P2.9 */
+#if USB_VBUS_PIN_USED
+ PINSEL3 = (PINSEL3 & ~(0x3<<28)) | (0x2<<28); /* Vbus @ P1.30 */
+#endif
+ /* switch USB power on */
+ PCONP |= 1<<31;
+ /* switch USB internal clock switch on */
+ USBClkCtrl = 0x12;
+ while ((USBClkSt & 0x12) != 0x12);
+
+#endif /* MACH_LPC23XX */
/* Partial Manual Reset since Automatic Bus Reset is not working */
lpc_usb_reset();