/* Main program entry point. This routine configures the hardware required by the application, then enters a loop to run the application tasks in sequence.  */
int main(void)
/* Main program entry point. This routine configures the hardware required by the application, then enters a loop to run the application tasks in sequence.  */
int main(void)
{
	SetupHardware();
	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();
	while (RunBootloader)
	{
		uint8_t BytesReceived = PRNT_Device_BytesReceived(&TextOnly_Printer_Interface);
		if (BytesReceived)
		{
			LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
			while (BytesReceived--)
			{
				int16_t ReceivedByte = PRNT_Device_ReceiveByte(&TextOnly_Printer_Interface);
				ParseIntelHEXByte(ReceivedByte);
			}
			LEDs_SetAllLEDs(LEDMASK_USB_READY);
		}
		PRNT_Device_USBTask(&TextOnly_Printer_Interface);
		USB_USBTask();
	}
	_delay_us(1000);
	USB_Detach();
	MagicBootKey = MAGIC_BOOT_KEY;
	wdt_enable(WDTO_250MS);
	for (;;);
}