diff options
author | Luiz Ribeiro <luizribeiro@gmail.com> | 2017-07-04 11:17:28 -0400 |
---|---|---|
committer | Luiz Ribeiro <luizribeiro@gmail.com> | 2017-07-04 11:17:28 -0400 |
commit | d5486265b8afcada68306c815b08c225fce287af (patch) | |
tree | 8fb7f8fee4aa3937003bd69d5c77ca867c010d12 /quantum | |
parent | 738b072bb0f25d0369a998c550c369e4f64cc7a5 (diff) | |
parent | 34c8bf47a76c8a2dcd3b1a19dd608f8fb2fafb31 (diff) | |
download | firmware-d5486265b8afcada68306c815b08c225fce287af.tar.gz firmware-d5486265b8afcada68306c815b08c225fce287af.tar.bz2 firmware-d5486265b8afcada68306c815b08c225fce287af.zip |
Merge branch 'master' into ps2avrGB
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/audio/audio.c | 317 | ||||
-rw-r--r-- | quantum/audio/voices.c | 2 | ||||
-rw-r--r-- | quantum/keycode_config.c | 28 | ||||
-rw-r--r-- | quantum/keycode_config.h | 2 | ||||
-rw-r--r-- | quantum/keymap_common.c | 3 | ||||
-rw-r--r-- | quantum/keymap_extras/keymap_spanish.h | 6 | ||||
-rw-r--r-- | quantum/keymap_extras/keymap_swedish.h | 52 | ||||
-rw-r--r-- | quantum/quantum.c | 150 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 7 | ||||
-rw-r--r-- | quantum/template/rules.mk | 2 | ||||
-rw-r--r-- | quantum/visualizer/lcd_backlight.c | 4 | ||||
-rw-r--r-- | quantum/visualizer/lcd_backlight.h | 3 | ||||
-rw-r--r-- | quantum/visualizer/led_keyframes.c | 20 | ||||
-rw-r--r-- | quantum/visualizer/led_keyframes.h | 3 | ||||
-rw-r--r-- | quantum/visualizer/visualizer.c | 67 | ||||
-rw-r--r-- | quantum/visualizer/visualizer.h | 10 | ||||
-rw-r--r-- | quantum/visualizer/visualizer.mk | 29 |
17 files changed, 620 insertions, 85 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 597073611..c924f2bd5 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -33,17 +33,41 @@ // TIMSK3 - Timer/Counter #3 Interrupt Mask Register // Turn on/off 3A interputs, stopping/enabling the ISR calls -#define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A) -#define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A) +#ifdef C6_AUDIO + #define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A) + #define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A) +#endif + +#ifdef B5_AUDIO + #define ENABLE_AUDIO_COUNTER_1_ISR TIMSK1 |= _BV(OCIE1A) + #define DISABLE_AUDIO_COUNTER_1_ISR TIMSK1 &= ~_BV(OCIE1A) +#endif // TCCR3A: Timer/Counter #3 Control Register // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6 -#define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1); -#define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0)); + +#ifdef C6_AUDIO + #define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1); + #define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0)); +#endif + +#ifdef B5_AUDIO + #define ENABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A |= _BV(COM1A1); + #define DISABLE_AUDIO_COUNTER_1_OUTPUT TCCR1A &= ~(_BV(COM1A1) | _BV(COM1A0)); +#endif // Fast PWM Mode Controls -#define TIMER_3_PERIOD ICR3 -#define TIMER_3_DUTY_CYCLE OCR3A + +#ifdef C6_AUDIO + #define TIMER_3_PERIOD ICR3 + #define TIMER_3_DUTY_CYCLE OCR3A +#endif + +#ifdef B5_AUDIO + #define TIMER_1_PERIOD ICR1 + #define TIMER_1_DUTY_CYCLE OCR1A +#endif + // ----------------------------------------------------------------------------- @@ -51,6 +75,7 @@ int voices = 0; int voice_place = 0; float frequency = 0; +float frequency_alt = 0; int volume = 0; long position = 0; @@ -105,16 +130,43 @@ void audio_init() audio_config.raw = eeconfig_read_audio(); // Set port PC6 (OC3A and /OC4A) as output - DDRC |= _BV(PORTC6); - DISABLE_AUDIO_COUNTER_3_ISR; + #ifdef C6_AUDIO + DDRC |= _BV(PORTC6); + #else + DDRC |= _BV(PORTC6); + PORTC &= ~_BV(PORTC6); + #endif + + #ifdef B5_AUDIO + DDRB |= _BV(PORTB5); + #else + DDRB |= _BV(PORTB5); + PORTB &= ~_BV(PORTB5); + #endif + + #ifdef C6_AUDIO + DISABLE_AUDIO_COUNTER_3_ISR; + #endif + + #ifdef B5_AUDIO + DISABLE_AUDIO_COUNTER_1_ISR; + #endif // TCCR3A / TCCR3B: Timer/Counter #3 Control Registers // Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6 // Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A) // Clock Select (CS3n) = 0b010 = Clock / 8 - TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); - TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); + + #ifdef C6_AUDIO + TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); + TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30); + #endif + + #ifdef B5_AUDIO + TCCR1A = (0 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (0 << WGM10); + TCCR1B = (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10); + #endif audio_initialized = true; } @@ -128,12 +180,21 @@ void stop_all_notes() } voices = 0; - DISABLE_AUDIO_COUNTER_3_ISR; - DISABLE_AUDIO_COUNTER_3_OUTPUT; + + #ifdef C6_AUDIO + DISABLE_AUDIO_COUNTER_3_ISR; + DISABLE_AUDIO_COUNTER_3_OUTPUT; + #endif + + #ifdef B5_AUDIO + DISABLE_AUDIO_COUNTER_1_ISR; + DISABLE_AUDIO_COUNTER_1_OUTPUT; + #endif playing_notes = false; playing_note = false; frequency = 0; + frequency_alt = 0; volume = 0; for (uint8_t i = 0; i < 8; i++) @@ -171,9 +232,16 @@ void stop_note(float freq) voice_place = 0; } if (voices == 0) { - DISABLE_AUDIO_COUNTER_3_ISR; - DISABLE_AUDIO_COUNTER_3_OUTPUT; + #ifdef C6_AUDIO + DISABLE_AUDIO_COUNTER_3_ISR; + DISABLE_AUDIO_COUNTER_3_OUTPUT; + #endif + #ifdef B5_AUDIO + DISABLE_AUDIO_COUNTER_1_ISR; + DISABLE_AUDIO_COUNTER_1_OUTPUT; + #endif frequency = 0; + frequency_alt = 0; volume = 0; playing_note = false; } @@ -200,12 +268,56 @@ float vibrato(float average_freq) { #endif +#ifdef C6_AUDIO ISR(TIMER3_COMPA_vect) { float freq; if (playing_note) { if (voices > 0) { + + #ifdef B5_AUDIO + float freq_alt = 0; + if (voices > 1) { + if (polyphony_rate == 0) { + if (glissando) { + if (frequency_alt != 0 && frequency_alt < frequencies[voices - 2] && frequency_alt < frequencies[voices - 2] * pow(2, -440/frequencies[voices - 2]/12/2)) { + frequency_alt = frequency_alt * pow(2, 440/frequency_alt/12/2); + } else if (frequency_alt != 0 && frequency_alt > frequencies[voices - 2] && frequency_alt > frequencies[voices - 2] * pow(2, 440/frequencies[voices - 2]/12/2)) { + frequency_alt = frequency_alt * pow(2, -440/frequency_alt/12/2); + } else { + frequency_alt = frequencies[voices - 2]; + } + } else { + frequency_alt = frequencies[voices - 2]; + } + + #ifdef VIBRATO_ENABLE + if (vibrato_strength > 0) { + freq_alt = vibrato(frequency_alt); + } else { + freq_alt = frequency_alt; + } + #else + freq_alt = frequency_alt; + #endif + } + + if (envelope_index < 65535) { + envelope_index++; + } + + freq_alt = voice_envelope(freq_alt); + + if (freq_alt < 30.517578125) { + freq_alt = 30.52; + } + + TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq_alt * CPU_PRESCALER)); + TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq_alt * CPU_PRESCALER)) * note_timbre); + } + #endif + if (polyphony_rate > 0) { if (voices > 1) { voice_place %= voices; @@ -328,6 +440,140 @@ ISR(TIMER3_COMPA_vect) playing_note = false; } } +#endif + +#ifdef B5_AUDIO +ISR(TIMER1_COMPA_vect) +{ + #if defined(B5_AUDIO) && !defined(C6_AUDIO) + float freq = 0; + + if (playing_note) { + if (voices > 0) { + if (polyphony_rate > 0) { + if (voices > 1) { + voice_place %= voices; + if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) { + voice_place = (voice_place + 1) % voices; + place = 0.0; + } + } + + #ifdef VIBRATO_ENABLE + if (vibrato_strength > 0) { + freq = vibrato(frequencies[voice_place]); + } else { + freq = frequencies[voice_place]; + } + #else + freq = frequencies[voice_place]; + #endif + } else { + if (glissando) { + if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) { + frequency = frequency * pow(2, 440/frequency/12/2); + } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) { + frequency = frequency * pow(2, -440/frequency/12/2); + } else { + frequency = frequencies[voices - 1]; + } + } else { + frequency = frequencies[voices - 1]; + } + + #ifdef VIBRATO_ENABLE + if (vibrato_strength > 0) { + freq = vibrato(frequency); + } else { + freq = frequency; + } + #else + freq = frequency; + #endif + } + + if (envelope_index < 65535) { + envelope_index++; + } + + freq = voice_envelope(freq); + + if (freq < 30.517578125) { + freq = 30.52; + } + + TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER)); + TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); + } + } + + if (playing_notes) { + if (note_frequency > 0) { + #ifdef VIBRATO_ENABLE + if (vibrato_strength > 0) { + freq = vibrato(note_frequency); + } else { + freq = note_frequency; + } + #else + freq = note_frequency; + #endif + + if (envelope_index < 65535) { + envelope_index++; + } + freq = voice_envelope(freq); + + TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER)); + TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); + } else { + TIMER_1_PERIOD = 0; + TIMER_1_DUTY_CYCLE = 0; + } + + note_position++; + bool end_of_note = false; + if (TIMER_1_PERIOD > 0) { + end_of_note = (note_position >= (note_length / TIMER_1_PERIOD * 0xFFFF)); + } else { + end_of_note = (note_position >= (note_length * 0x7FF)); + } + + if (end_of_note) { + current_note++; + if (current_note >= notes_count) { + if (notes_repeat) { + current_note = 0; + } else { + DISABLE_AUDIO_COUNTER_1_ISR; + DISABLE_AUDIO_COUNTER_1_OUTPUT; + playing_notes = false; + return; + } + } + if (!note_resting && (notes_rest > 0)) { + note_resting = true; + note_frequency = 0; + note_length = notes_rest; + current_note--; + } else { + note_resting = false; + envelope_index = 0; + note_frequency = (*notes_pointer)[current_note][0]; + note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100); + } + + note_position = 0; + } + } + + if (!audio_config.enable) { + playing_notes = false; + playing_note = false; + } +#endif +} +#endif void play_note(float freq, int vol) { @@ -338,7 +584,12 @@ void play_note(float freq, int vol) { } if (audio_config.enable && voices < 8) { - DISABLE_AUDIO_COUNTER_3_ISR; + #ifdef C6_AUDIO + DISABLE_AUDIO_COUNTER_3_ISR; + #endif + #ifdef B5_AUDIO + DISABLE_AUDIO_COUNTER_1_ISR; + #endif // Cancel notes if notes are playing if (playing_notes) @@ -354,8 +605,21 @@ void play_note(float freq, int vol) { voices++; } - ENABLE_AUDIO_COUNTER_3_ISR; - ENABLE_AUDIO_COUNTER_3_OUTPUT; + #ifdef C6_AUDIO + ENABLE_AUDIO_COUNTER_3_ISR; + ENABLE_AUDIO_COUNTER_3_OUTPUT; + #endif + #ifdef B5_AUDIO + #ifdef C6_AUDIO + if (voices > 1) { + ENABLE_AUDIO_COUNTER_1_ISR; + ENABLE_AUDIO_COUNTER_1_OUTPUT; + } + #else + ENABLE_AUDIO_COUNTER_1_ISR; + ENABLE_AUDIO_COUNTER_1_OUTPUT; + #endif + #endif } } @@ -369,7 +633,12 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) if (audio_config.enable) { - DISABLE_AUDIO_COUNTER_3_ISR; + #ifdef C6_AUDIO + DISABLE_AUDIO_COUNTER_3_ISR; + #endif + #ifdef B5_AUDIO + DISABLE_AUDIO_COUNTER_1_ISR; + #endif // Cancel note if a note is playing if (playing_note) @@ -390,8 +659,16 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) note_position = 0; - ENABLE_AUDIO_COUNTER_3_ISR; - ENABLE_AUDIO_COUNTER_3_OUTPUT; + #ifdef C6_AUDIO + ENABLE_AUDIO_COUNTER_3_ISR; + ENABLE_AUDIO_COUNTER_3_OUTPUT; + #endif + #ifdef B5_AUDIO + #ifndef C6_AUDIO + ENABLE_AUDIO_COUNTER_1_ISR; + ENABLE_AUDIO_COUNTER_1_OUTPUT; + #endif + #endif } } diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c index 54ebd423b..94147ccb6 100644 --- a/quantum/audio/voices.c +++ b/quantum/audio/voices.c @@ -44,7 +44,7 @@ float voice_envelope(float frequency) { switch (voice) { case default_voice: - glissando = true; + glissando = false; note_timbre = TIMBRE_50; polyphony_rate = 0; break; diff --git a/quantum/keycode_config.c b/quantum/keycode_config.c index 4f7bc525e..eb39c8fe0 100644 --- a/quantum/keycode_config.c +++ b/quantum/keycode_config.c @@ -88,3 +88,31 @@ uint16_t keycode_config(uint16_t keycode) { return keycode; } } + +uint8_t mod_config(uint8_t mod) { + keymap_config.raw = eeconfig_read_keymap(); + if (keymap_config.swap_lalt_lgui) { + if ((mod & MOD_RGUI) == MOD_LGUI) { + mod &= ~MOD_LGUI; + mod |= MOD_LALT; + } else if ((mod & MOD_RALT) == MOD_LALT) { + mod &= ~MOD_LALT; + mod |= MOD_LGUI; + } + } + if (keymap_config.swap_ralt_rgui) { + if ((mod & MOD_RGUI) == MOD_RGUI) { + mod &= ~MOD_RGUI; + mod |= MOD_RALT; + } else if ((mod & MOD_RALT) == MOD_RALT) { + mod &= ~MOD_RALT; + mod |= MOD_RGUI; + } + } + if (keymap_config.no_gui) { + mod &= ~MOD_LGUI; + mod &= ~MOD_RGUI; + } + + return mod; +}
\ No newline at end of file diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index 293fefecf..022f4bd19 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -16,11 +16,13 @@ #include "eeconfig.h" #include "keycode.h" +#include "action_code.h" #ifndef KEYCODE_CONFIG_H #define KEYCODE_CONFIG_H uint16_t keycode_config(uint16_t keycode); +uint8_t mod_config(uint8_t mod); /* NOTE: Not portable. Bit field order depends on implementation */ typedef union { diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 9dafc8b51..b1460c53c 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -123,7 +123,8 @@ action_t action_for_key(uint8_t layer, keypos_t key) action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF); break; case QK_MOD_TAP ... QK_MOD_TAP_MAX: - action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0x1F, keycode & 0xFF); + mod = mod_config((keycode >> 0x8) & 0x1F); + action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF); break; #ifdef BACKLIGHT_ENABLE case BL_0 ... BL_15: diff --git a/quantum/keymap_extras/keymap_spanish.h b/quantum/keymap_extras/keymap_spanish.h index 3a5787e9c..224db7be1 100644 --- a/quantum/keymap_extras/keymap_spanish.h +++ b/quantum/keymap_extras/keymap_spanish.h @@ -55,8 +55,8 @@ #define ES_UMLT LSFT(ES_GRV) #define ES_GRTR LSFT(ES_LESS) -#define ES_SCLN LSFT(ES_COMM) -#define ES_COLN LSFT(ES_DOT) +#define ES_SCLN LSFT(KC_COMM) +#define ES_COLN LSFT(KC_DOT) #define ES_UNDS LSFT(ES_MINS) // Alt Gr-ed characters @@ -72,6 +72,6 @@ #define ES_RBRC ALGR(ES_PLUS) #define ES_LCBR ALGR(ES_ACUT) -#define ES_RCRB ALGR(ES_CCED) +#define ES_RCBR ALGR(ES_CCED) #endif diff --git a/quantum/keymap_extras/keymap_swedish.h b/quantum/keymap_extras/keymap_swedish.h new file mode 100644 index 000000000..dcfad720d --- /dev/null +++ b/quantum/keymap_extras/keymap_swedish.h @@ -0,0 +1,52 @@ +/* Copyright 2017 Andreas Lindhé + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef KEYMAP_SWEDISH_H +#define KEYMAP_SWEDISH_H + +#include "keymap_nordic.h" + +// There are slight differrences in the keyboards in the nordic contries + +// Swedish redifinitions from the nordic keyset +#undef NO_AE +#define NO_AE KC_QUOT // ä +#undef NO_CIRC +#define NO_CIRC LSFT(KC_RBRC) // ^ +#undef NO_GRV +#define NO_GRV LSFT(NO_BSLS) // +#undef NO_OSLH +#define NO_OSLH KC_SCLN // ö + +// Additional Swedish keys not defined in the nordic keyset +#define NO_AA KC_LBRC // å +#define NO_ASTR LSFT(KC_BSLS) // * + +// Norwegian unique MAC characters (not vetted for Swedish) +#define NO_ACUT_MAC KC_EQL // = +#define NO_APOS_MAC KC_NUBS // ' +#define NO_AT_MAC KC_BSLS // @ +#define NO_BSLS_MAC ALGR(LSFT(KC_7)) // '\' +#define NO_DLR_MAC LSFT(KC_4) // $ +#define NO_GRV_MAC ALGR(NO_BSLS) // ` +#define NO_GRTR_MAC LSFT(KC_GRV) // > +#define NO_LCBR_MAC ALGR(LSFT(KC_8)) // } +#define NO_LESS_MAC KC_GRV // > +#define NO_PIPE_MAC ALGR(KC_7) // | +#define NO_RCBR_MAC ALGR(LSFT(KC_9)) // } + +#endif + diff --git a/quantum/quantum.c b/quantum/quantum.c index 4f4cee4e9..5bb7b04d5 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -437,6 +437,14 @@ bool process_record_quantum(keyrecord_t *record) { return false; // break; } + case GRAVE_ESC: { + void (*method)(uint8_t) = (record->event.pressed) ? &add_key : &del_key; + uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) + |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))); + + method(shifted ? KC_GRAVE : KC_ESCAPE); + send_keyboard_report(); + } default: { shift_interrupted[0] = true; shift_interrupted[1] = true; @@ -447,7 +455,103 @@ bool process_record_quantum(keyrecord_t *record) { return process_action_kb(record); } -const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { +#ifdef JIS_KEYCODE +static const uint16_t ascii_to_shift_lut[8] PROGMEM = { + 0x0000, /*0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0,*/ + 0x0000, /*0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0,*/ + 0x7ff0, /*0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0,*/ + 0x000f, /*0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1,*/ + 0x7fff, /*0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1,*/ + 0xffe1, /*1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 1,*/ + 0x8000, /*1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0,*/ + 0x001e, /*0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 0*/ +}; + +static const struct { + uint8_t controls_0[16], + controls_1[16], + numerics[16], + alphabets_0[16], + alphabets_1[16]; +} lower_to_keycode PROGMEM = { + .controls_0 = { + 0, 0, 0, 0, 0, 0, 0, 0, + KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, + }, + .controls_1 = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, KC_ESC, 0, 0, 0, 0, + }, + .numerics = { + KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, + KC_8, KC_9, KC_QUOT, KC_SCLN, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, + }, + .alphabets_0 = { + KC_LBRC, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, + KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, + }, + .alphabets_1 = { + KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, + KC_X, KC_Y, KC_Z, KC_RBRC, KC_JYEN, KC_BSLS, KC_EQL, KC_RO, + }, +}; +static const uint8_t* ascii_to_keycode_lut[8] = { + lower_to_keycode.controls_0, + lower_to_keycode.controls_1, + lower_to_keycode.numerics, + lower_to_keycode.numerics, + lower_to_keycode.alphabets_0, + lower_to_keycode.alphabets_1, + lower_to_keycode.alphabets_0, + lower_to_keycode.alphabets_1 +}; + +void send_string(const char *str) { + while (1) { + uint8_t keycode; + bool shift; + uint8_t ascii_code = pgm_read_byte(str); + + if ( ascii_code == 0x00u ){ break; } + else if (ascii_code == 0x20u) { + keycode = KC_SPC; + shift = false; + } + else if (ascii_code == 0x7Fu) { + keycode = KC_DEL; + shift = false; + } + else { + int hi = ascii_code>>4 & 0x0f, + lo = ascii_code & 0x0f; + keycode = pgm_read_byte(&ascii_to_keycode_lut[hi][lo]); + shift = !!( pgm_read_word(&ascii_to_shift_lut[hi]) & (0x8000u>>lo) ); + } + + if (shift) { + register_code(KC_LSFT); + register_code(keycode); + unregister_code(keycode); + unregister_code(KC_LSFT); + } + else { + register_code(keycode); + unregister_code(keycode); + } + ++str; + } +} + +#else +static const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -466,7 +570,7 @@ const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { 0, 0, 0, 1, 1, 1, 1, 0 }; -const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { +static const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -485,6 +589,28 @@ const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL }; +void send_string(const char *str) { + while (1) { + uint8_t keycode; + uint8_t ascii_code = pgm_read_byte(str); + if (!ascii_code) break; + keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]); + if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) { + register_code(KC_LSFT); + register_code(keycode); + unregister_code(keycode); + unregister_code(KC_LSFT); + } + else { + register_code(keycode); + unregister_code(keycode); + } + ++str; + } +} + +#endif + /* for users whose OSes are set to Colemak */ #if 0 #include "keymap_colemak.h" @@ -529,26 +655,6 @@ const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = { #endif -void send_string(const char *str) { - while (1) { - uint8_t keycode; - uint8_t ascii_code = pgm_read_byte(str); - if (!ascii_code) break; - keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]); - if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) { - register_code(KC_LSFT); - register_code(keycode); - unregister_code(keycode); - unregister_code(KC_LSFT); - } - else { - register_code(keycode); - unregister_code(keycode); - } - ++str; - } -} - void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { layer_on(layer3); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 7354ae0da..6038e31c4 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -104,6 +104,7 @@ enum quantum_keycodes { MAGIC_UNHOST_NKRO, MAGIC_UNSWAP_ALT_GUI, MAGIC_TOGGLE_NKRO, + GRAVE_ESC, // Leader key #ifndef DISABLE_LEADER @@ -514,6 +515,8 @@ enum quantum_keycodes { #define MACROTAP(kc) (kc | QK_MACRO | FUNC_TAP<<8) #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) +#define KC_GESC GRAVE_ESC + // L-ayer, T-ap - 256 keycode max, 16 layer max #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8)) @@ -547,13 +550,13 @@ enum quantum_keycodes { #define OSL(layer) (layer | QK_ONE_SHOT_LAYER) // One-shot mod -#define OSM(mod) (mod | QK_ONE_SHOT_MOD) +#define OSM(mod) ((mod) | QK_ONE_SHOT_MOD) // Layer tap-toggle #define TT(layer) (layer | QK_LAYER_TAP_TOGGLE) // M-od, T-ap - 256 keycode max -#define MT(mod, kc) (kc | QK_MOD_TAP | ((mod & 0x1F) << 8)) +#define MT(mod, kc) (kc | QK_MOD_TAP | (((mod) & 0x1F) << 8)) #define CTL_T(kc) MT(MOD_LCTL, kc) #define LCTL_T(kc) MT(MOD_LCTL, kc) diff --git a/quantum/template/rules.mk b/quantum/template/rules.mk index a1f9377d8..a3571e8de 100644 --- a/quantum/template/rules.mk +++ b/quantum/template/rules.mk @@ -1,5 +1,5 @@ # MCU name -#MCU = at90usb1287 +#MCU = at90usb1286 MCU = atmega32u4 # Processor frequency. diff --git a/quantum/visualizer/lcd_backlight.c b/quantum/visualizer/lcd_backlight.c index 00de3fab5..6cd996f75 100644 --- a/quantum/visualizer/lcd_backlight.c +++ b/quantum/visualizer/lcd_backlight.c @@ -83,3 +83,7 @@ void lcd_backlight_brightness(uint8_t b) { current_brightness = b; lcd_backlight_color(current_hue, current_saturation, current_intensity); } + +uint8_t lcd_get_backlight_brightness(void) { + return current_brightness; +} diff --git a/quantum/visualizer/lcd_backlight.h b/quantum/visualizer/lcd_backlight.h index 14dde64a1..95d7a07b4 100644 --- a/quantum/visualizer/lcd_backlight.h +++ b/quantum/visualizer/lcd_backlight.h @@ -32,13 +32,14 @@ SOFTWARE. #define LCD_SAT(color) ((color >> 8) & 0xFF) #define LCD_INT(color) (color & 0xFF) -inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) { +static inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) { return (color & 0xFFFFFF00) | new_intensity; } void lcd_backlight_init(void); void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity); void lcd_backlight_brightness(uint8_t b); +uint8_t lcd_get_backlight_brightness(void); void lcd_backlight_hal_init(void); void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b); diff --git a/quantum/visualizer/led_keyframes.c b/quantum/visualizer/led_keyframes.c index 2dacd990d..7e6e5d1ab 100644 --- a/quantum/visualizer/led_keyframes.c +++ b/quantum/visualizer/led_keyframes.c @@ -41,14 +41,14 @@ static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint } // TODO: Should be customizable per keyboard -#define NUM_ROWS 7 -#define NUM_COLS 7 +#define NUM_ROWS LED_NUM_ROWS +#define NUM_COLS LED_NUM_COLS static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS]; static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS]; static uint8_t compute_gradient_color(float t, float index, float num) { - const float two_pi = M_2_PI; + const float two_pi = M_PI * 2.0f; float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi; float x = t * two_pi + normalized_index; float v = 0.5 * (cosf(x) + 1.0f); @@ -127,3 +127,17 @@ bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0); return false; } + +bool led_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)state; + (void)animation; + gdispGSetPowerMode(LED_DISPLAY, powerOff); + return false; +} + +bool led_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)state; + (void)animation; + gdispGSetPowerMode(LED_DISPLAY, powerOn); + return false; +} diff --git a/quantum/visualizer/led_keyframes.h b/quantum/visualizer/led_keyframes.h index a68943041..a59a4f37d 100644 --- a/quantum/visualizer/led_keyframes.h +++ b/quantum/visualizer/led_keyframes.h @@ -35,6 +35,9 @@ bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t* bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state); bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state); +bool led_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state); +bool led_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state); + extern keyframe_animation_t led_test_animation; diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 6f134097f..cc99d1e3b 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "visualizer.h" #include "config.h" +#include "visualizer.h" #include <string.h> #ifdef PROTOCOL_CHIBIOS #include "ch.h" @@ -58,8 +58,11 @@ SOFTWARE. static visualizer_keyboard_status_t current_status = { .layer = 0xFFFFFFFF, .default_layer = 0xFFFFFFFF, - .mods = 0xFF, .leds = 0xFFFFFFFF, +#ifdef BACKLIGHT_ENABLE + .backlight_level = 0, +#endif + .mods = 0xFF, .suspended = false, #ifdef VISUALIZER_USER_DATA_SIZE .user_data = {0} @@ -72,6 +75,9 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa status1->mods == status2->mods && status1->leds == status2->leds && status1->suspended == status2->suspended +#ifdef BACKLIGHT_ENABLE + && status1->backlight_level == status2->backlight_level +#endif #ifdef VISUALIZER_USER_DATA_SIZE && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0 #endif @@ -99,15 +105,19 @@ static remote_object_t* remote_objects[] = { GDisplay* LCD_DISPLAY = 0; GDisplay* LED_DISPLAY = 0; +#ifdef LCD_DISPLAY_NUMBER __attribute__((weak)) GDisplay* get_lcd_display(void) { - return gdispGetDisplay(0); + return gdispGetDisplay(LCD_DISPLAY_NUMBER); } +#endif +#ifdef LED_DISPLAY_NUMBER __attribute__((weak)) GDisplay* get_led_display(void) { - return gdispGetDisplay(1); + return gdispGetDisplay(LED_DISPLAY_NUMBER); } +#endif void start_keyframe_animation(keyframe_animation_t* animation) { animation->current_frame = -1; @@ -245,9 +255,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { .mods = 0xFF, .leds = 0xFFFFFFFF, .suspended = false, -#ifdef VISUALIZER_USER_DATA_SIZE + #ifdef VISUALIZER_USER_DATA_SIZE .user_data = {0}, -#endif + #endif }; visualizer_state_t state = { @@ -279,6 +289,18 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { bool enabled = visualizer_enabled; if (force_update || !same_status(&state.status, ¤t_status)) { force_update = false; + #if BACKLIGHT_ENABLE + if(current_status.backlight_level != state.status.backlight_level) { + if (current_status.backlight_level != 0) { + gdispGSetPowerMode(LED_DISPLAY, powerOn); + uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS; + gdispGSetBacklight(LED_DISPLAY, percent); + } + else { + gdispGSetPowerMode(LED_DISPLAY, powerOff); + } + } + #endif if (visualizer_enabled) { if (current_status.suspended) { stop_all_keyframe_animations(); @@ -309,7 +331,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { update_keyframe_animation(animations[i], &state, delta, &sleep_time); } } -#ifdef LED_ENABLE +#ifdef BACKLIGHT_ENABLE gdispGFlush(LED_DISPLAY); #endif @@ -361,25 +383,26 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { void visualizer_init(void) { gfxInit(); -#ifdef LCD_BACKLIGHT_ENABLE + #ifdef LCD_BACKLIGHT_ENABLE lcd_backlight_init(); -#endif + #endif -#ifdef SERIAL_LINK_ENABLE + #ifdef SERIAL_LINK_ENABLE add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); -#endif + #endif -#ifdef LCD_ENABLE + #ifdef LCD_ENABLE LCD_DISPLAY = get_lcd_display(); -#endif -#ifdef LED_ENABLE + #endif + + #ifdef BACKLIGHT_ENABLE LED_DISPLAY = get_led_display(); -#endif + #endif // We are using a low priority thread, the idea is to have it run only // when the main thread is sleeping during the matrix scanning - gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack), - VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); + gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack), + VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); } void update_status(bool changed) { @@ -445,6 +468,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin .default_layer = default_state, .mods = mods, .leds = leds, +#ifdef BACKLIGHT_ENABLE + .backlight_level = current_status.backlight_level, +#endif .suspended = current_status.suspended, }; #ifdef VISUALIZER_USER_DATA_SIZE @@ -467,3 +493,10 @@ void visualizer_resume(void) { current_status.suspended = false; update_status(true); } + +#ifdef BACKLIGHT_ENABLE +void backlight_set(uint8_t level) { + current_status.backlight_level = level; + update_status(true); +} +#endif diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index d6f279e10..90ecdcbae 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -28,12 +28,17 @@ SOFTWARE. #include <stdint.h> #include <stdbool.h> +#include "config.h" #include "gfx.h" #ifdef LCD_BACKLIGHT_ENABLE #include "lcd_backlight.h" #endif +#ifdef BACKLIGHT_ENABLE +#include "backlight.h" +#endif + // use this function to merge both real_mods and oneshot_mods in a uint16_t uint8_t visualizer_get_mods(void); @@ -65,9 +70,12 @@ struct keyframe_animation_t; typedef struct { uint32_t layer; uint32_t default_layer; - uint8_t mods; uint32_t leds; // See led.h for available statuses + uint8_t mods; bool suspended; +#ifdef BACKLIGHT_ENABLE + uint8_t backlight_level; +#endif #ifdef VISUALIZER_USER_DATA_SIZE uint8_t user_data[VISUALIZER_USER_DATA_SIZE]; #endif diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index 5f710124b..0f7d8636c 100644 --- a/quantum/visualizer/visualizer.mk +++ b/quantum/visualizer/visualizer.mk @@ -42,9 +42,8 @@ SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c OPT_DEFS += -DLCD_BACKLIGHT_ENABLE endif -ifeq ($(strip $(LED_ENABLE)), yes) +ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) SRC += $(VISUALIZER_DIR)/led_keyframes.c -OPT_DEFS += -DLED_ENABLE endif include $(GFXLIB)/gfx.mk @@ -52,19 +51,23 @@ GFXSRC := $(patsubst $(TOP_DIR)/%,%,$(GFXSRC)) GFXDEFS := $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS))) ifneq ("$(wildcard $(KEYMAP_PATH)/visualizer.c)","") - SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c + SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c else - ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","") - ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","") -$(error "$(KEYMAP_PATH)/visualizer.c" does not exist) - else - SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c - endif - else - SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c - endif + ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","") + ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","") + ifeq ("$(wildcard $(KEYBOARD_PATH)/visualizer.c)","") +$(error "visualizer.c" not found") + else + SRC += keyboards/$(KEYBOARD)/visualizer.c + endif + else + SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c + endif + else + SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c + endif endif ifdef EMULATOR UINCDIR += $(TMK_DIR)/common -endif
\ No newline at end of file +endif |