]> git.gir.st - tmk_keyboard.git/blob - pjrc/usb_extra.c
added protocol stack: pjrc, vusb
[tmk_keyboard.git] / pjrc / usb_extra.c
1 #include <avr/interrupt.h>
2 #include "usb_extra.h"
3
4
5 int8_t usb_extra_send(uint8_t report_id, uint8_t bits)
6 {
7 uint8_t intr_state, timeout;
8
9 if (!usb_configured()) return -1;
10 intr_state = SREG;
11 cli();
12 UENUM = EXTRA_ENDPOINT;
13 timeout = UDFNUML + 50;
14 while (1) {
15 // are we ready to transmit?
16 if (UEINTX & (1<<RWAL)) break;
17 SREG = intr_state;
18 // has the USB gone offline?
19 if (!usb_configured()) return -1;
20 // have we waited too long?
21 if (UDFNUML == timeout) return -1;
22 // get ready to try checking again
23 intr_state = SREG;
24 cli();
25 UENUM = EXTRA_ENDPOINT;
26 }
27
28 UEDATX = report_id;
29 UEDATX = bits;
30
31 UEINTX = 0x3A;
32 SREG = intr_state;
33 return 0;
34 }
35
36 int8_t usb_extra_audio_send(uint8_t bits)
37 {
38 return usb_extra_send(1, bits);
39 }
40
41 int8_t usb_extra_system_send(uint8_t bits)
42 {
43 return usb_extra_send(2, bits);
44 }
Imprint / Impressum