converted to 8bit messages

daktil_thumb_popravljen
Jack Humbert 2016-11-23 00:30:06 -05:00
parent 450a8fb5b6
commit 3d7aaa31e4
3 changed files with 70 additions and 53 deletions

View File

@ -25,5 +25,4 @@ ENV subproject=ez
ENV keymap=default ENV keymap=default
VOLUME /qmk VOLUME /qmk
WORKDIR /qmk WORKDIR /qmk
CMD make clean ; make keyboard=${keyboard} subproject=${subproject} keymap=${keymap}

View File

@ -76,6 +76,10 @@
#include "rgblight.h" #include "rgblight.h"
#endif #endif
#ifdef MIDI_ENABLE
#include "sysex_tools.h"
#endif
uint8_t keyboard_idle = 0; uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */ /* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1; uint8_t keyboard_protocol = 1;
@ -1124,8 +1128,16 @@ void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t
for (uint8_t place = 0; place < length; place++) { for (uint8_t place = 0; place < length; place++) {
// send_byte(*data); // send_byte(*data);
midi_buffer[start + place] = *data; midi_buffer[start + place] = *data;
if (*data == 0xF7 && midi_buffer[0] == 0xF0) if (*data == 0xF7) {
sysex_buffer_callback(device, start + place, midi_buffer); // 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);
sysex_buffer_callback(device, decode_length, decoded);
}
// SEND_STRING(" "); // SEND_STRING(" ");
data++; data++;
} }
@ -1161,32 +1173,35 @@ void encode_uint8_chunk(uint8_t data, uint8_t * pointer) {
*pointer++ = (data) & 0x7F; *pointer++ = (data) & 0x7F;
} }
void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { void dword_to_bytes(uint8_t * bytes, uint32_t dword) {
// uint8_t * pointer_copy = data; // use for debugging bytes[0] = (dword >> 24) & 0xFF;
bytes[1] = (dword >> 16) & 0xFF;
bytes[2] = (dword >> 8) & 0xFF;
bytes[3] = (dword >> 0) & 0xFF;
}
//data++; // i'm 98% sure there's a better way to do this void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) {
data++; // SEND_STRING("\nRX: ");
data++; // for (uint8_t i = 0; i < length; i++) {
data++; // send_byte(data[i]);
data++; // SEND_STRING(" ");
// }
switch (*data++) { switch (*data++) {
case 0x07: ; // Quantum action case 0x07: ; // Quantum action
break; break;
case 0x08: ; // Keyboard acion case 0x08: ; // Keyboard action
break; break;
case 0x09: ; // User action case 0x09: ; // User action
break; break;
case 0x12: ; // Set info on keyboard case 0x12: ; // Set info on keyboard
switch (*data++) { switch (*data++) {
case 0x02: ; // set default layer case 0x02: ; // set default layer
uint8_t default_layer = decode_uint8_chunk(data); eeconfig_update_default_layer(data[0] << 8 | data[1]);
eeconfig_update_default_layer(default_layer); default_layer_set((uint32_t)(data[0] << 8 | data[1]));
default_layer_set((uint32_t)default_layer);
break; break;
case 0x08: ; // set keymap options case 0x08: ; // set keymap options
uint8_t keymap_options = decode_uint8_chunk(data); eeconfig_update_keymap(data[0]);
eeconfig_update_keymap(keymap_options);
break; break;
} }
break; break;
@ -1196,42 +1211,37 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data)
send_bytes_sysex(0x00, NULL, 0); send_bytes_sysex(0x00, NULL, 0);
break; break;
case 0x01: ; // Get debug state case 0x01: ; // Get debug state
uint8_t debug[2]; uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) };
encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), debug); send_bytes_sysex(0x01, debug_bytes, 1);
send_bytes_sysex(0x01, debug, 2);
break; break;
case 0x02: ; // Get default layer case 0x02: ; // Get default layer
uint8_t default_layer[2]; uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) };
encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), default_layer); send_bytes_sysex(0x02, default_bytes, 1);
send_bytes_sysex(0x02, default_layer, 2);
break; break;
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
case 0x03: ; // Get backlight state case 0x03: ; // Get backlight state
uint8_t audio[2]; uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) };
encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), audio); send_bytes_sysex(0x03, audio_bytes, 1);
send_bytes_sysex(0x03, audio, 2);
#endif #endif
case 0x04: ; // Get layer state case 0x04: ; // Get layer state
uint8_t layers[5]; uint8_t layer_state_bytes[4];
encode_uint32_chunk(layer_state, layers); dword_to_bytes(layer_state_bytes, layer_state);
send_bytes_sysex(0x04, layers, 5); send_bytes_sysex(0x04, layer_state_bytes, 4);
break; break;
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
case 0x06: ; // Get backlight state case 0x06: ; // Get backlight state
uint8_t backlight[2]; uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) };
encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), backlight); send_bytes_sysex(0x06, backlight_bytes, 1);
send_bytes_sysex(0x06, backlight, 2);
#endif #endif
#ifdef RGBLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE
case 0x07: ; // Get rgblight state case 0x07: ; // Get rgblight state
uint8_t rgblight[2]; uint8_t rgblight_bytes[4];
encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), rgblight); dword_to_bytes(rgblight_bytes, eeprom_read_dword(EECONFIG_RGBLIGHT));
send_bytes_sysex(0x07, rgblight, 5); send_bytes_sysex(0x07, rgblight_bytes, 4);
#endif #endif
case 0x08: ; // Keymap options case 0x08: ; // Keymap options
uint8_t keymap_options[2]; uint8_t keymap_bytes[1] = { eeconfig_read_keymap() };
encode_uint8_chunk(eeconfig_read_keymap(), keymap_options); send_bytes_sysex(0x08, keymap_bytes, 1);
send_bytes_sysex(0x08, keymap_options, 2);
break; break;
} }
break; break;
@ -1239,26 +1249,18 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data)
case 0x27: ; // RGB LED functions case 0x27: ; // RGB LED functions
switch (*data++) { switch (*data++) {
case 0x00: ; // Update HSV case 0x00: ; // Update HSV
uint32_t hsv = decode_uint32_chunk(data); rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]);
rgblight_sethsv(((hsv >> 16) & 0xFFFF) % 360, (hsv >> 8) & 0xFF, hsv & 0xFF);
break; break;
case 0x01: ; // Update RGB case 0x01: ; // Update RGB
break; break;
case 0x02: ; // Update mode case 0x02: ; // Update mode
uint8_t rgb_mode = decode_uint8_chunk(data); rgblight_mode(data[0]);
rgblight_mode(rgb_mode);
break; break;
} }
break; break;
#endif #endif
} }
// SEND_STRING("\nDATA:\n");
// while (*pointer_copy != 0xF7) {
// send_byte(*pointer_copy++);
// SEND_STRING(" ");
// }
} }
void send_unicode_midi(uint32_t unicode) { void send_unicode_midi(uint32_t unicode) {
@ -1268,15 +1270,30 @@ void send_unicode_midi(uint32_t unicode) {
} }
void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) {
uint8_t * array = malloc(sizeof(uint8_t) * (length + 6)); // SEND_STRING("\nTX: ");
// for (uint8_t i = 0; i < length; i++) {
// send_byte(bytes[i]);
// SEND_STRING(" ");
// }
uint8_t * precode = malloc(sizeof(uint8_t) * (length + 1));
precode[0] = type;
memcpy(precode + 1, bytes, length);
uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 1)));
uint16_t encoded_length = sysex_encode(encoded, precode, length + 1);
uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5));
array[0] = 0xF0; array[0] = 0xF0;
array[1] = 0x00; array[1] = 0x00;
array[2] = 0x00; array[2] = 0x00;
array[3] = 0x00; array[3] = 0x00;
array[4] = type; array[encoded_length + 4] = 0xF7;
array[length + 5] = 0xF7; memcpy(array + 4, encoded, encoded_length);
memcpy(array + 5, bytes, length); midi_send_array(&midi_device, encoded_length + 5, array);
midi_send_array(&midi_device, length + 6, array);
// SEND_STRING("\nTD: ");
// for (uint8_t i = 0; i < encoded_length + 5; i++) {
// send_byte(array[i]);
// SEND_STRING(" ");
// }
} }
#endif #endif

View File

@ -4,6 +4,7 @@ SRC += midi.c \
midi_device.c \ midi_device.c \
bytequeue/bytequeue.c \ bytequeue/bytequeue.c \
bytequeue/interrupt_setting.c \ bytequeue/interrupt_setting.c \
sysex_tools.c \
$(LUFA_SRC_USBCLASS) $(LUFA_SRC_USBCLASS)
VPATH += $(TMK_PATH)/$(MIDI_DIR) VPATH += $(TMK_PATH)/$(MIDI_DIR)