X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/e5e7eaee7af719cee00a8c2cb6fb4649dde0aa05..189d0c7e669b6a3d07ed35c1eaa0bfc8cbc7a729:/Bootloaders/TeensyHID/TeensyHID.c diff --git a/Bootloaders/TeensyHID/TeensyHID.c b/Bootloaders/TeensyHID/TeensyHID.c index e81c462a0..12d5c0de8 100644 --- a/Bootloaders/TeensyHID/TeensyHID.c +++ b/Bootloaders/TeensyHID/TeensyHID.c @@ -49,6 +49,27 @@ bool RunBootloader = true; */ int main(void) { + /* Setup hardware required for the bootloader */ + SetupHardware(); + + while (RunBootloader) + USB_USBTask(); + + /* Reset all configured hardware to their default states for the user app */ + ResetHardware(); + + /* Wait 100ms to give the host time to register the disconnection */ + _delay_ms(100); + + /* Enable the watchdog and force a timeout to reset the AVR */ + wdt_enable(WDTO_250MS); + + for (;;); +} + +/** Configures all hardware required for the bootloader. */ +void SetupHardware(void) +{ /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); @@ -62,26 +83,19 @@ int main(void) /* Initialize USB subsystem */ USB_Init(); - - while (RunBootloader) - USB_USBTask(); - - /* Shut down the USB interface, so that the host will register the disconnection */ - USB_ShutDown(); - - /* Wait 100ms to give the host time to register the disconnection */ - _delay_ms(100); +} - /* Enable the watchdog and force a timeout to reset the AVR */ - wdt_enable(WDTO_250MS); - - for (;;); +/** Resets all configured hardware required for the bootloader back to their original states. */ +void ResetHardware(void) +{ + /* Shut down the USB subsystem */ + USB_ShutDown(); } /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready * to relay data to and from the attached USB host. */ -EVENT_HANDLER(USB_ConfigurationChanged) +void EVENT_USB_ConfigurationChanged(void) { /* Setup HID Report Endpoint */ Endpoint_ConfigureEndpoint(HID_EPNUM, EP_TYPE_INTERRUPT, @@ -93,13 +107,13 @@ EVENT_HANDLER(USB_ConfigurationChanged) * control requests that are not handled internally by the USB library (including the HID commands, which are * all issued via the control endpoint), so that they can be handled appropriately for the application. */ -EVENT_HANDLER(USB_UnhandledControlPacket) +void EVENT_USB_UnhandledControlPacket(void) { /* Handle HID Class specific requests */ - switch (bRequest) + switch (USB_ControlRequest.bRequest) { case REQ_SetReport: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { Endpoint_ClearSETUP();