diff options
| -rw-r--r-- | common.mk | 1 | ||||
| -rw-r--r-- | common/action.c | 2 | ||||
| -rw-r--r-- | common/action.h | 24 | ||||
| -rw-r--r-- | common/action_macro.c | 67 | ||||
| -rw-r--r-- | common/action_macro.h | 107 | ||||
| -rw-r--r-- | common/keymap.c | 2 | ||||
| -rw-r--r-- | common/keymap.h | 3 | ||||
| -rw-r--r-- | keyboard/hhkb/keymap.c | 42 |
8 files changed, 226 insertions, 22 deletions
| @@ -2,6 +2,7 @@ COMMON_DIR = common | |||
| 2 | SRC += $(COMMON_DIR)/host.c \ | 2 | SRC += $(COMMON_DIR)/host.c \ |
| 3 | $(COMMON_DIR)/keyboard.c \ | 3 | $(COMMON_DIR)/keyboard.c \ |
| 4 | $(COMMON_DIR)/action.c \ | 4 | $(COMMON_DIR)/action.c \ |
| 5 | $(COMMON_DIR)/action_macro.c \ | ||
| 5 | $(COMMON_DIR)/keymap.c \ | 6 | $(COMMON_DIR)/keymap.c \ |
| 6 | $(COMMON_DIR)/command.c \ | 7 | $(COMMON_DIR)/command.c \ |
| 7 | $(COMMON_DIR)/timer.c \ | 8 | $(COMMON_DIR)/timer.c \ |
diff --git a/common/action.c b/common/action.c index cb44e272a..301a9b6a0 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -620,7 +620,7 @@ static void process_action(keyrecord_t *record) | |||
| 620 | break; | 620 | break; |
| 621 | case ACT_FUNCTION: | 621 | case ACT_FUNCTION: |
| 622 | // TODO | 622 | // TODO |
| 623 | keymap_call_function(record, action.func.id); | 623 | keymap_call_function(record, action.func.id, action.func.opt); |
| 624 | break; | 624 | break; |
| 625 | default: | 625 | default: |
| 626 | break; | 626 | break; |
diff --git a/common/action.h b/common/action.h index b657aa540..b1e958a26 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -49,27 +49,27 @@ typedef union { | |||
| 49 | uint16_t code; | 49 | uint16_t code; |
| 50 | struct action_kind { | 50 | struct action_kind { |
| 51 | uint16_t param :12; | 51 | uint16_t param :12; |
| 52 | uint16_t id :4; | 52 | uint8_t id :4; |
| 53 | } kind; | 53 | } kind; |
| 54 | struct action_key { | 54 | struct action_key { |
| 55 | uint16_t code :8; | 55 | uint8_t code :8; |
| 56 | uint16_t mods :4; | 56 | uint8_t mods :4; |
| 57 | uint16_t kind :4; | 57 | uint8_t kind :4; |
| 58 | } key; | 58 | } key; |
| 59 | struct action_layer { | 59 | struct action_layer { |
| 60 | uint16_t code :8; | 60 | uint8_t code :8; |
| 61 | uint16_t val :4; | 61 | uint8_t val :4; |
| 62 | uint16_t kind :4; | 62 | uint8_t kind :4; |
| 63 | } layer; | 63 | } layer; |
| 64 | struct action_usage { | 64 | struct action_usage { |
| 65 | uint16_t code :10; | 65 | uint16_t code :10; |
| 66 | uint16_t page :2; | 66 | uint8_t page :2; |
| 67 | uint16_t kind :4; | 67 | uint8_t kind :4; |
| 68 | } usage; | 68 | } usage; |
| 69 | struct action_command { | 69 | struct action_command { |
| 70 | uint16_t id :8; | 70 | uint8_t id :8; |
| 71 | uint16_t opt :4; | 71 | uint8_t opt :4; |
| 72 | uint16_t kind :4; | 72 | uint8_t kind :4; |
| 73 | } command; | 73 | } command; |
| 74 | struct action_function { | 74 | struct action_function { |
| 75 | uint8_t id :8; | 75 | uint8_t id :8; |
diff --git a/common/action_macro.c b/common/action_macro.c new file mode 100644 index 000000000..72859c0dd --- /dev/null +++ b/common/action_macro.c | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <util/delay.h> | ||
| 18 | #include "debug.h" | ||
| 19 | #include "action.h" | ||
| 20 | #include "action_macro.h" | ||
| 21 | |||
| 22 | |||
| 23 | #define MACRO_READ() (macro = pgm_read_byte(macro_p++)) | ||
| 24 | void action_macro_play(const prog_macro_t *macro_p) | ||
| 25 | { | ||
| 26 | macro_t macro = END; | ||
| 27 | uint8_t interval = 0; | ||
| 28 | |||
| 29 | if (!macro_p) return; | ||
| 30 | while (true) { | ||
| 31 | switch (MACRO_READ()) { | ||
| 32 | case INTERVAL: | ||
| 33 | interval = MACRO_READ(); | ||
| 34 | debug("INTERVAL("); debug_dec(interval); debug(")\n"); | ||
| 35 | break; | ||
| 36 | case WAIT: | ||
| 37 | MACRO_READ(); | ||
| 38 | debug("WAIT("); debug_dec(macro); debug(")\n"); | ||
| 39 | { uint8_t ms = macro; while (ms--) _delay_ms(1); } | ||
| 40 | break; | ||
| 41 | case MODS_DOWN: | ||
| 42 | MACRO_READ(); | ||
| 43 | debug("MODS_DOWN("); debug_hex(macro); debug(")\n"); | ||
| 44 | debug("MODS_UP("); debug_hex(macro); debug(")\n"); | ||
| 45 | add_mods(macro); | ||
| 46 | break; | ||
| 47 | case MODS_UP: | ||
| 48 | MACRO_READ(); | ||
| 49 | debug("MODS_UP("); debug_hex(macro); debug(")\n"); | ||
| 50 | del_mods(macro); | ||
| 51 | break; | ||
| 52 | case 0x04 ... 0x73: | ||
| 53 | debug("DOWN("); debug_hex(macro); debug(")\n"); | ||
| 54 | register_code(macro); | ||
| 55 | break; | ||
| 56 | case 0x84 ... 0xF3: | ||
| 57 | debug("UP("); debug_hex(macro); debug(")\n"); | ||
| 58 | unregister_code(macro&0x7F); | ||
| 59 | break; | ||
| 60 | case END: | ||
| 61 | default: | ||
| 62 | return; | ||
| 63 | } | ||
| 64 | // interval | ||
| 65 | { uint8_t ms = interval; while (ms--) _delay_ms(1); } | ||
| 66 | } | ||
| 67 | } | ||
diff --git a/common/action_macro.h b/common/action_macro.h new file mode 100644 index 000000000..3833c7c8a --- /dev/null +++ b/common/action_macro.h | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #ifndef ACTION_MACRO_H | ||
| 18 | #define ACTION_MACRO_H | ||
| 19 | #include <stdint.h> | ||
| 20 | #include <avr/pgmspace.h> | ||
| 21 | |||
| 22 | |||
| 23 | typedef uint8_t macro_t; | ||
| 24 | typedef macro_t prog_macro_t PROGMEM; | ||
| 25 | |||
| 26 | |||
| 27 | void action_macro_play(const prog_macro_t *macro); | ||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | /* TODO: NOT FINISHED | ||
| 32 | normal mode command: | ||
| 33 | key(down): 0x04-7f/73(F24) | ||
| 34 | key(up): 0x84-ff | ||
| 35 | command: 0x00-03, 0x80-83(0x74-7f, 0xf4-ff) | ||
| 36 | mods down 0x00 | ||
| 37 | mods up 0x01 | ||
| 38 | wait 0x02 | ||
| 39 | interval 0x03 | ||
| 40 | extkey down 0x80 | ||
| 41 | extkey up 0x81 | ||
| 42 | ext commad 0x82 | ||
| 43 | ext mode 0x83 | ||
| 44 | end 0xff | ||
| 45 | |||
| 46 | extension mode command: NOT IMPLEMENTED | ||
| 47 | key down 0x00 | ||
| 48 | key up 0x01 | ||
| 49 | key down + wait | ||
| 50 | key up + wait | ||
| 51 | mods push | ||
| 52 | mods pop | ||
| 53 | wait | ||
| 54 | interval | ||
| 55 | if | ||
| 56 | loop | ||
| 57 | push | ||
| 58 | pop | ||
| 59 | all up | ||
| 60 | end | ||
| 61 | */ | ||
| 62 | enum macro_command_id{ | ||
| 63 | /* 0x00 - 0x03 */ | ||
| 64 | END = 0x00, | ||
| 65 | MODS_DOWN = 0x01, | ||
| 66 | MODS_UP = 0x02, | ||
| 67 | MODS_SET, | ||
| 68 | MODS_PUSH, | ||
| 69 | MODS_POP, | ||
| 70 | |||
| 71 | WAIT = 0x74, | ||
| 72 | INTERVAL, | ||
| 73 | /* 0x74 - 0x7f */ | ||
| 74 | /* 0x80 - 0x84 */ | ||
| 75 | |||
| 76 | EXT_DOWN, | ||
| 77 | EXT_UP, | ||
| 78 | EXT_WAIT, | ||
| 79 | EXT_INTERVAL, | ||
| 80 | COMPRESSION_MODE, | ||
| 81 | |||
| 82 | EXTENSION_MODE = 0xff, | ||
| 83 | }; | ||
| 84 | |||
| 85 | |||
| 86 | /* normal mode */ | ||
| 87 | #define DOWN(key) (key) | ||
| 88 | #define UP(key) ((key) | 0x80) | ||
| 89 | #define TYPE(key) (key), (key | 0x80) | ||
| 90 | #define MODS_DOWN(mods) MODS_DOWN, (mods) | ||
| 91 | #define MODS_UP(mods) MODS_UP, (mods) | ||
| 92 | #define WAIT(ms) WAIT, (ms) | ||
| 93 | #define INTERVAL(ms) INTERVAL, (ms) | ||
| 94 | |||
| 95 | #define D(key) DOWN(KC_##key) | ||
| 96 | #define U(key) UP(KC_##key) | ||
| 97 | #define T(key) TYPE(KC_##key) | ||
| 98 | #define MD(key) MODS_DOWN(MOD_BIT(KC_##key)) | ||
| 99 | #define MU(key) MODS_UP(MOD_BIT(KC_##key)) | ||
| 100 | #define W(ms) WAIT(ms) | ||
| 101 | #define I(ms) INTERVAL(ms) | ||
| 102 | |||
| 103 | |||
| 104 | /* extension mode */ | ||
| 105 | |||
| 106 | |||
| 107 | #endif /* ACTION_MACRO_H */ | ||
diff --git a/common/keymap.c b/common/keymap.c index 40d20f684..8302c2704 100644 --- a/common/keymap.c +++ b/common/keymap.c | |||
| @@ -68,6 +68,6 @@ action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) | |||
| 68 | #endif | 68 | #endif |
| 69 | 69 | ||
| 70 | __attribute__ ((weak)) | 70 | __attribute__ ((weak)) |
| 71 | void keymap_call_function(keyrecord_t *event, uint8_t id) | 71 | void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt) |
| 72 | { | 72 | { |
| 73 | } | 73 | } |
diff --git a/common/keymap.h b/common/keymap.h index e0fafeaf2..30d73f797 100644 --- a/common/keymap.h +++ b/common/keymap.h | |||
| @@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 23 | #include "action.h" | 23 | #include "action.h" |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | // TODO: move to action.h? | ||
| 26 | /* layer used currently */ | 27 | /* layer used currently */ |
| 27 | extern uint8_t current_layer; | 28 | extern uint8_t current_layer; |
| 28 | /* layer to return or start with */ | 29 | /* layer to return or start with */ |
| @@ -34,7 +35,7 @@ extern uint8_t default_layer; | |||
| 34 | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col); | 35 | action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col); |
| 35 | 36 | ||
| 36 | /* user defined special function */ | 37 | /* user defined special function */ |
| 37 | void keymap_call_function(keyrecord_t *record, uint8_t id); | 38 | void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt); |
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | #ifndef NO_LEGACY_KEYMAP_SUPPORT | 41 | #ifndef NO_LEGACY_KEYMAP_SUPPORT |
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c index e11b4563a..f2f21e8ce 100644 --- a/keyboard/hhkb/keymap.c +++ b/keyboard/hhkb/keymap.c | |||
| @@ -21,12 +21,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | #include <stdint.h> | 21 | #include <stdint.h> |
| 22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
| 23 | #include <avr/pgmspace.h> | 23 | #include <avr/pgmspace.h> |
| 24 | #include "host.h" | ||
| 25 | #include "keycode.h" | 24 | #include "keycode.h" |
| 26 | #include "print.h" | ||
| 27 | #include "debug.h" | ||
| 28 | #include "util.h" | ||
| 29 | #include "action.h" | 25 | #include "action.h" |
| 26 | #include "action_macro.h" | ||
| 27 | #include "host.h" | ||
| 28 | #include "debug.h" | ||
| 30 | #include "keymap.h" | 29 | #include "keymap.h" |
| 31 | 30 | ||
| 32 | 31 | ||
| @@ -69,7 +68,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 69 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ | 68 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ |
| 70 | FN6, A, S, D, F, G, H, J, K, L, FN3, QUOT,FN7, \ | 69 | FN6, A, S, D, F, G, H, J, K, L, FN3, QUOT,FN7, \ |
| 71 | FN8, Z, X, C, V, B, N, M, COMM,DOT, FN2, FN12,FN10, \ | 70 | FN8, Z, X, C, V, B, N, M, COMM,DOT, FN2, FN12,FN10, \ |
| 72 | LGUI,LALT, FN5, RALT,FN4), | 71 | LGUI,LALT, FN5, FN13,FN4), |
| 73 | 72 | ||
| 74 | /* Layer 1: HHKB mode (HHKB Fn) | 73 | /* Layer 1: HHKB mode (HHKB Fn) |
| 75 | * ,-----------------------------------------------------------. | 74 | * ,-----------------------------------------------------------. |
| @@ -162,6 +161,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 162 | enum function_id { | 161 | enum function_id { |
| 163 | LSHIFT_LPAREN, | 162 | LSHIFT_LPAREN, |
| 164 | RSHIFT_RPAREN, | 163 | RSHIFT_RPAREN, |
| 164 | MACRO = 0xff | ||
| 165 | }; | 165 | }; |
| 166 | 166 | ||
| 167 | /* | 167 | /* |
| @@ -172,7 +172,8 @@ static const uint16_t PROGMEM fn_actions[] = { | |||
| 172 | ACTION_LAYER_SET(1), // FN1 | 172 | ACTION_LAYER_SET(1), // FN1 |
| 173 | ACTION_LAYER_SET_TAP_KEY(2, KC_SLASH), // FN2 | 173 | ACTION_LAYER_SET_TAP_KEY(2, KC_SLASH), // FN2 |
| 174 | ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // FN3 | 174 | ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // FN3 |
| 175 | ACTION_LAYER_SET(3), // FN4 | 175 | //ACTION_LAYER_SET(3), // FN4 |
| 176 | ACTION_FUNCTION(MACRO, 0), // FN4 | ||
| 176 | ACTION_LAYER_SET_TAP_KEY(5, KC_SPC), // FN5 | 177 | ACTION_LAYER_SET_TAP_KEY(5, KC_SPC), // FN5 |
| 177 | ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // FN6 | 178 | ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // FN6 |
| 178 | ACTION_RMOD_TAP_KEY(KC_RCTL, KC_ENT), // FN7 | 179 | ACTION_RMOD_TAP_KEY(KC_RCTL, KC_ENT), // FN7 |
| @@ -183,12 +184,36 @@ static const uint16_t PROGMEM fn_actions[] = { | |||
| 183 | //ACTION_LAYER_BIT_TAP_TOGGLE(1), // FN10 | 184 | //ACTION_LAYER_BIT_TAP_TOGGLE(1), // FN10 |
| 184 | ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // FN11 | 185 | ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // FN11 |
| 185 | ACTION_FUNCTION_TAP(RSHIFT_RPAREN), // FN12 | 186 | ACTION_FUNCTION_TAP(RSHIFT_RPAREN), // FN12 |
| 187 | ACTION_FUNCTION(MACRO, 1), // FN13 | ||
| 186 | }; | 188 | }; |
| 187 | 189 | ||
| 190 | |||
| 191 | /* | ||
| 192 | * Macro definition | ||
| 193 | */ | ||
| 194 | #define MACRO(...) ({ static prog_macro_t _m[] PROGMEM = { __VA_ARGS__ }; _m; }) | ||
| 195 | #define MACRO_NONE 0 | ||
| 196 | static const prog_macro_t *get_macro(uint8_t id, bool pressed) | ||
| 197 | { | ||
| 198 | switch (id) { | ||
| 199 | case 0: | ||
| 200 | return (pressed ? | ||
| 201 | MACRO( MD(LSHIFT), D(D), END ) : | ||
| 202 | MACRO( U(D), MU(LSHIFT), END ) ); | ||
| 203 | case 1: | ||
| 204 | return (pressed ? | ||
| 205 | MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ) : | ||
| 206 | MACRO_NONE ); | ||
| 207 | } | ||
| 208 | return 0; | ||
| 209 | } | ||
| 210 | |||
| 211 | |||
| 212 | |||
| 188 | /* | 213 | /* |
| 189 | * user defined action function | 214 | * user defined action function |
| 190 | */ | 215 | */ |
| 191 | void keymap_call_function(keyrecord_t *record, uint8_t id) | 216 | void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt) |
| 192 | { | 217 | { |
| 193 | keyevent_t event = record->event; | 218 | keyevent_t event = record->event; |
| 194 | uint8_t tap_count = record->tap_count; | 219 | uint8_t tap_count = record->tap_count; |
| @@ -261,6 +286,9 @@ void keymap_call_function(keyrecord_t *record, uint8_t id) | |||
| 261 | } | 286 | } |
| 262 | } | 287 | } |
| 263 | break; | 288 | break; |
| 289 | case MACRO: | ||
| 290 | action_macro_play(get_macro(opt, event.pressed)); | ||
| 291 | break; | ||
| 264 | } | 292 | } |
| 265 | } | 293 | } |
| 266 | 294 | ||
