diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-11-21 19:50:55 -0500 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-11-21 19:50:55 -0500 |
| commit | 664c0a036b3d7c3ed39f4a7a78d97f4a9cc7d20c (patch) | |
| tree | e6cb0a7fb1c5c882fe394fd251680e0c88df323c | |
| parent | 27ebacb15d39046713bd87e06c1157b1ffab6aaf (diff) | |
| download | qmk_firmware-664c0a036b3d7c3ed39f4a7a78d97f4a9cc7d20c.tar.gz qmk_firmware-664c0a036b3d7c3ed39f4a7a78d97f4a9cc7d20c.zip | |
cleaning up new code
| -rwxr-xr-x | quantum/light_ws2812.h | 2 | ||||
| -rw-r--r-- | quantum/quantum.c | 40 | ||||
| -rw-r--r-- | quantum/quantum.h | 5 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 90 |
4 files changed, 73 insertions, 64 deletions
diff --git a/quantum/light_ws2812.h b/quantum/light_ws2812.h index 0bef93d5e..9498e550e 100755 --- a/quantum/light_ws2812.h +++ b/quantum/light_ws2812.h | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | #include <avr/io.h> | 16 | #include <avr/io.h> |
| 17 | #include <avr/interrupt.h> | 17 | #include <avr/interrupt.h> |
| 18 | //#include "ws2812_config.h" | 18 | //#include "ws2812_config.h" |
| 19 | #include "i2cmaster.h" | 19 | //#include "i2cmaster.h" |
| 20 | 20 | ||
| 21 | #define LIGHT_I2C 1 | 21 | #define LIGHT_I2C 1 |
| 22 | #define LIGHT_I2C_ADDR 0x84 | 22 | #define LIGHT_I2C_ADDR 0x84 |
diff --git a/quantum/quantum.c b/quantum/quantum.c index 9fd9a6ef7..8b2fefef6 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -802,6 +802,46 @@ void backlight_set(uint8_t level) | |||
| 802 | #endif // backlight | 802 | #endif // backlight |
| 803 | 803 | ||
| 804 | 804 | ||
| 805 | // Functions for spitting out values | ||
| 806 | // | ||
| 807 | |||
| 808 | void send_dword(uint32_t number) { // this might not actually work | ||
| 809 | uint16_t word = (number >> 16); | ||
| 810 | send_word(word); | ||
| 811 | send_word(number & 0xFFFFUL); | ||
| 812 | } | ||
| 813 | |||
| 814 | void send_word(uint16_t number) { | ||
| 815 | uint8_t byte = number >> 8; | ||
| 816 | send_byte(byte); | ||
| 817 | send_byte(number & 0xFF); | ||
| 818 | } | ||
| 819 | |||
| 820 | void send_byte(uint8_t number) { | ||
| 821 | uint8_t nibble = number >> 4; | ||
| 822 | send_nibble(nibble); | ||
| 823 | send_nibble(number & 0xF); | ||
| 824 | } | ||
| 825 | |||
| 826 | void send_nibble(uint8_t number) { | ||
| 827 | switch (number) { | ||
| 828 | case 0: | ||
| 829 | register_code(KC_0); | ||
| 830 | unregister_code(KC_0); | ||
| 831 | break; | ||
| 832 | case 1 ... 9: | ||
| 833 | register_code(KC_1 + (number - 1)); | ||
| 834 | unregister_code(KC_1 + (number - 1)); | ||
| 835 | break; | ||
| 836 | case 0xA ... 0xF: | ||
| 837 | register_code(KC_A + (number - 0xA)); | ||
| 838 | unregister_code(KC_A + (number - 0xA)); | ||
| 839 | break; | ||
| 840 | } | ||
| 841 | } | ||
| 842 | |||
| 843 | |||
| 844 | |||
| 805 | 845 | ||
| 806 | __attribute__ ((weak)) | 846 | __attribute__ ((weak)) |
| 807 | void led_set_user(uint8_t usb_led) { | 847 | void led_set_user(uint8_t usb_led) { |
diff --git a/quantum/quantum.h b/quantum/quantum.h index 06a2e049d..3d35f11fa 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -110,6 +110,11 @@ void breathing_speed_dec(uint8_t value); | |||
| 110 | #endif | 110 | #endif |
| 111 | 111 | ||
| 112 | #endif | 112 | #endif |
| 113 | void send_dword(uint32_t number); | ||
| 114 | void send_word(uint16_t number); | ||
| 115 | void send_byte(uint8_t number); | ||
| 116 | void send_nibble(uint8_t number); | ||
| 117 | |||
| 113 | 118 | ||
| 114 | void led_set_user(uint8_t usb_led); | 119 | void led_set_user(uint8_t usb_led); |
| 115 | void led_set_kb(uint8_t usb_led); | 120 | void led_set_kb(uint8_t usb_led); |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 35739e321..14da3b803 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -84,9 +84,9 @@ static uint8_t keyboard_led_stats = 0; | |||
| 84 | static report_keyboard_t keyboard_report_sent; | 84 | static report_keyboard_t keyboard_report_sent; |
| 85 | 85 | ||
| 86 | #ifdef MIDI_ENABLE | 86 | #ifdef MIDI_ENABLE |
| 87 | void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); | 87 | static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); |
| 88 | void usb_get_midi(MidiDevice * device); | 88 | static void usb_get_midi(MidiDevice * device); |
| 89 | void midi_usb_init(MidiDevice * device); | 89 | static void midi_usb_init(MidiDevice * device); |
| 90 | #endif | 90 | #endif |
| 91 | 91 | ||
| 92 | /* Host driver */ | 92 | /* Host driver */ |
| @@ -714,7 +714,7 @@ int8_t sendchar(uint8_t c) | |||
| 714 | ******************************************************************************/ | 714 | ******************************************************************************/ |
| 715 | 715 | ||
| 716 | #ifdef MIDI_ENABLE | 716 | #ifdef MIDI_ENABLE |
| 717 | void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { | 717 | static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) { |
| 718 | MIDI_EventPacket_t event; | 718 | MIDI_EventPacket_t event; |
| 719 | event.Data1 = byte0; | 719 | event.Data1 = byte0; |
| 720 | event.Data2 = byte1; | 720 | event.Data2 = byte1; |
| @@ -774,7 +774,7 @@ void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byt | |||
| 774 | USB_USBTask(); | 774 | USB_USBTask(); |
| 775 | } | 775 | } |
| 776 | 776 | ||
| 777 | void usb_get_midi(MidiDevice * device) { | 777 | static void usb_get_midi(MidiDevice * device) { |
| 778 | MIDI_EventPacket_t event; | 778 | MIDI_EventPacket_t event; |
| 779 | while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) { | 779 | while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) { |
| 780 | 780 | ||
| @@ -804,12 +804,12 @@ void usb_get_midi(MidiDevice * device) { | |||
| 804 | USB_USBTask(); | 804 | USB_USBTask(); |
| 805 | } | 805 | } |
| 806 | 806 | ||
| 807 | void midi_usb_init(MidiDevice * device){ | 807 | static void midi_usb_init(MidiDevice * device){ |
| 808 | midi_device_init(device); | 808 | midi_device_init(device); |
| 809 | midi_device_set_send_func(device, usb_send_func); | 809 | midi_device_set_send_func(device, usb_send_func); |
| 810 | midi_device_set_pre_input_process_func(device, usb_get_midi); | 810 | midi_device_set_pre_input_process_func(device, usb_get_midi); |
| 811 | 811 | ||
| 812 | SetupHardware(); | 812 | // SetupHardware(); |
| 813 | sei(); | 813 | sei(); |
| 814 | } | 814 | } |
| 815 | 815 | ||
| @@ -1112,41 +1112,6 @@ void cc_callback(MidiDevice * device, | |||
| 1112 | #endif | 1112 | #endif |
| 1113 | } | 1113 | } |
| 1114 | 1114 | ||
| 1115 | void send_dword(uint32_t number) { | ||
| 1116 | uint16_t word = (number >> 16); | ||
| 1117 | send_word(word); | ||
| 1118 | send_word(number & 0xFFFFUL); | ||
| 1119 | } | ||
| 1120 | |||
| 1121 | void send_word(uint16_t number) { | ||
| 1122 | uint8_t byte = number >> 8; | ||
| 1123 | send_byte(byte); | ||
| 1124 | send_byte(number & 0xFF); | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | void send_byte(uint8_t number) { | ||
| 1128 | uint8_t nibble = number >> 4; | ||
| 1129 | send_nibble(nibble); | ||
| 1130 | send_nibble(number & 0xF); | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | void send_nibble(uint8_t number) { | ||
| 1134 | switch (number) { | ||
| 1135 | case 0: | ||
| 1136 | register_code(KC_0); | ||
| 1137 | unregister_code(KC_0); | ||
| 1138 | break; | ||
| 1139 | case 1 ... 9: | ||
| 1140 | register_code(KC_1 + (number - 1)); | ||
| 1141 | unregister_code(KC_1 + (number - 1)); | ||
| 1142 | break; | ||
| 1143 | case 0xA ... 0xF: | ||
| 1144 | register_code(KC_A + (number - 0xA)); | ||
| 1145 | unregister_code(KC_A + (number - 0xA)); | ||
| 1146 | break; | ||
| 1147 | } | ||
| 1148 | } | ||
| 1149 | |||
| 1150 | uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; | 1115 | uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; |
| 1151 | 1116 | ||
| 1152 | void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) { | 1117 | void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) { |
| @@ -1159,8 +1124,8 @@ void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t | |||
| 1159 | for (uint8_t place = 0; place < length; place++) { | 1124 | for (uint8_t place = 0; place < length; place++) { |
| 1160 | // send_byte(*data); | 1125 | // send_byte(*data); |
| 1161 | midi_buffer[start + place] = *data; | 1126 | midi_buffer[start + place] = *data; |
| 1162 | if (*data == 0xF7) | 1127 | if (*data == 0xF7 && midi_buffer[0] == 0xF0) |
| 1163 | sysex_buffer_callback(device, start + place, &midi_buffer); | 1128 | sysex_buffer_callback(device, start + place, midi_buffer); |
| 1164 | // SEND_STRING(" "); | 1129 | // SEND_STRING(" "); |
| 1165 | data++; | 1130 | data++; |
| 1166 | } | 1131 | } |
| @@ -1197,10 +1162,9 @@ void encode_uint8_chunk(uint8_t data, uint8_t * pointer) { | |||
| 1197 | } | 1162 | } |
| 1198 | 1163 | ||
| 1199 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { | 1164 | void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { |
| 1200 | uint8_t * pointer_copy = data; | 1165 | // uint8_t * pointer_copy = data; // use for debugging |
| 1201 | 1166 | ||
| 1202 | if (*data++ != 0xF0) | 1167 | //data++; // i'm 98% sure there's a better way to do this |
| 1203 | return | ||
| 1204 | data++; | 1168 | data++; |
| 1205 | data++; | 1169 | data++; |
| 1206 | data++; | 1170 | data++; |
| @@ -1233,41 +1197,41 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) | |||
| 1233 | break; | 1197 | break; |
| 1234 | case 0x01: ; // Get debug state | 1198 | case 0x01: ; // Get debug state |
| 1235 | uint8_t debug[2]; | 1199 | uint8_t debug[2]; |
| 1236 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), &debug); | 1200 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), debug); |
| 1237 | send_bytes_sysex(0x01, &debug, 2); | 1201 | send_bytes_sysex(0x01, debug, 2); |
| 1238 | break; | 1202 | break; |
| 1239 | case 0x02: ; // Get default layer | 1203 | case 0x02: ; // Get default layer |
| 1240 | uint8_t default_layer[2]; | 1204 | uint8_t default_layer[2]; |
| 1241 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), &default_layer); | 1205 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), default_layer); |
| 1242 | send_bytes_sysex(0x02, &default_layer, 2); | 1206 | send_bytes_sysex(0x02, default_layer, 2); |
| 1243 | break; | 1207 | break; |
| 1244 | #ifdef AUDIO_ENABLE | 1208 | #ifdef AUDIO_ENABLE |
| 1245 | case 0x03: ; // Get backlight state | 1209 | case 0x03: ; // Get backlight state |
| 1246 | uint8_t audio[2]; | 1210 | uint8_t audio[2]; |
| 1247 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), &audio); | 1211 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), audio); |
| 1248 | send_bytes_sysex(0x03, &audio, 2); | 1212 | send_bytes_sysex(0x03, audio, 2); |
| 1249 | #endif | 1213 | #endif |
| 1250 | case 0x04: ; // Get layer state | 1214 | case 0x04: ; // Get layer state |
| 1251 | uint8_t layers[5]; | 1215 | uint8_t layers[5]; |
| 1252 | encode_uint32_chunk(layer_state, &layers); | 1216 | encode_uint32_chunk(layer_state, layers); |
| 1253 | send_bytes_sysex(0x04, &layers, 5); | 1217 | send_bytes_sysex(0x04, layers, 5); |
| 1254 | break; | 1218 | break; |
| 1255 | #ifdef BACKLIGHT_ENABLE | 1219 | #ifdef BACKLIGHT_ENABLE |
| 1256 | case 0x06: ; // Get backlight state | 1220 | case 0x06: ; // Get backlight state |
| 1257 | uint8_t backlight[2]; | 1221 | uint8_t backlight[2]; |
| 1258 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), &backlight); | 1222 | encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), backlight); |
| 1259 | send_bytes_sysex(0x06, &backlight, 2); | 1223 | send_bytes_sysex(0x06, backlight, 2); |
| 1260 | #endif | 1224 | #endif |
| 1261 | #ifdef RGBLIGHT_ENABLE | 1225 | #ifdef RGBLIGHT_ENABLE |
| 1262 | case 0x07: ; // Get rgblight state | 1226 | case 0x07: ; // Get rgblight state |
| 1263 | uint8_t rgblight[2]; | 1227 | uint8_t rgblight[2]; |
| 1264 | encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), &rgblight); | 1228 | encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), rgblight); |
| 1265 | send_bytes_sysex(0x07, &rgblight, 5); | 1229 | send_bytes_sysex(0x07, rgblight, 5); |
| 1266 | #endif | 1230 | #endif |
| 1267 | case 0x08: ; // Keymap options | 1231 | case 0x08: ; // Keymap options |
| 1268 | uint8_t keymap_options[2]; | 1232 | uint8_t keymap_options[2]; |
| 1269 | encode_uint8_chunk(eeconfig_read_keymap(), &keymap_options); | 1233 | encode_uint8_chunk(eeconfig_read_keymap(), keymap_options); |
| 1270 | send_bytes_sysex(0x08, &keymap_options, 2); | 1234 | send_bytes_sysex(0x08, keymap_options, 2); |
| 1271 | break; | 1235 | break; |
| 1272 | } | 1236 | } |
| 1273 | break; | 1237 | break; |
| @@ -1299,8 +1263,8 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) | |||
| 1299 | 1263 | ||
| 1300 | void send_unicode_midi(uint32_t unicode) { | 1264 | void send_unicode_midi(uint32_t unicode) { |
| 1301 | uint8_t chunk[5]; | 1265 | uint8_t chunk[5]; |
| 1302 | encode_uint32_chunk(unicode, &chunk); | 1266 | encode_uint32_chunk(unicode, chunk); |
| 1303 | send_bytes_sysex(0x05, &chunk, 5); | 1267 | send_bytes_sysex(0x05, chunk, 5); |
| 1304 | } | 1268 | } |
| 1305 | 1269 | ||
| 1306 | void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { | 1270 | void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { |
