diff options
author | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
commit | dc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch) | |
tree | 4ccb8fa5886b66fa9d480edef74236c27f035e16 /keyboards/3w6/rev2/keymaps |
Diffstat (limited to 'keyboards/3w6/rev2/keymaps')
5 files changed, 306 insertions, 0 deletions
diff --git a/keyboards/3w6/rev2/keymaps/default_pimoroni/config.h b/keyboards/3w6/rev2/keymaps/default_pimoroni/config.h new file mode 100644 index 000000000..45c9d5154 --- /dev/null +++ b/keyboards/3w6/rev2/keymaps/default_pimoroni/config.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 weteor | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #define PIMORONI_TRACKBALL_INVERT_Y | ||
20 | #define PIMORONI_TRACKBALL_ROTATE | ||
21 | |||
diff --git a/keyboards/3w6/rev2/keymaps/default_pimoroni/keymap.c b/keyboards/3w6/rev2/keymaps/default_pimoroni/keymap.c new file mode 100644 index 000000000..a5b8c6006 --- /dev/null +++ b/keyboards/3w6/rev2/keymaps/default_pimoroni/keymap.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | Copyright 2021 weteor | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include QMK_KEYBOARD_H | ||
19 | |||
20 | enum layers | ||
21 | { | ||
22 | _ALPHA_QWERTY = 0, | ||
23 | _ALPHA_COLEMAK, | ||
24 | _SYM, | ||
25 | _NAV, | ||
26 | _NUM, | ||
27 | _CFG, | ||
28 | }; | ||
29 | |||
30 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
31 | |||
32 | |||
33 | [_ALPHA_QWERTY] = LAYOUT( | ||
34 | KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, | ||
35 | KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, | ||
36 | LSFT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, RSFT_T(KC_SLSH), | ||
37 | |||
38 | LCTL_T(KC_ESC), LT(_NUM,KC_SPC), LT(_NAV, KC_TAB), LT(_SYM, KC_BSPC), KC_ENT, LALT_T(KC_DEL) | ||
39 | ), | ||
40 | [_ALPHA_COLEMAK] = LAYOUT( | ||
41 | KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_QUOT, | ||
42 | KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, | ||
43 | LSFT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, RSFT_T(KC_SCLN), | ||
44 | LCTL_T(KC_ENT), LT(_NUM,KC_SPC), LT(_NAV, KC_TAB), LT(_SYM, KC_BSPC), KC_ENT, LALT_T(KC_DEL) | ||
45 | ), | ||
46 | [_SYM] = LAYOUT( | ||
47 | KC_GRV , KC_CIRC, KC_AT, KC_DLR, KC_TILD, KC_AMPR, KC_EXLM, KC_PIPE, KC_UNDS, KC_HASH, | ||
48 | KC_SLSH, KC_LBRC, KC_LCBR, KC_LPRN, KC_EQL, KC_ASTR, KC_RPRN, KC_RCBR, KC_RBRC, KC_BSLS, | ||
49 | _______, KC_QUES, KC_PLUS, KC_PERC, XXXXXXX, XXXXXXX, XXXXXXX, KC_MINS, XXXXXXX, _______, | ||
50 | XXXXXXX, MO(_CFG), XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX | ||
51 | ), | ||
52 | [_NAV] = LAYOUT( | ||
53 | XXXXXXX, KC_VOLD, KC_MUTE, KC_VOLU, XXXXXXX, XXXXXXX, KC_PGDN, KC_UP, KC_PGUP, KC_DEL, | ||
54 | KC_MPRV, KC_MPLY, KC_MSTP, KC_MNXT, XXXXXXX, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, | ||
55 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
56 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, MO(_CFG), XXXXXXX | ||
57 | ), | ||
58 | [_NUM] = LAYOUT( | ||
59 | XXXXXXX, KC_F9, KC_F10, KC_F11, KC_F12, KC_PPLS, KC_P7, KC_P8, KC_P9, KC_PSLS, | ||
60 | XXXXXXX, KC_F5, KC_F6, KC_F7, KC_F8, KC_P0, KC_P4, KC_P5, KC_P6, KC_PDOT, | ||
61 | XXXXXXX, KC_F1, KC_F2, KC_F3, KC_F4, KC_PMNS, KC_P1, KC_P2, KC_P3, KC_PAST, | ||
62 | XXXXXXX, XXXXXXX, XXXXXXX, KC_PEQL, KC_PENT, XXXXXXX | ||
63 | ), | ||
64 | [_CFG] = LAYOUT( | ||
65 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,DF(_ALPHA_QWERTY), DF(_ALPHA_COLEMAK), | ||
66 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
67 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, | ||
68 | XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX | ||
69 | ), | ||
70 | }; | ||
diff --git a/keyboards/3w6/rev2/keymaps/default_pimoroni/pimoroni_trackball.c b/keyboards/3w6/rev2/keymaps/default_pimoroni/pimoroni_trackball.c new file mode 100644 index 000000000..c4f4a0441 --- /dev/null +++ b/keyboards/3w6/rev2/keymaps/default_pimoroni/pimoroni_trackball.c | |||
@@ -0,0 +1,177 @@ | |||
1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]> | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "pimoroni_trackball.h" | ||
18 | #include "i2c_master.h" | ||
19 | |||
20 | static uint8_t scrolling = 0; | ||
21 | static int16_t x_offset = 0; | ||
22 | static int16_t y_offset = 0; | ||
23 | static int16_t h_offset = 0; | ||
24 | static int16_t v_offset = 0; | ||
25 | static float precisionSpeed = 1; | ||
26 | |||
27 | static uint16_t i2c_timeout_timer; | ||
28 | |||
29 | #ifndef I2C_TIMEOUT | ||
30 | # define I2C_TIMEOUT 100 | ||
31 | #endif | ||
32 | #ifndef I2C_WAITCHECK | ||
33 | # define I2C_WAITCHECK 1000 | ||
34 | #endif | ||
35 | #ifndef MOUSE_DEBOUNCE | ||
36 | # define MOUSE_DEBOUNCE 5 | ||
37 | #endif | ||
38 | |||
39 | void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { | ||
40 | uint8_t data[] = {0x00, red, green, blue, white}; | ||
41 | i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), I2C_TIMEOUT); | ||
42 | } | ||
43 | |||
44 | int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) { | ||
45 | int16_t offset = (int16_t)positive - (int16_t)negative; | ||
46 | int16_t magnitude = (int16_t)(scale * offset * offset * precisionSpeed); | ||
47 | return offset < 0 ? -magnitude : magnitude; | ||
48 | } | ||
49 | |||
50 | void update_member(int8_t* member, int16_t* offset) { | ||
51 | if (*offset > 127) { | ||
52 | *member = 127; | ||
53 | *offset -= 127; | ||
54 | } else if (*offset < -127) { | ||
55 | *member = -127; | ||
56 | *offset += 127; | ||
57 | } else { | ||
58 | *member = *offset; | ||
59 | *offset = 0; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | __attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* mouse) { | ||
64 | if (pressed) { | ||
65 | mouse->buttons |= MOUSE_BTN1; | ||
66 | } else { | ||
67 | mouse->buttons &= ~MOUSE_BTN1; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | ||
72 | if (true) { | ||
73 | xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); | ||
74 | } | ||
75 | |||
76 | |||
77 | if (!process_record_user(keycode, record)) { return false; } | ||
78 | |||
79 | /* If Mousekeys is disabled, then use handle the mouse button | ||
80 | * keycodes. This makes things simpler, and allows usage of | ||
81 | * the keycodes in a consistent manner. But only do this if | ||
82 | * Mousekeys is not enable, so it's not handled twice. | ||
83 | */ | ||
84 | #ifndef MOUSEKEY_ENABLE | ||
85 | if (IS_MOUSEKEY_BUTTON(keycode)) { | ||
86 | report_mouse_t currentReport = pointing_device_get_report(); | ||
87 | if (record->event.pressed) { | ||
88 | currentReport.buttons |= 1 << (keycode - KC_MS_BTN1); | ||
89 | } else { | ||
90 | currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1)); | ||
91 | } | ||
92 | pointing_device_set_report(currentReport); | ||
93 | pointing_device_send(); | ||
94 | } | ||
95 | #endif | ||
96 | |||
97 | return true; | ||
98 | } | ||
99 | |||
100 | void trackball_register_button(bool pressed, enum mouse_buttons button) { | ||
101 | report_mouse_t currentReport = pointing_device_get_report(); | ||
102 | if (pressed) { | ||
103 | currentReport.buttons |= button; | ||
104 | } else { | ||
105 | currentReport.buttons &= ~button; | ||
106 | } | ||
107 | pointing_device_set_report(currentReport); | ||
108 | } | ||
109 | |||
110 | float trackball_get_precision(void) { return precisionSpeed; } | ||
111 | void trackball_set_precision(float precision) { precisionSpeed = precision; } | ||
112 | bool trackball_is_scrolling(void) { return scrolling; } | ||
113 | void trackball_set_scrolling(bool scroll) { scrolling = scroll; } | ||
114 | |||
115 | |||
116 | __attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x80, 0x00, 0x00, 0x00); } | ||
117 | |||
118 | void pointing_device_task(void) { | ||
119 | static bool debounce; | ||
120 | static uint16_t debounce_timer; | ||
121 | uint8_t state[5] = {}; | ||
122 | if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) { | ||
123 | if (i2c_readReg(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) { | ||
124 | if (!state[4] && !debounce) { | ||
125 | if (scrolling) { | ||
126 | #ifdef PIMORONI_TRACKBALL_INVERT_X | ||
127 | h_offset += mouse_offset(state[2], state[3], 1); | ||
128 | #else | ||
129 | h_offset -= mouse_offset(state[2], state[3], 1); | ||
130 | #endif | ||
131 | #ifdef PIMORONI_TRACKBALL_INVERT_Y | ||
132 | v_offset += mouse_offset(state[1], state[0], 1); | ||
133 | #else | ||
134 | v_offset -= mouse_offset(state[1], state[0], 1); | ||
135 | #endif | ||
136 | } else { | ||
137 | #ifdef PIMORONI_TRACKBALL_INVERT_X | ||
138 | x_offset -= mouse_offset(state[2], state[3], 5); | ||
139 | #else | ||
140 | x_offset += mouse_offset(state[2], state[3], 5); | ||
141 | #endif | ||
142 | #ifdef PIMORONI_TRACKBALL_INVERT_Y | ||
143 | y_offset -= mouse_offset(state[1], state[0], 5); | ||
144 | #else | ||
145 | y_offset += mouse_offset(state[1], state[0], 5); | ||
146 | #endif | ||
147 | } | ||
148 | } else { | ||
149 | if (state[4]) { | ||
150 | debounce = true; | ||
151 | debounce_timer = timer_read(); | ||
152 | } | ||
153 | } | ||
154 | } else { | ||
155 | i2c_timeout_timer = timer_read(); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false; | ||
160 | |||
161 | report_mouse_t mouse = pointing_device_get_report(); | ||
162 | // trackball_check_click(state[4] & (1 << 7), &mouse); | ||
163 | |||
164 | #ifndef PIMORONI_TRACKBALL_ROTATE | ||
165 | update_member(&mouse.x, &x_offset); | ||
166 | update_member(&mouse.y, &y_offset); | ||
167 | update_member(&mouse.h, &h_offset); | ||
168 | update_member(&mouse.v, &v_offset); | ||
169 | #else | ||
170 | update_member(&mouse.x, &y_offset); | ||
171 | update_member(&mouse.y, &x_offset); | ||
172 | update_member(&mouse.h, &v_offset); | ||
173 | update_member(&mouse.v, &h_offset); | ||
174 | #endif | ||
175 | pointing_device_set_report(mouse); | ||
176 | pointing_device_send(); | ||
177 | } | ||
diff --git a/keyboards/3w6/rev2/keymaps/default_pimoroni/pimoroni_trackball.h b/keyboards/3w6/rev2/keymaps/default_pimoroni/pimoroni_trackball.h new file mode 100644 index 000000000..cfcd5a47a --- /dev/null +++ b/keyboards/3w6/rev2/keymaps/default_pimoroni/pimoroni_trackball.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]> | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "quantum.h" | ||
20 | #include "pointing_device.h" | ||
21 | |||
22 | #ifndef TRACKBALL_ADDRESS | ||
23 | # define TRACKBALL_ADDRESS 0x0A | ||
24 | #endif | ||
25 | #define TRACKBALL_WRITE ((TRACKBALL_ADDRESS << 1) | I2C_WRITE) | ||
26 | #define TRACKBALL_READ ((TRACKBALL_ADDRESS << 1) | I2C_READ) | ||
27 | |||
28 | void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white); | ||
29 | void trackball_check_click(bool pressed, report_mouse_t *mouse); | ||
30 | void trackball_register_button(bool pressed, enum mouse_buttons button); | ||
31 | |||
32 | float trackball_get_precision(void); | ||
33 | void trackball_set_precision(float precision); | ||
34 | bool trackball_is_scrolling(void); | ||
35 | void trackball_set_scrolling(bool scroll); \ No newline at end of file | ||
diff --git a/keyboards/3w6/rev2/keymaps/default_pimoroni/rules.mk b/keyboards/3w6/rev2/keymaps/default_pimoroni/rules.mk new file mode 100644 index 000000000..231a88371 --- /dev/null +++ b/keyboards/3w6/rev2/keymaps/default_pimoroni/rules.mk | |||
@@ -0,0 +1,3 @@ | |||
1 | POINTING_DEVICE_ENABLE = yes | ||
2 | SRC += pimoroni_trackball.c | ||
3 | MOUSEKEY_ENABLE = no | ||