X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=key_process.c;h=2d4e788195e053b7a03d3612439bef225a0a8ab0;hb=590235d4bc92d1de4c17b96ae54f4daee8c3db2a;hp=0bd20280610fc1c91671db654a810431263c6d6e;hpb=9019c901dd7b4e37006eb1f0442a57dacc0b3f0c;p=max%2Ftmk_keyboard.git diff --git a/key_process.c b/key_process.c index 0bd20280..2d4e7881 100644 --- a/key_process.c +++ b/key_process.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "print.h" #include "debug.h" @@ -7,37 +8,29 @@ #include "util.h" #include "jump_bootloader.h" #include "usb_keyboard.h" -#include "usb_mouse.h" -#include "usb_extra.h" #include "usb_keycodes.h" #include "usb.h" #include "layer.h" #include "matrix_skel.h" #include "keymap_skel.h" -#include "controller.h" #include "key_process.h" - - -#define MOUSE_MOVE_UNIT 10 -#define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10) - -#ifndef MOUSE_DELAY_TIME -# define MOUSE_DELAY_TIME 255 +#ifdef MOUSEKEY_ENABLE +# include "mousekey.h" +#endif +#ifdef PS2_MOUSE_ENABLE +# include "ps2_mouse.h" +#endif +#ifdef USB_EXTRA_ENABLE +# include "usb_extra.h" +#endif +#ifdef USB_MOUSE_ENABLE +# include "usb_mouse.h" #endif -#define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 4)) // TODO: refactoring void proc_matrix(void) { - static int mouse_repeat = 0; - bool modified = false; - int key_index = 0; - uint8_t mouse_btn = 0; - int8_t mouse_x = 0; - int8_t mouse_y = 0; - int8_t mouse_vwheel = 0; - int8_t mouse_hwheel = 0; uint8_t fn_bits = 0; matrix_scan(); @@ -58,6 +51,7 @@ void proc_matrix(void) { return; } + usb_keyboard_swap_report(); usb_keyboard_clear_report(); for (int row = 0; row < matrix_rows(); row++) { for (int col = 0; col < matrix_cols(); col++) { @@ -68,25 +62,16 @@ void proc_matrix(void) { if (code == KB_NO) { // do nothing } else if (IS_MOD(code)) { - usb_keyboard_mods |= MOD_BIT(code); + usb_keyboard_add_mod(code); } else if (IS_FN(code)) { fn_bits |= FN_BIT(code); } else if (IS_MOUSE(code)) { - if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; - if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; - if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; - if (code == MS_RGHT) mouse_x += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL; - if (code == MS_BTN1) mouse_btn |= BIT_BTN1; - if (code == MS_BTN2) mouse_btn |= BIT_BTN2; - if (code == MS_BTN3) mouse_btn |= BIT_BTN3; - if (code == MS_BTN4) mouse_btn |= BIT_BTN4; - if (code == MS_BTN5) mouse_btn |= BIT_BTN5; - if (code == MS_WH_U) mouse_vwheel += 1; - if (code == MS_WH_D) mouse_vwheel -= 1; - if (code == MS_WH_L) mouse_hwheel -= 1; - if (code == MS_WH_R) mouse_hwheel += 1; +#ifdef MOUSEKEY_ENABLE + mousekey_decode(code); +#endif } +#ifdef USB_EXTRA_ENABLE // audio control & system control else if (code == KB_MUTE) { usb_extra_audio_send(AUDIO_MUTE); @@ -108,12 +93,11 @@ void proc_matrix(void) { } _delay_ms(1000); } +#endif // normal keys else { - if (key_index < 6) - usb_keyboard_keys[key_index] = code; - key_index++; + usb_keyboard_add_key(code); } } } @@ -129,24 +113,65 @@ void proc_matrix(void) { layer_switching(fn_bits); // TODO: clean code - // when 4 left modifier keys down + // special mode for control, develop and debug if (keymap_is_special_mode(fn_bits)) { - switch (usb_keyboard_keys[0]) { + switch (usb_keyboard_get_key()) { case KB_H: // help print_enable = true; print("b: jump to bootloader\n"); - print("d: debug print toggle\n"); - print("x: matrix debug toggle\n"); - print("k: keyboard debug toggle\n"); - print("m: mouse debug toggle\n"); - print("p: print enable toggle\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("r: print registers\n"); + print("s: print status\n"); + print("`: toggle protcol(boot/report)\n"); +#ifdef USB_NKRO_ENABLE + print("n: toggle USB_NKRO\n"); +#endif print("ESC: power down/wake up\n"); +#ifdef PS2_MOUSE_ENABLE + print("1: ps2_mouse_init \n"); + print("2: ps2_mouse_read \n"); + print("3: ps2_mouse: on/off toggle \n"); +#endif _delay_ms(500); print_enable = false; break; +#ifdef PS2_MOUSE_ENABLE + case KB_1: + usb_keyboard_clear_report(); + usb_keyboard_send(); + print_enable = true; + print("ps2_mouse_init...\n"); + _delay_ms(500); + ps2_mouse_init(); + break; + case KB_2: + usb_keyboard_clear_report(); + usb_keyboard_send(); + print_enable = true; + print("ps2_mouse_read[btn x y]: "); + _delay_ms(100); + ps2_mouse_read(); + phex(ps2_mouse_btn); print(" "); + phex(ps2_mouse_x); print(" "); + phex(ps2_mouse_y); print("\n"); + print("ps2_mouse_error_count: "); phex(ps2_mouse_error_count); print("\n"); + break; + case KB_3: + ps2_mouse_enable = !ps2_mouse_enable; + print("ps2_mouse: "); + if (ps2_mouse_enable) + print("on"); + else + print("off"); + print("\n"); + _delay_ms(500); + break; +#endif case KB_B: // bootloader usb_keyboard_clear_report(); usb_keyboard_send(); @@ -230,13 +255,48 @@ void proc_matrix(void) { } _delay_ms(1000); break; - case KB_R: + case KB_S: usb_keyboard_clear_report(); usb_keyboard_send(); + 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"); +#ifdef USB_MOUSE_ENABLE + print("usb_mouse_protocol:"); phex(usb_mouse_protocol); print("\n"); +#endif + if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n"); + _delay_ms(500); + break; + case KB_GRV: + usb_keyboard_clear_report(); + usb_keyboard_send(); + usb_keyboard_protocol = !usb_keyboard_protocol; + print("keyboard protcol: "); + if (usb_keyboard_protocol) print("report"); else print("boot"); + print("\n"); + +#ifdef USB_MOUSE_ENABLE + usb_mouse_protocol = !usb_mouse_protocol; + print("mouse protcol: "); + if (usb_mouse_protocol) print("report"); else print("boot"); + print("\n"); +#endif + _delay_ms(1000); + break; +#ifdef USB_NKRO_ENABLE + case KB_N: + usb_keyboard_clear_report(); + usb_keyboard_send(); + usb_keyboard_nkro = !usb_keyboard_nkro; + if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n"); _delay_ms(1000); break; +#endif +#ifdef USB_EXTRA_ENABLE case KB_ESC: usb_keyboard_clear_report(); usb_keyboard_send(); @@ -247,32 +307,23 @@ void proc_matrix(void) { } _delay_ms(1000); break; +#endif } } - // send mouse packet to host - if (mouse_x || mouse_y || mouse_vwheel || mouse_hwheel || mouse_btn != mouse_buttons) { - mouse_buttons = mouse_btn; - if (mouse_x && mouse_y) - usb_mouse_move(mouse_x*0.7, mouse_y*0.7, mouse_vwheel, mouse_hwheel); - else - usb_mouse_move(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel); - usb_mouse_print(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel); - - // acceleration - _delay_ms(MOUSE_DELAY_MS); - mouse_repeat++; - } else { - mouse_repeat = 0; - } - - - // send key packet to host if (modified) { - if (key_index > 6) { - //Rollover - } usb_keyboard_send(); } + +#ifdef MOUSEKEY_ENABLE + // mouse keys + mousekey_usb_send(); +#endif + +#ifdef PS2_MOUSE_ENABLE + // ps2 mouse + if (ps2_mouse_read() == 0) + ps2_mouse_usb_send(); +#endif }