diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2015-10-23 20:12:04 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2015-10-23 20:12:04 -0400 |
| commit | 71a8fd8b1286926bd21edce3d2ec7423d8ca4eef (patch) | |
| tree | 14c7ce66ad9224f0f957d0437d9be910416140a7 | |
| parent | bbb21f60e9834a25157fe9043e794b67f1ad615e (diff) | |
| download | qmk_firmware-71a8fd8b1286926bd21edce3d2ec7423d8ca4eef.tar.gz qmk_firmware-71a8fd8b1286926bd21edce3d2ec7423d8ca4eef.zip | |
bluetooth working with usb
| -rw-r--r-- | keyboard/planck/Makefile | 20 | ||||
| -rw-r--r-- | keyboard/planck/config.h | 4 | ||||
| -rw-r--r-- | keyboard/planck/keymaps/keymap_lock.c | 40 | ||||
| -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 |
8 files changed, 182 insertions, 40 deletions
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile index d9e8ce788..3ac4540e1 100644 --- a/keyboard/planck/Makefile +++ b/keyboard/planck/Makefile | |||
| @@ -124,13 +124,13 @@ COMMAND_ENABLE = yes # Commands for debug and configuration | |||
| 124 | # SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | 124 | # SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend |
| 125 | # NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA | 125 | # NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA |
| 126 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | 126 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality |
| 127 | # MIDI_ENABLE = YES # MIDI controls | 127 | MIDI_ENABLE = YES # MIDI controls |
| 128 | # UNICODE_ENABLE = YES # Unicode | 128 | # UNICODE_ENABLE = YES # Unicode |
| 129 | # BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID | 129 | BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID |
| 130 | 130 | ||
| 131 | ifdef MIDI_ENABLE | 131 | ifdef MIDI_ENABLE |
| 132 | SRC += keymap_midi.c | 132 | SRC += keymap_midi.c \ |
| 133 | # beeps.c | 133 | beeps.c |
| 134 | endif | 134 | endif |
| 135 | 135 | ||
| 136 | ifdef UNICODE_ENABLE | 136 | ifdef UNICODE_ENABLE |
| @@ -144,17 +144,7 @@ endif | |||
| 144 | VPATH += $(TARGET_DIR) | 144 | VPATH += $(TARGET_DIR) |
| 145 | VPATH += $(TOP_DIR) | 145 | VPATH += $(TOP_DIR) |
| 146 | 146 | ||
| 147 | 147 | include $(TOP_DIR)/protocol/lufa.mk | |
| 148 | |||
| 149 | ifdef BLUETOOTH_ENABLE | ||
| 150 | BLUEFRUIT_TRACE_SERIAL=true | ||
| 151 | |||
| 152 | include $(TOP_DIR)/protocol.mk | ||
| 153 | include $(TOP_DIR)/protocol/bluefruit.mk | ||
| 154 | include $(TOP_DIR)/protocol.mk | ||
| 155 | else | ||
| 156 | include $(TOP_DIR)/protocol/lufa.mk | ||
| 157 | endif | ||
| 158 | 148 | ||
| 159 | include $(TOP_DIR)/common.mk | 149 | include $(TOP_DIR)/common.mk |
| 160 | include $(TOP_DIR)/rules.mk | 150 | include $(TOP_DIR)/rules.mk |
diff --git a/keyboard/planck/config.h b/keyboard/planck/config.h index 0a1a6a935..cc3a1741a 100644 --- a/keyboard/planck/config.h +++ b/keyboard/planck/config.h | |||
| @@ -131,10 +131,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 131 | */ | 131 | */ |
| 132 | 132 | ||
| 133 | /* disable debug print */ | 133 | /* disable debug print */ |
| 134 | // #define NO_DEBUG | 134 | #define NO_DEBUG |
| 135 | 135 | ||
| 136 | /* disable print */ | 136 | /* disable print */ |
| 137 | // #define NO_PRINT | 137 | #define NO_PRINT |
| 138 | 138 | ||
| 139 | /* disable action features */ | 139 | /* disable action features */ |
| 140 | //#define NO_ACTION_LAYER | 140 | //#define NO_ACTION_LAYER |
diff --git a/keyboard/planck/keymaps/keymap_lock.c b/keyboard/planck/keymaps/keymap_lock.c index b844d1cda..cc9be55f6 100644 --- a/keyboard/planck/keymaps/keymap_lock.c +++ b/keyboard/planck/keymaps/keymap_lock.c | |||
| @@ -75,33 +75,33 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | |||
| 75 | default_layer_and(0); | 75 | default_layer_and(0); |
| 76 | default_layer_or((1<<5)); | 76 | default_layer_or((1<<5)); |
| 77 | 77 | ||
| 78 | uint8_t low = boot_lock_fuse_bits_get(0x0000); | 78 | // uint8_t low = boot_lock_fuse_bits_get(0x0000); |
| 79 | uint8_t high = boot_lock_fuse_bits_get(0x0003); | 79 | // uint8_t high = boot_lock_fuse_bits_get(0x0003); |
| 80 | uint8_t ext = boot_lock_fuse_bits_get(0x0002); | 80 | // uint8_t ext = boot_lock_fuse_bits_get(0x0002); |
| 81 | uint8_t lock = boot_lock_fuse_bits_get(0x0001); | 81 | // uint8_t lock = boot_lock_fuse_bits_get(0x0001); |
| 82 | 82 | ||
| 83 | register_code(hextokeycode((low & 0xF0) >> 4)); | 83 | // register_code(hextokeycode((low & 0xF0) >> 4)); |
| 84 | unregister_code(hextokeycode((low & 0xF0) >> 4)); | 84 | // unregister_code(hextokeycode((low & 0xF0) >> 4)); |
| 85 | register_code(hextokeycode((low & 0x0F))); | 85 | // register_code(hextokeycode((low & 0x0F))); |
| 86 | unregister_code(hextokeycode((low & 0x0F))); | 86 | // unregister_code(hextokeycode((low & 0x0F))); |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | register_code(hextokeycode((high & 0xF0) >> 4)); | 89 | // register_code(hextokeycode((high & 0xF0) >> 4)); |
| 90 | unregister_code(hextokeycode((high & 0xF0) >> 4)); | 90 | // unregister_code(hextokeycode((high & 0xF0) >> 4)); |
| 91 | register_code(hextokeycode((high & 0x0F))); | 91 | // register_code(hextokeycode((high & 0x0F))); |
| 92 | unregister_code(hextokeycode((high & 0x0F))); | 92 | // unregister_code(hextokeycode((high & 0x0F))); |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | register_code(hextokeycode((ext & 0xF0) >> 4)); | 95 | // register_code(hextokeycode((ext & 0xF0) >> 4)); |
| 96 | unregister_code(hextokeycode((ext & 0xF0) >> 4)); | 96 | // unregister_code(hextokeycode((ext & 0xF0) >> 4)); |
| 97 | register_code(hextokeycode((ext & 0x0F))); | 97 | // register_code(hextokeycode((ext & 0x0F))); |
| 98 | unregister_code(hextokeycode((ext & 0x0F))); | 98 | // unregister_code(hextokeycode((ext & 0x0F))); |
| 99 | 99 | ||
| 100 | 100 | ||
| 101 | register_code(hextokeycode((lock & 0xF0) >> 4)); | 101 | // register_code(hextokeycode((lock & 0xF0) >> 4)); |
| 102 | unregister_code(hextokeycode((lock & 0xF0) >> 4)); | 102 | // unregister_code(hextokeycode((lock & 0xF0) >> 4)); |
| 103 | register_code(hextokeycode((lock & 0x0F))); | 103 | // register_code(hextokeycode((lock & 0x0F))); |
| 104 | unregister_code(hextokeycode((lock & 0x0F))); | 104 | // unregister_code(hextokeycode((lock & 0x0F))); |
| 105 | 105 | ||
| 106 | // note(0+12, 20); | 106 | // note(0+12, 20); |
| 107 | // note(0+24, 20); | 107 | // note(0+24, 20); |
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" { |
