diff options
Diffstat (limited to 'usb_extra.c')
| -rw-r--r-- | usb_extra.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/usb_extra.c b/usb_extra.c new file mode 100644 index 000000000..94c317d98 --- /dev/null +++ b/usb_extra.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #include <avr/interrupt.h> | ||
| 2 | #include "usb_extra.h" | ||
| 3 | |||
| 4 | int8_t usb_extra_send(uint8_t bits) | ||
| 5 | { | ||
| 6 | uint8_t intr_state, timeout; | ||
| 7 | |||
| 8 | if (!usb_configured()) return -1; | ||
| 9 | intr_state = SREG; | ||
| 10 | cli(); | ||
| 11 | UENUM = EXTRA_ENDPOINT; | ||
| 12 | timeout = UDFNUML + 50; | ||
| 13 | while (1) { | ||
| 14 | // are we ready to transmit? | ||
| 15 | if (UEINTX & (1<<RWAL)) break; | ||
| 16 | SREG = intr_state; | ||
| 17 | // has the USB gone offline? | ||
| 18 | if (!usb_configured()) return -1; | ||
| 19 | // have we waited too long? | ||
| 20 | if (UDFNUML == timeout) return -1; | ||
| 21 | // get ready to try checking again | ||
| 22 | intr_state = SREG; | ||
| 23 | cli(); | ||
| 24 | UENUM = EXTRA_ENDPOINT; | ||
| 25 | } | ||
| 26 | |||
| 27 | UEDATX = 1; // report id | ||
| 28 | UEDATX = bits; | ||
| 29 | |||
| 30 | UEINTX = 0x3A; | ||
| 31 | SREG = intr_state; | ||
| 32 | return 0; | ||
| 33 | } | ||
