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
|
// Copyright 2023 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include QMK_KEYBOARD_H
// Enable debug console printing
// https://docusaurus.qmk.fm/faq_debug
#include "print.h"
enum layer_names {
_COLEMAK = 0,
_QWERTY,
_FN,
};
enum custom_keycodes {
COLEMAK = SAFE_RANGE,
QWERTY,
};
// Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers.
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/*
┌───┬───┬───┬───┬───┬───┐ ┌───┬───┬───┬───┬───┬───┬───┬───┐
│ESC│F1 │F2 │F3 │F4 │F5 │ │F6 │F7 │F8 │F9 │F10│F11│F12│DEL│
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┼───┤
│ ` │ 1 │ 2 │ 3 │ 4 │ 5 │ │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │BCK│
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┼───┤
│TAB│ Q │ W │ F │ P │ G │ │ J │ L │ U │ Y │ ; │ [ │ ] │ \ │
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┴───┤
│COM│ A │ R │ S │ T │ D │ │ H │ N │ E │ I │ O │ ' │RETURN │
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┬───┤
│SHI│ Z │ X │ C │ V │ B │ │ K │ M │ , │ . │ / │PGU│ ↑ │PGD│
├───┼───┼───┼───┼───┴───┤ ┌───┼───┼───┼───┼───┼───┼───┼───┼───┤
│CTL│SUP│ALT│FN │ SPACE │ │M1 │M3 │M2 │MEN│HOM│END│ ← │ ↓ │ → │
└───┴───┴───┴───┴───────┘ └───┴───┴───┴───┴───┴───┴───┴───┴───┘
*/
[_COLEMAK] = LAYOUT(
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
KC_ESC, 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_GRV, 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_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_LBRC, KC_RBRC, KC_BSLS,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
KC_CAPS, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, KC_ENT,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_PGUP, KC_UP, KC_PGDN,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------+--------|
KC_LCTL, KC_LGUI, KC_LALT, KC_A, KC_SPACE, KC_BTN1, KC_BTN3, KC_BTN2, KC_APP, KC_HOME, KC_END, KC_LEFT, KC_DOWN, KC_RGHT
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------+--------|
),
/*
┌───┬───┬───┬───┬───┬───┐ ┌───┬───┬───┬───┬───┬───┬───┬───┐
│ESC│F1 │F2 │F3 │F4 │F5 │ │F6 │F7 │F8 │F9 │F10│F11│F12│DEL│
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┼───┤
│ ` │ 1 │ 2 │ 3 │ 4 │ 5 │ │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │BCK│
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┼───┤
│TAB│ Q │ W │ E │ R │ T │ │ Y │ U │ I │ O │ P │ [ │ ] │ \ │
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┴───┤
│COM│ A │ S │ D │ F │ G │ │ H │ J │ K │ L │ ; │ ' │RETURN │
├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┼───┬───┤
│SHI│ Z │ X │ C │ V │ B │ │ N │ M │ , │ . │ / │PGU│ ↑ │PGD│
├───┼───┼───┼───┼───┴───┤ ┌───┼───┼───┼───┼───┼───┼───┼───┼───┤
│CTL│SUP│ALT│FN │ SPACE │ │M1 │M3 │M2 │MEN│HOM│END│ ← │ ↓ │ → │
└───┴───┴───┴───┴───────┘ └───┴───┴───┴───┴───┴───┴───┴───┴───┘
*/
[_QWERTY] = LAYOUT(
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
KC_ESC, 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_GRV, 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_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_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_PGUP, KC_UP, KC_PGDN,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------+--------|
KC_LCTL, KC_LGUI, KC_LALT, MO(_FN), KC_SPACE, KC_BTN1, KC_BTN3, KC_BTN2, KC_APP, KC_HOME, KC_END, KC_LEFT, KC_DOWN, KC_RGHT
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------+--------|
),
[_FN] = LAYOUT(
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
KC_A, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------+--------+--------|
)
};
// Custom composite data type for holding colors
typedef struct {
int red;
int green;
int blue;
} color_type;
// Used for middle mouse button logic
bool scrolled = false;
typedef struct {
color_type color;
int cpi;
} cpi_type;
// Trackball cpi. First one is the default This is also the default color
cpi_type cpis[] = {
{
.color = {
.red = 0,
.green = 255,
.blue = 0
},
.cpi = 40000
},
{
.color = {
.red = 255,
.green = 0,
.blue = 0
},
.cpi = 20000
}
};
int cpi_index = 0;
bool cpi_changed = false;
void set_trackball_normal_color(void) {
// Sets color based on current cpi
pimoroni_trackball_set_rgbw(
cpis[cpi_index].color.red,
cpis[cpi_index].color.green,
cpis[cpi_index].color.blue,
0
);
}
void keyboard_post_init_user(void) {
// Call the post init code.
setrgb(0, 15, 0, (LED_TYPE *)&led[0]); // led 0
rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
set_trackball_normal_color();
pointing_device_set_cpi(cpis[cpi_index].cpi);
debug_enable=true;
}
bool set_scrolling = false;
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
// Only fires on pointing device click, not keyboard mouse buttons
if (!mouse_report.buttons) {
cpi_changed = false;
} else {
// Don't send a mouse button event
mouse_report.buttons = 0;
if(!cpi_changed){
cpi_changed = true;
// Cycle CPI
cpi_index++;
if (cpi_index == sizeof(cpis) / sizeof(cpis[0])) {
cpi_index = 0;
}
// Set CPI
pointing_device_set_cpi(cpis[cpi_index].cpi);
// Sets color based on current selected cpi
set_trackball_normal_color();
dprintf("CPI: %d\n", cpis[cpi_index].cpi);
}
}
if (set_scrolling) {
if (mouse_report.x || mouse_report.y) {
// Used for middle mouse button scroll logic
scrolled = true;
// dprintf("X: %d\nY: %d\n", mouse_report.x, mouse_report.y);
}
mouse_report.h = mouse_report.x;
mouse_report.v = -mouse_report.y;
mouse_report.x = 0;
mouse_report.y = 0;
}
return mouse_report;
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
//dprintf("keycode: %d\n", keycode);
if (keycode == KC_BTN3) {
if (record->event.pressed) {
// Middle mouse button pressed
// Start scrolling mode
set_scrolling = true;
pointing_device_set_cpi(8000);
pimoroni_trackball_set_rgbw(0, 0, 255, 0);
// Don't send pressed to computer, as there's some logic
// to check if scrolled. This logic is handled later
return false;
} else {
// Stop scrolling mode
set_scrolling = false;
// Reset CPI
pointing_device_set_cpi(cpis[cpi_index].cpi);
set_trackball_normal_color();
// Middle mouse button wasn't sent earlier,
// send if not scrolled on mouse button up.
// Similar to how ThinkPads handles it
if (!scrolled) {
SEND_STRING(SS_TAP(X_MS_BTN3));
}
else {
scrolled = false;
}
}
}
return true;
}
void suspend_power_down_user(void) {
// code will run multiple times while keyboard is suspended
// Turn off light when computer is suspended
pimoroni_trackball_set_rgbw(0, 0, 0, 0);
setrgb(0, 0, 0, (LED_TYPE *)&led[0]); // led 0
rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
}
void suspend_wakeup_init_user(void) {
// code will run on keyboard wakeup
// Turn on light when computer is woken from sleep
set_trackball_normal_color();
setrgb(0, 15, 0, (LED_TYPE *)&led[0]); // led 0
rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
}
/*
uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button) {
if (pressed) {
buttons |= 1 << (button);
if (buttons) {
dprintf("buttons: %d\npressed: %d\nbutton: %d\n", buttons, pressed, button);
}
} else {
buttons &= ~(1 << (button));
}
return buttons;
}
*/
|