]>
git.gir.st - tmk_keyboard.git/blob - pjrc/usb_debug.c
1 #include <avr/interrupt.h>
6 // the time remaining before we transmit any partially full
7 // packet, or send a zero length packet.
8 volatile uint8_t debug_flush_timer
=0;
11 int8_t sendchar(uint8_t c
)
13 static uint8_t previous_timeout
=0;
14 uint8_t timeout
, intr_state
;
16 // if we're not online (enumerated and configured), error
17 if (!usb_configured()) return -1;
18 // interrupts are disabled so these functions can be
19 // used from the main program or interrupt context,
20 // even both in the same program!
23 UENUM
= DEBUG_TX_ENDPOINT
;
24 // if we gave up due to timeout before, don't wait again
25 if (previous_timeout
) {
26 if (!(UEINTX
& (1<<RWAL
))) {
32 // wait for the FIFO to be ready to accept data
33 timeout
= UDFNUML
+ 4;
35 // are we ready to transmit?
36 if (UEINTX
& (1<<RWAL
)) break;
38 // have we waited too long?
39 if (UDFNUML
== timeout
) {
43 // has the USB gone offline?
44 if (!usb_configured()) return -1;
45 // get ready to try checking again
48 UENUM
= DEBUG_TX_ENDPOINT
;
50 // actually write the byte into the FIFO
52 // if this completed a packet, transmit it now!
53 if (!(UEINTX
& (1<<RWAL
))) {
55 debug_flush_timer
= 0;
57 debug_flush_timer
= 2;
63 // immediately transmit any buffered output.
64 void usb_debug_flush_output(void)
70 if (debug_flush_timer
) {
71 UENUM
= DEBUG_TX_ENDPOINT
;
72 while ((UEINTX
& (1<<RWAL
))) {
76 debug_flush_timer
= 0;