From 78ef3165a97d709a07f8e795f677ad3794157f3b Mon Sep 17 00:00:00 2001 From: Gondolindrim Date: Sun, 12 May 2024 23:43:00 -0300 Subject: [PATCH] Remove VIA code --- keyboards/typek/keymaps/default/keymap.c | 4 +- keyboards/typek/keymaps/via/keymap.c | 4 +- keyboards/typek/typek.c | 331 ++--------------------- 3 files changed, 22 insertions(+), 317 deletions(-) diff --git a/keyboards/typek/keymaps/default/keymap.c b/keyboards/typek/keymaps/default/keymap.c index 50e94b748cd..34d9522f930 100644 --- a/keyboards/typek/keymaps/default/keymap.c +++ b/keyboards/typek/keymaps/default/keymap.c @@ -17,14 +17,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -[0] = LAYOUT( /* Base */ +[0] = LAYOUT_all( /* Base */ KC_ESC , KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINS, KC_EQL, KC_BSLS, KC_PGUP, KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC, KC_RBRC, KC_PGDN, KC_CAPS, KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, KC_DEL , MO(1) , KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_RSFT, KC_LCTL, KC_LALT, KC_SPC , KC_LGUI, KC_6 , KC_SPC , KC_SPC , KC_RALT, KC_BSPC, KC_ENT , MO(1) , KC_RCTL ), -[1] = LAYOUT( +[1] = LAYOUT_all( QK_BOOT, 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_TRNS, KC_HOME, KC_TRNS, KC_TRNS, KC_UP , KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END , KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, diff --git a/keyboards/typek/keymaps/via/keymap.c b/keyboards/typek/keymaps/via/keymap.c index f3ff1882794..ad19869c1fc 100644 --- a/keyboards/typek/keymaps/via/keymap.c +++ b/keyboards/typek/keymaps/via/keymap.c @@ -17,14 +17,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -[0] = LAYOUT( /* Base */ +[0] = LAYOUT_all( /* Base */ KC_ESC , KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINS, KC_EQL, KC_BSLS, KC_PGUP, KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC, KC_RBRC, KC_PGDN, KC_CAPS, KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, KC_DEL , MO(1) , KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_RSFT, KC_LCTL, KC_LALT, KC_SPC , KC_LGUI, KC_6 , KC_SPC , KC_SPC , KC_RALT, KC_BSPC, KC_ENT , MO(1) , KC_RCTL ), -[1] = LAYOUT( +[1] = LAYOUT_all( QK_BOOT, KC_TRNS, KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_TRNS, KC_HOME, KC_TRNS, KC_TRNS, KC_UP , KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END , KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, diff --git a/keyboards/typek/typek.c b/keyboards/typek/typek.c index 97bb8925d6d..4a8b11cf0b4 100644 --- a/keyboards/typek/typek.c +++ b/keyboards/typek/typek.c @@ -17,323 +17,28 @@ #include "quantum.h" #include "print.h" -/* RGB indicators: by default, they are numbered (when looking from above) INDICATOR_R, INDICATOR_C, INDICATOR_L -*/ - -// Declaring a type indicator_config that stores color and enabled state -typedef struct _indicator_config_t { -// H, S, V store the color values; func stores the function (caps lock, scroll, num, layer indication); index stores the RGB LED index; and enabled stores the enabled state - uint8_t h; - uint8_t s; - uint8_t v; - uint8_t func ; - uint8_t index ; - bool enabled; -} indicator_config ; - -// Number of properties of the "indicator" struct -#define INDICATOR_PROPERTY_NUMBER 6 -// Declaring a keyboard_indicators type that stores the indicators states -#define INDICATOR_NUMBER 3 - -/* List of functions: - 0x00 NONE - 0x01 CAPS LOCK - 0x02 NUM LOCK - 0x03 SCROLL LOCK - 0x04 LAYER 0 - 0x05 LAYER 1 - 0x06 LAYER 2 - 0x07 LAYER 3 -*/ - -bool func_switch(uint8_t func) { - switch (func) - { - case 0x00: - { - return false; - break; - } - case 0x01: // If indicator is set as caps lock - { - if (host_keyboard_led_state().caps_lock) return true; - break; - } - case 0x02: // If indicator is set as num lock - { - if (host_keyboard_led_state().num_lock) return true; - break; - } - case 0x03: // If indicator is set as scroll lock - { - if (host_keyboard_led_state().scroll_lock) return true; - break; - } - case 0x04: // If indicator is set as layer 0 - case 0x05: - case 0x06: - case 0x07: - { - if ( IS_LAYER_ON( (int)(func) - 4 ) ) return true; - break; - } - default: - { - return false; - } - } - return false; -} - -// Here the indicators functions themselves are programmed. -bool set_indicator(indicator_config indicator) { - if (!indicator.enabled) return false; - return func_switch(indicator.func & 0x0F) | func_switch( (indicator.func & 0xF0) >> 4); -} - -typedef struct _keyboard_indicators_t { - indicator_config ind1 ; - indicator_config ind2 ; - indicator_config ind3 ; -} keyboard_indicators ; - -_Static_assert(sizeof(keyboard_indicators) == EECONFIG_KB_DATA_SIZE, "Mismatch in keyboard indicators stored data"); - -// Declaring a new variable indicators of the type keyboard_indicators -keyboard_indicators indicators; -uint8_t* pIndicators = (uint8_t*)&indicators ; // Gets a pointer to the first indicator - -// This function returns the pointer to an indicator given an index. Basically what is done is shifting the pointer of the indicators struct by 6*index. -// Each indicator is INDICATOR_PROPERTY_NUMBER bytes long, so the shift needs to be that size. -indicator_config* get_indicator_p (int index) { - return (indicator_config*) (pIndicators + INDICATOR_PROPERTY_NUMBER*index) ; -} - -// Initializing persistent memory configuration: default values are declared and stored in PMEM -void eeconfig_init_kb(void) { - // Default values: indicators start at white, 150 (roughly 60%) brightness value. Indicators 1 and 2 are active by default. - // INDICATOR 0: RIGHT INDICATOR - indicators.ind1.h = 0; - indicators.ind1.s = 255; - indicators.ind1.v = 150; - indicators.ind1.func = 0x76; - indicators.ind1.index = 0; - indicators.ind1.enabled = true; - - // INDICATOR 1: MIDDLE INDICATOR - indicators.ind2.h = 86; - indicators.ind2.s = 255; - indicators.ind2.v = 150; - indicators.ind2.func = 0x75; - indicators.ind2.index = 1; - indicators.ind2.enabled = true; - - // INDICATOR 2: LEFT INDICATOR - indicators.ind3.h = 166; - indicators.ind3.s = 254; - indicators.ind3.v = 150; - indicators.ind3.func = 0x01; - indicators.ind3.index = 2; - indicators.ind3.enabled = true; - - // Write default value to EEPROM now - eeconfig_update_kb_datablock(&indicators); -} - -// INDICATOR CALLBACK ------------------------------------------------------------------------------ -bool indicators_callback(void) { - - // Basic functioning: for each indicator, set_indicator is used to decide if the current indicator should be lit or off. - indicator_config* current_indicator_p ; - int index ; - for (index = 0 ; index < INDICATOR_NUMBER ; index++) { - current_indicator_p = get_indicator_p(index) ; - if (set_indicator( *(current_indicator_p)) ) sethsv( current_indicator_p -> h, current_indicator_p -> s, current_indicator_p -> v, (LED_TYPE *)&led[current_indicator_p -> index]); - else sethsv( 0,0,0, (LED_TYPE *)&led[current_indicator_p -> index]); - } - return true; -} - // This function gets called when caps, num, scroll change bool led_update_kb(led_t led_state) { - indicators_callback(); - return true; + bool res = led_update_user(led_state); + if (res) { + led_state.caps_lock ? sethsv( HSV_RED, (rgb_led_t *)&led[0]) : sethsv( HSV_BLACK, (rgb_led_t *)&led[0]); + } + return res; } // This function is called when layers change -layer_state_t layer_state_set_user(layer_state_t state) { - indicators_callback(); +layer_state_t layer_state_set_kb(layer_state_t state) { + switch(get_highest_layer(state)) { + case 1: + sethsv(HSV_GREEN, (rgb_led_t *)&led[1]); + break; + case 2: + sethsv(HSV_BLUE, (rgb_led_t *)&led[2]); + break; + default: + sethsv(HSV_BLACK, (rgb_led_t *)&led[1]); + sethsv(HSV_BLACK, (rgb_led_t *)&led[2]); + break; + } return state; } - -// At the keyboard start, retrieves PMEM stored configs and runs indicator_callback -void keyboard_post_init_kb(void) { - eeconfig_read_kb_datablock(&indicators); - rgblight_set_effect_range(3,66); - indicators_callback(); - - debug_enable = true; - //debug_keyboard = true; -} - -// VIA CONFIGURATION ------------------------------------------------------------------------------- -enum via_indicator_color { - id_ind1_enabled = 1, - id_ind1_brightness = 2, - id_ind1_color = 3, - id_ind1_func1 = 4, - id_ind1_func2 = 5, -// - id_ind2_enabled = 6, - id_ind2_brightness = 7, - id_ind2_color = 8, - id_ind2_func1 = 9, - id_ind2_func2 = 10, -// - id_ind3_enabled = 11, - id_ind3_brightness = 12, - id_ind3_color = 13, - id_ind3_func1 = 14, - id_ind3_func2 = 15 -}; - -int indi_index; -int data_index; - -void indicator_config_set_value( uint8_t *data ) -{ - // data = [ value_id, value_data ] - uint8_t *value_id; - value_id = &(data[0]); - uint8_t *value_data = &(data[1]); - - /* Suppose that the brightness value of indicator 3 is being changed; then - index = (12-1)/INDICATOR_PROPERTY_NUMBER = 11/5 = 2 (integer division!), which indeed relates to indicator 3 (ind1 is 0, ind2 is 1 etc) - data_index = (12 - index*INDICATOR_PROPERTY_NUMBER) = 12 - 2*5 = 2, which indeed relates to a brightness setting (0 is for enabled, 1 for brightness, 2 for color and 3 for func) - Therefore, the basic idea is that index is about which indicator the set_value is about, and data_index about what indicator property it is - */ - indi_index = ( (int)(*value_id) - 1) / 5; - data_index = (int)(*value_id) - indi_index*5; - indicator_config* current_indicator_p = get_indicator_p(indi_index); - uprintf("--> value_id: %X\n", (int)(*value_id)); - switch ( data_index ) - { - case 1 : - { - current_indicator_p -> enabled = value_data[0]; - break; - } - case 2 : - { - current_indicator_p -> v = value_data[0]; - break; - } - case 3: - { - current_indicator_p -> h = value_data[0]; - current_indicator_p -> s = value_data[1]; - break; - } - case 4: - { - current_indicator_p -> func = (current_indicator_p -> func & 0xF0 ) | (uint8_t) value_data[0]; - break; - } - case 5: - { - - current_indicator_p -> func = (current_indicator_p -> func & 0x0F ) | ((uint8_t) value_data[0] << 4); - break; - } - } - indicators_callback(); -} - - -void indicator_config_get_value( uint8_t *data ) -{ - // data = [ value_id, value_data ] - uint8_t *value_id = &(data[0]); - uint8_t *value_data = &(data[1]); - - indi_index = ( (int)(*value_id) - 1) / 5; data_index = (int)(*value_id) - indi_index*5; - indicator_config* current_indicator_p = get_indicator_p(indi_index); - switch ( data_index ) - { - case 1: - { - value_data[0] = current_indicator_p -> enabled; - break; - } - case 2: - { - - value_data[0] = current_indicator_p -> v; - break; - } - case 3: - { - - value_data[0] = current_indicator_p -> h; - value_data[1] = current_indicator_p -> s; - break; - } - case 4: - { - - value_data[0] = current_indicator_p -> func & 0x0F; - uprintf("--> Current func: %x, current func with bitwise or: %X\n", current_indicator_p -> func, current_indicator_p -> func % 0x0F); - break; - } - case 5: - { - - value_data[0] = (current_indicator_p -> func & 0xF0) >> 4; - uprintf("--> Current func: %x, current func with bitwise or: %X\n", current_indicator_p -> func, current_indicator_p -> func % 0xF0); - break; - } - } -} - -void indicator_config_save(void) -{ - eeconfig_update_kb_datablock(&indicators); -} - -void via_custom_value_command_kb(uint8_t *data, uint8_t length) { - // data = [ command_id, channel_id, value_id, value_data ] - uint8_t *command_id = &(data[0]); - uint8_t *channel_id = &(data[1]); - uint8_t *value_id_and_data = &(data[2]); - - if ( *channel_id == id_custom_channel ) { - switch ( *command_id ) - { - case id_custom_set_value: - { - indicator_config_set_value(value_id_and_data); - break; - } - case id_custom_get_value: - { - indicator_config_get_value(value_id_and_data); - break; - } - case id_custom_save: - { - indicator_config_save(); - break; - } - default: - { - // Unhandled message. - *command_id = id_unhandled; - break; - } - } - return; - } - - *command_id = id_unhandled; -}