diff options
author | tmk <nobody@nowhere> | 2012-08-25 15:49:08 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2012-08-28 21:56:15 +0900 |
commit | c5060ea81942b0e3f8577536ff78402a19abe3d3 (patch) | |
tree | bcdd4cd269be3064982014b0afdc0aea628d7048 /protocol/usb_hid | |
parent | 9382bf2f765cfbb8f7a9a48157391cac2bb71780 (diff) | |
download | qmk_firmware-c5060ea81942b0e3f8577536ff78402a19abe3d3.tar.gz qmk_firmware-c5060ea81942b0e3f8577536ff78402a19abe3d3.zip |
test build of 'Host shield' in minimal env.
Diffstat (limited to 'protocol/usb_hid')
-rw-r--r-- | protocol/usb_hid/NullSerial.cpp | 44 | ||||
-rw-r--r-- | protocol/usb_hid/README | 19 | ||||
-rw-r--r-- | protocol/usb_hid/USBAPI.h | 22 | ||||
-rw-r--r-- | protocol/usb_hid/arduino-1.0.1/cores/arduino/USBDesc.h | 4 | ||||
-rw-r--r-- | protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring.c | 2 | ||||
-rw-r--r-- | protocol/usb_hid/leonardo_led.h | 10 | ||||
-rw-r--r-- | protocol/usb_hid/main.cpp | 66 | ||||
-rw-r--r-- | protocol/usb_hid/override_Serial.cpp | 51 | ||||
-rw-r--r-- | protocol/usb_hid/override_wiring.c | 28 | ||||
-rw-r--r-- | protocol/usb_hid/parser.cpp | 15 | ||||
-rw-r--r-- | protocol/usb_hid/parser.h | 5 | ||||
-rw-r--r-- | protocol/usb_hid/test/Makefile (renamed from protocol/usb_hid/Makefile) | 119 | ||||
-rw-r--r-- | protocol/usb_hid/test/config.h | 40 | ||||
-rw-r--r-- | protocol/usb_hid/test/test.cpp | 92 |
14 files changed, 306 insertions, 211 deletions
diff --git a/protocol/usb_hid/NullSerial.cpp b/protocol/usb_hid/NullSerial.cpp deleted file mode 100644 index 6d85caf2d..000000000 --- a/protocol/usb_hid/NullSerial.cpp +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #include "USBAPI.h" | ||
2 | |||
3 | |||
4 | void NullSerial::begin(uint16_t baud_count) | ||
5 | { | ||
6 | } | ||
7 | |||
8 | void NullSerial::end(void) | ||
9 | { | ||
10 | } | ||
11 | |||
12 | void NullSerial::accept(void) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | int NullSerial::available(void) | ||
17 | { | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | int NullSerial::peek(void) | ||
22 | { | ||
23 | return -1; | ||
24 | } | ||
25 | |||
26 | int NullSerial::read(void) | ||
27 | { | ||
28 | return -1; | ||
29 | } | ||
30 | |||
31 | void NullSerial::flush(void) | ||
32 | { | ||
33 | } | ||
34 | |||
35 | size_t NullSerial::write(uint8_t c) | ||
36 | { | ||
37 | return 1; | ||
38 | } | ||
39 | |||
40 | NullSerial::operator bool() { | ||
41 | return true; | ||
42 | } | ||
43 | |||
44 | NullSerial Serial; | ||
diff --git a/protocol/usb_hid/README b/protocol/usb_hid/README index 0acf677f8..9750a1cc8 100644 --- a/protocol/usb_hid/README +++ b/protocol/usb_hid/README | |||
@@ -1,3 +1,8 @@ | |||
1 | USB HID protocol | ||
2 | ================ | ||
3 | Host side of USB HID keyboard protocol implementation. | ||
4 | Only standard HID Boot mode is supported at this time. This means most of normal keyboards are supported while proprietary >6KRO and NKRO is not. | ||
5 | |||
1 | Third party Libraries | 6 | Third party Libraries |
2 | --------------------- | 7 | --------------------- |
3 | USB_Host_Shield_2.0 | 8 | USB_Host_Shield_2.0 |
@@ -7,3 +12,17 @@ USB_Host_Shield_2.0 | |||
7 | arduino-1.0.1 | 12 | arduino-1.0.1 |
8 | Arduino files copied from: | 13 | Arduino files copied from: |
9 | https://github.com/arduino/Arduino/hardware/arduino/{cores,variants} | 14 | https://github.com/arduino/Arduino/hardware/arduino/{cores,variants} |
15 | |||
16 | |||
17 | Test build | ||
18 | ---------- | ||
19 | In test directory; | ||
20 | $ make | ||
21 | $ DEV=/dev/ttyACM0 make program | ||
22 | |||
23 | You can see HID keyboard reports on debug output. | ||
24 | |||
25 | |||
26 | Restriction and Bug | ||
27 | ------------------- | ||
28 | Not statble yet. | ||
diff --git a/protocol/usb_hid/USBAPI.h b/protocol/usb_hid/USBAPI.h deleted file mode 100644 index e3390d49a..000000000 --- a/protocol/usb_hid/USBAPI.h +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | /* | ||
2 | * Override original arduino USBAPI.h. | ||
3 | */ | ||
4 | #include <stdint.h> | ||
5 | #include "Stream.h" | ||
6 | |||
7 | |||
8 | class NullSerial : public Stream | ||
9 | { | ||
10 | public: | ||
11 | void begin(uint16_t baud_count); | ||
12 | void end(void); | ||
13 | |||
14 | virtual int available(void); | ||
15 | virtual void accept(void); | ||
16 | virtual int peek(void); | ||
17 | virtual int read(void); | ||
18 | virtual void flush(void); | ||
19 | virtual size_t write(uint8_t); | ||
20 | operator bool(); | ||
21 | }; | ||
22 | extern NullSerial Serial; | ||
diff --git a/protocol/usb_hid/arduino-1.0.1/cores/arduino/USBDesc.h b/protocol/usb_hid/arduino-1.0.1/cores/arduino/USBDesc.h index 229a638c5..900713e0f 100644 --- a/protocol/usb_hid/arduino-1.0.1/cores/arduino/USBDesc.h +++ b/protocol/usb_hid/arduino-1.0.1/cores/arduino/USBDesc.h | |||
@@ -16,8 +16,8 @@ | |||
16 | ** SOFTWARE. | 16 | ** SOFTWARE. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | //#define CDC_ENABLED | 19 | #define CDC_ENABLED |
20 | //#define HID_ENABLED | 20 | #define HID_ENABLED |
21 | 21 | ||
22 | 22 | ||
23 | #ifdef CDC_ENABLED | 23 | #ifdef CDC_ENABLED |
diff --git a/protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring.c b/protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring.c index b1a4ce4b0..ac8bb6f9b 100644 --- a/protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring.c +++ b/protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring.c | |||
@@ -108,7 +108,6 @@ unsigned long micros() { | |||
108 | 108 | ||
109 | void delay(unsigned long ms) | 109 | void delay(unsigned long ms) |
110 | { | 110 | { |
111 | //PORTB &= ~(1<<0); | ||
112 | uint16_t start = (uint16_t)micros(); | 111 | uint16_t start = (uint16_t)micros(); |
113 | 112 | ||
114 | while (ms > 0) { | 113 | while (ms > 0) { |
@@ -117,7 +116,6 @@ void delay(unsigned long ms) | |||
117 | start += 1000; | 116 | start += 1000; |
118 | } | 117 | } |
119 | } | 118 | } |
120 | //PORTB |= (1<<0); | ||
121 | } | 119 | } |
122 | 120 | ||
123 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ | 121 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ |
diff --git a/protocol/usb_hid/leonardo_led.h b/protocol/usb_hid/leonardo_led.h new file mode 100644 index 000000000..6f67a88f5 --- /dev/null +++ b/protocol/usb_hid/leonardo_led.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef LEONARDO_LED_H | ||
2 | #define LEONARDO_LED_H | ||
3 | |||
4 | // Leonardo "TX" LED for debug | ||
5 | #define LED_TX_INIT (DDRD |= (1<<5)) | ||
6 | #define LED_TX_ON (PORTD &= ~(1<<5)) | ||
7 | #define LED_TX_OFF (PORTD |= (1<<5)) | ||
8 | #define LED_TX_TOGGLE (PORTD ^= (1<<5)) | ||
9 | |||
10 | #endif | ||
diff --git a/protocol/usb_hid/main.cpp b/protocol/usb_hid/main.cpp deleted file mode 100644 index c292d458e..000000000 --- a/protocol/usb_hid/main.cpp +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | #include <util/delay.h> | ||
2 | #include <Arduino.h> | ||
3 | #include "Usb.h" | ||
4 | #include "hid.h" | ||
5 | #include "hidboot.h" | ||
6 | #include "parser.h" | ||
7 | |||
8 | |||
9 | USB Usb; | ||
10 | HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&Usb); | ||
11 | KBDReportParser Prs; | ||
12 | |||
13 | void usb_disable() | ||
14 | { | ||
15 | USBCON &= ~(1<<VBUSTI); | ||
16 | UDIEN = 0; | ||
17 | USBINT = 0; | ||
18 | UDINT = 0; | ||
19 | UDCON |= (1<<DETACH); | ||
20 | USBCON &= ~(1<<USBE); | ||
21 | PLLCSR = 0; | ||
22 | UHWCON &= ~(1<<UVREGE); | ||
23 | USBCON &= ~(1<<OTGPADE); | ||
24 | } | ||
25 | |||
26 | void setup() | ||
27 | { | ||
28 | usb_disable(); | ||
29 | |||
30 | // RX LED for debug | ||
31 | DDRB |= (1<<0); | ||
32 | |||
33 | Serial.begin( 115200 ); | ||
34 | while (!Serial) ; | ||
35 | |||
36 | delay( 1000 ); | ||
37 | |||
38 | Serial.println("Start"); | ||
39 | |||
40 | if (Usb.Init() == -1) { | ||
41 | Serial.println("OSC did not start."); | ||
42 | } | ||
43 | |||
44 | delay( 200 ); | ||
45 | |||
46 | kbd.SetReportParser(0, (HIDReportParser*)&Prs); | ||
47 | } | ||
48 | |||
49 | void loop() | ||
50 | { | ||
51 | Usb.Task(); | ||
52 | } | ||
53 | |||
54 | int main(void) | ||
55 | { | ||
56 | // arduino/wiring.c(Timer initialize) | ||
57 | init(); | ||
58 | |||
59 | setup(); | ||
60 | |||
61 | for (;;) { | ||
62 | loop(); | ||
63 | } | ||
64 | |||
65 | return 0; | ||
66 | } | ||
diff --git a/protocol/usb_hid/override_Serial.cpp b/protocol/usb_hid/override_Serial.cpp new file mode 100644 index 000000000..e1755a5dc --- /dev/null +++ b/protocol/usb_hid/override_Serial.cpp | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Null implementation of Serial to dump debug print into blackhole | ||
3 | */ | ||
4 | #include "Arduino.h" | ||
5 | #include "sendchar.h" | ||
6 | |||
7 | #include "USBAPI.h" | ||
8 | |||
9 | |||
10 | void Serial_::begin(uint16_t baud_count) | ||
11 | { | ||
12 | } | ||
13 | |||
14 | void Serial_::end(void) | ||
15 | { | ||
16 | } | ||
17 | |||
18 | void Serial_::accept(void) | ||
19 | { | ||
20 | } | ||
21 | |||
22 | int Serial_::available(void) | ||
23 | { | ||
24 | return 0; | ||
25 | } | ||
26 | |||
27 | int Serial_::peek(void) | ||
28 | { | ||
29 | return -1; | ||
30 | } | ||
31 | |||
32 | int Serial_::read(void) | ||
33 | { | ||
34 | return -1; | ||
35 | } | ||
36 | |||
37 | void Serial_::flush(void) | ||
38 | { | ||
39 | } | ||
40 | |||
41 | size_t Serial_::write(uint8_t c) | ||
42 | { | ||
43 | sendchar(c); | ||
44 | return 1; | ||
45 | } | ||
46 | |||
47 | Serial_::operator bool() { | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | Serial_ Serial; | ||
diff --git a/protocol/usb_hid/override_wiring.c b/protocol/usb_hid/override_wiring.c new file mode 100644 index 000000000..a8c28dd89 --- /dev/null +++ b/protocol/usb_hid/override_wiring.c | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * To keep Timer0 for common/timer.c override arduino/wiring.c. | ||
3 | */ | ||
4 | #include <util/delay.h> | ||
5 | #include "common/timer.h" | ||
6 | #include "Arduino.h" | ||
7 | |||
8 | |||
9 | unsigned long millis() | ||
10 | { | ||
11 | return timer_read(); | ||
12 | } | ||
13 | unsigned long micros() | ||
14 | { | ||
15 | return timer_read() * 1000UL; | ||
16 | } | ||
17 | void delay(unsigned long ms) | ||
18 | { | ||
19 | _delay_ms(ms); | ||
20 | } | ||
21 | void delayMicroseconds(unsigned int us) | ||
22 | { | ||
23 | _delay_us(us); | ||
24 | } | ||
25 | void init() | ||
26 | { | ||
27 | timer_init(); | ||
28 | } | ||
diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp index cf6432230..b03af8ae4 100644 --- a/protocol/usb_hid/parser.cpp +++ b/protocol/usb_hid/parser.cpp | |||
@@ -1,15 +1,14 @@ | |||
1 | #include "parser.h" | 1 | #include "parser.h" |
2 | #include "leonardo_led.h" | ||
3 | #include "debug.h" | ||
2 | 4 | ||
3 | void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) | 5 | void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) |
4 | { | 6 | { |
5 | PORTB ^= (1<<0); | 7 | LED_TX_TOGGLE; |
6 | /* | 8 | debug("KBDReport: "); |
7 | Serial.print("KBDReport: "); | ||
8 | for (uint8_t i = 0; i < len; i++) { | 9 | for (uint8_t i = 0; i < len; i++) { |
9 | PrintHex<uint8_t>(buf[i]); | 10 | debug_hex(buf[i]); |
10 | Serial.print(" "); | 11 | debug(" "); |
11 | } | 12 | } |
12 | Serial.print("\r\n"); | 13 | debug("\r\n"); |
13 | */ | ||
14 | //PORTC &= ~(1<<7); | ||
15 | } | 14 | } |
diff --git a/protocol/usb_hid/parser.h b/protocol/usb_hid/parser.h index dc14c8270..703eb1ed4 100644 --- a/protocol/usb_hid/parser.h +++ b/protocol/usb_hid/parser.h | |||
@@ -1,3 +1,6 @@ | |||
1 | #ifndef PARSER_H | ||
2 | #define PARSER_H | ||
3 | |||
1 | #include "hid.h" | 4 | #include "hid.h" |
2 | 5 | ||
3 | class KBDReportParser : public HIDReportParser | 6 | class KBDReportParser : public HIDReportParser |
@@ -5,3 +8,5 @@ class KBDReportParser : public HIDReportParser | |||
5 | public: | 8 | public: |
6 | virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); | 9 | virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); |
7 | }; | 10 | }; |
11 | |||
12 | #endif | ||
diff --git a/protocol/usb_hid/Makefile b/protocol/usb_hid/test/Makefile index ed3d6518d..39f5de455 100644 --- a/protocol/usb_hid/Makefile +++ b/protocol/usb_hid/test/Makefile | |||
@@ -39,7 +39,9 @@ | |||
39 | #---------------------------------------------------------------------------- | 39 | #---------------------------------------------------------------------------- |
40 | 40 | ||
41 | # Target file name (without extension). | 41 | # Target file name (without extension). |
42 | TARGET = usbkbd | 42 | TARGET = usb_hid_test |
43 | |||
44 | TOP_DIR = ../../.. | ||
43 | 45 | ||
44 | # Directory keyboard dependent files exist | 46 | # Directory keyboard dependent files exist |
45 | TARGET_DIR = . | 47 | TARGET_DIR = . |
@@ -63,79 +65,62 @@ F_CPU = 16000000 | |||
63 | 65 | ||
64 | 66 | ||
65 | 67 | ||
68 | # | ||
69 | # LUFA specific | ||
70 | # | ||
71 | # Target architecture (see library "Board Types" documentation). | ||
72 | ARCH = AVR8 | ||
73 | # Input clock frequency. | ||
74 | # This will define a symbol, F_USB, in all source code files equal to the | ||
75 | # input clock frequency (before any prescaling is performed) in Hz. This value may | ||
76 | # differ from F_CPU if prescaling is used on the latter, and is required as the | ||
77 | # raw input clock is fed directly to the PLL sections of the AVR for high speed | ||
78 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' | ||
79 | # at the end, this will be done automatically to create a 32-bit value in your | ||
80 | # source code. | ||
81 | # | ||
82 | # If no clock division is performed on the input clock inside the AVR (via the | ||
83 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | ||
84 | F_USB = $(F_CPU) | ||
85 | # Interrupt driven control endpoint task | ||
86 | OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | ||
87 | |||
88 | |||
89 | |||
90 | # Build Options | ||
91 | # comment out to disable the options. | ||
92 | # | ||
93 | # Console for debug | ||
94 | OPT_DEFS += -DCONSOLE_ENABLE | ||
95 | |||
96 | # Boot Section Size in bytes | ||
97 | # Teensy halfKay 512 | ||
98 | # Atmel DFU loader 4096 | ||
99 | # LUFA bootloader 4096 | ||
100 | #OPT_DEFS += -DBOOT_SIZE=4096 | ||
101 | |||
102 | |||
103 | |||
104 | SRC = test.cpp | ||
105 | SRC += common/debug.c | ||
106 | SRC += common/print.c | ||
107 | |||
108 | CONFIG_H = config.h | ||
109 | |||
66 | 110 | ||
67 | ARDUINO_DIR = arduino-1.0.1/cores | ||
68 | ARDUINO_SRC = \ | ||
69 | arduino/Print.cpp \ | ||
70 | arduino/Stream.cpp \ | ||
71 | arduino/wiring.c | ||
72 | |||
73 | # arduino/main.cpp \ | ||
74 | # arduino/USBCore.cpp \ | ||
75 | # arduino/CDC.cpp \ | ||
76 | # arduino/HID.cpp \ | ||
77 | # arduino/HardwareSerial.cpp \ | ||
78 | # arduino/IPAddress.cpp \ | ||
79 | # arduino/Tone.cpp \ | ||
80 | # arduino/WMath.cpp \ | ||
81 | # arduino/WInterrupts.c \ | ||
82 | # arduino/wiring_analog.c \ | ||
83 | # arduino/wiring_pulse.c \ | ||
84 | # arduino/wiring_shift.c | ||
85 | # arduino/wiring_digital.c \ | ||
86 | # arduino/WString.cpp \ | ||
87 | # arduino/new.cpp \ | ||
88 | |||
89 | USB_HOST_DIR = ./USB_Host_Shield_2.0 | ||
90 | USB_HOST_SRC = \ | ||
91 | Usb.cpp \ | ||
92 | cdcacm.cpp \ | ||
93 | cdcftdi.cpp \ | ||
94 | cdcprolific.cpp \ | ||
95 | hid.cpp \ | ||
96 | hidboot.cpp \ | ||
97 | hiduniversal.cpp \ | ||
98 | hidusagetitlearrays.cpp \ | ||
99 | hidescriptorparser.cpp \ | ||
100 | message.cpp \ | ||
101 | parsetools.cpp | ||
102 | |||
103 | #PS3BT.cpp \ | ||
104 | #PS3USB.cpp \ | ||
105 | #RFCOMM.cpp \ | ||
106 | #XBOXUSB.cpp \ | ||
107 | #adk.cpp \ | ||
108 | #masstorage.cpp \ | ||
109 | #max_LCD.cpp \ | ||
110 | #usbhub.cpp | ||
111 | |||
112 | #SRC = host_kbd.cpp | ||
113 | SRC = main.cpp | ||
114 | SRC += parser.cpp | ||
115 | SRC += NullSerial.cpp | ||
116 | SRC += $(USB_HOST_SRC) | ||
117 | SRC += $(ARDUINO_SRC) | ||
118 | |||
119 | OPT_DEFS = -DARDUINO=101 -DUSB_VID=0x2341 -DUSB_PID=0x8036 | ||
120 | 111 | ||
121 | # Search Path | 112 | # Search Path |
122 | VPATH += $(TARGET_DIR) | 113 | VPATH += $(TARGET_DIR) |
123 | VPATH += $(USB_HOST_DIR) | 114 | VPATH += $(TOP_DIR) |
124 | VPATH += $(ARDUINO_DIR) | 115 | VPATH += $(TOP_DIR)/common |
125 | # for Arduino.h | ||
126 | VPATH += arduino-1.0.1/cores/arduino | ||
127 | # for pins_arduino.h | ||
128 | VPATH += arduino-1.0.1/variants/leonardo | ||
129 | 116 | ||
130 | 117 | ||
131 | # Ad hoc workaround to override original arduino/USBAPI.h with our own USBAPI.h. | ||
132 | # Obsolete but needed in order to remove directory including the current input file from search list. | ||
133 | # Option -iquote can't replace -I- for this purpose. | ||
134 | EXTRAFLAGS += -I- | ||
135 | |||
136 | 118 | ||
137 | # program Leonardo | 119 | # program Leonardo |
138 | PROGRAM_CMD = avrdude -patmega32u4 -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex | 120 | PROGRAM_CMD = avrdude -p$(MCU) -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex |
121 | |||
139 | 122 | ||
140 | 123 | ||
141 | include ../../rules.mk | 124 | include $(TOP_DIR)/protocol/usb_hid.mk |
125 | include $(TOP_DIR)/protocol/lufa.mk | ||
126 | include $(TOP_DIR)/rules.mk | ||
diff --git a/protocol/usb_hid/test/config.h b/protocol/usb_hid/test/config.h new file mode 100644 index 000000000..c2230fb57 --- /dev/null +++ b/protocol/usb_hid/test/config.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef CONFIG_H | ||
19 | #define CONFIG_H | ||
20 | |||
21 | |||
22 | #define VENDOR_ID 0xFEED | ||
23 | #define PRODUCT_ID 0xCAFE | ||
24 | #define DEVICE_VER 0x0814 | ||
25 | #define MANUFACTURER t.m.k. | ||
26 | #define PRODUCT USB to USB keyboard converter | ||
27 | |||
28 | |||
29 | #define DESCRIPTION Product from t.m.k. keyboard firmware project | ||
30 | |||
31 | |||
32 | /* matrix size */ | ||
33 | #define MATRIX_ROWS 32 | ||
34 | #define MATRIX_COLS 8 | ||
35 | |||
36 | |||
37 | /* key combination for command */ | ||
38 | #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) | ||
39 | |||
40 | #endif | ||
diff --git a/protocol/usb_hid/test/test.cpp b/protocol/usb_hid/test/test.cpp new file mode 100644 index 000000000..4958f0c61 --- /dev/null +++ b/protocol/usb_hid/test/test.cpp | |||
@@ -0,0 +1,92 @@ | |||
1 | #include <avr/io.h> | ||
2 | #include <avr/wdt.h> | ||
3 | #include <avr/power.h> | ||
4 | #include <util/delay.h> | ||
5 | #include <Arduino.h> | ||
6 | |||
7 | // USB HID host | ||
8 | #include "Usb.h" | ||
9 | #include "hid.h" | ||
10 | #include "hidboot.h" | ||
11 | #include "parser.h" | ||
12 | |||
13 | // LUFA | ||
14 | #include "lufa.h" | ||
15 | |||
16 | #include "debug.h" | ||
17 | |||
18 | #include "leonardo_led.h" | ||
19 | |||
20 | |||
21 | static USB usb_host; | ||
22 | static HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&usb_host); | ||
23 | static KBDReportParser kbd_parser; | ||
24 | |||
25 | static void LUFA_setup(void) | ||
26 | { | ||
27 | /* Disable watchdog if enabled by bootloader/fuses */ | ||
28 | MCUSR &= ~(1 << WDRF); | ||
29 | wdt_disable(); | ||
30 | |||
31 | /* Disable clock division */ | ||
32 | clock_prescale_set(clock_div_1); | ||
33 | |||
34 | // Leonardo needs. Without this USB device is not recognized. | ||
35 | USB_Disable(); | ||
36 | |||
37 | USB_Init(); | ||
38 | |||
39 | // for Console_Task | ||
40 | USB_Device_EnableSOFEvents(); | ||
41 | } | ||
42 | |||
43 | static void HID_setup() | ||
44 | { | ||
45 | // Arduino Timer startup: wiring.c | ||
46 | init(); | ||
47 | |||
48 | if (usb_host.Init() == -1) { | ||
49 | debug("HID init: failed\n"); | ||
50 | LED_TX_OFF; | ||
51 | } | ||
52 | |||
53 | _delay_ms(200); | ||
54 | |||
55 | kbd.SetReportParser(0, (HIDReportParser*)&kbd_parser); | ||
56 | } | ||
57 | |||
58 | int main(void) | ||
59 | { | ||
60 | // LED for debug | ||
61 | LED_TX_INIT; | ||
62 | LED_TX_ON; | ||
63 | |||
64 | print_enable = true; | ||
65 | debug_enable = true; | ||
66 | debug_matrix = true; | ||
67 | debug_keyboard = true; | ||
68 | debug_mouse = true; | ||
69 | |||
70 | LUFA_setup(); | ||
71 | sei(); | ||
72 | |||
73 | // wait for startup of sendchar routine | ||
74 | while (USB_DeviceState != DEVICE_STATE_Configured) ; | ||
75 | if (debug_enable) { | ||
76 | _delay_ms(1000); | ||
77 | } | ||
78 | |||
79 | HID_setup(); | ||
80 | |||
81 | debug("init: done\n"); | ||
82 | for (;;) { | ||
83 | usb_host.Task(); | ||
84 | |||
85 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | ||
86 | // LUFA Task for control request | ||
87 | USB_USBTask(); | ||
88 | #endif | ||
89 | } | ||
90 | |||
91 | return 0; | ||
92 | } | ||