able to get connect status change interrupt occured

This commit is contained in:
hathach
2013-12-13 12:26:37 +07:00
parent 51b6c6ff41
commit 30c8f68930
7 changed files with 133 additions and 22 deletions

View File

@@ -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-
// LPC_PINCON->PINSEL3 &= ~(3<<6); TODO HOST
// LPC_PINCON->PINSEL3 |= (2<<6);
#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
//------------- Device -------------//
LPC_PINCON->PINSEL4 &= ~(3 << 18);
LPC_PINCON->PINSEL4 |= (1 << 18); // P2_9 as USB Connect
LPC_USB->USBClkCtrl = USBCLK_HOST;
while ((LPC_USB->USBClkSt & USBCLK_HOST) != USBCLK_HOST);
LPC_USB->OTGStCtrl = 0x3;
#endif
#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;
}