Commands for reading and setting keyboard map

This commit is contained in:
Jeremy Soller
2020-09-15 13:19:27 -06:00
committed by Jeremy Soller
parent 432c4f64d2
commit de26cdfa74
4 changed files with 157 additions and 32 deletions

View File

@ -6,6 +6,7 @@
#ifndef __SCRATCH__
#include <board/scratch.h>
#include <board/keymap.h>
#endif
#include <board/smfi.h>
#include <common/command.h>
@ -178,6 +179,39 @@ static enum Result cmd_fan_set(void) {
// Failed if fan not found
return RES_ERR;
}
static enum Result cmd_keymap_get(void) {
int layer = smfi_cmd[2];
int output = smfi_cmd[3];
int input = smfi_cmd[4];
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
uint16_t key = KEYMAP[layer][output][input];
smfi_cmd[5] = (uint8_t)key;
smfi_cmd[6] = (uint8_t)(key >> 8);
return RES_OK;
}
// Failed if keyboard mapping not found
return RES_ERR;
}
static enum Result cmd_keymap_set(void) {
int layer = smfi_cmd[2];
int output = smfi_cmd[3];
int input = smfi_cmd[4];
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
uint16_t key =
((uint16_t)smfi_cmd[5]) |
(((uint16_t)smfi_cmd[6]) << 8);
KEYMAP[layer][output][input] = key;
return RES_OK;
}
// Failed if keyboard mapping not found
return RES_ERR;
}
#endif
// Set a watchdog timer of 10 seconds
@ -230,6 +264,12 @@ void smfi_event(void) {
case CMD_FAN_SET:
smfi_cmd[1] = cmd_fan_set();
break;
case CMD_KEYMAP_GET:
smfi_cmd[1] = cmd_keymap_get();
break;
case CMD_KEYMAP_SET:
smfi_cmd[1] = cmd_keymap_set();
break;
#endif // __SCRATCH__
default:
// Command not found