mirror of
https://github.com/openstenoproject/qmk
synced 2024-11-10 18:49:08 +00:00
Change keymap API
This commit is contained in:
parent
48e6d0848c
commit
63c03dc137
4 changed files with 112 additions and 98 deletions
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "keymap.h"
|
#include "keymap.h"
|
||||||
#include "report.h"
|
#include "report.h"
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
#include "action.h"
|
||||||
|
|
||||||
|
|
||||||
/* layer */
|
/* layer */
|
||||||
|
@ -24,46 +25,61 @@ uint8_t default_layer = 0;
|
||||||
uint8_t current_layer = 0;
|
uint8_t current_layer = 0;
|
||||||
|
|
||||||
|
|
||||||
|
action_t keymap_keycode_to_action(uint8_t keycode)
|
||||||
|
{
|
||||||
|
action_t action;
|
||||||
|
switch (keycode) {
|
||||||
|
case KC_A ... KC_EXSEL:
|
||||||
|
action.code = ACTION_KEY(keycode);
|
||||||
|
break;
|
||||||
|
case KC_LCTRL ... KC_LGUI:
|
||||||
|
action.code = ACTION_LMOD(keycode);
|
||||||
|
break;
|
||||||
|
case KC_RCTRL ... KC_RGUI:
|
||||||
|
action.code = ACTION_RMOD(keycode);
|
||||||
|
break;
|
||||||
|
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
|
||||||
|
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
|
||||||
|
break;
|
||||||
|
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
|
||||||
|
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
|
||||||
|
break;
|
||||||
|
case KC_MS_UP ... KC_MS_ACCEL2:
|
||||||
|
action.code = ACTION_MOUSEKEY(keycode);
|
||||||
|
break;
|
||||||
|
case KC_TRNS:
|
||||||
|
action.code = ACTION_TRANSPARENT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
action.code = ACTION_NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NO_LEGACY_KEYMAP_SUPPORT
|
#ifndef NO_LEGACY_KEYMAP_SUPPORT
|
||||||
/* legacy support with weak reference */
|
/* legacy support with weak reference */
|
||||||
__attribute__ ((weak))
|
__attribute__ ((weak))
|
||||||
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
|
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
|
||||||
{
|
{
|
||||||
/* convert from legacy keycode to action */
|
/* convert from legacy keycode to action */
|
||||||
uint8_t key = keymap_get_keycode(layer, row, col);
|
uint8_t keycode = keymap_get_keycode(layer, row, col);
|
||||||
action_t action;
|
action_t action;
|
||||||
switch (key) {
|
switch (keycode) {
|
||||||
case KC_A ... KC_EXSEL:
|
|
||||||
action.code = ACTION_KEY(key);
|
|
||||||
break;
|
|
||||||
case KC_LCTRL ... KC_LGUI:
|
|
||||||
action.code = ACTION_LMOD(key);
|
|
||||||
break;
|
|
||||||
case KC_RCTRL ... KC_RGUI:
|
|
||||||
action.code = ACTION_RMOD(key);
|
|
||||||
break;
|
|
||||||
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
|
|
||||||
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(key));
|
|
||||||
break;
|
|
||||||
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
|
|
||||||
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(key));
|
|
||||||
break;
|
|
||||||
case KC_MS_UP ... KC_MS_ACCEL2:
|
|
||||||
action.code = ACTION_MOUSEKEY(key);
|
|
||||||
break;
|
|
||||||
case KC_FN0 ... KC_FN31:
|
case KC_FN0 ... KC_FN31:
|
||||||
{
|
{
|
||||||
uint8_t layer = keymap_fn_layer(FN_INDEX(key));
|
uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
|
||||||
uint8_t code = keymap_fn_keycode(FN_INDEX(key));
|
uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
|
||||||
action.code = ACTION_LAYER_SET_TAP_KEY(layer, code);
|
if (key) {
|
||||||
|
action.code = ACTION_LAYER_SET_TAP_KEY(layer, key);
|
||||||
|
} else {
|
||||||
|
action.code = ACTION_LAYER_SET_MOMENTARY(layer);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case KC_NO ... KC_UNDEFINED:
|
|
||||||
default:
|
|
||||||
action.code = ACTION_NO;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return action;
|
return action;
|
||||||
|
default:
|
||||||
|
return keymap_keycode_to_action(keycode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,23 @@ extern uint8_t current_layer;
|
||||||
extern uint8_t default_layer;
|
extern uint8_t default_layer;
|
||||||
|
|
||||||
|
|
||||||
|
/* translates key_t to keycode */
|
||||||
|
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key);
|
||||||
|
/* translates keycode to action */
|
||||||
|
action_t keymap_keycode_to_action(uint8_t keycode);
|
||||||
|
/* translates Fn keycode to action */
|
||||||
|
action_t keymap_fn_to_action(uint8_t keycode);
|
||||||
|
|
||||||
|
|
||||||
/* action for key */
|
/* action for key */
|
||||||
// TODO: should use struct key_t?
|
// TODO: should use struct key_t? move to action.h?
|
||||||
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col);
|
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col);
|
||||||
|
|
||||||
/* user defined special function */
|
/* user defined special function */
|
||||||
void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt);
|
void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_LEGACY_KEYMAP_SUPPORT
|
#ifndef NO_LEGACY_KEYMAP_SUPPORT
|
||||||
/* keycode of key */
|
/* keycode of key */
|
||||||
uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col);
|
uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col);
|
||||||
|
|
|
@ -162,43 +162,35 @@ static const uint16_t PROGMEM fn_actions[] = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* convert keycode to action */
|
/* translates key to keycode */
|
||||||
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) {
|
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
|
||||||
uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)]));
|
{
|
||||||
|
return pgm_read_byte(&keymaps[(layer)][(key.pos.row)][(key.pos.col)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* translates Fn index to action */
|
||||||
|
action_t keymap_fn_to_action(uint8_t keycode)
|
||||||
|
{
|
||||||
action_t action;
|
action_t action;
|
||||||
switch (key) {
|
if (FN_INDEX(keycode) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
|
||||||
case KC_A ... KC_EXSEL:
|
action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
|
||||||
action.code = ACTION_KEY(key);
|
|
||||||
break;
|
|
||||||
case KC_LCTRL ... KC_LGUI:
|
|
||||||
action.code = ACTION_LMOD(key);
|
|
||||||
break;
|
|
||||||
case KC_RCTRL ... KC_RGUI:
|
|
||||||
action.code = ACTION_RMOD(key);
|
|
||||||
break;
|
|
||||||
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
|
|
||||||
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(key));
|
|
||||||
break;
|
|
||||||
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
|
|
||||||
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(key));
|
|
||||||
break;
|
|
||||||
case KC_MS_UP ... KC_MS_ACCEL2:
|
|
||||||
action.code = ACTION_MOUSEKEY(key);
|
|
||||||
break;
|
|
||||||
case KC_FN0 ... KC_FN31:
|
|
||||||
if (FN_INDEX(key) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
|
|
||||||
action.code = pgm_read_word(&fn_actions[FN_INDEX(key)]);
|
|
||||||
} else {
|
} else {
|
||||||
action.code = ACTION_NO;
|
action.code = ACTION_NO;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case KC_TRNS:
|
|
||||||
action.code = ACTION_TRANSPARENT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
action.code = ACTION_NO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* convert key to action */
|
||||||
|
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
|
||||||
|
{
|
||||||
|
key_t key;
|
||||||
|
key.pos.row = row;
|
||||||
|
key.pos.col = col;
|
||||||
|
uint8_t keycode = keymap_key_to_keycode(layer, key);
|
||||||
|
switch (keycode) {
|
||||||
|
case KC_FN0 ... KC_FN31:
|
||||||
|
return keymap_fn_to_action(keycode);
|
||||||
|
default:
|
||||||
|
return keymap_keycode_to_action(keycode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "action_macro.h"
|
#include "action_macro.h"
|
||||||
|
#include "report.h"
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "keymap.h"
|
#include "keymap.h"
|
||||||
|
@ -48,7 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: use [1] = KEYMAP(...) to prevent from changing index of element?
|
|
||||||
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
/* Layer 0: Default Layer
|
/* Layer 0: Default Layer
|
||||||
* ,-----------------------------------------------------------.
|
* ,-----------------------------------------------------------.
|
||||||
|
@ -309,40 +309,37 @@ void keymap_call_function(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert keycode to action */
|
|
||||||
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) {
|
|
||||||
uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)]));
|
/* translates key to keycode */
|
||||||
|
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
|
||||||
|
{
|
||||||
|
return pgm_read_byte(&keymaps[(layer)][(key.pos.row)][(key.pos.col)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* translates Fn index to action */
|
||||||
|
action_t keymap_fn_to_action(uint8_t keycode)
|
||||||
|
{
|
||||||
action_t action;
|
action_t action;
|
||||||
switch (key) {
|
if (FN_INDEX(keycode) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
|
||||||
case KC_A ... KC_EXSEL:
|
action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
|
||||||
action.code = ACTION_KEY(key);
|
|
||||||
break;
|
|
||||||
case KC_LCTRL ... KC_LGUI:
|
|
||||||
action.code = ACTION_LMOD(key);
|
|
||||||
break;
|
|
||||||
case KC_RCTRL ... KC_RGUI:
|
|
||||||
action.code = ACTION_RMOD(key);
|
|
||||||
break;
|
|
||||||
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
|
|
||||||
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(key));
|
|
||||||
break;
|
|
||||||
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
|
|
||||||
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(key));
|
|
||||||
break;
|
|
||||||
case KC_MS_UP ... KC_MS_ACCEL2:
|
|
||||||
action.code = ACTION_MOUSEKEY(key);
|
|
||||||
break;
|
|
||||||
case KC_FN0 ... KC_FN31:
|
|
||||||
if (FN_INDEX(key) < sizeof(fn_actions) / sizeof(fn_actions[0])) {
|
|
||||||
action.code = pgm_read_word(&fn_actions[FN_INDEX(key)]);
|
|
||||||
} else {
|
} else {
|
||||||
action.code = ACTION_NO;
|
action.code = ACTION_NO;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case KC_NO ... KC_UNDEFINED:
|
|
||||||
default:
|
|
||||||
action.code = ACTION_NO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* convert key to action */
|
||||||
|
action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
|
||||||
|
{
|
||||||
|
key_t key;
|
||||||
|
key.pos.row = row;
|
||||||
|
key.pos.col = col;
|
||||||
|
uint8_t keycode = keymap_key_to_keycode(layer, key);
|
||||||
|
switch (keycode) {
|
||||||
|
case KC_FN0 ... KC_FN31:
|
||||||
|
return keymap_fn_to_action(keycode);
|
||||||
|
default:
|
||||||
|
return keymap_keycode_to_action(keycode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue