aboutsummaryrefslogtreecommitdiff
path: root/common/host.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2012-10-12 04:46:37 +0900
committertmk <nobody@nowhere>2012-10-17 15:55:37 +0900
commit1677b021d7bff6af7763532b038612363b61dada (patch)
tree1f9d95373843f620cbd7be7d4bd7cbb84c9e8c22 /common/host.c
parent0a70be9a97215e2b514841f67e52b4c55a6adab1 (diff)
downloadqmk_firmware-1677b021d7bff6af7763532b038612363b61dada.tar.gz
qmk_firmware-1677b021d7bff6af7763532b038612363b61dada.zip
Fix layer switching and host API.
Diffstat (limited to 'common/host.c')
-rw-r--r--common/host.c95
1 files changed, 58 insertions, 37 deletions
diff --git a/common/host.c b/common/host.c
index a671c97d3..261ec6472 100644
--- a/common/host.c
+++ b/common/host.c
@@ -27,9 +27,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27bool keyboard_nkro = false; 27bool keyboard_nkro = false;
28#endif 28#endif
29 29
30static host_driver_t *driver;
31report_keyboard_t *keyboard_report = &(report_keyboard_t){}; 30report_keyboard_t *keyboard_report = &(report_keyboard_t){};
31report_mouse_t mouse_report = {};
32
32 33
34static host_driver_t *driver;
35static uint16_t last_system_report = 0;
36static uint16_t last_consumer_report = 0;
33 37
34static inline void add_key_byte(uint8_t code); 38static inline void add_key_byte(uint8_t code);
35static inline void del_key_byte(uint8_t code); 39static inline void del_key_byte(uint8_t code);
@@ -52,8 +56,48 @@ uint8_t host_keyboard_leds(void)
52 if (!driver) return 0; 56 if (!driver) return 0;
53 return (*driver->keyboard_leds)(); 57 return (*driver->keyboard_leds)();
54} 58}
59/* send report */
60void host_keyboard_send(report_keyboard_t *report)
61{
62 if (!driver) return;
63 (*driver->send_keyboard)(report);
64
65 if (debug_keyboard) {
66 print("keys: ");
67 for (int i = 0; i < REPORT_KEYS; i++) {
68 phex(keyboard_report->keys[i]); print(" ");
69 }
70 print(" mods: "); phex(keyboard_report->mods); print("\n");
71 }
72}
73
74void host_mouse_send(report_mouse_t *report)
75{
76 if (!driver) return;
77 (*driver->send_mouse)(report);
78}
79
80void host_system_send(uint16_t report)
81{
82 if (report == last_system_report) return;
83 last_system_report = report;
84
85 if (!driver) return;
86 (*driver->send_system)(report);
87}
88
89void host_consumer_send(uint16_t report)
90{
91 if (report == last_consumer_report) return;
92 last_consumer_report = report;
93
94 if (!driver) return;
95 (*driver->send_consumer)(report);
96}
97
98
55 99
56/* keyboard report operations */ 100/* keyboard report utils */
57void host_add_key(uint8_t key) 101void host_add_key(uint8_t key)
58{ 102{
59#ifdef NKRO_ENABLE 103#ifdef NKRO_ENABLE
@@ -113,6 +157,11 @@ uint8_t host_has_anykey(void)
113 return cnt; 157 return cnt;
114} 158}
115 159
160uint8_t host_has_anymod(void)
161{
162 return bitpop(keyboard_report->mods);
163}
164
116uint8_t host_get_first_key(void) 165uint8_t host_get_first_key(void)
117{ 166{
118#ifdef NKRO_ENABLE 167#ifdef NKRO_ENABLE
@@ -129,52 +178,24 @@ uint8_t host_get_first_key(void)
129void host_send_keyboard_report(void) 178void host_send_keyboard_report(void)
130{ 179{
131 if (!driver) return; 180 if (!driver) return;
132 (*driver->send_keyboard)(keyboard_report); 181 host_keyboard_send(keyboard_report);
133
134 if (debug_keyboard) {
135 print("keys: ");
136 for (int i = 0; i < REPORT_KEYS; i++) {
137 phex(keyboard_report->keys[i]); print(" ");
138 }
139 print(" mods: "); phex(keyboard_report->mods); print("\n");
140 }
141} 182}
142 183
143 184uint8_t host_mouse_in_use(void)
144/* send report */
145void host_keyboard_send(report_keyboard_t *report)
146{ 185{
147 if (!driver) return; 186 return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h);
148 (*driver->send_keyboard)(report);
149} 187}
150 188
151void host_mouse_send(report_mouse_t *report) 189uint16_t host_last_sysytem_report(void)
152{ 190{
153 if (!driver) return; 191 return last_system_report;
154 (*driver->send_mouse)(report);
155} 192}
156 193
157void host_system_send(uint16_t data) 194uint16_t host_last_consumer_report(void)
158{ 195{
159 static uint16_t last_data = 0; 196 return last_consumer_report;
160 if (data == last_data) return;
161 last_data = data;
162
163 if (!driver) return;
164 (*driver->send_system)(data);
165} 197}
166 198
167void host_consumer_send(uint16_t data)
168{
169 static uint16_t last_data = 0;
170 if (data == last_data) return;
171 last_data = data;
172
173 if (!driver) return;
174 (*driver->send_consumer)(data);
175}
176
177
178static inline void add_key_byte(uint8_t code) 199static inline void add_key_byte(uint8_t code)
179{ 200{
180 int8_t i = 0; 201 int8_t i = 0;