]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - common/host.c
Create keymap.md
[max/tmk_keyboard.git] / common / host.c
index a671c97d309b09629db71bc16e3f8be4879c91a6..6ed3d780f640affa88668ab11a303b40090200db 100644 (file)
@@ -27,9 +27,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 bool keyboard_nkro = false;
 #endif
 
-static host_driver_t *driver;
 report_keyboard_t *keyboard_report = &(report_keyboard_t){};
+report_mouse_t mouse_report = {};
+
 
+static host_driver_t *driver;
+static uint16_t last_system_report = 0;
+static uint16_t last_consumer_report = 0;
 
 static inline void add_key_byte(uint8_t code);
 static inline void del_key_byte(uint8_t code);
@@ -52,8 +56,48 @@ uint8_t host_keyboard_leds(void)
     if (!driver) return 0;
     return (*driver->keyboard_leds)();
 }
+/* send report */
+void host_keyboard_send(report_keyboard_t *report)
+{
+    if (!driver) return;
+    (*driver->send_keyboard)(report);
+
+    if (debug_keyboard) {
+        print("keys: ");
+        for (int i = 0; i < REPORT_KEYS; i++) {
+            phex(keyboard_report->keys[i]); print(" ");
+        }
+        print(" mods: "); phex(keyboard_report->mods); print("\n");
+    }
+}
+
+void host_mouse_send(report_mouse_t *report)
+{
+    if (!driver) return;
+    (*driver->send_mouse)(report);
+}
+
+void host_system_send(uint16_t report)
+{
+    if (report == last_system_report) return;
+    last_system_report = report;
+
+    if (!driver) return;
+    (*driver->send_system)(report);
+}
+
+void host_consumer_send(uint16_t report)
+{
+    if (report == last_consumer_report) return;
+    last_consumer_report = report;
+
+    if (!driver) return;
+    (*driver->send_consumer)(report);
+}
 
-/* keyboard report operations */
+
+
+/* keyboard report utils */
 void host_add_key(uint8_t key)
 {
 #ifdef NKRO_ENABLE
@@ -83,14 +127,19 @@ void host_clear_keys(void)
     }
 }
 
-void host_add_mod_bit(uint8_t mod)
+uint8_t host_get_mods(void)
+{
+    return keyboard_report->mods;
+}
+
+void host_add_mods(uint8_t mods)
 {
-    keyboard_report->mods |= mod;
+    keyboard_report->mods |= mods;
 }
 
-void host_del_mod_bit(uint8_t mod)
+void host_del_mods(uint8_t mods)
 {
-    keyboard_report->mods &= ~mod;
+    keyboard_report->mods &= ~mods;
 }
 
 void host_set_mods(uint8_t mods)
@@ -113,6 +162,11 @@ uint8_t host_has_anykey(void)
     return cnt;
 }
 
+uint8_t host_has_anymod(void)
+{
+    return bitpop(keyboard_report->mods);
+}
+
 uint8_t host_get_first_key(void)
 {
 #ifdef NKRO_ENABLE
@@ -129,52 +183,24 @@ uint8_t host_get_first_key(void)
 void host_send_keyboard_report(void)
 {
     if (!driver) return;
-    (*driver->send_keyboard)(keyboard_report);
-
-    if (debug_keyboard) {
-        print("keys: ");
-        for (int i = 0; i < REPORT_KEYS; i++) {
-            phex(keyboard_report->keys[i]); print(" ");
-        }
-        print(" mods: "); phex(keyboard_report->mods); print("\n");
-    }
-}
-
-
-/* send report */
-void host_keyboard_send(report_keyboard_t *report)
-{
-    if (!driver) return;
-    (*driver->send_keyboard)(report);
+    host_keyboard_send(keyboard_report);
 }
 
-void host_mouse_send(report_mouse_t *report)
+uint8_t host_mouse_in_use(void)
 {
-    if (!driver) return;
-    (*driver->send_mouse)(report);
+    return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h);
 }
 
-void host_system_send(uint16_t data)
+uint16_t host_last_sysytem_report(void)
 {
-    static uint16_t last_data = 0;
-    if (data == last_data) return;
-    last_data = data;
-
-    if (!driver) return;
-    (*driver->send_system)(data);
+    return last_system_report;
 }
 
-void host_consumer_send(uint16_t data)
+uint16_t host_last_consumer_report(void)
 {
-    static uint16_t last_data = 0;
-    if (data == last_data) return;
-    last_data = data;
-
-    if (!driver) return;
-    (*driver->send_consumer)(data);
+    return last_consumer_report;
 }
 
-
 static inline void add_key_byte(uint8_t code)
 {
     int8_t i = 0;