aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-11-26 15:37:46 -0500
committerJack Humbert <jack.humb@gmail.com>2016-11-26 15:38:44 -0500
commit7edac212c8ed8442bf4207e70dc8194631b2bf27 (patch)
treefd1905e1a24c237daa0e3e4172fe74f273d6b646
parentf25596b8dc2f15f620c07164d871023d9284618c (diff)
downloadqmk_firmware-7edac212c8ed8442bf4207e70dc8194631b2bf27.tar.gz
qmk_firmware-7edac212c8ed8442bf4207e70dc8194631b2bf27.zip
separated into api files/folder
-rw-r--r--build_keyboard.mk8
-rw-r--r--common.mk1
-rw-r--r--keyboards/ergodox/keymaps/jack/keymap.c2
-rw-r--r--keyboards/ergodox/rules.mk1
-rw-r--r--keyboards/planck/rules.mk1
-rw-r--r--keyboards/preonic/keymaps/default/Makefile22
-rw-r--r--keyboards/preonic/rules.mk3
-rw-r--r--quantum/api.c178
-rw-r--r--quantum/api.h59
-rw-r--r--quantum/api/api_sysex.c29
-rw-r--r--quantum/api/api_sysex.h10
-rw-r--r--quantum/quantum.c6
-rw-r--r--quantum/quantum.h2
-rw-r--r--tmk_core/protocol/lufa/lufa.c203
-rw-r--r--tmk_core/protocol/lufa/lufa.h61
15 files changed, 303 insertions, 283 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 42f8f8ac7..c1e554003 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -131,6 +131,14 @@ ifndef CUSTOM_MATRIX
131 SRC += $(QUANTUM_DIR)/matrix.c 131 SRC += $(QUANTUM_DIR)/matrix.c
132endif 132endif
133 133
134ifeq ($(strip $(API_SYSEX_ENABLE)), yes)
135 OPT_DEFS += -DAPI_SYSEX_ENABLE
136 SRC += $(QUANTUM_DIR)/api/api_sysex.c
137 OPT_DEFS += -DAPI_ENABLE
138 SRC += $(QUANTUM_DIR)/api.c
139 MIDI_ENABLE=yes
140endif
141
134ifeq ($(strip $(MIDI_ENABLE)), yes) 142ifeq ($(strip $(MIDI_ENABLE)), yes)
135 OPT_DEFS += -DMIDI_ENABLE 143 OPT_DEFS += -DMIDI_ENABLE
136 SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c 144 SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
diff --git a/common.mk b/common.mk
index 18751cd5a..c4b9394a2 100644
--- a/common.mk
+++ b/common.mk
@@ -23,4 +23,5 @@ COMMON_VPATH += $(QUANTUM_PATH)
23COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras 23COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras
24COMMON_VPATH += $(QUANTUM_PATH)/audio 24COMMON_VPATH += $(QUANTUM_PATH)/audio
25COMMON_VPATH += $(QUANTUM_PATH)/process_keycode 25COMMON_VPATH += $(QUANTUM_PATH)/process_keycode
26COMMON_VPATH += $(QUANTUM_PATH)/api
26COMMON_VPATH += $(SERIAL_PATH) \ No newline at end of file 27COMMON_VPATH += $(SERIAL_PATH) \ No newline at end of file
diff --git a/keyboards/ergodox/keymaps/jack/keymap.c b/keyboards/ergodox/keymaps/jack/keymap.c
index eb41f1212..9cb80c59d 100644
--- a/keyboards/ergodox/keymaps/jack/keymap.c
+++ b/keyboards/ergodox/keymaps/jack/keymap.c
@@ -91,7 +91,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
91 break; 91 break;
92 case 2: 92 case 2:
93 if (record->event.pressed) { // For resetting EEPROM 93 if (record->event.pressed) { // For resetting EEPROM
94 send_unicode_midi(0x0CA0); 94 api_send_unicode(0x0CA0);
95 } 95 }
96 break; 96 break;
97 } 97 }
diff --git a/keyboards/ergodox/rules.mk b/keyboards/ergodox/rules.mk
index add64ec76..2e501e81b 100644
--- a/keyboards/ergodox/rules.mk
+++ b/keyboards/ergodox/rules.mk
@@ -24,6 +24,5 @@ COMMAND_ENABLE ?= yes # Commands for debug and configuration
24CUSTOM_MATRIX ?= yes # Custom matrix file for the ErgoDox EZ 24CUSTOM_MATRIX ?= yes # Custom matrix file for the ErgoDox EZ
25SLEEP_LED_ENABLE ?= yes # Breathing sleep LED during USB suspend 25SLEEP_LED_ENABLE ?= yes # Breathing sleep LED during USB suspend
26NKRO_ENABLE ?= yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 26NKRO_ENABLE ?= yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
27MIDI_ENABLE ?= no # MIDI controls
28UNICODE_ENABLE ?= yes # Unicode 27UNICODE_ENABLE ?= yes # Unicode
29ONEHAND_ENABLE ?= yes # Allow swapping hands of keyboard 28ONEHAND_ENABLE ?= yes # Allow swapping hands of keyboard
diff --git a/keyboards/planck/rules.mk b/keyboards/planck/rules.mk
index 25db53a31..ccee97271 100644
--- a/keyboards/planck/rules.mk
+++ b/keyboards/planck/rules.mk
@@ -62,6 +62,7 @@ AUDIO_ENABLE ?= no # Audio output on port C6
62UNICODE_ENABLE ?= no # Unicode 62UNICODE_ENABLE ?= no # Unicode
63BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID 63BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID
64RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. 64RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
65API_SYSEX_ENABLE = yes
65 66
66# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 67# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
67SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend \ No newline at end of file 68SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend \ No newline at end of file
diff --git a/keyboards/preonic/keymaps/default/Makefile b/keyboards/preonic/keymaps/default/Makefile
index 581e08cd0..3d4659ceb 100644
--- a/keyboards/preonic/keymaps/default/Makefile
+++ b/keyboards/preonic/keymaps/default/Makefile
@@ -1,25 +1,3 @@
1
2
3# Build Options
4# change to "no" to disable the options, or define them in the Makefile in
5# the appropriate keymap folder that will get included automatically
6#
7BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
8MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
9EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
10CONSOLE_ENABLE = no # Console for debug(+400)
11COMMAND_ENABLE = yes # Commands for debug and configuration
12NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
13BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
14MIDI_ENABLE = no # MIDI controls
15AUDIO_ENABLE = yes # Audio output on port C6
16UNICODE_ENABLE = no # Unicode
17BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
18RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
19
20# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
21SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
22
23ifndef QUANTUM_DIR 1ifndef QUANTUM_DIR
24 include ../../../../Makefile 2 include ../../../../Makefile
25endif \ No newline at end of file 3endif \ No newline at end of file
diff --git a/keyboards/preonic/rules.mk b/keyboards/preonic/rules.mk
index d0f3a3a1c..c4ce2aacc 100644
--- a/keyboards/preonic/rules.mk
+++ b/keyboards/preonic/rules.mk
@@ -53,7 +53,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
53# the appropriate keymap folder that will get included automatically 53# the appropriate keymap folder that will get included automatically
54# 54#
55BOOTMAGIC_ENABLE ?= no # Virtual DIP switch configuration(+1000) 55BOOTMAGIC_ENABLE ?= no # Virtual DIP switch configuration(+1000)
56MOUSEKEY_ENABLE ?= yes # Mouse keys(+4700) 56MOUSEKEY_ENABLE ?= no # Mouse keys(+4700)
57EXTRAKEY_ENABLE ?= yes # Audio control and System control(+450) 57EXTRAKEY_ENABLE ?= yes # Audio control and System control(+450)
58CONSOLE_ENABLE ?= no # Console for debug(+400) 58CONSOLE_ENABLE ?= no # Console for debug(+400)
59COMMAND_ENABLE ?= yes # Commands for debug and configuration 59COMMAND_ENABLE ?= yes # Commands for debug and configuration
@@ -64,6 +64,7 @@ AUDIO_ENABLE ?= no # Audio output on port C6
64UNICODE_ENABLE ?= no # Unicode 64UNICODE_ENABLE ?= no # Unicode
65BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID 65BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID
66RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. 66RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
67API_SYSEX_ENABLE ?= yes
67 68
68# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 69# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
69SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend \ No newline at end of file 70SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend \ No newline at end of file
diff --git a/quantum/api.c b/quantum/api.c
new file mode 100644
index 000000000..4ca3b9676
--- /dev/null
+++ b/quantum/api.c
@@ -0,0 +1,178 @@
1#include "api.h"
2#include "quantum.h"
3
4void dword_to_bytes(uint32_t dword, uint8_t * bytes) {
5 bytes[0] = (dword >> 24) & 0xFF;
6 bytes[1] = (dword >> 16) & 0xFF;
7 bytes[2] = (dword >> 8) & 0xFF;
8 bytes[3] = (dword >> 0) & 0xFF;
9}
10
11uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index) {
12 return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3];
13}
14
15__attribute__ ((weak))
16bool process_api_quantum(uint8_t length, uint8_t * data) {
17 return process_api_keyboard(length, data);
18}
19
20__attribute__ ((weak))
21bool process_api_keyboard(uint8_t length, uint8_t * data) {
22 return process_api_user(length, data);
23}
24
25__attribute__ ((weak))
26bool process_api_user(uint8_t length, uint8_t * data) {
27 return true;
28}
29
30void process_api(uint16_t length, uint8_t * data) {
31 // SEND_STRING("\nRX: ");
32 // for (uint8_t i = 0; i < length; i++) {
33 // send_byte(data[i]);
34 // SEND_STRING(" ");
35 // }
36 if (!process_api_quantum(length, data))
37 return;
38
39 switch (data[0]) {
40 case MT_SET_DATA:
41 switch (data[1]) {
42 case DT_DEFAULT_LAYER: {
43 eeconfig_update_default_layer(data[2]);
44 default_layer_set((uint32_t)(data[2]));
45 break;
46 }
47 case DT_KEYMAP_OPTIONS: {
48 eeconfig_update_keymap(data[2]);
49 break;
50 }
51 case DT_RGBLIGHT: {
52 #ifdef RGBLIGHT_ENABLE
53 uint32_t rgblight = bytes_to_dword(data, 2);
54 rgblight_update_dword(rgblight);
55 #endif
56 break;
57 }
58 }
59 case MT_GET_DATA:
60 switch (data[1]) {
61 case DT_HANDSHAKE: {
62 MT_GET_DATA_ACK(DT_HANDSHAKE, NULL, 0);
63 break;
64 }
65 case DT_DEBUG: {
66 uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) };
67 MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1);
68 break;
69 }
70 case DT_DEFAULT_LAYER: {
71 uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) };
72 MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1);
73 break;
74 }
75 case DT_CURRENT_LAYER: {
76 uint8_t layer_state_bytes[4];
77 dword_to_bytes(layer_state, layer_state_bytes);
78 MT_GET_DATA_ACK(DT_CURRENT_LAYER, layer_state_bytes, 4);
79 break;
80 }
81 case DT_AUDIO: {
82 #ifdef AUDIO_ENABLE
83 uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) };
84 MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1);
85 #else
86 MT_GET_DATA_ACK(DT_AUDIO, NULL, 0);
87 #endif
88 break;
89 }
90 case DT_BACKLIGHT: {
91 #ifdef BACKLIGHT_ENABLE
92 uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) };
93 MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1);
94 #else
95 MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0);
96 #endif
97 break;
98 }
99 case DT_RGBLIGHT: {
100 #ifdef RGBLIGHT_ENABLE
101 uint8_t rgblight_bytes[4];
102 dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes);
103 MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4);
104 #else
105 MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0);
106 #endif
107 break;
108 }
109 case DT_KEYMAP_OPTIONS: {
110 uint8_t keymap_bytes[1] = { eeconfig_read_keymap() };
111 MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1);
112 break;
113 }
114 case DT_KEYMAP_SIZE: {
115 uint8_t keymap_size[2] = {MATRIX_ROWS, MATRIX_COLS};
116 MT_GET_DATA_ACK(DT_KEYMAP_SIZE, keymap_size, 2);
117 break;
118 }
119 case DT_KEYMAP: {
120 uint8_t keymap_data[MATRIX_ROWS * MATRIX_COLS * 4 + 3];
121 keymap_data[0] = data[2];
122 keymap_data[1] = MATRIX_ROWS;
123 keymap_data[2] = MATRIX_COLS;
124 for (int i = 0; i < MATRIX_ROWS; i++) {
125 for (int j = 0; j < MATRIX_COLS; j++) {
126 keymap_data[3 + (i*MATRIX_COLS*2) + (j*2)] = pgm_read_word(&keymaps[data[2]][i][j]) >> 8;
127 keymap_data[3 + (i*MATRIX_COLS*2) + (j*2) + 1] = pgm_read_word(&keymaps[data[2]][i][j]) & 0xFF;
128 }
129 }
130 MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, MATRIX_ROWS * MATRIX_COLS * 4 + 3);
131 // uint8_t keymap_data[5];
132 // keymap_data[0] = data[2];
133 // keymap_data[1] = data[3];
134 // keymap_data[2] = data[4];
135 // keymap_data[3] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) >> 8;
136 // keymap_data[4] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) & 0xFF;
137
138 // MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, 5);
139 break;
140 }
141 default:
142 break;
143 }
144 break;
145 case MT_SET_DATA_ACK:
146 case MT_GET_DATA_ACK:
147 break;
148 case MT_SEND_DATA:
149 break;
150 case MT_SEND_DATA_ACK:
151 break;
152 case MT_EXE_ACTION:
153 break;
154 case MT_EXE_ACTION_ACK:
155 break;
156 case MT_TYPE_ERROR:
157 break;
158 default: ; // command not recognised
159 SEND_BYTES(MT_TYPE_ERROR, DT_NONE, data, length);
160 break;
161
162 // #ifdef RGBLIGHT_ENABLE
163 // case 0x27: ; // RGB LED functions
164 // switch (*data++) {
165 // case 0x00: ; // Update HSV
166 // rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]);
167 // break;
168 // case 0x01: ; // Update RGB
169 // break;
170 // case 0x02: ; // Update mode
171 // rgblight_mode(data[0]);
172 // break;
173 // }
174 // break;
175 // #endif
176 }
177
178} \ No newline at end of file
diff --git a/quantum/api.h b/quantum/api.h
new file mode 100644
index 000000000..00dcdb895
--- /dev/null
+++ b/quantum/api.h
@@ -0,0 +1,59 @@
1#ifndef _API_H_
2#define _API_H_
3
4#include "lufa.h"
5
6enum MESSAGE_TYPE {
7 MT_GET_DATA = 0x10, // Get data from keyboard
8 MT_GET_DATA_ACK = 0x11, // returned data to process (ACK)
9 MT_SET_DATA = 0x20, // Set data on keyboard
10 MT_SET_DATA_ACK = 0x21, // returned data to confirm (ACK)
11 MT_SEND_DATA = 0x30, // Sending data/action from keyboard
12 MT_SEND_DATA_ACK = 0x31, // returned data/action confirmation (ACK)
13 MT_EXE_ACTION = 0x40, // executing actions on keyboard
14 MT_EXE_ACTION_ACK =0x41, // return confirmation/value (ACK)
15 MT_TYPE_ERROR = 0x80 // type not recofgnised (ACK)
16};
17
18enum DATA_TYPE {
19 DT_NONE = 0x00,
20 DT_HANDSHAKE,
21 DT_DEFAULT_LAYER,
22 DT_CURRENT_LAYER,
23 DT_KEYMAP_OPTIONS,
24 DT_BACKLIGHT,
25 DT_RGBLIGHT,
26 DT_UNICODE,
27 DT_DEBUG,
28 DT_AUDIO,
29 DT_QUANTUM_ACTION,
30 DT_KEYBOARD_ACTION,
31 DT_USER_ACTION,
32 DT_KEYMAP_SIZE,
33 DT_KEYMAP
34};
35
36void dword_to_bytes(uint32_t dword, uint8_t * bytes);
37uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index);
38
39#define MT_GET_DATA(data_type, data, length) SEND_BYTES(MT_GET_DATA, data_type, data, length)
40#define MT_GET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_GET_DATA_ACK, data_type, data, length)
41#define MT_SET_DATA(data_type, data, length) SEND_BYTES(MT_SET_DATA, data_type, data, length)
42#define MT_SET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_SET_DATA_ACK, data_type, data, length)
43#define MT_SEND_DATA(data_type, data, length) SEND_BYTES(MT_SEND_DATA, data_type, data, length)
44#define MT_SEND_DATA_ACK(data_type, data, length) SEND_BYTES(MT_SEND_DATA_ACK, data_type, data, length)
45#define MT_EXE_ACTION(data_type, data, length) SEND_BYTES(MT_EXE_ACTION, data_type, data, length)
46#define MT_EXE_ACTION_ACK(data_type, data, length) SEND_BYTES(MT_EXE_ACTION_ACK, data_type, data, length)
47
48void process_api(uint16_t length, uint8_t * data);
49
50__attribute__ ((weak))
51bool process_api_quantum(uint8_t length, uint8_t * data);
52
53__attribute__ ((weak))
54bool process_api_keyboard(uint8_t length, uint8_t * data);
55
56__attribute__ ((weak))
57bool process_api_user(uint8_t length, uint8_t * data);
58
59#endif \ No newline at end of file
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
3void 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
6void 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
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 8372a7adc..f653564a6 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -847,12 +847,12 @@ void send_nibble(uint8_t number) {
847 } 847 }
848} 848}
849 849
850void send_unicode_midi(uint32_t unicode) { 850void api_send_unicode(uint32_t unicode) {
851 #ifdef MIDI_ENABLE 851#ifdef API_ENABLE
852 uint8_t chunk[4]; 852 uint8_t chunk[4];
853 dword_to_bytes(unicode, chunk); 853 dword_to_bytes(unicode, chunk);
854 MT_SEND_DATA(DT_UNICODE, chunk, 5); 854 MT_SEND_DATA(DT_UNICODE, chunk, 5);
855 #endif 855#endif
856} 856}
857 857
858__attribute__ ((weak)) 858__attribute__ ((weak))
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 316da15b9..e6adf974a 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -119,6 +119,6 @@ void send_nibble(uint8_t number);
119void led_set_user(uint8_t usb_led); 119void led_set_user(uint8_t usb_led);
120void led_set_kb(uint8_t usb_led); 120void led_set_kb(uint8_t usb_led);
121 121
122void send_unicode_midi(uint32_t unicode); 122void api_send_unicode(uint32_t unicode);
123 123
124#endif 124#endif
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index aa2e781c8..39d4824b6 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1091,37 +1091,17 @@ void fallthrough_callback(MidiDevice * device,
1091#endif 1091#endif
1092} 1092}
1093 1093
1094#ifdef RGB_MIDI
1095 rgblight_config_t rgblight_config;
1096#endif
1097 1094
1098void cc_callback(MidiDevice * device, 1095void cc_callback(MidiDevice * device,
1099 uint8_t chan, uint8_t num, uint8_t val) { 1096 uint8_t chan, uint8_t num, uint8_t val) {
1100 //sending it back on the next channel 1097 //sending it back on the next channel
1101 // midi_send_cc(device, (chan + 1) % 16, num, val); 1098 // midi_send_cc(device, (chan + 1) % 16, num, val);
1102 #ifdef RGB_MIDI
1103 rgblight_config.raw = eeconfig_read_rgblight();
1104 switch (num) {
1105 case 14:
1106 rgblight_config.hue = val * 360 / 127;
1107 break;
1108 case 15:
1109 rgblight_config.sat = val << 1;
1110 break;
1111 case 16:
1112 rgblight_config.val = val << 1;
1113 break;
1114 }
1115 rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
1116 #endif
1117} 1099}
1118 1100
1119uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; 1101uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
1120 1102
1121void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) { 1103void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) {
1122 // for (int i = 0; i < length; i++) 1104 #ifdef API_SYSEX_ENABLE
1123 // midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i));
1124 // if (start == 0x27) {
1125 // SEND_STRING("\n"); 1105 // SEND_STRING("\n");
1126 // send_word(start); 1106 // send_word(start);
1127 // SEND_STRING(": "); 1107 // SEND_STRING(": ");
@@ -1136,190 +1116,13 @@ void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t
1136 // } 1116 // }
1137 uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4))); 1117 uint8_t * decoded = malloc(sizeof(uint8_t) * (sysex_decoded_length(start + place - 4)));
1138 uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4); 1118 uint16_t decode_length = sysex_decode(decoded, midi_buffer + 4, start + place - 4);
1139 sysex_buffer_callback(device, decode_length, decoded); 1119 process_api(decode_length, decoded);
1140 } 1120 }
1141 // SEND_STRING(" "); 1121 // SEND_STRING(" ");
1142 data++; 1122 data++;
1143 } 1123 }
1144 // } 1124 #endif
1145
1146}
1147
1148void dword_to_bytes(uint32_t dword, uint8_t * bytes) {
1149 bytes[0] = (dword >> 24) & 0xFF;
1150 bytes[1] = (dword >> 16) & 0xFF;
1151 bytes[2] = (dword >> 8) & 0xFF;
1152 bytes[3] = (dword >> 0) & 0xFF;
1153}
1154
1155uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index) {
1156 return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3];
1157}
1158
1159void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint8_t length) {
1160 // SEND_STRING("\nTX: ");
1161 // for (uint8_t i = 0; i < length; i++) {
1162 // send_byte(bytes[i]);
1163 // SEND_STRING(" ");
1164 // }
1165 uint8_t * precode = malloc(sizeof(uint8_t) * (length + 2));
1166 precode[0] = message_type;
1167 precode[1] = data_type;
1168 memcpy(precode + 2, bytes, length);
1169 uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 2)));
1170 uint16_t encoded_length = sysex_encode(encoded, precode, length + 2);
1171 uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5));
1172 array[0] = 0xF0;
1173 array[1] = 0x00;
1174 array[2] = 0x00;
1175 array[3] = 0x00;
1176 array[encoded_length + 4] = 0xF7;
1177 memcpy(array + 4, encoded, encoded_length);
1178 midi_send_array(&midi_device, encoded_length + 5, array);
1179
1180 // SEND_STRING("\nTD: ");
1181 // for (uint8_t i = 0; i < encoded_length + 5; i++) {
1182 // send_byte(array[i]);
1183 // SEND_STRING(" ");
1184 // }
1185}
1186
1187__attribute__ ((weak))
1188bool sysex_process_quantum(uint8_t length, uint8_t * data) {
1189 return sysex_process_keyboard(length, data);
1190}
1191
1192__attribute__ ((weak))
1193bool sysex_process_keyboard(uint8_t length, uint8_t * data) {
1194 return sysex_process_user(length, data);
1195}
1196
1197__attribute__ ((weak))
1198bool sysex_process_user(uint8_t length, uint8_t * data) {
1199 return true;
1200} 1125}
1201 1126
1202void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) {
1203 // SEND_STRING("\nRX: ");
1204 // for (uint8_t i = 0; i < length; i++) {
1205 // send_byte(data[i]);
1206 // SEND_STRING(" ");
1207 // }
1208 if (!sysex_process_quantum(length, data))
1209 return;
1210
1211 switch (data[0]) {
1212 case MT_SET_DATA:
1213 switch (data[1]) {
1214 case DT_DEFAULT_LAYER: {
1215 eeconfig_update_default_layer(data[2]);
1216 default_layer_set((uint32_t)(data[2]));
1217 break;
1218 }
1219 case DT_KEYMAP_OPTIONS: {
1220 eeconfig_update_keymap(data[2]);
1221 break;
1222 }
1223 case DT_RGBLIGHT: {
1224 #ifdef RGBLIGHT_ENABLE
1225 uint32_t rgblight = bytes_to_dword(data, 2);
1226 rgblight_update_dword(rgblight);
1227 #endif
1228 break;
1229 }
1230 }
1231 case MT_GET_DATA:
1232 switch (data[1]) {
1233 case DT_HANDSHAKE: {
1234 MT_GET_DATA_ACK(DT_HANDSHAKE, NULL, 0);
1235 break;
1236 }
1237 case DT_DEBUG: {
1238 uint8_t debug_bytes[1] = { eeprom_read_byte(EECONFIG_DEBUG) };
1239 MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1);
1240 break;
1241 }
1242 case DT_DEFAULT_LAYER: {
1243 uint8_t default_bytes[1] = { eeprom_read_byte(EECONFIG_DEFAULT_LAYER) };
1244 MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1);
1245 break;
1246 }
1247 case DT_CURRENT_LAYER: {
1248 uint8_t layer_state_bytes[4];
1249 dword_to_bytes(layer_state, layer_state_bytes);
1250 MT_GET_DATA_ACK(DT_CURRENT_LAYER, layer_state_bytes, 4);
1251 break;
1252 }
1253 case DT_AUDIO: {
1254 #ifdef AUDIO_ENABLE
1255 uint8_t audio_bytes[1] = { eeprom_read_byte(EECONFIG_AUDIO) };
1256 MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1);
1257 #else
1258 MT_GET_DATA_ACK(DT_AUDIO, NULL, 0);
1259 #endif
1260 break;
1261 }
1262 case DT_BACKLIGHT: {
1263 #ifdef BACKLIGHT_ENABLE
1264 uint8_t backlight_bytes[1] = { eeprom_read_byte(EECONFIG_BACKLIGHT) };
1265 MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1);
1266 #else
1267 MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0);
1268 #endif
1269 break;
1270 }
1271 case DT_RGBLIGHT: {
1272 #ifdef RGBLIGHT_ENABLE
1273 uint8_t rgblight_bytes[4];
1274 dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes);
1275 MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4);
1276 #else
1277 MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0);
1278 #endif
1279 break;
1280 }
1281 case DT_KEYMAP_OPTIONS: {
1282 uint8_t keymap_bytes[1] = { eeconfig_read_keymap() };
1283 MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1);
1284 break;
1285 }
1286 default:
1287 break;
1288 }
1289 break;
1290 case MT_SET_DATA_ACK:
1291 case MT_GET_DATA_ACK:
1292 break;
1293 case MT_SEND_DATA:
1294 break;
1295 case MT_SEND_DATA_ACK:
1296 break;
1297 case MT_EXE_ACTION:
1298 break;
1299 case MT_EXE_ACTION_ACK:
1300 break;
1301 case MT_TYPE_ERROR:
1302 break;
1303 default: ; // command not recognised
1304 send_bytes_sysex(MT_TYPE_ERROR, DT_NONE, data, length);
1305 break;
1306
1307 // #ifdef RGBLIGHT_ENABLE
1308 // case 0x27: ; // RGB LED functions
1309 // switch (*data++) {
1310 // case 0x00: ; // Update HSV
1311 // rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]);
1312 // break;
1313 // case 0x01: ; // Update RGB
1314 // break;
1315 // case 0x02: ; // Update mode
1316 // rgblight_mode(data[0]);
1317 // break;
1318 // }
1319 // break;
1320 // #endif
1321 }
1322
1323}
1324 1127
1325#endif 1128#endif
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index 0962dda8d..b11854101 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -68,64 +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 #define MIDI_SYSEX_BUFFER 16
72 void MIDI_Task(void); 71 void MIDI_Task(void);
73 MidiDevice midi_device; 72 MidiDevice midi_device;
73 #define MIDI_SYSEX_BUFFER 32
74#endif
74 75
75 void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data); 76#ifdef API_ENABLE
76 void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data); 77 #include "api.h"
77 void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint8_t length); 78#endif
78 void dword_to_bytes(uint32_t dword, uint8_t * bytes);
79 uint32_t bytes_to_dword(uint8_t * bytes, uint8_t index);
80
81 __attribute__ ((weak))
82 bool sysex_process_quantum(uint8_t length, uint8_t * data);
83
84 __attribute__ ((weak))
85 bool sysex_process_keyboard(uint8_t length, uint8_t * data);
86
87 __attribute__ ((weak))
88 bool sysex_process_user(uint8_t length, uint8_t * data);
89
90 enum MESSAGE_TYPE {
91 MT_GET_DATA = 0x10, // Get data from keyboard
92 MT_GET_DATA_ACK = 0x11, // returned data to process (ACK)
93 MT_SET_DATA = 0x20, // Set data on keyboard
94 MT_SET_DATA_ACK = 0x21, // returned data to confirm (ACK)
95 MT_SEND_DATA = 0x30, // Sending data/action from keyboard
96 MT_SEND_DATA_ACK = 0x31, // returned data/action confirmation (ACK)
97 MT_EXE_ACTION = 0x40, // executing actions on keyboard
98 MT_EXE_ACTION_ACK =0x41, // return confirmation/value (ACK)
99 MT_TYPE_ERROR = 0x80 // type not recofgnised (ACK)
100 };
101
102 enum DATA_TYPE {
103 DT_NONE = 0x00,
104 DT_HANDSHAKE,
105 DT_DEFAULT_LAYER,
106 DT_CURRENT_LAYER,
107 DT_KEYMAP_OPTIONS,
108 DT_BACKLIGHT,
109 DT_RGBLIGHT,
110 DT_UNICODE,
111 DT_DEBUG,
112 DT_AUDIO,
113 DT_QUANTUM_ACTION,
114 DT_KEYBOARD_ACTION,
115 DT_USER_ACTION,
116
117 };
118
119
120 #define MT_GET_DATA(data_type, data, length) send_bytes_sysex(MT_GET_DATA, data_type, data, length)
121 #define MT_GET_DATA_ACK(data_type, data, length) send_bytes_sysex(MT_GET_DATA_ACK, data_type, data, length)
122 #define MT_SET_DATA(data_type, data, length) send_bytes_sysex(MT_SET_DATA, data_type, data, length)
123 #define MT_SET_DATA_ACK(data_type, data, length) send_bytes_sysex(MT_SET_DATA_ACK, data_type, data, length)
124 #define MT_SEND_DATA(data_type, data, length) send_bytes_sysex(MT_SEND_DATA, data_type, data, length)
125 #define MT_SEND_DATA_ACK(data_type, data, length) send_bytes_sysex(MT_SEND_DATA_ACK, data_type, data, length)
126 #define MT_EXE_ACTION(data_type, data, length) send_bytes_sysex(MT_EXE_ACTION, data_type, data, length)
127 #define MT_EXE_ACTION_ACK(data_type, data, length) send_bytes_sysex(MT_EXE_ACTION_ACK, data_type, data, length)
128 79
80#ifdef API_SYSEX_ENABLE
81 #include "api_sysex.h"
129#endif 82#endif
130 83
131// #if LUFA_VERSION_INTEGER < 0x120730 84// #if LUFA_VERSION_INTEGER < 0x120730