summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2012-09-04 14:24:52 +0900
committertmk <nobody@nowhere>2012-09-04 14:24:52 +0900
commitdc79a8521946a3a2e5b86945b8043b87a8b8d78c (patch)
tree737827112555c00a7f2ebbb88e61079c460be71a
parent7350b7c6aa300a234244c264b10d1732803c27df (diff)
parent232ab308e358e41f3253d66fa009c1ebca0951a2 (diff)
Merge branch 'usb_hid'
-rw-r--r--.gitmodules3
-rw-r--r--common.mk1
-rw-r--r--common/debug.c9
-rw-r--r--common/debug.h19
-rw-r--r--common/host.h8
-rw-r--r--common/keyboard.h6
-rw-r--r--common/print.h13
-rw-r--r--common/report.h9
-rw-r--r--common/sendchar.h8
-rw-r--r--common/timer.c34
-rw-r--r--common/timer.h24
-rw-r--r--common/usb_keycodes.h1
-rw-r--r--converter/usb_usb/Makefile130
-rw-r--r--converter/usb_usb/config.h40
-rw-r--r--converter/usb_usb/keymap.c251
-rw-r--r--converter/usb_usb/led.c24
-rw-r--r--converter/usb_usb/main.cpp107
-rw-r--r--converter/usb_usb/matrix.c133
-rw-r--r--keyboard/hbkb/Makefile.pjrc56
-rw-r--r--protocol/lufa.mk10
-rw-r--r--protocol/lufa/lufa.c96
-rw-r--r--protocol/lufa/lufa.h11
-rw-r--r--protocol/pjrc/main.c6
-rw-r--r--protocol/usb_hid.mk73
-rwxr-xr-xprotocol/usb_hid/README46
m---------protocol/usb_hid/USB_Host_Shield_2.00
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Arduino.h215
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/CDC.cpp233
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Client.h26
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/HID.cpp520
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/HardwareSerial.cpp428
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/HardwareSerial.h81
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/IPAddress.cpp56
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/IPAddress.h76
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Platform.h23
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Print.cpp263
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Print.h78
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Printable.h40
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Server.h9
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Stream.cpp270
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Stream.h96
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Tone.cpp601
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/USBAPI.h195
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/USBCore.cpp672
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/USBCore.h303
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/USBDesc.h63
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/Udp.h88
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WCharacter.h168
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WInterrupts.c298
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WMath.cpp60
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.cpp645
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h205
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/binary.h515
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/main.cpp20
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/new.cpp18
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/new.h22
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring.c324
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring_analog.c282
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring_digital.c178
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring_private.h69
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring_pulse.c69
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/wiring_shift.c55
-rw-r--r--protocol/usb_hid/arduino-1.0.1/variants/eightanaloginputs/pins_arduino.h27
-rw-r--r--protocol/usb_hid/arduino-1.0.1/variants/leonardo/pins_arduino.h256
-rw-r--r--protocol/usb_hid/arduino-1.0.1/variants/mega/pins_arduino.h363
-rw-r--r--protocol/usb_hid/arduino-1.0.1/variants/standard/pins_arduino.h218
-rw-r--r--protocol/usb_hid/leonardo_led.h10
-rw-r--r--protocol/usb_hid/override_Serial.cpp51
-rw-r--r--protocol/usb_hid/override_wiring.c28
-rw-r--r--protocol/usb_hid/parser.cpp26
-rw-r--r--protocol/usb_hid/parser.h12
-rw-r--r--protocol/usb_hid/test/Makefile126
-rw-r--r--protocol/usb_hid/test/config.h40
-rw-r--r--protocol/usb_hid/test/test.cpp92
-rw-r--r--protocol/usb_hid/usb_hid.h10
-rw-r--r--rules.mk14
76 files changed, 9525 insertions, 130 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000000..3e34a635c7
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "protocol/usb_hid/USB_Host_Shield_2.0"]
+ path = protocol/usb_hid/USB_Host_Shield_2.0
+ url = git@github.com:tmk/USB_Host_Shield_2.0.git
diff --git a/common.mk b/common.mk
index 580a8cf8ff..26b4bb8596 100644
--- a/common.mk
+++ b/common.mk
@@ -5,6 +5,7 @@ SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/layer.c \
$(COMMON_DIR)/timer.c \
$(COMMON_DIR)/print.c \
+ $(COMMON_DIR)/debug.c \
$(COMMON_DIR)/bootloader.c \
$(COMMON_DIR)/util.c
diff --git a/common/debug.c b/common/debug.c
new file mode 100644
index 0000000000..41d566ee3a
--- /dev/null
+++ b/common/debug.c
@@ -0,0 +1,9 @@
+#include <stdbool.h>
+#include "debug.h"
+
+
+bool debug_enable = false;
+bool debug_matrix = false;
+bool debug_keyboard = false;
+bool debug_mouse = false;
+
diff --git a/common/debug.h b/common/debug.h
index 230d3b3499..9cc8d882f3 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -18,19 +18,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef DEBUG_H
#define DEBUG_H 1
+#include <stdbool.h>
#include "print.h"
-#define debug(s) if(debug_enable) print(s)
+#define debug(s) if(debug_enable) print_P(PSTR(s))
#define debug_hex(c) if(debug_enable) phex(c)
#define debug_hex16(i) if(debug_enable) phex16(i)
#define debug_bin(c) if(debug_enable) pbin(c)
#define debug_bin_reverse(c) if(debug_enable) pbin_reverse(c)
-bool debug_enable;
-bool debug_matrix;
-bool debug_keyboard;
-bool debug_mouse;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern bool debug_enable;
+extern bool debug_matrix;
+extern bool debug_keyboard;
+extern bool debug_mouse;
+
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/common/host.h b/common/host.h
index 11b9aacd7c..26bf3c362f 100644
--- a/common/host.h
+++ b/common/host.h
@@ -23,6 +23,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "host_driver.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifdef NKRO_ENABLE
extern bool keyboard_nkro;
#endif
@@ -54,4 +58,8 @@ void host_mouse_send(report_mouse_t *report);
void host_system_send(uint16_t data);
void host_consumer_send(uint16_t data);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/common/keyboard.h b/common/keyboard.h
index 988dac36ed..51bf67379a 100644
--- a/common/keyboard.h
+++ b/common/keyboard.h
@@ -21,8 +21,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
void keyboard_init(void);
void keyboard_proc(void);
void keyboard_set_leds(uint8_t leds);
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/common/print.h b/common/print.h
index 686fa89acc..d55f5695dc 100644
--- a/common/print.h
+++ b/common/print.h
@@ -29,11 +29,17 @@
#include <avr/pgmspace.h>
-extern bool print_enable;
-
+// avoid collision with arduino/Print.h
+#ifndef __cplusplus
// this macro allows you to write print("some text") and
// the string is automatically placed into flash memory :)
#define print(s) print_P(PSTR(s))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern bool print_enable;
void print_S(const char *s);
void print_P(const char *s);
@@ -41,5 +47,8 @@ void phex(unsigned char c);
void phex16(unsigned int i);
void pbin(unsigned char c);
void pbin_reverse(unsigned char c);
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/common/report.h b/common/report.h
index 45f5c0b881..a73e0aba18 100644
--- a/common/report.h
+++ b/common/report.h
@@ -78,6 +78,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define REPORT_KEYS 6
#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct {
uint8_t mods;
uint8_t rserved;
@@ -92,4 +97,8 @@ typedef struct {
int8_t h;
} __attribute__ ((packed)) report_mouse_t;
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/common/sendchar.h b/common/sendchar.h
index 7c81303c7a..7a64d00c7f 100644
--- a/common/sendchar.h
+++ b/common/sendchar.h
@@ -21,7 +21,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* transmit a character. return 0 on success, -1 on error. */
int8_t sendchar(uint8_t c);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/common/timer.c b/common/timer.c
index 48a38c9b68..8b8d37e8b3 100644
--- a/common/timer.c
+++ b/common/timer.c
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// counter resolution 1ms
-volatile uint16_t timer_count = 0;
+volatile uint32_t timer_count = 0;
void timer_init(void)
{
@@ -59,7 +59,20 @@ void timer_clear(void)
inline
uint16_t timer_read(void)
{
- uint16_t t;
+ uint32_t t;
+
+ uint8_t sreg = SREG;
+ cli();
+ t = timer_count;
+ SREG = sreg;
+
+ return (t & 0xFFFF);
+}
+
+inline
+uint32_t timer_read32(void)
+{
+ uint32_t t;
uint8_t sreg = SREG;
cli();
@@ -72,14 +85,27 @@ uint16_t timer_read(void)
inline
uint16_t timer_elapsed(uint16_t last)
{
- uint16_t t;
+ uint32_t t;
+
+ uint8_t sreg = SREG;
+ cli();
+ t = timer_count;
+ SREG = sreg;
+
+ return TIMER_DIFF_16((t & 0xFFFF), last);
+}
+
+inline
+uint32_t timer_elapsed32(uint32_t last)
+{
+ uint32_t t;
uint8_t sreg = SREG;
cli();
t = timer_count;
SREG = sreg;
- return TIMER_DIFF_MS(t, last);
+ return TIMER_DIFF_32(t, last);
}
// excecuted once per 1ms.(excess for just timer count?)
diff --git a/common/timer.h b/common/timer.h
index f9e8181e6f..6437473ff7 100644
--- a/common/timer.h
+++ b/common/timer.h
@@ -23,10 +23,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef TIMER_PRESCALER
# if F_CPU > 16000000
# define TIMER_PRESCALER 256
-# elif F_CPU >= 4000000
+# elif F_CPU > 2000000
# define TIMER_PRESCALER 64
-# else
+# elif F_CPU > 250000
# define TIMER_PRESCALER 8
+# else
+# define TIMER_PRESCALER 1
# endif
#endif
#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
@@ -38,16 +40,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a))
-#define TIMER_DIFF_RAW(a, b) TIMER_DIFF(a, b, UINT8_MAX)
-#define TIMER_DIFF_MS(a, b) TIMER_DIFF(a, b, UINT16_MAX)
+#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX)
+#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX)
+#define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX)
+#define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
-extern volatile uint16_t timer_count;
+extern volatile uint32_t timer_count;
void timer_init(void);
void timer_clear(void);
uint16_t timer_read(void);
+uint32_t timer_read32(void);
uint16_t timer_elapsed(uint16_t last);
+uint32_t timer_elapsed32(uint32_t last);
+
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/common/usb_keycodes.h b/common/usb_keycodes.h
index 9b6cce1532..04b398fa2a 100644
--- a/common/usb_keycodes.h
+++ b/common/usb_keycodes.h
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define IS_ERROR(code) (KB_ROLL_OVER <= (code) && (code) <= KB_UNDEFINED)
+#define IS_ANY(code) (KB_A <= (code))
#define IS_KEY(code) (KB_A <= (code) && (code) <= KB_EXSEL)
#define IS_MOD(code) (KB_LCTRL <= (code) && (code) <= KB_RGUI)
#define IS_FN(code) (KB_FN0 <= (code) && (code) <= KB_FN7)
diff --git a/converter/usb_usb/Makefile b/converter/usb_usb/Makefile
new file mode 100644
index 0000000000..41a64e4643
--- /dev/null
+++ b/converter/usb_usb/Makefile
@@ -0,0 +1,130 @@
+#----------------------------------------------------------------------------
+# 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 = usb_usb
+
+TOP_DIR = ../..
+
+# 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
+
+
+
+#
+# LUFA specific
+#
+# Target architecture (see library "Board Types" documentation).
+ARCH = AVR8
+# Input clock frequency.
+# This will define a symbol, F_USB, in all source code files equal to the
+# input clock frequency (before any prescaling is performed) in Hz. This value may
+# differ from F_CPU if prescaling is used on the latter, and is required as the
+# raw input clock is fed directly to the PLL sections of the AVR for high speed
+# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
+# at the end, this will be done automatically to create a 32-bit value in your
+# source code.
+#
+# If no clock division is performed on the input clock inside the AVR (via the
+# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
+F_USB = $(F_CPU)
+# Interrupt driven control endpoint task
+OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
+
+
+
+# Build Options
+# comment out to disable the options.
+#
+MOUSEKEY_ENABLE = yes # Mouse keys
+EXTRAKEY_ENABLE = yes # Media control and System control
+CONSOLE_ENABLE = yes # Console for debug
+#NKRO_ENABLE = yes # USB Nkey Rollover
+
+# Boot Section Size in bytes
+# Teensy halfKay 512
+# Atmel DFU loader 4096
+# LUFA bootloader 4096
+#OPT_DEFS += -DBOOT_SIZE=4096
+
+
+
+SRC = \
+ keymap.c \
+ matrix.c \
+ led.c \
+ main.cpp
+
+CONFIG_H = config.h
+
+
+
+# Search Path
+VPATH += $(TARGET_DIR)
+VPATH += $(TOP_DIR)
+
+
+
+# program Leonardo
+PROGRAM_CMD = avrdude -p$(MCU) -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex
+
+
+
+include $(TOP_DIR)/protocol/usb_hid.mk
+include $(TOP_DIR)/protocol/lufa.mk
+include $(TOP_DIR)/common.mk
+include $(TOP_DIR)/rules.mk
diff --git a/converter/usb_usb/config.h b/converter/usb_usb/config.h
new file mode 100644
index 0000000000..c2230fb570
--- /dev/null
+++ b/converter/usb_usb/config.h
@@ -0,0 +1,40 @@
+/*
+Copyright 2012 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+
+#define VENDOR_ID 0xFEED
+#define PRODUCT_ID 0xCAFE
+#define DEVICE_VER 0x0814
+#define MANUFACTURER t.m.k.
+#define PRODUCT USB to USB keyboard converter
+
+
+#define DESCRIPTION Product from t.m.k. keyboard firmware project
+
+
+/* matrix size */
+#define MATRIX_ROWS 32
+#define MATRIX_COLS 8
+
+
+/* key combination for command */
+#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
+
+#endif</