diff options
Diffstat (limited to 'tmk_core/protocol/host.c')
-rw-r--r-- | tmk_core/protocol/host.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c new file mode 100644 index 000000000..56d4bb084 --- /dev/null +++ b/tmk_core/protocol/host.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | Copyright 2011,2012 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <stdint.h> | ||
19 | //#include <avr/interrupt.h> | ||
20 | #include "keyboard.h" | ||
21 | #include "keycode.h" | ||
22 | #include "host.h" | ||
23 | #include "util.h" | ||
24 | #include "debug.h" | ||
25 | #include "digitizer.h" | ||
26 | |||
27 | #ifdef NKRO_ENABLE | ||
28 | # include "keycode_config.h" | ||
29 | extern keymap_config_t keymap_config; | ||
30 | #endif | ||
31 | |||
32 | static host_driver_t *driver; | ||
33 | static uint16_t last_system_report = 0; | ||
34 | static uint16_t last_consumer_report = 0; | ||
35 | static uint32_t last_programmable_button_report = 0; | ||
36 | |||
37 | void host_set_driver(host_driver_t *d) { driver = d; } | ||
38 | |||
39 | host_driver_t *host_get_driver(void) { return driver; } | ||
40 | |||
41 | #ifdef SPLIT_KEYBOARD | ||
42 | uint8_t split_led_state = 0; | ||
43 | void set_split_host_keyboard_leds(uint8_t led_state) { split_led_state = led_state; } | ||
44 | #endif | ||
45 | |||
46 | uint8_t host_keyboard_leds(void) { | ||
47 | #ifdef SPLIT_KEYBOARD | ||
48 | if (!is_keyboard_master()) return split_led_state; | ||
49 | #endif | ||
50 | if (!driver) return 0; | ||
51 | return (*driver->keyboard_leds)(); | ||
52 | } | ||
53 | |||
54 | led_t host_keyboard_led_state(void) { return (led_t)host_keyboard_leds(); } | ||
55 | |||
56 | /* send report */ | ||
57 | void host_keyboard_send(report_keyboard_t *report) { | ||
58 | if (!driver) return; | ||
59 | #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP) | ||
60 | if (keyboard_protocol && keymap_config.nkro) { | ||
61 | /* The callers of this function assume that report->mods is where mods go in. | ||
62 | * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID. | ||
63 | */ | ||
64 | report->nkro.mods = report->mods; | ||
65 | report->nkro.report_id = REPORT_ID_NKRO; | ||
66 | } else | ||
67 | #endif | ||
68 | { | ||
69 | #ifdef KEYBOARD_SHARED_EP | ||
70 | report->report_id = REPORT_ID_KEYBOARD; | ||
71 | #endif | ||
72 | } | ||
73 | (*driver->send_keyboard)(report); | ||
74 | |||
75 | if (debug_keyboard) { | ||
76 | dprint("keyboard_report: "); | ||
77 | for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) { | ||
78 | dprintf("%02X ", report->raw[i]); | ||
79 | } | ||
80 | dprint("\n"); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | void host_mouse_send(report_mouse_t *report) { | ||
85 | if (!driver) return; | ||
86 | #ifdef MOUSE_SHARED_EP | ||
87 | report->report_id = REPORT_ID_MOUSE; | ||
88 | #endif | ||
89 | (*driver->send_mouse)(report); | ||
90 | } | ||
91 | |||
92 | void host_system_send(uint16_t report) { | ||
93 | if (report == last_system_report) return; | ||
94 | last_system_report = report; | ||
95 | |||
96 | if (!driver) return; | ||
97 | (*driver->send_system)(report); | ||
98 | } | ||
99 | |||
100 | void host_consumer_send(uint16_t report) { | ||
101 | if (report == last_consumer_report) return; | ||
102 | last_consumer_report = report; | ||
103 | |||
104 | if (!driver) return; | ||
105 | (*driver->send_consumer)(report); | ||
106 | } | ||
107 | |||
108 | void host_digitizer_send(digitizer_t *digitizer) { | ||
109 | if (!driver) return; | ||
110 | |||
111 | report_digitizer_t report = { | ||
112 | #ifdef DIGITIZER_SHARED_EP | ||
113 | .report_id = REPORT_ID_DIGITIZER, | ||
114 | #endif | ||
115 | .tip = digitizer->tipswitch & 0x1, | ||
116 | .inrange = digitizer->inrange & 0x1, | ||
117 | .x = (uint16_t)(digitizer->x * 0x7FFF), | ||
118 | .y = (uint16_t)(digitizer->y * 0x7FFF), | ||
119 | }; | ||
120 | |||
121 | send_digitizer(&report); | ||
122 | } | ||
123 | |||
124 | __attribute__((weak)) void send_digitizer(report_digitizer_t *report) {} | ||
125 | |||
126 | void host_programmable_button_send(uint32_t report) { | ||
127 | if (report == last_programmable_button_report) return; | ||
128 | last_programmable_button_report = report; | ||
129 | |||
130 | if (!driver) return; | ||
131 | (*driver->send_programmable_button)(report); | ||
132 | } | ||
133 | |||
134 | uint16_t host_last_system_report(void) { return last_system_report; } | ||
135 | |||
136 | uint16_t host_last_consumer_report(void) { return last_consumer_report; } | ||
137 | |||
138 | uint32_t host_last_programmable_button_report(void) { return last_programmable_button_report; } | ||