diff options
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/usb_hid/Makefile | 141 | ||||
| -rw-r--r-- | protocol/usb_hid/NullSerial.cpp | 44 | ||||
| -rw-r--r-- | protocol/usb_hid/USBAPI.h | 22 | ||||
| -rw-r--r-- | protocol/usb_hid/main.cpp | 66 | ||||
| -rw-r--r-- | protocol/usb_hid/parser.cpp | 15 | ||||
| -rw-r--r-- | protocol/usb_hid/parser.h | 7 | 
6 files changed, 295 insertions, 0 deletions
diff --git a/protocol/usb_hid/Makefile b/protocol/usb_hid/Makefile new file mode 100644 index 000000000..ed3d6518d --- /dev/null +++ b/protocol/usb_hid/Makefile @@ -0,0 +1,141 @@ +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software. +# +# make clean = Clean out built project files. +# +# make coff = Convert ELF to AVR COFF. +# +# make extcoff = Convert ELF to AVR Extended COFF. +# +# make program = Download the hex file to the device. +#                Please customize your programmer settings(PROGRAM_CMD) +# +# make teensy = Download the hex file to the device, using teensy_loader_cli. +#               (must have teensy_loader_cli installed). +# +# make dfu = Download the hex file to the device, using dfu-programmer (must +#            have dfu-programmer installed). +# +# make flip = Download the hex file to the device, using Atmel FLIP (must +#             have Atmel FLIP installed). +# +# make dfu-ee = Download the eeprom file to the device, using dfu-programmer +#               (must have dfu-programmer installed). +# +# make flip-ee = Download the eeprom file to the device, using Atmel FLIP +#                (must have Atmel FLIP installed). +# +# make debug = Start either simulavr or avarice as specified for debugging,  +#              with avr-gdb or avr-insight as the front end for debugging. +# +# make filename.s = Just compile filename.c into the assembler code only. +# +# make filename.i = Create a preprocessed source file for use in submitting +#                   bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +# Target file name (without extension). +TARGET = usbkbd + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# MCU name +MCU = atmega32u4 + + +# Processor frequency. +#     This will define a symbol, F_CPU, in all source code files equal to the +#     processor frequency in Hz. You can then use this symbol in your source code to +#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done +#     automatically to create a 32-bit value in your source code. +# +#     This will be an integer division of F_USB below, as it is sourced by +#     F_USB after it has run through any CPU prescalers. Note that this value +#     does not *change* the processor frequency - it should merely be updated to +#     reflect the processor speed set externally so that the code can use accurate +#     software delays. +F_CPU = 16000000 + + + + +ARDUINO_DIR = arduino-1.0.1/cores +ARDUINO_SRC = \ +	arduino/Print.cpp \ +	arduino/Stream.cpp \ +	arduino/wiring.c + +#	arduino/main.cpp \ +#	arduino/USBCore.cpp \ +#	arduino/CDC.cpp \ +#	arduino/HID.cpp \ +#	arduino/HardwareSerial.cpp \ +#	arduino/IPAddress.cpp \ +#	arduino/Tone.cpp \ +#	arduino/WMath.cpp \ +#	arduino/WInterrupts.c \ +#	arduino/wiring_analog.c \ +#	arduino/wiring_pulse.c \ +#	arduino/wiring_shift.c +#	arduino/wiring_digital.c \ +#	arduino/WString.cpp \ +#	arduino/new.cpp \ + +USB_HOST_DIR = ./USB_Host_Shield_2.0 +USB_HOST_SRC = \ +	Usb.cpp \ +	cdcacm.cpp \ +	cdcftdi.cpp \ +	cdcprolific.cpp \ +	hid.cpp \ +	hidboot.cpp \ +	hiduniversal.cpp \ +	hidusagetitlearrays.cpp \ +	hidescriptorparser.cpp \ +	message.cpp \ +	parsetools.cpp + +	#PS3BT.cpp \ +	#PS3USB.cpp \ +	#RFCOMM.cpp \ +	#XBOXUSB.cpp \ +	#adk.cpp \ +	#masstorage.cpp \ +	#max_LCD.cpp \ +	#usbhub.cpp + +#SRC =  host_kbd.cpp +SRC =  main.cpp +SRC +=  parser.cpp +SRC +=  NullSerial.cpp +SRC += $(USB_HOST_SRC) +SRC += $(ARDUINO_SRC) + +OPT_DEFS = -DARDUINO=101 -DUSB_VID=0x2341 -DUSB_PID=0x8036 + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(USB_HOST_DIR) +VPATH += $(ARDUINO_DIR) +# for Arduino.h +VPATH += arduino-1.0.1/cores/arduino +# for pins_arduino.h +VPATH += arduino-1.0.1/variants/leonardo + + +# Ad hoc workaround to override original arduino/USBAPI.h with our own USBAPI.h. +# Obsolete but needed in order to remove directory including the current input file from search list. +# Option -iquote can't replace -I- for this purpose. +EXTRAFLAGS += -I- + + +# program Leonardo +PROGRAM_CMD = avrdude -patmega32u4 -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex + + +include ../../rules.mk diff --git a/protocol/usb_hid/NullSerial.cpp b/protocol/usb_hid/NullSerial.cpp new file mode 100644 index 000000000..6d85caf2d --- /dev/null +++ b/protocol/usb_hid/NullSerial.cpp @@ -0,0 +1,44 @@ +#include "USBAPI.h" + + +void NullSerial::begin(uint16_t baud_count) +{ +} + +void NullSerial::end(void) +{ +} + +void NullSerial::accept(void) +{ +} + +int NullSerial::available(void) +{ +    return 0; +} + +int NullSerial::peek(void) +{ +    return -1; +} + +int NullSerial::read(void) +{ +    return -1; +} + +void NullSerial::flush(void) +{ +} + +size_t NullSerial::write(uint8_t c) +{ +    return 1; +} + +NullSerial::operator bool() { +    return true; +} + +NullSerial Serial; diff --git a/protocol/usb_hid/USBAPI.h b/protocol/usb_hid/USBAPI.h new file mode 100644 index 000000000..e3390d49a --- /dev/null +++ b/protocol/usb_hid/USBAPI.h @@ -0,0 +1,22 @@ +/* + * Override original arduino USBAPI.h. + */ +#include <stdint.h> +#include "Stream.h" + + +class NullSerial : public Stream +{ +public: +	void begin(uint16_t baud_count); +	void end(void); + +	virtual int available(void); +	virtual void accept(void); +	virtual int peek(void); +	virtual int read(void); +	virtual void flush(void); +	virtual size_t write(uint8_t); +	operator bool(); +}; +extern NullSerial Serial; diff --git a/protocol/usb_hid/main.cpp b/protocol/usb_hid/main.cpp new file mode 100644 index 000000000..c292d458e --- /dev/null +++ b/protocol/usb_hid/main.cpp @@ -0,0 +1,66 @@ +#include <util/delay.h> +#include <Arduino.h> +#include "Usb.h" +#include "hid.h" +#include "hidboot.h" +#include "parser.h" + + +USB     Usb; +HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd(&Usb); +KBDReportParser Prs; + +void usb_disable() +{ +    USBCON &= ~(1<<VBUSTI); +    UDIEN = 0; +    USBINT = 0; +    UDINT = 0; +    UDCON |= (1<<DETACH); +    USBCON &= ~(1<<USBE); +    PLLCSR = 0; +    UHWCON &= ~(1<<UVREGE); +    USBCON &= ~(1<<OTGPADE); +} + +void setup() +{ +    usb_disable(); + +    // RX LED for debug +    DDRB |= (1<<0); + +    Serial.begin( 115200 ); +    while (!Serial) ; + +    delay( 1000 ); + +    Serial.println("Start"); + +    if (Usb.Init() == -1) { +        Serial.println("OSC did not start."); +    } +       +    delay( 200 ); +   +    kbd.SetReportParser(0, (HIDReportParser*)&Prs); +} + +void loop() +{ +    Usb.Task(); +} + +int main(void) +{ +    // arduino/wiring.c(Timer initialize) +    init(); + +    setup(); +     +    for (;;) { +        loop(); +    } +         +    return 0; +} diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp new file mode 100644 index 000000000..cf6432230 --- /dev/null +++ b/protocol/usb_hid/parser.cpp @@ -0,0 +1,15 @@ +#include "parser.h" + +void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) +{ +    PORTB ^= (1<<0); +/* +    Serial.print("KBDReport: "); +    for (uint8_t i = 0; i < len; i++) { +        PrintHex<uint8_t>(buf[i]); +        Serial.print(" "); +    } +    Serial.print("\r\n"); +*/ +    //PORTC &= ~(1<<7); +} diff --git a/protocol/usb_hid/parser.h b/protocol/usb_hid/parser.h new file mode 100644 index 000000000..dc14c8270 --- /dev/null +++ b/protocol/usb_hid/parser.h @@ -0,0 +1,7 @@ +#include "hid.h" + +class KBDReportParser : public HIDReportParser +{ +public: +	virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); +};  | 
