]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - pjrc/host.c
Merge branch 'fix_layer_delay'
[max/tmk_keyboard.git] / pjrc / host.c
index 8da88517b5cffb8c59a61a8d62a6f59860e6cda9..fcf71d57907f6475c7f21ac5bf4cfa9ea7765cd5 100644 (file)
@@ -1,13 +1,36 @@
+/*
+Copyright 2011 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
 #include <stdint.h>
+#include <avr/interrupt.h>
 #include "usb_keycodes.h"
 #include "usb_keyboard.h"
+#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
 #include "usb_mouse.h"
+#endif
+#ifdef EXTRAKEY_ENABLE
+#include "usb_extra.h"
+#endif
 #include "debug.h"
 #include "host.h"
 #include "util.h"
 
 
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
 bool keyboard_nkro = false;
 #endif
 
@@ -28,7 +51,7 @@ uint8_t host_keyboard_leds(void)
 /* keyboard report operations */
 void host_add_key(uint8_t key)
 {
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
     if (keyboard_nkro) {
         add_key_bit(key);
         return;
@@ -58,9 +81,12 @@ void host_add_code(uint8_t code)
 
 void host_swap_keyboard_report(void)
 {
+    uint8_t sreg = SREG;
+    cli();
     report_keyboard_t *tmp = keyboard_report_prev;
     keyboard_report_prev = keyboard_report;
     keyboard_report = tmp;
+    SREG = sreg;
 }
 
 void host_clear_keyboard_report(void)
@@ -83,7 +109,7 @@ uint8_t host_has_anykey(void)
 
 uint8_t host_get_first_key(void)
 {
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
     if (keyboard_nkro) {
         uint8_t i = 0;
         for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++)
@@ -100,10 +126,28 @@ void host_send_keyboard_report(void)
     usb_keyboard_send_report(keyboard_report);
 }
 
+#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
 void host_mouse_send(report_mouse_t *report)
 {
     usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
 }
+#endif
+
+#ifdef EXTRAKEY_ENABLE
+void host_system_send(uint16_t data)
+{
+    usb_extra_system_send(data);
+}
+
+void host_consumer_send(uint16_t data)
+{
+    static uint16_t last_data = 0;
+    if (data == last_data) return;
+    last_data = data;
+
+    usb_extra_consumer_send(data);
+}
+#endif
 
 
 static inline void add_key_byte(uint8_t code)