diff options
Diffstat (limited to 'quantum/api')
| -rw-r--r-- | quantum/api/api_sysex.c | 29 | ||||
| -rw-r--r-- | quantum/api/api_sysex.h | 10 |
2 files changed, 39 insertions, 0 deletions
diff --git a/quantum/api/api_sysex.c b/quantum/api/api_sysex.c new file mode 100644 index 000000000..a4a554e76 --- /dev/null +++ b/quantum/api/api_sysex.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #include "api_sysex.h" | ||
| 2 | |||
| 3 | void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length) { | ||
| 4 | // SEND_STRING("\nTX: "); | ||
| 5 | // for (uint8_t i = 0; i < length; i++) { | ||
| 6 | // send_byte(bytes[i]); | ||
| 7 | // SEND_STRING(" "); | ||
| 8 | // } | ||
| 9 | uint8_t * precode = malloc(sizeof(uint8_t) * (length + 2)); | ||
| 10 | precode[0] = message_type; | ||
| 11 | precode[1] = data_type; | ||
| 12 | memcpy(precode + 2, bytes, length); | ||
| 13 | uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 2))); | ||
| 14 | uint16_t encoded_length = sysex_encode(encoded, precode, length + 2); | ||
| 15 | uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5)); | ||
| 16 | array[0] = 0xF0; | ||
| 17 | array[1] = 0x00; | ||
| 18 | array[2] = 0x00; | ||
| 19 | array[3] = 0x00; | ||
| 20 | array[encoded_length + 4] = 0xF7; | ||
| 21 | memcpy(array + 4, encoded, encoded_length); | ||
| 22 | midi_send_array(&midi_device, encoded_length + 5, array); | ||
| 23 | |||
| 24 | // SEND_STRING("\nTD: "); | ||
| 25 | // for (uint8_t i = 0; i < encoded_length + 5; i++) { | ||
| 26 | // send_byte(array[i]); | ||
| 27 | // SEND_STRING(" "); | ||
| 28 | // } | ||
| 29 | } \ No newline at end of file | ||
diff --git a/quantum/api/api_sysex.h b/quantum/api/api_sysex.h new file mode 100644 index 000000000..b947b60e5 --- /dev/null +++ b/quantum/api/api_sysex.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef _API_SYSEX_H_ | ||
| 2 | #define _API_SYSEX_H_ | ||
| 3 | |||
| 4 | #include "api.h" | ||
| 5 | |||
| 6 | void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length); | ||
| 7 | |||
| 8 | #define SEND_BYTES(mt, dt, b, l) send_bytes_sysex(mt, dt, b, l) | ||
| 9 | |||
| 10 | #endif \ No newline at end of file | ||
