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 | |
| 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')
| -rw-r--r-- | protocol/lufa.mk | 10 | ||||
| -rw-r--r-- | protocol/lufa/lufa.c | 96 | ||||
| -rw-r--r-- | protocol/lufa/lufa.h | 11 | ||||
| -rw-r--r-- | protocol/usb_hid.mk | 67 | ||||
| -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 |
18 files changed, 442 insertions, 259 deletions
diff --git a/protocol/lufa.mk b/protocol/lufa.mk index ad6cab6d3..bf6fc97b8 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk | |||
| @@ -1,18 +1,20 @@ | |||
| 1 | LUFA_DIR = protocol/lufa | 1 | LUFA_DIR = protocol/lufa |
| 2 | 2 | ||
| 3 | # Path to the LUFA library | 3 | # Path to the LUFA library |
| 4 | LUFA_PATH = $(TOP_DIR)/protocol/lufa/LUFA-120219 | 4 | LUFA_PATH = protocol/lufa/LUFA-120219 |
| 5 | 5 | ||
| 6 | # Create the LUFA source path variables by including the LUFA root makefile | 6 | # Create the LUFA source path variables by including the LUFA root makefile |
| 7 | include $(LUFA_PATH)/LUFA/makefile | 7 | include $(TOP_DIR)/$(LUFA_PATH)/LUFA/makefile |
| 8 | 8 | ||
| 9 | LUFA_SRC = $(LUFA_DIR)/lufa.c \ | 9 | LUFA_SRC = $(LUFA_DIR)/lufa.c \ |
| 10 | $(LUFA_DIR)/descriptor.c \ | 10 | $(LUFA_DIR)/descriptor.c \ |
| 11 | $(LUFA_SRC_USB) | 11 | $(LUFA_SRC_USB) |
| 12 | SRC += $(subst $(LUFA_PATH)/,,$(LUFA_SRC)) | 12 | |
| 13 | SRC += $(LUFA_SRC) | ||
| 13 | 14 | ||
| 14 | # Search Path | 15 | # Search Path |
| 15 | VPATH += $(LUFA_PATH) | 16 | VPATH += $(TOP_DIR)/$(LUFA_DIR) |
| 17 | VPATH += $(TOP_DIR)/$(LUFA_PATH) | ||
| 16 | 18 | ||
| 17 | # Option modules | 19 | # Option modules |
| 18 | #ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) | 20 | #ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) |
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index b7ecb8488..81409ce9e 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -59,7 +59,7 @@ static void send_keyboard(report_keyboard_t *report); | |||
| 59 | static void send_mouse(report_mouse_t *report); | 59 | static void send_mouse(report_mouse_t *report); |
| 60 | static void send_system(uint16_t data); | 60 | static void send_system(uint16_t data); |
| 61 | static void send_consumer(uint16_t data); | 61 | static void send_consumer(uint16_t data); |
| 62 | static host_driver_t lufa_driver = { | 62 | host_driver_t lufa_driver = { |
| 63 | keyboard_leds, | 63 | keyboard_leds, |
| 64 | send_keyboard, | 64 | send_keyboard, |
| 65 | send_mouse, | 65 | send_mouse, |
| @@ -68,49 +68,9 @@ static host_driver_t lufa_driver = { | |||
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | static void SetupHardware(void); | 71 | /******************************************************************************* |
| 72 | static void Console_Task(void); | 72 | * Console |
| 73 | 73 | ******************************************************************************/ | |
| 74 | int main(void) | ||
| 75 | { | ||
| 76 | SetupHardware(); | ||
| 77 | sei(); | ||
| 78 | |||
| 79 | print_enable = true; | ||
| 80 | debug_enable = true; | ||
| 81 | debug_matrix = true; | ||
| 82 | debug_keyboard = true; | ||
| 83 | debug_mouse = true; | ||
| 84 | |||
| 85 | // TODO: can't print here | ||
| 86 | debug("LUFA init\n"); | ||
| 87 | |||
| 88 | keyboard_init(); | ||
| 89 | host_set_driver(&lufa_driver); | ||
| 90 | while (1) { | ||
| 91 | keyboard_proc(); | ||
| 92 | |||
| 93 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | ||
| 94 | USB_USBTask(); | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | void SetupHardware(void) | ||
| 100 | { | ||
| 101 | /* Disable watchdog if enabled by bootloader/fuses */ | ||
| 102 | MCUSR &= ~(1 << WDRF); | ||
| 103 | wdt_disable(); | ||
| 104 | |||
| 105 | /* Disable clock division */ | ||
| 106 | clock_prescale_set(clock_div_1); | ||
| 107 | |||
| 108 | USB_Init(); | ||
| 109 | |||
| 110 | // for Console_Task | ||
| 111 | USB_Device_EnableSOFEvents(); | ||
| 112 | } | ||
| 113 | |||
| 114 | #ifdef CONSOLE_ENABLE | 74 | #ifdef CONSOLE_ENABLE |
| 115 | static void Console_Task(void) | 75 | static void Console_Task(void) |
| 116 | { | 76 | { |
| @@ -446,3 +406,51 @@ int8_t sendchar(uint8_t c) | |||
| 446 | return 0; | 406 | return 0; |
| 447 | } | 407 | } |
| 448 | #endif | 408 | #endif |
| 409 | |||
| 410 | |||
| 411 | /******************************************************************************* | ||
| 412 | * main | ||
| 413 | ******************************************************************************/ | ||
| 414 | static void SetupHardware(void) | ||
| 415 | { | ||
| 416 | /* Disable watchdog if enabled by bootloader/fuses */ | ||
| 417 | MCUSR &= ~(1 << WDRF); | ||
| 418 | wdt_disable(); | ||
| 419 | |||
| 420 | /* Disable clock division */ | ||
| 421 | clock_prescale_set(clock_div_1); | ||
| 422 | |||
| 423 | // Leonardo needs. Without this USB device is not recognized. | ||
| 424 | USB_Disable(); | ||
| 425 | |||
| 426 | USB_Init(); | ||
| 427 | |||
| 428 | // for Console_Task | ||
| 429 | USB_Device_EnableSOFEvents(); | ||
| 430 | } | ||
| 431 | |||
| 432 | int main(void) __attribute__ ((weak)); | ||
| 433 | int main(void) | ||
| 434 | { | ||
| 435 | SetupHardware(); | ||
| 436 | sei(); | ||
| 437 | |||
| 438 | print_enable = true; | ||
| 439 | debug_enable = true; | ||
| 440 | debug_matrix = true; | ||
| 441 | debug_keyboard = true; | ||
| 442 | debug_mouse = true; | ||
| 443 | |||
| 444 | // TODO: can't print here | ||
| 445 | debug("LUFA init\n"); | ||
| 446 | |||
| 447 | keyboard_init(); | ||
| 448 | host_set_driver(&lufa_driver); | ||
| 449 | while (1) { | ||
| 450 | keyboard_proc(); | ||
| 451 | |||
| 452 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | ||
| 453 | USB_USBTask(); | ||
| 454 | #endif | ||
| 455 | } | ||
| 456 | } | ||
diff --git a/protocol/lufa/lufa.h b/protocol/lufa/lufa.h index 71c279b0d..bcee060d6 100644 --- a/protocol/lufa/lufa.h +++ b/protocol/lufa/lufa.h | |||
| @@ -47,8 +47,19 @@ | |||
| 47 | #include <string.h> | 47 | #include <string.h> |
| 48 | #include <LUFA/Version.h> | 48 | #include <LUFA/Version.h> |
| 49 | #include <LUFA/Drivers/USB/USB.h> | 49 | #include <LUFA/Drivers/USB/USB.h> |
| 50 | #include "host.h" | ||
| 50 | 51 | ||
| 51 | 52 | ||
| 53 | #ifdef __cplusplus | ||
| 54 | extern "C" { | ||
| 55 | #endif | ||
| 56 | |||
| 57 | extern host_driver_t lufa_driver; | ||
| 58 | |||
| 59 | #ifdef __cplusplus | ||
| 60 | } | ||
| 61 | #endif | ||
| 62 | |||
| 52 | /* extra report structure */ | 63 | /* extra report structure */ |
| 53 | typedef struct { | 64 | typedef struct { |
| 54 | uint8_t report_id; | 65 | uint8_t report_id; |
diff --git a/protocol/usb_hid.mk b/protocol/usb_hid.mk new file mode 100644 index 000000000..f3149f7f4 --- /dev/null +++ b/protocol/usb_hid.mk | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | USB_HID_DIR = protocol/usb_hid | ||
| 2 | |||
| 3 | |||
| 4 | # | ||
| 5 | # USB Host Shield | ||
| 6 | # | ||
| 7 | USB_HOST_SHIELD_DIR = $(USB_HID_DIR)/USB_Host_Shield_2.0 | ||
| 8 | USB_HOST_SHIELD_SRC = \ | ||
| 9 | $(USB_HOST_SHIELD_DIR)/Usb.cpp \ | ||
| 10 | $(USB_HOST_SHIELD_DIR)/hid.cpp \ | ||
| 11 | $(USB_HOST_SHIELD_DIR)/parsetools.cpp \ | ||
| 12 | $(USB_HOST_SHIELD_DIR)/message.cpp | ||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | # | ||
| 17 | # Arduino | ||
| 18 | # | ||
| 19 | ARDUINO_DIR = $(USB_HID_DIR)/arduino-1.0.1 | ||
| 20 | ARDUINO_CORES_DIR = $(ARDUINO_DIR)/cores/arduino | ||
| 21 | ARDUINO_CORES_SRC = \ | ||
| 22 | $(ARDUINO_CORES_DIR)/Print.cpp \ | ||
| 23 | $(ARDUINO_CORES_DIR)/Stream.cpp | ||
| 24 | |||
| 25 | # replaced with override_Serial.c | ||
| 26 | # $(ARDUINO_CORES_DIR)/CDC.cpp \ | ||
| 27 | # $(ARDUINO_CORES_DIR)/HID.cpp \ | ||
| 28 | # $(ARDUINO_CORES_DIR)/USBCore.cpp \ | ||
| 29 | |||
| 30 | # replaced with override_wiring.c and common/timer.c | ||
| 31 | # $(ARDUINO_CORES_DIR)/wiring.c \ | ||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | # | ||
| 36 | # HID parser | ||
| 37 | # | ||
| 38 | SRC += $(USB_HID_DIR)/parser.cpp | ||
| 39 | |||
| 40 | # replace arduino/CDC.cpp | ||
| 41 | SRC += $(USB_HID_DIR)/override_Serial.cpp | ||
| 42 | |||
| 43 | # replace arduino/wiring.c | ||
| 44 | SRC += $(USB_HID_DIR)/override_wiring.c | ||
| 45 | SRC += common/timer.c | ||
| 46 | |||
| 47 | SRC += $(USB_HOST_SHIELD_SRC) | ||
| 48 | SRC += $(ARDUINO_CORES_SRC) | ||
| 49 | |||
| 50 | |||
| 51 | OPT_DEFS += -DARDUINO=101 | ||
| 52 | # Arduino USBCore needs USB_VID and USB_PID. | ||
| 53 | #OPT_DEFS += -DARDUINO=101 -DUSB_VID=0x2341 -DUSB_PID=0x8036 | ||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | # | ||
| 58 | # Search Path | ||
| 59 | # | ||
| 60 | VPATH += $(TOP_DIR)/$(USB_HID_DIR) | ||
| 61 | VPATH += $(TOP_DIR)/$(USB_HOST_SHIELD_DIR) | ||
| 62 | |||
| 63 | # for #include "Arduino.h" | ||
| 64 | VPATH += $(TOP_DIR)/$(ARDUINO_CORES_DIR) | ||
| 65 | |||
| 66 | # for #include "pins_arduino.h" | ||
| 67 | VPATH += $(TOP_DIR)/$(ARDUINO_DIR)/variants/leonardo | ||
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 | } | ||
