Add a FnLock key
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>
This commit is contained in:
		
				
					committed by
					
						 Jeremy Soller
						Jeremy Soller
					
				
			
			
				
	
			
			
			
						parent
						
							b63e2092ce
						
					
				
				
					commit
					01907011bb
				
			| @@ -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> | ||||
| @@ -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) { | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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 | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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 | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user