aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/lufa/lufa.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
-rw-r--r--tmk_core/protocol/lufa/lufa.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 01c0e45b0..39d4824b6 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -51,6 +51,7 @@
51 51
52#include "descriptor.h" 52#include "descriptor.h"
53#include "lufa.h" 53#include "lufa.h"
54#include "quantum.h"
54 55
55#ifdef NKRO_ENABLE 56#ifdef NKRO_ENABLE
56 #include "keycode_config.h" 57 #include "keycode_config.h"
@@ -71,6 +72,14 @@
71 #include "virtser.h" 72 #include "virtser.h"
72#endif 73#endif
73 74
75#if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE)
76 #include "rgblight.h"
77#endif
78
79#ifdef MIDI_ENABLE
80 #include "sysex_tools.h"
81#endif
82
74uint8_t keyboard_idle = 0; 83uint8_t keyboard_idle = 0;
75/* 0: Boot Protocol, 1: Report Protocol(default) */ 84/* 0: Boot Protocol, 1: Report Protocol(default) */
76uint8_t keyboard_protocol = 1; 85uint8_t keyboard_protocol = 1;
@@ -79,9 +88,9 @@ static uint8_t keyboard_led_stats = 0;
79static report_keyboard_t keyboard_report_sent; 88static report_keyboard_t keyboard_report_sent;
80 89
81#ifdef MIDI_ENABLE 90#ifdef MIDI_ENABLE
82void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); 91static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2);
83void usb_get_midi(MidiDevice * device); 92static void usb_get_midi(MidiDevice * device);
84void midi_usb_init(MidiDevice * device); 93static void midi_usb_init(MidiDevice * device);
85#endif 94#endif
86 95
87/* Host driver */ 96/* Host driver */
@@ -709,7 +718,7 @@ int8_t sendchar(uint8_t c)
709 ******************************************************************************/ 718 ******************************************************************************/
710 719
711#ifdef MIDI_ENABLE 720#ifdef MIDI_ENABLE
712void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { 721static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
713 MIDI_EventPacket_t event; 722 MIDI_EventPacket_t event;
714 event.Data1 = byte0; 723 event.Data1 = byte0;
715 event.Data2 = byte1; 724 event.Data2 = byte1;
@@ -769,7 +778,7 @@ void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byt
769 USB_USBTask(); 778 USB_USBTask();
770} 779}
771 780
772void usb_get_midi(MidiDevice * device) { 781static void usb_get_midi(MidiDevice * device) {
773 MIDI_EventPacket_t event; 782 MIDI_EventPacket_t event;
774 while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) { 783 while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) {
775 784
@@ -799,12 +808,12 @@ void usb_get_midi(MidiDevice * device) {
799 USB_USBTask(); 808 USB_USBTask();
800} 809}
801 810
802void midi_usb_init(MidiDevice * device){ 811static void midi_usb_init(MidiDevice * device){
803 midi_device_init(device); 812 midi_device_init(device);
804 midi_device_set_send_func(device, usb_send_func); 813 midi_device_set_send_func(device, usb_send_func);
805 midi_device_set_pre_input_process_func(device, usb_get_midi); 814 midi_device_set_pre_input_process_func(device, usb_get_midi);
806 815
807 SetupHardware(); 816 // SetupHardware();
808 sei(); 817 sei();
809} 818}
810 819
@@ -1039,11 +1048,16 @@ int main(void)
1039 } 1048 }
1040 #endif 1049 #endif
1041 1050
1051 keyboard_task();
1052
1042#ifdef MIDI_ENABLE 1053#ifdef MIDI_ENABLE
1043 midi_device_process(&midi_device); 1054 midi_device_process(&midi_device);
1044 // MIDI_Task(); 1055 // MIDI_Task();
1045#endif 1056#endif
1046 keyboard_task(); 1057
1058#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE)
1059 rgblight_task();
1060#endif
1047 1061
1048#ifdef VIRTSER_ENABLE 1062#ifdef VIRTSER_ENABLE
1049 virtser_task(); 1063 virtser_task();
@@ -1077,15 +1091,38 @@ void fallthrough_callback(MidiDevice * device,
1077#endif 1091#endif
1078} 1092}
1079 1093
1094
1080void cc_callback(MidiDevice * device, 1095void cc_callback(MidiDevice * device,
1081 uint8_t chan, uint8_t num, uint8_t val) { 1096 uint8_t chan, uint8_t num, uint8_t val) {
1082 //sending it back on the next channel 1097 //sending it back on the next channel
1083 midi_send_cc(device, (chan + 1) % 16, num, val); 1098 // midi_send_cc(device, (chan + 1) % 16, num, val);
1084} 1099}
1085 1100
1086void sysex_callback(MidiDevice * device, 1101uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
1087 uint16_t start, uint8_t length, uint8_t * data) { 1102
1088 for (int i = 0; i < length; i++) 1103void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
1089 midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i)); 1104 #ifdef API_SYSEX_ENABLE
1105 // SEND_STRING("\n");
1106 // send_word(start);
1107 // SEND_STRING(": ");
1108 for (uint8_t place = 0; place < length; place++) {
1109 // send_byte(*data);
1110 midi_buffer[start + place] = *data;
1111 if (*data == 0xF7) {
1112 // SEND_STRING("\nRD: ");
1113 // for (uint8_t i = 0; i < start + place + 1; i++){
1114 // send_byte(midi_buffer[i]);
1115 // SEND_STRING(" ");
1116 // }
1117 uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4)));
1118 uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4);
1119 process_api(decode_length, decoded);
1120 }
1121 // SEND_STRING(" ");
1122 data++;
1123 }
1124 #endif
1090} 1125}
1126
1127
1091#endif 1128#endif