1
0
Fork 0

cleaning up new code

This commit is contained in:
Jack Humbert 2016-11-21 19:50:55 -05:00
parent 27ebacb15d
commit 664c0a036b
4 changed files with 73 additions and 64 deletions

View file

@ -16,7 +16,7 @@
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
//#include "ws2812_config.h" //#include "ws2812_config.h"
#include "i2cmaster.h" //#include "i2cmaster.h"
#define LIGHT_I2C 1 #define LIGHT_I2C 1
#define LIGHT_I2C_ADDR 0x84 #define LIGHT_I2C_ADDR 0x84

View file

@ -802,6 +802,46 @@ void backlight_set(uint8_t level)
#endif // backlight #endif // backlight
// Functions for spitting out values
//
void send_dword(uint32_t number) { // this might not actually work
uint16_t word = (number >> 16);
send_word(word);
send_word(number & 0xFFFFUL);
}
void send_word(uint16_t number) {
uint8_t byte = number >> 8;
send_byte(byte);
send_byte(number & 0xFF);
}
void send_byte(uint8_t number) {
uint8_t nibble = number >> 4;
send_nibble(nibble);
send_nibble(number & 0xF);
}
void send_nibble(uint8_t number) {
switch (number) {
case 0:
register_code(KC_0);
unregister_code(KC_0);
break;
case 1 ... 9:
register_code(KC_1 + (number - 1));
unregister_code(KC_1 + (number - 1));
break;
case 0xA ... 0xF:
register_code(KC_A + (number - 0xA));
unregister_code(KC_A + (number - 0xA));
break;
}
}
__attribute__ ((weak)) __attribute__ ((weak))
void led_set_user(uint8_t usb_led) { void led_set_user(uint8_t usb_led) {

View file

@ -110,6 +110,11 @@ void breathing_speed_dec(uint8_t value);
#endif #endif
#endif #endif
void send_dword(uint32_t number);
void send_word(uint16_t number);
void send_byte(uint8_t number);
void send_nibble(uint8_t number);
void led_set_user(uint8_t usb_led); void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led); void led_set_kb(uint8_t usb_led);

View file

@ -84,9 +84,9 @@ static uint8_t keyboard_led_stats = 0;
static report_keyboard_t keyboard_report_sent; static report_keyboard_t keyboard_report_sent;
#ifdef MIDI_ENABLE #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);
void usb_get_midi(MidiDevice * device); static void usb_get_midi(MidiDevice * device);
void midi_usb_init(MidiDevice * device); static void midi_usb_init(MidiDevice * device);
#endif #endif
/* Host driver */ /* Host driver */
@ -714,7 +714,7 @@ int8_t sendchar(uint8_t c)
******************************************************************************/ ******************************************************************************/
#ifdef MIDI_ENABLE #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; MIDI_EventPacket_t event;
event.Data1 = byte0; event.Data1 = byte0;
event.Data2 = byte1; event.Data2 = byte1;
@ -774,7 +774,7 @@ void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byt
USB_USBTask(); USB_USBTask();
} }
void usb_get_midi(MidiDevice * device) { static void usb_get_midi(MidiDevice * device) {
MIDI_EventPacket_t event; MIDI_EventPacket_t event;
while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) { while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) {
@ -804,12 +804,12 @@ void usb_get_midi(MidiDevice * device) {
USB_USBTask(); USB_USBTask();
} }
void midi_usb_init(MidiDevice * device){ static void midi_usb_init(MidiDevice * device){
midi_device_init(device); midi_device_init(device);
midi_device_set_send_func(device, usb_send_func); midi_device_set_send_func(device, usb_send_func);
midi_device_set_pre_input_process_func(device, usb_get_midi); midi_device_set_pre_input_process_func(device, usb_get_midi);
SetupHardware(); // SetupHardware();
sei(); sei();
} }
@ -1112,41 +1112,6 @@ void cc_callback(MidiDevice * device,
#endif #endif
} }
void send_dword(uint32_t number) {
uint16_t word = (number >> 16);
send_word(word);
send_word(number & 0xFFFFUL);
}
void send_word(uint16_t number) {
uint8_t byte = number >> 8;
send_byte(byte);
send_byte(number & 0xFF);
}
void send_byte(uint8_t number) {
uint8_t nibble = number >> 4;
send_nibble(nibble);
send_nibble(number & 0xF);
}
void send_nibble(uint8_t number) {
switch (number) {
case 0:
register_code(KC_0);
unregister_code(KC_0);
break;
case 1 ... 9:
register_code(KC_1 + (number - 1));
unregister_code(KC_1 + (number - 1));
break;
case 0xA ... 0xF:
register_code(KC_A + (number - 0xA));
unregister_code(KC_A + (number - 0xA));
break;
}
}
uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0}; uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data) { 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
for (uint8_t place = 0; place < length; place++) { for (uint8_t place = 0; place < length; place++) {
// send_byte(*data); // send_byte(*data);
midi_buffer[start + place] = *data; midi_buffer[start + place] = *data;
if (*data == 0xF7) if (*data == 0xF7 && midi_buffer[0] == 0xF0)
sysex_buffer_callback(device, start + place, &midi_buffer); sysex_buffer_callback(device, start + place, midi_buffer);
// SEND_STRING(" "); // SEND_STRING(" ");
data++; data++;
} }
@ -1197,10 +1162,9 @@ void encode_uint8_chunk(uint8_t data, uint8_t * pointer) {
} }
void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) { void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) {
uint8_t * pointer_copy = data; // uint8_t * pointer_copy = data; // use for debugging
if (*data++ != 0xF0) //data++; // i'm 98% sure there's a better way to do this
return
data++; data++;
data++; data++;
data++; data++;
@ -1233,41 +1197,41 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data)
break; break;
case 0x01: ; // Get debug state case 0x01: ; // Get debug state
uint8_t debug[2]; uint8_t debug[2];
encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), &debug); encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), debug);
send_bytes_sysex(0x01, &debug, 2); send_bytes_sysex(0x01, debug, 2);
break; break;
case 0x02: ; // Get default layer case 0x02: ; // Get default layer
uint8_t default_layer[2]; uint8_t default_layer[2];
encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), &default_layer); encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), default_layer);
send_bytes_sysex(0x02, &default_layer, 2); send_bytes_sysex(0x02, default_layer, 2);
break; break;
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
case 0x03: ; // Get backlight state case 0x03: ; // Get backlight state
uint8_t audio[2]; uint8_t audio[2];
encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), &audio); encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), audio);
send_bytes_sysex(0x03, &audio, 2); send_bytes_sysex(0x03, audio, 2);
#endif #endif
case 0x04: ; // Get layer state case 0x04: ; // Get layer state
uint8_t layers[5]; uint8_t layers[5];
encode_uint32_chunk(layer_state, &layers); encode_uint32_chunk(layer_state, layers);
send_bytes_sysex(0x04, &layers, 5); send_bytes_sysex(0x04, layers, 5);
break; break;
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
case 0x06: ; // Get backlight state case 0x06: ; // Get backlight state
uint8_t backlight[2]; uint8_t backlight[2];
encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), &backlight); encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), backlight);
send_bytes_sysex(0x06, &backlight, 2); send_bytes_sysex(0x06, backlight, 2);
#endif #endif
#ifdef RGBLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE
case 0x07: ; // Get rgblight state case 0x07: ; // Get rgblight state
uint8_t rgblight[2]; uint8_t rgblight[2];
encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), &rgblight); encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), rgblight);
send_bytes_sysex(0x07, &rgblight, 5); send_bytes_sysex(0x07, rgblight, 5);
#endif #endif
case 0x08: ; // Keymap options case 0x08: ; // Keymap options
uint8_t keymap_options[2]; uint8_t keymap_options[2];
encode_uint8_chunk(eeconfig_read_keymap(), &keymap_options); encode_uint8_chunk(eeconfig_read_keymap(), keymap_options);
send_bytes_sysex(0x08, &keymap_options, 2); send_bytes_sysex(0x08, keymap_options, 2);
break; break;
} }
break; break;
@ -1299,8 +1263,8 @@ void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data)
void send_unicode_midi(uint32_t unicode) { void send_unicode_midi(uint32_t unicode) {
uint8_t chunk[5]; uint8_t chunk[5];
encode_uint32_chunk(unicode, &chunk); encode_uint32_chunk(unicode, chunk);
send_bytes_sysex(0x05, &chunk, 5); send_bytes_sysex(0x05, chunk, 5);
} }
void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) { void send_bytes_sysex(uint8_t type, uint8_t * bytes, uint8_t length) {