@@ -197,10 +197,24 @@ void EVENT_USB_Device_WakeUp()
197
197
#endif
198
198
}
199
199
200
+ #ifdef CONSOLE_ENABLE
201
+ static bool console_flush = false;
202
+ #define CONSOLE_FLUSH_SET (b ) do { \
203
+ uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \
204
+ } while (0)
205
+
206
+ // called every 1ms
200
207
void EVENT_USB_Device_StartOfFrame (void )
201
208
{
209
+ static uint8_t count ;
210
+ if (++ count % 50 ) return ;
211
+ count = 0 ;
212
+
213
+ if (!console_flush ) return ;
202
214
Console_Task ();
215
+ console_flush = false;
203
216
}
217
+ #endif
204
218
205
219
/** Event handler for the USB_ConfigurationChanged event.
206
220
* This is fired when the host sets the current configuration of the USB device after enumeration.
@@ -491,6 +505,10 @@ int8_t sendchar(uint8_t c)
491
505
// Because sendchar() is called so many times, waiting each call causes big lag.
492
506
static bool timeouted = false;
493
507
508
+ // prevents Console_Task() from running during sendchar() runs.
509
+ // or char will be lost. These two function is mutually exclusive.
510
+ CONSOLE_FLUSH_SET (false);
511
+
494
512
if (USB_DeviceState != DEVICE_STATE_Configured )
495
513
return -1 ;
496
514
@@ -524,8 +542,12 @@ int8_t sendchar(uint8_t c)
524
542
Endpoint_Write_8 (c );
525
543
526
544
// send when bank is full
527
- if (!Endpoint_IsReadWriteAllowed ())
545
+ if (!Endpoint_IsReadWriteAllowed ()) {
546
+ while (!(Endpoint_IsINReady ()));
528
547
Endpoint_ClearIN ();
548
+ } else {
549
+ CONSOLE_FLUSH_SET (true);
550
+ }
529
551
530
552
Endpoint_SelectEndpoint (ep );
531
553
return 0 ;
0 commit comments