aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocol/usb_hid/Makefile141
-rw-r--r--protocol/usb_hid/NullSerial.cpp44
-rw-r--r--protocol/usb_hid/USBAPI.h22
-rw-r--r--protocol/usb_hid/main.cpp66
-rw-r--r--protocol/usb_hid/parser.cpp15
-rw-r--r--protocol/usb_hid/parser.h7
-rw-r--r--rules.mk5
7 files changed, 300 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 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = usbkbd
43
44# Directory keyboard dependent files exist
45TARGET_DIR = .
46
47# MCU name
48MCU = atmega32u4
49
50
51# Processor frequency.
52# This will define a symbol, F_CPU, in all source code files equal to the
53# processor frequency in Hz. You can then use this symbol in your source code to
54# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
55# automatically to create a 32-bit value in your source code.
56#
57# This will be an integer division of F_USB below, as it is sourced by
58# F_USB after it has run through any CPU prescalers. Note that this value
59# does not *change* the processor frequency - it should merely be updated to
60# reflect the processor speed set externally so that the code can use accurate
61# software delays.
62F_CPU = 16000000
63
64
65
66
67ARDUINO_DIR = arduino-1.0.1/cores
68ARDUINO_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
89USB_HOST_DIR = ./USB_Host_Shield_2.0
90USB_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
113SRC = main.cpp
114SRC += parser.cpp
115SRC += NullSerial.cpp
116SRC += $(USB_HOST_SRC)
117SRC += $(ARDUINO_SRC)
118
119OPT_DEFS = -DARDUINO=101 -DUSB_VID=0x2341 -DUSB_PID=0x8036
120
121# Search Path
122VPATH += $(TARGET_DIR)
123VPATH += $(USB_HOST_DIR)
124VPATH += $(ARDUINO_DIR)
125# for Arduino.h
126VPATH += arduino-1.0.1/cores/arduino
127# for pins_arduino.h
128VPATH += arduino-1.0.1/variants/leonardo
129
130
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.
134EXTRAFLAGS += -I-
135
136
137# program Leonardo
138PROGRAM_CMD = avrdude -patmega32u4 -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex
139
140
141include ../../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 @@
1#include "USBAPI.h"
2
3
4void NullSerial::begin(uint16_t baud_count)
5{
6}
7
8void NullSerial::end(void)
9{
10}
11
12void NullSerial::accept(void)
13{
14}
15
16int NullSerial::available(void)
17{
18 return 0;
19}
20
21int NullSerial::peek(void)
22{
23 return -1;
24}
25
26int NullSerial::read(void)
27{
28 return -1;
29}
30
31void NullSerial::flush(void)
32{
33}
34
35size_t NullSerial::write(uint8_t c)
36{
37 return 1;
38}
39
40NullSerial::operator bool() {
41 return true;
42}
43
44NullSerial 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 @@
1/*
2 * Override original arduino USBAPI.h.
3 */
4#include <stdint.h>
5#include "Stream.h"
6
7
8class NullSerial : public Stream
9{
10public:
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};
22extern 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 @@
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
9USB Usb;
10HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&Usb);
11KBDReportParser Prs;
12
13void 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
26void 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
49void loop()
50{
51 Usb.Task();
52}
53
54int 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/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 @@
1#include "parser.h"
2
3void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
4{
5 PORTB ^= (1<<0);
6/*
7 Serial.print("KBDReport: ");
8 for (uint8_t i = 0; i < len; i++) {
9 PrintHex<uint8_t>(buf[i]);
10 Serial.print(" ");
11 }
12 Serial.print("\r\n");
13*/
14 //PORTC &= ~(1<<7);
15}
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 @@
1#include "hid.h"
2
3class KBDReportParser : public HIDReportParser
4{
5public:
6 virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
7};
diff --git a/rules.mk b/rules.mk
index e561eae63..02f07fd6f 100644
--- a/rules.mk
+++ b/rules.mk
@@ -158,6 +158,10 @@ CPPFLAGS += -funsigned-bitfields
158CPPFLAGS += -fpack-struct 158CPPFLAGS += -fpack-struct
159CPPFLAGS += -fshort-enums 159CPPFLAGS += -fshort-enums
160CPPFLAGS += -fno-exceptions 160CPPFLAGS += -fno-exceptions
161CPPFLAGS += -ffunction-sections
162CPPFLAGS += -fdata-sections
163# to supress "warning: only initialized variables can be placed into program memory area"
164CPPFLAGS += -w
161CPPFLAGS += -Wall 165CPPFLAGS += -Wall
162CPPFLAGS += -Wundef 166CPPFLAGS += -Wundef
163#CPPFLAGS += -mshort-calls 167#CPPFLAGS += -mshort-calls
@@ -541,6 +545,7 @@ $(OBJDIR)/%.o : %.c
541# Compile: create object files from C++ source files. 545# Compile: create object files from C++ source files.
542$(OBJDIR)/%.o : %.cpp 546$(OBJDIR)/%.o : %.cpp
543 @echo 547 @echo
548 mkdir -p $(@D)
544 @echo $(MSG_COMPILING_CPP) $< 549 @echo $(MSG_COMPILING_CPP) $<
545 $(CC) -c $(ALL_CPPFLAGS) $< -o $@ 550 $(CC) -c $(ALL_CPPFLAGS) $< -o $@
546 551