summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/lufa/lufa.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-12-30 11:05:50 -0500
committerGitHub <noreply@github.com>2016-12-30 11:05:50 -0500
commit2eced29675b50fbc695920fdceaa0e7521571b76 (patch)
treef26d870eb321fdc438518e8193d82bb958d1a07f /tmk_core/protocol/lufa/lufa.c
parent8a76075ca7bb2a8346053b8293e177853fe8e92f (diff)
parentdd685eceb2045371d38f24d454f1ab08ca7416f4 (diff)
Merge pull request #974 from fredizzimo/remove_malloc_from_sysex
API Sysex fixes
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
-rw-r--r--tmk_core/protocol/lufa/lufa.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 0971897706..6dd5959dc4 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1252,28 +1252,40 @@ void cc_callback(MidiDevice * device,
// midi_send_cc(device, (chan + 1) % 16, num, val);
}
+#ifdef API_SYSEX_ENABLE
uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
+#endif
void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
#ifdef API_SYSEX_ENABLE
// SEND_STRING("\n");
// send_word(start);
// SEND_STRING(": ");
+ // Don't store the header
+ int16_t pos = start - 4;
for (uint8_t place = 0; place < length; place++) {
// send_byte(*data);
- midi_buffer[start + place] = *data;
- if (*data == 0xF7) {
- // SEND_STRING("\nRD: ");
- // for (uint8_t i = 0; i < start + place + 1; i++){
- // send_byte(midi_buffer[i]);
- // SEND_STRING(" ");
- // }
- uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4)));
- uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4);
- process_api(decode_length, decoded);
+ if (pos >= 0) {
+ if (*data == 0xF7) {
+ // SEND_STRING("\nRD: ");
+ // for (uint8_t i = 0; i < start + place + 1; i++){
+ // send_byte(midi_buffer[i]);
+ // SEND_STRING(" ");
+ // }
+ const unsigned decoded_length = sysex_decoded_length(pos);
+ uint8_t decoded[API_SYSEX_MAX_SIZE];
+ sysex_decode(decoded, midi_buffer, pos);
+ process_api(decoded_length, decoded);
+ return;
+ }
+ else if (pos >= MIDI_SYSEX_BUFFER) {
+ return;
+ }
+ midi_buffer[pos] = *data;
}
// SEND_STRING(" ");
data++;
+ pos++;
}
#endif
}