diff options
author | Wilba <wilba@wilba.tech> | 2022-11-10 07:46:44 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 07:46:44 +1100 |
commit | bc6f8dc8b0822e5e03893eacffa42a7badb4c2fa (patch) | |
tree | b1e8a219803f30b7347e479734a5c6e7352a5f30 | |
parent | 575b0e33fa47034f5cfaf6f7cd98570268efa0a2 (diff) |
VIA V3 - The Custom UI Update (#18222)
68 files changed, 751 insertions, 886 deletions
diff --git a/keyboards/cannonkeys/satisfaction75/config.h b/keyboards/cannonkeys/satisfaction75/config.h index 615ad1d056..a650a362c0 100644 --- a/keyboards/cannonkeys/satisfaction75/config.h +++ b/keyboards/cannonkeys/satisfaction75/config.h @@ -82,9 +82,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // 6 for 3x custom encoder settings, left, right, and press (18 bytes) #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 21 -// VIA lighting is handled by the keyboard-level code -#define VIA_CUSTOM_LIGHTING_ENABLE - /* * Feature disable options * These options are also useful to firmware size reduction. diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.c b/keyboards/cannonkeys/satisfaction75/satisfaction75.c index 3cd52d5f23..13b44b85db 100644 --- a/keyboards/cannonkeys/satisfaction75/satisfaction75.c +++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.c @@ -102,113 +102,142 @@ void backlight_set_value( uint8_t *data ) } } -void raw_hid_receive_kb( uint8_t *data, uint8_t length ) -{ - uint8_t *command_id = &(data[0]); - uint8_t *command_data = &(data[1]); - switch ( *command_id ) - { - case id_get_keyboard_value: - { - switch( command_data[0]) - { - case id_oled_default_mode: - { - uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED); - command_data[1] = default_oled; - break; - } - case id_oled_mode: - { - command_data[1] = oled_mode; - break; - } - case id_encoder_modes: - { - command_data[1] = 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]){ +void custom_set_value(uint8_t *data) { + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch ( *value_id ) { case id_oled_default_mode: { - eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, command_data[1]); - break; + eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, value_data[0]); + break; } case id_oled_mode: { - oled_mode = command_data[1]; - oled_request_wakeup(); - break; + oled_mode = value_data[0]; + oled_request_wakeup(); + break; } case id_encoder_modes: { - enabled_encoder_modes = command_data[1]; - eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes); - break; + uint8_t index = value_data[0]; + uint8_t enable = value_data[1]; + enabled_encoder_modes = (enabled_encoder_modes & ~(1<<index)) | (enable<<index); + 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; + uint8_t custom_encoder_idx = value_data[0]; + uint8_t encoder_behavior = value_data[1]; + uint16_t keycode = (value_data[2] << 8) | value_data[3]; + set_custom_encoder_config(custom_encoder_idx, encoder_behavior, keycode); + break; } - default: + } +} + +void custom_get_value(uint8_t *data) { + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch ( *value_id ) { + case id_oled_default_mode: { - *command_id = id_unhandled; - break; + uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED); + value_data[0] = default_oled; + break; + } + case id_oled_mode: + { + value_data[0] = oled_mode; + break; + } + case id_encoder_modes: + { + uint8_t index = value_data[0]; + value_data[1] = (enabled_encoder_modes & (1<<index)) ? 1 : 0; + break; + } + case id_encoder_custom: + { + uint8_t custom_encoder_idx = value_data[0]; + uint8_t encoder_behavior = value_data[1]; + uint16_t keycode = retrieve_custom_encoder_config(custom_encoder_idx, encoder_behavior); + value_data[2] = keycode >> 8; + value_data[3] = keycode & 0xFF; + break; } - } - break; - } - case id_lighting_set_value: - { - backlight_set_value(command_data); - break; - } - case id_lighting_get_value: - { - backlight_get_value(command_data); - break; - } - case id_lighting_save: - { - backlight_config_save(); - break; } - default: - { - // Unhandled message. - *command_id = id_unhandled; - break; +} + +// TODO +// Refactor so this keyboard uses QMK Core backlight code, +// then change this to via_custom_value_command_kb() so it +// only handles the custom values not the backlight +// (i.e. use QMK Core default handler for backlight values). +// +void via_custom_value_command(uint8_t *data, uint8_t length) { + uint8_t *command_id = &(data[0]); + uint8_t *channel_id = &(data[1]); + uint8_t *value_id_and_data = &(data[2]); + + if ( *channel_id == id_qmk_backlight_channel ) { + switch ( *command_id ) + { + case id_custom_set_value: + { + backlight_set_value(value_id_and_data); + break; + } + case id_custom_get_value: + { + backlight_get_value(value_id_and_data); + break; + } + case id_custom_save: + { + backlight_config_save(); + break; + } + default: + { + // Unhandled message. + *command_id = id_unhandled; + break; + } + } + } else if ( *channel_id == id_custom_channel ) { + switch ( *command_id ) + { + case id_custom_set_value: + { + custom_set_value(value_id_and_data); + break; + } + case id_custom_get_value: + { + custom_get_value(value_id_and_data); + break; + } + case id_custom_save: + { + // values are saved in custom_set_value() + break; + } + default: + { + // Unhandled message. + *command_id = id_unhandled; + break; + } + } + return; } - } - // DO NOT call raw_hid_send(data,length) here, let caller do this + + *command_id = id_unhandled; + + // DO NOT call raw_hid_send(data,length) here, let caller do this } #endif diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.h b/keyboards/cannonkeys/satisfaction75/satisfaction75.h index ea71345a38..ec852eef6c 100644 --- a/keyboards/cannonkeys/satisfaction75/satisfaction75.h +++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.h @@ -30,8 +30,8 @@ enum my_keycodes { OLED_TOGG }; -enum s75_keyboard_value_id { - id_encoder_modes = 0x80, +enum s75_custom_value_id { + id_encoder_modes = 1, id_oled_default_mode, id_encoder_custom, id_oled_mode diff --git a/keyboards/durgod/dgk6x/config.h b/keyboards/durgod/dgk6x/config.h index 70247fd745..fe4ca58072 100644 --- a/keyboards/durgod/dgk6x/config.h +++ b/keyboards/durgod/dgk6x/config.h @@ -130,7 +130,4 @@ # define ENABLE_RGB_MATRIX_SOLID_SPLASH # define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH -// This allows VIA to control RGB Matrix settings in the 'Lighting' section. -#define VIA_QMK_RGBLIGHT_ENABLE - #endif /* RGB_MATRIX_ENABLE */ diff --git a/keyboards/frooastboard/walnut/keymaps/via/config.h b/keyboards/frooastboard/walnut/keymaps/via/config.h index 0ef255fb51..e1f0fc0db6 100644 --- a/keyboards/frooastboard/walnut/keymaps/via/config.h +++ b/keyboards/frooastboard/walnut/keymaps/via/config.h @@ -3,5 +3,4 @@ #pragma once -#define VIA_CUSTOM_LIGHTING_ENABLE #define DYNAMIC_KEYMAP_LAYER_COUNT 2 diff --git a/keyboards/frooastboard/walnut/keymaps/via/keymap.c b/keyboards/frooastboard/walnut/keymaps/via/keymap.c index 84b73e2186..f502205761 100644 --- a/keyboards/frooastboard/walnut/keymaps/via/keymap.c +++ b/keyboards/frooastboard/walnut/keymaps/via/keymap.c @@ -17,115 +17,4 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_VAI, KC_TRNS, GUI_TOG, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_RMOD,RGB_VAD, RGB_MOD) -}; - -#if defined(RGB_MATRIX_ENABLE) && defined(VIA_CUSTOM_LIGHTING_ENABLE) - -// VIA supports only 4 discrete values for effect speed; map these to some -// useful speed values for RGB Matrix. -enum speed_values { - RGBLIGHT_SPEED_0 = UINT8_MAX / 16, // not 0 to avoid really slow effects - RGBLIGHT_SPEED_1 = UINT8_MAX / 4, - RGBLIGHT_SPEED_2 = UINT8_MAX / 2, // matches the default value - RGBLIGHT_SPEED_3 = UINT8_MAX / 4 * 3, // UINT8_MAX is really fast -}; - -static uint8_t speed_from_rgblight(uint8_t rgblight_speed) { - switch (rgblight_speed) { - case 0: - return RGBLIGHT_SPEED_0; - case 1: - return RGBLIGHT_SPEED_1; - case 2: - default: - return RGBLIGHT_SPEED_2; - case 3: - return RGBLIGHT_SPEED_3; - } -} - -static uint8_t speed_to_rgblight(uint8_t rgb_matrix_speed) { - if (rgb_matrix_speed < ((RGBLIGHT_SPEED_0 + RGBLIGHT_SPEED_1) / 2)) { - return 0; - } else if (rgb_matrix_speed < ((RGBLIGHT_SPEED_1 + RGBLIGHT_SPEED_2) / 2)) { - return 1; - } else if (rgb_matrix_speed < ((RGBLIGHT_SPEED_2 + RGBLIGHT_SPEED_3) / 2)) { - return 2; - } else { - return 3; - } -} - -void via_qmk_rgblight_get_value(uint8_t *data) { - uint8_t *value_id = &(data[0]); - uint8_t *value_data = &(data[1]); - switch (*value_id) { - case id_qmk_rgblight_brightness: { - value_data[0] = rgb_matrix_get_val(); - break; - } - case id_qmk_rgblight_effect: { - value_data[0] = rgb_matrix_is_enabled() ? rgb_matrix_get_mode() : 0; - break; - } - case id_qmk_rgblight_effect_speed: { - value_data[0] = speed_to_rgblight(rgb_matrix_get_speed()); - break; - } - case id_qmk_rgblight_color: { - value_data[0] = rgb_matrix_get_hue(); - value_data[1] = rgb_matrix_get_sat(); - break; - } - } -} - -void via_qmk_rgblight_set_value(uint8_t *data) { - uint8_t *value_id = &(data[0]); - uint8_t *value_data = &(data[1]); - switch (*value_id) { - case id_qmk_rgblight_brightness: { - rgb_matrix_sethsv_noeeprom(rgblight_get_hue(), rgblight_get_sat(), value_data[0]); - break; - } - case id_qmk_rgblight_effect: { - if (value_data[0] == 0) { - rgb_matrix_disable_noeeprom(); - } else { - rgb_matrix_enable_noeeprom(); - rgb_matrix_mode_noeeprom(value_data[0]); - } - break; - } - case id_qmk_rgblight_effect_speed: { - rgb_matrix_set_speed_noeeprom(speed_from_rgblight(value_data[0])); - break; - } - case id_qmk_rgblight_color: { - rgb_matrix_sethsv_noeeprom(value_data[0], value_data[1], rgblight_get_val()); - break; - } - } -} - -void raw_hid_receive_kb(uint8_t *data, uint8_t length) { - uint8_t *command_id = &(data[0]); - uint8_t *command_data = &(data[1]); - switch (*command_id) { - case id_lighting_set_value: - via_qmk_rgblight_set_value(command_data); - break; - case id_lighting_get_value: - via_qmk_rgblight_get_value(command_data); - break; - case id_lighting_save: - eeconfig_update_rgb_matrix(); - break; - default: - // Unhandled message. - *command_id = id_unhandled; - break; - } -} - -#endif // defined(RGB_MATRIX_ENABLE) && defined(VIA_CUSTOM_LIGHTING_ENABLE) +};
\ No newline at end of file diff --git a/keyboards/geekboards/macropad_v2/keymaps/via/config.h b/keyboards/geekboards/macropad_v2/keymaps/via/config.h deleted file mode 100644 index 9d75edbe74..0000000000 --- a/keyboards/geekboards/macropad_v2/keymaps/via/config.h +++ /dev/null @@ -1,2 +0,0 @@ -#define DYNAMIC_KEYMAP_LAYER_COUNT 4 -#define VIA_QMK_RGBLIGHT_ENABLE diff --git a/keyboards/horrortroll/handwired_k552/keymaps/via/config.h b/keyboards/horrortroll/handwired_k552/keymaps/via/config.h index ba3e8e9a03..a36ce468bc 100644 --- a/keyboards/horrortroll/handwired_k552/keymaps/via/config.h +++ b/keyboards/horrortroll/handwired_k552/keymaps/via/config.h @@ -17,7 +17,3 @@ #pragma once #define DYNAMIC_KEYMAP_LAYER_COUNT 3 - -#ifdef RGB_MATRIX_ENABLE - #define VIA_QMK_RGBLIGHT_ENABLE -#endif diff --git a/keyboards/hs60/v2/ansi/config.h b/keyboards/hs60/v2/ansi/config.h index 509661db8d..4211e7ce94 100644 --- a/keyboards/hs60/v2/ansi/config.h +++ b/keyboards/hs60/v2/ansi/config.h @@ -135,6 +135,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // Backlight config starts after VIA's EEPROM usage, // dynamic keymaps start after this. #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 32 - -// VIA lighting is handled by the keyboard-level code -#define VIA_CUSTOM_LIGHTING_ENABLE diff --git a/keyboards/hs60/v2/hhkb/config.h b/keyboards/hs60/v2/hhkb/config.h index 46090673db..ac1e9aa012 100644 --- a/keyboards/hs60/v2/hhkb/config.h +++ b/keyboards/hs60/v2/hhkb/config.h @@ -135,6 +135,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // Backlight config starts after VIA's EEPROM usage, // dynamic keymaps start after this. #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 32 - -// VIA lighting is handled by the keyboard-level code -#define VIA_CUSTOM_LIGHTING_ENABLE diff --git a/keyboards/hs60/v2/iso/config.h b/keyboards/hs60/v2/iso/config.h index cf43e3dd94..22e2c3fbfe 100644 --- a/keyboards/hs60/v2/iso/config.h +++ b/keyboards/hs60/v2/iso/config.h @@ -133,6 +133,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // Backlight config starts after VIA's EEPROM usage, // dynamic keymaps start after this. #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 32 - -// VIA lighting is handled by the keyboard-level code -#define VIA_CUSTOM_LIGHTING_ENABLE diff --git a/keyboards/keebio/iris/keymaps/via/rules.mk b/keyboards/keebio/iris/keymaps/via/rules.mk index 1189f4ad19..873ff6cdfc 100644 --- a/keyboards/keebio/iris/keymaps/via/rules.mk +++ b/keyboards/keebio/iris/keymaps/via/rules.mk @@ -1,3 +1,4 @@ VIA_ENABLE = yes LTO_ENABLE = yes ENCODER_MAP_ENABLE = yes +CONSOLE_ENABLE = no diff --git a/keyboards/keebwerk/mega/ansi/config.h b/keyboards/keebwerk/mega/ansi/config.h index 43bc368925..0322bf3e64 100755 --- a/keyboards/keebwerk/mega/ansi/config.h +++ b/keyboards/keebwerk/mega/ansi/config.h @@ -133,6 +133,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // Backlight config starts after VIA's EEPROM usage, // dynamic keymaps start after this. #define VIA_EEPROM_CUSTOM_CONFIG_SIZE |