summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/host.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/host.c')
-rw-r--r--tmk_core/protocol/host.c150
1 files changed, 122 insertions, 28 deletions
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c
index 3d8604d541..b441d2d5d9 100644
--- a/tmk_core/protocol/host.c
+++ b/tmk_core/protocol/host.c
@@ -16,13 +16,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
-//#include <avr/interrupt.h>
#include "keyboard.h"
#include "keycode.h"
#include "host.h"
#include "util.h"
#include "debug.h"
-#include "digitizer.h"
+
+#ifdef DIGITIZER_ENABLE
+# include "digitizer.h"
+#endif
+
+#ifdef JOYSTICK_ENABLE
+# include "joystick.h"
+#endif
+
+#ifdef BLUETOOTH_ENABLE
+# include "bluetooth.h"
+# include "outputselect.h"
+#endif
#ifdef NKRO_ENABLE
# include "keycode_config.h"
@@ -30,9 +41,8 @@ extern keymap_config_t keymap_config;
#endif
static host_driver_t *driver;
-static uint16_t last_system_report = 0;
-static uint16_t last_consumer_report = 0;
-static uint32_t last_programmable_button_report = 0;
+static uint16_t last_system_usage = 0;
+static uint16_t last_consumer_usage = 0;
void host_set_driver(host_driver_t *d) {
driver = d;
@@ -63,6 +73,13 @@ led_t host_keyboard_led_state(void) {
/* send report */
void host_keyboard_send(report_keyboard_t *report) {
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_keyboard(report);
+ return;
+ }
+#endif
+
if (!driver) return;
#if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP)
if (keyboard_protocol && keymap_config.nkro) {
@@ -90,6 +107,13 @@ void host_keyboard_send(report_keyboard_t *report) {
}
void host_mouse_send(report_mouse_t *report) {
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_mouse(report);
+ return;
+ }
+#endif
+
if (!driver) return;
#ifdef MOUSE_SHARED_EP
report->report_id = REPORT_ID_MOUSE;
@@ -102,29 +126,97 @@ void host_mouse_send(report_mouse_t *report) {
(*driver->send_mouse)(report);
}
-void host_system_send(uint16_t report) {
- if (report == last_system_report) return;
- last_system_report = report;
+void host_system_send(uint16_t usage) {
+ if (usage == last_system_usage) return;
+ last_system_usage = usage;
if (!driver) return;
- (*driver->send_system)(report);
+
+ report_extra_t report = {
+ .report_id = REPORT_ID_SYSTEM,
+ .usage = usage,
+ };
+ (*driver->send_extra)(&report);
}
-void host_consumer_send(uint16_t report) {
- if (report == last_consumer_report) return;
- last_consumer_report = report;
+void host_consumer_send(uint16_t usage) {
+ if (usage == last_consumer_usage) return;
+ last_consumer_usage = usage;
+
+#ifdef BLUETOOTH_ENABLE
+ if (where_to_send() == OUTPUT_BLUETOOTH) {
+ bluetooth_send_consumer(usage);
+ return;
+ }
+#endif
if (!driver) return;
- (*driver->send_consumer)(report);
+
+ report_extra_t report = {
+ .report_id = REPORT_ID_CONSUMER,
+ .usage = usage,
+ };
+ (*driver->send_extra)(&report);
}
-void host_digitizer_send(digitizer_t *digitizer) {
+#ifdef JOYSTICK_ENABLE
+void host_joystick_send(joystick_t *joystick) {
if (!driver) return;
+ report_joystick_t report = {
+# if JOYSTICK_AXES_COUNT > 0
+ .axes =
+ {
+ joystick->axes[0],
+
+# if JOYSTICK_AXES_COUNT >= 2
+ joystick->axes[1],
+# endif
+# if JOYSTICK_AXES_COUNT >= 3
+ joystick->axes[2],
+# endif
+# if JOYSTICK_AXES_COUNT >= 4
+ joystick->axes[3],
+# endif
+# if JOYSTICK_AXES_COUNT >= 5
+ joystick->axes[4],
+# endif
+# if JOYSTICK_AXES_COUNT >= 6
+ joystick->axes[5],
+# endif
+ },
+# endif
+
+# if JOYSTICK_BUTTON_COUNT > 0
+ .buttons =
+ {
+ joystick->buttons[0],
+
+# if JOYSTICK_BUTTON_COUNT > 8
+ joystick->buttons[1],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 16
+ joystick->buttons[2],
+# endif
+# if JOYSTICK_BUTTON_COUNT > 24
+ joystick->buttons[3],
+# endif
+ },
+# endif
+ };
+
+ send_joystick(&report);
+}
+#endif
+
+__attribute__((weak)) void send_joystick(report_joystick_t *report) {}
+
+#ifdef DIGITIZER_ENABLE
+void host_digitizer_send(digitizer_t *digitizer) {
report_digitizer_t report = {
-#ifdef DIGITIZER_SHARED_EP
+# ifdef DIGITIZER_SHARED_EP
.report_id = REPORT_ID_DIGITIZER,
-#endif
+# endif
.tip = digitizer->tipswitch & 0x1,
.inrange = digitizer->inrange & 0x1,
.x = (uint16_t)(digitizer->x * 0x7FFF),
@@ -133,25 +225,27 @@ void host_digitizer_send(digitizer_t *digitizer) {
send_digitizer(&report);
}
+#endif
__attribute__((weak)) void send_digitizer(report_digitizer_t *report) {}
-void host_programmable_button_send(uint32_t report) {
- if (report == last_programmable_button_report) return;
- last_programmable_button_report = report;
+#ifdef PROGRAMMABLE_BUTTON_ENABLE
+void host_programmable_button_send(uint32_t data) {
+ report_programmable_button_t report = {
+ .report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
+ .usage = data,
+ };
- if (!driver) return;
- (*driver->send_programmable_button)(report);
+ send_programmable_button(&report);
}
+#endif
-uint16_t host_last_system_report(void) {
- return last_system_report;
-}
+__attribute__((weak)) void send_programmable_button(report_programmable_button_t *report) {}
-uint16_t host_last_consumer_report(void) {
- return last_consumer_report;
+uint16_t host_last_system_usage(void) {
+ return last_system_usage;
}
-uint32_t host_last_programmable_button_report(void) {
- return last_programmable_button_report;
+uint16_t host_last_consumer_usage(void) {
+ return last_consumer_usage;
}