Skip to content

Commit

Permalink
Add a FnLock key
Browse files Browse the repository at this point in the history
Implement a FnLock toggle that behaves as follows:

- Disabled: F1-F12 are normal
- Enabled: F1-F12 are the alternate function

Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd authored and jackpot51 committed Aug 1, 2023
1 parent b63e209 commit 0190701
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/board/system76/common/kbscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <board/acpi.h>
#include <board/fan.h>
#include <board/gpio.h>
#include <board/keymap.h>
#include <board/kbc.h>
#include <board/kbled.h>
#include <board/kbscan.h>
Expand Down Expand Up @@ -166,6 +167,12 @@ bool kbscan_press(uint16_t key, bool pressed, uint8_t *layer) {
pmc_swi();
}

if (key == K_FNLOCK && pressed) {
DEBUG("Toggling FnLock\n");
keymap_fnlock ^= 1;
return true;
}

switch (key & KT_MASK) {
case (KT_NORMAL):
if (kbscan_enabled) {
Expand Down Expand Up @@ -262,6 +269,7 @@ static inline bool key_should_repeat(uint16_t key) {
case K_CAMERA_TOGGLE:
case K_DISPLAY_TOGGLE:
case K_FAN_TOGGLE:
case K_FNLOCK:
case K_KBD_BKL:
case K_KBD_COLOR:
case K_KBD_TOGGLE:
Expand Down
4 changes: 4 additions & 0 deletions src/board/system76/common/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <board/flash.h>
#include <board/keymap.h>

bool keymap_fnlock = false;

uint16_t __xdata DYNAMIC_KEYMAP[KM_LAY][KM_OUT][KM_IN];

// Config is in the last sector of flash
Expand Down Expand Up @@ -69,6 +71,8 @@ bool keymap_save_config(void) {

bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) {
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
if (keymap_fnlock && keymap_is_f_key(output, input))
layer ^= 1;
*value = DYNAMIC_KEYMAP[layer][output][input];
return true;
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/common/include/common/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extern uint16_t __xdata DYNAMIC_KEYMAP[KM_LAY][KM_OUT][KM_IN];
#endif

#if HAVE_KEYMAP
// FnLock config
extern bool keymap_fnlock;

// Initialize the dynamic keymap
void keymap_init(void);
// Set the dynamic keymap to the default keymap
Expand Down Expand Up @@ -278,4 +281,9 @@ uint16_t keymap_translate(uint16_t key);
#define K_INT_1 (0x61)
#define K_INT_2 (0x5D)

// XXX: Custom keys

#define KF_CUSTOM (0x0200)
#define K_FNLOCK (KF_CUSTOM | 0x01)

#endif // _COMMON_KEYMAP_H
21 changes: 21 additions & 0 deletions src/keyboard/system76/14in_83/include/board/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,25 @@
#define MATRIX_FN_INPUT 0
#define MATRIX_FN_OUTPUT 6

static inline bool keymap_is_f_key(uint8_t row, uint8_t col) {
switch (row) {
case 8:
return col == 6 || col == 7;
case 9:
return col == 6 || col == 7;
case 10:
return col == 6 || col == 7;
case 11:
return col == 6 || col == 7;
case 12:
return col == 6 || col == 7;
case 13:
return col == 7;
case 15:
return col == 5;
default:
return false;
}
}

#endif // _BOARD_KEYMAP_H
21 changes: 21 additions & 0 deletions src/keyboard/system76/14in_86/include/board/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,25 @@
#define MATRIX_FN_INPUT 0
#define MATRIX_FN_OUTPUT 6

static inline bool keymap_is_f_key(uint8_t row, uint8_t col) {
switch (row) {
case 8:
return col == 6 || col == 7;
case 9:
return col == 6 || col == 7;
case 10:
return col == 6 || col == 7;
case 11:
return col == 6 || col == 7;
case 12:
return col == 6 || col == 7;
case 13:
return col == 7;
case 15:
return col == 5;
default:
return false;
}
}

#endif // _BOARD_KEYMAP_H
21 changes: 21 additions & 0 deletions src/keyboard/system76/15in_102/include/board/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,25 @@
#define MATRIX_FN_INPUT 3
#define MATRIX_FN_OUTPUT 17

static inline bool keymap_is_f_key(uint8_t row, uint8_t col) {
switch (row) {
case 8:
return col == 5 || col == 7;
case 9:
return col == 3;
case 10:
return col == 5 || col == 6;
case 12:
return col == 5;
case 13:
return col == 3 || col == 7;
case 14:
return col == 1 || col == 3;
case 16:
return col == 6 || col == 7;
default:
return false;
}
}

#endif // _BOARD_KEYMAP_H
25 changes: 25 additions & 0 deletions src/keyboard/system76/15in_102_nkey/include/board/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,29 @@
#define MATRIX_FN_INPUT 0
#define MATRIX_FN_OUTPUT 4

static inline bool keymap_is_f_key(uint8_t row, uint8_t col) {
switch (row) {
case 1:
return col == 1;
case 4:
return col == 2;
case 6:
return col == 2 || col == 3 || col == 4;
case 7:
return col == 1;
case 10:
return col == 2;
case 11:
return col == 2 || col == 3;
case 12:
return col == 0;
case 13:
return col == 3;
case 15:
return col == 1;
default:
return false;
}
}

#endif // _BOARD_KEYMAP_H
21 changes: 21 additions & 0 deletions src/keyboard/system76/18H9LHA04/include/board/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,25 @@
#define MATRIX_FN_INPUT 3
#define MATRIX_FN_OUTPUT 17

static inline bool keymap_is_f_key(uint8_t row, uint8_t col) {
switch (row) {
case 8:
return col == 5 || col == 7;
case 9:
return col == 3;
case 10:
return col == 5 || col == 6;
case 12:
return col == 5;
case 13:
return col == 3 || col == 7;
case 14:
return col == 1 || col == 3;
case 16:
return col == 6 || col == 7;
default:
return false;
}
}

#endif // _BOARD_KEYMAP_H
21 changes: 21 additions & 0 deletions src/keyboard/system76/18H9LHA05/include/board/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,25 @@
#define MATRIX_FN_INPUT 3
#define MATRIX_FN_OUTPUT 17

static inline bool keymap_is_f_key(uint8_t row, uint8_t col) {
switch (row) {
case 8:
return col == 5 || col == 7;
case 9:
return col == 3;
case 10:
return col == 5 || col == 6;
case 12:
return col == 5;
case 13:
return col == 3 || col == 7;
case 14:
return col == 1 || col == 3;
case 16:
return col == 6 || col == 7;
default:
return false;
}
}

#endif // _BOARD_KEYMAP_H

0 comments on commit 0190701

Please sign in to comment.