Browse Source

Haptic: driver-> feature (#13713)

Joel Challis 3 năm trước cách đây
mục cha
commit
f945c352e7

+ 2 - 1
common_features.mk

@@ -580,8 +580,9 @@ endif
 HAPTIC_ENABLE ?= no
 ifneq ($(strip $(HAPTIC_ENABLE)),no)
     COMMON_VPATH += $(DRIVER_PATH)/haptic
-    SRC += haptic.c
     OPT_DEFS += -DHAPTIC_ENABLE
+    SRC += $(QUANTUM_DIR)/haptic.c
+    SRC += $(QUANTUM_DIR)/process_keycode/process_haptic.c
 endif
 
 ifneq ($(filter DRV2605L, $(HAPTIC_ENABLE)), )

+ 3 - 130
drivers/haptic/haptic.c → quantum/haptic.c

@@ -16,7 +16,6 @@
  */
 #include "haptic.h"
 #include "eeconfig.h"
-#include "progmem.h"
 #include "debug.h"
 #ifdef DRV2605L
 #    include "DRV2605L.h"
@@ -28,7 +27,6 @@
 haptic_config_t haptic_config;
 
 void haptic_init(void) {
-    debug_enable = 1;  // Debug is ON!
     if (!eeconfig_is_enabled()) {
         eeconfig_init();
     }
@@ -65,7 +63,7 @@ void haptic_task(void) {
 }
 
 void eeconfig_debug_haptic(void) {
-    dprintf("haptic_config eprom\n");
+    dprintf("haptic_config eeprom\n");
     dprintf("haptic_config.enable = %d\n", haptic_config.enable);
     dprintf("haptic_config.mode = %d\n", haptic_config.mode);
 }
@@ -214,6 +212,8 @@ void haptic_set_dwell(uint8_t dwell) {
     xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
 }
 
+uint8_t haptic_get_enable(void) { return haptic_config.enable; }
+
 uint8_t haptic_get_mode(void) {
     if (!haptic_config.enable) {
         return false;
@@ -254,14 +254,11 @@ void haptic_disable_continuous(void) {
 }
 
 void haptic_toggle_continuous(void) {
-#ifdef DRV2605L
     if (haptic_config.cont) {
         haptic_disable_continuous();
     } else {
         haptic_enable_continuous();
     }
-    eeconfig_update_haptic(haptic_config.raw);
-#endif
 }
 
 void haptic_cont_increase(void) {
@@ -291,130 +288,6 @@ void haptic_play(void) {
 #endif
 }
 
-__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
-    switch(keycode) {
-#    ifdef NO_HAPTIC_MOD
-        case QK_MOD_TAP ... QK_MOD_TAP_MAX:
-            if (record->tap.count == 0) return false;
-            break;
-        case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
-            if (record->tap.count != TAPPING_TOGGLE) return false;
-            break;
-        case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
-            if (record->tap.count == 0) return false;
-            break;
-        case KC_LCTRL ... KC_RGUI:
-        case QK_MOMENTARY ... QK_MOMENTARY_MAX:
-#    endif
-#    ifdef NO_HAPTIC_FN
-        case KC_FN0 ... KC_FN31:
-#    endif
-#    ifdef NO_HAPTIC_ALPHA
-        case KC_A ... KC_Z:
-#    endif
-#    ifdef NO_HAPTIC_PUNCTUATION
-        case KC_ENTER:
-        case KC_ESCAPE:
-        case KC_BSPACE:
-        case KC_SPACE:
-        case KC_MINUS:
-        case KC_EQUAL:
-        case KC_LBRACKET:
-        case KC_RBRACKET:
-        case KC_BSLASH:
-        case KC_NONUS_HASH:
-        case KC_SCOLON:
-        case KC_QUOTE:
-        case KC_GRAVE:
-        case KC_COMMA:
-        case KC_SLASH:
-        case KC_DOT:
-        case KC_NONUS_BSLASH:
-#    endif
-#    ifdef NO_HAPTIC_LOCKKEYS
-        case KC_CAPSLOCK:
-        case KC_SCROLLLOCK:
-        case KC_NUMLOCK:
-#    endif
-#    ifdef NO_HAPTIC_NAV
-        case KC_PSCREEN:
-        case KC_PAUSE:
-        case KC_INSERT:
-        case KC_DELETE:
-        case KC_PGDOWN:
-        case KC_PGUP:
-        case KC_LEFT:
-        case KC_UP:
-        case KC_RIGHT:
-        case KC_DOWN:
-        case KC_END:
-        case KC_HOME:
-#    endif
-#    ifdef NO_HAPTIC_NUMERIC
-        case KC_1 ... KC_0:
-#    endif
-         return false;
-    }
-    return true;
-}
-
-bool process_haptic(uint16_t keycode, keyrecord_t *record) {
-    if (keycode == HPT_ON && record->event.pressed) {
-        haptic_enable();
-    }
-    if (keycode == HPT_OFF && record->event.pressed) {
-        haptic_disable();
-    }
-    if (keycode == HPT_TOG && record->event.pressed) {
-        haptic_toggle();
-    }
-    if (keycode == HPT_RST && record->event.pressed) {
-        haptic_reset();
-    }
-    if (keycode == HPT_FBK && record->event.pressed) {
-        haptic_feedback_toggle();
-    }
-    if (keycode == HPT_BUZ && record->event.pressed) {
-        haptic_buzz_toggle();
-    }
-    if (keycode == HPT_MODI && record->event.pressed) {
-        haptic_mode_increase();
-    }
-    if (keycode == HPT_MODD && record->event.pressed) {
-        haptic_mode_decrease();
-    }
-    if (keycode == HPT_DWLI && record->event.pressed) {
-        haptic_dwell_increase();
-    }
-    if (keycode == HPT_DWLD && record->event.pressed) {
-        haptic_dwell_decrease();
-    }
-    if (keycode == HPT_CONT && record->event.pressed) {
-        haptic_toggle_continuous();
-    }
-    if (keycode == HPT_CONI && record->event.pressed) {
-        haptic_cont_increase();
-    }
-    if (keycode == HPT_COND && record->event.pressed) {
-        haptic_cont_decrease();
-    }
-
-    if (haptic_config.enable) {
-        if (record->event.pressed) {
-            // keypress
-            if (haptic_config.feedback < 2 && get_haptic_enabled_key(keycode, record)) {
-                haptic_play();
-            }
-        } else {
-            // keyrelease
-            if (haptic_config.feedback > 0 && get_haptic_enabled_key(keycode, record)) {
-                haptic_play();
-            }
-        }
-    }
-    return true;
-}
-
 void haptic_shutdown(void) {
 #ifdef SOLENOID_ENABLE
     solenoid_shutdown();

+ 1 - 5
drivers/haptic/haptic.h → quantum/haptic.h

@@ -18,10 +18,6 @@
 #pragma once
 #include <stdint.h>
 #include <stdbool.h>
-#include "quantum.h"
-#ifdef DRV2605L
-#    include "DRV2605L.h"
-#endif
 
 #ifndef HAPTIC_FEEDBACK_DEFAULT
 #    define HAPTIC_FEEDBACK_DEFAULT 0
@@ -52,7 +48,6 @@ typedef enum HAPTIC_FEEDBACK {
     HAPTIC_FEEDBACK_MAX,
 } HAPTIC_FEEDBACK;
 
-bool    process_haptic(uint16_t keycode, keyrecord_t *record);
 void    haptic_init(void);
 void    haptic_task(void);
 void    eeconfig_debug_haptic(void);
@@ -69,6 +64,7 @@ void    haptic_set_mode(uint8_t mode);
 void    haptic_set_dwell(uint8_t dwell);
 void    haptic_set_buzz(uint8_t buzz);
 void    haptic_buzz_toggle(void);
+uint8_t haptic_get_enable(void);
 uint8_t haptic_get_mode(void);
 uint8_t haptic_get_feedback(void);
 void    haptic_dwell_increase(void);

+ 147 - 0
quantum/process_keycode/process_haptic.c

@@ -0,0 +1,147 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "haptic.h"
+#include "process_haptic.h"
+#include "quantum_keycodes.h"
+
+__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
+    switch (keycode) {
+#ifdef NO_HAPTIC_MOD
+        case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+            if (record->tap.count == 0) return false;
+            break;
+        case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+            if (record->tap.count != TAPPING_TOGGLE) return false;
+            break;
+        case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
+            if (record->tap.count == 0) return false;
+            break;
+        case KC_LCTRL ... KC_RGUI:
+        case QK_MOMENTARY ... QK_MOMENTARY_MAX:
+#endif
+#ifdef NO_HAPTIC_FN
+        case KC_FN0 ... KC_FN31:
+#endif
+#ifdef NO_HAPTIC_ALPHA
+        case KC_A ... KC_Z:
+#endif
+#ifdef NO_HAPTIC_PUNCTUATION
+        case KC_ENTER:
+        case KC_ESCAPE:
+        case KC_BSPACE:
+        case KC_SPACE:
+        case KC_MINUS:
+        case KC_EQUAL:
+        case KC_LBRACKET:
+        case KC_RBRACKET:
+        case KC_BSLASH:
+        case KC_NONUS_HASH:
+        case KC_SCOLON:
+        case KC_QUOTE:
+        case KC_GRAVE:
+        case KC_COMMA:
+        case KC_SLASH:
+        case KC_DOT:
+        case KC_NONUS_BSLASH:
+#endif
+#ifdef NO_HAPTIC_LOCKKEYS
+        case KC_CAPSLOCK:
+        case KC_SCROLLLOCK:
+        case KC_NUMLOCK:
+#endif
+#ifdef NO_HAPTIC_NAV
+        case KC_PSCREEN:
+        case KC_PAUSE:
+        case KC_INSERT:
+        case KC_DELETE:
+        case KC_PGDOWN:
+        case KC_PGUP:
+        case KC_LEFT:
+        case KC_UP:
+        case KC_RIGHT:
+        case KC_DOWN:
+        case KC_END:
+        case KC_HOME:
+#endif
+#ifdef NO_HAPTIC_NUMERIC
+        case KC_1 ... KC_0:
+#endif
+            return false;
+    }
+    return true;
+}
+
+bool process_haptic(uint16_t keycode, keyrecord_t *record) {
+    if (record->event.pressed) {
+        switch (keycode) {
+            case HPT_ON:
+                haptic_enable();
+                break;
+            case HPT_OFF:
+                haptic_disable();
+                break;
+            case HPT_TOG:
+                haptic_toggle();
+                break;
+            case HPT_RST:
+                haptic_reset();
+                break;
+            case HPT_FBK:
+                haptic_feedback_toggle();
+                break;
+            case HPT_BUZ:
+                haptic_buzz_toggle();
+                break;
+            case HPT_MODI:
+                haptic_mode_increase();
+                break;
+            case HPT_MODD:
+                haptic_mode_decrease();
+                break;
+            case HPT_DWLI:
+                haptic_dwell_increase();
+                break;
+            case HPT_DWLD:
+                haptic_dwell_decrease();
+                break;
+            case HPT_CONT:
+                haptic_toggle_continuous();
+                break;
+            case HPT_CONI:
+                haptic_cont_increase();
+                break;
+            case HPT_COND:
+                haptic_cont_decrease();
+                break;
+        }
+    }
+
+    if (haptic_get_enable()) {
+        if (record->event.pressed) {
+            // keypress
+            if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) {
+                haptic_play();
+            }
+        } else {
+            // keyrelease
+            if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, record)) {
+                haptic_play();
+            }
+        }
+    }
+
+    return true;
+}

+ 21 - 0
quantum/process_keycode/process_haptic.h

@@ -0,0 +1,21 @@
+/* Copyright 2021 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include <stdbool.h>
+#include "action.h"
+
+bool process_haptic(uint16_t keycode, keyrecord_t *record);

+ 2 - 2
quantum/quantum.c

@@ -220,10 +220,10 @@ bool process_record_quantum(keyrecord_t *record) {
 #endif
 #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
             process_clicky(keycode, record) &&
-#endif  // AUDIO_CLICKY
+#endif
 #ifdef HAPTIC_ENABLE
             process_haptic(keycode, record) &&
-#endif  // HAPTIC_ENABLE
+#endif
 #if defined(VIA_ENABLE)
             process_record_via(keycode, record) &&
 #endif

+ 1 - 0
quantum/quantum.h

@@ -161,6 +161,7 @@ extern layer_state_t layer_state;
 
 #ifdef HAPTIC_ENABLE
 #    include "haptic.h"
+#    include "process_haptic.h"
 #endif
 
 #ifdef OLED_DRIVER_ENABLE