From 4107856b70eb686d2e151254ca73adf522312c49 Mon Sep 17 00:00:00 2001 From: Jay Greco Date: Tue, 9 Feb 2021 06:50:16 -0800 Subject: Simplify NIBBLE encoder code and clean up keymaps (#11808) * Simplify encoder code and clean up keymaps. -Removed overly complex VIA encoder code. It wasn't adding any value and was confusing users who were trying to customize encoder functionality on VIA keymaps. -Replaced KC_TILDE with KC_HOME in all keymaps, as KC_TILDE sends a left shift, which was confusing some folks as they tested their build. -Move layer names to enum * Change encoder_update_kb to encoder_update_user per PR feedback --- keyboards/nullbitsco/nibble/keymaps/via/config.h | 21 ---- keyboards/nullbitsco/nibble/keymaps/via/keymap.c | 30 +++-- .../nullbitsco/nibble/keymaps/via/nibble_encoder.c | 133 --------------------- .../nullbitsco/nibble/keymaps/via/nibble_encoder.h | 50 -------- keyboards/nullbitsco/nibble/keymaps/via/rules.mk | 5 +- .../nullbitsco/nibble/keymaps/via/via_extras.c | 129 -------------------- .../nullbitsco/nibble/keymaps/via/via_extras.h | 39 ------ 7 files changed, 21 insertions(+), 386 deletions(-) delete mode 100644 keyboards/nullbitsco/nibble/keymaps/via/config.h delete mode 100644 keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.c delete mode 100644 keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.h delete mode 100644 keyboards/nullbitsco/nibble/keymaps/via/via_extras.c delete mode 100644 keyboards/nullbitsco/nibble/keymaps/via/via_extras.h (limited to 'keyboards/nullbitsco/nibble/keymaps/via') diff --git a/keyboards/nullbitsco/nibble/keymaps/via/config.h b/keyboards/nullbitsco/nibble/keymaps/via/config.h deleted file mode 100644 index 961e2aed1a..0000000000 --- a/keyboards/nullbitsco/nibble/keymaps/via/config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2020 Jay Greco - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -// Custom config starts after VIA's EEPROM usage, -// dynamic keymaps start after this. -// Custom config Usage: -// 1 for enabled encoder modes (1 byte) -// 6 for 3x custom encoder settings, left, right, and press (18 bytes) -#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 19 \ No newline at end of file diff --git a/keyboards/nullbitsco/nibble/keymaps/via/keymap.c b/keyboards/nullbitsco/nibble/keymaps/via/keymap.c index f72ffc56e1..5b2f3b4f2e 100644 --- a/keyboards/nullbitsco/nibble/keymaps/via/keymap.c +++ b/keyboards/nullbitsco/nibble/keymaps/via/keymap.c @@ -14,12 +14,13 @@ * along with this program. If not, see . */ #include QMK_KEYBOARD_H -#include "via_extras.h" -#define _BASE 0 -#define _VIA1 1 -#define _VIA2 2 -#define _VIA3 3 +enum layer_names { + _BASE, + _VIA1, + _VIA2, + _VIA3 +}; #define KC_DISC_MUTE KC_F23 #define KC_DISC_DEAF KC_F24 @@ -50,7 +51,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), [_VIA1] = LAYOUT_all( - RESET, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, KC_INS, + RESET, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_END, RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, @@ -100,7 +101,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { tap_code(KC_DISC_MUTE); if (!rgblight_is_enabled()) break; - + if (muted) { rgblight_enable_noeeprom(); } else { @@ -133,7 +134,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { if (!is_alt_tab_active) { is_alt_tab_active = true; register_code(KC_LALT); - } + } alt_tab_timer = timer_read(); register_code(KC_TAB); } else { @@ -142,11 +143,20 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; default: - break; + break; } return true; } +void encoder_update_user(uint8_t index, bool clockwise) { + // Encoder is mapped to volume functions by default + if (clockwise) { + tap_code(KC_VOLU); + } else { + tap_code(KC_VOLD); + } +} + void matrix_init_user(void) { // Initialize remote keyboard, if connected (see readme) matrix_init_remote_kb(); @@ -161,4 +171,4 @@ void matrix_scan_user(void) { is_alt_tab_active = false; } } -} \ No newline at end of file +} diff --git a/keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.c b/keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.c deleted file mode 100644 index bdea1869c2..0000000000 --- a/keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.c +++ /dev/null @@ -1,133 +0,0 @@ -/* Copyright 2020 Jay Greco - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "nibble_encoder.h" - -uint8_t encoder_value = 0x20, - encoder_mode = ENC_MODE_VOLUME, - enabled_encoder_modes = 0x1F; - -uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior) { -#ifdef DYNAMIC_KEYMAP_ENABLE - void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); - uint16_t keycode = eeprom_read_byte(addr) << 8; - keycode |= eeprom_read_byte(addr + 1); - return keycode; -#else - return 0; -#endif -} - -void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code) { -#ifdef DYNAMIC_KEYMAP_ENABLE - void* addr = (void*)(EEPROM_CUSTOM_ENCODER + (encoder_idx * 6) + (behavior * 2)); - eeprom_update_byte(addr, (uint8_t)(new_code >> 8)); - eeprom_update_byte(addr + 1, (uint8_t)(new_code & 0xFF)); -#endif -} - -void pre_encoder_mode_change(void) { - dprintf("Changing encoder mode: %u\n", encoder_mode); -} - -void post_encoder_mode_change(void) { - dprintf("Encoder mode: %u\n", encoder_mode); -} - -//??? -void change_encoder_mode(bool clockwise) { - pre_encoder_mode_change(); - if(enabled_encoder_modes == 0){ - enabled_encoder_modes = 0x1F; - } - do { - if(!clockwise){ - if (encoder_mode == 0){ - encoder_mode = _NUM_ENCODER_MODES - 1; - } else{ - encoder_mode = encoder_mode - 1; - } - } else { - encoder_mode = (encoder_mode + 1) % _NUM_ENCODER_MODES; - } - } while(((1 << encoder_mode) & enabled_encoder_modes) == 0); - post_encoder_mode_change(); -} - -uint16_t handle_encoder_cw(void) { - dprintf("Encoder mode: %u\n", encoder_mode); - uint16_t mapped_code = 0; - switch(encoder_mode){ - default: - break; - case ENC_MODE_VOLUME: - mapped_code = KC_VOLU; - break; - case ENC_MODE_MEDIA: - mapped_code = KC_MEDIA_NEXT_TRACK; - break; - case ENC_MODE_SCROLL: - mapped_code = KC_WH_D; - break; - case ENC_MODE_BACKLIGHT: - mapped_code = RGB_VAI; - break; -#ifdef DYNAMIC_KEYMAP_ENABLE - case ENC_MODE_CUSTOM0: - mapped_code = retrieve_custom_encoder_config(0, ENC_CUSTOM_CW); - break; - case ENC_MODE_CUSTOM1: - mapped_code = retrieve_custom_encoder_config(1, ENC_CUSTOM_CW); - break; - case ENC_MODE_CUSTOM2: - mapped_code = retrieve_custom_encoder_config(2, ENC_CUSTOM_CW); - break; -#endif - } - return mapped_code; -} - -uint16_t handle_encoder_ccw(void) { - dprintf("Encoder mode: %u\n", encoder_mode); - uint16_t mapped_code = 0; - switch(encoder_mode){ - default: - break; - case ENC_MODE_VOLUME: - mapped_code = KC_VOLD; - break; - case ENC_MODE_MEDIA: - mapped_code = KC_MEDIA_PREV_TRACK; - break; - case ENC_MODE_SCROLL: - mapped_code = KC_WH_U; - break; - case ENC_MODE_BACKLIGHT: - mapped_code = RGB_VAD; - break; -#ifdef DYNAMIC_KEYMAP_ENABLE - case ENC_MODE_CUSTOM0: - mapped_code = retrieve_custom_encoder_config(0, ENC_CUSTOM_CCW); - break; - case ENC_MODE_CUSTOM1: - mapped_code = retrieve_custom_encoder_config(1, ENC_CUSTOM_CCW); - break; - case ENC_MODE_CUSTOM2: - mapped_code = retrieve_custom_encoder_config(2, ENC_CUSTOM_CCW); - break; -#endif - } - return mapped_code; -} diff --git a/keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.h b/keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.h deleted file mode 100644 index fc1e61434b..0000000000 --- a/keyboards/nullbitsco/nibble/keymaps/via/nibble_encoder.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright 2020 Jay Greco - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include QMK_KEYBOARD_H -#include "eeprom.h" - -#define EEPROM_ENABLED_ENCODER_MODES (VIA_EEPROM_CUSTOM_CONFIG_ADDR) -#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1) - -enum encoder_modes { - ENC_MODE_VOLUME, - ENC_MODE_MEDIA, - ENC_MODE_SCROLL, - ENC_MODE_BRIGHTNESS, - ENC_MODE_BACKLIGHT, - ENC_MODE_CUSTOM0, - ENC_MODE_CUSTOM1, - ENC_MODE_CUSTOM2, - _NUM_ENCODER_MODES, -}; - -enum custom_encoder_behavior { - ENC_CUSTOM_CW = 0, - ENC_CUSTOM_CCW, - ENC_CUSTOM_PRESS -}; - -uint16_t - retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior), - handle_encoder_cw(void), - handle_encoder_ccw(void); - -void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code), - pre_encoder_mode_change(void), - post_encoder_mode_change(void), - change_encoder_mode(bool clockwise); \ No newline at end of file diff --git a/keyboards/nullbitsco/nibble/keymaps/via/rules.mk b/keyboards/nullbitsco/nibble/keymaps/via/rules.mk index ee197efc02..036bd6d1c3 100644 --- a/keyboards/nullbitsco/nibble/keymaps/via/rules.mk +++ b/keyboards/nullbitsco/nibble/keymaps/via/rules.mk @@ -1,4 +1 @@ -VIA_ENABLE = yes - -SRC += keymaps/via/nibble_encoder.c -SRC += keymaps/via/via_extras.c \ No newline at end of file +VIA_ENABLE = yes \ No newline at end of file diff --git a/keyboards/nullbitsco/nibble/keymaps/via/via_extras.c b/keyboards/nullbitsco/nibble/keymaps/via/via_extras.c deleted file mode 100644 index 067296b76b..0000000000 --- a/keyboards/nullbitsco/nibble/keymaps/via/via_extras.c +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright 2020 Jay Greco - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "via_extras.h" - -// Encoder Behavior -extern uint8_t encoder_value; -extern uint8_t encoder_mode; -extern uint8_t enabled_encoder_modes; - -void raw_hid_receive_kb( uint8_t *data, uint8_t length ) -{ - uint8_t *command_id = &(data[0]); - uint8_t *command_data = &(data[1]); - dprintf("raw hid recv! command_id: %u\n",*command_id); - switch ( *command_id ) - { - case id_get_keyboard_value: - { - switch( command_data[0]) - { - case id_encoder_modes: - { - command_data[1] = enabled_encoder_modes; - dprintf("[read] enabled_encoder_modes: %u\n", enabled_encoder_modes); - } - break; - - case id_encoder_custom: - { - uint8_t custom_encoder_idx = command_data[1]; - uint16_t keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_CW); - command_data[2] = keycode >> 8; - command_data[3] = keycode & 0xFF; - keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_CCW); - command_data[4] = keycode >> 8; - command_data[5] = keycode & 0xFF; - keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_PRESS); - command_data[6] = keycode >> 8; - command_data[7] = keycode & 0xFF; - } - break; - - default: - { - *command_id = id_unhandled; - } - break; - } - } - break; - case id_set_keyboard_value: - { - switch(command_data[0]){ - case id_encoder_modes: - { - enabled_encoder_modes = command_data[1]; - dprintf("[write] enabled_encoder_modes: %u\n", enabled_encoder_modes); - eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes); - } - break; - - case id_encoder_custom: - { - uint8_t custom_encoder_idx = command_data[1]; - uint8_t encoder_behavior = command_data[2]; - uint16_t keycode = (command_data[3] << 8) | command_data[4]; - set_custom_encoder_config(custom_encoder_idx, encoder_behavior, keycode); - } - break; - - default: - { - *command_id = id_unhandled; - } - break; - } - } - break; - - default: - { - // Unhandled message. - *command_id = id_unhandled; - } - break; - } -} - -void encoder_update_kb(uint8_t index, bool clockwise) { - if (layer_state_is(1)) { - change_encoder_mode(clockwise); - return; - } - uint16_t mapped_code = 0; - if (clockwise) { - mapped_code = handle_encoder_cw(); - } else { - mapped_code = handle_encoder_ccw(); - } - if(mapped_code != 0){ - tap_code16(mapped_code); - } -} - -void custom_config_load(void){ -#ifdef DYNAMIC_KEYMAP_ENABLE - enabled_encoder_modes = eeprom_read_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES); -#endif -} - -void via_init_kb(void) -{ - dprintf("VIA is enabled.\n"); - custom_config_load(); -} diff --git a/keyboards/nullbitsco/nibble/keymaps/via/via_extras.h b/keyboards/nullbitsco/nibble/keymaps/via/via_extras.h deleted file mode 100644 index 83c3c13128..0000000000 --- a/keyboards/nullbitsco/nibble/keymaps/via/via_extras.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright 2020 Jay Greco - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#include "nibble_encoder.h" -#include "via.h" -#include "raw_hid.h" -#include "dynamic_keymap.h" -#include "tmk_core/common/eeprom.h" - -enum nibble_keyboard_value_id { - id_encoder_modes = 0x80, - id_unused_mode_1, - id_encoder_custom, - id_unused_mode_2 -}; - -// Encoder Behavior -extern uint8_t encoder_value, - encoder_mode, - enabled_encoder_modes; - -void raw_hid_receive_kb(uint8_t *data, uint8_t length), - encoder_update_kb(uint8_t index, bool clockwise), - custom_config_load(void), - via_init_kb(void); \ No newline at end of file -- cgit v1.2.3