summaryrefslogtreecommitdiff
path: root/keyboards/knops/mini/keymaps/mverteuil/keymap.c
blob: bd172e7aa8228c782e70ae4a6c9a97ca5add5d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include QMK_KEYBOARD_H

#define MAXIMIZ A(G(KC_F))
#define NXTDSPL C(A(G(KC_RIGHT)))
#define BTMHALF A(G(KC_DOWN))
#define TOPHALF A(G(KC_UP))
#define NXTTHRD SS_LCTL(SS_LALT(SS_TAP(X_RIGHT)))
#define PRVTHRD C(A(KC_LEFT))

#define LT_MSTP LT(_LAYER_SELECT, KC_MSTP)
#define LT_ESC LT(_LAYER_SELECT, KC_ESC)
#define LT_NXTH TD(TD_SPEC)

#define writeLayerLedState(layer) writePin(layer)
#define layer_led_0_off B6, false
#define layer_led_1_off D5, true
#define layer_led_2_off B0, false
#define layer_led_0_on B6, true
#define layer_led_1_on D5, false
#define layer_led_2_on B0, true

void led_init_animation(void);
void led_set_layer(int layer);
void td_spectacles_finish(qk_tap_dance_state_t *state, void *user_data);
void td_spectacles_reset(qk_tap_dance_state_t *state, void *user_data);

enum layer_led_mode {
    ALL_LAYERS_OFF = -1,
    LAYER_0,
    LAYER_1,
    LAYER_2,
    LAYER_3,
    LAYER_4,
    LAYER_5,
    ALL_LAYERS_ON,
};

enum mini_layers {
    _MEDIA,
    _COPYPASTA,
    _SPECTACLES,
    _LAYER_3,
    _LAYER_4,
    _LAYER_5,
    _LAYER_SELECT,
};

enum { TD_SPEC = 0 };

qk_tap_dance_action_t tap_dance_actions[] = {
    /* Tap once for spectacles macro, hold for layer toggle */
    [TD_SPEC] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, td_spectacles_finish, td_spectacles_reset),
};

/*
 *   Key Layout
 *   _____   _____   _____
 *  |     | |     | |     |
 *  |  1  | |  2  | |  3  |
 *  |_____| |_____| |_____|
 *   _____   _____   _____
 *  |     | |     | |     |
 *  |  4  | |  5  | |  6  |
 *  |_____| |_____| |_____|
 *
 *  Hold 1 and:
 *    - press 4, 5, or 6 to change layers
 *    - press 3 to reset, or press and hold 3 to enter DFU programming mode
 *
 *  If something prevents you from using the above to reprogram, you can hold 3 while powering on as a fallback.
 */

/* clang-format off */
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /*
     *  Layer 0 (Media Keys)
     *   _____   _____   _____
     *  |     | |     | |     |
     *  |Stop | |VolUp| |Play |
     *  |_____| |_____| |_____|
     *   _____   _____   _____
     *  |     | |     | |     |
     *  |Prev | |VolDn| |Next |
     *  |_____| |_____| |_____|
     *
     */
    [_MEDIA] = LAYOUT(
        LT_MSTP, KC_VOLU, KC_MPLY,
        KC_MPRV, KC_VOLD, KC_MNXT
    ),

    /*
     *  Layer 1 (Copy and Paste Macros)
     *   _____   _____   _____
     *  |     | |     | |     |
     *	| ESC | |Ctl+Z| |CSf+Z|
     *	|_____| |_____| |_____|
     *   _____   _____   _____
     *  |     | |     | |     |
     *	|Ctl+X| |Ctl+C| |Ctl+V|
     *	|_____| |_____| |_____|
     *
     */

    [_COPYPASTA] = LAYOUT(
        LT_ESC,  C(KC_Z), C(S(KC_Z)),
        C(KC_X), C(KC_C), C(KC_V)
    ),

    /*
     *   Layer 2 (Spectacles Macros)
     *   _LT&_   _____   _____
     *  | Win | | Win | | Win |
     *  | Next| | Top | |Mximze
     *  |_1/3_| |_1/2_| |_____|
     *   _____	 _____	 _____
     *  | Win | | Win | | Win |
     *  | Prev| | Bot | | Next|
     *  |_1/3_| |_1/2_| |Displ|
     *
     */
    [_SPECTACLES] = LAYOUT(
        LT_NXTH,TOPHALF,MAXIMIZ,
        PRVTHRD,BTMHALF,NXTDSPL
    ),

    /*
     *  Layer 6 (Layer Select/Reset)
     *   _____   _____   _____
     *  |     | |     | |     |
     *  |None | |None | |Reset|
     *  |_____| |_____| |_____|
     *   _____   _____   _____
     *  |Layer| |Layer| |Layer|
     *  |  0  | |  1  | |  2  |
     *  |_____| |_____| |_____|
     *
     *  Layers 0, 1, and 2 have the top left button held to activate this layer.
     *  Then press the specific layer to switch to it.
     *
     */
    [_LAYER_SELECT] = LAYOUT(
        _______, _______, RESET,
        TO(_MEDIA),TO(_COPYPASTA),TO(_SPECTACLES)
    )
};
/* clang-format on */

/*
 *	Knops Mini LED Numbers:
 *   _____   _____   _____
 *  |     | |     | |     |
 *  |  1  | |  2  | |  3  |    <---
 *  |_____| |_____| |_____|       |      These LEDs are called 'Switch LEDs'
 *   _____   _____   _____        |----- To turn on/off these leds, use:
 *  |     | |     | |     |       |          set_switch_led( [1-6], [true/false]);
 *  |  4  | |  5  | |  6  |    <---
 *  |_____| |_____| |_____|
 *
 *	 < 0 >   < 1 >   < 2 >     <---      These front-LEDs are called 'Layer LEDs'
 *                                       To turn on/off these leds, use:
 *                                           set_layer_led( [0-2], [true/false] );
 */

void set_switch_led(int ledId, bool state) {
    switch (ledId) {
        case 1:
            writePin(D7, state);
            break;
        case 2:
            writePin(readPin(B7) ? C6 : C7, state);
            break;
        case 3:
            writePin(D4, state);
            break;
        case 4:
            writePin(E6, state);
            break;
        case 5:
            writePin(B4, state);
            break;
        case 6:
            writePin(D6, state);
            break;
    }
}

void set_layer_led(int layerLedMode) {
    writeLayerLedState(layer_led_0_off);
    writeLayerLedState(layer_led_1_off);
    writeLayerLedState(layer_led_2_off);

    switch (layerLedMode) {
        case ALL_LAYERS_OFF:
            break;
        case LAYER_0:
            writeLayerLedState(layer_led_0_on);
            break;
        case LAYER_1:
            writeLayerLedState(layer_led_1_on);
            break;
        case LAYER_2:
            writeLayerLedState(layer_led_2_on);
            break;
        case LAYER_3:
            writeLayerLedState(layer_led_0_on);
            writeLayerLedState(layer_led_1_on);
            break;
        case LAYER_4:
            writeLayerLedState(layer_led_1_on);
            writeLayerLedState(layer_led_2_on);
            break;
        case LAYER_5:
            writeLayerLedState(layer_led_0_on);
            writeLayerLedState(layer_led_2_on);
            break;
        default:
            writeLayerLedState(layer_led_0_on);
            writeLayerLedState(layer_led_1_on);
            writeLayerLedState(layer_led_2_on);
            break;
    }
}

void led_init_animation() {
    for (int i = ALL_LAYERS_OFF; i <= ALL_LAYERS_ON; i++) {
        led_set_layer(i);
    }

    led_set_layer(LAYER_0);
}

/*
 * This function led_set_layer gets called when you switch between layers.
 * It allows you to turn on and off leds for each different layer and do
 * other cool stuff.
 */
void led_set_layer(int layer) {
    switch (layer) {
        case ALL_LAYERS_OFF:
            set_switch_led(1, false);
            set_switch_led(2, false);
            set_switch_led(3, false);
            set_switch_led(4, false);
            set_switch_led(5, false);
            set_switch_led(6, false);

        case _LAYER_SELECT:
            set_switch_led(1, false);
            set_switch_led(2, false);
            set_switch_led(3, false);
            set_switch_led(4, true);
            set_switch_led(5, true);
            set_switch_led(6, true);
            break;

        default:
            set_switch_led(1, true);
            set_switch_led(2, true);
            set_switch_led(3, true);
            set_switch_led(4, true);
            set_switch_led(5, true);
            set_switch_led(6, true);
            break;
    }

    set_layer_led(layer);
}

/*
 * Prepare all LED ports for output
 */
void led_init_ports_user() {
    setPinOutput(D7);  // Switch 1 LED
    setPinOutput(C6);  // Switch 2 LED Pin1
    setPinOutput(C7);  // Switch 2 LED Pin2
    setPinOutput(D4);  // Switch 3 LED
    setPinOutput(E6);  // Switch 4 LED
    setPinOutput(B4);  // Switch 5 LED
    setPinOutput(D6);  // Switch 6 LED
    setPinOutput(D5);  // Layer 0 LED
    setPinOutput(B6);  // Layer 1 LED
    setPinOutput(B0);  // Layer 2 LED
}

// Runs on layer change, no matter where the change was initiated
layer_state_t layer_state_set_user(layer_state_t state) {
    set_layer_led(get_highest_layer(state));
    led_set_layer(get_highest_layer(state));
    return state;
}

void matrix_init_user(void) {
    led_init_ports_user();
    led_init_animation();
}

void td_spectacles_finish(qk_tap_dance_state_t *state, void *user_data) {
    if (state->pressed) {
        layer_on(_LAYER_SELECT);
    } else {
        SEND_STRING(NXTTHRD);
    }
}

void td_spectacles_reset(qk_tap_dance_state_t *state, void *user_data) { layer_off(_LAYER_SELECT); }