X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=common%2Fhost.c;h=37f707d0b310a42ec9db70e83ed539c9c60e0729;hb=373ab0e7192811944786c095facb80938c33f1d5;hp=cc26d55c22b94b9d85f06503fad3160ccadafaf7;hpb=f4125707399d11a7d80587659c464b9bcddb8c56;p=max%2Ftmk_keyboard.git
diff --git a/common/host.c b/common/host.c
index cc26d55c..37f707d0 100644
--- a/common/host.c
+++ b/common/host.c
@@ -17,7 +17,7 @@ along with this program. If not, see .
#include
#include
-#include "usb_keycodes.h"
+#include "keycode.h"
#include "host.h"
#include "util.h"
#include "debug.h"
@@ -56,6 +56,27 @@ uint8_t host_keyboard_leds(void)
return (*driver->keyboard_leds)();
}
+/* new interface */
+void host_register_key(uint8_t key)
+{
+ host_add_key(key);
+ host_send_keyboard_report();
+}
+
+void host_unregister_key(uint8_t key)
+{
+ host_del_key(key);
+ host_send_keyboard_report();
+}
+
+void host_clear_all_keys_but_mods(void)
+{
+ for (int8_t i = 0; i < REPORT_KEYS; i++) {
+ keyboard_report->keys[i] = 0;
+ }
+ host_send_keyboard_report();
+}
+
/* keyboard report operations */
void host_add_key(uint8_t key)
{
@@ -158,6 +179,14 @@ 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");
+ }
}
void host_mouse_send(report_mouse_t *report)
@@ -168,13 +197,16 @@ void host_mouse_send(report_mouse_t *report)
void host_system_send(uint16_t data)
{
+ static uint16_t last_data = 0;
+ if (data == last_data) return;
+ last_data = data;
+
if (!driver) return;
(*driver->send_system)(data);
}
void host_consumer_send(uint16_t data)
{
- // TODO: this is needed?
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;
@@ -213,7 +245,6 @@ static inline void del_key_byte(uint8_t code)
for (; i < REPORT_KEYS; i++) {
if (keyboard_report->keys[i] == code) {
keyboard_report->keys[i] = 0;
- break;
}
}
}