|
|
|
|
|
|
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONSOLE_ENABLE |
|
|
|
|
|
static bool console_flush = false; |
|
|
|
|
|
#define CONSOLE_FLUSH_SET(b) do { \ |
|
|
|
|
|
uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \ |
|
|
|
|
|
} while (0) |
|
|
|
|
|
|
|
|
|
|
|
// called every 1ms |
|
|
void EVENT_USB_Device_StartOfFrame(void) |
|
|
void EVENT_USB_Device_StartOfFrame(void) |
|
|
{ |
|
|
{ |
|
|
|
|
|
static uint8_t count; |
|
|
|
|
|
if (++count % 50) return; |
|
|
|
|
|
count = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!console_flush) return; |
|
|
Console_Task(); |
|
|
Console_Task(); |
|
|
|
|
|
console_flush = false; |
|
|
} |
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
/** Event handler for the USB_ConfigurationChanged event. |
|
|
/** Event handler for the USB_ConfigurationChanged event. |
|
|
* This is fired when the host sets the current configuration of the USB device after enumeration. |
|
|
* This is fired when the host sets the current configuration of the USB device after enumeration. |
|
|
|
|
|
|
|
|
// Because sendchar() is called so many times, waiting each call causes big lag. |
|
|
// Because sendchar() is called so many times, waiting each call causes big lag. |
|
|
static bool timeouted = false; |
|
|
static bool timeouted = false; |
|
|
|
|
|
|
|
|
|
|
|
// prevents Console_Task() from running during sendchar() runs. |
|
|
|
|
|
// or char will be lost. These two function is mutually exclusive. |
|
|
|
|
|
CONSOLE_FLUSH_SET(false); |
|
|
|
|
|
|
|
|
if (USB_DeviceState != DEVICE_STATE_Configured) |
|
|
if (USB_DeviceState != DEVICE_STATE_Configured) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Endpoint_Write_8(c); |
|
|
Endpoint_Write_8(c); |
|
|
|
|
|
|
|
|
// send when bank is full |
|
|
// send when bank is full |
|
|
if (!Endpoint_IsReadWriteAllowed()) |
|
|
|
|
|
|
|
|
if (!Endpoint_IsReadWriteAllowed()) { |
|
|
|
|
|
while (!(Endpoint_IsINReady())); |
|
|
Endpoint_ClearIN(); |
|
|
Endpoint_ClearIN(); |
|
|
|
|
|
} else { |
|
|
|
|
|
CONSOLE_FLUSH_SET(true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Endpoint_SelectEndpoint(ep); |
|
|
Endpoint_SelectEndpoint(ep); |
|
|
return 0; |
|
|
return 0; |