Skip to content

Commit 3b39346

Browse files
committed
added layer hold
1 parent 59d0c3e commit 3b39346

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ Please refer to the [MK32 Wiki page](https://github.com/Galzai/MK32/wiki) for in
2323
- Connection switching.
2424
- Modify keymap via webserver (in progress) .
2525
- Security (?)
26-
- layer hold

main/keyboard_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
#define REPORT_LEN (MOD_LED_BYTES+MACRO_LEN+MATRIX_ROWS*KEYMAP_COLS) //size of hid reports with NKRO and room for 3 key macro
7171
#define REPORT_COUNT_BYTES (MATRIX_ROWS*KEYMAP_COLS+MACRO_LEN)
7272

73+
74+
#define LAYER_HOLD_MAX_VAL 0x134
75+
#define LAYER_HOLD_BASE_VAL 0x123
7376
#define MACRO_BASE_VAL 0x103
7477
#define LAYERS_BASE_VAL 0xFF
7578

main/keymap.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ enum custom_keycodes {
1717
// DVORAK,
1818
};
1919

20+
//Set these for each layer and use when layers are needed in a hold-to use layer
21+
enum layer_holds {
22+
QWERTY_H = LAYER_HOLD_BASE_VAL ,
23+
NUM_H,
24+
};
25+
2026

2127
// array to hold names of layouts for oled
2228
char default_layout_names[LAYERS][MAX_LAYOUT_NAME_LENGTH] ={
@@ -89,7 +95,7 @@ uint16_t default_slave_encoder_map[LAYERS][ENCODER_SIZE] ={
8995
{KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC },
9096
{KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT },
9197
{KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT } ,
92-
{KC_LCTRL,KC_LGUI, KC_LALT, DEFAULT, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT }
98+
{KC_LCTRL,KC_LGUI, KC_LALT, DEFAULT, NUM_H, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT }
9399

94100
};
95101

main/keypress_handles.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "matrix.h"
2727
#include "HID_kbdmousejoystick.h"
2828
#include "oled_tasks.h"
29+
#include "nvs_keymaps.h"
2930

3031
#define KEY_PRESS_TAG "KEY_PRESS"
3132

@@ -45,6 +46,10 @@ uint8_t current_report[REPORT_LEN] = {0};
4546
// Array to send when releasing macros
4647
uint8_t macro_release[3] = {0};
4748

49+
// Flag in order to know when to ignore layer change on layer hold
50+
uint8_t layer_hold_flag = 0;
51+
uint8_t prev_layout = 0;
52+
4853
// checking if a modifier key was pressed
4954
uint16_t check_modifier( uint16_t key ){
5055

@@ -95,6 +100,7 @@ void media_control_release(uint16_t keycode ){
95100
// adjust current layer
96101
void layer_adjust( uint16_t keycode ){
97102

103+
if(layer_hold_flag == 0){
98104
switch(keycode){
99105
case DEFAULT:
100106
current_layout=0;
@@ -121,6 +127,7 @@ void layer_adjust( uint16_t keycode ){
121127
#endif
122128
vTaskDelay(125/portTICK_PERIOD_MS);
123129
ESP_LOGI(KEY_PRESS_TAG,"Layer modified!, Current layer: %d ",current_layout);
130+
}
124131
}
125132

126133

@@ -151,14 +158,23 @@ uint8_t *check_key_state( uint16_t **keymap){
151158
led_status=check_led_status(keycode);
152159
if(matrix_state[row][col-MATRIX_COLS*pad]==1){
153160

161+
//checking for layer hold
162+
if((keycode >=LAYER_HOLD_BASE_VAL)&&(keycode <= LAYER_HOLD_MAX_VAL)){
163+
prev_layout = current_layout;
164+
current_layout = (keycode-LAYER_HOLD_BASE_VAL);
165+
layer_hold_flag = 1;
166+
continue;
167+
168+
}
169+
154170
// checking for layer adjust keycodes
155171
if((keycode>=LAYERS_BASE_VAL)&&(keycode<MACRO_BASE_VAL)){
156172
layer_adjust(keycode);
157173
continue;
158174
}
159175

160176
// checking for macros
161-
if(keycode>=MACRO_BASE_VAL){
177+
if((keycode>=MACRO_BASE_VAL)&&(keycode<=LAYER_HOLD_BASE_VAL)){
162178
for(uint8_t i=0; i < 3; i++){
163179
uint16_t key=macros[MACRO_BASE_VAL-keycode][i];
164180
current_report[REPORT_LEN-1-i]=key;
@@ -187,8 +203,14 @@ uint8_t *check_key_state( uint16_t **keymap){
187203
}
188204
if(matrix_state[row][col-MATRIX_COLS*pad]==0){
189205

206+
//checking for layer hold release
207+
if((layouts[prev_layout][row][col] >=LAYER_HOLD_BASE_VAL)&&(keycode <= LAYER_HOLD_MAX_VAL)){
208+
current_layout = 0;
209+
layer_hold_flag = 0;
210+
}
211+
190212
//checking if macro was released
191-
if(keycode>=MACRO_BASE_VAL){
213+
if((keycode>=MACRO_BASE_VAL)&&(keycode<=LAYER_HOLD_BASE_VAL)){
192214
for(uint8_t i=0; i < 3; i++){
193215
uint16_t key=macros[MACRO_BASE_VAL-keycode][i];
194216
current_report[REPORT_LEN-1-i]=0;

plugins/plugin_components/hid_keycode_conv/keycode_conv.c

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// Sizing the report for N-key rollover
1313
uint8_t current_report[REPORT_LEN] = {0};
1414

15-
1615
void enable_key_to_char(void){
1716
vTaskSuspend(xKeyreportTask);
1817
ESP_LOGI(TAG,"Suspending hid reports");

sdkconfig.old

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CONFIG_FLASH_ENCRYPTION_ENABLED=
3636
#
3737
# Serial flasher config
3838
#
39-
CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB0"
39+
CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB1"
4040
CONFIG_ESPTOOLPY_BAUD_115200B=y
4141
CONFIG_ESPTOOLPY_BAUD_230400B=
4242
CONFIG_ESPTOOLPY_BAUD_921600B=

0 commit comments

Comments
 (0)