summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/command.c536
-rw-r--r--common/command.h4
-rw-r--r--common/debug.h2
-rw-r--r--common/host.c138
-rw-r--r--common/host.h28
-rw-r--r--common/keyboard.c690
-rw-r--r--common/keyboard.h28
-rw-r--r--common/keycode.h448
-rw-r--r--common/layer.c207
-rw-r--r--common/layer.h32
-rw-r--r--common/matrix.h21
-rw-r--r--common/mousekey.c202
-rw-r--r--common/mousekey.h46
-rw-r--r--common/print.c8
-rw-r--r--common/print.h1
-rw-r--r--common/timer.c1
-rw-r--r--common/usb_keycodes.h424
-rw-r--r--common/util.c16
-rw-r--r--common/util.h4
19 files changed, 1775 insertions, 1061 deletions
diff --git a/common/command.c b/common/command.c
index 13d37242d9..8e2e21a707 100644
--- a/common/command.c
+++ b/common/command.c
@@ -17,16 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
#include <util/delay.h>
-#include "usb_keycodes.h"
+#include "keycode.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "util.h"
#include "timer.h"
-#include "layer.h"
-#include "matrix.h"
+#include "keyboard.h"
#include "bootloader.h"
#include "command.h"
+#ifdef MOUSEKEY_ENABLE
+#include "mousekey.h"
+#endif
#ifdef HOST_PJRC
# include "usb_keyboard.h"
@@ -40,104 +42,182 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
-static uint8_t command_common(void);
-static void help(void);
+static bool command_common(uint8_t code);
+static void command_common_help(void);
+static bool command_console(uint8_t code);
+static void command_console_help(void);
+#ifdef MOUSEKEY_ENABLE
+static bool mousekey_console(uint8_t code);
+static void mousekey_console_help(void);
+#endif
+
+static uint8_t numkey2num(uint8_t code);
static void switch_layer(uint8_t layer);
+static void clear_keyboard(void);
-static bool last_print_enable;
-uint8_t command_proc(void)
-{
- uint8_t processed = 0;
- last_print_enable = print_enable;
+typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
+static cmdstate_t state = ONESHOT;
- if (!IS_COMMAND())
- return 0;
- print_enable = true;
- if (command_extra() || command_common()) {
- processed = 1;
- _delay_ms(500);
+bool command_proc(uint8_t code)
+{
+ switch (state) {
+ case ONESHOT:
+ if (!IS_COMMAND())
+ return false;
+ return (command_extra(code) || command_common(code));
+ case CONSOLE:
+ command_console(code);
+ break;
+#ifdef MOUSEKEY_ENABLE
+ case MOUSEKEY:
+ mousekey_console(code);
+ break;
+#endif
+ default:
+ state = ONESHOT;
+ return false;
}
- print_enable = last_print_enable;
- return processed;
+ return true;
}
-/* This allows to define extra commands. return 0 when not processed. */
-uint8_t command_extra(void) __attribute__ ((weak));
-uint8_t command_extra(void)
+/* This allows to define extra commands. return false when not processed. */
+bool command_extra(uint8_t code) __attribute__ ((weak));
+bool command_extra(uint8_t code)
{
- return 0;
+ return false;
}
-static uint8_t command_common(void)
+/***********************************************************
+ * Command common
+ ***********************************************************/
+static void command_common_help(void)
+{
+ print_enable = true;
+ print("\n\n----- Command Help -----\n");
+ print("c: enter console mode\n");
+ print("d: toggle debug enable\n");
+ print("x: toggle matrix debug\n");
+ print("k: toggle keyboard debug\n");
+ print("m: toggle mouse debug\n");
+ print("p: toggle print enable\n");
+ print("v: print device version & info\n");
+ print("t: print timer count\n");
+ print("s: print status\n");
+#ifdef NKRO_ENABLE
+ print("n: toggle NKRO\n");
+#endif
+ print("0/F10: switch to Layer0 \n");
+ print("1/F1: switch to Layer1 \n");
+ print("2/F2: switch to Layer2 \n");
+ print("3/F3: switch to Layer3 \n");
+ print("4/F4: switch to Layer4 \n");
+ print("PScr: power down/remote wake-up\n");
+ print("Caps: Lock Keyboard(Child Proof)\n");
+ print("Paus: jump to bootloader\n");
+}
+
+static bool command_common(uint8_t code)
{
- switch (host_get_first_key()) {
- case KB_H:
- help();
- break;
- case KB_B:
- host_clear_keyboard_report();
- host_send_keyboard_report();
- print("jump to bootloader... ");
+ static host_driver_t *host_driver = 0;
+ switch (code) {
+ case KC_CAPSLOCK:
+ if (host_get_driver()) {
+ host_driver = host_get_driver();
+ host_set_driver(0);
+ print("Locked.\n");
+ } else {
+ host_set_driver(host_driver);
+ print("Unlocked.\n");
+ }
+ break;
+ case KC_H:
+ case KC_SLASH: /* ? */
+ command_common_help();
+ break;
+ case KC_C:
+ print_enable = true;
+ debug_matrix = false;
+ debug_keyboard = false;
+ debug_mouse = false;
+ debug_enable = false;
+ command_console_help();
+ print("\nEnter Console Mode\n");
+ print("C> ");
+ state = CONSOLE;
+ break;
+ case KC_PAUSE:
+ clear_keyboard();
+ print("\n\nJump to bootloader... ");
_delay_ms(1000);
bootloader_jump(); // not return
print("not supported.\n");
break;
- case KB_D:
- debug_enable = !debug_enable;
+ case KC_D:
if (debug_enable) {
- last_print_enable = true;
- print("debug enabled.\n");
- debug_matrix = true;
- debug_keyboard = true;
- debug_mouse = true;
- } else {
- print("debug disabled.\n");
- last_print_enable = false;
- debug_matrix = false;
+ print("\nDEBUG: disabled.\n");
+ debug_matrix = false;
debug_keyboard = false;
- debug_mouse = false;
+ debug_mouse = false;
+ debug_enable = false;
+ } else {
+ print("\nDEBUG: enabled.\n");
+ debug_matrix = true;
+ debug_keyboard = true;
+ debug_mouse = true;
+ debug_enable = true;
}
break;
- case KB_X: // debug matrix toggle
+ case KC_X: // debug matrix toggle
debug_matrix = !debug_matrix;
- if (debug_matrix)
- print("debug matrix enabled.\n");
- else
- print("debug matrix disabled.\n");
+ if (debug_matrix) {
+ print("\nDEBUG: matrix enabled.\n");
+ debug_enable = true;
+ } else {
+ print("\nDEBUG: matrix disabled.\n");
+ }
break;
- case KB_K: // debug keyboard toggle
+ case KC_K: // debug keyboard toggle
debug_keyboard = !debug_keyboard;
- if (debug_keyboard)
- print("debug keyboard enabled.\n");
- else
- print("debug keyboard disabled.\n");
+ if (debug_keyboard) {
+ print("\nDEBUG: keyboard enabled.\n");
+ debug_enable = true;
+ } else {
+ print("\nDEBUG: keyboard disabled.\n");
+ }
break;
- case KB_M: // debug mouse toggle
+ case KC_M: // debug mouse toggle
debug_mouse = !debug_mouse;
- if (debug_mouse)
- print("debug mouse enabled.\n");
- else
- print("debug mouse disabled.\n");
+ if (debug_mouse) {
+ print("\nDEBUG: mouse enabled.\n");
+ debug_enable = true;
+ } else {
+ print("\nDEBUG: mouse disabled.\n");
+ }
break;
- case KB_V: // print version & information
+ case KC_V: // print version & information
+ print("\n\n----- Version -----\n");
print(STR(DESCRIPTION) "\n");
+ print(STR(MANUFACTURER) "(" STR(VENDOR_ID) ")/");
+ print(STR(PRODUCT) "(" STR(PRODUCT_ID) ") ");
+ print("VERSION: " STR(DEVICE_VER) "\n");
break;
- case KB_T: // print timer
- print("timer: "); phex16(timer_count); print("\n");
+ case KC_T: // print timer
+ print("timer: "); phex16(timer_count>>16); phex16(timer_count); print("\n");
break;
- case KB_P: // print toggle
- if (last_print_enable) {
+ case KC_P: // print toggle
+ if (print_enable) {
print("print disabled.\n");
- last_print_enable = false;
+ print_enable = false;
} else {
- last_print_enable = true;
+ print_enable = true;
print("print enabled.\n");
}
break;
- case KB_S:
+ case KC_S:
+ print("\n\n----- Status -----\n");
print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
#ifdef HOST_PJRC
print("UDCON: "); phex(UDCON); print("\n");
@@ -156,10 +236,7 @@ static uint8_t command_common(void)
#endif
break;
#ifdef NKRO_ENABLE
- case KB_N:
- // send empty report before change
- host_clear_keyboard_report();
- host_send_keyboard_report();
+ case KC_N:
keyboard_nkro = !keyboard_nkro;
if (keyboard_nkro)
print("NKRO: enabled\n");
@@ -168,9 +245,8 @@ static uint8_t command_common(void)
break;
#endif
#ifdef EXTRAKEY_ENABLE
- case KB_ESC:
- host_clear_keyboard_report();
- host_send_keyboard_report();
+ case KC_PSCREEN:
+ // TODO: Power key should take this feature? otherwise any key during suspend.
#ifdef HOST_PJRC
if (suspend && remote_wakeup) {
usb_remote_wakeup();
@@ -181,57 +257,296 @@ static uint8_t command_common(void)
}
#else
host_system_send(SYSTEM_POWER_DOWN);
+ _delay_ms(100);
host_system_send(0);
_delay_ms(500);
#endif
break;
#endif
- case KB_BSPC:
- matrix_init();
- print("clear matrix\n");
- break;
- case KB_0:
+ case KC_0:
+ case KC_F10:
switch_layer(0);
break;
- case KB_1:
+ case KC_1:
+ case KC_F1:
switch_layer(1);
break;
- case KB_2:
+ case KC_2:
+ case KC_F2:
switch_layer(2);
break;
- case KB_3:
+ case KC_3:
+ case KC_F3:
switch_layer(3);
break;
- case KB_4:
+ case KC_4:
+ case KC_F4:
switch_layer(4);
break;
default:
- return 0;
+ print("?");
+ return false;
}
- return 1;
+ return true;
}
-static void help(void)
+
+/***********************************************************
+ * Command console
+ ***********************************************************/
+static void command_console_help(void)
{
- print("b: jump to bootloader\n");
- print("d: toggle debug enable\n");
- print("x: toggle matrix debug\n");
- print("k: toggle keyboard debug\n");
- print("m: toggle mouse debug\n");
- print("p: toggle print enable\n");
- print("v: print version\n");
- print("t: print timer count\n");
- print("s: print status\n");
-#ifdef NKRO_ENABLE
- print("n: toggle NKRO\n");
+ print_enable = true;
+ print("\n\n----- Console Help -----\n");
+ print("ESC/q: quit\n");
+#ifdef MOUSEKEY_ENABLE
+ print("m: mousekey\n");
+#endif
+}
+
+static bool command_console(uint8_t code)
+{
+ switch (code) {
+ case KC_H:
+ case KC_SLASH: /* ? */
+ command_console_help();
+ break;
+ case KC_Q:
+ case KC_ESC:
+ print("\nQuit Console Mode\n");
+ state = ONESHOT;
+ return false;
+#ifdef MOUSEKEY_ENABLE
+ case KC_M:
+ mousekey_console_help();
+ print("\nEnter Mousekey Console\n");
+ print("M0>");
+ state = MOUSEKEY;
+ return true;
+#endif
+ default:
+ print("?");
+ return false;
+ }
+ print("C> ");
+ return true;
+}
+
+
+#ifdef MOUSEKEY_ENABLE
+/***********************************************************
+ * Mousekey console
+ ***********************************************************/
+static uint8_t mousekey_param = 0;
+
+static void mousekey_param_print(void)
+{
+ print("\n\n----- Mousekey Parameters -----\n");
+ print("1: mk_delay(*10ms): "); pdec(mk_delay); print("\n");
+ print("2: mk_interval(ms): "); pdec(mk_interval); print("\n");
+ print("3: mk_max_speed: "); pdec(mk_max_speed); print("\n");
+ print("4: mk_time_to_max: "); pdec(mk_time_to_max); print("\n");
+ print("5: mk_wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
+ print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
+}
+
+static void mousekey_param_inc(uint8_t param, uint8_t inc)
+{
+ switch (param) {
+ case 1:
+ if (mk_delay + inc < UINT8_MAX)
+ mk_delay += inc;
+ else
+ mk_delay = UINT8_MAX;
+ print("mk_delay = "); pdec(mk_delay); print("\n");
+ break;
+ case 2:
+ if (mk_interval + inc < UINT8_MAX)
+ mk_interval += inc;
+ else
+ mk_interval = UINT8_MAX;
+ print("mk_interval = "); pdec(mk_interval); print("\n");
+ break;
+ case 3:
+ if (mk_max_speed + inc < UINT8_MAX)
+ mk_max_speed += inc;
+ else
+ mk_max_speed = UINT8_MAX;
+ print("mk_max_speed = "); pdec(mk_max_speed); print("\n");
+ break;
+ case 4:
+ if (mk_time_to_max + inc < UINT8_MAX)
+ mk_time_to_max += inc;
+ else
+ mk_time_to_max = UINT8_MAX;
+ print("mk_time_to_max = "); pdec(mk_time_to_max); print("\n");
+ break;
+ case 5:
+ if (mk_wheel_max_speed + inc < UINT8_MAX)
+ mk_wheel_max_speed += inc;
+ else
+ mk_wheel_max_speed = UINT8_MAX;
+ print("mk_wheel_max_speed = "); pdec(mk_wheel_max_speed); print("\n");
+ break;
+ case 6:
+ if (mk_wheel_time_to_max + inc < UINT8_MAX)
+ mk_wheel_time_to_max += inc;
+ else
+ mk_wheel_time_to_max = UINT8_MAX;
+ print("mk_wheel_time_to_max = "); pdec(mk_wheel_time_to_max); print("\n");
+ break;
+ }
+}
+
+static void mousekey_param_dec(uint8_t param, uint8_t dec)
+{
+ switch (param) {
+ case 1:
+ if (mk_delay > dec)
+ mk_delay -= dec;
+ else
+ mk_delay = 0;
+ print("mk_delay = "); pdec(mk_delay); print("\n");
+ break;
+ case 2:
+ if (mk_interval > dec)
+ mk_interval -= dec;
+ else
+ mk_interval = 0;
+ print("mk_interval = "); pdec(mk_interval); print("\n");
+ break;
+ case 3:
+ if (mk_max_speed > dec)
+ mk_max_speed -= dec;
+ else
+ mk_max_speed = 0;
+ print("mk_max_speed = "); pdec(mk_max_speed); print("\n");
+ break;
+ case 4:
+ if (mk_time_to_max > dec)
+ mk_time_to_max -= dec;
+ else
+ mk_time_to_max = 0;
+ print("mk_time_to_max = "); pdec(mk_time_to_max); print("\n");
+ break;
+ case 5:
+ if (mk_wheel_max_speed > dec)
+ mk_wheel_max_speed -= dec;
+ else
+ mk_wheel_max_speed = 0;
+ print("mk_wheel_max_speed = "); pdec(mk_wheel_max_speed); print("\n");
+ break;
+ case 6:
+ if (mk_wheel_time_to_max > dec)
+ mk_wheel_time_to_max -= dec;
+ else
+ mk_wheel_time_to_max = 0;
+ print("mk_wheel_time_to_max = "); pdec(mk_wheel_time_to_max); print("\n");
+ break;
+ }
+}
+
+static void mousekey_console_help(void)
+{
+ print("\n\n----- Mousekey Parameters Help -----\n");
+ print("ESC/q: quit\n");
+ print("1: select mk_delay(*10ms)\n");
+ print("2: select mk_interval(ms)\n");
+ print("3: select mk_max_speed\n");
+ print("4: select mk_time_to_max\n");
+ print("5: select mk_wheel_max_speed\n");
+ print("6: select mk_wheel_time_to_max\n");
+ print("p: print prameters\n");
+ print("d: set default values\n");
+ print("up: increase prameters(+1)\n");
+ print("down: decrease prameters(-1)\n");
+ print("pgup: increase prameters(+10)\n");
+ print("pgdown: decrease prameters(-10)\n");
+ print("\nspeed = delta * max_speed * (repeat / time_to_max)\n");
+ print("where delta: cursor="); pdec(MOUSEKEY_MOVE_DELTA);
+ print(", wheel="); pdec(MOUSEKEY_WHEEL_DELTA); print("\n");
+ print("See http://en.wikipedia.org/wiki/Mouse_keys\n");
+}
+
+static bool mousekey_console(uint8_t code)
+{
+ switch (code) {
+ case KC_H:
+ case KC_SLASH: /* ? */
+ mousekey_console_help();
+ break;
+ case KC_Q:
+ case KC_ESC:
+ mousekey_param = 0;
+ print("\nQuit Mousekey Console\n");
+ print("C> ");
+ state = CONSOLE;
+ return false;
+ case KC_P:
+ mousekey_param_print();
+ break;
+ case KC_1:
+ case KC_2:
+ case KC_3:
+ case KC_4:
+ case KC_5:
+ case KC_6:
+ case KC_7:
+ case KC_8:
+ case KC_9:
+ case KC_0:
+ mousekey_param = numkey2num(code);
+ print("selected parameter: "); pdec(mousekey_param); print("\n");
+ break;
+ case KC_UP:
+ mousekey_param_inc(mousekey_param, 1);
+ break;
+ case KC_DOWN:
+ mousekey_param_dec(mousekey_param, 1);
+ break;
+ case KC_PGUP:
+ mousekey_param_inc(mousekey_param, 10);
+ break;
+ case KC_PGDN:
+ mousekey_param_dec(mousekey_param, 10);
+ break;
+ case KC_D:
+ mk_delay = MOUSEKEY_DELAY/10;
+ mk_interval = MOUSEKEY_INTERVAL;
+ mk_max_speed = MOUSEKEY_MAX_SPEED;
+ mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
+ mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
+ mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
+ print("set default values.\n");
+ break;
+ default:
+ print("?");
+ return false;
+ }
+ print("M"); pdec(mousekey_param); print("> ");
+ return true;
+}
#endif
- print("Backspace: clear matrix\n");
- print("ESC: power down/wake up\n");
- print("0: switch to Layer0 \n");
- print("1: switch to Layer1 \n");
- print("2: switch to Layer2 \n");
- print("3: switch to Layer3 \n");
- print("4: switch to Layer4 \n");
+
+
+/***********************************************************
+ * Utilities
+ ***********************************************************/
+static uint8_t numkey2num(uint8_t code)
+{
+ switch (code) {
+ case KC_1: return 1;
+ case KC_2: return 2;
+ case KC_3: return 3;
+ case KC_4: return 4;
+ case KC_5: return 5;
+ case KC_6: return 6;
+ case KC_7: return 7;
+ case KC_8: return 8;
+ case KC_9: return 9;
+ case KC_0: return 0;
+ }
+ return 0;
}
static void switch_layer(uint8_t layer)
@@ -242,3 +557,18 @@ static void switch_layer(uint8_t layer)
default_layer = layer;
print("switch to Layer: "); phex(layer); print("\n");
}
+
+static void clear_keyboard(void)
+{
+ host_clear_keys();
+ host_clear_mods();
+ host_send_keyboard_report();
+
+ host_system_send(0);
+ host_consumer_send(0);
+
+#ifdef MOUSEKEY_ENABLE
+ mousekey_clear();
+ mousekey_send();
+#endif
+}
diff --git a/common/command.h b/common/command.h
index 4888f5ee0b..dafd4d0f38 100644
--- a/common/command.h
+++ b/common/command.h
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef COMMAND_H
#define COMMAND
-uint8_t command_proc(void);
+bool command_proc(uint8_t code);
/* This allows to extend commands. Return 0 when command is not processed. */
-uint8_t command_extra(void);
+bool command_extra(uint8_t code);
#endif
diff --git a/common/debug.h b/common/debug.h
index 9cc8d882f3..1d56e21f77 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define debug(s) if(debug_enable) print_P(PSTR(s))
+#define debug_P(s) if(debug_enable) print_P(s)
+#define debug_S(s) if(debug_enable) print_S(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)
diff --git a/common/host.c b/common/host.c
index 8dd2abbee8..261ec6472f 100644
--- a/common/host.c
+++ b/common/host.c
@@ -1,5 +1,5 @@
/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
+Copyright 2011,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
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <avr/interrupt.h>
-#include "usb_keycodes.h"
+#include "keycode.h"
#include "host.h"
#include "util.h"
#include "debug.h"
@@ -27,12 +27,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
bool keyboard_nkro = false;
#endif
-static host_driver_t *driver;
-static report_keyboard_t report0;
-static report_keyboard_t report1;
-report_keyboard_t *keyboard_report = &report0;
-report_keyboard_t *keyboard_report_prev = &report1;
+report_keyboard_t *keyboard_report = &(report_keyboard_t){};
+report_mouse_t mouse_report = {};
+
+static host_driver_t *driver;
+static uint16_t last_system_report = 0;
+static uint16_t last_consumer_report = 0;
static inline void add_key_byte(uint8_t code);
static inline void del_key_byte(uint8_t code);
@@ -55,8 +56,48 @@ uint8_t host_keyboard_leds(void)
if (!driver) return 0;
return (*driver->keyboard_leds)();
}
+/* send report */
+void host_keyboard_send(report_keyboard_t *report)
+{
+ if (!driver) return;
+ (*driver->send_keyboard)(report);
+
+ if (debug_keyboard) {
+ print("keys: ");
+ for (int i = 0; i < REPORT_KEYS; i++) {
+ phex(keyboard_report->keys[i]); print(" ");
+ }
+ print(" mods: "); phex(keyboard_report->mods); print("\n");
+ }
+}
+
+void host_mouse_send(report_mouse_t *report)
+{
+ if (!driver) return;
+ (*driver->send_mouse)(report);
+}
+
+void host_system_send(uint16_t report)
+{
+ if (report == last_system_report) return;
+ last_system_report = report;
+
+ if (!driver) return;
+ (*driver->send_system)(report);
+}
+
+void host_consumer_send(uint16_t report)
+{
+ if (report == last_consumer_report) return;
+ last_consumer_report = report;
+
+ if (!driver) return;
+ (*driver->send_consumer)(report);
+}
+
-/* keyboard report operations */
+
+/* keyboard report utils */
void host_add_key(uint8_t key)
{
#ifdef NKRO_ENABLE
@@ -79,6 +120,13 @@ void host_del_key(uint8_t key)
del_key_byte(key);
}
+void host_clear_keys(void)
+{
+ for (int8_t i = 0; i < REPORT_KEYS; i++) {
+ keyboard_report->keys[i] = 0;
+ }
+}
+
void host_add_mod_bit(uint8_t mod)
{
keyboard_report->mods |= mod;
@@ -94,40 +142,9 @@ void host_set_mods(uint8_t mods)
keyboard_report->mods = mods;
}
-void host_add_code(uint8_t code)
-{
- if (IS_MOD(code)) {
- host_add_mod_bit(MOD_BIT(code));
- } else {
- host_add_key(code);
- }
-}
-
-void host_del_code(uint8_t code)
-{
- if (IS_MOD(code)) {
- host_del_mod_bit(MOD_BIT(code));
- } else {
- host_del_key(code);
- }
-}
-
-void host_swap_keyboard_report(void)
-{
- uint8_t sreg = SREG;
- cli();
- report_keyboard_t *tmp = keyboard_report_prev;
- keyboard_report_prev = keyboard_report;
- keyboard_report = tmp;
- SREG = sreg;
-}
-
-void host_clear_keyboard_report(void)
+void host_clear_mods(void)
{
keyboard_report->mods = 0;
- for (int8_t i = 0; i < REPORT_KEYS; i++) {
- keyboard_report->keys[i] = 0;
- }
}
uint8_t host_has_anykey(void)
@@ -140,6 +157,11 @@ uint8_t host_has_anykey(void)
return cnt;
}
+uint8_t host_has_anymod(void)
+{
+ return bitpop(keyboard_report->mods);
+}
+
uint8_t host_get_first_key(void)
{
#ifdef NKRO_ENABLE
@@ -153,53 +175,36 @@ uint8_t host_get_first_key(void)
return keyboard_report->keys[0];
}
-
void host_send_keyboard_report(void)
{
if (!driver) return;
- (*driver->send_keyboard)(keyboard_report);
+ host_keyboard_send(keyboard_report);
}
-void host_mouse_send(report_mouse_t *report)
+uint8_t host_mouse_in_use(void)
{
- if (!driver) return;
- (*driver->send_mouse)(report);
+ return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h);
}
-void host_system_send(uint16_t data)
+uint16_t host_last_sysytem_report(void)
{
- static uint16_t last_data = 0;
- if (data == last_data) return;
- last_data = data;
-
- if (!driver) return;
- (*driver->send_system)(data);
+ return last_system_report;
}
-void host_consumer_send(uint16_t data)
+uint16_t host_last_consumer_report(void)
{
- static uint16_t last_data = 0;
- if (data == last_data) return;
- last_data = data;
-
- if (!driver) return;
- (*driver->send_consumer)(data);
+ return last_consumer_report;
}
-
static inline void add_key_byte(uint8_t code)
{
- // TODO: fix ugly code
int8_t i = 0;
int8_t empty = -1;
for (; i < REPORT_KEYS; i++) {
- if (keyboard_report_prev->keys[i] == code) {
- keyboard_report->keys[i] = code;
+ if (keyboard_report->keys[i] == code) {
break;
}
- if (empty == -1 &&
- keyboard_report_prev->keys[i] == 0 &&
- keyboard_report->keys[i] == 0) {
+ if (empty == -1 && keyboard_report->keys[i] == 0) {
empty = i;
}
}
@@ -216,7 +221,6 @@ static inline void del_key_byte(uint8_t code)
for (; i < REPORT_KEYS; i++) {
if (keyboard_report->keys[i] == code) {
keyboard_report->keys[i] = 0;
- break;
}
}
}
diff --git a/common/host.h b/common/host.h
index 26bf3c362f..207b683100 100644
--- a/common/host.h
+++ b/common/host.h
@@ -31,32 +31,40 @@ extern "C" {
extern bool keyboard_nkro;
#endif
+/* report */
extern report_keyboard_t *keyboard_report;
-extern report_keyboard_t *keyboard_report_prev;
+extern report_mouse_t mouse_report;
+/* host driver */
void host_set_driver(host_driver_t *driver);
host_driver_t *host_get_driver(void);
+
+/* host driver interface */
uint8_t host_keyboard_leds(void);
+void host_keyboard_send(report_keyboard_t *report);
+void host_mouse_send(report_mouse_t *report);
+void host_system_send(uint16_t data);
+void host_consumer_send(uint16_t data);
-/* keyboard report operations */
+/* keyboard report utils */
void host_add_key(uint8_t key);
void host_del_key(uint8_t key);
+void host_clear_keys(void);
void host_add_mod_bit(uint8_t mod);
void host_del_mod_bit(uint8_t mod);
void host_set_mods(uint8_t mods);
-void host_add_code(uint8_t code);
-void host_del_code(uint8_t code);
-void host_swap_keyboard_report(void);
-void host_clear_keyboard_report(void);
+void host_clear_mods(void);
uint8_t host_has_anykey(void);
+uint8_t host_has_anymod(void);
uint8_t host_get_first_key(void);
+void host_send_keyboard_report(void);
+/* mouse report utils */
+uint8_t host_mouse_in_use(void);
-void host_send_keyboard_report(void);
-void host_mouse_send(report_mouse_t *report);
-void host_system_send(uint16_t data);
-void host_consumer_send(uint16_t data);
+uint16_t host_last_sysytem_report(void);
+uint16_t host_last_consumer_report(void);
#ifdef __cplusplus
}
diff --git a/common/keyboard.c b/common/keyboard.c
index 25f32eb02f..e973c46d5b 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -15,179 +15,609 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "keyboard.h"
-#include "host.h"
-#include "layer.h"
#include "matrix.h"
+#include "keymap.h"
+#include "host.h"
#include "led.h"
-#include "usb_keycodes.h"
+#include "keycode.h"
#include "timer.h"
#include "print.h"
#include "debug.h"
#include "command.h"
+#include "util.h"
#ifdef MOUSEKEY_ENABLE
#include "mousekey.h"
#endif
-#ifdef EXTRAKEY_ENABLE
-#include <util/delay.h>
+
+
+#define Kdebug(s) do { if (debug_keyboard) debug(s); } while(0)
+#define Kdebug_P(s) do { if (debug_keyboard) debug_P(s); } while(0)
+#define Kdebug_hex(s) do { if (debug_keyboard) debug_hex(s); } while(0)
+
+#define LAYER_DELAY 250
+
+typedef enum keykind {
+ NONE,
+ FN_DOWN, FN_UP,