]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - host.c
FIX: layer switching bug when Fn has no keycode.
[max/tmk_keyboard.git] / host.c
diff --git a/host.c b/host.c
index c5383ed4242c705c703a79fe1e9f3cc2852de923..cc26d55c22b94b9d85f06503fad3160ccadafaf7 100644 (file)
--- a/host.c
+++ b/host.c
@@ -35,7 +35,9 @@ report_keyboard_t *keyboard_report_prev = &report1;
 
 
 static inline void add_key_byte(uint8_t code);
+static inline void del_key_byte(uint8_t code);
 static inline void add_key_bit(uint8_t code);
+static inline void del_key_bit(uint8_t code);
 
 
 void host_set_driver(host_driver_t *d)
@@ -66,11 +68,27 @@ void host_add_key(uint8_t key)
     add_key_byte(key);
 }
 
+void host_del_key(uint8_t key)
+{
+#ifdef NKRO_ENABLE
+    if (keyboard_nkro) {
+        del_key_bit(key);
+        return;
+    }
+#endif
+    del_key_byte(key);
+}
+
 void host_add_mod_bit(uint8_t mod)
 {
     keyboard_report->mods |= mod;
 }
 
+void host_del_mod_bit(uint8_t mod)
+{
+    keyboard_report->mods &= ~mod;
+}
+
 void host_set_mods(uint8_t mods)
 {
     keyboard_report->mods = mods;
@@ -85,6 +103,15 @@ void host_add_code(uint8_t code)
     }
 }
 
+void host_del_code(uint8_t code)
+{
+    if (IS_MOD(code)) {
+        host_del_mod_bit(MOD_BIT(code));
+    } else {
+        host_del_key(code);
+    }
+}
+
 void host_swap_keyboard_report(void)
 {
     uint8_t sreg = SREG;
@@ -180,6 +207,17 @@ static inline void add_key_byte(uint8_t code)
     }
 }
 
+static inline void del_key_byte(uint8_t code)
+{
+    int i = 0;
+    for (; i < REPORT_KEYS; i++) {
+        if (keyboard_report->keys[i] == code) {
+            keyboard_report->keys[i] = 0;
+            break;
+        }
+    }
+}
+
 static inline void add_key_bit(uint8_t code)
 {
     if ((code>>3) < REPORT_KEYS) {
@@ -188,3 +226,12 @@ static inline void add_key_bit(uint8_t code)
         debug("add_key_bit: can't add: "); phex(code); debug("\n");
     }
 }
+
+static inline void del_key_bit(uint8_t code)
+{
+    if ((code>>3) < REPORT_KEYS) {
+        keyboard_report->keys[code>>3] &= ~(1<<(code&7));
+    } else {
+        debug("del_key_bit: can't del: "); phex(code); debug("\n");
+    }
+}