diff options
| author | Priyadi Iman Nurcahyo <priyadi@priyadi.net> | 2017-02-01 05:07:05 +0700 |
|---|---|---|
| committer | Priyadi Iman Nurcahyo <priyadi@priyadi.net> | 2017-02-01 05:07:05 +0700 |
| commit | d8a9c63c265869822a77ad5c5cb7c8dfa4ff1f6c (patch) | |
| tree | aef00ec84122c366bfc0e70e7d3190976380685b /tmk_core/protocol/lufa/lufa.c | |
| parent | ec05f654210a01ef82db2ab54e6065783536b802 (diff) | |
| download | qmk_firmware-d8a9c63c265869822a77ad5c5cb7c8dfa4ff1f6c.tar.gz qmk_firmware-d8a9c63c265869822a77ad5c5cb7c8dfa4ff1f6c.zip | |
Implement runtime selectable output (USB or BT)
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 116 |
1 files changed, 47 insertions, 69 deletions
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 |
| 592 | p | ||
| 593 | ******************************************************************************/ | 593 | ******************************************************************************/ |
| 594 | static uint8_t keyboard_leds(void) | 594 | static 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 | |||
| 603 | static 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 | |||
| 626 | static void send_keyboard(report_keyboard_t *report) | 599 | static 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) | |||
| 681 | static void send_mouse(report_mouse_t *report) | 656 | static 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 | ||
| 747 | static void send_consumer(uint16_t data) | 723 | static 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 | ||
