diff options
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 82 |
1 files changed, 71 insertions, 11 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 39d4824b6..ee2552c19 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -52,6 +52,7 @@ | |||
| 52 | #include "descriptor.h" | 52 | #include "descriptor.h" |
| 53 | #include "lufa.h" | 53 | #include "lufa.h" |
| 54 | #include "quantum.h" | 54 | #include "quantum.h" |
| 55 | #include <util/atomic.h> | ||
| 55 | 56 | ||
| 56 | #ifdef NKRO_ENABLE | 57 | #ifdef NKRO_ENABLE |
| 57 | #include "keycode_config.h" | 58 | #include "keycode_config.h" |
| @@ -67,13 +68,16 @@ | |||
| 67 | #ifdef BLUETOOTH_ENABLE | 68 | #ifdef BLUETOOTH_ENABLE |
| 68 | #include "bluetooth.h" | 69 | #include "bluetooth.h" |
| 69 | #endif | 70 | #endif |
| 71 | #ifdef ADAFRUIT_BLE_ENABLE | ||
| 72 | #include "adafruit_ble.h" | ||
| 73 | #endif | ||
| 70 | 74 | ||
| 71 | #ifdef VIRTSER_ENABLE | 75 | #ifdef VIRTSER_ENABLE |
| 72 | #include "virtser.h" | 76 | #include "virtser.h" |
| 73 | #endif | 77 | #endif |
| 74 | 78 | ||
| 75 | #if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE) | 79 | #if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE) |
| 76 | #include "rgblight.h" | 80 | #include "rgblight.h" |
| 77 | #endif | 81 | #endif |
| 78 | 82 | ||
| 79 | #ifdef MIDI_ENABLE | 83 | #ifdef MIDI_ENABLE |
| @@ -297,7 +301,9 @@ void EVENT_USB_Device_WakeUp() | |||
| 297 | #ifdef CONSOLE_ENABLE | 301 | #ifdef CONSOLE_ENABLE |
| 298 | static bool console_flush = false; | 302 | static bool console_flush = false; |
| 299 | #define CONSOLE_FLUSH_SET(b) do { \ | 303 | #define CONSOLE_FLUSH_SET(b) do { \ |
| 300 | uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \ | 304 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\ |
| 305 | console_flush = b; \ | ||
| 306 | } \ | ||
| 301 | } while (0) | 307 | } while (0) |
| 302 | 308 | ||
| 303 | // called every 1ms | 309 | // called every 1ms |
| @@ -501,9 +507,35 @@ static uint8_t keyboard_leds(void) | |||
| 501 | return keyboard_led_stats; | 507 | return keyboard_led_stats; |
| 502 | } | 508 | } |
| 503 | 509 | ||
| 510 | #define SendToUSB 1 | ||
| 511 | #define SendToBT 2 | ||
| 512 | #define SendToBLE 4 | ||
| 513 | |||
| 514 | static inline uint8_t where_to_send(void) { | ||
| 515 | #ifdef ADAFRUIT_BLE_ENABLE | ||
| 516 | #if 0 | ||
| 517 | if (adafruit_ble_is_connected()) { | ||
| 518 | // For testing, send to BLE as a priority | ||
| 519 | return SendToBLE; | ||
| 520 | } | ||
| 521 | #endif | ||
| 522 | |||
| 523 | // This is the real policy | ||
| 524 | if (USB_DeviceState != DEVICE_STATE_Configured) { | ||
| 525 | if (adafruit_ble_is_connected()) { | ||
| 526 | return SendToBLE; | ||
| 527 | } | ||
| 528 | } | ||
| 529 | #endif | ||
| 530 | return ((USB_DeviceState == DEVICE_STATE_Configured) ? SendToUSB : 0) | ||
| 531 | #ifdef BLUETOOTH_ENABLE | ||
| 532 | || SendToBT | ||
| 533 | #endif | ||
| 534 | ; | ||
| 535 | } | ||
| 536 | |||
| 504 | static void send_keyboard(report_keyboard_t *report) | 537 | static void send_keyboard(report_keyboard_t *report) |
| 505 | { | 538 | { |
| 506 | |||
| 507 | #ifdef BLUETOOTH_ENABLE | 539 | #ifdef BLUETOOTH_ENABLE |
| 508 | bluefruit_serial_send(0xFD); | 540 | bluefruit_serial_send(0xFD); |
| 509 | for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { | 541 | for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { |
| @@ -512,9 +544,17 @@ static void send_keyboard(report_keyboard_t *report) | |||
| 512 | #endif | 544 | #endif |
| 513 | 545 | ||
| 514 | uint8_t timeout = 255; | 546 | uint8_t timeout = 255; |
| 547 | uint8_t where = where_to_send(); | ||
| 515 | 548 | ||
| 516 | if (USB_DeviceState != DEVICE_STATE_Configured) | 549 | #ifdef ADAFRUIT_BLE_ENABLE |
| 517 | return; | 550 | if (where & SendToBLE) { |
| 551 | adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); | ||
| 552 | } | ||
| 553 | #endif | ||
| 554 | |||
| 555 | if (!(where & SendToUSB)) { | ||
| 556 | return; | ||
| 557 | } | ||
| 518 | 558 | ||
| 519 | /* Select the Keyboard Report Endpoint */ | 559 | /* Select the Keyboard Report Endpoint */ |
| 520 | #ifdef NKRO_ENABLE | 560 | #ifdef NKRO_ENABLE |
| @@ -567,8 +607,17 @@ static void send_mouse(report_mouse_t *report) | |||
| 567 | 607 | ||
| 568 | uint8_t timeout = 255; | 608 | uint8_t timeout = 255; |
| 569 | 609 | ||
| 570 | if (USB_DeviceState != DEVICE_STATE_Configured) | 610 | uint8_t where = where_to_send(); |
| 571 | return; | 611 | |
| 612 | #ifdef ADAFRUIT_BLE_ENABLE | ||
| 613 | if (where & SendToBLE) { | ||
| 614 | // FIXME: mouse buttons | ||
| 615 | adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h); | ||
| 616 | } | ||
| 617 | #endif | ||
| 618 | if (!(where & SendToUSB)) { | ||
| 619 | return; | ||
| 620 | } | ||
| 572 | 621 | ||
| 573 | /* Select the Mouse Report Endpoint */ | 622 | /* Select the Mouse Report Endpoint */ |
| 574 | Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); | 623 | Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); |
| @@ -626,9 +675,16 @@ static void send_consumer(uint16_t data) | |||
| 626 | #endif | 675 | #endif |
| 627 | 676 | ||
| 628 | uint8_t timeout = 255; | 677 | uint8_t timeout = 255; |
| 678 | uint8_t where = where_to_send(); | ||
| 629 | 679 | ||
| 630 | if (USB_DeviceState != DEVICE_STATE_Configured) | 680 | #ifdef ADAFRUIT_BLE_ENABLE |
| 631 | return; | 681 | if (where & SendToBLE) { |
| 682 | adafruit_ble_send_consumer_key(data, 0); | ||
| 683 | } | ||
| 684 | #endif | ||
| 685 | if (!(where & SendToUSB)) { | ||
| 686 | return; | ||
| 687 | } | ||
| 632 | 688 | ||
| 633 | report_extra_t r = { | 689 | report_extra_t r = { |
| 634 | .report_id = REPORT_ID_CONSUMER, | 690 | .report_id = REPORT_ID_CONSUMER, |
| @@ -1038,7 +1094,7 @@ int main(void) | |||
| 1038 | 1094 | ||
| 1039 | print("Keyboard start.\n"); | 1095 | print("Keyboard start.\n"); |
| 1040 | while (1) { | 1096 | while (1) { |
| 1041 | #ifndef BLUETOOTH_ENABLE | 1097 | #if !defined(BLUETOOTH_ENABLE) && !defined(ADAFRUIT_BLE_ENABLE) |
| 1042 | while (USB_DeviceState == DEVICE_STATE_Suspended) { | 1098 | while (USB_DeviceState == DEVICE_STATE_Suspended) { |
| 1043 | print("[s]"); | 1099 | print("[s]"); |
| 1044 | suspend_power_down(); | 1100 | suspend_power_down(); |
| @@ -1054,11 +1110,15 @@ int main(void) | |||
| 1054 | midi_device_process(&midi_device); | 1110 | midi_device_process(&midi_device); |
| 1055 | // MIDI_Task(); | 1111 | // MIDI_Task(); |
| 1056 | #endif | 1112 | #endif |
| 1057 | 1113 | ||
| 1058 | #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) | 1114 | #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) |
| 1059 | rgblight_task(); | 1115 | rgblight_task(); |
| 1060 | #endif | 1116 | #endif |
| 1061 | 1117 | ||
| 1118 | #ifdef ADAFRUIT_BLE_ENABLE | ||
| 1119 | adafruit_ble_task(); | ||
| 1120 | #endif | ||
| 1121 | |||
| 1062 | #ifdef VIRTSER_ENABLE | 1122 | #ifdef VIRTSER_ENABLE |
| 1063 | virtser_task(); | 1123 | virtser_task(); |
| 1064 | CDC_Device_USBTask(&cdc_device); | 1124 | CDC_Device_USBTask(&cdc_device); |
