]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/common/action_tapping.c
Usbasploader bootloader option addition (#6304)
[qmk_firmware.git] / tmk_core / common / action_tapping.c
index e6343e6da7f9f759e1b2b2038899de2753e18275..3b67ed152f798f47778824d674d4328385183976 100644 (file)
 #define IS_TAPPING_PRESSED()    (IS_TAPPING() && tapping_key.event.pressed)
 #define IS_TAPPING_RELEASED()   (IS_TAPPING() && !tapping_key.event.pressed)
 #define IS_TAPPING_KEY(k)       (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
-#define WITHIN_TAPPING_TERM(e)  (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
 
+__attribute__ ((weak))
+uint16_t get_tapping_term(uint16_t keycode) {
+  return TAPPING_TERM;
+}
+
+#ifdef TAPPING_TERM_PER_KEY
+#define WITHIN_TAPPING_TERM(e)  (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event)))
+#else
+#define WITHIN_TAPPING_TERM(e)  (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
+#endif
 
 static keyrecord_t tapping_key = {};
 static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {};
@@ -36,6 +45,10 @@ static void debug_tapping_key(void);
 static void debug_waiting_buffer(void);
 
 
+/** \brief Action Tapping Process
+ *
+ * FIXME: Needs doc
+ */
 void action_tapping_process(keyrecord_t record)
 {
     if (process_tapping(&record)) {
@@ -70,7 +83,7 @@ void action_tapping_process(keyrecord_t record)
 }
 
 
-/* Tapping
+/** \brief Tapping
  *
  * Rule: Tap key is typed(pressed and released) within TAPPING_TERM.
  *       (without interfering by typing other key)
@@ -89,21 +102,26 @@ bool process_tapping(keyrecord_t *keyp)
                     debug("Tapping: First tap(0->1).\n");
                     tapping_key.tap.count = 1;
                     debug_tapping_key();
-                    process_action(&tapping_key);
+                    process_record(&tapping_key);
 
                     // copy tapping state
                     keyp->tap = tapping_key.tap;
                     // enqueue
                     return false;
                 }
-#if TAPPING_TERM >= 500
                 /* Process a key typed within TAPPING_TERM
                  * This can register the key before settlement of tapping,
                  * useful for long TAPPING_TERM but may prevent fast typing.
                  */
-                else if (IS_RELEASED(event) && waiting_buffer_typed(event)) {
+#if defined(TAPPING_TERM_PER_KEY) || (!defined(PER_KEY_TAPPING_TERM) && TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD)
+#ifdef TAPPING_TERM_PER_KEY
+                else if ( ( get_tapping_term(get_event_keycode(tapping_key.event)) >= 500) && IS_RELEASED(event) && waiting_buffer_typed(event))
+#else
+                else if ( IS_RELEASED(event) && waiting_buffer_typed(event))
+#endif
+                {
                     debug("Tapping: End. No tap. Interfered by typing key\n");
-                    process_action(&tapping_key);
+                    process_record(&tapping_key);
                     tapping_key = (keyrecord_t){};
                     debug_tapping_key();
                     // enqueue
@@ -131,7 +149,7 @@ bool process_tapping(keyrecord_t *keyp)
                     }
                     // Release of key should be process immediately.
                     debug("Tapping: release event of a key pressed before tapping\n");
-                    process_action(keyp);
+                    process_record(keyp);
                     return true;
                 }
                 else {
@@ -148,7 +166,7 @@ bool process_tapping(keyrecord_t *keyp)
                 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
                     debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n");
                     keyp->tap = tapping_key.tap;
-                    process_action(keyp);
+                    process_record(keyp);
                     tapping_key = *keyp;
                     debug_tapping_key();
                     return true;
@@ -157,7 +175,7 @@ bool process_tapping(keyrecord_t *keyp)
                     if (tapping_key.tap.count > 1) {
                         debug("Tapping: Start new tap with releasing last tap(>1).\n");
                         // unregister key
-                        process_action(&(keyrecord_t){
+                        process_record(&(keyrecord_t){
                                 .tap = tapping_key.tap,
                                 .event.key = tapping_key.event.key,
                                 .event.time = event.time,
@@ -175,7 +193,7 @@ bool process_tapping(keyrecord_t *keyp)
                     if (!IS_NOEVENT(event)) {
                         debug("Tapping: key event while last tap(>0).\n");
                     }
-                    process_action(keyp);
+                    process_record(keyp);
                     return true;
                 }
             }
@@ -185,7 +203,7 @@ bool process_tapping(keyrecord_t *keyp)
             if (tapping_key.tap.count == 0) {
                 debug("Tapping: End. Timeout. Not tap(0): ");
                 debug_event(event); debug("\n");
-                process_action(&tapping_key);
+                process_record(&tapping_key);
                 tapping_key = (keyrecord_t){};
                 debug_tapping_key();
                 return false;
@@ -193,7 +211,7 @@ bool process_tapping(keyrecord_t *keyp)
                 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
                     debug("Tapping: End. last timeout tap release(>0).");
                     keyp->tap = tapping_key.tap;
-                    process_action(keyp);
+                    process_record(keyp);
                     tapping_key = (keyrecord_t){};
                     return true;
                 }
@@ -201,7 +219,7 @@ bool process_tapping(keyrecord_t *keyp)
                     if (tapping_key.tap.count > 1) {
                         debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
                         // unregister key
-                        process_action(&(keyrecord_t){
+                        process_record(&(keyrecord_t){
                                 .tap = tapping_key.tap,
                                 .event.key = tapping_key.event.key,
                                 .event.time = event.time,
@@ -219,7 +237,7 @@ bool process_tapping(keyrecord_t *keyp)
                     if (!IS_NOEVENT(event)) {
                         debug("Tapping: key event while last timeout tap(>0).\n");
                     }
-                    process_action(keyp);
+                    process_record(keyp);
                     return true;
                 }
             }
@@ -228,20 +246,21 @@ bool process_tapping(keyrecord_t *keyp)
         if (WITHIN_TAPPING_TERM(event)) {
             if (event.pressed) {
                 if (IS_TAPPING_KEY(event.key)) {
+#ifndef TAPPING_FORCE_HOLD
                     if (!tapping_key.tap.interrupted && tapping_key.tap.count > 0) {
                         // sequential tap.
                         keyp->tap = tapping_key.tap;
                         if (keyp->tap.count < 15) keyp->tap.count += 1;
                         debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n");
-                        process_action(keyp);
+                        process_record(keyp);
                         tapping_key = *keyp;
                         debug_tapping_key();
                         return true;
-                    } else {
-                        // FIX: start new tap again
-                        tapping_key = *keyp;
-                        return true;
                     }
+#endif
+                    // FIX: start new tap again
+                    tapping_key = *keyp;
+                    return true;
                 } else if (is_tap_key(event.key)) {
                     // Sequential tap can be interfered with other tap key.
                     debug("Tapping: Start with interfering other tap.\n");
@@ -253,16 +272,16 @@ bool process_tapping(keyrecord_t *keyp)
                     // should none in buffer
                     // FIX: interrupted when other key is pressed
                     tapping_key.tap.interrupted = true;
-                    process_action(keyp);
+                    process_record(keyp);
                     return true;
                 }
             } else {
                 if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n");
-                process_action(keyp);
+                process_record(keyp);
                 return true;
             }
         } else {
-            // FIX: process_aciton here?
+            // FIX: process_action here?
             // timeout. no sequential tap.
             debug("Tapping: End(Timeout after releasing last tap): ");
             debug_event(event); debug("\n");
@@ -276,19 +295,21 @@ bool process_tapping(keyrecord_t *keyp)
         if (event.pressed && is_tap_key(event.key)) {
             debug("Tapping: Start(Press tap key).\n");
             tapping_key = *keyp;
+            process_record_tap_hint(&tapping_key);
             waiting_buffer_scan_tap();
             debug_tapping_key();
             return true;
         } else {
-            process_action(keyp);
+            process_record(keyp);
             return true;
         }
     }
 }
 
 
-/*
- * Waiting buffer
+/** \brief Waiting buffer enq
+ *
+ * FIXME: Needs docs
  */
 bool waiting_buffer_enq(keyrecord_t record)
 {
@@ -308,12 +329,20 @@ bool waiting_buffer_enq(keyrecord_t record)
     return true;
 }
 
+/** \brief Waiting buffer clear
+ *
+ * FIXME: Needs docs
+ */
 void waiting_buffer_clear(void)
 {
     waiting_buffer_head = 0;
     waiting_buffer_tail = 0;
 }
 
+/** \brief Waiting buffer typed
+ *
+ * FIXME: Needs docs
+ */
 bool waiting_buffer_typed(keyevent_t event)
 {
     for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
@@ -324,6 +353,10 @@ bool waiting_buffer_typed(keyevent_t event)
     return false;
 }
 
+/** \brief Waiting buffer has anykey pressed
+ *
+ * FIXME: Needs docs
+ */
 __attribute__((unused))
 bool waiting_buffer_has_anykey_pressed(void)
 {
@@ -333,7 +366,10 @@ bool waiting_buffer_has_anykey_pressed(void)
     return false;
 }
 
-/* scan buffer for tapping */
+/** \brief Scan buffer for tapping
+ *
+ * FIXME: Needs docs
+ */
 void waiting_buffer_scan_tap(void)
 {
     // tapping already is settled
@@ -347,7 +383,7 @@ void waiting_buffer_scan_tap(void)
                 WITHIN_TAPPING_TERM(waiting_buffer[i].event)) {
             tapping_key.tap.count = 1;
             waiting_buffer[i].tap.count = 1;
-            process_action(&tapping_key);
+            process_record(&tapping_key);
 
             debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n");
             debug_waiting_buffer();
@@ -357,14 +393,19 @@ void waiting_buffer_scan_tap(void)
 }
 
 
-/*
- * debug print
+/** \brief Tapping key debug print
+ *
+ * FIXME: Needs docs
  */
 static void debug_tapping_key(void)
 {
     debug("TAPPING_KEY="); debug_record(tapping_key); debug("\n");
 }
 
+/** \brief Waiting buffer debug print
+ *
+ * FIXME: Needs docs
+ */
 static void debug_waiting_buffer(void)
 {
     debug("{ ");