I am trying to understand 32U4 USB core code in Arduino IDE 1.6.5-r5 with atmel's doc on 32u4.
In USBCore.cpp:
void USBDevice_::attach()
{
_usbConfiguration = 0;
UHWCON = 0x01; // power internal reg
USBCON = (1<<USBE)|(1<<FRZCLK); // clock frozen, usb enabled
#if F_CPU == 16000000UL
PLLCSR = 0x12; // Need 16 MHz xtal
#elif F_CPU == 8000000UL
PLLCSR = 0x02; // Need 8 MHz xtal
#endif
while (!(PLLCSR & (1<<PLOCK))) // wait for lock pll
;
// Some tests on specific versions of macosx (10.7.3), reported some
// strange behaviuors when the board is reset using the serial
// port touch at 1200 bps. This delay fixes this behaviour.
delay(1);
USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
UDIEN = (1<<EORSTE)|(1<<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
UDCON = 0; // enable attach resistor
TX_RX_LED_INIT;
}
void USBDevice_::detach()
{
}
As you can see, there is no code in detach(). How would I detach then? Going back to atmel doc? This reminds me when arduino IDE has only .begin() for so many things but not a single .end() to complete the loop. Are we looking at this again, all assuming best-case scenario? Thanks.
As far as my studies, I know that one should reset USEN bit in USBCON but that's probably not enough for detach.