diff options
Diffstat (limited to 'tmk_core/protocol/bluefruit/bluefruit.c')
-rw-r--r-- | tmk_core/protocol/bluefruit/bluefruit.c | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/tmk_core/protocol/bluefruit/bluefruit.c b/tmk_core/protocol/bluefruit/bluefruit.c deleted file mode 100644 index fb001855e..000000000 --- a/tmk_core/protocol/bluefruit/bluefruit.c +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | /* | ||
2 | Bluefruit Protocol for TMK firmware | ||
3 | Author: Benjamin Gould, 2013 | ||
4 | Based on code Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
5 | This program is free software: you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation, either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | You should have received a copy of the GNU General Public License | ||
14 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <stdint.h> | ||
18 | #include "host.h" | ||
19 | #include "report.h" | ||
20 | #include "print.h" | ||
21 | #include "debug.h" | ||
22 | #include "host_driver.h" | ||
23 | #include "serial.h" | ||
24 | #include "bluefruit.h" | ||
25 | |||
26 | #define BLUEFRUIT_TRACE_SERIAL 1 | ||
27 | |||
28 | static uint8_t bluefruit_keyboard_leds = 0; | ||
29 | |||
30 | static void bluefruit_serial_send(uint8_t); | ||
31 | |||
32 | void bluefruit_keyboard_print_report(report_keyboard_t *report) { | ||
33 | if (!debug_keyboard) return; | ||
34 | dprintf("keys: "); | ||
35 | for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) { | ||
36 | debug_hex8(report->keys[i]); | ||
37 | dprintf(" "); | ||
38 | } | ||
39 | dprintf(" mods: "); | ||
40 | debug_hex8(report->mods); | ||
41 | dprintf(" reserved: "); | ||
42 | debug_hex8(report->reserved); | ||
43 | dprintf("\n"); | ||
44 | } | ||
45 | |||
46 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
47 | static void bluefruit_trace_header() { | ||
48 | dprintf("+------------------------------------+\n"); | ||
49 | dprintf("| HID report to Bluefruit via serial |\n"); | ||
50 | dprintf("+------------------------------------+\n|"); | ||
51 | } | ||
52 | |||
53 | static void bluefruit_trace_footer() { dprintf("|\n+------------------------------------+\n\n"); } | ||
54 | #endif | ||
55 | |||
56 | static void bluefruit_serial_send(uint8_t data) { | ||
57 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
58 | dprintf(" "); | ||
59 | debug_hex8(data); | ||
60 | dprintf(" "); | ||
61 | #endif | ||
62 | serial_send(data); | ||
63 | } | ||
64 | |||
65 | /*------------------------------------------------------------------* | ||
66 | * Host driver | ||
67 | *------------------------------------------------------------------*/ | ||
68 | |||
69 | static uint8_t keyboard_leds(void); | ||
70 | static void send_keyboard(report_keyboard_t *report); | ||
71 | static void send_mouse(report_mouse_t *report); | ||
72 | static void send_system(uint16_t data); | ||
73 | static void send_consumer(uint16_t data); | ||
74 | |||
75 | void sendString(char string[], int length) { | ||
76 | for (int i = 0; i < length; i++) { | ||
77 | serial_send(string[i]); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; | ||
82 | |||
83 | host_driver_t *bluefruit_driver(void) { return &driver; } | ||
84 | |||
85 | static uint8_t keyboard_leds(void) { return bluefruit_keyboard_leds; } | ||
86 | |||
87 | static void send_keyboard(report_keyboard_t *report) { | ||
88 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
89 | bluefruit_trace_header(); | ||
90 | #endif | ||
91 | bluefruit_serial_send(0xFD); | ||
92 | for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) { | ||
93 | bluefruit_serial_send(report->raw[i]); | ||
94 | } | ||
95 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
96 | bluefruit_trace_footer(); | ||
97 | #endif | ||
98 | } | ||
99 | |||
100 | static void send_mouse(report_mouse_t *report) { | ||
101 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
102 | bluefruit_trace_header(); | ||
103 | #endif | ||
104 | bluefruit_serial_send(0xFD); | ||
105 | bluefruit_serial_send(0x00); | ||
106 | bluefruit_serial_send(0x03); | ||
107 | bluefruit_serial_send(report->buttons); | ||
108 | bluefruit_serial_send(report->x); | ||
109 | bluefruit_serial_send(report->y); | ||
110 | bluefruit_serial_send(report->v); // should try sending the wheel v here | ||
111 | bluefruit_serial_send(report->h); // should try sending the wheel h here | ||
112 | bluefruit_serial_send(0x00); | ||
113 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
114 | bluefruit_trace_footer(); | ||
115 | #endif | ||
116 | } | ||
117 | |||
118 | static void send_system(uint16_t data) {} | ||
119 | |||
120 | /* | ||
121 | +-----------------+-------------------+-------+ | ||
122 | | Consumer Key | Bit Map | Hex | | ||
123 | +-----------------+-------------------+-------+ | ||
124 | | Home | 00000001 00000000 | 01 00 | | ||
125 | | KeyboardLayout | 00000010 00000000 | 02 00 | | ||
126 | | Search | 00000100 00000000 | 04 00 | | ||
127 | | Snapshot | 00001000 00000000 | 08 00 | | ||
128 | | VolumeUp | 00010000 00000000 | 10 00 | | ||
129 | | VolumeDown | 00100000 00000000 | 20 00 | | ||
130 | | Play/Pause | 01000000 00000000 | 40 00 | | ||
131 | | Fast Forward | 10000000 00000000 | 80 00 | | ||
132 | | Rewind | 00000000 00000001 | 00 01 | | ||
133 | | Scan Next Track | 00000000 00000010 | 00 02 | | ||
134 | | Scan Prev Track | 00000000 00000100 | 00 04 | | ||
135 | | Random Play | 00000000 00001000 | 00 08 | | ||
136 | | Stop | 00000000 00010000 | 00 10 | | ||
137 | +-------------------------------------+-------+ | ||
138 | */ | ||
139 | #define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0))))))))))))))))))) | ||
140 | |||
141 | static void send_consumer(uint16_t data) { | ||
142 | static uint16_t last_data = 0; | ||
143 | if (data == last_data) return; | ||
144 | last_data = data; | ||
145 | |||
146 | uint16_t bitmap = CONSUMER2BLUEFRUIT(data); | ||
147 | |||
148 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
149 | dprintf("\nData: "); | ||
150 | debug_hex16(data); | ||
151 | dprintf("; bitmap: "); | ||
152 | debug_hex16(bitmap); | ||
153 | dprintf("\n"); | ||
154 | bluefruit_trace_header(); | ||
155 | #endif | ||
156 | bluefruit_serial_send(0xFD); | ||
157 | bluefruit_serial_send(0x00); | ||
158 | bluefruit_serial_send(0x02); | ||
159 | bluefruit_serial_send((bitmap >> 8) & 0xFF); | ||
160 | bluefruit_serial_send(bitmap & 0xFF); | ||
161 | bluefruit_serial_send(0x00); | ||
162 | bluefruit_serial_send(0x00); | ||
163 | bluefruit_serial_send(0x00); | ||
164 | bluefruit_serial_send(0x00); | ||
165 | #ifdef BLUEFRUIT_TRACE_SERIAL | ||
166 | bluefruit_trace_footer(); | ||
167 | #endif | ||
168 | } \ No newline at end of file | ||