diff options
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/lufa.mk | 5 | ||||
| -rw-r--r-- | protocol/lufa/bluetooth.c | 37 | ||||
| -rw-r--r-- | protocol/lufa/bluetooth.h | 63 | ||||
| -rw-r--r-- | protocol/lufa/lufa.c | 51 | ||||
| -rw-r--r-- | protocol/lufa/lufa.h | 2 |
5 files changed, 155 insertions, 3 deletions
diff --git a/protocol/lufa.mk b/protocol/lufa.mk index 5dbb74ffc..958c37516 100644 --- a/protocol/lufa.mk +++ b/protocol/lufa.mk | |||
| @@ -29,6 +29,11 @@ ifdef MIDI_ENABLE | |||
| 29 | $(LUFA_SRC_USBCLASS) | 29 | $(LUFA_SRC_USBCLASS) |
| 30 | endif | 30 | endif |
| 31 | 31 | ||
| 32 | ifdef BLUETOOTH_ENABLE | ||
| 33 | LUFA_SRC += $(LUFA_DIR)/bluetooth.c \ | ||
| 34 | $(LUFA_DIR)/../serial_uart.c | ||
| 35 | endif | ||
| 36 | |||
| 32 | SRC += $(LUFA_SRC) | 37 | SRC += $(LUFA_SRC) |
| 33 | 38 | ||
| 34 | # Search Path | 39 | # Search Path |
diff --git a/protocol/lufa/bluetooth.c b/protocol/lufa/bluetooth.c new file mode 100644 index 000000000..ed66e52c1 --- /dev/null +++ b/protocol/lufa/bluetooth.c | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* | ||
| 2 | Bluefruit Protocol for TMK firmware | ||
| 3 | Author: Benjamin Gould, 2013 | ||
| 4 | Jack Humbert, 2015 | ||
| 5 | Based on code Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 6 | This program is free software: you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation, either version 2 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include "report.h" | ||
| 20 | #include "print.h" | ||
| 21 | #include "debug.h" | ||
| 22 | #include "../serial.h" | ||
| 23 | #include "bluetooth.h" | ||
| 24 | |||
| 25 | void bluefruit_keyboard_print_report(report_keyboard_t *report) | ||
| 26 | { | ||
| 27 | if (!debug_keyboard) return; | ||
| 28 | dprintf("keys: "); for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { debug_hex8(report->keys[i]); dprintf(" "); } | ||
| 29 | dprintf(" mods: "); debug_hex8(report->mods); | ||
| 30 | dprintf(" reserved: "); debug_hex8(report->reserved); | ||
| 31 | dprintf("\n"); | ||
| 32 | } | ||
| 33 | |||
| 34 | void bluefruit_serial_send(uint8_t data) | ||
| 35 | { | ||
| 36 | serial_send(data); | ||
| 37 | } \ No newline at end of file | ||
diff --git a/protocol/lufa/bluetooth.h b/protocol/lufa/bluetooth.h new file mode 100644 index 000000000..01f07e8e6 --- /dev/null +++ b/protocol/lufa/bluetooth.h | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /* | ||
| 2 | Bluefruit Protocol for TMK firmware | ||
| 3 | Author: Benjamin Gould, 2013 | ||
| 4 | Jack Humbert, 2015 | ||
| 5 | Based on code Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 6 | This program is free software: you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation, either version 2 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef BLUETOOTH_H | ||
| 19 | #define BLUETOOTH_H | ||
| 20 | |||
| 21 | void bluefruit_serial_send(uint8_t data); | ||
| 22 | |||
| 23 | /* | ||
| 24 | +-----------------+-------------------+-------+ | ||
| 25 | | Consumer Key | Bit Map | Hex | | ||
| 26 | +-----------------+-------------------+-------+ | ||
| 27 | | Home | 00000001 00000000 | 01 00 | | ||
| 28 | | KeyboardLayout | 00000010 00000000 | 02 00 | | ||
| 29 | | Search | 00000100 00000000 | 04 00 | | ||
| 30 | | Snapshot | 00001000 00000000 | 08 00 | | ||
| 31 | | VolumeUp | 00010000 00000000 | 10 00 | | ||
| 32 | | VolumeDown | 00100000 00000000 | 20 00 | | ||
| 33 | | Play/Pause | 01000000 00000000 | 40 00 | | ||
| 34 | | Fast Forward | 10000000 00000000 | 80 00 | | ||
| 35 | | Rewind | 00000000 00000001 | 00 01 | | ||
| 36 | | Scan Next Track | 00000000 00000010 | 00 02 | | ||
| 37 | | Scan Prev Track | 00000000 00000100 | 00 04 | | ||
| 38 | | Random Play | 00000000 00001000 | 00 08 | | ||
| 39 | | Stop | 00000000 00010000 | 00 10 | | ||
| 40 | +-------------------------------------+-------+ | ||
| 41 | */ | ||
| 42 | #define CONSUMER2BLUEFRUIT(usage) \ | ||
| 43 | (usage == AUDIO_MUTE ? 0x0000 : \ | ||
| 44 | (usage == AUDIO_VOL_UP ? 0x1000 : \ | ||
| 45 | (usage == AUDIO_VOL_DOWN ? 0x2000 : \ | ||
| 46 | (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : \ | ||
| 47 | (usage == TRANSPORT_PREV_TRACK ? 0x0004 : \ | ||
| 48 | (usage == TRANSPORT_STOP ? 0x0010 : \ | ||
| 49 | (usage == TRANSPORT_STOP_EJECT ? 0x0000 : \ | ||
| 50 | (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : \ | ||
| 51 | (usage == AL_CC_CONFIG ? 0x0000 : \ | ||
| 52 | (usage == AL_EMAIL ? 0x0000 : \ | ||
| 53 | (usage == AL_CALCULATOR ? 0x0000 : \ | ||
| 54 | (usage == AL_LOCAL_BROWSER ? 0x0000 : \ | ||
| 55 | (usage == AC_SEARCH ? 0x0400 : \ | ||
| 56 | (usage == AC_HOME ? 0x0100 : \ | ||
| 57 | (usage == AC_BACK ? 0x0000 : \ | ||
| 58 | (usage == AC_FORWARD ? 0x0000 : \ | ||
| 59 | (usage == AC_STOP ? 0x0000 : \ | ||
| 60 | (usage == AC_REFRESH ? 0x0000 : \ | ||
| 61 | (usage == AC_BOOKMARKS ? 0x0000 : 0))))))))))))))))))) | ||
| 62 | |||
| 63 | #endif \ No newline at end of file | ||
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 85c7bf712..e5267fead 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -51,8 +51,13 @@ | |||
| 51 | 51 | ||
| 52 | #include "descriptor.h" | 52 | #include "descriptor.h" |
| 53 | #include "lufa.h" | 53 | #include "lufa.h" |
| 54 | |||
| 54 | #ifdef MIDI_ENABLE | 55 | #ifdef MIDI_ENABLE |
| 55 | #include <beeps.h> | 56 | #include <beeps.h> |
| 57 | #endif | ||
| 58 | |||
| 59 | #ifdef BLUETOOTH_ENABLE | ||
| 60 | #include "bluetooth.h" | ||
| 56 | #endif | 61 | #endif |
| 57 | 62 | ||
| 58 | // #include <LUFA/Version.h> | 63 | // #include <LUFA/Version.h> |
| @@ -89,7 +94,6 @@ host_driver_t lufa_driver = { | |||
| 89 | usb_get_midi, | 94 | usb_get_midi, |
| 90 | midi_usb_init, | 95 | midi_usb_init, |
| 91 | #endif | 96 | #endif |
| 92 | |||
| 93 | }; | 97 | }; |
| 94 | 98 | ||
| 95 | void SetupHardware(void); | 99 | void SetupHardware(void); |
| @@ -477,6 +481,13 @@ static void send_keyboard(report_keyboard_t *report) | |||
| 477 | Endpoint_ClearIN(); | 481 | Endpoint_ClearIN(); |
| 478 | 482 | ||
| 479 | keyboard_report_sent = *report; | 483 | keyboard_report_sent = *report; |
| 484 | |||
| 485 | #ifdef BLUETOOTH_ENABLE | ||
| 486 | bluefruit_serial_send(0xFD); | ||
| 487 | for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { | ||
| 488 | bluefruit_serial_send(report->raw[i]); | ||
| 489 | } | ||
| 490 | #endif | ||
| 480 | } | 491 | } |
| 481 | 492 | ||
| 482 | static void send_mouse(report_mouse_t *report) | 493 | static void send_mouse(report_mouse_t *report) |
| @@ -499,6 +510,20 @@ static void send_mouse(report_mouse_t *report) | |||
| 499 | 510 | ||
| 500 | /* Finalize the stream transfer to send the last packet */ | 511 | /* Finalize the stream transfer to send the last packet */ |
| 501 | Endpoint_ClearIN(); | 512 | Endpoint_ClearIN(); |
| 513 | |||
| 514 | |||
| 515 | #ifdef BLUETOOTH_ENABLE | ||
| 516 | bluefruit_serial_send(0xFD); | ||
| 517 | bluefruit_serial_send(0x00); | ||
| 518 | bluefruit_serial_send(0x03); | ||
| 519 | bluefruit_serial_send(report->buttons); | ||
| 520 | bluefruit_serial_send(report->x); | ||
| 521 | bluefruit_serial_send(report->y); | ||
| 522 | bluefruit_serial_send(report->v); // should try sending the wheel v here | ||
| 523 | bluefruit_serial_send(report->h); // should try sending the wheel h here | ||
| 524 | bluefruit_serial_send(0x00); | ||
| 525 | #endif | ||
| 526 | |||
| 502 | #endif | 527 | #endif |
| 503 | } | 528 | } |
| 504 | 529 | ||
| @@ -542,6 +567,23 @@ static void send_consumer(uint16_t data) | |||
| 542 | 567 | ||
| 543 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); | 568 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); |
| 544 | Endpoint_ClearIN(); | 569 | Endpoint_ClearIN(); |
| 570 | |||
| 571 | #ifdef BLUETOOTH_ENABLE | ||
| 572 | static uint16_t last_data = 0; | ||
| 573 | if (data == last_data) return; | ||
| 574 | last_data = data; | ||
| 575 | uint16_t bitmap = CONSUMER2BLUEFRUIT(data); | ||
| 576 | bluefruit_serial_send(0xFD); | ||
| 577 | bluefruit_serial_send(0x00); | ||
| 578 | bluefruit_serial_send(0x02); | ||
| 579 | bluefruit_serial_send((bitmap>>8)&0xFF); | ||
| 580 | bluefruit_serial_send(bitmap&0xFF); | ||
| 581 | bluefruit_serial_send(0x00); | ||
| 582 | bluefruit_serial_send(0x00); | ||
| 583 | bluefruit_serial_send(0x00); | ||
| 584 | bluefruit_serial_send(0x00); | ||
| 585 | #endif | ||
| 586 | |||
| 545 | } | 587 | } |
| 546 | 588 | ||
| 547 | 589 | ||
| @@ -838,6 +880,11 @@ int main(void) | |||
| 838 | // midi_send_noteoff(&midi_device, 0, 64, 127); | 880 | // midi_send_noteoff(&midi_device, 0, 64, 127); |
| 839 | #endif | 881 | #endif |
| 840 | 882 | ||
| 883 | #ifdef BLUETOOTH_ENABLE | ||
| 884 | print_set_sendchar(sendchar); | ||
| 885 | serial_init(); | ||
| 886 | #endif | ||
| 887 | |||
| 841 | 888 | ||
| 842 | /* wait for USB startup & debug output */ | 889 | /* wait for USB startup & debug output */ |
| 843 | while (USB_DeviceState != DEVICE_STATE_Configured) { | 890 | while (USB_DeviceState != DEVICE_STATE_Configured) { |
diff --git a/protocol/lufa/lufa.h b/protocol/lufa/lufa.h index 8bcd8503a..af01bf6b9 100644 --- a/protocol/lufa/lufa.h +++ b/protocol/lufa/lufa.h | |||
| @@ -49,7 +49,7 @@ | |||
| 49 | #include <LUFA/Drivers/USB/USB.h> | 49 | #include <LUFA/Drivers/USB/USB.h> |
| 50 | #include "host.h" | 50 | #include "host.h" |
| 51 | #ifdef MIDI_ENABLE | 51 | #ifdef MIDI_ENABLE |
| 52 | #include "midi/midi.h" | 52 | #include "midi/midi.h" |
| 53 | #endif | 53 | #endif |
| 54 | #ifdef __cplusplus | 54 | #ifdef __cplusplus |
| 55 | extern "C" { | 55 | extern "C" { |
