diff options
author | Jack Humbert <jack.humb@gmail.com> | 2016-12-30 11:05:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-30 11:05:50 -0500 |
commit | 2eced29675b50fbc695920fdceaa0e7521571b76 (patch) | |
tree | f26d870eb321fdc438518e8193d82bb958d1a07f /tmk_core | |
parent | 8a76075ca7bb2a8346053b8293e177853fe8e92f (diff) | |
parent | dd685eceb2045371d38f24d454f1ab08ca7416f4 (diff) | |
download | qmk_firmware-2eced29675b50fbc695920fdceaa0e7521571b76.tar.gz qmk_firmware-2eced29675b50fbc695920fdceaa0e7521571b76.zip |
Merge pull request #974 from fredizzimo/remove_malloc_from_sysex
API Sysex fixes
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 32 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.h | 4 |
2 files changed, 25 insertions, 11 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 } diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h index b11854101d..a049fd43c9 100644 --- a/tmk_core/protocol/lufa/lufa.h +++ b/tmk_core/protocol/lufa/lufa.h @@ -70,7 +70,6 @@ typedef struct { #ifdef MIDI_ENABLE void MIDI_Task(void); MidiDevice midi_device; - #define MIDI_SYSEX_BUFFER 32 #endif #ifdef API_ENABLE @@ -79,6 +78,9 @@ typedef struct { #ifdef API_SYSEX_ENABLE #include "api_sysex.h" + // Allocate space for encoding overhead. + //The header and terminator are not stored to save a few bytes of precious ram + #define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0)) #endif // #if LUFA_VERSION_INTEGER < 0x120730 |