diff options
author | lokher <lokher@gmail.com> | 2022-12-06 17:04:10 +0800 |
---|---|---|
committer | lokher <lokher@gmail.com> | 2022-12-06 17:04:10 +0800 |
commit | 27fc28fd2ff52e079a5bc58d6aaea4c752420615 (patch) | |
tree | 7ac943fb1ba4f430a7220efd18f66f6a77205c30 /keyboards/mxss | |
parent | e736133392fe6427cfb995da0787337189828272 (diff) | |
parent | 2709b6ed616f8012ff4cfd3ee69a822a8d188351 (diff) |
Merge upstream master
Diffstat (limited to 'keyboards/mxss')
-rw-r--r-- | keyboards/mxss/config.h | 89 | ||||
-rw-r--r-- | keyboards/mxss/keymaps/default/keymap.c | 53 | ||||
-rw-r--r-- | keyboards/mxss/keymaps/via/keymap.c | 33 | ||||
-rw-r--r-- | keyboards/mxss/mxss_frontled.c | 278 | ||||
-rw-r--r-- | keyboards/mxss/templates/keymap.c | 40 |
5 files changed, 493 insertions, 0 deletions
diff --git a/keyboards/mxss/config.h b/keyboards/mxss/config.h new file mode 100644 index 0000000000..1b0d6a097e --- /dev/null +++ b/keyboards/mxss/config.h @@ -0,0 +1,89 @@ +/* +Copyright 2018 Jumail Mundekkat / MxBlue + +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 <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "config_common.h" + +/* key matrix size */ +#define MATRIX_ROWS 5 +#define MATRIX_COLS 15 + +/* matrix pin configuration */ +#define MATRIX_ROW_PINS { F4, F1, F7, B1, B7 } +#define MATRIX_COL_PINS { D7, D6, D4, D0, C6, B6, D1, B5, D2, B4, D3, D5, B0, B2, B3 } + +/* COL2ROW, ROW2COL*/ +#define DIODE_DIRECTION COL2ROW + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCE 5 + +/* Basic RGB configuration */ +#define RGB_DI_PIN C7 +#define RGBLIGHT_EFFECT_BREATHING +#define RGBLIGHT_EFFECT_RAINBOW_MOOD +#define RGBLIGHT_EFFECT_RAINBOW_SWIRL +#define RGBLIGHT_EFFECT_SNAKE +#define RGBLIGHT_EFFECT_KNIGHT +#define RGBLIGHT_EFFECT_CHRISTMAS +#define RGBLIGHT_EFFECT_STATIC_GRADIENT +#define RGBLIGHT_EFFECT_RGB_TEST +#define RGBLIGHT_EFFECT_ALTERNATING +#define RGBLIGHT_EFFECT_TWINKLE +#define RGBLED_NUM 20 +#define RGBLIGHT_HUE_STEP 8 +#define RGBLIGHT_SAT_STEP 8 +#define RGBLIGHT_VAL_STEP 8 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +#define LOCKING_RESYNC_ENABLE + +// Just for posterity, define bootlite matrix pos +#define BOOTMAGIC_LITE_ROW 0 +#define BOOTMAGIC_LITE_COLUMN 0 + +// FLED config takes up 1 byte, stored color count takes 1, stored colors take up to 8 +#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 10 + +/* If defined, GRAVE_ESC will always act as ESC when CTRL is held. + * This is userful for the Windows task manager shortcut (ctrl+shift+esc). + */ +// #define GRAVE_ESC_CTRL_OVERRIDE + +/* + * Force NKRO + * + * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved + * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the + * makefile for this to work.) + * + * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N) + * until the next keyboard reset. + * + * NKRO may prevent your keystrokes from being detected in the BIOS, but it is + * fully operational during normal computer usage. + * + * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N) + * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by + * bootmagic, NKRO mode will always be enabled until it is toggled again during a + * power-up. + * + */ +//#define FORCE_NKRO diff --git a/keyboards/mxss/keymaps/default/keymap.c b/keyboards/mxss/keymaps/default/keymap.c new file mode 100644 index 0000000000..8fe84d6b45 --- /dev/null +++ b/keyboards/mxss/keymaps/default/keymap.c @@ -0,0 +1,53 @@ +/* Copyright 2018 Jumail Mundekkat / MxBlue + * + * 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 <http://www.gnu.org/licenses/>. + */ +#include QMK_KEYBOARD_H + +hs_set caps_color = { .hue = 0, .sat = 255 }; + +// Colors for layers +// Format: {hue, saturation} +// {0, 0} to turn off the LED +// Add additional rows to handle more layers +hs_set layer_colors[4] = { + [0] = {.hue = 0, .sat = 0}, // Color for Layer 0 + [1] = {.hue = 86, .sat = 255}, // Color for Layer 1 + [2] = {.hue = 36, .sat = 255}, // Color for Layer 2 + [3] = {.hue = 185, .sat = 255}, // Color for Layer 3 +}; +size_t lc_size = ARRAY_SIZE(layer_colors); + +// Use NEW_SAFE_RANGE to define new custom keycodes in order to not overwrite the ones used for front LED control +enum custom_keycodes { + MY_KEYCODE = NEW_SAFE_RANGE, +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + LAYOUT( /* Base */ + QK_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, + 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_BSLS, KC_DEL, + 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_ENT, KC_PGUP, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPACE, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT +), + + LAYOUT( /* L1 */ + KC_GRV, 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_DEL, + KC_TRNS, KC_MPLY, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PSCR, FLED_VAD, FLED_VAI, FLED_MOD, RGB_VAI, + QK_BOOT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END, KC_TRNS, KC_TRNS, KC_TRNS, RGB_VAD, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, KC_VOLD, KC_VOLU, KC_TRNS, RGB_MOD, RGB_SAI, RGB_TOG, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_HUD, RGB_SAD, RGB_HUI +), +}; diff --git a/keyboards/mxss/keymaps/via/keymap.c b/keyboards/mxss/keymaps/via/keymap.c new file mode 100644 index 0000000000..ae7b7ff40c --- /dev/null +++ b/keyboards/mxss/keymaps/via/keymap.c @@ -0,0 +1,33 @@ +/* Copyright 2018 Jumail Mundekkat / MxBlue + * + * 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 <http://www.gnu.org/licenses/>. + */ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + LAYOUT_all( /* L0 */ + QK_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_NO, KC_BSPC, + 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_BSLS, KC_DEL, + 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_NO, KC_ENT, KC_PGUP, + KC_LSFT, KC_NO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPACE, KC_SPACE, KC_SPACE, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT + ), + LAYOUT_all( /* L1 */ + KC_GRV, 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_TRNS, + KC_TRNS, KC_MPLY, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PSCR, FLED_VAD, FLED_VAI, FLED_MOD, RGB_VAI, + QK_BOOT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_VAD, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, KC_VOLD, KC_VOLU, KC_TRNS, RGB_MOD, RGB_SAI, RGB_TOG, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_HUD, RGB_SAD, RGB_HUI + ) +}; diff --git a/keyboards/mxss/mxss_frontled.c b/keyboards/mxss/mxss_frontled.c new file mode 100644 index 0000000000..2ab9a27bea --- /dev/null +++ b/keyboards/mxss/mxss_frontled.c @@ -0,0 +1,278 @@ +/* Copyright 2020 Jumail Mundekkat / MxBlue + * + * 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 <http://www.gnu.org/licenses/>. + * + * Extended from the work done by fcoury: https://github.com/qmk/qmk_firmware/pull/4915 + */ + +#include "mxss_frontled.h" +#include "eeprom.h" +#include "rgblight.h" +#include "via.h" +#include "version.h" // for QMK_BUILDDATE used in EEPROM magic + +// Variables for controlling front LED application +uint8_t fled_mode; // Mode for front LEDs +uint8_t fled_val; // Brightness for front leds (0 - 255) +LED_TYPE fleds[2]; // Front LED rgb values for indicator mode use + +// Layer indicator colors +__attribute__ ((weak)) +hs_set layer_colors[FRONTLED_COLOR_MAXCNT]; + +// Caps lock indicator color +__attribute__ ((weak)) +hs_set caps_color; + +__attribute__ ((weak)) +size_t lc_size = ARRAY_SIZE(layer_colors); + +void fled_init(void) { + // This checks both an EEPROM reset (from bootmagic lite, keycodes) + // and also firmware build date (from via_eeprom_is_valid()) + if (eeconfig_is_enabled()) { + fled_load_conf(); + // Else, default config + } else { + // Default mode/brightness + fled_mode = FLED_RGB; + fled_val = 10 * FLED_VAL_STEP; + + // Default colors + caps_color.hue = 0; + caps_color.sat = 255; + layer_colors[0].hue = 0; + layer_colors[0].sat = 0; + layer_colors[1].hue = 86; + layer_colors[1].sat = 255; + layer_colors[2].hue = 36; + layer_colors[2].sat = 255; + layer_colors[3].hue = 185; + layer_colors[3].sat = 255; + + fled_update_conf(); // Store default config to EEPROM + } + + // Set default values for leds + setrgb(0, 0, 0, &fleds[0]); + setrgb(0, 0, 0, &fleds[1]); + + // Handle lighting for indicator mode + if (fled_mode == FLED_INDI) { + fled_lock_update(host_keyboard_led_state()); + fled_layer_update(layer_state); + } +} + +void process_record_fled(uint16_t keycode, keyrecord_t *record) { + // Handle custom keycodes for front LED operation + switch (keycode) { + case FLED_MOD: // Change between front LED operation modes (off, indicator, RGB) + if (record->event.pressed) + fled_mode_cycle(); + break; + + case FLED_VAI: // Increase the brightness of the front LEDs by FLED_VAL_STEP + if (record->event.pressed) + fled_val_increase(); + break; + + case FLED_VAD: // Decrease the brightness of the front LEDs by FLED_VAL_STEP + if (record->event.pressed) + fled_val_decrease(); + break; + + default: + break; // Process all other keycodes normally + } + + return; +} + +void fled_load_conf(void) { + // Load config + fled_config fled_conf; + fled_conf.raw = eeprom_read_byte(FRONTLED_CONF_ADDR); + fled_mode = fled_conf.mode; + fled_val = fled_conf.val * FLED_VAL_STEP; + + // Load color data + uint8_t stored_cnt = eeprom_read_byte(FRONTLED_COLOR_CNT_ADDR); + uint16_t *color_ptr = FRONTLED_COLOR_ADDR; + caps_color.raw = eeprom_read_word(color_ptr); // Should always store at least 1 color + for (uint8_t i = 1; i < stored_cnt; i++) { + if (i == lc_size) // Can't load more layers than we have available + break; + layer_colors[i].raw = eeprom_read_word(&color_ptr[i]); + } + layer_colors[0].raw = 0; // hue = sat = 0 for layer 0 +} + +// Store current front led config in EEPROM +void fled_update_conf(void) +{ + // Create storage struct and set values + fled_config conf; + conf.mode = fled_mode; + + // Small hack to ensure max value is stored correctly + if (fled_val == 255) + conf.val = 256 / FLED_VAL_STEP; + else + conf.val = fled_val / FLED_VAL_STEP; + + // Store config + eeprom_update_byte(FRONTLED_CONF_ADDR, conf.raw); + + // Store color data + uint16_t *color_ptr = FRONTLED_COLOR_ADDR; + eeprom_update_word(color_ptr, caps_color.raw); + // Start from 1, layer 0 is not modifiable and therefore not persisted + uint8_t i = 1; + for (; i < lc_size; i++) { + if (i == FRONTLED_COLOR_MAXCNT) // Can't store more than the EEPROM we have available + break; + eeprom_update_word(&color_ptr[i], layer_colors[i].raw); + } + eeprom_update_byte(FRONTLED_COLOR_CNT_ADDR, i); // For safety, store the count of colors stored +} + +// Custom keycode functions + +void fled_mode_cycle(void) +{ + // FLED -> FLED_RGB -> FLED_INDI + switch (fled_mode) { + case FLED_OFF: + fled_mode = FLED_RGB; + rgblight_timer_enable(); + break; + + case FLED_RGB: + fled_mode = FLED_INDI; + break; + + case FLED_INDI: + fled_mode = FLED_OFF; + break; + } + + // Update stored config + fled_update_conf(); + rgblight_set(); +} + +void fled_val_increase(void) +{ + // Increase val by FLED_VAL_STEP, handling the upper edge case + if (fled_val + FLED_VAL_STEP > 255) + fled_val = 255; + else + fled_val += FLED_VAL_STEP; + + // Update stored config + fled_update_conf(); + + // Update and set LED state + if (fled_mode == FLED_INDI) { + fled_layer_update(layer_state); + fled_lock_update(host_keyboard_led_state()); + } else { + rgblight_set(); + } +} + +void fled_val_decrease(void) +{ + // Decrease val by FLED_VAL_STEP, handling the lower edge case + if (fled_val - FLED_VAL_STEP > 255) + fled_val = 255; + else + fled_val -= FLED_VAL_STEP; + + // Update stored config + fled_update_conf(); + + // Update and set LED state + if (fled_mode == FLED_INDI) { + fled_layer_update(layer_state); + fled_lock_update(host_keyboard_led_state()); + } else { + rgblight_set(); + } +} + +void fled_layer_update(layer_state_t state) { + // Determine and set colour of layer LED according to current layer + // if hue = sat = 0, leave LED off + uint8_t layer = get_highest_layer(state); + + if (layer < lc_size && !(layer_colors[layer].hue == 0 && layer_colors[layer].sat == 0)) { + sethsv(layer_colors[layer].hue, layer_colors[layer].sat, fled_val, &fleds[1]); + } else { + setrgb(0, 0, 0, &fleds[1]); + } +} + +void fled_lock_update(led_t led_state) { + // Set indicator LED appropriately, whether it is used or not + if (led_state.caps_lock) { + sethsv(caps_color.hue, caps_color.sat, fled_val, &fleds[0]); + } else { + setrgb(0, 0, 0, &fleds[0]); + } + + rgblight_set(); +} + +void set_fled_layer_color(uint8_t layer, hs_set hs) { + // Update layer colors and refresh LEDs + layer_colors[layer] = hs; + fled_layer_update(layer_state); + fled_update_conf(); +} + +hs_set get_fled_layer_color(uint8_t layer) { + return layer_colors[layer]; +} + +void set_fled_caps_color(hs_set hs) { + // Update caplock color and refresh LEDs + caps_color = hs; + fled_lock_update(host_keyboard_led_state()); + fled_update_conf(); +} + +hs_set get_fled_caps_color(void) { + return caps_color; +} + +// Fallback eeprom functions if VIA is not enabled +#ifndef VIA_ENABLE + +// Can be called in an overriding via_init_kb() to test if keyboard level code usage of +// EEPROM is invalid and use/save defaults. +bool via_eeprom_is_valid(void) +{ + char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54" + uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F ); + uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F ); + uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F ); + + return (eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0 ) == magic0 && + eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1 ) == magic1 && + eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2 ) == magic2 ); +} + +#endif diff --git a/keyboards/mxss/templates/keymap.c b/keyboards/mxss/templates/keymap.c new file mode 100644 index 0000000000..48cab22852 --- /dev/null +++ b/keyboards/mxss/templates/keymap.c @@ -0,0 +1,40 @@ +/* Copyright 2018 REPLACE_WITH_YOUR_NAME + * + * 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 <http://www.gnu.org/licenses/>. + */ +#include QMK_KEYBOARD_H + +hs_set caps_color = { .hue = 0, .sat = 255 }; + +// Colors for layers +// Format: {hue, saturation} +// {0, 0} to turn off the LED +// Add additional rows to handle more layers +hs_set layer_colors[4] = { + [0] = {.hue = 0, .sat = 0}, // Color for Layer 0 + [1] = {.hue = 86, .sat = 255}, // Color for Layer 1 + [2] = {.hue = 36, .sat = 255}, // Color for Layer 2 + [3] = {.hue = 185, .sat = 255}, // Color for Layer 3 +}; +size_t lc_size = ARRAY_SIZE(layer_colors); + +// Use NEW_SAFE_RANGE to define new custom keycodes in order to not overwrite the ones used for front LED control +enum custom_keycodes { + MY_KEYCODE = NEW_SAFE_RANGE, +}; + + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { +__KEYMAP_GOES_HERE__ +}; |