]> git.gir.st - tmk_keyboard.git/blob - common/host.c
changed tabs to spaces in bluefruit.c
[tmk_keyboard.git] / common / host.c
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 "keycode.h"
21 #include "host.h"
22 #include "util.h"
23 #include "debug.h"
24
25
26 #ifdef NKRO_ENABLE
27 bool keyboard_nkro = false;
28 #endif
29
30 report_mouse_t mouse_report = {};
31
32
33 static host_driver_t *driver;
34 static uint16_t last_system_report = 0;
35 static uint16_t last_consumer_report = 0;
36
37
38 void host_set_driver(host_driver_t *d)
39 {
40 driver = d;
41 }
42
43 host_driver_t *host_get_driver(void)
44 {
45 return driver;
46 }
47
48 uint8_t host_keyboard_leds(void)
49 {
50 if (!driver) return 0;
51 return (*driver->keyboard_leds)();
52 }
53 /* send report */
54 void host_keyboard_send(report_keyboard_t *report)
55 {
56 if (!driver) return;
57 (*driver->send_keyboard)(report);
58
59 if (debug_keyboard) {
60 dprint("keyboard_report: ");
61 for (uint8_t i = 0; i < REPORT_SIZE; i++) {
62 dprintf("%02X ", report->raw[i]);
63 }
64 dprint("\n");
65 }
66 }
67
68 void host_mouse_send(report_mouse_t *report)
69 {
70 if (!driver) return;
71 (*driver->send_mouse)(report);
72 }
73
74 void host_system_send(uint16_t report)
75 {
76 if (report == last_system_report) return;
77 last_system_report = report;
78
79 if (!driver) return;
80 (*driver->send_system)(report);
81 }
82
83 void host_consumer_send(uint16_t report)
84 {
85 if (report == last_consumer_report) return;
86 last_consumer_report = report;
87
88 if (!driver) return;
89 (*driver->send_consumer)(report);
90 }
91
92 uint8_t host_mouse_in_use(void)
93 {
94 return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h);
95 }
96
97 uint16_t host_last_sysytem_report(void)
98 {
99 return last_system_report;
100 }
101
102 uint16_t host_last_consumer_report(void)
103 {
104 return last_consumer_report;
105 }
Imprint / Impressum