aboutsummaryrefslogtreecommitdiff
path: root/keyboard/hhkb/keymap.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-02-13 11:20:47 +0900
committertmk <nobody@nowhere>2013-02-13 11:20:47 +0900
commit63c03dc137afe6600156a060b592662feaad0cdc (patch)
treec69cb8e797ac407028426a96dfebd56cf29211e3 /keyboard/hhkb/keymap.c
parent48e6d0848cdeac26ffab101ea2ef48e5ac60acd3 (diff)
downloadqmk_firmware-63c03dc137afe6600156a060b592662feaad0cdc.tar.gz
qmk_firmware-63c03dc137afe6600156a060b592662feaad0cdc.zip
Change keymap API
Diffstat (limited to 'keyboard/hhkb/keymap.c')
-rw-r--r--keyboard/hhkb/keymap.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
index 65ef89ad7..a5b6d3ace 100644
--- a/keyboard/hhkb/keymap.c
+++ b/keyboard/hhkb/keymap.c
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24#include "keycode.h" 24#include "keycode.h"
25#include "action.h" 25#include "action.h"
26#include "action_macro.h" 26#include "action_macro.h"
27#include "report.h"
27#include "host.h" 28#include "host.h"
28#include "debug.h" 29#include "debug.h"
29#include "keymap.h" 30#include "keymap.h"
@@ -48,7 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
48} 49}
49 50
50 51
51// TODO: use [1] = KEYMAP(...) to prevent from changing index of element?
52static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 52static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
53 /* Layer 0: Default Layer 53 /* Layer 0: Default Layer
54 * ,-----------------------------------------------------------. 54 * ,-----------------------------------------------------------.
@@ -309,40 +309,37 @@ void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt)
309 } 309 }
310} 310}
311 311
312/* convert keycode to action */ 312
313action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { 313
314 uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)])); 314/* translates key to keycode */
315uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
316{
317 return pgm_read_byte(&keymaps[(layer)][(key.pos.row)][(key.pos.col)]);
318}
319
320/* translates Fn index to action */
321action_t keymap_fn_to_action(uint8_t keycode)
322{
315 action_t action; 323 action_t action;
316 switch (key) { 324 if (FN_INDEX(keycode) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
317 case KC_A ... KC_EXSEL: 325 action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
318 action.code = ACTION_KEY(key); 326 } else {
319 break; 327 action.code = ACTION_NO;
320 case KC_LCTRL ... KC_LGUI: 328 }
321 action.code = ACTION_LMOD(key); 329 return action;
322 break; 330}
323 case KC_RCTRL ... KC_RGUI: 331
324 action.code = ACTION_RMOD(key); 332/* convert key to action */
325 break; 333action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
326 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: 334{
327 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(key)); 335 key_t key;
328 break; 336 key.pos.row = row;
329 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES: 337 key.pos.col = col;
330 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(key)); 338 uint8_t keycode = keymap_key_to_keycode(layer, key);
331 break; 339 switch (keycode) {
332 case KC_MS_UP ... KC_MS_ACCEL2:
333 action.code = ACTION_MOUSEKEY(key);
334 break;
335 case KC_FN0 ... KC_FN31: 340 case KC_FN0 ... KC_FN31:
336 if (FN_INDEX(key) < sizeof(fn_actions) / sizeof(fn_actions[0])) { 341 return keymap_fn_to_action(keycode);
337 action.code = pgm_read_word(&fn_actions[FN_INDEX(key)]);
338 } else {
339 action.code = ACTION_NO;
340 }
341 break;
342 case KC_NO ... KC_UNDEFINED:
343 default: 342 default:
344 action.code = ACTION_NO; 343 return keymap_keycode_to_action(keycode);
345 break;
346 } 344 }
347 return action;
348} 345}