diff options
| -rw-r--r-- | Dockerfile | 3 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 119 | ||||
| -rw-r--r-- | tmk_core/protocol/midi.mk | 1 |
3 files changed, 70 insertions, 53 deletions
diff --git a/Dockerfile b/Dockerfile index 744ded857..c42bbeb32 100644 --- a/Dockerfile +++ b/Dockerfile | |||
| @@ -25,5 +25,4 @@ ENV subproject=ez | |||
| 25 | ENV keymap=default | 25 | ENV keymap=default |
| 26 | 26 | ||
| 27 | VOLUME /qmk | 27 | VOLUME /qmk |
| 28 | WORKDIR /qmk | 28 | WORKDIR /qmk \ No newline at end of file |
| 29 | CMD make clean ; make keyboard=${keyboard} subproject=${subproject} keymap=${keymap} | ||
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index a33a16599..c4531c8d7 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -76,6 +76,10 @@ | |||
| 76 | #include "rgblight.h" | 76 | #include "rgblight.h" |
| 77 | #endif | 77 | #endif |
| 78 | 78 | ||
| 79 | #ifdef MIDI_ENABLE | ||
| 80 | #include "sysex_tools.h" | ||
| 81 | #endif | ||
| 82 | |||
| 79 | uint8_t keyboard_idle = 0; | 83 | uint8_t keyboard_idle = 0; |
| 80 | /* 0: Boot Protocol, 1: Report Protocol(default) */ | 84 | /* 0: Boot Protocol, 1: Report Protocol(default) */ |
| 81 | uint8_t keyboard_protocol = 1; | 85 | uint8_t keyboard_protocol = 1; |
| @@ -1124,8 +1128,16 @@ void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t | |||
| 1124 | for (uint8_t place = 0; place < length; place++) { | 1128 | for (uint8_t place = 0; place < length; place++) { |
| 1125 | // send_byte(*data); | 1129 | // send_byte(*data); |
| 1126 | midi_buffer[start + place] = *data; | 1130 | midi_buffer[start + place] = *data; |
| 1127 | if (*data == 0xF7 && midi_buffer[0] == 0xF0) | 1131 | if (*data == 0xF7) { |
| 1128 | sysex_buffer_callback(device, start + place, midi_buffer); | 1132 | // SEND_STRING("\nRD: "); |
| 1133 | // for (uint8_t i = 0; i < start + place + 1; i++){ | ||
| 1134 | // send_byte(midi_buffer[i]); | ||
| 1135 | // SEND_STRING(" "); | ||
| 1136 | // } | ||
| 1137 | uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4))); | ||
| 1138 | uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4); | ||
| 1139 | sysex_buffer_callback(device, decode_length, decoded); | ||
| 1140 | } | ||
| 1129 | // SEND_STRING(" "); | 1141 | // SEND_STRING(" "); |
| 1130 | data++; | 1142 | data++; |
| 1131 | } | 1143 | } |
| @@ -1161,32 +1173,35 @@ void encode_uint8_chunk(uint8_t data, uint8_t * pointer) { | |||
| 1161 | *pointer++ = (data) & 0x7F; | 1173 | *pointer++ = (data) & 0x7F; |
| 1162 | } | 1174 | } |
| 1163 | 1175 | ||
| 1164 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { | 1176 | void dword_to_bytes(uint8_t * bytes, uint32_t dword) { |
| 1165 | // uint8_t * pointer_copy = data; // use for debugging | 1177 | bytes[0] = (dword >> 24) & 0xFF; |
| 1178 | bytes[1] = (dword >> 16) & 0xFF; | ||
| 1179 | bytes[2] = (dword >> 8) & 0xFF; | ||
| 1180 | bytes[3] = (dword >> 0) & 0xFF; | ||
| 1181 | } | ||
| 1166 | 1182 | ||
| 1167 | //data++; // i'm 98% sure there's a better way to do this | 1183 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { |
| 1168 | data++; | 1184 | // SEND_STRING("\nRX: "); |
| 1169 | data++; | 1185 | // for (uint8_t i = 0; i < length; i++) { |
| 1170 | data++; | 1186 | // send_byte(data[i]); |
| 1171 | data++; | 1187 | // SEND_STRING(" "); |
| 1188 | // } | ||
| 1172 | 1189 | ||
| 1173 | switch (*data++) { | 1190 | switch (*data++) { |
| 1174 | case 0x07: ; // Quantum action | 1191 | case 0x07: ; // Quantum action |
| 1175 | break; | 1192 | break; |
| 1176 | case 0x08: ; // Keyboard acion | 1193 | case 0x08: ; // Keyboard action |
| 1177 | break; | 1194 | break; |
| 1178 | case 0x09: ; // User action | 1195 | case 0x09: ; // User action |
| 1179 | break; | 1196 | break; |
| 1180 | case 0x12: ; // Set info on keyboard | 1197 | case 0x12: ; // Set info on keyboard |
| 1181 | switch (*data++) { | 1198 | switch (*data++) { |
| 1182 | case 0x02: ; // set default layer | 1199 | case 0x02: ; // set default layer |
| 1183 | uint8_t default_layer = decode_uint8_chunk(data); | 1200 | eeconfig_update_default_layer(data[0] << 8 | data[1]); |
| 1184 | eeconfig_update_default_layer(default_layer); | 1201 | default_layer_set((uint32_t)(data[0] << 8 | data[1])); |
| 1185 | default_layer_set((uint32_t)default_layer); | ||
| 1186 | break; | 1202 | break; |
| 1187 | case 0x08: ; // set keymap options | 1203 | case 0x08: ; // set keymap options |
| 1188 | uint8_t keymap_options = decode_uint8_chunk(data); | 1204 | eeconfig_update_keymap(data[0]); |
| 1189 | eeconfig_update_keymap(keymap_options); | ||
| 1190 | break; | 1205 | break; |
| 1191 | } | 1206 | } |
| 1192 | break; | 1207 | break; |
| @@ -1196,42 +1211,37 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) | |||
| 1196 | send_bytes_sysex(0x00, NULL, 0); | 1211 | send_bytes_sysex(0x00, NULL, 0); |
| 1197 | break; | 1212 | break; |
| 1198 | case 0x01: ; // Get debug state | 1213 | case 0x01: ; // Get debug state |
| 1199 | uint8_t debug[2]; | 1214 | uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) }; |
| 1200 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), debug); | 1215 | send_bytes_sysex(0x01, debug_bytes, 1); |
| 1201 | send_bytes_sysex(0x01, debug, 2); | ||
| 1202 | break; | 1216 | break; |
| 1203 | case 0x02: ; // Get default layer | 1217 | case 0x02: ; // Get default layer |
| 1204 | uint8_t default_layer[2]; | 1218 | uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) }; |
| 1205 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), default_layer); | 1219 | send_bytes_sysex(0x02, default_bytes, 1); |
| 1206 | send_bytes_sysex(0x02, default_layer, 2); | ||
| 1207 | break; | 1220 | break; |
| 1208 | #ifdef AUDIO_ENABLE | 1221 | #ifdef AUDIO_ENABLE |
| 1209 | case 0x03: ; // Get backlight state | 1222 | case 0x03: ; // Get backlight state |
| 1210 | uint8_t audio[2]; | 1223 | uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) }; |
| 1211 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), audio); | 1224 | send_bytes_sysex(0x03, audio_bytes, 1); |
| 1212 | send_bytes_sysex(0x03, audio, 2); | ||
| 1213 | #endif | 1225 | #endif |
| 1214 | case 0x04: ; // Get layer state | 1226 | case 0x04: ; // Get layer state |
| 1215 | uint8_t layers[5]; | 1227 | uint8_t layer_state_bytes[4]; |
| 1216 | encode_uint32_chunk(layer_state, layers); | 1228 | dword_to_bytes(layer_state_bytes, layer_state); |
| 1217 | send_bytes_sysex(0x04, layers, 5); | 1229 | send_bytes_sysex(0x04, layer_state_bytes, 4); |
| 1218 | break; | 1230 | break; |
| 1219 | #ifdef BACKLIGHT_ENABLE | 1231 | #ifdef BACKLIGHT_ENABLE |
| 1220 | case 0x06: ; // Get backlight state | 1232 | case 0x06: ; // Get backlight state |
| 1221 | uint8_t backlight[2]; | 1233 | uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) }; |
| 1222 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), backlight); | 1234 | send_bytes_sysex(0x06, backlight_bytes, 1); |
| 1223 | send_bytes_sysex(0x06, backlight, 2); | ||
| 1224 | #endif | 1235 | #endif |
| 1225 | #ifdef RGBLIGHT_ENABLE | 1236 | #ifdef RGBLIGHT_ENABLE |
| 1226 | case 0x07: ; // Get rgblight state | 1237 | case 0x07: ; // Get rgblight state |
| 1227 | uint8_t rgblight[2]; | 1238 | uint8_t rgblight_bytes[4]; |
| 1228 | encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), rgblight); | 1239 | dword_to_bytes(rgblight_bytes, eeprom_read_dword(EECONFIG_RGBLIGHT)); |
| 1229 | send_bytes_sysex(0x07, rgblight, 5); | 1240 | send_bytes_sysex(0x07, rgblight_bytes, 4); |
| 1230 | #endif | 1241 | #endif |
| 1231 | case 0x08: ; // Keymap options | 1242 | case 0x08: ; // Keymap options |
| 1232 | uint8_t keymap_options[2]; | 1243 | uint8_t keymap_bytes[1] = { eeconfig_read_keymap() }; |
| 1233 | encode_uint8_chunk(eeconfig_read_keymap(), keymap_options); | 1244 | send_bytes_sysex(0x08, keymap_bytes, 1); |
| 1234 | send_bytes_sysex(0x08, keymap_options, 2); | ||
| 1235 | break; | 1245 | break; |
| 1236 | } | 1246 | } |
| 1237 | break; | 1247 | break; |
| @@ -1239,26 +1249,18 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) | |||
| 1239 | case 0x27: ; // RGB LED functions | 1249 | case 0x27: ; // RGB LED functions |
| 1240 | switch (*data++) { | 1250 | switch (*data++) { |
| 1241 | case 0x00: ; // Update HSV | 1251 | case 0x00: ; // Update HSV |
| 1242 | uint32_t hsv = decode_uint32_chunk(data); | 1252 | rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]); |
| 1243 | rgblight_sethsv(((hsv >> 16) & 0xFFFF) % 360, (hsv >> 8) & 0xFF, hsv & 0xFF); | ||
| 1244 | break; | 1253 | break; |
| 1245 | case 0x01: ; // Update RGB | 1254 | case 0x01: ; // Update RGB |
| 1246 | break; | 1255 | break; |
| 1247 | case 0x02: ; // Update mode | 1256 | case 0x02: ; // Update mode |
| 1248 | uint8_t rgb_mode = decode_uint8_chunk(data); | 1257 | rgblight_mode(data[0]); |
| 1249 | rgblight_mode(rgb_mode); | ||
| 1250 | break; | 1258 | break; |
| 1251 | } | 1259 | } |
| 1252 | break; | 1260 | break; |
| 1253 | #endif | 1261 | #endif |
| 1254 | } | 1262 | } |
| 1255 | 1263 | ||
| 1256 | // SEND_STRING("\nDATA:\n"); | ||
| 1257 | // while (*pointer_copy != 0xF7) { | ||
| 1258 | // send_byte(*pointer_copy++); | ||
| 1259 | // SEND_STRING(" "); | ||
| 1260 | // } | ||
| 1261 | |||
| 1262 | } | 1264 | } |
| 1263 | 1265 | ||
| 1264 | void send_unicode_midi(uint32_t unicode) { | 1266 | void send_unicode_midi(uint32_t unicode) { |
| @@ -1268,15 +1270,30 @@ void send_unicode_midi(uint32_t unicode) { | |||
| 1268 | } | 1270 | } |
| 1269 | 1271 | ||
| 1270 | void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { | 1272 | void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { |
| 1271 | uint8_t * array = malloc(sizeof(uint8_t) * (length + 6)); | 1273 | // SEND_STRING("\nTX: "); |
| 1274 | // for (uint8_t i = 0; i < length; i++) { | ||
| 1275 | // send_byte(bytes[i]); | ||
| 1276 | // SEND_STRING(" "); | ||
| 1277 | // } | ||
| 1278 | uint8_t * precode = malloc(sizeof(uint8_t) * (length + 1)); | ||
| 1279 | precode[0] = type; | ||
| 1280 | memcpy(precode + 1, bytes, length); | ||
| 1281 | uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 1))); | ||
| 1282 | uint16_t encoded_length = sysex_encode(encoded, precode, length + 1); | ||
| 1283 | uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5)); | ||
| 1272 | array[0] = 0xF0; | 1284 | array[0] = 0xF0; |
| 1273 | array[1] = 0x00; | 1285 | array[1] = 0x00; |
| 1274 | array[2] = 0x00; | 1286 | array[2] = 0x00; |
| 1275 | array[3] = 0x00; | 1287 | array[3] = 0x00; |
| 1276 | array[4] = type; | 1288 | array[encoded_length + 4] = 0xF7; |
| 1277 | array[length + 5] = 0xF7; | 1289 | memcpy(array + 4, encoded, encoded_length); |
| 1278 | memcpy(array + 5, bytes, length); | 1290 | midi_send_array(&midi_device, encoded_length + 5, array); |
| 1279 | midi_send_array(&midi_device, length + 6, array); | 1291 | |
| 1292 | // SEND_STRING("\nTD: "); | ||
| 1293 | // for (uint8_t i = 0; i < encoded_length + 5; i++) { | ||
| 1294 | // send_byte(array[i]); | ||
| 1295 | // SEND_STRING(" "); | ||
| 1296 | // } | ||
| 1280 | } | 1297 | } |
| 1281 | 1298 | ||
| 1282 | #endif | 1299 | #endif |
diff --git a/tmk_core/protocol/midi.mk b/tmk_core/protocol/midi.mk index c85ae42ff..4855b23d3 100644 --- a/tmk_core/protocol/midi.mk +++ b/tmk_core/protocol/midi.mk | |||
| @@ -4,6 +4,7 @@ SRC += midi.c \ | |||
| 4 | midi_device.c \ | 4 | midi_device.c \ |
| 5 | bytequeue/bytequeue.c \ | 5 | bytequeue/bytequeue.c \ |
| 6 | bytequeue/interrupt_setting.c \ | 6 | bytequeue/interrupt_setting.c \ |
| 7 | sysex_tools.c \ | ||
| 7 | $(LUFA_SRC_USBCLASS) | 8 | $(LUFA_SRC_USBCLASS) |
| 8 | 9 | ||
| 9 | VPATH += $(TMK_PATH)/$(MIDI_DIR) \ No newline at end of file | 10 | VPATH += $(TMK_PATH)/$(MIDI_DIR) \ No newline at end of file |
