From 5ae1411fc387a682d3e22f5cddfe1102e3312af5 Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Thu, 16 Feb 2017 20:49:02 -0800 Subject: Expand MIDI key codes --- quantum/quantum_keycodes.h | 114 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 63b626926..3728fa366 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -107,10 +107,122 @@ enum quantum_keycodes { MUV_IN, MUV_DE, - // Midi mode on/off +#ifdef MIDI_ENABLE + // Midi MIDI_ON, MIDI_OFF, + MIDI_TONE_MIN, + + MI_C = MIDI_TONE_MIN, + MI_Cs, + MI_Db = MI_Cs, + MI_D, + MI_Ds, + MI_Eb = MI_Ds, + MI_E, + MI_F, + MI_Fs, + MI_Gb = MI_Fs, + MI_G, + MI_Gs, + MI_Ab = MI_Gs, + MI_A, + MI_As, + MI_Bb = MI_As, + MI_B, + + MI_C_1, + MI_Cs_1, + MI_Db_1 = MI_Cs_1, + MI_D_1, + MI_Ds_1, + MI_Eb_1 = MI_Ds_1, + MI_E_1, + MI_F_1, + MI_Fs_1, + MI_Gb_1 = MI_Fs_1, + MI_G_1, + MI_Gs_1, + MI_Ab_1 = MI_Gs_1, + MI_A_1, + MI_As_1, + MI_Bb_1 = MI_As_1, + MI_B_1, + + MI_C_2, + MI_Cs_2, + MI_Db_2 = MI_Cs_2, + MI_D_2, + MI_Ds_2, + MI_Eb_2 = MI_Ds_2, + MI_E_2, + MI_F_2, + MI_Fs_2, + MI_Gb_2 = MI_Fs_2, + MI_G_2, + MI_Gs_2, + MI_Ab_2 = MI_Gs_2, + MI_A_2, + MI_As_2, + MI_Bb_2 = MI_As_2, + MI_B_2, + + MIDI_TONE_MAX = MI_B_2, + + MIDI_OCTAVE_MIN, + MI_OCT_N2 = MIDI_OCTAVE_MIN, + MI_OCT_N1, + MI_OCT_0, + MI_OCT_1, + MI_OCT_2, + MI_OCT_3, + MI_OCT_4, + MI_OCT_5, + MI_OCT_6, + MI_OCT_7, + MIDI_OCTAVE_MAX = MI_OCT_7, + MI_OCTD, // octave down + MI_OCTU, // octave up + + MIDI_VELOCITY_MIN, + MI_VEL_1 = MIDI_VELOCITY_MIN, + MI_VEL_2, + MI_VEL_3, + MI_VEL_5, + MI_VEL_6, + MI_VEL_7, + MI_VEL_8, + MI_VEL_9, + MI_VEL_10, + MIDI_VELOCITY_MAX = MI_VEL_10, + MI_VELD, // velocity down + MI_VELU, // velocity up + + MIDI_CHANNEL_MIN, + MI_CH1 = MIDI_CHANNEL_MIN, + MI_CH2, + MI_CH3, + MI_CH4, + MI_CH5, + MI_CH6, + MI_CH7, + MI_CH8, + MI_CH9, + MI_CH10, + MI_CH11, + MI_CH12, + MI_CH13, + MI_CH14, + MI_CH15, + MI_CH16, + MIDI_CHANNEL_MAX = MI_CH16, + MI_CHD, // previous channel + MI_CHU, // next channel + + MI_SUS, // sustain +#endif + // Backlight functionality BL_0, BL_1, -- cgit v1.2.3 From e405ab4bc6ff47d189d99c4d51aadf60a642d82a Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 18 Feb 2017 03:12:13 -0800 Subject: initial implementation of polyphony using variable length array of notes on --- quantum/process_keycode/process_midi.c | 199 ++++++++++++++++++++++++++++++++- quantum/process_keycode/process_midi.h | 3 + quantum/quantum_keycodes.h | 1 + tmk_core/protocol/lufa/lufa.c | 13 ++- tmk_core/protocol/lufa/lufa.h | 2 +- 5 files changed, 211 insertions(+), 7 deletions(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 577dad43a..bc48b3905 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -1,10 +1,204 @@ #include "process_midi.h" +#if 0 bool midi_activated = false; uint8_t midi_starting_note = 0x0C; int midi_offset = 7; +#endif + +typedef union { + uint16_t raw; + struct { + uint8_t octave :4; + uint8_t velocity :4; + uint8_t channel :4; + }; +} midi_config_t; + +midi_config_t midi_config; + +#define MIDI_INVALID_NOTE 0xFF + +#if 0 +typedef struct { + uint64_t low; + uint64_t high; +} uint128_t; + +#if 0 +static void right_shift_uint128_t(uint128_t* val, uint8_t shift) +{ + uint64_t high_mask = ~0 >> (64 - shift); + uint64_t high_bits = (val->high & high_mask) << (64 - shift); + val->high = val->high >> shift; + val->low = (val->low >> shift) | high_bits; +} +#endif + +static uint64_t left_shift_uint64_t(uint64_t val, uint8_t shift) +{ + dprintf("left_shift_uint64_t(val, %c) ...\n", val, shift); + while (shift > 16u) { + dprintf(" left_shift_uint64_t: val=?, shift=%c\n", val, shift); + val <<= 16; + shift -= 16; + } + dprintf(" left_shift_uint64_t: val=?, shift=%c\n", val, shift); + val <<= shift; + return val; +} + +static void set_bit_uint128_t(uint128_t* val, uint8_t shift) +{ + uint64_t x = 1u; + + if (shift < 64) + { + x = left_shift_uint64_t(x, shift); + dprintf("x: %d\n", x); + dprintf("set_bit_uint128_t (%d): 0x%016X%016X\n", shift, 0, x); + val->low = val->low | left_shift_uint64_t(1u, shift); + } + else + { + x = left_shift_uint64_t(x, shift - 64); + dprintf("set_bit_uint128_t (%d): 0x%016X%016X\n", shift, x, 0); + val->high = val->high | left_shift_uint64_t(1u, shift - 64); + } +} + +static void clear_bit_uint128_t(uint128_t* val, uint8_t shift) +{ + if (shift < 64) + { + val->low = val->low & ~left_shift_uint64_t(1u, shift); + } + else + { + val->high = val->high & ~left_shift_uint64_t(1u, shift - 64); + } +} -bool process_midi(uint16_t keycode, keyrecord_t *record) { +static bool is_bit_set_uint128_t(const uint128_t* val, uint8_t shift) +{ + if (shift < 64) + { + return !!(val->low & (1u << shift)); + } + else + { + return !!(val->high & (1u << (shift - 64))); + } +} + +uint128_t note_status = { 0, 0 }; +#endif + + +#define MIDI_MAX_NOTES_ON 10 + +typedef struct { + uint8_t note; + uint8_t tone; +} midi_notes_on_array_entry_t; + +typedef struct { + uint8_t length; + midi_notes_on_array_entry_t values[MIDI_MAX_NOTES_ON]; +} midi_notes_on_array_t; + +static midi_notes_on_array_t notes_on; + +inline uint8_t compute_velocity(uint8_t setting) +{ + return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); +} + +void midi_init(void) +{ + midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN; + midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); + midi_config.channel = 0; + notes_on.length = 0; +} + +bool process_midi(uint16_t keycode, keyrecord_t *record) +{ + switch (keycode) { + case MIDI_TONE_MIN ... MIDI_TONE_MAX: + { + uint8_t channel = midi_config.channel; + uint8_t tone = keycode - MIDI_TONE_MIN; + uint8_t velocity = compute_velocity(midi_config.velocity); + if (record->event.pressed && notes_on.length < MIDI_MAX_NOTES_ON) { + uint8_t note = 12 * midi_config.octave + tone; + midi_send_noteon(&midi_device, channel, note, velocity); + dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); + notes_on.values[notes_on.length].note = note; + notes_on.values[notes_on.length].tone = tone; + notes_on.length++; + } + else { + for (uint8_t i = 0; i < notes_on.length; i++) { + uint8_t note = notes_on.values[i].note; + if (tone == notes_on.values[i].tone) { + midi_send_noteoff(&midi_device, channel, note, velocity); + dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); + + for (uint8_t j=i; j < notes_on.length - 1; j++) + { + notes_on.values[j] = notes_on.values[j + 1]; + } + + notes_on.length--; + break; + } + } + } + return false; + } + case MIDI_OCTAVE_MIN ... MIDI_OCTAVE_MAX: + if (record->event.pressed) + midi_config.octave = keycode - MIDI_OCTAVE_MIN; + return false; + case MI_OCTD: + if (record->event.pressed && midi_config.octave > 0) + midi_config.octave--; + return false; + case MI_OCTU: + if (record->event.pressed && midi_config.octave < (MIDI_OCTAVE_MAX - MIDI_OCTAVE_MIN)) + midi_config.octave++; + return false; + case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: + if (record->event.pressed) + midi_config.velocity = keycode - MIDI_VELOCITY_MIN; + return false; + case MI_VELD: + if (record->event.pressed && midi_config.velocity > 0) + midi_config.velocity--; + return false; + case MI_VELU: + if (record->event.pressed) + midi_config.velocity++; + return false; + case MIDI_CHANNEL_MIN ... MIDI_CHANNEL_MAX: + if (record->event.pressed) + midi_config.channel = keycode - MIDI_CHANNEL_MIN; + return false; + case MI_CHD: + if (record->event.pressed) + midi_config.channel--; + return false; + case MI_CHU: + if (record->event.pressed) + midi_config.channel++; + return false; + case MI_SUS: + //TODO + return false; + }; + +#if 0 if (keycode == MI_ON && record->event.pressed) { midi_activated = true; #ifdef AUDIO_ENABLE @@ -64,5 +258,6 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through return false; } - return true; +#endif + return true; } diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index acd4fc1b1..b0e0aeb83 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -2,6 +2,9 @@ #define PROCESS_MIDI_H #include "quantum.h" +#include "midi.h" + +void midi_init(void); bool process_midi(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 3728fa366..a024a9639 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -189,6 +189,7 @@ enum quantum_keycodes { MI_VEL_1 = MIDI_VELOCITY_MIN, MI_VEL_2, MI_VEL_3, + MI_VEL_4, MI_VEL_5, MI_VEL_6, MI_VEL_7, diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index ba49284c9..fb60658df 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1101,16 +1101,21 @@ void cc_callback(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val); void sysex_callback(MidiDevice * device, uint16_t start, uint8_t length, uint8_t * data); + +void setup_midi(void) +{ + midi_init(); + midi_device_init(&midi_device); + midi_device_set_send_func(&midi_device, usb_send_func); + midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); +} #endif int main(void) __attribute__ ((weak)); int main(void) { - #ifdef MIDI_ENABLE - midi_device_init(&midi_device); - midi_device_set_send_func(&midi_device, usb_send_func); - midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); + setup_midi(); #endif setup_mcu(); diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h index a049fd43c..a51573786 100644 --- a/tmk_core/protocol/lufa/lufa.h +++ b/tmk_core/protocol/lufa/lufa.h @@ -49,7 +49,7 @@ #include #include "host.h" #ifdef MIDI_ENABLE - #include "midi.h" + #include "process_midi.h" #endif #ifdef __cplusplus extern "C" { -- cgit v1.2.3 From 7c5e510fe2e57d1b3c0f98612f1f89d413c07525 Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 18 Feb 2017 04:25:17 -0800 Subject: add support for pedal cc messages --- quantum/process_keycode/process_midi.c | 61 ++++++++++++++++++++++++++++------ quantum/quantum_keycodes.h | 11 +++--- 2 files changed, 57 insertions(+), 15 deletions(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 2ce7418ea..f7a8b6650 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -62,43 +62,84 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) return false; } case MIDI_OCTAVE_MIN ... MIDI_OCTAVE_MAX: - if (record->event.pressed) + if (record->event.pressed) { midi_config.octave = keycode - MIDI_OCTAVE_MIN; + dprintf("midi octave %d\n", midi_config.octave); + } return false; case MI_OCTD: - if (record->event.pressed && midi_config.octave > 0) + if (record->event.pressed && midi_config.octave > 0) { midi_config.octave--; + dprintf("midi octave %d\n", midi_config.octave); + } return false; case MI_OCTU: - if (record->event.pressed && midi_config.octave < (MIDI_OCTAVE_MAX - MIDI_OCTAVE_MIN)) + if (record->event.pressed && midi_config.octave < (MIDI_OCTAVE_MAX - MIDI_OCTAVE_MIN)) { midi_config.octave++; + dprintf("midi octave %d\n", midi_config.octave); + } return false; case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: - if (record->event.pressed) + if (record->event.pressed) { midi_config.velocity = keycode - MIDI_VELOCITY_MIN; + dprintf("midi velocity %d\n", midi_config.velocity); + } return false; case MI_VELD: - if (record->event.pressed && midi_config.velocity > 0) + if (record->event.pressed && midi_config.velocity > 0) { midi_config.velocity--; + dprintf("midi velocity %d\n", midi_config.velocity); + } return false; case MI_VELU: - if (record->event.pressed) + if (record->event.pressed) { midi_config.velocity++; + dprintf("midi velocity %d\n", midi_config.velocity); + } return false; case MIDI_CHANNEL_MIN ... MIDI_CHANNEL_MAX: - if (record->event.pressed) + if (record->event.pressed) { midi_config.channel = keycode - MIDI_CHANNEL_MIN; + dprintf("midi channel %d\n", midi_config.channel); + } return false; case MI_CHD: - if (record->event.pressed) + if (record->event.pressed) { midi_config.channel--; + dprintf("midi channel %d\n", midi_config.channel); + } return false; case MI_CHU: - if (record->event.pressed) + if (record->event.pressed) { midi_config.channel++; + dprintf("midi channel %d\n", midi_config.channel); + } + return false; + case MI_OFF: + if (record->event.pressed) { + midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0); + dprintf("midi off\n"); + } return false; case MI_SUS: - //TODO + midi_send_cc(&midi_device, midi_config.channel, 0x40, record->event.pressed ? 127 : 0); + dprintf("midi sustain %d\n", record->event.pressed); + return false; + case MI_PORT: + midi_send_cc(&midi_device, midi_config.channel, 0x41, record->event.pressed ? 127 : 0); + dprintf("midi portamento %d\n", record->event.pressed); + return false; + case MI_SOST: + midi_send_cc(&midi_device, midi_config.channel, 0x42, record->event.pressed ? 127 : 0); + dprintf("midi sostenuto %d\n", record->event.pressed); + return false; + case MI_SOFT: + midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); + dprintf("midi soft %d\n", record->event.pressed); + return false; + case MI_LEG: + midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); + dprintf("midi legato %d\n", record->event.pressed); return false; }; diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index a024a9639..f2b9509b5 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -109,8 +109,6 @@ enum quantum_keycodes { #ifdef MIDI_ENABLE // Midi - MIDI_ON, - MIDI_OFF, MIDI_TONE_MIN, @@ -221,7 +219,13 @@ enum quantum_keycodes { MI_CHD, // previous channel MI_CHU, // next channel + MI_OFF, // all notes off + MI_SUS, // sustain + MI_PORT, // portamento + MI_SOST, // sostenuto + MI_SOFT, // soft + MI_LEG, // legato #endif // Backlight functionality @@ -394,9 +398,6 @@ enum quantum_keycodes { #define BL_ON BL_9 #define BL_OFF BL_0 -#define MI_ON MIDI_ON -#define MI_OFF MIDI_OFF - // GOTO layer - 16 layers max // when: // ON_PRESS = 1 -- cgit v1.2.3 From dd8f8e6baeb1549735403edf2a2f04f07edb4bf2 Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 18 Feb 2017 05:32:55 -0800 Subject: implement modulation --- quantum/process_keycode/process_midi.c | 58 +++++++++- quantum/process_keycode/process_midi.h | 201 +-------------------------------- quantum/quantum_keycodes.h | 6 +- tmk_core/protocol/lufa/lufa.c | 2 +- 4 files changed, 61 insertions(+), 206 deletions(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index f7a8b6650..d09aa0b38 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -1,4 +1,5 @@ #include "process_midi.h" +#include "timer.h" typedef union { uint16_t raw; @@ -6,6 +7,7 @@ typedef union { uint8_t octave :4; uint8_t velocity :4; uint8_t channel :4; + uint8_t modulation_interval :4; }; } midi_config_t; @@ -16,6 +18,10 @@ midi_config_t midi_config; #define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1) static uint8_t tone_status[MIDI_TONE_COUNT]; +static uint8_t midi_modulation; +static int8_t midi_modulation_step; +static uint16_t midi_modulation_timer; + inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); @@ -26,14 +32,40 @@ void midi_init(void) midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN; midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); midi_config.channel = 0; - #ifdef MIDI_USE_NOTE_ON_ARRAY - notes_on.length = 0; - #else + midi_config.modulation_interval = 8; + for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) { tone_status[i] = MIDI_INVALID_NOTE; } - #endif + + midi_modulation = 0; + midi_modulation_step = 0; + midi_modulation_timer = 0; +} + +void midi_task(void) +{ + if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) + return; + midi_modulation_timer = timer_read(); + + if (midi_modulation_step != 0) + { + dprintf("midi modulation %d\n", midi_modulation); + midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation); + + if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) { + midi_modulation = 0; + midi_modulation_step = 0; + return; + } + + midi_modulation += midi_modulation_step; + + if (midi_modulation > 127) + midi_modulation = 127; + } } bool process_midi(uint16_t keycode, keyrecord_t *record) @@ -141,6 +173,24 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); dprintf("midi legato %d\n", record->event.pressed); return false; + case MI_MOD: + midi_modulation_step = record->event.pressed ? 1 : -1; + return false; + case MI_MODSD: + if (record->event.pressed) { + midi_config.modulation_interval++; + // prevent overflow + if (midi_config.modulation_interval == 0) + midi_config.modulation_interval--; + dprintf("midi modulation interval %d\n", midi_config.modulation_interval); + } + return false; + case MI_MODSU: + if (record->event.pressed && midi_config.modulation_interval > 0) { + midi_config.modulation_interval--; + dprintf("midi modulation interval %d\n", midi_config.modulation_interval); + } + return false; }; return true; diff --git a/quantum/process_keycode/process_midi.h b/quantum/process_keycode/process_midi.h index b0e0aeb83..66ce60b0e 100644 --- a/quantum/process_keycode/process_midi.h +++ b/quantum/process_keycode/process_midi.h @@ -5,206 +5,7 @@ #include "midi.h" void midi_init(void); - +void midi_task(void); bool process_midi(uint16_t keycode, keyrecord_t *record); -#define MIDI(n) ((n) | 0x6000) -#define MIDI12 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000 - -#define CHNL(note, channel) (note + (channel << 8)) - -#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ - 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ - 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \ - 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \ - 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } - -#define N_CN1 (0x600C + (12 * -1) + 0 ) -#define N_CN1S (0x600C + (12 * -1) + 1 ) -#define N_DN1F (0x600C + (12 * -1) + 1 ) -#define N_DN1 (0x600C + (12 * -1) + 2 ) -#define N_DN1S (0x600C + (12 * -1) + 3 ) -#define N_EN1F (0x600C + (12 * -1) + 3 ) -#define N_EN1 (0x600C + (12 * -1) + 4 ) -#define N_FN1 (0x600C + (12 * -1) + 5 ) -#define N_FN1S (0x600C + (12 * -1) + 6 ) -#define N_GN1F (0x600C + (12 * -1) + 6 ) -#define N_GN1 (0x600C + (12 * -1) + 7 ) -#define N_GN1S (0x600C + (12 * -1) + 8 ) -#define N_AN1F (0x600C + (12 * -1) + 8 ) -#define N_AN1 (0x600C + (12 * -1) + 9 ) -#define N_AN1S (0x600C + (12 * -1) + 10) -#define N_BN1F (0x600C + (12 * -1) + 10) -#define N_BN1 (0x600C + (12 * -1) + 11) -#define N_C0 (0x600C + (12 * 0) + 0 ) -#define N_C0S (0x600C + (12 * 0) + 1 ) -#define N_D0F (0x600C + (12 * 0) + 1 ) -#define N_D0 (0x600C + (12 * 0) + 2 ) -#define N_D0S (0x600C + (12 * 0) + 3 ) -#define N_E0F (0x600C + (12 * 0) + 3 ) -#define N_E0 (0x600C + (12 * 0) + 4 ) -#define N_F0 (0x600C + (12 * 0) + 5 ) -#define N_F0S (0x600C + (12 * 0) + 6 ) -#define N_G0F (0x600C + (12 * 0) + 6 ) -#define N_G0 (0x600C + (12 * 0) + 7 ) -#define N_G0S (0x600C + (12 * 0) + 8 ) -#define N_A0F (0x600C + (12 * 0) + 8 ) -#define N_A0 (0x600C + (12 * 0) + 9 ) -#define N_A0S (0x600C + (12 * 0) + 10) -#define N_B0F (0x600C + (12 * 0) + 10) -#define N_B0 (0x600C + (12 * 0) + 11) -#define N_C1 (0x600C + (12 * 1) + 0 ) -#define N_C1S (0x600C + (12 * 1) + 1 ) -#define N_D1F (0x600C + (12 * 1) + 1 ) -#define N_D1 (0x600C + (12 * 1) + 2 ) -#define N_D1S (0x600C + (12 * 1) + 3 ) -#define N_E1F (0x600C + (12 * 1) + 3 ) -#define N_E1 (0x600C + (12 * 1) + 4 ) -#define N_F1 (0x600C + (12 * 1) + 5 ) -#define N_F1S (0x600C + (12 * 1) + 6 ) -#define N_G1F (0x600C + (12 * 1) + 6 ) -#define N_G1 (0x600C + (12 * 1) + 7 ) -#define N_G1S (0x600C + (12 * 1) + 8 ) -#define N_A1F (0x600C + (12 * 1) + 8 ) -#define N_A1 (0x600C + (12 * 1) + 9 ) -#define N_A1S (0x600C + (12 * 1) + 10) -#define N_B1F (0x600C + (12 * 1) + 10) -#define N_B1 (0x600C + (12 * 1) + 11) -#define N_C2 (0x600C + (12 * 2) + 0 ) -#define N_C2S (0x600C + (12 * 2) + 1 ) -#define N_D2F (0x600C + (12 * 2) + 1 ) -#define N_D2 (0x600C + (12 * 2) + 2 ) -#define N_D2S (0x600C + (12 * 2) + 3 ) -#define N_E2F (0x600C + (12 * 2) + 3 ) -#define N_E2 (0x600C + (12 * 2) + 4 ) -#define N_F2 (0x600C + (12 * 2) + 5 ) -#define N_F2S (0x600C + (12 * 2) + 6 ) -#define N_G2F (0x600C + (12 * 2) + 6 ) -#define N_G2 (0x600C + (12 * 2) + 7 ) -#define N_G2S (0x600C + (12 * 2) + 8 ) -#define N_A2F (0x600C + (12 * 2) + 8 ) -#define N_A2 (0x600C + (12 * 2) + 9 ) -#define N_A2S (0x600C + (12 * 2) + 10) -#define N_B2F (0x600C + (12 * 2) + 10) -#define N_B2 (0x600C + (12 * 2) + 11) -#define N_C3 (0x600C + (12 * 3) + 0 ) -#define N_C3S (0x600C + (12 * 3) + 1 ) -#define N_D3F (0x600C + (12 * 3) + 1 ) -#define N_D3 (0x600C + (12 * 3) + 2 ) -#define N_D3S (0x600C + (12 * 3) + 3 ) -#define N_E3F (0x600C + (12 * 3) + 3 ) -#define N_E3 (0x600C + (12 * 3) + 4 ) -#define N_F3 (0x600C + (12 * 3) + 5 ) -#define N_F3S (0x600C + (12 * 3) + 6 ) -#define N_G3F (0x600C + (12 * 3) + 6 ) -#define N_G3 (0x600C + (12 * 3) + 7 ) -#define N_G3S (0x600C + (12 * 3) + 8 ) -#define N_A3F (0x600C + (12 * 3) + 8 ) -#define N_A3 (0x600C + (12 * 3) + 9 ) -#define N_A3S (0x600C + (12 * 3) + 10) -#define N_B3F (0x600C + (12 * 3) + 10) -#define N_B3 (0x600C + (12 * 3) + 11) -#define N_C4 (0x600C + (12 * 4) + 0 ) -#define N_C4S (0x600C + (12 * 4) + 1 ) -#define N_D4F (0x600C + (12 * 4) + 1 ) -#define N_D4 (0x600C + (12 * 4) + 2 ) -#define N_D4S (0x600C + (12 * 4) + 3 ) -#define N_E4F (0x600C + (12 * 4) + 3 ) -#define N_E4 (0x600C + (12 * 4) + 4 ) -#define N_F4 (0x600C + (12 * 4) + 5 ) -#define N_F4S (0x600C + (12 * 4) + 6 ) -#define N_G4F (0x600C + (12 * 4) + 6 ) -#define N_G4 (0x600C + (12 * 4) + 7 ) -#define N_G4S (0x600C + (12 * 4) + 8 ) -#define N_A4F (0x600C + (12 * 4) + 8 ) -#define N_A4 (0x600C + (12 * 4) + 9 ) -#define N_A4S (0x600C + (12 * 4) + 10) -#define N_B4F (0x600C + (12 * 4) + 10) -#define N_B4 (0x600C + (12 * 4) + 11) -#define N_C5 (0x600C + (12 * 5) + 0 ) -#define N_C5S (0x600C + (12 * 5) + 1 ) -#define N_D5F (0x600C + (12 * 5) + 1 ) -#define N_D5 (0x600C + (12 * 5) + 2 ) -#define N_D5S (0x600C + (12 * 5) + 3 ) -#define N_E5F (0x600C + (12 * 5) + 3 ) -#define N_E5 (0x600C + (12 * 5) + 4 ) -#define N_F5 (0x600C + (12 * 5) + 5 ) -#define N_F5S (0x600C + (12 * 5) + 6 ) -#define N_G5F (0x600C + (12 * 5) + 6 ) -#define N_G5 (0x600C + (12 * 5) + 7 ) -#define N_G5S (0x600C + (12 * 5) + 8 ) -#define N_A5F (0x600C + (12 * 5) + 8 ) -#define N_A5 (0x600C + (12 * 5) + 9 ) -#define N_A5S (0x600C + (12 * 5) + 10) -#define N_B5F (0x600C + (12 * 5) + 10) -#define N_B5 (0x600C + (12 * 5) + 11) -#define N_C6 (0x600C + (12 * 6) + 0 ) -#define N_C6S (0x600C + (12 * 6) + 1 ) -#define N_D6F (0x600C + (12 * 6) + 1 ) -#define N_D6 (0x600C + (12 * 6) + 2 ) -#define N_D6S (0x600C + (12 * 6) + 3 ) -#define N_E6F (0x600C + (12 * 6) + 3 ) -#define N_E6 (0x600C + (12 * 6) + 4 ) -#define N_F6 (0x600C + (12 * 6) + 5 ) -#define N_F6S (0x600C + (12 * 6) + 6 ) -#define N_G6F (0x600C + (12 * 6) + 6 ) -#define N_G6 (0x600C + (12 * 6) + 7 ) -#define N_G6S (0x600C + (12 * 6) + 8 ) -#define N_A6F (0x600C + (12 * 6) + 8 ) -#define N_A6 (0x600C + (12 * 6) + 9 ) -#define N_A6S (0x600C + (12 * 6) + 10) -#define N_B6F (0x600C + (12 * 6) + 10) -#define N_B6 (0x600C + (12 * 6) + 11) -#define N_C7 (0x600C + (12 * 7) + 0 ) -#define N_C7S (0x600C + (12 * 7) + 1 ) -#define N_D7F (0x600C + (12 * 7) + 1 ) -#define N_D7 (0x600C + (12 * 7) + 2 ) -#define N_D7S (0x600C + (12 * 7) + 3 ) -#define N_E7F (0x600C + (12 * 7) + 3 ) -#define N_E7 (0x600C + (12 * 7) + 4 ) -#define N_F7 (0x600C + (12 * 7) + 5 ) -#define N_F7S (0x600C + (12 * 7) + 6 ) -#define N_G7F (0x600C + (12 * 7) + 6 ) -#define N_G7 (0x600C + (12 * 7) + 7 ) -#define N_G7S (0x600C + (12 * 7) + 8 ) -#define N_A7F (0x600C + (12 * 7) + 8 ) -#define N_A7 (0x600C + (12 * 7) + 9 ) -#define N_A7S (0x600C + (12 * 7) + 10) -#define N_B7F (0x600C + (12 * 7) + 10) -#define N_B7 (0x600C + (12 * 7) + 11) -#define N_C8 (0x600C + (12 * 8) + 0 ) -#define N_C8S (0x600C + (12 * 8) + 1 ) -#define N_D8F (0x600C + (12 * 8) + 1 ) -#define N_D8 (0x600C + (12 * 8) + 2 ) -#define N_D8S (0x600C + (12 * 8) + 3 ) -#define N_E8F (0x600C + (12 * 8) + 3 ) -#define N_E8 (0x600C + (12 * 8) + 4 ) -#define N_F8 (0x600C + (12 * 8) + 5 ) -#define N_F8S (0x600C + (12 * 8) + 6 ) -#define N_G8F (0x600C + (12 * 8) + 6 ) -#define N_G8 (0x600C + (12 * 8) + 7 ) -#define N_G8S (0x600C + (12 * 8) + 8 ) -#define N_A8F (0x600C + (12 * 8) + 8 ) -#define N_A8 (0x600C + (12 * 8) + 9 ) -#define N_A8S (0x600C + (12 * 8) + 10) -#define N_B8F (0x600C + (12 * 8) + 10) -#define N_B8 (0x600C + (12 * 8) + 11) -#define N_C8 (0x600C + (12 * 8) + 0 ) -#define N_C8S (0x600C + (12 * 8) + 1 ) -#define N_D8F (0x600C + (12 * 8) + 1 ) -#define N_D8 (0x600C + (12 * 8) + 2 ) -#define N_D8S (0x600C + (12 * 8) + 3 ) -#define N_E8F (0x600C + (12 * 8) + 3 ) -#define N_E8 (0x600C + (12 * 8) + 4 ) -#define N_F8 (0x600C + (12 * 8) + 5 ) -#define N_F8S (0x600C + (12 * 8) + 6 ) -#define N_G8F (0x600C + (12 * 8) + 6 ) -#define N_G8 (0x600C + (12 * 8) + 7 ) -#define N_G8S (0x600C + (12 * 8) + 8 ) -#define N_A8F (0x600C + (12 * 8) + 8 ) -#define N_A8 (0x600C + (12 * 8) + 9 ) -#define N_A8S (0x600C + (12 * 8) + 10) -#define N_B8F (0x600C + (12 * 8) + 10) -#define N_B8 (0x600C + (12 * 8) + 11) - #endif \ No newline at end of file diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index f2b9509b5..4423d25ef 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -224,8 +224,12 @@ enum quantum_keycodes { MI_SUS, // sustain MI_PORT, // portamento MI_SOST, // sostenuto - MI_SOFT, // soft + MI_SOFT, // soft pedal MI_LEG, // legato + + MI_MOD, // modulation + MI_MODSD, // decrease modulation speed + MI_MODSU, // increase modulation speed #endif // Backlight functionality diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index fb60658df..bd2498057 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1180,7 +1180,7 @@ int main(void) #ifdef MIDI_ENABLE midi_device_process(&midi_device); - // MIDI_Task(); + midi_task(); #endif #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) -- cgit v1.2.3 From 5e6097f0154403dccb9b5658390c84441aa509bc Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 18 Feb 2017 06:19:48 -0800 Subject: add keycodes for transpose range --- quantum/process_keycode/process_midi.c | 37 +++++++++++++++++++++++++++------- quantum/quantum_keycodes.h | 18 +++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index d09aa0b38..4d60aefb1 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -2,12 +2,13 @@ #include "timer.h" typedef union { - uint16_t raw; + uint32_t raw; struct { - uint8_t octave :4; - uint8_t velocity :4; - uint8_t channel :4; - uint8_t modulation_interval :4; + uint8_t octave :4; + int8_t transpose :4; + uint8_t velocity :4; + uint8_t channel :4; + uint8_t modulation_interval :4; }; } midi_config_t; @@ -29,7 +30,8 @@ inline uint8_t compute_velocity(uint8_t setting) void midi_init(void) { - midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN; + midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; + midi_config.transpose = 0; midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); midi_config.channel = 0; midi_config.modulation_interval = 8; @@ -77,7 +79,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) uint8_t tone = keycode - MIDI_TONE_MIN; uint8_t velocity = compute_velocity(midi_config.velocity); if (record->event.pressed) { - uint8_t note = 12 * midi_config.octave + tone; + uint8_t note = 12 * midi_config.octave + tone + midi_config.transpose; midi_send_noteon(&midi_device, channel, note, velocity); dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); tone_status[tone] = note; @@ -111,6 +113,27 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) dprintf("midi octave %d\n", midi_config.octave); } return false; + case MIDI_TRANSPOSE_MIN ... MIDI_TRANSPOSE_MAX: + if (record->event.pressed) { + midi_config.transpose = keycode - MI_TRNS_0; + dprintf("midi transpose %d\n", midi_config.transpose); + } + return false; + case MI_TRNSD: + if (record->event.pressed && midi_config.transpose > (MIDI_TRANSPOSE_MIN - MI_TRNS_0)) { + midi_config.transpose--; + dprintf("midi transpose %d\n", midi_config.transpose); + } + return false; + case MI_TRNSU: + if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { + const bool positive = midi_config.transpose > 0; + midi_config.transpose++; + if (positive && midi_config.transpose < 0) + midi_config.transpose--; + dprintf("midi transpose %d\n", midi_config.transpose); + } + return false; case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: if (record->event.pressed) { midi_config.velocity = keycode - MIDI_VELOCITY_MIN; diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 4423d25ef..30cc9abdb 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -183,6 +183,24 @@ enum quantum_keycodes { MI_OCTD, // octave down MI_OCTU, // octave up + MIDI_TRANSPOSE_MIN, + MI_TRNS_N6 = MIDI_TRANSPOSE_MIN, + MI_TRNS_N5, + MI_TRNS_N4, + MI_TRNS_N3, + MI_TRNS_N2, + MI_TRNS_N1, + MI_TRNS_0, + MI_TRNS_1, + MI_TRNS_2, + MI_TRNS_3, + MI_TRNS_4, + MI_TRNS_5, + MI_TRNS_6, + MIDI_TRANSPOSE_MAX = MI_TRNS_6, + MI_TRNSD, // transpose down + MI_TRNSU, // transpose up + MIDI_VELOCITY_MIN, MI_VEL_1 = MIDI_VELOCITY_MIN, MI_VEL_2, -- cgit v1.2.3 From d1fe24ad9f85768774ae50465c71f3757a33cc00 Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sun, 19 Feb 2017 17:18:05 -0800 Subject: Allow customization of the number of tone keycodes and add example keymap --- keyboards/satan/keymaps/midi/Makefile | 21 +++++++++ keyboards/satan/keymaps/midi/config.h | 11 +++++ keyboards/satan/keymaps/midi/keymap.c | 60 ++++++++++++++++++++++++ keyboards/satan/keymaps/midi/readme.md | 1 + quantum/quantum_keycodes.h | 84 ++++++++++++++++++++++++++++++++++ quantum/template/config.h | 3 ++ 6 files changed, 180 insertions(+) create mode 100644 keyboards/satan/keymaps/midi/Makefile create mode 100644 keyboards/satan/keymaps/midi/config.h create mode 100644 keyboards/satan/keymaps/midi/keymap.c create mode 100644 keyboards/satan/keymaps/midi/readme.md (limited to 'quantum/quantum_keycodes.h') diff --git a/keyboards/satan/keymaps/midi/Makefile b/keyboards/satan/keymaps/midi/Makefile new file mode 100644 index 000000000..5cbda96ce --- /dev/null +++ b/keyboards/satan/keymaps/midi/Makefile @@ -0,0 +1,21 @@ +# Build Options +# change to "no" to disable the options, or define them in the Makefile in +# the appropriate keymap folder that will get included automatically +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = no # Console for debug(+400) +COMMAND_ENABLE = yes # Commands for debug and configuration +NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +MIDI_ENABLE = yes # MIDI controls +AUDIO_ENABLE = no # Audio output on port C6 +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend + +ifndef QUANTUM_DIR + include ../../../../Makefile +endif diff --git a/keyboards/satan/keymaps/midi/config.h b/keyboards/satan/keymaps/midi/config.h new file mode 100644 index 000000000..e345d40c9 --- /dev/null +++ b/keyboards/satan/keymaps/midi/config.h @@ -0,0 +1,11 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +// place overrides here + +/* override number of MIDI tone keycodes (each octave adds 12 bytes) */ +#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/satan/keymaps/midi/keymap.c b/keyboards/satan/keymaps/midi/keymap.c new file mode 100644 index 000000000..ac9725933 --- /dev/null +++ b/keyboards/satan/keymaps/midi/keymap.c @@ -0,0 +1,60 @@ +#include "satan.h" + +// Each layer gets a name for readability, which is then used in the keymap matrix below. +// The underscores don't mean anything - you can have a layer called STUFF or any other name. +// Layer names don't all need to be of the same length, obviously, and you can also skip them +// entirely and just use numbers. +#define _BL 0 +#define _ML 1 + +// readability +#define _______ KC_TRNS +#define XXXXXXX KC_NO + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Keymap _BL: (Base Layer) Default Layer + * ,-----------------------------------------------------------. + * |Esc | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | + * |-----------------------------------------------------------| + * |CAPS | A| S| D| F| G| H| J| K| L| ;| '|Return | + * |-----------------------------------------------------------| + * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | + * |-----------------------------------------------------------| + * |Ctrl|Gui |Alt | Space |Alt |Gui |FN |Ctrl | + * `-----------------------------------------------------------' + */ +[_BL] = KEYMAP_ANSI( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC,KC_BSLS, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \ + KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(_ML), KC_RCTL), + +/* Keymap _ML: MIDI Layer + * ,------------------------------------------------------------------------. + * | Exit | | | | | | | | | | | | | | + * |------------------------------------------------------------------------| + * | Ch+ | | C# | D# | | F# | G# | A# | | C# | D# | | | | + * |------------------------------------------------------------------------| + * | Mod | C | D | E | F | G | A | B | C | D | E | F |>>OnStage| + * |------------------------------------------------------------------------| + * | Sustain |Oct-|Oct+|Mod-|Mod+| | | |Tns-|Tns+|Tns0| Sustain | + * |------------------------------------------------------------------------| + * | | | | All notes off | | | | | + * `------------------------------------------------------------------------' + * + * Foot switches: + * ,--------. ,--------. + * | | | | + * | | | | + * `--------' `--------' + */ +[_ML] = KEYMAP_ANSI( + TG(_ML), MI_VEL_1, MI_VEL_2, MI_VEL_3, MI_VEL_4, MI_VEL_5, MI_VEL_6, MI_VEL_7, MI_VEL_8, MI_VEL_9, MI_VEL_10, XXXXXXX, XXXXXXX, XXXXXXX, \ + MI_CHU, XXXXXXX, MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX, XXXXXXX, \ + MI_MOD, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1, _______, \ + MI_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \ + _______, _______, _______, MI_OFF, _______, _______, _______, _______), +}; \ No newline at end of file diff --git a/keyboards/satan/keymaps/midi/readme.md b/keyboards/satan/keymaps/midi/readme.md new file mode 100644 index 000000000..87844a854 --- /dev/null +++ b/keyboards/satan/keymaps/midi/readme.md @@ -0,0 +1 @@ +# Satan GH60 layout demonstrating MIDI key mapping diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 30cc9abdb..6d1438051 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -2,6 +2,12 @@ #ifndef QUANTUM_KEYCODES_H #define QUANTUM_KEYCODES_H +#ifdef MIDI_ENABLE +#ifndef MIDI_TONE_KEYCODE_OCTAVES +#define MIDI_TONE_KEYCODE_OCTAVES 3 +#endif +#endif + enum quantum_keycodes { // Ranges used in shortucuts - not to be used directly QK_TMK = 0x0000, @@ -112,6 +118,7 @@ enum quantum_keycodes { MIDI_TONE_MIN, +#if MIDI_TONE_KEYCODE_OCTAVES > 0 MI_C = MIDI_TONE_MIN, MI_Cs, MI_Db = MI_Cs, @@ -129,7 +136,9 @@ enum quantum_keycodes { MI_As, MI_Bb = MI_As, MI_B, +#endif +#if MIDI_TONE_KEYCODE_OCTAVES > 1 MI_C_1, MI_Cs_1, MI_Db_1 = MI_Cs_1, @@ -147,7 +156,9 @@ enum quantum_keycodes { MI_As_1, MI_Bb_1 = MI_As_1, MI_B_1, +#endif +#if MIDI_TONE_KEYCODE_OCTAVES > 2 MI_C_2, MI_Cs_2, MI_Db_2 = MI_Cs_2, @@ -165,8 +176,81 @@ enum quantum_keycodes { MI_As_2, MI_Bb_2 = MI_As_2, MI_B_2, +#endif +#if MIDI_TONE_KEYCODE_OCTAVES > 3 + MI_C_3, + MI_Cs_3, + MI_Db_3 = MI_Cs_3, + MI_D_3, + MI_Ds_3, + MI_Eb_3 = MI_Ds_3, + MI_E_3, + MI_F_3, + MI_Fs_3, + MI_Gb_3 = MI_Fs_3, + MI_G_3, + MI_Gs_3, + MI_Ab_3 = MI_Gs_3, + MI_A_3, + MI_As_3, + MI_Bb_3 = MI_As_3, + MI_B_3, +#endif + +#if MIDI_TONE_KEYCODE_OCTAVES > 4 + MI_C_4, + MI_Cs_4, + MI_Db_4 = MI_Cs_4, + MI_D_4, + MI_Ds_4, + MI_Eb_4 = MI_Ds_4, + MI_E_4, + MI_F_4, + MI_Fs_4, + MI_Gb_4 = MI_Fs_4, + MI_G_4, + MI_Gs_4, + MI_Ab_4 = MI_Gs_4, + MI_A_4, + MI_As_4, + MI_Bb_4 = MI_As_4, + MI_B_4, +#endif + +#if MIDI_TONE_KEYCODE_OCTAVES > 5 + MI_C_5, + MI_Cs_5, + MI_Db_5 = MI_Cs_5, + MI_D_5, + MI_Ds_5, + MI_Eb_5 = MI_Ds_5, + MI_E_5, + MI_F_5, + MI_Fs_5, + MI_Gb_5 = MI_Fs_5, + MI_G_5, + MI_Gs_5, + MI_Ab_5 = MI_Gs_5, + MI_A_5, + MI_As_5, + MI_Bb_5 = MI_As_5, + MI_B_5, +#endif + +#if MIDI_TONE_KEYCODE_OCTAVES > 5 + MIDI_TONE_MAX = MI_B_5, +#elif MIDI_TONE_KEYCODE_OCTAVES > 4 + MIDI_TONE_MAX = MI_B_4, +#elif MIDI_TONE_KEYCODE_OCTAVES > 3 + MIDI_TONE_MAX = MI_B_3, +#elif MIDI_TONE_KEYCODE_OCTAVES > 2 MIDI_TONE_MAX = MI_B_2, +#elif MIDI_TONE_KEYCODE_OCTAVES > 1 + MIDI_TONE_MAX = MI_B_1, +#elif MIDI_TONE_KEYCODE_OCTAVES > 0 + MIDI_TONE_MAX = MI_B, +#endif MIDI_OCTAVE_MIN, MI_OCT_N2 = MIDI_OCTAVE_MIN, diff --git a/quantum/template/config.h b/quantum/template/config.h index c61c4a618..d0bee0d89 100644 --- a/quantum/template/config.h +++ b/quantum/template/config.h @@ -159,4 +159,7 @@ along with this program. If not, see . //#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION +/* override number of MIDI tone keycodes (each octave adds 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 1 + #endif -- cgit v1.2.3 From 525be99ee938aa6e48448d7dd6ea6e6fe50bb36d Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 25 Feb 2017 15:02:43 -0800 Subject: Split MIDI functionality into MIDI_BASIC and MIDI_ADVANCED MIDI_ENABLE = no text data bss dec hex filename 0 17080 0 17080 42b8 satan_midi.hex MIDI_ENABLE = yes MIDI_BASIC undefined MIDI_ADVANCED undefined text data bss dec hex filename 0 19494 0 19494 4c26 satan_midi.hex MIDI_ENABLE = yes #define MIDI_BASIC MIDI_ADVANCED undefined text data bss dec hex filename 0 19788 0 19788 4d4c satan_midi.hex MIDI_ENABLE = yes MIDI_BASIC undefined #define MIDI_ADVANCED text data bss dec hex filename 0 20846 0 20846 516e satan_midi.hex MIDI_ENABLE = yes #define MIDI_BASIC #define MIDI_ADVANCED text data bss dec hex filename 0 21140 0 21140 5294 satan_midi.hex --- build_keyboard.mk | 1 + keyboards/satan/keymaps/midi/config.h | 17 ++++++++++++++++- keyboards/satan/keymaps/midi/keymap.c | 4 ++-- quantum/process_keycode/process_midi.c | 9 ++++++--- quantum/process_keycode/process_music.c | 22 ++++++++++++++++++++++ quantum/quantum.c | 4 ++-- quantum/quantum_keycodes.h | 13 ++++++++++--- quantum/template/config.h | 17 +++++++++++++++++ tmk_core/protocol/lufa/lufa.c | 4 ++++ 9 files changed, 80 insertions(+), 11 deletions(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/build_keyboard.mk b/build_keyboard.mk index 4a6fc0980..eea8d5919 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -141,6 +141,7 @@ endif ifeq ($(strip $(MIDI_ENABLE)), yes) OPT_DEFS += -DMIDI_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_music.c SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c endif diff --git a/keyboards/satan/keymaps/midi/config.h b/keyboards/satan/keymaps/midi/config.h index 0dbdb5cbc..59250b49e 100644 --- a/keyboards/satan/keymaps/midi/config.h +++ b/keyboards/satan/keymaps/midi/config.h @@ -3,7 +3,22 @@ #include "../../config.h" -// place overrides here +/* + * MIDI options + */ + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +#define MIDI_ADVANCED /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ #define MIDI_TONE_KEYCODE_OCTAVES 2 diff --git a/keyboards/satan/keymaps/midi/keymap.c b/keyboards/satan/keymaps/midi/keymap.c index 397fe097b..349391c3b 100644 --- a/keyboards/satan/keymaps/midi/keymap.c +++ b/keyboards/satan/keymaps/midi/keymap.c @@ -32,7 +32,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \ KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(_ML), KC_RCTL), -#ifdef MIDI_ENABLE +#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) /* Keymap _ML: MIDI Layer * ,------------------------------------------------------------------------. * | Exit | | | | | | | | | | | | | | @@ -51,6 +51,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { MI_CHU, XXXXXXX, MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX, XXXXXXX, \ MI_MOD, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1, _______, \ MI_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \ - _______, _______, _______, MI_OFF, _______, _______, _______, _______), + _______, _______, _______, MI_ALLOFF, _______, _______, _______, _______), #endif }; \ No newline at end of file diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 5530ea97c..161f04a24 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -1,6 +1,7 @@ -#define MIDI_TONE_KEYCODE_OCTAVES 2 - #include "process_midi.h" + +#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) + #include "timer.h" static uint8_t tone_status[MIDI_TONE_COUNT]; @@ -161,7 +162,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) dprintf("midi channel %d\n", midi_config.channel); } return false; - case MI_OFF: + case MI_ALLOFF: if (record->event.pressed) { midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0); dprintf("midi off\n"); @@ -209,3 +210,5 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) return true; } + +#endif // MIDI_ADVANCED diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 1e2648bff..ac906b628 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -17,6 +17,7 @@ static uint16_t music_sequence_interval = 100; bool process_music(uint16_t keycode, keyrecord_t *record) { + #ifdef AUDIO_ENABLE if (keycode == AU_ON && record->event.pressed) { audio_on(); return false; @@ -38,6 +39,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } return false; } + #endif // AUDIO_ENABLE if (keycode == MU_ON && record->event.pressed) { music_on(); @@ -61,6 +63,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { return false; } + #ifdef AUDIO_ENABLE if (keycode == MUV_IN && record->event.pressed) { voice_iterate(); music_scale_user(); @@ -72,11 +75,14 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { music_scale_user(); return false; } + #endif // AUDIO_ENABLE if (music_activated) { if (keycode == KC_LCTL && record->event.pressed) { // Start recording + #ifdef AUDIO_ENABLE stop_all_notes(); + #endif music_sequence_recording = true; music_sequence_recorded = false; music_sequence_playing = false; @@ -85,7 +91,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing + #ifdef AUDIO_ENABLE stop_all_notes(); + #endif if (music_sequence_recording) { // was recording music_sequence_recorded = true; } @@ -95,7 +103,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing + #ifdef AUDIO_ENABLE stop_all_notes(); + #endif music_sequence_recording = false; music_sequence_playing = true; music_sequence_position = 0; @@ -116,6 +126,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } #define MUSIC_MODE_GUITAR + #ifdef AUDIO_ENABLE #ifdef MUSIC_MODE_CHROMATIC float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row)); #elif defined(MUSIC_MODE_GUITAR) @@ -125,15 +136,20 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { #else float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); #endif + #endif // AUDIO_ENABLE if (record->event.pressed) { + #ifdef AUDIO_ENABLE play_note(freq, 0xF); if (music_sequence_recording) { music_sequence[music_sequence_count] = freq; music_sequence_count++; } + #endif } else { + #ifdef AUDIO_ENABLE stop_note(freq); + #endif } if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through @@ -161,15 +177,19 @@ void music_on(void) { void music_off(void) { music_activated = 0; + #ifdef AUDIO_ENABLE stop_all_notes(); + #endif } __attribute__ ((weak)) void music_on_user() {} +#ifdef AUDIO_ENABLE __attribute__ ((weak)) void audio_on_user() {} +#endif __attribute__ ((weak)) void music_scale_user() {} @@ -178,8 +198,10 @@ void matrix_scan_music(void) { if (music_sequence_playing) { if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { music_sequence_timer = timer_read(); + #ifdef AUDIO_ENABLE stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]); play_note(music_sequence[music_sequence_position], 0xF); + #endif music_sequence_position = (music_sequence_position + 1) % music_sequence_count; } } diff --git a/quantum/quantum.c b/quantum/quantum.c index 4a6d0355f..83fa87708 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -150,10 +150,10 @@ bool process_record_quantum(keyrecord_t *record) { if (!( process_record_kb(keycode, record) && - #ifdef MIDI_ENABLE + #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) process_midi(keycode, record) && #endif - #ifdef AUDIO_ENABLE + #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) process_music(keycode, record) && #endif #ifdef TAP_DANCE_ENABLE diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 6d1438051..3b82b7208 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -2,7 +2,7 @@ #ifndef QUANTUM_KEYCODES_H #define QUANTUM_KEYCODES_H -#ifdef MIDI_ENABLE +#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) #ifndef MIDI_TONE_KEYCODE_OCTAVES #define MIDI_TONE_KEYCODE_OCTAVES 3 #endif @@ -116,6 +116,12 @@ enum quantum_keycodes { #ifdef MIDI_ENABLE // Midi +#ifdef MIDI_BASIC + MI_ON, // send midi notes when music mode is enabled + MI_OFF, // don't send midi notes when music mode is enabled +#endif + +#ifdef MIDI_ADVANCED MIDI_TONE_MIN, #if MIDI_TONE_KEYCODE_OCTAVES > 0 @@ -321,7 +327,7 @@ enum quantum_keycodes { MI_CHD, // previous channel MI_CHU, // next channel - MI_OFF, // all notes off + MI_ALLOFF, // all notes off MI_SUS, // sustain MI_PORT, // portamento @@ -332,7 +338,8 @@ enum quantum_keycodes { MI_MOD, // modulation MI_MODSD, // decrease modulation speed MI_MODSU, // increase modulation speed -#endif +#endif // MIDI_ADVANCED +#endif // MIDI_ENABLE // Backlight functionality BL_0, diff --git a/quantum/template/config.h b/quantum/template/config.h index cd6dfa2c6..54db4f242 100644 --- a/quantum/template/config.h +++ b/quantum/template/config.h @@ -159,6 +159,23 @@ along with this program. If not, see . //#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION +/* + * MIDI options + */ + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +//#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index bd2498057..651a0f347 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1104,7 +1104,9 @@ void sysex_callback(MidiDevice * device, void setup_midi(void) { +#ifdef MIDI_ADVANCED midi_init(); +#endif midi_device_init(&midi_device); midi_device_set_send_func(&midi_device, usb_send_func); midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); @@ -1180,8 +1182,10 @@ int main(void) #ifdef MIDI_ENABLE midi_device_process(&midi_device); +#ifdef MIDI_ADVANCED midi_task(); #endif +#endif #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) rgblight_task(); -- cgit v1.2.3 From a64ae1066250d3aafb6e9670bf617237ec4338e7 Mon Sep 17 00:00:00 2001 From: Gabriel Young Date: Sat, 25 Feb 2017 20:41:13 -0800 Subject: Update existing keymaps Update existing keymaps to enable MIDI_BASIC functionality. Also added an option MIDI_ENABLE_STRICT to be strict about keycode use (which also reduces memory footprint at runtime) --- keyboards/planck/keymaps/dbroqua/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/default/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/experimental/config.h | 23 ++++++++++++++++++ keyboards/planck/keymaps/impossible/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/jeebak/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/jhenahan/config.h | 23 ++++++++++++++++++ keyboards/planck/keymaps/premek/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/sgoodwin/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/smt/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/thermal_printer/config.h | 23 ++++++++++++++++++ keyboards/planck/keymaps/unicode/config.h | 29 +++++++++++++++++++++++ keyboards/planck/keymaps/xyverz/config.h | 29 +++++++++++++++++++++++ keyboards/preonic/keymaps/CMD-Preonic/config.h | 29 +++++++++++++++++++++++ keyboards/preonic/keymaps/default/config.h | 29 +++++++++++++++++++++++ keyboards/preonic/keymaps/smt/config.h | 29 +++++++++++++++++++++++ keyboards/satan/keymaps/midi/config.h | 3 +++ keyboards/subatomic/keymaps/default/config.h | 29 +++++++++++++++++++++++ quantum/process_keycode/process_audio.c | 4 ++-- quantum/process_keycode/process_music.c | 2 +- quantum/process_keycode/process_music.h | 1 + quantum/quantum.c | 4 ++-- quantum/quantum_keycodes.h | 28 +++++++++++----------- quantum/template/config.h | 3 +++ 23 files changed, 472 insertions(+), 19 deletions(-) create mode 100644 keyboards/planck/keymaps/dbroqua/config.h create mode 100644 keyboards/planck/keymaps/default/config.h create mode 100644 keyboards/planck/keymaps/impossible/config.h create mode 100644 keyboards/planck/keymaps/jeebak/config.h create mode 100644 keyboards/planck/keymaps/premek/config.h create mode 100644 keyboards/planck/keymaps/sgoodwin/config.h create mode 100644 keyboards/planck/keymaps/smt/config.h create mode 100644 keyboards/planck/keymaps/unicode/config.h create mode 100644 keyboards/planck/keymaps/xyverz/config.h create mode 100644 keyboards/preonic/keymaps/CMD-Preonic/config.h create mode 100644 keyboards/preonic/keymaps/default/config.h create mode 100644 keyboards/preonic/keymaps/smt/config.h create mode 100644 keyboards/subatomic/keymaps/default/config.h (limited to 'quantum/quantum_keycodes.h') diff --git a/keyboards/planck/keymaps/dbroqua/config.h b/keyboards/planck/keymaps/dbroqua/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/dbroqua/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/default/config.h b/keyboards/planck/keymaps/default/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/default/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/experimental/config.h b/keyboards/planck/keymaps/experimental/config.h index cc093bee4..492490ca1 100644 --- a/keyboards/planck/keymaps/experimental/config.h +++ b/keyboards/planck/keymaps/experimental/config.h @@ -14,4 +14,27 @@ #define RGBLIGHT_HUE_STEP 10 #define RGBLIGHT_SAT_STEP 17 +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + #endif diff --git a/keyboards/planck/keymaps/impossible/config.h b/keyboards/planck/keymaps/impossible/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/impossible/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/jeebak/config.h b/keyboards/planck/keymaps/jeebak/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/jeebak/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/jhenahan/config.h b/keyboards/planck/keymaps/jhenahan/config.h index cd3adc41c..1e42b92b9 100644 --- a/keyboards/planck/keymaps/jhenahan/config.h +++ b/keyboards/planck/keymaps/jhenahan/config.h @@ -6,4 +6,27 @@ #define FORCE_NKRO #define WORKMAN_SOUND COLEMAK_SOUND +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + #endif diff --git a/keyboards/planck/keymaps/premek/config.h b/keyboards/planck/keymaps/premek/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/premek/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/sgoodwin/config.h b/keyboards/planck/keymaps/sgoodwin/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/sgoodwin/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/smt/config.h b/keyboards/planck/keymaps/smt/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/smt/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/thermal_printer/config.h b/keyboards/planck/keymaps/thermal_printer/config.h index 430b6493c..bcd098930 100644 --- a/keyboards/planck/keymaps/thermal_printer/config.h +++ b/keyboards/planck/keymaps/thermal_printer/config.h @@ -20,4 +20,27 @@ sei(); \ } while(0) +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + #endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/unicode/config.h b/keyboards/planck/keymaps/unicode/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/unicode/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/planck/keymaps/xyverz/config.h b/keyboards/planck/keymaps/xyverz/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/planck/keymaps/xyverz/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/preonic/keymaps/CMD-Preonic/config.h b/keyboards/preonic/keymaps/CMD-Preonic/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/preonic/keymaps/CMD-Preonic/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/preonic/keymaps/default/config.h b/keyboards/preonic/keymaps/default/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/preonic/keymaps/default/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/preonic/keymaps/smt/config.h b/keyboards/preonic/keymaps/smt/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/preonic/keymaps/smt/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/keyboards/satan/keymaps/midi/config.h b/keyboards/satan/keymaps/midi/config.h index 59250b49e..8e10b04ec 100644 --- a/keyboards/satan/keymaps/midi/config.h +++ b/keyboards/satan/keymaps/midi/config.h @@ -7,6 +7,9 @@ * MIDI options */ +/* Prevent use of disabled MIDI features in the keymap */ +#define MIDI_ENABLE_STRICT 1 + /* enable basic MIDI features: - MIDI notes can be sent when in Music mode is on */ diff --git a/keyboards/subatomic/keymaps/default/config.h b/keyboards/subatomic/keymaps/default/config.h new file mode 100644 index 000000000..4c6158199 --- /dev/null +++ b/keyboards/subatomic/keymaps/default/config.h @@ -0,0 +1,29 @@ +#ifndef CONFIG_USER_H +#define CONFIG_USER_H + +#include "../../config.h" + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 2 + +#endif \ No newline at end of file diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index d45242c9e..71c0297ee 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c @@ -1,5 +1,5 @@ -#include "process_audio.h" #include "audio.h" +#include "process_audio.h" static float compute_freq_for_midi_note(uint8_t note) { @@ -43,7 +43,7 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) { return false; } - return true + return true; } void process_audio_noteon(uint8_t note) { diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 43bcf973e..4b86b91f0 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -42,7 +42,7 @@ static void music_noteoff(uint8_t note) { #endif } -static void music_all_notes_off(void) { +void music_all_notes_off(void) { #ifdef AUDIO_ENABLE process_audio_stop_all_notes(); #endif diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 69913b276..a36514a44 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h @@ -14,6 +14,7 @@ void music_off(void); void music_on_user(void); void music_scale_user(void); +void music_all_notes_off(void); void matrix_scan_music(void); diff --git a/quantum/quantum.c b/quantum/quantum.c index 7a27a568a..a4a12061b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -95,8 +95,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { void reset_keyboard(void) { clear_keyboard(); -#ifdef AUDIO_ENABLE - stop_all_notes(); +#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_ENABLE_BASIC)) + music_all_notes_off(); shutdown_user(); #endif wait_ms(250); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 3b82b7208..56228f276 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -1,8 +1,11 @@ - #ifndef QUANTUM_KEYCODES_H #define QUANTUM_KEYCODES_H -#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) +#ifndef MIDI_ENABLE_STRICT +#define MIDI_ENABLE_STRICT 0 +#endif + +#if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)) #ifndef MIDI_TONE_KEYCODE_OCTAVES #define MIDI_TONE_KEYCODE_OCTAVES 3 #endif @@ -113,18 +116,16 @@ enum quantum_keycodes { MUV_IN, MUV_DE, -#ifdef MIDI_ENABLE // Midi - -#ifdef MIDI_BASIC +#if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) MI_ON, // send midi notes when music mode is enabled MI_OFF, // don't send midi notes when music mode is enabled #endif -#ifdef MIDI_ADVANCED +#if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)) MIDI_TONE_MIN, -#if MIDI_TONE_KEYCODE_OCTAVES > 0 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 0 MI_C = MIDI_TONE_MIN, MI_Cs, MI_Db = MI_Cs, @@ -144,7 +145,7 @@ enum quantum_keycodes { MI_B, #endif -#if MIDI_TONE_KEYCODE_OCTAVES > 1 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 1 MI_C_1, MI_Cs_1, MI_Db_1 = MI_Cs_1, @@ -164,7 +165,7 @@ enum quantum_keycodes { MI_B_1, #endif -#if MIDI_TONE_KEYCODE_OCTAVES > 2 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 2 MI_C_2, MI_Cs_2, MI_Db_2 = MI_Cs_2, @@ -184,7 +185,7 @@ enum quantum_keycodes { MI_B_2, #endif -#if MIDI_TONE_KEYCODE_OCTAVES > 3 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 3 MI_C_3, MI_Cs_3, MI_Db_3 = MI_Cs_3, @@ -204,7 +205,7 @@ enum quantum_keycodes { MI_B_3, #endif -#if MIDI_TONE_KEYCODE_OCTAVES > 4 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 4 MI_C_4, MI_Cs_4, MI_Db_4 = MI_Cs_4, @@ -224,7 +225,7 @@ enum quantum_keycodes { MI_B_4, #endif -#if MIDI_TONE_KEYCODE_OCTAVES > 5 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5 MI_C_5, MI_Cs_5, MI_Db_5 = MI_Cs_5, @@ -244,7 +245,7 @@ enum quantum_keycodes { MI_B_5, #endif -#if MIDI_TONE_KEYCODE_OCTAVES > 5 +#if !MIDI_ENABLE_STRICT || MIDI_TONE_KEYCODE_OCTAVES > 5 MIDI_TONE_MAX = MI_B_5, #elif MIDI_TONE_KEYCODE_OCTAVES > 4 MIDI_TONE_MAX = MI_B_4, @@ -339,7 +340,6 @@ enum quantum_keycodes { MI_MODSD, // decrease modulation speed MI_MODSU, // increase modulation speed #endif // MIDI_ADVANCED -#endif // MIDI_ENABLE // Backlight functionality BL_0, diff --git a/quantum/template/config.h b/quantum/template/config.h index 54db4f242..7393097e1 100644 --- a/quantum/template/config.h +++ b/quantum/template/config.h @@ -163,6 +163,9 @@ along with this program. If not, see . * MIDI options */ +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + /* enable basic MIDI features: - MIDI notes can be sent when in Music mode is on */ -- cgit v1.2.3 From ddc036b69ea508750f5129d9a43fee484148716a Mon Sep 17 00:00:00 2001 From: Travis La Marr Date: Fri, 24 Mar 2017 12:53:55 -0400 Subject: Refactor Bluetooth Handling Refactored Bluetooth support to make adding new Bluetooth modules easier in the future. * Remove `OUT_BLE` key from QMK's keymap. `OUT_BT` is all we need now as there's no difference anymore. * Made BLUETOOTH_ENABLE build option legacy as not to break existing keymaps (Falls back to existing EZ Key support if on) * Removed `ADAFRUIT_BLE_ENABLE` build option * Created new build option `BLUETOOTH` with module option (Currently `AdafruitEZKey` & `AdafruitBLE`) * Moved all LUFA bluetooth key/mouse events under `BLUETOOTH_ENABLE` ifdef with selected modules output. --- quantum/quantum.c | 8 ---- quantum/quantum_keycodes.h | 3 -- tmk_core/common.mk | 12 ++++-- tmk_core/protocol/lufa.mk | 12 ++++-- tmk_core/protocol/lufa/adafruit_ble.h | 4 +- tmk_core/protocol/lufa/lufa.c | 77 ++++++++++++++++------------------- tmk_core/protocol/lufa/outputselect.c | 6 +-- tmk_core/protocol/lufa/outputselect.h | 1 - 8 files changed, 57 insertions(+), 66 deletions(-) (limited to 'quantum/quantum_keycodes.h') diff --git a/quantum/quantum.c b/quantum/quantum.c index 582f8920b..807a7084a 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -294,14 +294,6 @@ bool process_record_quantum(keyrecord_t *record) { return false; break; #endif - #ifdef ADAFRUIT_BLE_ENABLE - case OUT_BLE: - if (record->event.pressed) { - set_output(OUTPUT_ADAFRUIT_BLE); - } - return false; - break; - #endif #endif case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: if (record->event.pressed) { diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 903d57f1e..78b02a0de 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -159,9 +159,6 @@ enum quantum_keycodes { #ifdef BLUETOOTH_ENABLE OUT_BT, #endif -#ifdef ADAFRUIT_BLE_ENABLE - OUT_BLE, -#endif // always leave at the end SAFE_RANGE diff --git a/tmk_core/common.mk b/tmk_core/common.mk index a86dccc61..2b0fda5f2 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -93,14 +93,18 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE endif -ifeq ($(strip $(ADAFRUIT_BLE_ENABLE)), yes) - TMK_COMMON_DEFS += -DADAFRUIT_BLE_ENABLE -endif - ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE endif +ifeq ($(strip $(BLUETOOTH)), AdafruitBLE) + TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE +endif + +ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey) + TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE +endif + ifeq ($(strip $(ONEHAND_ENABLE)), yes) TMK_COMMON_DEFS += -DONEHAND_ENABLE endif diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk index de0cc795f..5b1577972 100644 --- a/tmk_core/protocol/lufa.mk +++ b/tmk_core/protocol/lufa.mk @@ -22,11 +22,16 @@ ifeq ($(strip $(MIDI_ENABLE)), yes) include $(TMK_PATH)/protocol/midi.mk endif -ifeq ($(strip $(ADAFRUIT_BLE_ENABLE)), yes) - LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp +ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) + LUFA_SRC += $(LUFA_DIR)/bluetooth.c \ + $(TMK_DIR)/protocol/serial_uart.c endif -ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) +ifeq ($(strip $(BLUETOOTH)), AdafruitBLE) + LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp +endif + +ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey) LUFA_SRC += $(LUFA_DIR)/bluetooth.c \ $(TMK_DIR)/protocol/serial_uart.c endif @@ -54,6 +59,7 @@ LUFA_OPTS += -DUSE_FLASH_DESCRIPTORS LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" #LUFA_OPTS += -DINTERRUPT_CONTROL_ENDPOINT LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1 # Remote wakeup fix for ATmega32U2 https://github.com/tmk/tmk_keyboard/issues/361 diff --git a/tmk_core/protocol/lufa/adafruit_ble.h b/tmk_core/protocol/lufa/adafruit_ble.h index 351fd55ae..b3bab3ca0 100644 --- a/tmk_core/protocol/lufa/adafruit_ble.h +++ b/tmk_core/protocol/lufa/adafruit_ble.h @@ -3,7 +3,7 @@ * Supports the Adafruit BLE board built around the nRF51822 chip. */ #pragma once -#ifdef ADAFRUIT_BLE_ENABLE +#ifdef MODULE_ADAFRUIT_BLE #include #include #include @@ -57,4 +57,4 @@ extern bool adafruit_ble_set_power_level(int8_t level); } #endif -#endif // ADAFRUIT_BLE_ENABLE +#endif // MODULE_ADAFRUIT_BLE diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index ba49284c9..d71748ce3 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -67,10 +67,11 @@ #endif #ifdef BLUETOOTH_ENABLE - #include "bluetooth.h" -#endif -#ifdef ADAFRUIT_BLE_ENABLE + #ifdef MODULE_ADAFRUIT_BLE #include "adafruit_ble.h" + #else + #include "bluetooth.h" + #endif #endif #ifdef VIRTSER_ENABLE @@ -602,18 +603,14 @@ static void send_keyboard(report_keyboard_t *report) uint8_t where = where_to_send(); #ifdef BLUETOOTH_ENABLE - if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { - bluefruit_serial_send(0xFD); - for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { - bluefruit_serial_send(report->raw[i]); - } - } -#endif - -#ifdef ADAFRUIT_BLE_ENABLE - if (where == OUTPUT_ADAFRUIT_BLE) { - adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); + #ifdef MODULE_ADAFRUIT_BLE + adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); + #else + bluefruit_serial_send(0xFD); + for (uint8_t i = 0; i < KEYBOARD_EPSIZE; i++) { + bluefruit_serial_send(report->raw[i]); } + #endif #endif if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { @@ -660,24 +657,22 @@ static void send_mouse(report_mouse_t *report) uint8_t where = where_to_send(); #ifdef BLUETOOTH_ENABLE - if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { - bluefruit_serial_send(0xFD); - bluefruit_serial_send(0x00); - bluefruit_serial_send(0x03); - bluefruit_serial_send(report->buttons); - bluefruit_serial_send(report->x); - bluefruit_serial_send(report->y); - bluefruit_serial_send(report->v); // should try sending the wheel v here - bluefruit_serial_send(report->h); // should try sending the wheel h here - bluefruit_serial_send(0x00); - } -#endif - -#ifdef ADAFRUIT_BLE_ENABLE - if (where == OUTPUT_ADAFRUIT_BLE) { + if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { + #ifdef MODULE_ADAFRUIT_BLE // FIXME: mouse buttons adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h); - } + #else + bluefruit_serial_send(0xFD); + bluefruit_serial_send(0x00); + bluefruit_serial_send(0x03); + bluefruit_serial_send(report->buttons); + bluefruit_serial_send(report->x); + bluefruit_serial_send(report->y); + bluefruit_serial_send(report->v); // should try sending the wheel v here + bluefruit_serial_send(report->h); // should try sending the wheel h here + bluefruit_serial_send(0x00); + #endif + } #endif if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { @@ -727,6 +722,9 @@ static void send_consumer(uint16_t data) #ifdef BLUETOOTH_ENABLE if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { + #ifdef MODULE_ADAFRUIT_BLE + adafruit_ble_send_consumer_key(data, 0); + #else static uint16_t last_data = 0; if (data == last_data) return; last_data = data; @@ -740,12 +738,7 @@ static void send_consumer(uint16_t data) bluefruit_serial_send(0x00); bluefruit_serial_send(0x00); bluefruit_serial_send(0x00); - } -#endif - -#ifdef ADAFRUIT_BLE_ENABLE - if (where == OUTPUT_ADAFRUIT_BLE) { - adafruit_ble_send_consumer_key(data, 0); + #endif } #endif @@ -1130,10 +1123,6 @@ int main(void) // midi_send_noteoff(&midi_device, 0, 64, 127); #endif -#ifdef BLUETOOTH_ENABLE - serial_init(); -#endif - /* wait for USB startup & debug output */ #ifdef WAIT_FOR_USB @@ -1161,7 +1150,7 @@ int main(void) print("Keyboard start.\n"); while (1) { - #if !defined(BLUETOOTH_ENABLE) && !defined(ADAFRUIT_BLE_ENABLE) + #if !defined(BLUETOOTH_ENABLE) while (USB_DeviceState == DEVICE_STATE_Suspended) { print("[s]"); suspend_power_down(); @@ -1182,7 +1171,11 @@ int main(void) rgblight_task(); #endif -#ifdef ADAFRUIT_BLE_ENABLE +#ifdef MODULE_ADAFRUIT_EZKEY + serial_init(); +#endif + +#ifdef MODULE_ADAFRUIT_BLE adafruit_ble_task(); #endif diff --git a/tmk_core/protocol/lufa/outputselect.c b/tmk_core/protocol/lufa/outputselect.c index 5d2457bff..0df5d3b75 100644 --- a/tmk_core/protocol/lufa/outputselect.c +++ b/tmk_core/protocol/lufa/outputselect.c @@ -14,7 +14,7 @@ along with this program. If not, see . #include "lufa.h" #include "outputselect.h" -#ifdef ADAFRUIT_BLE_ENABLE +#ifdef MODULE_ADAFRUIT_BLE #include "adafruit_ble.h" #endif @@ -34,9 +34,9 @@ uint8_t auto_detect_output(void) { return OUTPUT_USB; } -#ifdef ADAFRUIT_BLE_ENABLE +#ifdef MODULE_ADAFRUIT_BLE if (adafruit_ble_is_connected()) { - return OUTPUT_ADAFRUIT_BLE; + return OUTPUT_BLUETOOTH; } #endif diff --git a/tmk_core/protocol/lufa/outputselect.h b/tmk_core/protocol/lufa/outputselect.h index 79b4dd35d..28cc3298e 100644 --- a/tmk_core/protocol/lufa/outputselect.h +++ b/tmk_core/protocol/lufa/outputselect.h @@ -18,7 +18,6 @@ enum outputs { OUTPUT_NONE, OUTPUT_USB, OUTPUT_BLUETOOTH, - OUTPUT_ADAFRUIT_BLE, // backward compatibility OUTPUT_USB_AND_BT -- cgit v1.2.3