diff options
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/common/host_driver.h | 9 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 63 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.h | 13 | ||||
-rw-r--r-- | tmk_core/protocol/midi.mk | 1 |
4 files changed, 70 insertions, 16 deletions
diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h index edb9e5dd9c..588d1c0be8 100644 --- a/tmk_core/common/host_driver.h +++ b/tmk_core/common/host_driver.h @@ -20,7 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdint.h> #include "report.h" - +#ifdef MIDI_ENABLE + #include "midi.h" +#endif typedef struct { uint8_t (*keyboard_leds)(void); @@ -28,6 +30,11 @@ typedef struct { void (*send_mouse)(report_mouse_t *); void (*send_system)(uint16_t); void (*send_consumer)(uint16_t); +#ifdef MIDI_ENABLE + void (*usb_send_func)(MidiDevice *, uint16_t, uint8_t, uint8_t, uint8_t); + void (*usb_get_midi)(MidiDevice *); + void (*midi_usb_init)(MidiDevice *); +#endif } host_driver_t; #endif diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 01c0e45b0b..39d4824b6b 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -51,6 +51,7 @@ #include "descriptor.h" #include "lufa.h" +#include "quantum.h" #ifdef NKRO_ENABLE #include "keycode_config.h" @@ -71,6 +72,14 @@ #include "virtser.h" #endif +#if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE) + #include "rgblight.h" +#endif + +#ifdef MIDI_ENABLE + #include "sysex_tools.h" +#endif + uint8_t keyboard_idle = 0; /* 0: Boot Protocol, 1: Report Protocol(default) */ uint8_t keyboard_protocol = 1; @@ -79,9 +88,9 @@ static uint8_t keyboard_led_stats = 0; static report_keyboard_t keyboard_report_sent; #ifdef MIDI_ENABLE -void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); -void usb_get_midi(MidiDevice * device); -void midi_usb_init(MidiDevice * device); +static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); +static void usb_get_midi(MidiDevice * device); +static void midi_usb_init(MidiDevice * device); #endif /* Host driver */ @@ -709,7 +718,7 @@ int8_t sendchar(uint8_t c) ******************************************************************************/ #ifdef MIDI_ENABLE -void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { +static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { MIDI_EventPacket_t event; event.Data1 = byte0; event.Data2 = byte1; @@ -769,7 +778,7 @@ void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byt USB_USBTask(); } -void usb_get_midi(MidiDevice * device) { +static void usb_get_midi(MidiDevice * device) { MIDI_EventPacket_t event; while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) { @@ -799,12 +808,12 @@ void usb_get_midi(MidiDevice * device) { USB_USBTask(); } -void midi_usb_init(MidiDevice * device){ +static void midi_usb_init(MidiDevice * device){ midi_device_init(device); midi_device_set_send_func(device, usb_send_func); midi_device_set_pre_input_process_func(device, usb_get_midi); - SetupHardware(); + // SetupHardware(); sei(); } @@ -1039,11 +1048,16 @@ int main(void) } #endif + keyboard_task(); + #ifdef MIDI_ENABLE midi_device_process(&midi_device); // MIDI_Task(); #endif - keyboard_task(); + +#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) + rgblight_task(); +#endif #ifdef VIRTSER_ENABLE virtser_task(); @@ -1077,15 +1091,38 @@ void fallthrough_callback(MidiDevice * device, #endif } + void cc_callback(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val) { //sending it back on the next channel - midi_send_cc(device, (chan + 1) % 16, num, val); + // midi_send_cc(device, (chan + 1) % 16, num, val); } -void sysex_callback(MidiDevice * device, - uint16_t start, uint8_t length, uint8_t * data) { - for (int i = 0; i < length; i++) - midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i)); +uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; + +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(": "); + 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); + } + // SEND_STRING(" "); + data++; + } + #endif } + + #endif diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h index aad08d6407..b11854101d 100644 --- a/tmk_core/protocol/lufa/lufa.h +++ b/tmk_core/protocol/lufa/lufa.h @@ -68,8 +68,17 @@ typedef struct { } __attribute__ ((packed)) report_extra_t; #ifdef MIDI_ENABLE -void MIDI_Task(void); -MidiDevice midi_device; + void MIDI_Task(void); + MidiDevice midi_device; + #define MIDI_SYSEX_BUFFER 32 +#endif + +#ifdef API_ENABLE + #include "api.h" +#endif + +#ifdef API_SYSEX_ENABLE + #include "api_sysex.h" #endif // #if LUFA_VERSION_INTEGER < 0x120730 diff --git a/tmk_core/protocol/midi.mk b/tmk_core/protocol/midi.mk index c85ae42ff2..4855b23d30 100644 --- a/tmk_core/protocol/midi.mk +++ b/tmk_core/protocol/midi.mk @@ -4,6 +4,7 @@ SRC += midi.c \ midi_device.c \ bytequeue/bytequeue.c \ bytequeue/interrupt_setting.c \ + sysex_tools.c \ $(LUFA_SRC_USBCLASS) VPATH += $(TMK_PATH)/$(MIDI_DIR)
\ No newline at end of file |