#include <usb/usb.h>
#include <usb/lpcusb.h>
-#ifdef MACH_LPC17XX
+#if defined(MACH_LPC178X)
+ #include <LPC177x_8x.h>
+ #include <lpcUSB.h>
+ #include <hal_gpio.h>
+ #ifndef PCONP
+ #define PCONP (LPC_SC->PCONP)
+ #endif
+#elif defined(MACH_LPC17XX)
#include <LPC17xx.h>
#include <lpcUSB.h>
#ifndef PINSEL1
#define USB_VBUS_PIN_USED 1
#endif
+static void lpc_usb_configure_pins(void)
+{
+#ifdef USB_PPWR2_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB_PPWR2_PIN);
+#endif
+#ifdef USB_DPLUS_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB_DPLUS_PIN);
+#endif
+#ifdef USB_DMINUS_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB_DMINUS_PIN);
+#endif
+#ifdef USB1_DPLUS_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB1_DPLUS_PIN);
+#endif
+#ifdef USB1_DMINUS_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB1_DMINUS_PIN);
+#endif
+#ifdef USB2_DPLUS_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB2_DPLUS_PIN);
+#endif
+#ifdef USB2_DMINUS_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB2_DMINUS_PIN);
+#endif
+#ifdef USB2_OVRCR_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB2_OVRCR_PIN);
+#endif
+#ifdef USB_CONNECT_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB_CONNECT_PIN);
+#endif
+#ifdef USB1_CONNECT_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB1_CONNECT_PIN);
+#endif
+#ifdef USB1_PWR_SW_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB1_PWR_SW_PIN);
+#endif
+#ifdef USB1_ID_PIN
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB1_ID_PIN);
+#endif
+#if defined(USB_VBUS_PIN) && defined(USB_VBUS_PIN_USED)
+ #define NEW_USB_PIN_CFG
+ hal_pin_conf(USB_VBUS_PIN);
+#endif
+
+#ifndef NEW_USB_PIN_CFG
+#if defined(INC_LPC214x_H) || defined(MACH_LPC21XX)
+ PINSEL1 &= ~0xC000C000;
+// PINSEL1 |= 0x40004000; /* Select USB Link, VBUS */
+ PINSEL1 |= 0x80000000; /* Select USB Link, VBUS */
+#endif /* MACH_LPC21XX */
+#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX) || defined(MACH_LPC178X)
+ /* 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
+#endif /* Known LPC MACH */
+#endif /*NEW_USB_PIN_CFG*/
+}
+
unsigned int lpc_ep2addr(unsigned int ep_num)
{
unsigned int val;
void lpc_usb_hw_init (void)
{
+ lpc_usb_configure_pins();
#if defined(INC_LPC214x_H) || defined(MACH_LPC21XX)
- PINSEL1 &= ~0xC000C000;
-// PINSEL1 |= 0x40004000; /* Select USB Link, VBUS */
- PINSEL1 |= 0x80000000; /* Select USB Link, VBUS */
-
PCONP |= 0x80000000; /* Turn On USB PCLK */
/* Configure 48MHz USB Clock; FOsc = 12MHz, M = 4, P = 2 */
USBDevIntEn = USBDevInt_DEV_STAT; /* Enable Device Status Interrupt */
#endif /* MACH_LPC21XX */
-#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX)
+#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX) || defined(MACH_LPC178X)
/**
** ** ATTENTION **
** USB clock (48MHz) should be set up externally before calling this fn
** 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 */
#endif /* MACH_LPC23XX */
+#if defined(MACH_LPC178X)
+// OTGStCtrl &= ~3;
+#endif
+
/* Partial Manual Reset since Automatic Bus Reset is not working */
lpc_usb_reset();
lpc_usb_set_addr(0);