serialPort_t *usbVcpOpen(void) { vcpPort_t *s; IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0); IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0); #if defined(STM32F4) usbGenerateDisconnectPulse(); switch (usbDevConfig()->type) { #ifdef USE_USB_CDC_HID case COMPOSITE: USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_CDC_cb, &USR_cb); break; #endif default: USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); break; } #elif defined(STM32F7) usbGenerateDisconnectPulse(); /* Init Device Library */ USBD_Init(&USBD_Device, &VCP_Desc, 0); /* Add Supported Class */ switch (usbDevConfig()->type) { #ifdef USE_USB_CDC_HID case COMPOSITE: USBD_RegisterClass(&USBD_Device, USBD_HID_CDC_CLASS); break; #endif default: USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS); break; } /* HID Interface doesn't have any callbacks... */ /* Add CDC Interface Class */ USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops); /* Start Device Process */ USBD_Start(&USBD_Device); #else Set_System(); Set_USBClock(); USB_Init(); USB_Interrupts_Config(); #endif s = &vcpPort; s->port.vTable = usbVTable; return (serialPort_t *)s; }
void buttonsHandleColdBootButtonPresses(void) { uint8_t secondsRemaining = 10; bool bothButtonsHeld; do { bothButtonsHeld = !digitalIn(BUTTON_A_PORT, BUTTON_A_PIN) && !digitalIn(BUTTON_B_PORT, BUTTON_B_PIN); if (bothButtonsHeld) { if (--secondsRemaining == 0) { resetEEPROM(); systemReset(); } if (secondsRemaining > 5) { delay(1000); } else { // flash quicker after a few seconds delay(500); LED0_TOGGLE; delay(500); } LED0_TOGGLE; } } while (bothButtonsHeld); // buttons released between 5 and 10 seconds if (secondsRemaining < 5) { usbGenerateDisconnectPulse(); flashLedsAndBeep(); systemResetToBootloader(); } }