X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/cc1afb21bdc089426652f21769164645cae062fd..243fec4450d3a3246f3f0d92751a95daef7c1503:/embedded/libs4c/usb/lpcusb/lpcusb.c diff --git a/embedded/libs4c/usb/lpcusb/lpcusb.c b/embedded/libs4c/usb/lpcusb/lpcusb.c index 09b1eac..4041371 100644 --- a/embedded/libs4c/usb/lpcusb/lpcusb.c +++ b/embedded/libs4c/usb/lpcusb/lpcusb.c @@ -8,6 +8,23 @@ #include #include +#ifdef MACH_LPC17XX + #include + #include + #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; @@ -103,6 +120,7 @@ void lpc_usb_reset(void) 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 */ @@ -122,6 +140,31 @@ void lpc_usb_hw_init (void) 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();