aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzer09 <zer09@users.noreply.github.com>2018-04-30 04:02:37 +0800
committerDrashna Jaelre <drashna@live.com>2018-04-29 13:02:37 -0700
commit7216fd0f47bb41d0a49432095767aef6ead33da2 (patch)
treea5585c8c4be4ada0fd945685446d0874c43abf68
parent3b7b1994cd9e3e61fdee84eff78875135642aa6c (diff)
downloadqmk_firmware-7216fd0f47bb41d0a49432095767aef6ead33da2.tar.gz
qmk_firmware-7216fd0f47bb41d0a49432095767aef6ead33da2.zip
My userspace and lets_split keymap (#2842)
* copied lets_slit to splinter * initial splinter layout * remove unused keymaps * implemented second half of the keyboard * initial definition of tap dance * the tap dance is working now tap dance for right hand 4c 2r hold - shift single tap - n double tap - ñ triple tap - Ñ * clear the keymap.c * put the tap state on to array * the n tilde tap dance should produce right shift if hold * add esc grv tap dance * remove the defined SS_LSFT on tap_dance.h because it was added on the quantum.h * minor cleanup for the keymap * use the X_* on tap dance * added super alt tap dance * use the NO_TAP on tap dance reset * allow track what rows and cols pressed * added the RGUI_ALT * keymap arrangement * use i2c * initial rgb * layer colors * initial rgb pressed key * set the layers led * SUCCESS!!! * cleaning * improve shifted layer * led brightness * initial caps rainbow * rename SET_LED_RGB to SET_LED_RGB_HEX * clean the SET_LED_RGB_HEX and added SET_LED_RGB * clean format * caps lock rainbow * rename key_led to set_key_led * caps lock rainbow enhanced * make varibiables static * change back the loop max value to 360 for the rainbow * add scroll lock to the rainbow led * fix pos calculation of right hand board * add ative keys and make rainbow color can override by key press * remove the TOTAL_MATRIX_POINTS * some improvments for the rgb * call the rgblight_set on the process_record_user * some enhancement for the leds * pass the dim value to set_layer_led and limit the brightness on _VL set the brightness to 2 if the dim value is less than 2 because their is not enought power for the leds. * remove the rgb steps on the config * use the non rev config * remove all the revisions * favor i2c instead of serial and remove all the ref for the serial * clang formatting * allow to save to eeprom the brightness value * add bootloader caterina this will enable soft reset key * initial commit for the userspace * added my own keymap for splinter * first working userspace * move splinter to handwired keyboards * handwired splinter default keymap * move some config to my keymap * cleanup some headers on the keymap * move the EECONFIG_RGB_DIM to the user space * I fix remove the GUI on SPC and ENT * remove the default include on tap_dance.c * add lights.c and refactoring * fix wrong source for led index * seperate the variable on set_layer_led for readabilty. * set the usb max power consumption to 50 * fix led lighting * add new enums for tap dance * use romeve path avr on eeprom.h * fix wrong spelling on TP names * changed the tap dance * allow to set rainbow on some pressed key * add reset key * fix error on matrix.c if ROW2COL is used * add extraflags -flto * See e2352d4 * Got no love from i2c, serial to the rescue * Fix the led will lit up to color red after boot * Trial if the power can handle yellow color at full * Add comment * Use EE_HANDS * add config.h in the use space * KC_N on BL should wrap in SFT_T * See d13567d, put it back but increase 1 level * Fix led soldering mistake * set the tapping_term to 100 * Use TT for the changing the layer * Remove the changing space to enter and vice version on BL and UL * Increate the tapping term * Use tap dance on changing layer * Add assorted layer * propery way to tapdance * Remove DA_EGRV This also fix the wrong placement of the reset and dance lspr should register the KC_LGUI on finished not unregistered. * Remove the media control to the up and down layer * Remove the interrupted state of the tap dance * swapt the space and enter on to th caps * Shorthand * Keymap update * My keymap for lets_split * cleaning
-rw-r--r--keyboards/lets_split/keymaps/zer09/config.h59
-rw-r--r--keyboards/lets_split/keymaps/zer09/keymap.c38
-rw-r--r--keyboards/lets_split/keymaps/zer09/keymap.h32
-rw-r--r--keyboards/lets_split/keymaps/zer09/rules.mk6
-rw-r--r--users/zer09/config.h32
-rw-r--r--users/zer09/lights.c189
-rw-r--r--users/zer09/lights.h45
-rw-r--r--users/zer09/rules.mk2
-rw-r--r--users/zer09/tap_dance.c182
-rw-r--r--users/zer09/tap_dance.h55
-rw-r--r--users/zer09/zer09.c88
-rw-r--r--users/zer09/zer09.h18
12 files changed, 746 insertions, 0 deletions
diff --git a/keyboards/lets_split/keymaps/zer09/config.h b/keyboards/lets_split/keymaps/zer09/config.h
new file mode 100644
index 000000000..73438d8a9
--- /dev/null
+++ b/keyboards/lets_split/keymaps/zer09/config.h
@@ -0,0 +1,59 @@
1/*
2This is the c configuration file for the keymap
3
4Copyright 2012 Jun Wako <wakojun@gmail.com>
5Copyright 2015 Jack Humbert
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef CONFIG_USER_H
22#define CONFIG_USER_H
23
24#include "../../config.h"
25
26/* key matrix size */
27/* Rows are doubled-up */
28#undef MATRIX_ROWS
29#undef MATRIX_COLS
30#define MATRIX_ROWS 10
31#define MATRIX_COLS 5
32
33#undef MATRIX_ROW_PINS
34#undef MATRIX_COL_PINS
35#define MATRIX_ROW_PINS { C6, D7, E6, B4, B5 }
36#define MATRIX_COL_PINS { F7, B1, B3, B2, B6 }
37
38#define CATERINA_BOOTLOADER
39#define USB_MAX_POWER_CONSUMPTION 50
40
41/* Use I2C or Serial, not both */
42
43#define USE_SERIAL
44// #define USE_I2C
45
46/* Select hand configuration */
47
48/* #define MASTER_LEFT */
49// #define MASTER_RIGHT
50#define EE_HANDS
51
52/* ws2812 RGB LED */
53#undef RGBLED_NUM
54#define RGB_DI_PIN D3
55#define RGBLIGHT_TIMER
56#define RGBLED_NUM 50
57#define ws2812_PORTREG PORTD
58#define ws2812_DDRREG DDRD
59#endif
diff --git a/keyboards/lets_split/keymaps/zer09/keymap.c b/keyboards/lets_split/keymaps/zer09/keymap.c
new file mode 100644
index 000000000..8d0eaf141
--- /dev/null
+++ b/keyboards/lets_split/keymaps/zer09/keymap.c
@@ -0,0 +1,38 @@
1#include "keymap.h"
2
3extern keymap_config_t keymap_config;
4
5#define _baseLayer LAYOUT( \
6 KC_QUOTE, KC_COMMA, KC_DOT, KC_P, KC_Y, /**/KC_F, KC_G, KC_C, KC_R, KC_L, \
7 CTL_T(KC_A), SFT_T(KC_O), ALT_T(KC_E), KC_U, KC_I, /**/KC_D, KC_H, ALT_T(KC_T), SFT_T(KC_N), CTL_T(KC_S), \
8 KC_SCOLON, KC_Q, KC_J, KC_K, KC_X, /**/KC_B, KC_M, KC_W, KC_V, KC_Z, \
9 TD(DA_UPLY), MO(_VL), KC_TAB, KC_BSPACE, KC_ESC, /**/KC_INS, KC_HOME, KC_PGUP, MO(_VL), TD(DA_UPLY), \
10 TD(DA_DWLY), TD(DA_LCTL), KC_SPC, TD(DA_LSPR), LSFT_T(KC_CAPS),/**/SFT_T(KC_CAPS), TD(DA_RALT), KC_ENT, TD(DA_RCTL), TD(DA_DWLY))
11
12#define _upLayer LAYOUT( \
13 KC_4, KC_5, KC_6, _______, _______,/**/ _______, KC_RBRC, _______, _______, _______, \
14 LCTL_T(KC_1), LSFT_T(KC_2), LALT_T(KC_3), _______, _______,/**/ KC_LBRC, KC_BSLS, _______, _______, _______, \
15 KC_7, KC_8, KC_9, KC_0, KC_GRV, /**/ KC_SLSH, _______, _______, _______, _______, \
16 _______, _______, _______, _______, _______,/**/ KC_DEL, KC_END, KC_PGDN, _______, _______, \
17 _______, _______, _______, _______, _______,/**/ _______, _______, _______, _______, _______)
18
19#define _downLayer LAYOUT( \
20 KC_F4, KC_F5, KC_F6, KC_F12, _______,/**/ _______, KC_RPRN, _______, _______, _______, \
21 LCTL_T(KC_F1), LSFT_T(KC_F2), LALT_T(KC_F3), KC_F11, _______,/**/ KC_LPRN, KC_EQUAL, KC_LEFT, KC_UP, KC_RIGHT, \
22 KC_F7, KC_F8, KC_F9, KC_F10, _______,/**/ KC_MINUS, _______, _______, KC_DOWN, _______, \
23 _______, _______, _______, _______, _______,/**/ KC_PSCR, KC_SLCK, KC_PAUSE, _______, _______, \
24 _______, _______, _______, _______, _______,/**/ _______, _______, _______, _______, _______)
25
26#define _astdLayer LAYOUT( \
27 KC_MPRV, KC_MUTE, _______, _______, _______,/**/KC_PSCR, KC_SLCK, KC_PAUSE, _______, KC_RGUP, \
28 KC_MPLY, KC_VOLD, _______, _______, _______,/**/_______, _______, _______, _______, KC_RGDWN, \
29 KC_MNXT, KC_VOLU, RESET, _______, _______,/**/_______, _______, RESET, _______, _______, \
30 _______, _______, _______, _______, _______,/**/_______, _______, _______, _______, _______, \
31 _______, _______, _______, _______, _______,/**/_______, _______, _______, _______, _______)
32
33const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
34 [_BL] = _baseLayer,
35 [_UL] = _upLayer,
36 [_DL] = _downLayer,
37 [_VL] = _upLayer,
38 [_AL] = _astdLayer};
diff --git a/keyboards/lets_split/keymaps/zer09/keymap.h b/keyboards/lets_split/keymaps/zer09/keymap.h
new file mode 100644
index 000000000..03f8f480a
--- /dev/null
+++ b/keyboards/lets_split/keymaps/zer09/keymap.h
@@ -0,0 +1,32 @@
1#include "lets_split.h"
2#include "action_layer.h"
3#include "eeconfig.h"
4#include "tap_dance.h"
5#include "zer09.h"
6
7#ifdef LAYOUT_ortho_4x12
8#undef LAYOUT_ortho_4x12
9#endif
10
11#ifdef LAYOUT
12#undef LAYOUT
13#define LAYOUT( \
14 L00, L01, L02, L03, L04, R00, R01, R02, R03, R04, \
15 L10, L11, L12, L13, L14, R10, R11, R12, R13, R14, \
16 L20, L21, L22, L23, L24, R20, R21, R22, R23, R24, \
17 L30, L31, L32, L33, L34, R30, R31, R32, R33, R34, \
18 L40, L41, L42, L43, L44, R40, R41, R42, R43, R44 \
19) \
20 { \
21 { L00, L01, L02, L03, L04 }, \
22 { L10, L11, L12, L13, L14 }, \
23 { L20, L21, L22, L23, L24 }, \
24 { L30, L31, L32, L33, L34 }, \
25 { L40, L41, L42, L43, L44 }, \
26 { R00, R01, R02, R03, R04 }, \
27 { R10, R11, R12, R13, R14 }, \
28 { R20, R21, R22, R23, R24 }, \
29 { R30, R31, R32, R33, R34 }, \
30 { R40, R41, R42, R43, R44 } \
31 }
32#endif
diff --git a/keyboards/lets_split/keymaps/zer09/rules.mk b/keyboards/lets_split/keymaps/zer09/rules.mk
new file mode 100644
index 000000000..d8adc7088
--- /dev/null
+++ b/keyboards/lets_split/keymaps/zer09/rules.mk
@@ -0,0 +1,6 @@
1RGBLIGHT_ENABLE = yes
2TAP_DANCE_ENABLE = yes
3
4ifndef QUANTUM_DIR
5 include ../../../../Makefile
6endif
diff --git a/users/zer09/config.h b/users/zer09/config.h
new file mode 100644
index 000000000..766806462
--- /dev/null
+++ b/users/zer09/config.h
@@ -0,0 +1,32 @@
1#ifndef USERSPACE_CONFIG_H
2#define USERSPACE_CONFIG_H
3
4#ifndef QMK_KEYS_PER_SCAN
5#define QMK_KEYS_PER_SCAN 4
6#endif // !QMK_KEYS_PER_SCAN
7
8// this makes it possible to do rolling combos (zx) with keys that
9// convert to other keys on hold (z becomes ctrl when you hold it,
10// and when this option isn't enabled, z rapidly followed by x
11// actually sends Ctrl-x. That's bad.)
12#define IGNORE_MOD_TAP_INTERRUPT
13#undef PERMISSIVE_HOLD
14#undef PREVENT_STUCK_MODIFIERS
15
16#define FORCE_NKRO
17
18#ifndef TAPPING_TOGGLE
19#define TAPPING_TOGGLE 1
20#endif
21
22#ifdef TAPPING_TERM
23#undef TAPPING_TERM
24#endif
25#define TAPPING_TERM 120
26
27// Disable action_get_macro and fn_actions, since we don't use these
28// and it saves on space in the firmware.
29#define NO_ACTION_MACRO
30#define NO_ACTION_FUNCTION
31
32#endif
diff --git a/users/zer09/lights.c b/users/zer09/lights.c
new file mode 100644
index 000000000..448ef494e
--- /dev/null
+++ b/users/zer09/lights.c
@@ -0,0 +1,189 @@
1#include "lights.h"
2
3static bool active_key_pos[50] = {};
4static uint8_t led_dim = 0;
5
6volatile led_key rbw_led_keys[RBW] = {
7 [RBW_LCTL] = {DEFAULT, 21, true}, [RBW_LCAP] = {DEFAULT, 24, false},
8 [RBW_LSPR] = {DEFAULT, 23, true}, [RBW_RCTL] = {DEFAULT, 48, true},
9 [RBW_RCAP] = {DEFAULT, 45, false}, [RBW_RALT] = {DEFAULT, 46, true},
10 [RBW_SCRL] = {DEFAULT, 42, true}};
11
12/* Pressed led color. */
13const uint32_t _PC[3] = {0xFF, 0x00, 0x00};
14
15/* Layer color. */
16const uint8_t _LC[5][3] = {[_BL] = {0x00, 0x00, 0x00},
17 [_UL] = {0x00, 0x00, 0xFF},
18 [_VL] = {0xFF, 0xFF, 0x00},
19 [_DL] = {0x00, 0xFF, 0x00},
20 [_AL] = {0xFF, 0x00, 0x00}};
21
22/* Color table by sine wave */
23const uint8_t _LIGHTS[360] = {
24 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8,
25 11, 12, 9, 13, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 35,
26 37, 39, 42, 44, 47, 49, 52, 55, 58, 60, 63, 66, 69, 72, 75,
27 78, 81, 85, 88, 91, 94, 97, 101, 104, 107, 111, 114, 117, 121, 124,
28 127, 131, 134, 137, 141, 144, 147, 150, 154, 157, 160, 163, 167, 170, 173,
29 176, 179, 182, 185, 188, 191, 194, 197, 200, 202, 205, 208, 210, 213, 215,
30 217, 220, 222, 224, 226, 229, 231, 232, 234, 236, 238, 239, 241, 242, 244,
31 245, 246, 248, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255, 255, 255,
32 255, 255, 255, 255, 254, 254, 253, 253, 252, 251, 251, 250, 249, 248, 246,
33 245, 244, 242, 241, 239, 238, 236, 234, 232, 231, 229, 226, 224, 222, 220,
34 217, 215, 213, 210, 208, 205, 202, 200, 197, 194, 191, 188, 185, 182, 179,
35 176, 173, 170, 167, 163, 160, 157, 154, 150, 147, 144, 141, 137, 134, 131,
36 127, 124, 121, 117, 114, 111, 107, 104, 101, 97, 94, 91, 88, 85, 81,
37 78, 75, 72, 69, 66, 63, 60, 58, 55, 52, 49, 47, 44, 42, 39,
38 37, 35, 32, 30, 28, 26, 24, 22, 20, 18, 17, 15, 13, 12, 11,
39 9, 8, 7, 6, 5, 4, 3, 2, 2, 1, 1, 0, 0, 0, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
48
49void set_key_led(keyrecord_t *record, uint8_t lyr) {
50 static uint8_t base = 5;
51
52 uint8_t r = record->event.key.row;
53 uint8_t c = record->event.key.col;
54 uint8_t pos;
55
56 // This was the result of my soldering.
57 // Lesson of the day: always check.
58 if (r < 5) {
59 pos = r % 2 == 0 ? r * base + c : r * base + (base - (c + 1));
60 } else {
61 pos = r % 2 == 0 ? r * base + (base - (c + 1)) : r * base + c;
62 }
63
64 if (record->event.pressed) {
65 active_key_pos[pos] = true;
66 SET_LED_RGB(_PC[0], _PC[1], _PC[2], led_dim, pos);
67 } else {
68 active_key_pos[pos] = false;
69 SET_LED_RGB(_LC[lyr][0], _LC[lyr][1], _LC[lyr][2], led_dim, pos);
70 }
71}
72
73/* Fix for unknown reason after testin flash the eeprom handedness,
74 the leds will ligth up after boot.
75 This should be call in the set layer led.*/
76bool is_first_run(void) {
77 static uint8_t run = 0;
78
79 if (run == 0) {
80 run++;
81 return true;
82 } else {
83 return false;
84 }
85}
86
87bool set_layer_led(uint8_t lyr) {
88 static uint8_t p_lyr = 0; // Previous layer.
89 static uint8_t p_dim = 0; // Previous dim.
90
91 if (p_lyr == lyr && p_dim == led_dim && !is_first_run()) {
92 return false;
93 }
94
95 p_lyr = lyr;
96 p_dim = led_dim;
97 const uint8_t r = _LC[lyr][0];
98 const uint8_t g = _LC[lyr][1];
99 const uint8_t b = _LC[lyr][2];
100 const uint8_t d = (p_lyr == _VL && p_dim < 1) ? 1 : p_dim;
101
102 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
103 SET_LED_RGB(r, g, b, d, i);
104 }
105
106 return true;
107}
108
109bool rainbow_loop(uint8_t lyr) {
110 static uint16_t last_timer = 0;
111 static uint16_t i = 0;
112 static uint8_t r, g, b, pos;
113
114 if (timer_elapsed(last_timer) < 8) {
115 return false;
116 }
117
118 if (i >= 360) {
119 i = 0;
120 }
121
122 last_timer = timer_read();
123 r = _LIGHTS[(i + 120) % 360];
124 g = _LIGHTS[i];
125 b = _LIGHTS[(i + 240) % 360];
126
127 i++;
128
129 bool set_rbw = false;
130
131 for (uint8_t j = 0; j < RBW; j++) {
132 pos = rbw_led_keys[j].pos;
133
134 switch (rbw_led_keys[j].status) {
135 case ENABLED:
136 if (!active_key_pos[pos] || rbw_led_keys[j].forced) {
137 SET_LED_RGB(r, g, b, led_dim, pos);
138 set_rbw = true;
139 }
140
141 break;
142 case DISABLED:
143 if (!active_key_pos[pos] || rbw_led_keys[j].forced) {
144 SET_LED_RGB(_LC[lyr][0], _LC[lyr][1], _LC[lyr][2], led_dim, pos);
145 set_rbw = true;
146 }
147
148 rbw_led_keys[j].status = DEFAULT;
149 break;
150 default:
151 break;
152 }
153 }
154
155 return set_rbw;
156}
157
158bool led_brightness(uint16_t keycode, keyrecord_t *record) {
159 switch (keycode) {
160 case RGUP:
161 if (record->event.pressed && led_dim > 0) {
162 led_dim--;
163 eeprom_write_byte(EECONFIG_LED_DIM_LVL, led_dim);
164 }
165
166 return true;
167 break;
168 case RGDWN:
169 if (record->event.pressed && led_dim < 8) {
170 led_dim++;
171 eeprom_write_byte(EECONFIG_LED_DIM_LVL, led_dim);
172 }
173
174 return true;
175 break;
176 default:
177 return false;
178 break;
179 }
180}
181
182void eeprom_read_led_dim_lvl(void) {
183 led_dim = eeprom_read_byte(EECONFIG_LED_DIM_LVL);
184
185 if (led_dim > 8 || led_dim < 0) {
186 led_dim = 0;
187 eeprom_write_byte(EECONFIG_LED_DIM_LVL, led_dim);
188 }
189}
diff --git a/users/zer09/lights.h b/users/zer09/lights.h
new file mode 100644
index 000000000..f1bd7245d
--- /dev/null
+++ b/users/zer09/lights.h
@@ -0,0 +1,45 @@
1#ifndef LIGHTS_H
2#define LIGHTS_H
3
4#include "eeprom.h"
5#include "tap_dance.h"
6#include "zer09.h"
7
8/* Will hold the RGB brightness level */
9#define EECONFIG_LED_DIM_LVL (uint8_t *)15
10
11#define SET_LED_RGB(r, g, b, led_dim, pos) \
12 setrgb(r >> led_dim, g >> led_dim, b >> led_dim, (LED_TYPE *)&led[pos])
13
14typedef enum {
15 DEFAULT,
16 ENABLED,
17 DISABLED,
18} led_status;
19
20typedef struct {
21 led_status status;
22 uint8_t pos;
23 bool forced;
24} led_key;
25
26enum rbw_keys {
27 RBW_LCTL,
28 RBW_LCAP,
29 RBW_LSPR,
30 RBW_RCTL,
31 RBW_RCAP,
32 RBW_RALT,
33 RBW_SCRL,
34 RBW
35};
36
37extern volatile led_key rbw_led_keys[RBW];
38
39void set_key_led(keyrecord_t *record, uint8_t lyr);
40bool set_layer_led(uint8_t lyr);
41bool rainbow_loop(uint8_t lyr);
42bool led_brightness(uint16_t keycode, keyrecord_t *record);
43void eeprom_read_led_dim_lvl(void);
44
45#endif
diff --git a/users/zer09/rules.mk b/users/zer09/rules.mk
new file mode 100644
index 000000000..43b409eca
--- /dev/null
+++ b/users/zer09/rules.mk
@@ -0,0 +1,2 @@
1SRC += zer09.c tap_dance.c lights.c
2EXTRAFLAGS += -flto
diff --git a/users/zer09/tap_dance.c b/users/zer09/tap_dance.c
new file mode 100644
index 000000000..a23705ad8
--- /dev/null
+++ b/users/zer09/tap_dance.c
@@ -0,0 +1,182 @@
1#include "tap_dance.h"
2#include "lights.h"
3
4qk_tap_dance_action_t tap_dance_actions[] = {
5 [DA_LCTL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_lctl_finished,
6 dance_lctl_reset),
7 [DA_LSPR] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_lspr_finished,
8 dance_lspr_reset),
9 [DA_RCTL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_rctl_finished,
10 dance_rctl_reset),
11 [DA_RALT] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_ralt_finished,
12 dance_ralt_reset),
13 [DA_UPLY] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_uply_finished,
14 dance_uply_reset),
15 [DA_DWLY] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_dwly_finished,
16 dance_dwly_reset),
17};
18
19volatile uint8_t active_layer = _BL;
20static tap upltap_state = {.state = 0};
21static tap dwltap_state = {.state = 0};
22static tap lsprtap_state = {.state = 0};
23static tap ralttap_state = {.state = 0};
24
25void layer_switcher_tap(uint8_t new_layer) {
26 layer_off(active_layer);
27 layer_on(new_layer);
28 active_layer = new_layer;
29}
30
31int cur_dance(qk_tap_dance_state_t *state) {
32 switch (state->count) {
33 case 1:
34 return state->pressed == 0 ? SINGLE_TAP : SINGLE_HOLD;
35 case 2:
36 return state->pressed == 0 ? DOUBLE_TAP : DOUBLE_HOLD;
37 case 3:
38 return state->pressed == 0 ? TRIPLE_TAP : TRIPLE_HOLD;
39 default:
40 return state->pressed == 0 ? DEFAULT_TAP : DEFAULT_HOLD;
41 }
42}
43
44void dance_lctl_finished(qk_tap_dance_state_t *state, void *user_data) {
45 rbw_led_keys[RBW_LCTL].status = ENABLED;
46 register_code(KC_LCTRL);
47};
48
49void dance_lctl_reset(qk_tap_dance_state_t *state, void *user_data) {
50 unregister_code(KC_LCTRL);
51 rbw_led_keys[RBW_LCTL].status = DISABLED;
52};
53
54void dance_lspr_finished(qk_tap_dance_state_t *state, void *user_data) {
55 lsprtap_state.state = cur_dance(state);
56
57 switch (lsprtap_state.state) {
58 case DOUBLE_HOLD:
59 rbw_led_keys[RBW_LSPR].status = ENABLED;
60 register_code(KC_LALT);
61 break;
62 default:
63 register_code(KC_LGUI);
64 break;
65 }
66};
67
68void dance_lspr_reset(qk_tap_dance_state_t *state, void *user_data) {
69 switch (lsprtap_state.state) {
70 case DOUBLE_HOLD:
71 unregister_code(KC_LALT);
72 rbw_led_keys[RBW_LSPR].status = DISABLED;
73 break;
74 default:
75 unregister_code(KC_LGUI);
76 break;
77 }
78};
79
80void dance_rctl_finished(qk_tap_dance_state_t *state, void *user_data) {
81 rbw_led_keys[RBW_RCTL].status = ENABLED;
82 register_code(KC_RCTRL);
83};
84
85void dance_rctl_reset(qk_tap_dance_state_t *state, void *user_data) {
86 unregister_code(KC_RCTRL);
87 rbw_led_keys[RBW_RCTL].status = DISABLED;
88};
89
90void dance_ralt_finished(qk_tap_dance_state_t *state, void *user_data) {
91 ralttap_state.state = cur_dance(state);
92
93 switch (ralttap_state.state) {
94 case DOUBLE_HOLD:
95 rbw_led_keys[RBW_RALT].status = ENABLED;
96 unregister_code(KC_LGUI);
97 break;
98 default:
99 register_code(KC_RALT);
100 break;
101 }
102};
103
104void dance_ralt_reset(qk_tap_dance_state_t *state, void *user_data) {
105 switch (ralttap_state.state) {
106 case DOUBLE_HOLD:
107 unregister_code(KC_RGUI);
108 rbw_led_keys[RBW_RALT].status = DISABLED;
109 break;
110 default:
111 unregister_code(KC_RALT);
112 break;
113 }
114};
115
116void dance_uply_finished(qk_tap_dance_state_t *state, void *user_data) {
117 upltap_state.state = cur_dance(state);
118
119 switch (upltap_state.state) {
120 case SINGLE_TAP:
121 if (active_layer == _UL) {
122 layer_switcher_tap(_BL);
123 } else {
124 layer_switcher_tap(_UL);
125 }
126 break;
127 case SINGLE_HOLD:
128 layer_switcher_tap(_UL);
129 break;
130 default:
131 layer_switcher_tap(_BL);
132 break;
133 }
134}
135
136void dance_uply_reset(qk_tap_dance_state_t *state, void *user_data) {
137 switch (upltap_state.state) {
138 case SINGLE_TAP:
139 break;
140 case SINGLE_HOLD:
141 default:
142 layer_switcher_tap(_BL);
143 break;
144 }
145 upltap_state.state = 0;
146}
147
148void dance_dwly_finished(qk_tap_dance_state_t *state, void *user_data) {
149 dwltap_state.state = cur_dance(state);
150
151 switch (dwltap_state.state) {
152 case SINGLE_TAP:
153 if (active_layer == _DL) {
154 layer_switcher_tap(_BL);
155 } else {
156 layer_switcher_tap(_DL);
157 }
158 break;
159 case SINGLE_HOLD:
160 layer_switcher_tap(_DL);
161 break;
162 case DOUBLE_HOLD:
163 layer_switcher_tap(_AL);
164 break;
165 default:
166 layer_switcher_tap(_BL);
167 break;
168 }
169}
170
171void dance_dwly_reset(qk_tap_dance_state_t *state, void *user_data) {
172 switch (dwltap_state.state) {
173 case SINGLE_TAP:
174 break;
175 case SINGLE_HOLD:
176 case DOUBLE_HOLD:
177 default:
178 layer_switcher_tap(_BL);
179 break;
180 }
181 dwltap_state.state = 0;
182}
diff --git a/users/zer09/tap_dance.h b/users/zer09/tap_dance.h
new file mode 100644
index 000000000..555c15924
--- /dev/null
+++ b/users/zer09/tap_dance.h
@@ -0,0 +1,55 @@
1#ifndef TAP_DANCE_H
2#define TAP_DANCE_H
3
4#include "zer09.h"
5
6typedef struct {
7 int state;
8} tap;
9
10enum {
11 DEFAULT_TAP,
12 DEFAULT_HOLD,
13 SINGLE_TAP,
14 SINGLE_HOLD,
15 DOUBLE_TAP,
16 DOUBLE_HOLD,
17 TRIPLE_TAP,
18 TRIPLE_HOLD
19};
20
21enum {
22 DA_SAFE_START,
23 DA_LCTL,
24 DA_LSPR,
25 DA_RCTL,
26 DA_RALT,
27 DA_UPLY,
28 DA_DWLY,
29 DA_SAFE_END
30};
31
32extern volatile uint8_t active_layer;
33
34void layer_switcher_tap(uint8_t);
35int cur_dance(qk_tap_dance_state_t *);
36
37void dance_lctl_finished(qk_tap_dance_state_t *, void *);
38void dance_lctl_reset(qk_tap_dance_state_t *, void *);
39
40void dance_lspr_finished(qk_tap_dance_state_t *, void *);
41void dance_lspr_reset(qk_tap_dance_state_t *, void *);
42
43void dance_rctl_finished(qk_tap_dance_state_t *, void *);
44void dance_rctl_reset(qk_tap_dance_state_t *, void *);
45
46void dance_ralt_finished(qk_tap_dance_state_t *, void *);
47void dance_ralt_reset(qk_tap_dance_state_t *, void *);
48
49void dance_uply_finished(qk_tap_dance_state_t *, void *);
50void dance_uply_reset(qk_tap_dance_state_t *, void *);
51
52void dance_dwly_finished(qk_tap_dance_state_t *, void *);
53void dance_dwly_reset(qk_tap_dance_state_t *, void *);
54
55#endif
diff --git a/users/zer09/zer09.c b/users/zer09/zer09.c
new file mode 100644
index 000000000..a6768f0a1
--- /dev/null
+++ b/users/zer09/zer09.c
@@ -0,0 +1,88 @@
1#include "zer09.h"
2#include "lights.h"
3#include "tap_dance.h"
4
5__attribute__((weak)) void matrix_init_keymap(void) {}
6
7__attribute__((weak)) void matrix_scan_keymap(void) {}
8
9__attribute__((weak)) bool process_record_keymap(uint16_t keycode,
10 keyrecord_t *record) {
11 return true;
12}
13
14__attribute__((weak)) void led_set_keymap(uint8_t usb_led) {}
15
16static uint8_t c_lyr = 0; // current layer.
17
18bool shifted_layer(void) {
19 static bool is_shifted = false;
20
21 if (c_lyr == _VL) {
22 if (!is_shifted) {
23 register_code(KC_LSFT);
24 is_shifted = true;
25 return true;
26 }
27 } else {
28 if (is_shifted) {
29 unregister_code(KC_LSFT);
30 is_shifted = false;
31 return true;
32 }
33 }
34
35 return false;
36}
37
38void matrix_init_user(void) {
39 eeprom_read_led_dim_lvl();
40
41 matrix_init_keymap();
42}
43
44void matrix_scan_user(void) {
45 static uint8_t is_leds_changes = 1;
46 c_lyr = biton32(layer_state);
47
48 is_leds_changes = is_leds_changes << set_layer_led(c_lyr);
49 is_leds_changes = is_leds_changes << shifted_layer();
50 is_leds_changes = is_leds_changes << rainbow_loop(c_lyr);
51
52 if (is_leds_changes > 1) {
53 rgblight_set();
54 is_leds_changes = 1;
55 }
56
57 matrix_scan_keymap();
58}
59
60bool process_record_user(uint16_t keycode, keyrecord_t *record) {
61 set_key_led(record, c_lyr);
62
63 if (led_brightness(keycode, record)) {
64 rgblight_set();
65 return false;
66 }
67
68 rgblight_set();
69 return process_record_keymap(keycode, record);
70}
71
72void led_set_user(uint8_t usb_led) {
73 if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
74 rbw_led_keys[RBW_LCAP].status = ENABLED;
75 rbw_led_keys[RBW_RCAP].status = ENABLED;
76 } else {
77 rbw_led_keys[RBW_LCAP].status = DISABLED;
78 rbw_led_keys[RBW_RCAP].status = DISABLED;
79 }
80
81 if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
82 rbw_led_keys[RBW_SCRL].status = ENABLED;
83 } else {
84 rbw_led_keys[RBW_SCRL].status = DISABLED;
85 }
86
87 led_set_keymap(usb_led);
88}
diff --git a/users/zer09/zer09.h b/users/zer09/zer09.h
new file mode 100644
index 000000000..75c1d3cad
--- /dev/null
+++ b/users/zer09/zer09.h
@@ -0,0 +1,18 @@
1#ifndef USERSPACE
2#define USERSPACE
3
4#include "quantum.h"
5
6enum custom_keycodes { CK_SAFE = SAFE_RANGE, RGUP, RGDWN, NEWPLACEHOLDER };
7
8#define _______ KC_TRNS
9#define KC_RGUP RGUP
10#define KC_RGDWN RGDWN
11
12#define _BL 0 // The base layer
13#define _UL 1 // The up layer
14#define _DL 2 // The down layer
15#define _VL 3 // The shifted up layer
16#define _AL 4 // The assorted layer
17
18#endif