]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/host.c
Usbasploader bootloader option addition (#6304)
[qmk_firmware.git] / tmk_core / 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 #ifdef NKRO_ENABLE
26   #include "keycode_config.h"
27   extern keymap_config_t keymap_config;
28 #endif
29
30 static host_driver_t *driver;
31 static uint16_t last_system_report = 0;
32 static uint16_t last_consumer_report = 0;
33
34
35 void host_set_driver(host_driver_t *d)
36 {
37     driver = d;
38 }
39
40 host_driver_t *host_get_driver(void)
41 {
42     return driver;
43 }
44
45 uint8_t host_keyboard_leds(void)
46 {
47     if (!driver) return 0;
48     return (*driver->keyboard_leds)();
49 }
50 /* send report */
51 void host_keyboard_send(report_keyboard_t *report)
52 {
53     if (!driver) return;
54 #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP)
55     if (keyboard_protocol && keymap_config.nkro) {
56         /* The callers of this function assume that report->mods is where mods go in.
57          * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID.
58          */
59         report->nkro.mods = report->mods;
60         report->nkro.report_id = REPORT_ID_NKRO;
61     } else
62 #endif
63     {
64 #ifdef KEYBOARD_SHARED_EP
65         report->report_id = REPORT_ID_KEYBOARD;
66 #endif
67     }
68     (*driver->send_keyboard)(report);
69
70     if (debug_keyboard) {
71         dprint("keyboard_report: ");
72         for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) {
73             dprintf("%02X ", report->raw[i]);
74         }
75         dprint("\n");
76     }
77 }
78
79 void host_mouse_send(report_mouse_t *report)
80 {
81     if (!driver) return;
82 #ifdef MOUSE_SHARED_EP
83     report->report_id = REPORT_ID_MOUSE;
84 #endif
85     (*driver->send_mouse)(report);
86 }
87
88 void host_system_send(uint16_t report)
89 {
90     if (report == last_system_report) return;
91     last_system_report = report;
92
93     if (!driver) return;
94     (*driver->send_system)(report);
95 }
96
97 void host_consumer_send(uint16_t report)
98 {
99     if (report == last_consumer_report) return;
100     last_consumer_report = report;
101
102     if (!driver) return;
103     (*driver->send_consumer)(report);
104 }
105
106 uint16_t host_last_system_report(void)
107 {
108     return last_system_report;
109 }
110
111 uint16_t host_last_consumer_report(void)
112 {
113     return last_consumer_report;
114 }