diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/command.c | 77 | ||||
| -rw-r--r-- | common/command.h | 4 | ||||
| -rw-r--r-- | common/debug.h | 2 | ||||
| -rw-r--r-- | common/keyboard.c | 28 | ||||
| -rw-r--r-- | common/matrix.h | 2 | ||||
| -rw-r--r-- | common/mousekey.c | 2 |
6 files changed, 64 insertions, 51 deletions
diff --git a/common/command.c b/common/command.c index 16c6cfb88..0ad06e65b 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -24,9 +24,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | #include "util.h" | 24 | #include "util.h" |
| 25 | #include "timer.h" | 25 | #include "timer.h" |
| 26 | #include "keyboard.h" | 26 | #include "keyboard.h" |
| 27 | #include "matrix.h" | ||
| 28 | #include "bootloader.h" | 27 | #include "bootloader.h" |
| 29 | #include "command.h" | 28 | #include "command.h" |
| 29 | #ifdef MOUSEKEY_ENABLE | ||
| 30 | #include "mousekey.h" | ||
| 31 | #endif | ||
| 30 | 32 | ||
| 31 | #ifdef HOST_PJRC | 33 | #ifdef HOST_PJRC |
| 32 | # include "usb_keyboard.h" | 34 | # include "usb_keyboard.h" |
| @@ -40,44 +42,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 40 | #endif | 42 | #endif |
| 41 | 43 | ||
| 42 | 44 | ||
| 43 | static uint8_t command_common(void); | 45 | static bool command_common(uint8_t code); |
| 44 | static void help(void); | 46 | static void help(void); |
| 45 | static void switch_layer(uint8_t layer); | 47 | static void switch_layer(uint8_t layer); |
| 48 | static void clear_keyboard(void); | ||
| 46 | 49 | ||
| 47 | static bool last_print_enable; | 50 | static bool last_print_enable; |
| 48 | 51 | ||
| 49 | uint8_t command_proc(void) | ||
| 50 | { | ||
| 51 | uint8_t processed = 0; | ||
| 52 | last_print_enable = print_enable; | ||
| 53 | 52 | ||
| 53 | bool command_proc(uint8_t code) | ||
| 54 | { | ||
| 54 | if (!IS_COMMAND()) | 55 | if (!IS_COMMAND()) |
| 55 | return 0; | 56 | return false; |
| 56 | 57 | ||
| 58 | last_print_enable = print_enable; | ||
| 57 | print_enable = true; | 59 | print_enable = true; |
| 58 | if (command_extra() || command_common()) { | 60 | if (command_extra(code) || command_common(code)) { |
| 59 | processed = 1; | ||
| 60 | _delay_ms(500); | 61 | _delay_ms(500); |
| 62 | return true; | ||
| 61 | } | 63 | } |
| 62 | print_enable = last_print_enable; | 64 | print_enable = last_print_enable; |
| 63 | return processed; | 65 | return false; |
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | /* This allows to define extra commands. return 0 when not processed. */ | 68 | /* This allows to define extra commands. return 0 when not processed. */ |
| 67 | uint8_t command_extra(void) __attribute__ ((weak)); | 69 | bool command_extra(uint8_t code) __attribute__ ((weak)); |
| 68 | uint8_t command_extra(void) | 70 | bool command_extra(uint8_t code) |
| 69 | { | 71 | { |
| 70 | return 0; | 72 | return false; |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | 75 | ||
| 74 | static uint8_t command_common(void) | 76 | static bool command_common(uint8_t code) |
| 75 | { | 77 | { |
| 76 | switch (host_get_first_key()) { | 78 | switch (code) { |
| 77 | case KC_H: | 79 | case KC_H: |
| 78 | help(); | 80 | help(); |
| 79 | break; | 81 | break; |
| 80 | case KC_B: | 82 | case KC_DEL: |
| 83 | clear_keyboard(); | ||
| 81 | print("jump to bootloader... "); | 84 | print("jump to bootloader... "); |
| 82 | _delay_ms(1000); | 85 | _delay_ms(1000); |
| 83 | bootloader_jump(); // not return | 86 | bootloader_jump(); // not return |
| @@ -179,34 +182,34 @@ static uint8_t command_common(void) | |||
| 179 | #endif | 182 | #endif |
| 180 | break; | 183 | break; |
| 181 | #endif | 184 | #endif |
| 182 | case KC_BSPC: | ||
| 183 | matrix_init(); | ||
| 184 | print("clear matrix\n"); | ||
| 185 | break; | ||
| 186 | case KC_0: | 185 | case KC_0: |
| 186 | case KC_F10: | ||
| 187 | switch_layer(0); | 187 | switch_layer(0); |
| 188 | break; | 188 | break; |
| 189 | case KC_1: | 189 | case KC_1: |
| 190 | case KC_F1: | ||
| 190 | switch_layer(1); | 191 | switch_layer(1); |
| 191 | break; | 192 | break; |
| 192 | case KC_2: | 193 | case KC_2: |
| 194 | case KC_F2: | ||
| 193 | switch_layer(2); | 195 | switch_layer(2); |
| 194 | break; | 196 | break; |
| 195 | case KC_3: | 197 | case KC_3: |
| 198 | case KC_F3: | ||
| 196 | switch_layer(3); | 199 | switch_layer(3); |
| 197 | break; | 200 | break; |
| 198 | case KC_4: | 201 | case KC_4: |
| 202 | case KC_F4: | ||
| 199 | switch_layer(4); | 203 | switch_layer(4); |
| 200 | break; | 204 | break; |
| 201 | default: | 205 | default: |
| 202 | return 0; | 206 | return false; |
| 203 | } | 207 | } |
| 204 | return 1; | 208 | return true; |
| 205 | } | 209 | } |
| 206 | 210 | ||
| 207 | static void help(void) | 211 | static void help(void) |
| 208 | { | 212 | { |
| 209 | print("b: jump to bootloader\n"); | ||
| 210 | print("d: toggle debug enable\n"); | 213 | print("d: toggle debug enable\n"); |
| 211 | print("x: toggle matrix debug\n"); | 214 | print("x: toggle matrix debug\n"); |
| 212 | print("k: toggle keyboard debug\n"); | 215 | print("k: toggle keyboard debug\n"); |
| @@ -215,16 +218,16 @@ static void help(void) | |||
| 215 | print("v: print version\n"); | 218 | print("v: print version\n"); |
| 216 | print("t: print timer count\n"); | 219 | print("t: print timer count\n"); |
| 217 | print("s: print status\n"); | 220 | print("s: print status\n"); |
| 221 | print("ESC: power down/wake up\n"); | ||
| 222 | print("0/F10: switch to Layer0 \n"); | ||
| 223 | print("1/F1: switch to Layer1 \n"); | ||
| 224 | print("2/F2: switch to Layer2 \n"); | ||
| 225 | print("3/F3: switch to Layer3 \n"); | ||
| 226 | print("4/F4: switch to Layer4 \n"); | ||
| 218 | #ifdef NKRO_ENABLE | 227 | #ifdef NKRO_ENABLE |
| 219 | print("n: toggle NKRO\n"); | 228 | print("n: toggle NKRO\n"); |
| 220 | #endif | 229 | #endif |
| 221 | print("Backspace: clear matrix\n"); | 230 | print("DEL: jump to bootloader\n"); |
| 222 | print("ESC: power down/wake up\n"); | ||
| 223 | print("0: switch to Layer0 \n"); | ||
| 224 | print("1: switch to Layer1 \n"); | ||
| 225 | print("2: switch to Layer2 \n"); | ||
| 226 | print("3: switch to Layer3 \n"); | ||
| 227 | print("4: switch to Layer4 \n"); | ||
| 228 | } | 231 | } |
| 229 | 232 | ||
| 230 | static void switch_layer(uint8_t layer) | 233 | static void switch_layer(uint8_t layer) |
| @@ -235,3 +238,17 @@ static void switch_layer(uint8_t layer) | |||
| 235 | default_layer = layer; | 238 | default_layer = layer; |
| 236 | print("switch to Layer: "); phex(layer); print("\n"); | 239 | print("switch to Layer: "); phex(layer); print("\n"); |
| 237 | } | 240 | } |
| 241 | |||
| 242 | static void clear_keyboard(void) | ||
| 243 | { | ||
| 244 | host_clear_keys(); | ||
| 245 | host_send_keyboard_report(); | ||
| 246 | |||
| 247 | host_system_send(0); | ||
| 248 | host_consumer_send(0); | ||
| 249 | |||
| 250 | #ifdef MOUSEKEY_ENABLE | ||
| 251 | mousekey_clear(); | ||
| 252 | mousekey_send(); | ||
| 253 | #endif | ||
| 254 | } | ||
diff --git a/common/command.h b/common/command.h index 4888f5ee0..dafd4d0f3 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/>. | |||
| 18 | #ifndef COMMAND_H | 18 | #ifndef COMMAND_H |
| 19 | #define COMMAND | 19 | #define COMMAND |
| 20 | 20 | ||
| 21 | uint8_t command_proc(void); | 21 | bool command_proc(uint8_t code); |
| 22 | /* This allows to extend commands. Return 0 when command is not processed. */ | 22 | /* This allows to extend commands. Return 0 when command is not processed. */ |
| 23 | uint8_t command_extra(void); | 23 | bool command_extra(uint8_t code); |
| 24 | 24 | ||
| 25 | #endif | 25 | #endif |
diff --git a/common/debug.h b/common/debug.h index 9cc8d882f..1d56e21f7 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/>. | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | #define debug(s) if(debug_enable) print_P(PSTR(s)) | 25 | #define debug(s) if(debug_enable) print_P(PSTR(s)) |
| 26 | #define debug_P(s) if(debug_enable) print_P(s) | ||
| 27 | #define debug_S(s) if(debug_enable) print_S(s) | ||
| 26 | #define debug_hex(c) if(debug_enable) phex(c) | 28 | #define debug_hex(c) if(debug_enable) phex(c) |
| 27 | #define debug_hex16(i) if(debug_enable) phex16(i) | 29 | #define debug_hex16(i) if(debug_enable) phex16(i) |
| 28 | #define debug_bin(c) if(debug_enable) pbin(c) | 30 | #define debug_bin(c) if(debug_enable) pbin(c) |
diff --git a/common/keyboard.c b/common/keyboard.c index be01e5540..c7ea2b840 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
| @@ -28,9 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 28 | #ifdef MOUSEKEY_ENABLE | 28 | #ifdef MOUSEKEY_ENABLE |
| 29 | #include "mousekey.h" | 29 | #include "mousekey.h" |
| 30 | #endif | 30 | #endif |
| 31 | #ifdef EXTRAKEY_ENABLE | ||
| 32 | #include <util/delay.h> | ||
| 33 | #endif | ||
| 34 | 31 | ||
| 35 | 32 | ||
| 36 | #define LAYER_DELAY 250 | 33 | #define LAYER_DELAY 250 |
| @@ -154,8 +151,12 @@ static bool layer_switch_off(uint8_t code) | |||
| 154 | static void register_code(uint8_t code) | 151 | static void register_code(uint8_t code) |
| 155 | { | 152 | { |
| 156 | if IS_KEY(code) { | 153 | if IS_KEY(code) { |
| 157 | host_add_key(code); | 154 | if (command_proc(code)) { |
| 158 | host_send_keyboard_report(); | 155 | //clear_keyboard(); |
| 156 | } else { | ||
| 157 | host_add_key(code); | ||
| 158 | host_send_keyboard_report(); | ||
| 159 | } | ||
| 159 | } | 160 | } |
| 160 | else if IS_MOD(code) { | 161 | else if IS_MOD(code) { |
| 161 | host_add_mod_bit(MOD_BIT(code)); | 162 | host_add_mod_bit(MOD_BIT(code)); |
| @@ -330,9 +331,9 @@ static void unregister_code(uint8_t code) | |||
| 330 | * Ld: Switch back to default layer(*unregister* all keys but modifiers) | 331 | * Ld: Switch back to default layer(*unregister* all keys but modifiers) |
| 331 | */ | 332 | */ |
| 332 | #define NEXT(state) do { \ | 333 | #define NEXT(state) do { \ |
| 333 | debug("NEXT: "); print_P(state_str(kbdstate)); \ | 334 | debug("NEXT: "); debug_P(state_str(kbdstate)); \ |
| 334 | kbdstate = state; \ | 335 | kbdstate = state; \ |
| 335 | debug(" -> "); print_P(state_str(kbdstate)); debug("\n"); \ | 336 | debug(" -> "); debug_P(state_str(kbdstate)); debug("\n"); \ |
| 336 | } while (0) | 337 | } while (0) |
| 337 | 338 | ||
| 338 | static inline void process_key(keyevent_t event) | 339 | static inline void process_key(keyevent_t event) |
| @@ -342,7 +343,7 @@ static inline void process_key(keyevent_t event) | |||
| 342 | 343 | ||
| 343 | uint8_t tmp_mods; | 344 | uint8_t tmp_mods; |
| 344 | 345 | ||
| 345 | debug("state: "); print_P(state_str(kbdstate)); | 346 | debug("state: "); debug_P(state_str(kbdstate)); |
| 346 | debug(" kind: "); debug_hex(kind); | 347 | debug(" kind: "); debug_hex(kind); |
| 347 | debug(" code: "); debug_hex(code); | 348 | debug(" code: "); debug_hex(code); |
| 348 | if (event.pressed) { debug("d"); } else { debug("u"); } | 349 | if (event.pressed) { debug("d"); } else { debug("u"); } |
| @@ -554,18 +555,11 @@ void keyboard_task(void) | |||
| 554 | matrix_row_t matrix_change = 0; | 555 | matrix_row_t matrix_change = 0; |
| 555 | 556 | ||
| 556 | matrix_scan(); | 557 | matrix_scan(); |
| 557 | if (command_proc()) { | ||
| 558 | debug("COMMAND\n"); | ||
| 559 | // TODO: COMMAND state? | ||
| 560 | clear_keyboard(); | ||
| 561 | return; | ||
| 562 | } | ||
| 563 | |||
| 564 | for (int r = 0; r < MATRIX_ROWS; r++) { | 558 | for (int r = 0; r < MATRIX_ROWS; r++) { |
| 565 | matrix_row = matrix_get_row(r); | 559 | matrix_row = matrix_get_row(r); |
| 566 | matrix_change = matrix_row ^ matrix_prev[r]; | 560 | matrix_change = matrix_row ^ matrix_prev[r]; |
| 567 | if (matrix_change) { | 561 | if (matrix_change) { |
| 568 | if (debug_matrix) matrix_print(); | 562 | matrix_debug(); |
| 569 | 563 | ||
| 570 | for (int c = 0; c < MATRIX_COLS; c++) { | 564 | for (int c = 0; c < MATRIX_COLS; c++) { |
| 571 | if (matrix_change & (1<<c)) { | 565 | if (matrix_change & (1<<c)) { |
| @@ -618,7 +612,7 @@ void keyboard_task(void) | |||
| 618 | current_layer = default_layer; | 612 | current_layer = default_layer; |
| 619 | } | 613 | } |
| 620 | } | 614 | } |
| 621 | 615 | ||
| 622 | return; | 616 | return; |
| 623 | } | 617 | } |
| 624 | 618 | ||
diff --git a/common/matrix.h b/common/matrix.h index b3332d5ff..91231e765 100644 --- a/common/matrix.h +++ b/common/matrix.h | |||
| @@ -54,7 +54,7 @@ matrix_row_t matrix_get_row(uint8_t row); | |||
| 54 | /* count keys pressed */ | 54 | /* count keys pressed */ |
| 55 | uint8_t matrix_key_count(void); | 55 | uint8_t matrix_key_count(void); |
| 56 | /* print matrix for debug */ | 56 | /* print matrix for debug */ |
| 57 | void matrix_print(void); | 57 | void matrix_debug(void); |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | #endif | 60 | #endif |
diff --git a/common/mousekey.c b/common/mousekey.c index 353890a16..99e6d34ff 100644 --- a/common/mousekey.c +++ b/common/mousekey.c | |||
| @@ -103,7 +103,7 @@ static uint8_t wheel_unit(void) | |||
| 103 | if (mousekey_repeat > mk_time_to_max) { | 103 | if (mousekey_repeat > mk_time_to_max) { |
| 104 | unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; | 104 | unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; |
| 105 | } else { | 105 | } else { |
| 106 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_time_to_max; | 106 | unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; |
| 107 | } | 107 | } |
| 108 | if (unit == 0) return 1; | 108 | if (unit == 0) return 1; |
| 109 | return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : unit); | 109 | return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : unit); |
