aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/quantum.c33
-rw-r--r--quantum/quantum.h1
-rw-r--r--quantum/quantum_keycodes.h10
-rw-r--r--tmk_core/protocol/lufa.mk3
-rw-r--r--tmk_core/protocol/lufa/lufa.c116
-rw-r--r--tmk_core/protocol/lufa/outputselect.c56
-rw-r--r--tmk_core/protocol/lufa/outputselect.h41
7 files changed, 189 insertions, 71 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index b83ae433e..d3905decf 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -1,4 +1,7 @@
1#include "quantum.h" 1#include "quantum.h"
2#ifdef PROTOCOL_LUFA
3#include "outputselect.h"
4#endif
2 5
3#ifndef TAPPING_TERM 6#ifndef TAPPING_TERM
4#define TAPPING_TERM 200 7#define TAPPING_TERM 200
@@ -243,6 +246,36 @@ bool process_record_quantum(keyrecord_t *record) {
243 return false; 246 return false;
244 break; 247 break;
245 #endif 248 #endif
249 #ifdef PROTOCOL_LUFA
250 case OUT_AUTO:
251 if (record->event.pressed) {
252 set_output(OUTPUT_AUTO);
253 }
254 return false;
255 break;
256 case OUT_USB:
257 if (record->event.pressed) {
258 set_output(OUTPUT_USB);
259 }
260 return false;
261 break;
262 #ifdef BLUETOOTH_ENABLE
263 case OUT_BT:
264 if (record->event.pressed) {
265 set_output(OUTPUT_BLUETOOTH);
266 }
267 return false;
268 break;
269 #endif
270 #ifdef ADAFRUIT_BLE_ENABLE
271 case OUT_BLE:
272 if (record->event.pressed) {
273 set_output(OUTPUT_ADAFRUIT_BLE);
274 }
275 return false;
276 break;
277 #endif
278 #endif
246 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: 279 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
247 if (record->event.pressed) { 280 if (record->event.pressed) {
248 // MAGIC actions (BOOTMAGIC without the boot) 281 // MAGIC actions (BOOTMAGIC without the boot)
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 8614c053a..18f072189 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -15,7 +15,6 @@
15#ifdef RGBLIGHT_ENABLE 15#ifdef RGBLIGHT_ENABLE
16 #include "rgblight.h" 16 #include "rgblight.h"
17#endif 17#endif
18
19#include "action_layer.h" 18#include "action_layer.h"
20#include "eeconfig.h" 19#include "eeconfig.h"
21#include <stddef.h> 20#include <stddef.h>
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 91324be35..a786bd322 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -141,6 +141,16 @@ enum quantum_keycodes {
141 PRINT_ON, 141 PRINT_ON,
142 PRINT_OFF, 142 PRINT_OFF,
143 143
144 // output selection
145 OUT_AUTO,
146 OUT_USB,
147#ifdef BLUETOOTH_ENABLE
148 OUT_BT,
149#endif
150#ifdef ADAFRUIT_BLE_ENABLE
151 OUT_BLE,
152#endif
153
144 // always leave at the end 154 // always leave at the end
145 SAFE_RANGE 155 SAFE_RANGE
146}; 156};
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk
index 151d26cbc..de0cc795f 100644
--- a/tmk_core/protocol/lufa.mk
+++ b/tmk_core/protocol/lufa.mk
@@ -8,13 +8,14 @@ LUFA_PATH ?= $(LUFA_DIR)/LUFA-git
8ifneq (, $(wildcard $(TMK_PATH)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk)) 8ifneq (, $(wildcard $(TMK_PATH)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk))
9 # New build system from 20120730 9 # New build system from 20120730
10 LUFA_ROOT_PATH = $(LUFA_PATH)/LUFA 10 LUFA_ROOT_PATH = $(LUFA_PATH)/LUFA
11 include $(TMK_PATH)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk 11 include $(TMK_PATH)/$(LUFA_PATH)/LUFA/Build/lufa_sources.mk
12else 12else
13 include $(TMK_PATH)/$(LUFA_PATH)/LUFA/makefile 13 include $(TMK_PATH)/$(LUFA_PATH)/LUFA/makefile
14endif 14endif
15 15
16LUFA_SRC = lufa.c \ 16LUFA_SRC = lufa.c \
17 descriptor.c \ 17 descriptor.c \
18 outputselect.c \
18 $(LUFA_SRC_USB) 19 $(LUFA_SRC_USB)
19 20
20ifeq ($(strip $(MIDI_ENABLE)), yes) 21ifeq ($(strip $(MIDI_ENABLE)), yes)
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 6dd5959dc..ba49284c9 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -53,6 +53,7 @@
53#include "lufa.h" 53#include "lufa.h"
54#include "quantum.h" 54#include "quantum.h"
55#include <util/atomic.h> 55#include <util/atomic.h>
56#include "outputselect.h"
56 57
57#ifdef NKRO_ENABLE 58#ifdef NKRO_ENABLE
58 #include "keycode_config.h" 59 #include "keycode_config.h"
@@ -589,59 +590,33 @@ void EVENT_USB_Device_ControlRequest(void)
589 590
590/******************************************************************************* 591/*******************************************************************************
591 * Host driver 592 * Host driver
592p
593 ******************************************************************************/ 593 ******************************************************************************/
594static uint8_t keyboard_leds(void) 594static uint8_t keyboard_leds(void)
595{ 595{
596 return keyboard_led_stats; 596 return keyboard_led_stats;
597} 597}
598 598
599#define SendToUSB 1
600#define SendToBT 2
601#define SendToBLE 4
602
603static inline uint8_t where_to_send(void) {
604#ifdef ADAFRUIT_BLE_ENABLE
605#if 0
606 if (adafruit_ble_is_connected()) {
607 // For testing, send to BLE as a priority
608 return SendToBLE;
609 }
610#endif
611
612 // This is the real policy
613 if (USB_DeviceState != DEVICE_STATE_Configured) {
614 if (adafruit_ble_is_connected()) {
615 return SendToBLE;
616 }
617 }
618#endif
619 return ((USB_DeviceState == DEVICE_STATE_Configured) ? SendToUSB : 0)
620#ifdef BLUETOOTH_ENABLE
621 || SendToBT
622#endif
623 ;
624}
625
626static void send_keyboard(report_keyboard_t *report) 599static void send_keyboard(report_keyboard_t *report)
627{ 600{
601 uint8_t timeout = 255;
602 uint8_t where = where_to_send();
603
628#ifdef BLUETOOTH_ENABLE 604#ifdef BLUETOOTH_ENABLE
629 bluefruit_serial_send(0xFD); 605 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
630 for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { 606 bluefruit_serial_send(0xFD);
631 bluefruit_serial_send(report->raw[i]); 607 for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) {
608 bluefruit_serial_send(report->raw[i]);
609 }
632 } 610 }
633#endif 611#endif
634 612
635 uint8_t timeout = 255;
636 uint8_t where = where_to_send();
637
638#ifdef ADAFRUIT_BLE_ENABLE 613#ifdef ADAFRUIT_BLE_ENABLE
639 if (where & SendToBLE) { 614 if (where == OUTPUT_ADAFRUIT_BLE) {
640 adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); 615 adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
641 } 616 }
642#endif 617#endif
643 618
644 if (!(where & SendToUSB)) { 619 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
645 return; 620 return;
646 } 621 }
647 622
@@ -681,30 +656,31 @@ static void send_keyboard(report_keyboard_t *report)
681static void send_mouse(report_mouse_t *report) 656static void send_mouse(report_mouse_t *report)
682{ 657{
683#ifdef MOUSE_ENABLE 658#ifdef MOUSE_ENABLE
659 uint8_t timeout = 255;
660 uint8_t where = where_to_send();
684 661
685#ifdef BLUETOOTH_ENABLE 662#ifdef BLUETOOTH_ENABLE
686 bluefruit_serial_send(0xFD); 663 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
687 bluefruit_serial_send(0x00); 664 bluefruit_serial_send(0xFD);
688 bluefruit_serial_send(0x03); 665 bluefruit_serial_send(0x00);
689 bluefruit_serial_send(report->buttons); 666 bluefruit_serial_send(0x03);
690 bluefruit_serial_send(report->x); 667 bluefruit_serial_send(report->buttons);
691 bluefruit_serial_send(report->y); 668 bluefruit_serial_send(report->x);
692 bluefruit_serial_send(report->v); // should try sending the wheel v here 669 bluefruit_serial_send(report->y);
693 bluefruit_serial_send(report->h); // should try sending the wheel h here 670 bluefruit_serial_send(report->v); // should try sending the wheel v here
694 bluefruit_serial_send(0x00); 671 bluefruit_serial_send(report->h); // should try sending the wheel h here
672 bluefruit_serial_send(0x00);
673 }
695#endif 674#endif
696 675
697 uint8_t timeout = 255;
698
699 uint8_t where = where_to_send();
700
701#ifdef ADAFRUIT_BLE_ENABLE 676#ifdef ADAFRUIT_BLE_ENABLE
702 if (where & SendToBLE) { 677 if (where == OUTPUT_ADAFRUIT_BLE) {
703 // FIXME: mouse buttons 678 // FIXME: mouse buttons
704 adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h); 679 adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h);
705 } 680 }
706#endif 681#endif
707 if (!(where & SendToUSB)) { 682
683 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
708 return; 684 return;
709 } 685 }
710 686
@@ -746,32 +722,34 @@ static void send_system(uint16_t data)
746 722
747static void send_consumer(uint16_t data) 723static void send_consumer(uint16_t data)
748{ 724{
725 uint8_t timeout = 255;
726 uint8_t where = where_to_send();
749 727
750#ifdef BLUETOOTH_ENABLE 728#ifdef BLUETOOTH_ENABLE
751 static uint16_t last_data = 0; 729 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
752 if (data == last_data) return; 730 static uint16_t last_data = 0;
753 last_data = data; 731 if (data == last_data) return;
754 uint16_t bitmap = CONSUMER2BLUEFRUIT(data); 732 last_data = data;
755 bluefruit_serial_send(0xFD); 733 uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
756 bluefruit_serial_send(0x00); 734 bluefruit_serial_send(0xFD);
757 bluefruit_serial_send(0x02); 735 bluefruit_serial_send(0x00);
758 bluefruit_serial_send((bitmap>>8)&0xFF); 736 bluefruit_serial_send(0x02);
759 bluefruit_serial_send(bitmap&0xFF); 737 bluefruit_serial_send((bitmap>>8)&0xFF);
760 bluefruit_serial_send(0x00); 738 bluefruit_serial_send(bitmap&0xFF);
761 bluefruit_serial_send(0x00); 739 bluefruit_serial_send(0x00);
762 bluefruit_serial_send(0x00); 740 bluefruit_serial_send(0x00);
763 bluefruit_serial_send(0x00); 741 bluefruit_serial_send(0x00);
742 bluefruit_serial_send(0x00);
743 }
764#endif 744#endif
765 745
766 uint8_t timeout = 255;
767 uint8_t where = where_to_send();
768
769#ifdef ADAFRUIT_BLE_ENABLE 746#ifdef ADAFRUIT_BLE_ENABLE
770 if (where & SendToBLE) { 747 if (where == OUTPUT_ADAFRUIT_BLE) {
771 adafruit_ble_send_consumer_key(data, 0); 748 adafruit_ble_send_consumer_key(data, 0);
772 } 749 }
773#endif 750#endif
774 if (!(where & SendToUSB)) { 751
752 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
775 return; 753 return;
776 } 754 }
777 755
diff --git a/tmk_core/protocol/lufa/outputselect.c b/tmk_core/protocol/lufa/outputselect.c
new file mode 100644
index 000000000..5d2457bff
--- /dev/null
+++ b/tmk_core/protocol/lufa/outputselect.c
@@ -0,0 +1,56 @@
1/*
2Copyright 2017 Priyadi Iman Nurcahyo
3This program is free software: you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation, either version 2 of the License, or
6(at your option) any later version.
7This program is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY; without even the implied warranty of
9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10GNU General Public License for more details.
11You should have received a copy of the GNU General Public License
12along with this program. If not, see <http://www.gnu.org/licenses/>.
13*/
14
15#include "lufa.h"
16#include "outputselect.h"
17#ifdef ADAFRUIT_BLE_ENABLE
18 #include "adafruit_ble.h"
19#endif
20
21uint8_t desired_output = OUTPUT_DEFAULT;
22
23void set_output(uint8_t output) {
24 set_output_user(output);
25 desired_output = output;
26}
27
28__attribute__((weak))
29void set_output_user(uint8_t output) {
30}
31
32uint8_t auto_detect_output(void) {
33 if (USB_DeviceState == DEVICE_STATE_Configured) {
34 return OUTPUT_USB;
35 }
36
37#ifdef ADAFRUIT_BLE_ENABLE
38 if (adafruit_ble_is_connected()) {
39 return OUTPUT_ADAFRUIT_BLE;
40 }
41#endif
42
43#ifdef BLUETOOTH_ENABLE
44 return OUTPUT_BLUETOOTH; // should check if BT is connected here
45#endif
46
47 return OUTPUT_NONE;
48}
49
50uint8_t where_to_send(void) {
51 if (desired_output == OUTPUT_AUTO) {
52 return auto_detect_output();
53 }
54 return desired_output;
55}
56
diff --git a/tmk_core/protocol/lufa/outputselect.h b/tmk_core/protocol/lufa/outputselect.h
new file mode 100644
index 000000000..79b4dd35d
--- /dev/null
+++ b/tmk_core/protocol/lufa/outputselect.h
@@ -0,0 +1,41 @@
1/*
2Copyright 2017 Priyadi Iman Nurcahyo
3This program is free software: you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation, either version 2 of the License, or
6(at your option) any later version.
7This program is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY; without even the implied warranty of
9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10GNU General Public License for more details.
11You should have received a copy of the GNU General Public License
12along with this program. If not, see <http://www.gnu.org/licenses/>.
13*/
14
15enum outputs {
16 OUTPUT_AUTO,
17
18 OUTPUT_NONE,
19 OUTPUT_USB,
20 OUTPUT_BLUETOOTH,
21 OUTPUT_ADAFRUIT_BLE,
22
23 // backward compatibility
24 OUTPUT_USB_AND_BT
25};
26
27/**
28 * backward compatibility for BLUETOOTH_ENABLE, send to BT and USB by default
29 */
30#ifndef OUTPUT_DEFAULT
31 #ifdef BLUETOOTH_ENABLE
32 #define OUTPUT_DEFAULT OUTPUT_USB_AND_BT
33 #else
34 #define OUTPUT_DEFAULT OUTPUT_AUTO
35 #endif
36#endif
37
38void set_output(uint8_t output);
39void set_output_user(uint8_t output);
40uint8_t auto_detect_output(void);
41uint8_t where_to_send(void); \ No newline at end of file