diff options
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 314 |
1 files changed, 205 insertions, 109 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 374add20f..cec004402 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -53,7 +53,6 @@ | |||
| 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" | ||
| 57 | 56 | ||
| 58 | #ifdef NKRO_ENABLE | 57 | #ifdef NKRO_ENABLE |
| 59 | # include "keycode_config.h" | 58 | # include "keycode_config.h" |
| @@ -66,10 +65,11 @@ extern keymap_config_t keymap_config; | |||
| 66 | #endif | 65 | #endif |
| 67 | 66 | ||
| 68 | #ifdef BLUETOOTH_ENABLE | 67 | #ifdef BLUETOOTH_ENABLE |
| 68 | # include "outputselect.h" | ||
| 69 | # ifdef MODULE_ADAFRUIT_BLE | 69 | # ifdef MODULE_ADAFRUIT_BLE |
| 70 | # include "adafruit_ble.h" | 70 | # include "adafruit_ble.h" |
| 71 | # else | 71 | # else |
| 72 | # include "bluetooth.h" | 72 | # include "../serial.h" |
| 73 | # endif | 73 | # endif |
| 74 | #endif | 74 | #endif |
| 75 | 75 | ||
| @@ -85,10 +85,54 @@ extern keymap_config_t keymap_config; | |||
| 85 | # include "raw_hid.h" | 85 | # include "raw_hid.h" |
| 86 | #endif | 86 | #endif |
| 87 | 87 | ||
| 88 | #ifdef JOYSTICK_ENABLE | ||
| 89 | # include "joystick.h" | ||
| 90 | #endif | ||
| 91 | |||
| 92 | // https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734 | ||
| 93 | static inline uint16_t CONSUMER2RN42(uint16_t usage) { | ||
| 94 | switch (usage) { | ||
| 95 | case AC_HOME: | ||
| 96 | return 0x0001; | ||
| 97 | case AL_EMAIL: | ||
| 98 | return 0x0002; | ||
| 99 | case AC_SEARCH: | ||
| 100 | return 0x0004; | ||
| 101 | case AL_KEYBOARD_LAYOUT: | ||
| 102 | return 0x0008; | ||
| 103 | case AUDIO_VOL_UP: | ||
| 104 | return 0x0010; | ||
| 105 | case AUDIO_VOL_DOWN: | ||
| 106 | return 0x0020; | ||
| 107 | case AUDIO_MUTE: | ||
| 108 | return 0x0040; | ||
| 109 | case TRANSPORT_PLAY_PAUSE: | ||
| 110 | return 0x0080; | ||
| 111 | case TRANSPORT_NEXT_TRACK: | ||
| 112 | return 0x0100; | ||
| 113 | case TRANSPORT_PREV_TRACK: | ||
| 114 | return 0x0200; | ||
| 115 | case TRANSPORT_STOP: | ||
| 116 | return 0x0400; | ||
| 117 | case TRANSPORT_EJECT: | ||
| 118 | return 0x0800; | ||
| 119 | case TRANSPORT_FAST_FORWARD: | ||
| 120 | return 0x1000; | ||
| 121 | case TRANSPORT_REWIND: | ||
| 122 | return 0x2000; | ||
| 123 | case TRANSPORT_STOP_EJECT: | ||
| 124 | return 0x4000; | ||
| 125 | case AL_LOCAL_BROWSER: | ||
| 126 | return 0x8000; | ||
| 127 | default: | ||
| 128 | return 0; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 88 | uint8_t keyboard_idle = 0; | 132 | uint8_t keyboard_idle = 0; |
| 89 | /* 0: Boot Protocol, 1: Report Protocol(default) */ | 133 | /* 0: Boot Protocol, 1: Report Protocol(default) */ |
| 90 | uint8_t keyboard_protocol = 1; | 134 | uint8_t keyboard_protocol = 1; |
| 91 | static uint8_t keyboard_led_stats = 0; | 135 | static uint8_t keyboard_led_state = 0; |
| 92 | 136 | ||
| 93 | static report_keyboard_t keyboard_report_sent; | 137 | static report_keyboard_t keyboard_report_sent; |
| 94 | 138 | ||
| @@ -103,30 +147,30 @@ host_driver_t lufa_driver = { | |||
| 103 | }; | 147 | }; |
| 104 | 148 | ||
| 105 | #ifdef VIRTSER_ENABLE | 149 | #ifdef VIRTSER_ENABLE |
| 150 | // clang-format off | ||
| 151 | |||
| 106 | USB_ClassInfo_CDC_Device_t cdc_device = { | 152 | USB_ClassInfo_CDC_Device_t cdc_device = { |
| 107 | .Config = | 153 | .Config = { |
| 108 | { | 154 | .ControlInterfaceNumber = CCI_INTERFACE, |
| 109 | .ControlInterfaceNumber = CCI_INTERFACE, | 155 | .DataINEndpoint = { |
| 110 | .DataINEndpoint = | 156 | .Address = (CDC_IN_EPNUM | ENDPOINT_DIR_IN), |
| 111 | { | 157 | .Size = CDC_EPSIZE, |
| 112 | .Address = CDC_IN_EPADDR, | 158 | .Banks = 1 |
| 113 | .Size = CDC_EPSIZE, | ||
| 114 | .Banks = 1, | ||
| 115 | }, | ||
| 116 | .DataOUTEndpoint = | ||
| 117 | { | ||
| 118 | .Address = CDC_OUT_EPADDR, | ||
| 119 | .Size = CDC_EPSIZE, | ||
| 120 | .Banks = 1, | ||
| 121 | }, | ||
| 122 | .NotificationEndpoint = | ||
| 123 | { | ||
| 124 | .Address = CDC_NOTIFICATION_EPADDR, | ||
| 125 | .Size = CDC_NOTIFICATION_EPSIZE, | ||
| 126 | .Banks = 1, | ||
| 127 | }, | ||
| 128 | }, | 159 | }, |
| 160 | .DataOUTEndpoint = { | ||
| 161 | .Address = (CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), | ||
| 162 | .Size = CDC_EPSIZE, | ||
| 163 | .Banks = 1 | ||
| 164 | }, | ||
| 165 | .NotificationEndpoint = { | ||
| 166 | .Address = (CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), | ||
| 167 | .Size = CDC_NOTIFICATION_EPSIZE, | ||
| 168 | .Banks = 1 | ||
| 169 | } | ||
| 170 | } | ||
| 129 | }; | 171 | }; |
| 172 | |||
| 173 | // clang-format on | ||
| 130 | #endif | 174 | #endif |
| 131 | 175 | ||
| 132 | #ifdef RAW_ENABLE | 176 | #ifdef RAW_ENABLE |
| @@ -254,7 +298,7 @@ static void Console_Task(void) { | |||
| 254 | // fill empty bank | 298 | // fill empty bank |
| 255 | while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0); | 299 | while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0); |
| 256 | 300 | ||
| 257 | // flash senchar packet | 301 | // flush sendchar packet |
| 258 | if (Endpoint_IsINReady()) { | 302 | if (Endpoint_IsINReady()) { |
| 259 | Endpoint_ClearIN(); | 303 | Endpoint_ClearIN(); |
| 260 | } | 304 | } |
| @@ -264,6 +308,70 @@ static void Console_Task(void) { | |||
| 264 | #endif | 308 | #endif |
| 265 | 309 | ||
| 266 | /******************************************************************************* | 310 | /******************************************************************************* |
| 311 | * Joystick | ||
| 312 | ******************************************************************************/ | ||
| 313 | #ifdef JOYSTICK_ENABLE | ||
| 314 | void send_joystick_packet(joystick_t *joystick) { | ||
| 315 | uint8_t timeout = 255; | ||
| 316 | |||
| 317 | joystick_report_t r = { | ||
| 318 | # if JOYSTICK_AXES_COUNT > 0 | ||
| 319 | .axes = | ||
| 320 | { | ||
| 321 | joystick->axes[0], | ||
| 322 | |||
| 323 | # if JOYSTICK_AXES_COUNT >= 2 | ||
| 324 | joystick->axes[1], | ||
| 325 | # endif | ||
| 326 | # if JOYSTICK_AXES_COUNT >= 3 | ||
| 327 | joystick->axes[2], | ||
| 328 | # endif | ||
| 329 | # if JOYSTICK_AXES_COUNT >= 4 | ||
| 330 | joystick->axes[3], | ||
| 331 | # endif | ||
| 332 | # if JOYSTICK_AXES_COUNT >= 5 | ||
| 333 | joystick->axes[4], | ||
| 334 | # endif | ||
| 335 | # if JOYSTICK_AXES_COUNT >= 6 | ||
| 336 | joystick->axes[5], | ||
| 337 | # endif | ||
| 338 | }, | ||
| 339 | # endif // JOYSTICK_AXES_COUNT>0 | ||
| 340 | |||
| 341 | # if JOYSTICK_BUTTON_COUNT > 0 | ||
| 342 | .buttons = | ||
| 343 | { | ||
| 344 | joystick->buttons[0], | ||
| 345 | |||
| 346 | # if JOYSTICK_BUTTON_COUNT > 8 | ||
| 347 | joystick->buttons[1], | ||
| 348 | # endif | ||
| 349 | # if JOYSTICK_BUTTON_COUNT > 16 | ||
| 350 | joystick->buttons[2], | ||
| 351 | # endif | ||
| 352 | # if JOYSTICK_BUTTON_COUNT > 24 | ||
| 353 | joystick->buttons[3], | ||
| 354 | # endif | ||
| 355 | } | ||
| 356 | # endif // JOYSTICK_BUTTON_COUNT>0 | ||
| 357 | }; | ||
| 358 | |||
| 359 | /* Select the Joystick Report Endpoint */ | ||
| 360 | Endpoint_SelectEndpoint(JOYSTICK_IN_EPNUM); | ||
| 361 | |||
| 362 | /* Check if write ready for a polling interval around 10ms */ | ||
| 363 | while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); | ||
| 364 | if (!Endpoint_IsReadWriteAllowed()) return; | ||
| 365 | |||
| 366 | /* Write Joystick Report Data */ | ||
| 367 | Endpoint_Write_Stream_LE(&r, sizeof(joystick_report_t), NULL); | ||
| 368 | |||
| 369 | /* Finalize the stream transfer to send the last packet */ | ||
| 370 | Endpoint_ClearIN(); | ||
| 371 | } | ||
| 372 | #endif | ||
| 373 | |||
| 374 | /******************************************************************************* | ||
| 267 | * USB Events | 375 | * USB Events |
| 268 | ******************************************************************************/ | 376 | ******************************************************************************/ |
| 269 | /* | 377 | /* |
| @@ -370,45 +478,51 @@ void EVENT_USB_Device_StartOfFrame(void) { | |||
| 370 | void EVENT_USB_Device_ConfigurationChanged(void) { | 478 | void EVENT_USB_Device_ConfigurationChanged(void) { |
| 371 | bool ConfigSuccess = true; | 479 | bool ConfigSuccess = true; |
| 372 | 480 | ||
| 373 | /* Setup Keyboard HID Report Endpoints */ | ||
| 374 | #ifndef KEYBOARD_SHARED_EP | 481 | #ifndef KEYBOARD_SHARED_EP |
| 375 | ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE); | 482 | /* Setup keyboard report endpoint */ |
| 483 | ConfigSuccess &= Endpoint_ConfigureEndpoint((KEYBOARD_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1); | ||
| 376 | #endif | 484 | #endif |
| 377 | 485 | ||
| 378 | #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP) | 486 | #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP) |
| 379 | /* Setup Mouse HID Report Endpoint */ | 487 | /* Setup mouse report endpoint */ |
| 380 | ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); | 488 | ConfigSuccess &= Endpoint_ConfigureEndpoint((MOUSE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1); |
| 381 | #endif | 489 | #endif |
| 382 | 490 | ||
| 383 | #ifdef SHARED_EP_ENABLE | 491 | #ifdef SHARED_EP_ENABLE |
| 384 | /* Setup Shared HID Report Endpoint */ | 492 | /* Setup shared report endpoint */ |
| 385 | ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE); | 493 | ConfigSuccess &= Endpoint_ConfigureEndpoint((SHARED_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, SHARED_EPSIZE, 1); |
| 386 | #endif | 494 | #endif |
| 387 | 495 | ||
| 388 | #ifdef RAW_ENABLE | 496 | #ifdef RAW_ENABLE |
| 389 | /* Setup Raw HID Report Endpoints */ | 497 | /* Setup raw HID endpoints */ |
| 390 | ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE); | 498 | ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1); |
| 391 | ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE); | 499 | ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1); |
| 392 | #endif | 500 | #endif |
| 393 | 501 | ||
| 394 | #ifdef CONSOLE_ENABLE | 502 | #ifdef CONSOLE_ENABLE |
| 395 | /* Setup Console HID Report Endpoints */ | 503 | /* Setup console endpoint */ |
| 396 | ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | 504 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1); |
| 397 | # if 0 | 505 | # if 0 |
| 398 | ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | 506 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1); |
| 399 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 400 | # endif | 507 | # endif |
| 401 | #endif | 508 | #endif |
| 402 | 509 | ||
| 403 | #ifdef MIDI_ENABLE | 510 | #ifdef MIDI_ENABLE |
| 404 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); | 511 | /* Setup MIDI stream endpoints */ |
| 405 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); | 512 | ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1); |
| 513 | ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1); | ||
| 406 | #endif | 514 | #endif |
| 407 | 515 | ||
| 408 | #ifdef VIRTSER_ENABLE | 516 | #ifdef VIRTSER_ENABLE |
| 409 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); | 517 | /* Setup virtual serial endpoints */ |
| 410 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); | 518 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1); |
| 411 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); | 519 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_BULK, CDC_EPSIZE, 1); |
| 520 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1); | ||
| 521 | #endif | ||
| 522 | |||
| 523 | #ifdef JOYSTICK_ENABLE | ||
| 524 | /* Setup joystick endpoint */ | ||
| 525 | ConfigSuccess &= Endpoint_ConfigureEndpoint((JOYSTICK_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1); | ||
| 412 | #endif | 526 | #endif |
| 413 | } | 527 | } |
| 414 | 528 | ||
| @@ -472,10 +586,10 @@ void EVENT_USB_Device_ControlRequest(void) { | |||
| 472 | uint8_t report_id = Endpoint_Read_8(); | 586 | uint8_t report_id = Endpoint_Read_8(); |
| 473 | 587 | ||
| 474 | if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { | 588 | if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { |
| 475 | keyboard_led_stats = Endpoint_Read_8(); | 589 | keyboard_led_state = Endpoint_Read_8(); |
| 476 | } | 590 | } |
| 477 | } else { | 591 | } else { |
| 478 | keyboard_led_stats = Endpoint_Read_8(); | 592 | keyboard_led_state = Endpoint_Read_8(); |
| 479 | } | 593 | } |
| 480 | 594 | ||
| 481 | Endpoint_ClearOUT(); | 595 | Endpoint_ClearOUT(); |
| @@ -545,7 +659,7 @@ void EVENT_USB_Device_ControlRequest(void) { | |||
| 545 | * | 659 | * |
| 546 | * FIXME: Needs doc | 660 | * FIXME: Needs doc |
| 547 | */ | 661 | */ |
| 548 | static uint8_t keyboard_leds(void) { return keyboard_led_stats; } | 662 | static uint8_t keyboard_leds(void) { return keyboard_led_state; } |
| 549 | 663 | ||
| 550 | /** \brief Send Keyboard | 664 | /** \brief Send Keyboard |
| 551 | * | 665 | * |
| @@ -553,35 +667,29 @@ static uint8_t keyboard_leds(void) { return keyboard_led_stats; } | |||
| 553 | */ | 667 | */ |
| 554 | static void send_keyboard(report_keyboard_t *report) { | 668 | static void send_keyboard(report_keyboard_t *report) { |
| 555 | uint8_t timeout = 255; | 669 | uint8_t timeout = 255; |
| 556 | uint8_t where = where_to_send(); | ||
| 557 | 670 | ||
| 558 | #ifdef BLUETOOTH_ENABLE | 671 | #ifdef BLUETOOTH_ENABLE |
| 672 | uint8_t where = where_to_send(); | ||
| 673 | |||
| 559 | if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { | 674 | if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { |
| 560 | # ifdef MODULE_ADAFRUIT_BLE | 675 | # ifdef MODULE_ADAFRUIT_BLE |
| 561 | adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); | 676 | adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); |
| 562 | # elif MODULE_RN42 | 677 | # elif MODULE_RN42 |
| 563 | bluefruit_serial_send(0xFD); | 678 | serial_send(0xFD); |
| 564 | bluefruit_serial_send(0x09); | 679 | serial_send(0x09); |
| 565 | bluefruit_serial_send(0x01); | 680 | serial_send(0x01); |
| 566 | bluefruit_serial_send(report->mods); | 681 | serial_send(report->mods); |
| 567 | bluefruit_serial_send(report->reserved); | 682 | serial_send(report->reserved); |
| 568 | for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { | ||
| 569 | bluefruit_serial_send(report->keys[i]); | ||
| 570 | } | ||
| 571 | # else | ||
| 572 | bluefruit_serial_send(0xFD); | ||
| 573 | bluefruit_serial_send(report->mods); | ||
| 574 | bluefruit_serial_send(report->reserved); | ||
| 575 | for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { | 683 | for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { |
| 576 | bluefruit_serial_send(report->keys[i]); | 684 | serial_send(report->keys[i]); |
| 577 | } | 685 | } |
| 578 | # endif | 686 | # endif |
| 579 | } | 687 | } |
| 580 | #endif | ||
| 581 | 688 | ||
| 582 | if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { | 689 | if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { |
| 583 | return; | 690 | return; |
| 584 | } | 691 | } |
| 692 | #endif | ||
| 585 | 693 | ||
| 586 | /* Select the Keyboard Report Endpoint */ | 694 | /* Select the Keyboard Report Endpoint */ |
| 587 | uint8_t ep = KEYBOARD_IN_EPNUM; | 695 | uint8_t ep = KEYBOARD_IN_EPNUM; |
| @@ -617,30 +725,31 @@ static void send_keyboard(report_keyboard_t *report) { | |||
| 617 | static void send_mouse(report_mouse_t *report) { | 725 | static void send_mouse(report_mouse_t *report) { |
| 618 | #ifdef MOUSE_ENABLE | 726 | #ifdef MOUSE_ENABLE |
| 619 | uint8_t timeout = 255; | 727 | uint8_t timeout = 255; |
| 620 | uint8_t where = where_to_send(); | ||
| 621 | 728 | ||
| 622 | # ifdef BLUETOOTH_ENABLE | 729 | # ifdef BLUETOOTH_ENABLE |
| 730 | uint8_t where = where_to_send(); | ||
| 731 | |||
| 623 | if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { | 732 | if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { |
| 624 | # ifdef MODULE_ADAFRUIT_BLE | 733 | # ifdef MODULE_ADAFRUIT_BLE |
| 625 | // FIXME: mouse buttons | 734 | // FIXME: mouse buttons |
| 626 | adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); | 735 | adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); |
| 627 | # else | 736 | # else |
| 628 | bluefruit_serial_send(0xFD); | 737 | serial_send(0xFD); |
| 629 | bluefruit_serial_send(0x00); | 738 | serial_send(0x00); |
| 630 | bluefruit_serial_send(0x03); | 739 | serial_send(0x03); |
| 631 | bluefruit_serial_send(report->buttons); | 740 | serial_send(report->buttons); |
| 632 | bluefruit_serial_send(report->x); | 741 | serial_send(report->x); |
| 633 | bluefruit_serial_send(report->y); | 742 | serial_send(report->y); |
| 634 | bluefruit_serial_send(report->v); // should try sending the wheel v here | 743 | serial_send(report->v); // should try sending the wheel v here |
| 635 | bluefruit_serial_send(report->h); // should try sending the wheel h here | 744 | serial_send(report->h); // should try sending the wheel h here |
| 636 | bluefruit_serial_send(0x00); | 745 | serial_send(0x00); |
| 637 | # endif | 746 | # endif |
| 638 | } | 747 | } |
| 639 | # endif | ||
| 640 | 748 | ||
| 641 | if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { | 749 | if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { |
| 642 | return; | 750 | return; |
| 643 | } | 751 | } |
| 752 | # endif | ||
| 644 | 753 | ||
| 645 | /* Select the Mouse Report Endpoint */ | 754 | /* Select the Mouse Report Endpoint */ |
| 646 | Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); | 755 | Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); |
| @@ -695,9 +804,9 @@ static void send_system(uint16_t data) { | |||
| 695 | */ | 804 | */ |
| 696 | static void send_consumer(uint16_t data) { | 805 | static void send_consumer(uint16_t data) { |
| 697 | #ifdef EXTRAKEY_ENABLE | 806 | #ifdef EXTRAKEY_ENABLE |
| 807 | # ifdef BLUETOOTH_ENABLE | ||
| 698 | uint8_t where = where_to_send(); | 808 | uint8_t where = where_to_send(); |
| 699 | 809 | ||
| 700 | # ifdef BLUETOOTH_ENABLE | ||
| 701 | if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { | 810 | if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { |
| 702 | # ifdef MODULE_ADAFRUIT_BLE | 811 | # ifdef MODULE_ADAFRUIT_BLE |
| 703 | adafruit_ble_send_consumer_key(data, 0); | 812 | adafruit_ble_send_consumer_key(data, 0); |
| @@ -706,32 +815,18 @@ static void send_consumer(uint16_t data) { | |||
| 706 | if (data == last_data) return; | 815 | if (data == last_data) return; |
| 707 | last_data = data; | 816 | last_data = data; |
| 708 | uint16_t bitmap = CONSUMER2RN42(data); | 817 | uint16_t bitmap = CONSUMER2RN42(data); |
| 709 | bluefruit_serial_send(0xFD); | 818 | serial_send(0xFD); |
| 710 | bluefruit_serial_send(0x03); | 819 | serial_send(0x03); |
| 711 | bluefruit_serial_send(0x03); | 820 | serial_send(0x03); |
| 712 | bluefruit_serial_send(bitmap & 0xFF); | 821 | serial_send(bitmap & 0xFF); |
| 713 | bluefruit_serial_send((bitmap >> 8) & 0xFF); | 822 | serial_send((bitmap >> 8) & 0xFF); |
| 714 | # else | ||
| 715 | static uint16_t last_data = 0; | ||
| 716 | if (data == last_data) return; | ||
| 717 | last_data = data; | ||
| 718 | uint16_t bitmap = CONSUMER2BLUEFRUIT(data); | ||
| 719 | bluefruit_serial_send(0xFD); | ||
| 720 | bluefruit_serial_send(0x00); | ||
| 721 | bluefruit_serial_send(0x02); | ||
| 722 | bluefruit_serial_send((bitmap >> 8) & 0xFF); | ||
| 723 | bluefruit_serial_send(bitmap & 0xFF); | ||
| 724 | bluefruit_serial_send(0x00); | ||
| 725 | bluefruit_serial_send(0x00); | ||
| 726 | bluefruit_serial_send(0x00); | ||
| 727 | bluefruit_serial_send(0x00); | ||
| 728 | # endif | 823 | # endif |
| 729 | } | 824 | } |
| 730 | # endif | ||
| 731 | 825 | ||
| 732 | if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { | 826 | if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { |
| 733 | return; | 827 | return; |
| 734 | } | 828 | } |
| 829 | # endif | ||
| 735 | 830 | ||
| 736 | send_extra(REPORT_ID_CONSUMER, data); | 831 | send_extra(REPORT_ID_CONSUMER, data); |
| 737 | #endif | 832 | #endif |
| @@ -808,25 +903,26 @@ ERROR_EXIT: | |||
| 808 | ******************************************************************************/ | 903 | ******************************************************************************/ |
| 809 | 904 | ||
| 810 | #ifdef MIDI_ENABLE | 905 | #ifdef MIDI_ENABLE |
| 906 | // clang-format off | ||
| 907 | |||
| 811 | USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = { | 908 | USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = { |
| 812 | .Config = | 909 | .Config = { |
| 813 | { | 910 | .StreamingInterfaceNumber = AS_INTERFACE, |
| 814 | .StreamingInterfaceNumber = AS_INTERFACE, | 911 | .DataINEndpoint = { |
| 815 | .DataINEndpoint = | 912 | .Address = (MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), |
| 816 | { | 913 | .Size = MIDI_STREAM_EPSIZE, |
| 817 | .Address = MIDI_STREAM_IN_EPADDR, | 914 | .Banks = 1 |
| 818 | .Size = MIDI_STREAM_EPSIZE, | ||
| 819 | .Banks = 1, | ||
| 820 | }, | ||
| 821 | .DataOUTEndpoint = | ||
| 822 | { | ||
| 823 | .Address = MIDI_STREAM_OUT_EPADDR, | ||
| 824 | .Size = MIDI_STREAM_EPSIZE, | ||
| 825 | .Banks = 1, | ||
| 826 | }, | ||
| 827 | }, | 915 | }, |
| 916 | .DataOUTEndpoint = { | ||
| 917 | .Address = (MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_OUT), | ||
| 918 | .Size = MIDI_STREAM_EPSIZE, | ||
| 919 | .Banks = 1 | ||
| 920 | } | ||
| 921 | } | ||
| 828 | }; | 922 | }; |
| 829 | 923 | ||
| 924 | // clang-format on | ||
| 925 | |||
| 830 | void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); } | 926 | void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); } |
| 831 | 927 | ||
| 832 | bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); } | 928 | bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); } |
| @@ -945,7 +1041,7 @@ int main(void) { | |||
| 945 | setup_usb(); | 1041 | setup_usb(); |
| 946 | sei(); | 1042 | sei(); |
| 947 | 1043 | ||
| 948 | #if defined(MODULE_ADAFRUIT_EZKEY) || defined(MODULE_RN42) | 1044 | #if defined(MODULE_RN42) |
| 949 | serial_init(); | 1045 | serial_init(); |
| 950 | #endif | 1046 | #endif |
| 951 | 1047 | ||
