X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;ds=sidebyside;f=pjrc%2Fhost.c;h=fcf71d57907f6475c7f21ac5bf4cfa9ea7765cd5;hb=225de7a847a511d004bf909b1334e19497cf2f9d;hp=7247288bd75fe91979f964ded05274a2f50bc2b8;hpb=9a938eecbd2b70c970992583b5c16da717d8e254;p=max%2Ftmk_keyboard.git diff --git a/pjrc/host.c b/pjrc/host.c index 7247288b..fcf71d57 100644 --- a/pjrc/host.c +++ b/pjrc/host.c @@ -1,12 +1,36 @@ +/* +Copyright 2011 Jun Wako + +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 . +*/ + #include +#include #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 @@ -27,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; @@ -57,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) @@ -80,14 +107,17 @@ uint8_t host_has_anykey(void) return cnt; } -uint8_t *host_get_keys(void) +uint8_t host_get_first_key(void) { - return keyboard_report->keys; -} - -uint8_t host_get_mods(void) -{ - return keyboard_report->mods; +#ifdef NKRO_ENABLE + if (keyboard_nkro) { + uint8_t i = 0; + for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++) + ; + return i<<3 | biton(keyboard_report->keys[i]); + } +#endif + return keyboard_report->keys[0]; } @@ -96,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)