diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-11-21 12:54:06 -0500 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-11-21 12:54:06 -0500 |
| commit | b57cf3c0c851f2fb0e32c955b16fc6f0ad236e54 (patch) | |
| tree | 24556bc878acdb2f7237ae4e15b803451bb91da5 | |
| parent | ab6557c1a04b7f6a1d262d07f9b42e7e28d8028a (diff) | |
| download | qmk_firmware-b57cf3c0c851f2fb0e32c955b16fc6f0ad236e54.tar.gz qmk_firmware-b57cf3c0c851f2fb0e32c955b16fc6f0ad236e54.zip | |
more structure to the package
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 107 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.h | 15 |
2 files changed, 100 insertions, 22 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index ae9cc2f96..cc00b3b89 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -1147,10 +1147,9 @@ void send_nibble(uint8_t number) { | |||
| 1147 | } | 1147 | } |
| 1148 | } | 1148 | } |
| 1149 | 1149 | ||
| 1150 | uint8_t midi_buffer[16] = {0}; | 1150 | uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; |
| 1151 | 1151 | ||
| 1152 | void sysex_callback(MidiDevice * device, | 1152 | void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) { |
| 1153 | uint16_t start, uint8_t length, uint8_t * data) { | ||
| 1154 | // for (int i = 0; i < length; i++) | 1153 | // for (int i = 0; i < length; i++) |
| 1155 | // midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i)); | 1154 | // midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i)); |
| 1156 | // if (start == 0x27) { | 1155 | // if (start == 0x27) { |
| @@ -1169,7 +1168,7 @@ void sysex_callback(MidiDevice * device, | |||
| 1169 | 1168 | ||
| 1170 | } | 1169 | } |
| 1171 | 1170 | ||
| 1172 | uint32_t decode_4byte_chunk(uint8_t * data) { | 1171 | uint32_t decode_uint32_chunk(uint8_t * data) { |
| 1173 | uint32_t part1 = *data++; | 1172 | uint32_t part1 = *data++; |
| 1174 | uint32_t part2 = *data++; | 1173 | uint32_t part2 = *data++; |
| 1175 | uint32_t part3 = *data++; | 1174 | uint32_t part3 = *data++; |
| @@ -1178,7 +1177,13 @@ uint32_t decode_4byte_chunk(uint8_t * data) { | |||
| 1178 | return ((part1 & 0x1FUL) << 28) | (part2 << 21) | (part3 << 14) | (part4 << 7) | part5; | 1177 | return ((part1 & 0x1FUL) << 28) | (part2 << 21) | (part3 << 14) | (part4 << 7) | part5; |
| 1179 | } | 1178 | } |
| 1180 | 1179 | ||
| 1181 | void encode_4byte_chunk(uint32_t data, uint8_t * pointer) { | 1180 | uint32_t decode_uint8_chunk(uint8_t * data) { |
| 1181 | uint32_t part4 = *data++; | ||
| 1182 | uint32_t part5 = *data++; | ||
| 1183 | return (part4 << 7) | part5; | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | void encode_uint32_chunk(uint32_t data, uint8_t * pointer) { | ||
| 1182 | *pointer++ = (data >> 28) & 0x7F; | 1187 | *pointer++ = (data >> 28) & 0x7F; |
| 1183 | *pointer++ = (data >> 21) & 0x7F; | 1188 | *pointer++ = (data >> 21) & 0x7F; |
| 1184 | *pointer++ = (data >> 14) & 0x7F; | 1189 | *pointer++ = (data >> 14) & 0x7F; |
| @@ -1186,6 +1191,11 @@ void encode_4byte_chunk(uint32_t data, uint8_t * pointer) { | |||
| 1186 | *pointer++ = (data) & 0x7F; | 1191 | *pointer++ = (data) & 0x7F; |
| 1187 | } | 1192 | } |
| 1188 | 1193 | ||
| 1194 | void encode_uint8_chunk(uint8_t data, uint8_t * pointer) { | ||
| 1195 | *pointer++ = (data >> 7) & 0x7F; | ||
| 1196 | *pointer++ = (data) & 0x7F; | ||
| 1197 | } | ||
| 1198 | |||
| 1189 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { | 1199 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { |
| 1190 | uint8_t * pointer_copy = data; | 1200 | uint8_t * pointer_copy = data; |
| 1191 | 1201 | ||
| @@ -1197,28 +1207,77 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) | |||
| 1197 | data++; | 1207 | data++; |
| 1198 | 1208 | ||
| 1199 | switch (*data++) { | 1209 | switch (*data++) { |
| 1210 | case 0x12: ; // Set info on keyboard | ||
| 1211 | switch (*data++) { | ||
| 1212 | case 0x02: ; // set default layer | ||
| 1213 | uint8_t default_layer = decode_uint8_chunk(data); | ||
| 1214 | eeconfig_update_default_layer(default_layer); | ||
| 1215 | default_layer_set((uint32_t)default_layer); | ||
| 1216 | break; | ||
| 1217 | case 0x08: ; // set keymap options | ||
| 1218 | uint8_t keymap_options = decode_uint8_chunk(data); | ||
| 1219 | eeconfig_update_keymap(keymap_options); | ||
| 1220 | break; | ||
| 1221 | } | ||
| 1222 | break; | ||
| 1200 | case 0x13: ; // Get info from keyboard | 1223 | case 0x13: ; // Get info from keyboard |
| 1201 | switch (*data++) { | 1224 | switch (*data++) { |
| 1202 | case 0x00: ; // Get layer state | 1225 | case 0x00: ; // Handshake |
| 1203 | // send_dword(layer_state); | 1226 | send_bytes_sysex(0x00, NULL, 0); |
| 1204 | uint8_t chunk[5]; | 1227 | break; |
| 1205 | encode_4byte_chunk(layer_state | default_layer_state, &chunk); | 1228 | case 0x01: ; // Get debug state |
| 1206 | 1229 | uint8_t debug[2]; | |
| 1207 | uint8_t array[] = {0xF0, 0x00, 0x00, 0x00, 0x00, chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], 0xF7}; | 1230 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), &debug); |
| 1208 | midi_send_array(&midi_device, 11, &array); | 1231 | send_bytes_sysex(0x01, &debug, 2); |
| 1209 | // midi_send_data(device, 3, 0x00, layer_state >> 24 & 0x7f, layer_state >> 16 & 0x7f); | 1232 | break; |
| 1210 | // midi_send_data(device, 6, layer_state >> 8 & 0x7f, layer_state & 0x7f, 0xF7); | 1233 | case 0x02: ; // Get default layer |
| 1234 | uint8_t default_layer[2]; | ||
| 1235 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), &default_layer); | ||
| 1236 | send_bytes_sysex(0x02, &default_layer, 2); | ||
| 1237 | break; | ||
| 1238 | #ifdef AUDIO_ENABLE | ||
| 1239 | case 0x03: ; // Get backlight state | ||
| 1240 | uint8_t audio[2]; | ||
| 1241 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), &audio); | ||
| 1242 | send_bytes_sysex(0x03, &audio, 2); | ||
| 1243 | #endif | ||
| 1244 | case 0x04: ; // Get layer state | ||
| 1245 | uint8_t layers[5]; | ||
| 1246 | encode_uint32_chunk(layer_state, &layers); | ||
| 1247 | send_bytes_sysex(0x04, &layers, 5); | ||
| 1248 | break; | ||
| 1249 | #ifdef BACKLIGHT_ENABLE | ||
| 1250 | case 0x06: ; // Get backlight state | ||
| 1251 | uint8_t backlight[2]; | ||
| 1252 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), &backlight); | ||
| 1253 | send_bytes_sysex(0x06, &backlight, 2); | ||
| 1254 | #endif | ||
| 1255 | #ifdef RGBLIGHT_ENABLE | ||
| 1256 | case 0x07: ; // Get rgblight state | ||
| 1257 | uint8_t rgblight[2]; | ||
| 1258 | encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), &rgblight); | ||
| 1259 | send_bytes_sysex(0x07, &rgblight, 5); | ||
| 1260 | #endif | ||
| 1261 | case 0x08: ; // Keymap options | ||
| 1262 | uint8_t keymap_options[2]; | ||
| 1263 | encode_uint8_chunk(eeconfig_read_keymap(), &keymap_options); | ||
| 1264 | send_bytes_sysex(0x08, &keymap_options, 2); | ||
| 1211 | break; | 1265 | break; |
| 1212 | } | 1266 | } |
| 1267 | break; | ||
| 1213 | #ifdef RGBLIGHT_ENABLE | 1268 | #ifdef RGBLIGHT_ENABLE |
| 1214 | case 0x27: ; // RGB LED functions | 1269 | case 0x27: ; // RGB LED functions |
| 1215 | switch (*data++) { | 1270 | switch (*data++) { |
| 1216 | case 0x00: ; // Update HSV | 1271 | case 0x00: ; // Update HSV |
| 1217 | uint32_t chunk = decode_4byte_chunk(data); | 1272 | uint32_t hsv = decode_uint32_chunk(data); |
| 1218 | rgblight_sethsv(((chunk >> 16) & 0xFFFF) % 360, (chunk >> 8) & 0xFF, chunk & 0xFF); | 1273 | rgblight_sethsv(((hsv >> 16) & 0xFFFF) % 360, (hsv >> 8) & 0xFF, hsv & 0xFF); |
| 1219 | break; | 1274 | break; |
| 1220 | case 0x01: ; // Update RGB | 1275 | case 0x01: ; // Update RGB |
| 1221 | break; | 1276 | break; |
| 1277 | case 0x02: ; // Update mode | ||
| 1278 | uint8_t rgb_mode = decode_uint8_chunk(data); | ||
| 1279 | rgblight_mode(rgb_mode); | ||
| 1280 | break; | ||
| 1222 | } | 1281 | } |
| 1223 | break; | 1282 | break; |
| 1224 | #endif | 1283 | #endif |
| @@ -1234,10 +1293,20 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) | |||
| 1234 | 1293 | ||
| 1235 | void send_unicode_midi(uint32_t unicode) { | 1294 | void send_unicode_midi(uint32_t unicode) { |
| 1236 | uint8_t chunk[5]; | 1295 | uint8_t chunk[5]; |
| 1237 | encode_4byte_chunk(unicode, &chunk); | 1296 | encode_uint32_chunk(unicode, &chunk); |
| 1297 | send_bytes_sysex(0x05, &chunk, 5); | ||
| 1298 | } | ||
| 1238 | 1299 | ||
| 1239 | uint8_t array[] = {0xF0, 0x00, 0x00, 0x00, 0x05, chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], 0xF7}; | 1300 | void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { |
| 1240 | midi_send_array(&midi_device, 11, &array); | 1301 | uint8_t * array = malloc(sizeof(uint8_t) * (length + 6)); |
| 1302 | array[0] = 0xF0; | ||
| 1303 | array[1] = 0x00; | ||
| 1304 | array[2] = 0x00; | ||
| 1305 | array[3] = 0x00; | ||
| 1306 | array[4] = type; | ||
| 1307 | array[length + 5] = 0xF7; | ||
| 1308 | memcpy(array + 5, bytes, length); | ||
| 1309 | midi_send_array(&midi_device, length + 6, array); | ||
| 1241 | } | 1310 | } |
| 1242 | 1311 | ||
| 1243 | #endif | 1312 | #endif |
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h index 3fec797b6..198964f90 100644 --- a/tmk_core/protocol/lufa/lufa.h +++ b/tmk_core/protocol/lufa/lufa.h | |||
| @@ -68,9 +68,18 @@ typedef struct { | |||
| 68 | } __attribute__ ((packed)) report_extra_t; | 68 | } __attribute__ ((packed)) report_extra_t; |
| 69 | 69 | ||
| 70 | #ifdef MIDI_ENABLE | 70 | #ifdef MIDI_ENABLE |
| 71 | void MIDI_Task(void); | 71 | #define MIDI_SYSEX_BUFFER 16 |
| 72 | MidiDevice midi_device; | 72 | void MIDI_Task(void); |
| 73 | void send_unicode_midi(uint32_t unicode); | 73 | MidiDevice midi_device; |
| 74 | |||
| 75 | void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data); | ||
| 76 | uint32_t decode_uint32_chunk(uint8_t * data); | ||
| 77 | uint32_t decode_uint8_chunk(uint8_t * data); | ||
| 78 | void encode_uint32_chunk(uint32_t data, uint8_t * pointer); | ||
| 79 | void encode_uint8_chunk(uint8_t data, uint8_t * pointer); | ||
| 80 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data); | ||
| 81 | void send_unicode_midi(uint32_t unicode); | ||
| 82 | void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length); | ||
| 74 | #endif | 83 | #endif |
| 75 | 84 | ||
| 76 | // #if LUFA_VERSION_INTEGER < 0x120730 | 85 | // #if LUFA_VERSION_INTEGER < 0x120730 |
