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