aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/lufa/lufa.c32
-rw-r--r--tmk_core/protocol/lufa/lufa.h4
2 files changed, 25 insertions, 11 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 097189770..6dd5959dc 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1252,28 +1252,40 @@ void cc_callback(MidiDevice * device,
1252 // midi_send_cc(device, (chan + 1) % 16, num, val); 1252 // midi_send_cc(device, (chan + 1) % 16, num, val);
1253} 1253}
1254 1254
1255#ifdef API_SYSEX_ENABLE
1255uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; 1256uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
1257#endif
1256 1258
1257void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) { 1259void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
1258 #ifdef API_SYSEX_ENABLE 1260 #ifdef API_SYSEX_ENABLE
1259 // SEND_STRING("\n"); 1261 // SEND_STRING("\n");
1260 // send_word(start); 1262 // send_word(start);
1261 // SEND_STRING(": "); 1263 // SEND_STRING(": ");
1264 // Don't store the header
1265 int16_t pos = start - 4;
1262 for (uint8_t place = 0; place < length; place++) { 1266 for (uint8_t place = 0; place < length; place++) {
1263 // send_byte(*data); 1267 // send_byte(*data);
1264 midi_buffer[start + place] = *data; 1268 if (pos >= 0) {
1265 if (*data == 0xF7) { 1269 if (*data == 0xF7) {
1266 // SEND_STRING("\nRD: "); 1270 // SEND_STRING("\nRD: ");
1267 // for (uint8_t i = 0; i < start + place + 1; i++){ 1271 // for (uint8_t i = 0; i < start + place + 1; i++){
1268 // send_byte(midi_buffer[i]); 1272 // send_byte(midi_buffer[i]);
1269 // SEND_STRING(" "); 1273 // SEND_STRING(" ");
1270 // } 1274 // }
1271 uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4))); 1275 const unsigned decoded_length = sysex_decoded_length(pos);
1272 uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4); 1276 uint8_t decoded[API_SYSEX_MAX_SIZE];
1273 process_api(decode_length, decoded); 1277 sysex_decode(decoded, midi_buffer, pos);
1278 process_api(decoded_length, decoded);
1279 return;
1280 }
1281 else if (pos >= MIDI_SYSEX_BUFFER) {
1282 return;
1283 }
1284 midi_buffer[pos] = *data;
1274 } 1285 }
1275 // SEND_STRING(" "); 1286 // SEND_STRING(" ");
1276 data++; 1287 data++;
1288 pos++;
1277 } 1289 }
1278 #endif 1290 #endif
1279} 1291}
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index b11854101..a049fd43c 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -70,7 +70,6 @@ typedef struct {
70#ifdef MIDI_ENABLE 70#ifdef MIDI_ENABLE
71 void MIDI_Task(void); 71 void MIDI_Task(void);
72 MidiDevice midi_device; 72 MidiDevice midi_device;
73 #define MIDI_SYSEX_BUFFER 32
74#endif 73#endif
75 74
76#ifdef API_ENABLE 75#ifdef API_ENABLE
@@ -79,6 +78,9 @@ typedef struct {
79 78
80#ifdef API_SYSEX_ENABLE 79#ifdef API_SYSEX_ENABLE
81 #include "api_sysex.h" 80 #include "api_sysex.h"
81 // Allocate space for encoding overhead.
82 //The header and terminator are not stored to save a few bytes of precious ram
83 #define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
82#endif 84#endif
83 85
84// #if LUFA_VERSION_INTEGER < 0x120730 86// #if LUFA_VERSION_INTEGER < 0x120730