aboutsummaryrefslogtreecommitdiff
path: root/keyboards/wuque/mammoth75x/mammoth75x.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/wuque/mammoth75x/mammoth75x.c')
-rw-r--r--keyboards/wuque/mammoth75x/mammoth75x.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/keyboards/wuque/mammoth75x/mammoth75x.c b/keyboards/wuque/mammoth75x/mammoth75x.c
new file mode 100644
index 000000000..6f14657f8
--- /dev/null
+++ b/keyboards/wuque/mammoth75x/mammoth75x.c
@@ -0,0 +1,67 @@
1/* Copyright 2021 wuquestudio
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 "mammoth75x.h"
18
19#ifdef VIA_ENABLE
20static uint8_t encoder_state[ENCODERS] = {0};
21static keypos_t encoder_cw[ENCODERS] = ENCODERS_CW_KEY;
22static keypos_t encoder_ccw[ENCODERS] = ENCODERS_CCW_KEY;
23
24void encoder_action_unregister(void)
25{
26 for (int index = 0; index < ENCODERS; ++index)
27 {
28 if (encoder_state[index])
29 {
30 keyevent_t encoder_event = (keyevent_t){
31 .key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
32 .pressed = false,
33 .time = (timer_read() | 1)};
34 encoder_state[index] = 0;
35 action_exec(encoder_event);
36 }
37 }
38}
39void encoder_action_register(uint8_t index, bool clockwise)
40{
41 keyevent_t encoder_event = (keyevent_t){
42 .key = clockwise ? encoder_cw[index] : encoder_ccw[index],
43 .pressed = true,
44 .time = (timer_read() | 1)};
45 encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
46 action_exec(encoder_event);
47}
48
49void matrix_scan_kb(void)
50{
51 encoder_action_unregister();
52 matrix_scan_user();
53}
54
55bool encoder_update_kb(uint8_t index, bool clockwise)
56{
57 encoder_action_register(index, clockwise);
58 return true;
59};
60#else
61bool encoder_update_kb(uint8_t index, bool clockwise) {
62 if (!encoder_update_user(index, clockwise)) { return false; }
63 tap_code_delay(clockwise ? KC_VOLU : KC_VOLD, 10);
64 return true;
65}
66#endif
67