X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=common%2Fcommand.c;h=216ad06128821074f0cdc2858abaf1b82c284da0;hb=9e39b222d0105b55c84a8301958d69209a3319fb;hp=bbc45f45a330d268dfc52138e7ec4f35bde64d51;hpb=30eb3e3520e9d4d7b9a9dbac0c5c0200485103c2;p=max%2Ftmk_keyboard.git
diff --git a/common/command.c b/common/command.c
index bbc45f45..216ad061 100644
--- a/common/command.c
+++ b/common/command.c
@@ -19,25 +19,31 @@ along with this program. If not, see .
#include
#include "keycode.h"
#include "host.h"
+#include "keymap.h"
#include "print.h"
#include "debug.h"
#include "util.h"
#include "timer.h"
#include "keyboard.h"
#include "bootloader.h"
+#include "action_layer.h"
+#include "eeconfig.h"
+#include "sleep_led.h"
+#include "led.h"
#include "command.h"
+
#ifdef MOUSEKEY_ENABLE
#include "mousekey.h"
#endif
-#ifdef HOST_PJRC
+#ifdef PROTOCOL_PJRC
# include "usb_keyboard.h"
# ifdef EXTRAKEY_ENABLE
# include "usb_extra.h"
# endif
#endif
-#ifdef HOST_VUSB
+#ifdef PROTOCOL_VUSB
# include "usbdrv.h"
#endif
@@ -46,12 +52,13 @@ 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 kc2int(uint8_t code);
-static void switch_layer(uint8_t layer);
-static void clear_keyboard(void);
+static uint8_t numkey2num(uint8_t code);
+static void switch_default_layer(uint8_t layer);
typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
@@ -68,9 +75,11 @@ bool command_proc(uint8_t code)
case CONSOLE:
command_console(code);
break;
+#ifdef MOUSEKEY_ENABLE
case MOUSEKEY:
mousekey_console(code);
break;
+#endif
default:
state = ONESHOT;
return false;
@@ -91,7 +100,6 @@ bool command_extra(uint8_t code)
***********************************************************/
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");
@@ -102,6 +110,7 @@ static void command_common_help(void)
print("v: print device version & info\n");
print("t: print timer count\n");
print("s: print status\n");
+ print("e: print eeprom config\n");
#ifdef NKRO_ENABLE
print("n: toggle NKRO\n");
#endif
@@ -111,18 +120,67 @@ static void command_common_help(void)
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");
}
+#ifdef BOOTMAGIC_ENABLE
+static void print_eeconfig(void)
+{
+ print("default_layer: "); print_dec(eeconfig_read_defalt_layer()); print("\n");
+
+ debug_config_t dc;
+ dc.raw = eeconfig_read_debug();
+ print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
+ print(".enable: "); print_dec(dc.enable); print("\n");
+ print(".matrix: "); print_dec(dc.matrix); print("\n");
+ print(".keyboard: "); print_dec(dc.keyboard); print("\n");
+ print(".mouse: "); print_dec(dc.mouse); print("\n");
+
+ keymap_config_t kc;
+ kc.raw = eeconfig_read_keymap();
+ print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
+ print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
+ print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
+ print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
+ print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
+ print(".no_gui: "); print_dec(kc.no_gui); print("\n");
+ print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
+ print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
+}
+#endif
+
static bool command_common(uint8_t code)
{
+ static host_driver_t *host_driver = 0;
switch (code) {
+ case KC_Z:
+ // test breathing sleep LED
+ print("Sleep LED test\n");
+ sleep_led_toggle();
+ led_set(host_keyboard_leds());
+ break;
+#ifdef BOOTMAGIC_ENABLE
+ case KC_E:
+ print("eeconfig:\n");
+ print_eeconfig();
+ break;
+#endif
+ 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;
@@ -148,9 +206,6 @@ static bool command_common(uint8_t code)
debug_enable = false;
} else {
print("\nDEBUG: enabled.\n");
- debug_matrix = true;
- debug_keyboard = true;
- debug_mouse = true;
debug_enable = true;
}
break;
@@ -189,38 +244,30 @@ static bool command_common(uint8_t code)
print("VERSION: " STR(DEVICE_VER) "\n");
break;
case KC_T: // print timer
- print("timer: "); phex16(timer_count>>16); phex16(timer_count); print("\n");
- break;
- case KC_P: // print toggle
- if (print_enable) {
- print("print disabled.\n");
- print_enable = false;
- } else {
- print_enable = true;
- print("print enabled.\n");
- }
+ print_val_hex32(timer_count);
break;
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");
- print("UDIEN: "); phex(UDIEN); print("\n");
- print("UDINT: "); phex(UDINT); print("\n");
- print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n");
- print("usb_keyboard_protocol: "); phex(usb_keyboard_protocol); print("\n");
- print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n");
- print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n");
+ print_val_hex8(host_keyboard_leds());
+#ifdef PROTOCOL_PJRC
+ print_val_hex8(UDCON);
+ print_val_hex8(UDIEN);
+ print_val_hex8(UDINT);
+ print_val_hex8(usb_keyboard_leds);
+ print_val_hex8(usb_keyboard_protocol);
+ print_val_hex8(usb_keyboard_idle_config);
+ print_val_hex8(usb_keyboard_idle_count);
#endif
-#ifdef HOST_VUSB
+#ifdef PROTOCOL_PJRC
# if USB_COUNT_SOF
- print("usbSofCount: "); phex(usbSofCount); print("\n");
+ print_val_hex8(usbSofCount);
# endif
#endif
break;
#ifdef NKRO_ENABLE
case KC_N:
+ clear_keyboard(); //Prevents stuck keys.
keyboard_nkro = !keyboard_nkro;
if (keyboard_nkro)
print("NKRO: enabled\n");
@@ -231,7 +278,7 @@ static bool command_common(uint8_t code)
#ifdef EXTRAKEY_ENABLE
case KC_PSCREEN:
// TODO: Power key should take this feature? otherwise any key during suspend.
-#ifdef HOST_PJRC
+#ifdef PROTOCOL_PJRC
if (suspend && remote_wakeup) {
usb_remote_wakeup();
} else {
@@ -241,30 +288,22 @@ static bool command_common(uint8_t code)
}
#else
host_system_send(SYSTEM_POWER_DOWN);
+ _delay_ms(100);
host_system_send(0);
_delay_ms(500);
#endif
break;
#endif
+ case KC_ESC:
+ case KC_GRV:
case KC_0:
- case KC_F10:
- switch_layer(0);
- break;
- case KC_1:
- case KC_F1:
- switch_layer(1);
- break;
- case KC_2:
- case KC_F2:
- switch_layer(2);
+ switch_default_layer(0);
break;
- case KC_3:
- case KC_F3:
- switch_layer(3);
+ case KC_1 ... KC_9:
+ switch_default_layer((code - KC_1) + 1);
break;
- case KC_4:
- case KC_F4:
- switch_layer(4);
+ case KC_F1 ... KC_F12:
+ switch_default_layer((code - KC_F1) + 1);
break;
default:
print("?");
@@ -279,7 +318,6 @@ static bool command_common(uint8_t code)
***********************************************************/
static void command_console_help(void)
{
- print_enable = true;
print("\n\n----- Console Help -----\n");
print("ESC/q: quit\n");
#ifdef MOUSEKEY_ENABLE
@@ -333,6 +371,7 @@ static void mousekey_param_print(void)
print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
}
+#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n");
static void mousekey_param_inc(uint8_t param, uint8_t inc)
{
switch (param) {
@@ -341,42 +380,42 @@ static void mousekey_param_inc(uint8_t param, uint8_t inc)
mk_delay += inc;
else
mk_delay = UINT8_MAX;
- print("mk_delay = "); pdec(mk_delay); print("\n");
+ PRINT_SET_VAL(mk_delay);
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");
+ PRINT_SET_VAL(mk_interval);
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");
+ PRINT_SET_VAL(mk_max_speed);
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");
+ PRINT_SET_VAL(mk_time_to_max);
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");
+ PRINT_SET_VAL(mk_wheel_max_speed);
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");
+ PRINT_SET_VAL(mk_wheel_time_to_max);
break;
}
}
@@ -389,42 +428,42 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec)
mk_delay -= dec;
else
mk_delay = 0;
- print("mk_delay = "); pdec(mk_delay); print("\n");
+ PRINT_SET_VAL(mk_delay);
break;
case 2:
if (mk_interval > dec)
mk_interval -= dec;
else
mk_interval = 0;
- print("mk_interval = "); pdec(mk_interval); print("\n");
+ PRINT_SET_VAL(mk_interval);
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");
+ PRINT_SET_VAL(mk_max_speed);
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");
+ PRINT_SET_VAL(mk_time_to_max);
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");
+ PRINT_SET_VAL(mk_wheel_max_speed);
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");
+ PRINT_SET_VAL(mk_wheel_time_to_max);
break;
}
}
@@ -478,7 +517,7 @@ static bool mousekey_console(uint8_t code)
case KC_8:
case KC_9:
case KC_0:
- mousekey_param = kc2int(code);
+ mousekey_param = numkey2num(code);
print("selected parameter: "); pdec(mousekey_param); print("\n");
break;
case KC_UP:
@@ -515,7 +554,7 @@ static bool mousekey_console(uint8_t code)
/***********************************************************
* Utilities
***********************************************************/
-static uint8_t kc2int(uint8_t code)
+static uint8_t numkey2num(uint8_t code)
{
switch (code) {
case KC_1: return 1;
@@ -532,26 +571,10 @@ static uint8_t kc2int(uint8_t code)
return 0;
}
-static void switch_layer(uint8_t layer)
-{
- print("current_layer: "); phex(current_layer); print("\n");
- print("default_layer: "); phex(default_layer); print("\n");
- current_layer = layer;
- default_layer = layer;
- print("switch to Layer: "); phex(layer); print("\n");
-}
-
-static void clear_keyboard(void)
+static void switch_default_layer(uint8_t layer)
{
- 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
+ print("switch_default_layer: "); print_dec(biton32(default_layer_state));
+ print(" to "); print_dec(layer); print("\n");
+ default_layer_set(layer);
+ clear_keyboard();
}