diff options
| author | Erez Zukerman <bulk@ezuk.org> | 2016-11-29 08:16:04 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-29 08:16:04 -0500 |
| commit | 51ae6da99edd732ccdec6e102bd757e08950d23b (patch) | |
| tree | 53e316e1fbe468e0b1f65fd11e161ebc74c6ef70 /tmk_core/protocol | |
| parent | 7b219a7f6016dfe80c1c3db33bcf859e3e355d8d (diff) | |
| parent | f946d830f98da0161753d37da9659caa7469cf4f (diff) | |
| download | qmk_firmware-51ae6da99edd732ccdec6e102bd757e08950d23b.tar.gz qmk_firmware-51ae6da99edd732ccdec6e102bd757e08950d23b.zip | |
Merge pull request #918 from jackhumbert/wu5y7
Adds Ergodox EZ RGB lights (both sides using I2C) and implements API base, Midi SysEx API
Diffstat (limited to 'tmk_core/protocol')
| -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 |
3 files changed, 62 insertions, 15 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 | |||
| 74 | uint8_t keyboard_idle = 0; | 83 | uint8_t keyboard_idle = 0; |
| 75 | /* 0: Boot Protocol, 1: Report Protocol(default) */ | 84 | /* 0: Boot Protocol, 1: Report Protocol(default) */ |
| 76 | uint8_t keyboard_protocol = 1; | 85 | uint8_t keyboard_protocol = 1; |
| @@ -79,9 +88,9 @@ static uint8_t keyboard_led_stats = 0; | |||
| 79 | static report_keyboard_t keyboard_report_sent; | 88 | static report_keyboard_t keyboard_report_sent; |
| 80 | 89 | ||
| 81 | #ifdef MIDI_ENABLE | 90 | #ifdef MIDI_ENABLE |
| 82 | void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); | 91 | static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); |
| 83 | void usb_get_midi(MidiDevice * device); | 92 | static void usb_get_midi(MidiDevice * device); |
| 84 | void midi_usb_init(MidiDevice * device); | 93 | static 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 |
| 712 | void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { | 721 | static 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 | ||
| 772 | void usb_get_midi(MidiDevice * device) { | 781 | static 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 | ||
| 802 | void midi_usb_init(MidiDevice * device){ | 811 | static 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 | |||
| 1080 | void cc_callback(MidiDevice * device, | 1095 | void 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 | ||
| 1086 | void sysex_callback(MidiDevice * device, | 1101 | uint8_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++) | 1103 | void 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 |
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h index aad08d640..b11854101 100644 --- a/tmk_core/protocol/lufa/lufa.h +++ b/tmk_core/protocol/lufa/lufa.h | |||
| @@ -68,8 +68,17 @@ typedef struct { | |||
| 68 | } __attribute__ ((packed)) report_extra_t; | 68 | } __attribute__ ((packed)) report_extra_t; |
| 69 | 69 | ||
| 70 | #ifdef MIDI_ENABLE | 70 | #ifdef MIDI_ENABLE |
| 71 | void MIDI_Task(void); | 71 | void MIDI_Task(void); |
| 72 | MidiDevice midi_device; | 72 | MidiDevice midi_device; |
| 73 | #define MIDI_SYSEX_BUFFER 32 | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #ifdef API_ENABLE | ||
| 77 | #include "api.h" | ||
| 78 | #endif | ||
| 79 | |||
| 80 | #ifdef API_SYSEX_ENABLE | ||
| 81 | #include "api_sysex.h" | ||
| 73 | #endif | 82 | #endif |
| 74 | 83 | ||
| 75 | // #if LUFA_VERSION_INTEGER < 0x120730 | 84 | // #if LUFA_VERSION_INTEGER < 0x120730 |
diff --git a/tmk_core/protocol/midi.mk b/tmk_core/protocol/midi.mk index c85ae42ff..4855b23d3 100644 --- a/tmk_core/protocol/midi.mk +++ b/tmk_core/protocol/midi.mk | |||
| @@ -4,6 +4,7 @@ SRC += midi.c \ | |||
| 4 | midi_device.c \ | 4 | midi_device.c \ |
| 5 | bytequeue/bytequeue.c \ | 5 | bytequeue/bytequeue.c \ |
| 6 | bytequeue/interrupt_setting.c \ | 6 | bytequeue/interrupt_setting.c \ |
| 7 | sysex_tools.c \ | ||
| 7 | $(LUFA_SRC_USBCLASS) | 8 | $(LUFA_SRC_USBCLASS) |
| 8 | 9 | ||
| 9 | VPATH += $(TMK_PATH)/$(MIDI_DIR) \ No newline at end of file | 10 | VPATH += $(TMK_PATH)/$(MIDI_DIR) \ No newline at end of file |
