From 2aa5e4464010a9292b50571243d8ef6e749a5ca4 Mon Sep 17 00:00:00 2001
From: Balz Guenat <balz.guenat@gmail.com>
Date: Sat, 12 Aug 2017 18:24:15 +0200
Subject: [PATCH] some major steps toward making the usb-usb converter work

---
 keyboards/converter/usb_usb/config.h          |  2 +
 .../usb_usb/keymaps/default/keymap.c          |  2 +-
 keyboards/converter/usb_usb/rules.mk          |  2 +-
 tmk_core/common/keycode.h                     |  8 ++++
 .../{readme.md => README.md}                  |  0
 .../testusbhostFAT/{readme.md => README.md}   |  0
 tmk_core/protocol/usb_hid/parser.cpp          | 24 ++---------
 tmk_core/protocol/usb_hid/parser.h            |  5 ++-
 tmk_core/protocol/usb_hid/test/Makefile       | 40 ++++++++++++++++++-
 9 files changed, 59 insertions(+), 24 deletions(-)
 rename tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/{readme.md => README.md} (100%)
 rename tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/{readme.md => README.md} (100%)

diff --git a/keyboards/converter/usb_usb/config.h b/keyboards/converter/usb_usb/config.h
index ff764ee4fa..fa059feeaf 100644
--- a/keyboards/converter/usb_usb/config.h
+++ b/keyboards/converter/usb_usb/config.h
@@ -31,6 +31,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define MATRIX_ROWS 16
 #define MATRIX_COLS 16
 
+#define DIODE_DIRECTION CUSTOM_MATRIX
+
 /* key combination for command */
 #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) 
 
diff --git a/keyboards/converter/usb_usb/keymaps/default/keymap.c b/keyboards/converter/usb_usb/keymaps/default/keymap.c
index fbbbd1cfa6..050332384c 100644
--- a/keyboards/converter/usb_usb/keymaps/default/keymap.c
+++ b/keyboards/converter/usb_usb/keymaps/default/keymap.c
@@ -27,7 +27,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "usb_usb.h"
 
 
-const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
+const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
     /* 0: plain Qwerty without layer switching
      *         ,---------------. ,---------------. ,---------------.
      *         |F13|F14|F15|F16| |F17|F18|F19|F20| |F21|F22|F23|F24|
diff --git a/keyboards/converter/usb_usb/rules.mk b/keyboards/converter/usb_usb/rules.mk
index 2ae908fec7..f6b816966c 100644
--- a/keyboards/converter/usb_usb/rules.mk
+++ b/keyboards/converter/usb_usb/rules.mk
@@ -146,7 +146,7 @@ SRC = matrix.cpp
 
 
 
-# include $(TMK_DIR)/protocol/usb_hid.mk
+include $(TMK_DIR)/protocol/usb_hid.mk
 # include $(TMK_DIR)/protocol/lufa.mk
 # include $(TMK_DIR)/common.mk
 # include $(TMK_DIR)/rules.mk
diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h
index 54e9c322c1..a1e0bc9a47 100644
--- a/tmk_core/common/keycode.h
+++ b/tmk_core/common/keycode.h
@@ -94,6 +94,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define KC_JYEN KC_INT3
 #define KC_HENK KC_INT4
 #define KC_MHEN KC_INT5
+/* Korean specific */
+#define KC_HAEN KC_LANG1
+#define KC_HANJ KC_LANG2
 /* Keypad */
 #define KC_P1   KC_KP_1
 #define KC_P2   KC_KP_2
@@ -113,6 +116,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define KC_PPLS KC_KP_PLUS
 #define KC_PEQL KC_KP_EQUAL
 #define KC_PENT KC_KP_ENTER
+/* Unix function key */
+#define KC_EXEC KC_EXECUTE
+#define KC_SLCT KC_SELECT
+#define KC_AGIN KC_AGAIN
+#define KC_PSTE KC_PASTE
 /* Mousekey */
 #define KC_MS_U KC_MS_UP
 #define KC_MS_D KC_MS_DOWN
diff --git a/tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/readme.md b/tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/README.md
similarity index 100%
rename from tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/readme.md
rename to tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/README.md
diff --git a/tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/readme.md b/tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/README.md
similarity index 100%
rename from tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/readme.md
rename to tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/testusbhostFAT/README.md
diff --git a/tmk_core/protocol/usb_hid/parser.cpp b/tmk_core/protocol/usb_hid/parser.cpp
index 1a152ff3f2..94e747ca4b 100644
--- a/tmk_core/protocol/usb_hid/parser.cpp
+++ b/tmk_core/protocol/usb_hid/parser.cpp
@@ -4,30 +4,14 @@
 #include "debug.h"
 
 
-report_keyboard_t usb_hid_keyboard_report;
-uint16_t usb_hid_time_stamp;
-
-
 void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
 {
-    bool is_error = false;
-    report_keyboard_t *report = (report_keyboard_t *)buf;
+    ::memcpy(&report, buf, sizeof(report_keyboard_t));
+    time_stamp = millis();
 
-    dprintf("KBDReport: %02X %02X", report->mods, report->reserved);
+    dprintf("input %d:  %02X %02X", hid->GetAddress(), report.mods, report.reserved);
     for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
-        if (IS_ERROR(report->keys[i])) {
-            is_error = true;
-        }
-        dprintf(" %02X", report->keys[i]);
+        dprintf(" %02X", report.keys[i]);
     }
     dprint("\r\n");
-
-    // ignore error and not send report to computer
-    if (is_error) {
-        dprint("Error usage! \r\n");
-        return;
-    }
-
-    ::memcpy(&usb_hid_keyboard_report, buf, sizeof(report_keyboard_t));
-    usb_hid_time_stamp = millis();
 }
diff --git a/tmk_core/protocol/usb_hid/parser.h b/tmk_core/protocol/usb_hid/parser.h
index 703eb1ed4c..036281fa66 100644
--- a/tmk_core/protocol/usb_hid/parser.h
+++ b/tmk_core/protocol/usb_hid/parser.h
@@ -2,11 +2,14 @@
 #define PARSER_H
 
 #include "hid.h"
+#include "report.h"
 
 class KBDReportParser : public HIDReportParser
 {
 public:
-	virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
+    report_keyboard_t report;
+    uint16_t time_stamp;
+    virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
 };
 
 #endif
diff --git a/tmk_core/protocol/usb_hid/test/Makefile b/tmk_core/protocol/usb_hid/test/Makefile
index c093bbd4c1..83bf2aed67 100644
--- a/tmk_core/protocol/usb_hid/test/Makefile
+++ b/tmk_core/protocol/usb_hid/test/Makefile
@@ -1,4 +1,42 @@
-
+#----------------------------------------------------------------------------
+# 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_hid_test