aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-07-26 03:14:58 +0100
committerGitHub <noreply@github.com>2021-07-25 19:14:58 -0700
commitf945c352e7db3fedb16c90f9f176b3df6e0b62ae (patch)
tree8b2cd252ad036b5199603c9c755c01be5cb326a2
parent4bb595f94b5c77e7a961ff69d2b4d9c53a9094fc (diff)
downloadqmk_firmware-f945c352e7db3fedb16c90f9f176b3df6e0b62ae.tar.gz
qmk_firmware-f945c352e7db3fedb16c90f9f176b3df6e0b62ae.zip
Haptic: driver-> feature (#13713)
-rw-r--r--common_features.mk3
-rw-r--r--quantum/haptic.c (renamed from drivers/haptic/haptic.c)133
-rw-r--r--quantum/haptic.h (renamed from drivers/haptic/haptic.h)6
-rw-r--r--quantum/process_keycode/process_haptic.c147
-rw-r--r--quantum/process_keycode/process_haptic.h21
-rw-r--r--quantum/quantum.c4
-rw-r--r--quantum/quantum.h1
7 files changed, 177 insertions, 138 deletions
diff --git a/common_features.mk b/common_features.mk
index f1414b4d0..a4991b05b 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -580,8 +580,9 @@ endif
580HAPTIC_ENABLE ?= no 580HAPTIC_ENABLE ?= no
581ifneq ($(strip $(HAPTIC_ENABLE)),no) 581ifneq ($(strip $(HAPTIC_ENABLE)),no)
582 COMMON_VPATH += $(DRIVER_PATH)/haptic 582 COMMON_VPATH += $(DRIVER_PATH)/haptic
583 SRC += haptic.c
584 OPT_DEFS += -DHAPTIC_ENABLE 583 OPT_DEFS += -DHAPTIC_ENABLE
584 SRC += $(QUANTUM_DIR)/haptic.c
585 SRC += $(QUANTUM_DIR)/process_keycode/process_haptic.c
585endif 586endif
586 587
587ifneq ($(filter DRV2605L, $(HAPTIC_ENABLE)), ) 588ifneq ($(filter DRV2605L, $(HAPTIC_ENABLE)), )
diff --git a/drivers/haptic/haptic.c b/quantum/haptic.c
index 3fab1be1a..65abcc15f 100644
--- a/drivers/haptic/haptic.c
+++ b/quantum/haptic.c
@@ -16,7 +16,6 @@
16 */ 16 */
17#include "haptic.h" 17#include "haptic.h"
18#include "eeconfig.h" 18#include "eeconfig.h"
19#include "progmem.h"
20#include "debug.h" 19#include "debug.h"
21#ifdef DRV2605L 20#ifdef DRV2605L
22# include "DRV2605L.h" 21# include "DRV2605L.h"
@@ -28,7 +27,6 @@
28haptic_config_t haptic_config; 27haptic_config_t haptic_config;
29 28
30void haptic_init(void) { 29void haptic_init(void) {
31 debug_enable = 1; // Debug is ON!
32 if (!eeconfig_is_enabled()) { 30 if (!eeconfig_is_enabled()) {
33 eeconfig_init(); 31 eeconfig_init();
34 } 32 }
@@ -65,7 +63,7 @@ void haptic_task(void) {
65} 63}
66 64
67void eeconfig_debug_haptic(void) { 65void eeconfig_debug_haptic(void) {
68 dprintf("haptic_config eprom\n"); 66 dprintf("haptic_config eeprom\n");
69 dprintf("haptic_config.enable = %d\n", haptic_config.enable); 67 dprintf("haptic_config.enable = %d\n", haptic_config.enable);
70 dprintf("haptic_config.mode = %d\n", haptic_config.mode); 68 dprintf("haptic_config.mode = %d\n", haptic_config.mode);
71} 69}
@@ -214,6 +212,8 @@ void haptic_set_dwell(uint8_t dwell) {
214 xprintf("haptic_config.dwell = %u\n", haptic_config.dwell); 212 xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
215} 213}
216 214
215uint8_t haptic_get_enable(void) { return haptic_config.enable; }
216
217uint8_t haptic_get_mode(void) { 217uint8_t haptic_get_mode(void) {
218 if (!haptic_config.enable) { 218 if (!haptic_config.enable) {
219 return false; 219 return false;
@@ -254,14 +254,11 @@ void haptic_disable_continuous(void) {
254} 254}
255 255
256void haptic_toggle_continuous(void) { 256void haptic_toggle_continuous(void) {
257#ifdef DRV2605L
258 if (haptic_config.cont) { 257 if (haptic_config.cont) {
259 haptic_disable_continuous(); 258 haptic_disable_continuous();
260 } else { 259 } else {
261 haptic_enable_continuous(); 260 haptic_enable_continuous();
262 } 261 }
263 eeconfig_update_haptic(haptic_config.raw);
264#endif
265} 262}
266 263
267void haptic_cont_increase(void) { 264void haptic_cont_increase(void) {
@@ -291,130 +288,6 @@ void haptic_play(void) {
291#endif 288#endif
292} 289}
293 290
294__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
295 switch(keycode) {
296# ifdef NO_HAPTIC_MOD
297 case QK_MOD_TAP ... QK_MOD_TAP_MAX:
298 if (record->tap.count == 0) return false;
299 break;
300 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
301 if (record->tap.count != TAPPING_TOGGLE) return false;
302 break;
303 case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
304 if (record->tap.count == 0) return false;
305 break;
306 case KC_LCTRL ... KC_RGUI:
307 case QK_MOMENTARY ... QK_MOMENTARY_MAX:
308# endif
309# ifdef NO_HAPTIC_FN
310 case KC_FN0 ... KC_FN31:
311# endif
312# ifdef NO_HAPTIC_ALPHA
313 case KC_A ... KC_Z:
314# endif
315# ifdef NO_HAPTIC_PUNCTUATION
316 case KC_ENTER:
317 case KC_ESCAPE:
318 case KC_BSPACE:
319 case KC_SPACE:
320 case KC_MINUS:
321 case KC_EQUAL:
322 case KC_LBRACKET:
323 case KC_RBRACKET:
324 case KC_BSLASH:
325 case KC_NONUS_HASH:
326 case KC_SCOLON:
327 case KC_QUOTE:
328 case KC_GRAVE:
329 case KC_COMMA:
330 case KC_SLASH:
331 case KC_DOT:
332 case KC_NONUS_BSLASH:
333# endif
334# ifdef NO_HAPTIC_LOCKKEYS
335 case KC_CAPSLOCK:
336 case KC_SCROLLLOCK:
337 case KC_NUMLOCK:
338# endif
339# ifdef NO_HAPTIC_NAV
340 case KC_PSCREEN:
341 case KC_PAUSE:
342 case KC_INSERT:
343 case KC_DELETE:
344 case KC_PGDOWN:
345 case KC_PGUP:
346 case KC_LEFT:
347 case KC_UP:
348 case KC_RIGHT:
349 case KC_DOWN:
350 case KC_END:
351 case KC_HOME:
352# endif
353# ifdef NO_HAPTIC_NUMERIC
354 case KC_1 ... KC_0:
355# endif
356 return false;
357 }
358 return true;
359}
360
361bool process_haptic(uint16_t keycode, keyrecord_t *record) {
362 if (keycode == HPT_ON && record->event.pressed) {
363 haptic_enable();
364 }
365 if (keycode == HPT_OFF && record->event.pressed) {
366 haptic_disable();
367 }
368 if (keycode == HPT_TOG && record->event.pressed) {
369 haptic_toggle();
370 }
371 if (keycode == HPT_RST && record->event.pressed) {
372 haptic_reset();
373 }
374 if (keycode == HPT_FBK && record->event.pressed) {
375 haptic_feedback_toggle();
376 }
377 if (keycode == HPT_BUZ && record->event.pressed) {
378 haptic_buzz_toggle();
379 }
380 if (keycode == HPT_MODI && record->event.pressed) {
381 haptic_mode_increase();
382 }
383 if (keycode == HPT_MODD && record->event.pressed) {
384 haptic_mode_decrease();
385 }
386 if (keycode == HPT_DWLI && record->event.pressed) {
387 haptic_dwell_increase();
388 }
389 if (keycode == HPT_DWLD && record->event.pressed) {
390 haptic_dwell_decrease();
391 }
392 if (keycode == HPT_CONT && record->event.pressed) {
393 haptic_toggle_continuous();
394 }
395 if (keycode == HPT_CONI && record->event.pressed) {
396 haptic_cont_increase();
397 }
398 if (keycode == HPT_COND && record->event.pressed) {
399 haptic_cont_decrease();
400 }
401
402 if (haptic_config.enable) {
403 if (record->event.pressed) {
404 // keypress
405 if (haptic_config.feedback < 2 && get_haptic_enabled_key(keycode, record)) {
406 haptic_play();
407 }
408 } else {
409 // keyrelease
410 if (haptic_config.feedback > 0 && get_haptic_enabled_key(keycode, record)) {
411 haptic_play();
412 }
413 }
414 }
415 return true;
416}
417
418void haptic_shutdown(void) { 291void haptic_shutdown(void) {
419#ifdef SOLENOID_ENABLE 292#ifdef SOLENOID_ENABLE
420 solenoid_shutdown(); 293 solenoid_shutdown();
diff --git a/drivers/haptic/haptic.h b/quantum/haptic.h
index ba8e0d20b..fc7ca2f3e 100644
--- a/drivers/haptic/haptic.h
+++ b/quantum/haptic.h
@@ -18,10 +18,6 @@
18#pragma once 18#pragma once
19#include <stdint.h> 19#include <stdint.h>
20#include <stdbool.h> 20#include <stdbool.h>
21#include "quantum.h"
22#ifdef DRV2605L
23# include "DRV2605L.h"
24#endif
25 21
26#ifndef HAPTIC_FEEDBACK_DEFAULT 22#ifndef HAPTIC_FEEDBACK_DEFAULT
27# define HAPTIC_FEEDBACK_DEFAULT 0 23# define HAPTIC_FEEDBACK_DEFAULT 0
@@ -52,7 +48,6 @@ typedef enum HAPTIC_FEEDBACK {
52 HAPTIC_FEEDBACK_MAX, 48 HAPTIC_FEEDBACK_MAX,
53} HAPTIC_FEEDBACK; 49} HAPTIC_FEEDBACK;
54 50
55bool process_haptic(uint16_t keycode, keyrecord_t *record);
56void haptic_init(void); 51void haptic_init(void);
57void haptic_task(void); 52void haptic_task(void);
58void eeconfig_debug_haptic(void); 53void eeconfig_debug_haptic(void);
@@ -69,6 +64,7 @@ void haptic_set_mode(uint8_t mode);
69void haptic_set_dwell(uint8_t dwell); 64void haptic_set_dwell(uint8_t dwell);
70void haptic_set_buzz(uint8_t buzz); 65void haptic_set_buzz(uint8_t buzz);
71void haptic_buzz_toggle(void); 66void haptic_buzz_toggle(void);
67uint8_t haptic_get_enable(void);
72uint8_t haptic_get_mode(void); 68uint8_t haptic_get_mode(void);
73uint8_t haptic_get_feedback(void); 69uint8_t haptic_get_feedback(void);
74void haptic_dwell_increase(void); 70void haptic_dwell_increase(void);
diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c
new file mode 100644
index 000000000..29a4ffd10
--- /dev/null
+++ b/quantum/process_keycode/process_haptic.c
@@ -0,0 +1,147 @@
1/* Copyright 2021 QMK
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#include "haptic.h"
17#include "process_haptic.h"
18#include "quantum_keycodes.h"
19
20__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
21 switch (keycode) {
22#ifdef NO_HAPTIC_MOD
23 case QK_MOD_TAP ... QK_MOD_TAP_MAX:
24 if (record->tap.count == 0) return false;
25 break;
26 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
27 if (record->tap.count != TAPPING_TOGGLE) return false;
28 break;
29 case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
30 if (record->tap.count == 0) return false;
31 break;
32 case KC_LCTRL ... KC_RGUI:
33 case QK_MOMENTARY ... QK_MOMENTARY_MAX:
34#endif
35#ifdef NO_HAPTIC_FN
36 case KC_FN0 ... KC_FN31:
37#endif
38#ifdef NO_HAPTIC_ALPHA
39 case KC_A ... KC_Z:
40#endif
41#ifdef NO_HAPTIC_PUNCTUATION
42 case KC_ENTER:
43 case KC_ESCAPE:
44 case KC_BSPACE:
45 case KC_SPACE:
46 case KC_MINUS:
47 case KC_EQUAL:
48 case KC_LBRACKET:
49 case KC_RBRACKET:
50 case KC_BSLASH:
51 case KC_NONUS_HASH:
52 case KC_SCOLON:
53 case KC_QUOTE:
54 case KC_GRAVE:
55 case KC_COMMA:
56 case KC_SLASH:
57 case KC_DOT:
58 case KC_NONUS_BSLASH:
59#endif
60#ifdef NO_HAPTIC_LOCKKEYS
61 case KC_CAPSLOCK:
62 case KC_SCROLLLOCK:
63 case KC_NUMLOCK:
64#endif
65#ifdef NO_HAPTIC_NAV
66 case KC_PSCREEN:
67 case KC_PAUSE:
68 case KC_INSERT:
69 case KC_DELETE:
70 case KC_PGDOWN:
71 case KC_PGUP:
72 case KC_LEFT:
73 case KC_UP:
74 case KC_RIGHT:
75 case KC_DOWN:
76 case KC_END:
77 case KC_HOME:
78#endif
79#ifdef NO_HAPTIC_NUMERIC
80 case KC_1 ... KC_0:
81#endif
82 return false;
83 }
84 return true;
85}
86
87bool process_haptic(uint16_t keycode, keyrecord_t *record) {
88 if (record->event.pressed) {
89 switch (keycode) {
90 case HPT_ON:
91 haptic_enable();
92 break;
93 case HPT_OFF:
94 haptic_disable();
95 break;
96 case HPT_TOG:
97 haptic_toggle();
98 break;
99 case HPT_RST:
100 haptic_reset();
101 break;
102 case HPT_FBK:
103 haptic_feedback_toggle();
104 break;
105 case HPT_BUZ:
106 haptic_buzz_toggle();
107 break;
108 case HPT_MODI:
109 haptic_mode_increase();
110 break;
111 case HPT_MODD:
112 haptic_mode_decrease();
113 break;
114 case HPT_DWLI:
115 haptic_dwell_increase();
116 break;
117 case HPT_DWLD:
118 haptic_dwell_decrease();
119 break;
120 case HPT_CONT:
121 haptic_toggle_continuous();
122 break;
123 case HPT_CONI:
124 haptic_cont_increase();
125 break;
126 case HPT_COND:
127 haptic_cont_decrease();
128 break;
129 }
130 }
131
132 if (haptic_get_enable()) {
133 if (record->event.pressed) {
134 // keypress
135 if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) {
136 haptic_play();
137 }
138 } else {
139 // keyrelease
140 if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, record)) {
141 haptic_play();
142 }
143 }
144 }
145
146 return true;
147}
diff --git a/quantum/process_keycode/process_haptic.h b/quantum/process_keycode/process_haptic.h
new file mode 100644
index 000000000..6dbb0f014
--- /dev/null
+++ b/quantum/process_keycode/process_haptic.h
@@ -0,0 +1,21 @@
1/* Copyright 2021 QMK
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#pragma once
17
18#include <stdbool.h>
19#include "action.h"
20
21bool process_haptic(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 56ceec5db..f430a521b 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -220,10 +220,10 @@ bool process_record_quantum(keyrecord_t *record) {
220#endif 220#endif
221#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) 221#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
222 process_clicky(keycode, record) && 222 process_clicky(keycode, record) &&
223#endif // AUDIO_CLICKY 223#endif
224#ifdef HAPTIC_ENABLE 224#ifdef HAPTIC_ENABLE
225 process_haptic(keycode, record) && 225 process_haptic(keycode, record) &&
226#endif // HAPTIC_ENABLE 226#endif
227#if defined(VIA_ENABLE) 227#if defined(VIA_ENABLE)
228 process_record_via(keycode, record) && 228 process_record_via(keycode, record) &&
229#endif 229#endif
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 756a5603c..72970a649 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -161,6 +161,7 @@ extern layer_state_t layer_state;
161 161
162#ifdef HAPTIC_ENABLE 162#ifdef HAPTIC_ENABLE
163# include "haptic.h" 163# include "haptic.h"
164# include "process_haptic.h"
164#endif 165#endif
165 166
166#ifdef OLED_DRIVER_ENABLE 167#ifdef OLED_DRIVER_ENABLE