summaryrefslogtreecommitdiff
path: root/tinyusb/hal
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-12-13 12:26:37 +0700
committerhathach <[email protected]>2013-12-13 12:26:37 +0700
commit30c8f68930880903fe6210fc8247d9350c630d95 (patch)
tree25338f4d69cd6ddb5403947f39829ae2fc2e5cee /tinyusb/hal
parent51b6c6ff41e17560ae054298e68762298d0f5d7c (diff)
able to get connect status change interrupt occured
Diffstat (limited to 'tinyusb/hal')
-rw-r--r--tinyusb/hal/hal_lpc175x_6x.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/tinyusb/hal/hal_lpc175x_6x.c b/tinyusb/hal/hal_lpc175x_6x.c
index 60b66a5e4..5398e9307 100644
--- a/tinyusb/hal/hal_lpc175x_6x.c
+++ b/tinyusb/hal/hal_lpc175x_6x.c
@@ -51,18 +51,30 @@
//--------------------------------------------------------------------+
tusb_error_t hal_init(void)
{
- LPC_SC->PCONP |= CLKPWR_PCONP_PCUSB; /* USB PCLK -> enable USB Per.*/
+ enum {
+ USBCLK_DEVCIE = 0x12, // AHB + Device
+ USBCLK_HOST = 0x19 // AHB + Host + OTG (!)
+ };
+
+ LPC_SC->PCONP |= CLKPWR_PCONP_PCUSB; // enable USB Peripherals
//------------- user manual 11.13 usb device controller initialization -------------//
- LPC_PINCON->PINSEL1 &= ~((3<<26)|(3<<28)); /* P0.29 D+, P0.30 D- */
- LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); /* PINSEL1 26.27, 28.29 = 01 */
+ LPC_PINCON->PINSEL1 = bit_set_range(LPC_PINCON->PINSEL1, 26, 27, BIN8(01)); // P0.29 as D+
+ LPC_PINCON->PINSEL1 = bit_set_range(LPC_PINCON->PINSEL1, 28, 29, BIN8(01)); // P0.30 as D-
+
+#if MODE_HOST_SUPPORTED
+ LPC_PINCON->PINSEL3 = bit_set_range(LPC_PINCON->PINSEL3, 12, 23, BIN8(10)); // P1.22 as USB_PWRD
+// PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 1, .Pinnum = 22,
+// .Funcnum = 2, .Pinmode = PINSEL_PINMODE_PULLUP} );
+ LPC_PINCON->PINSEL3 = bit_set_range(LPC_PINCON->PINSEL3, 6, 7, BIN8(10)); // P1.19 as USB_PPWR
-// LPC_PINCON->PINSEL3 &= ~(3<<6); TODO HOST
-// LPC_PINCON->PINSEL3 |= (2<<6);
+ LPC_USB->USBClkCtrl = USBCLK_HOST;
+ while ((LPC_USB->USBClkSt & USBCLK_HOST) != USBCLK_HOST);
+ LPC_USB->OTGStCtrl = 0x3;
+#endif
- //------------- Device -------------//
- LPC_PINCON->PINSEL4 &= ~(3 << 18);
- LPC_PINCON->PINSEL4 |= (1 << 18); // P2_9 as USB Connect
+#if MODE_DEVICE_SUPPORTED
+ LPC_PINCON->PINSEL4 = bit_set_range(LPC_PINCON->PINSEL4, 18, 19, BIN8(01)); // P2_9 as USB Connect
// P1_30 as VBUS, ignore if it is already in VBUS mode
if ( !(!BIT_TEST_(LPC_PINCON->PINSEL3, 28) && BIT_TEST_(LPC_PINCON->PINSEL3, 29)) )
@@ -74,8 +86,9 @@ tusb_error_t hal_init(void)
.Funcnum = 2, .Pinmode = PINSEL_PINMODE_PULLDOWN} );
}
- LPC_USB->USBClkCtrl = 0x12; /* Dev, PortSel, AHB clock enable */
- while ((LPC_USB->USBClkSt & 0x12) != 0x12);
+ LPC_USB->USBClkCtrl = USBCLK_DEVCIE;
+ while ((LPC_USB->USBClkSt & USBCLK_DEVCIE) != USBCLK_DEVCIE);
+#endif
return TUSB_ERROR_NONE;
}