mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-10-20 08:00:37 +02:00
Merge branch 'master' into rgblight.c-add-split-hook
This commit is contained in:
+310
-304
@@ -273,19 +273,24 @@ static const DACConversionGroup dacgrpcfg2 = {
|
||||
.trigger = DAC_TRG(0)
|
||||
};
|
||||
|
||||
void audio_init()
|
||||
{
|
||||
void audio_init() {
|
||||
|
||||
if (audio_initialized)
|
||||
return;
|
||||
if (audio_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check EEPROM
|
||||
// if (!eeconfig_is_enabled())
|
||||
// {
|
||||
// eeconfig_init();
|
||||
// }
|
||||
// audio_config.raw = eeconfig_read_audio();
|
||||
// Check EEPROM
|
||||
#if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
|
||||
if (!eeconfig_is_enabled()) {
|
||||
eeconfig_init();
|
||||
}
|
||||
audio_config.raw = eeconfig_read_audio();
|
||||
#else // ARM EEPROM
|
||||
audio_config.enable = true;
|
||||
#ifdef AUDIO_CLICKY_ON
|
||||
audio_config.clicky_enable = true;
|
||||
#endif
|
||||
#endif // ARM EEPROM
|
||||
|
||||
/*
|
||||
* Starting DAC1 driver, setting up the output pin as analog as suggested
|
||||
@@ -308,16 +313,17 @@ void audio_init()
|
||||
dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE);
|
||||
dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE);
|
||||
|
||||
audio_initialized = true;
|
||||
audio_initialized = true;
|
||||
|
||||
if (audio_config.enable) {
|
||||
PLAY_SONG(startup_song);
|
||||
}
|
||||
if (audio_config.enable) {
|
||||
PLAY_SONG(startup_song);
|
||||
} else {
|
||||
stop_all_notes();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void stop_all_notes()
|
||||
{
|
||||
void stop_all_notes() {
|
||||
dprintf("audio stop all notes");
|
||||
|
||||
if (!audio_initialized) {
|
||||
@@ -342,347 +348,347 @@ void stop_all_notes()
|
||||
}
|
||||
}
|
||||
|
||||
void stop_note(float freq)
|
||||
{
|
||||
dprintf("audio stop note freq=%d", (int)freq);
|
||||
void stop_note(float freq) {
|
||||
dprintf("audio stop note freq=%d", (int)freq);
|
||||
|
||||
if (playing_note) {
|
||||
if (!audio_initialized) {
|
||||
audio_init();
|
||||
}
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if (frequencies[i] == freq) {
|
||||
frequencies[i] = 0;
|
||||
volumes[i] = 0;
|
||||
for (int j = i; (j < 7); j++) {
|
||||
frequencies[j] = frequencies[j+1];
|
||||
frequencies[j+1] = 0;
|
||||
volumes[j] = volumes[j+1];
|
||||
volumes[j+1] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
voices--;
|
||||
if (voices < 0)
|
||||
voices = 0;
|
||||
if (voice_place >= voices) {
|
||||
voice_place = 0;
|
||||
}
|
||||
if (voices == 0) {
|
||||
STOP_CHANNEL_1();
|
||||
STOP_CHANNEL_2();
|
||||
gptStopTimer(&GPTD8);
|
||||
frequency = 0;
|
||||
frequency_alt = 0;
|
||||
volume = 0;
|
||||
playing_note = false;
|
||||
}
|
||||
if (playing_note) {
|
||||
if (!audio_initialized) {
|
||||
audio_init();
|
||||
}
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if (frequencies[i] == freq) {
|
||||
frequencies[i] = 0;
|
||||
volumes[i] = 0;
|
||||
for (int j = i; (j < 7); j++) {
|
||||
frequencies[j] = frequencies[j+1];
|
||||
frequencies[j+1] = 0;
|
||||
volumes[j] = volumes[j+1];
|
||||
volumes[j+1] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
voices--;
|
||||
if (voices < 0) {
|
||||
voices = 0;
|
||||
}
|
||||
if (voice_place >= voices) {
|
||||
voice_place = 0;
|
||||
}
|
||||
if (voices == 0) {
|
||||
STOP_CHANNEL_1();
|
||||
STOP_CHANNEL_2();
|
||||
gptStopTimer(&GPTD8);
|
||||
frequency = 0;
|
||||
frequency_alt = 0;
|
||||
volume = 0;
|
||||
playing_note = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VIBRATO_ENABLE
|
||||
|
||||
float mod(float a, int b)
|
||||
{
|
||||
float r = fmod(a, b);
|
||||
return r < 0 ? r + b : r;
|
||||
float mod(float a, int b) {
|
||||
float r = fmod(a, b);
|
||||
return r < 0 ? r + b : r;
|
||||
}
|
||||
|
||||
float vibrato(float average_freq) {
|
||||
#ifdef VIBRATO_STRENGTH_ENABLE
|
||||
float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
|
||||
#else
|
||||
float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
|
||||
#endif
|
||||
vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
|
||||
return vibrated_freq;
|
||||
#ifdef VIBRATO_STRENGTH_ENABLE
|
||||
float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
|
||||
#else
|
||||
float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
|
||||
#endif
|
||||
vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
|
||||
return vibrated_freq;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void gpt_cb8(GPTDriver *gptp) {
|
||||
float freq;
|
||||
float freq;
|
||||
|
||||
if (playing_note) {
|
||||
if (voices > 0) {
|
||||
if (playing_note) {
|
||||
if (voices > 0) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) {
|
||||
UPDATE_CHANNEL_2_FREQ(freq_alt);
|
||||
} else {
|
||||
RESTART_CHANNEL_2();
|
||||
}
|
||||
//note_timbre;
|
||||
}
|
||||
|
||||
if (polyphony_rate > 0) {
|
||||
if (voices > 1) {
|
||||
voice_place %= voices;
|
||||
if (place++ > (frequencies[voice_place] / polyphony_rate)) {
|
||||
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
|
||||
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 {
|
||||
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
|
||||
frequency_alt = frequencies[voices - 2];
|
||||
}
|
||||
} else {
|
||||
frequency_alt = frequencies[voices - 2];
|
||||
}
|
||||
|
||||
if (envelope_index < 65535) {
|
||||
envelope_index++;
|
||||
}
|
||||
|
||||
freq = voice_envelope(freq);
|
||||
|
||||
if (freq < 30.517578125) {
|
||||
freq = 30.52;
|
||||
}
|
||||
|
||||
|
||||
if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
|
||||
UPDATE_CHANNEL_1_FREQ(freq);
|
||||
#ifdef VIBRATO_ENABLE
|
||||
if (vibrato_strength > 0) {
|
||||
freq_alt = vibrato(frequency_alt);
|
||||
} else {
|
||||
RESTART_CHANNEL_1();
|
||||
freq_alt = frequency_alt;
|
||||
}
|
||||
//note_timbre;
|
||||
#else
|
||||
freq_alt = frequency_alt;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
if (envelope_index < 65535) {
|
||||
envelope_index++;
|
||||
}
|
||||
freq = voice_envelope(freq);
|
||||
freq_alt = voice_envelope(freq_alt);
|
||||
|
||||
if (freq_alt < 30.517578125) {
|
||||
freq_alt = 30.52;
|
||||
}
|
||||
|
||||
if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
|
||||
UPDATE_CHANNEL_1_FREQ(freq);
|
||||
UPDATE_CHANNEL_2_FREQ(freq);
|
||||
}
|
||||
//note_timbre;
|
||||
if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) {
|
||||
UPDATE_CHANNEL_2_FREQ(freq_alt);
|
||||
} else {
|
||||
// gptStopTimer(&GPTD6);
|
||||
// gptStopTimer(&GPTD7);
|
||||
RESTART_CHANNEL_2();
|
||||
}
|
||||
//note_timbre;
|
||||
}
|
||||
|
||||
if (polyphony_rate > 0) {
|
||||
if (voices > 1) {
|
||||
voice_place %= voices;
|
||||
if (place++ > (frequencies[voice_place] / polyphony_rate)) {
|
||||
voice_place = (voice_place + 1) % voices;
|
||||
place = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
note_position++;
|
||||
bool end_of_note = false;
|
||||
if (GET_CHANNEL_1_FREQ > 0) {
|
||||
if (!note_resting)
|
||||
end_of_note = (note_position >= (note_length*8 - 1));
|
||||
else
|
||||
end_of_note = (note_position >= (note_length*8));
|
||||
#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 {
|
||||
end_of_note = (note_position >= (note_length*8));
|
||||
frequency = frequencies[voices - 1];
|
||||
}
|
||||
|
||||
if (end_of_note) {
|
||||
current_note++;
|
||||
if (current_note >= notes_count) {
|
||||
if (notes_repeat) {
|
||||
current_note = 0;
|
||||
} else {
|
||||
STOP_CHANNEL_1();
|
||||
STOP_CHANNEL_2();
|
||||
// gptStopTimer(&GPTD8);
|
||||
playing_notes = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!note_resting) {
|
||||
note_resting = true;
|
||||
current_note--;
|
||||
if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
|
||||
note_frequency = 0;
|
||||
note_length = 1;
|
||||
} else {
|
||||
note_frequency = (*notes_pointer)[current_note][0];
|
||||
note_length = 1;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
#ifdef VIBRATO_ENABLE
|
||||
if (vibrato_strength > 0) {
|
||||
freq = vibrato(frequency);
|
||||
} else {
|
||||
freq = frequency;
|
||||
}
|
||||
#else
|
||||
freq = frequency;
|
||||
#endif
|
||||
}
|
||||
|
||||
note_position = 0;
|
||||
if (envelope_index < 65535) {
|
||||
envelope_index++;
|
||||
}
|
||||
|
||||
freq = voice_envelope(freq);
|
||||
|
||||
if (freq < 30.517578125) {
|
||||
freq = 30.52;
|
||||
}
|
||||
|
||||
|
||||
if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
|
||||
UPDATE_CHANNEL_1_FREQ(freq);
|
||||
} else {
|
||||
RESTART_CHANNEL_1();
|
||||
}
|
||||
//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);
|
||||
|
||||
|
||||
if (GET_CHANNEL_1_FREQ != (uint16_t)freq) {
|
||||
UPDATE_CHANNEL_1_FREQ(freq);
|
||||
UPDATE_CHANNEL_2_FREQ(freq);
|
||||
}
|
||||
//note_timbre;
|
||||
} else {
|
||||
// gptStopTimer(&GPTD6);
|
||||
// gptStopTimer(&GPTD7);
|
||||
}
|
||||
|
||||
if (!audio_config.enable) {
|
||||
playing_notes = false;
|
||||
playing_note = false;
|
||||
note_position++;
|
||||
bool end_of_note = false;
|
||||
if (GET_CHANNEL_1_FREQ > 0) {
|
||||
if (!note_resting)
|
||||
end_of_note = (note_position >= (note_length*8 - 1));
|
||||
else
|
||||
end_of_note = (note_position >= (note_length*8));
|
||||
} else {
|
||||
end_of_note = (note_position >= (note_length*8));
|
||||
}
|
||||
|
||||
if (end_of_note) {
|
||||
current_note++;
|
||||
if (current_note >= notes_count) {
|
||||
if (notes_repeat) {
|
||||
current_note = 0;
|
||||
} else {
|
||||
STOP_CHANNEL_1();
|
||||
STOP_CHANNEL_2();
|
||||
// gptStopTimer(&GPTD8);
|
||||
playing_notes = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!note_resting) {
|
||||
note_resting = true;
|
||||
current_note--;
|
||||
if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
|
||||
note_frequency = 0;
|
||||
note_length = 1;
|
||||
} else {
|
||||
note_frequency = (*notes_pointer)[current_note][0];
|
||||
note_length = 1;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
void play_note(float freq, int vol) {
|
||||
|
||||
dprintf("audio play note freq=%d vol=%d", (int)freq, vol);
|
||||
dprintf("audio play note freq=%d vol=%d", (int)freq, vol);
|
||||
|
||||
if (!audio_initialized) {
|
||||
audio_init();
|
||||
if (!audio_initialized) {
|
||||
audio_init();
|
||||
}
|
||||
|
||||
if (audio_config.enable && voices < 8) {
|
||||
|
||||
// Cancel notes if notes are playing
|
||||
if (playing_notes) {
|
||||
stop_all_notes();
|
||||
}
|
||||
|
||||
if (audio_config.enable && voices < 8) {
|
||||
playing_note = true;
|
||||
|
||||
envelope_index = 0;
|
||||
|
||||
// Cancel notes if notes are playing
|
||||
if (playing_notes)
|
||||
stop_all_notes();
|
||||
|
||||
playing_note = true;
|
||||
|
||||
envelope_index = 0;
|
||||
|
||||
if (freq > 0) {
|
||||
frequencies[voices] = freq;
|
||||
volumes[voices] = vol;
|
||||
voices++;
|
||||
}
|
||||
|
||||
gptStart(&GPTD8, &gpt8cfg1);
|
||||
gptStartContinuous(&GPTD8, 2U);
|
||||
RESTART_CHANNEL_1();
|
||||
RESTART_CHANNEL_2();
|
||||
if (freq > 0) {
|
||||
frequencies[voices] = freq;
|
||||
volumes[voices] = vol;
|
||||
voices++;
|
||||
}
|
||||
|
||||
gptStart(&GPTD8, &gpt8cfg1);
|
||||
gptStartContinuous(&GPTD8, 2U);
|
||||
RESTART_CHANNEL_1();
|
||||
RESTART_CHANNEL_2();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
|
||||
{
|
||||
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) {
|
||||
|
||||
if (!audio_initialized) {
|
||||
audio_init();
|
||||
if (!audio_initialized) {
|
||||
audio_init();
|
||||
}
|
||||
|
||||
if (audio_config.enable) {
|
||||
|
||||
// Cancel note if a note is playing
|
||||
if (playing_note) {
|
||||
stop_all_notes();
|
||||
}
|
||||
|
||||
if (audio_config.enable) {
|
||||
playing_notes = true;
|
||||
|
||||
// Cancel note if a note is playing
|
||||
if (playing_note)
|
||||
stop_all_notes();
|
||||
notes_pointer = np;
|
||||
notes_count = n_count;
|
||||
notes_repeat = n_repeat;
|
||||
|
||||
playing_notes = true;
|
||||
place = 0;
|
||||
current_note = 0;
|
||||
|
||||
notes_pointer = np;
|
||||
notes_count = n_count;
|
||||
notes_repeat = n_repeat;
|
||||
|
||||
place = 0;
|
||||
current_note = 0;
|
||||
|
||||
note_frequency = (*notes_pointer)[current_note][0];
|
||||
note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
|
||||
note_position = 0;
|
||||
|
||||
gptStart(&GPTD8, &gpt8cfg1);
|
||||
gptStartContinuous(&GPTD8, 2U);
|
||||
RESTART_CHANNEL_1();
|
||||
RESTART_CHANNEL_2();
|
||||
}
|
||||
note_frequency = (*notes_pointer)[current_note][0];
|
||||
note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
|
||||
note_position = 0;
|
||||
|
||||
gptStart(&GPTD8, &gpt8cfg1);
|
||||
gptStartContinuous(&GPTD8, 2U);
|
||||
RESTART_CHANNEL_1();
|
||||
RESTART_CHANNEL_2();
|
||||
}
|
||||
}
|
||||
|
||||
bool is_playing_notes(void) {
|
||||
return playing_notes;
|
||||
return playing_notes;
|
||||
}
|
||||
|
||||
bool is_audio_on(void) {
|
||||
return (audio_config.enable != 0);
|
||||
return (audio_config.enable != 0);
|
||||
}
|
||||
|
||||
void audio_toggle(void) {
|
||||
audio_config.enable ^= 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
if (audio_config.enable)
|
||||
audio_on_user();
|
||||
audio_config.enable ^= 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
if (audio_config.enable) {
|
||||
audio_on_user();
|
||||
}
|
||||
}
|
||||
|
||||
void audio_on(void) {
|
||||
audio_config.enable = 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
audio_on_user();
|
||||
audio_config.enable = 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
audio_on_user();
|
||||
}
|
||||
|
||||
void audio_off(void) {
|
||||
audio_config.enable = 0;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
stop_all_notes();
|
||||
audio_config.enable = 0;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
}
|
||||
|
||||
#ifdef VIBRATO_ENABLE
|
||||
@@ -690,29 +696,29 @@ void audio_off(void) {
|
||||
// Vibrato rate functions
|
||||
|
||||
void set_vibrato_rate(float rate) {
|
||||
vibrato_rate = rate;
|
||||
vibrato_rate = rate;
|
||||
}
|
||||
|
||||
void increase_vibrato_rate(float change) {
|
||||
vibrato_rate *= change;
|
||||
vibrato_rate *= change;
|
||||
}
|
||||
|
||||
void decrease_vibrato_rate(float change) {
|
||||
vibrato_rate /= change;
|
||||
vibrato_rate /= change;
|
||||
}
|
||||
|
||||
#ifdef VIBRATO_STRENGTH_ENABLE
|
||||
|
||||
void set_vibrato_strength(float strength) {
|
||||
vibrato_strength = strength;
|
||||
vibrato_strength = strength;
|
||||
}
|
||||
|
||||
void increase_vibrato_strength(float change) {
|
||||
vibrato_strength *= change;
|
||||
vibrato_strength *= change;
|
||||
}
|
||||
|
||||
void decrease_vibrato_strength(float change) {
|
||||
vibrato_strength /= change;
|
||||
vibrato_strength /= change;
|
||||
}
|
||||
|
||||
#endif /* VIBRATO_STRENGTH_ENABLE */
|
||||
@@ -722,45 +728,45 @@ void decrease_vibrato_strength(float change) {
|
||||
// Polyphony functions
|
||||
|
||||
void set_polyphony_rate(float rate) {
|
||||
polyphony_rate = rate;
|
||||
polyphony_rate = rate;
|
||||
}
|
||||
|
||||
void enable_polyphony() {
|
||||
polyphony_rate = 5;
|
||||
polyphony_rate = 5;
|
||||
}
|
||||
|
||||
void disable_polyphony() {
|
||||
polyphony_rate = 0;
|
||||
polyphony_rate = 0;
|
||||
}
|
||||
|
||||
void increase_polyphony_rate(float change) {
|
||||
polyphony_rate *= change;
|
||||
polyphony_rate *= change;
|
||||
}
|
||||
|
||||
void decrease_polyphony_rate(float change) {
|
||||
polyphony_rate /= change;
|
||||
polyphony_rate /= change;
|
||||
}
|
||||
|
||||
// Timbre function
|
||||
|
||||
void set_timbre(float timbre) {
|
||||
note_timbre = timbre;
|
||||
note_timbre = timbre;
|
||||
}
|
||||
|
||||
// Tempo functions
|
||||
|
||||
void set_tempo(uint8_t tempo) {
|
||||
note_tempo = tempo;
|
||||
note_tempo = tempo;
|
||||
}
|
||||
|
||||
void decrease_tempo(uint8_t tempo_change) {
|
||||
note_tempo += tempo_change;
|
||||
note_tempo += tempo_change;
|
||||
}
|
||||
|
||||
void increase_tempo(uint8_t tempo_change) {
|
||||
if (note_tempo - tempo_change < 10) {
|
||||
note_tempo = 10;
|
||||
} else {
|
||||
note_tempo -= tempo_change;
|
||||
}
|
||||
if (note_tempo - tempo_change < 10) {
|
||||
note_tempo = 10;
|
||||
} else {
|
||||
note_tempo -= tempo_change;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
#include "matrix.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
|
||||
#ifndef DEBOUNCING_DELAY
|
||||
# define DEBOUNCING_DELAY 5
|
||||
#endif
|
||||
|
||||
void debounce_init(uint8_t num_rows) {
|
||||
}
|
||||
|
||||
#if DEBOUNCING_DELAY > 0
|
||||
|
||||
static bool debouncing = false;
|
||||
|
||||
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
|
||||
static uint16_t debouncing_time;
|
||||
|
||||
if (changed) {
|
||||
debouncing = true;
|
||||
debouncing_time = timer_read();
|
||||
}
|
||||
|
||||
if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
|
||||
for (uint8_t i = 0; i < num_rows; i++) {
|
||||
cooked[i] = raw[i];
|
||||
}
|
||||
debouncing = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool debounce_active(void) {
|
||||
return debouncing;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// no debounce
|
||||
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
|
||||
if (changed)
|
||||
{
|
||||
for (uint8_t i = 0; i < num_rows; i++) {
|
||||
cooked[i] = raw[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool debounce_active(void) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -8,4 +8,4 @@ void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool
|
||||
|
||||
bool debounce_active(void);
|
||||
|
||||
void debounce_init(uint8_t num_rows);
|
||||
void debounce_init(uint8_t num_rows);
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright 2017 Alex Ong<the.onga@gmail.com>
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
Basic per-key algorithm. Uses an 8-bit counter per key.
|
||||
After pressing a key, it immediately changes state, and sets a counter.
|
||||
No further inputs are accepted until DEBOUNCE milliseconds have occurred.
|
||||
*/
|
||||
|
||||
#include "matrix.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef DEBOUNCE
|
||||
#define DEBOUNCE 5
|
||||
#endif
|
||||
|
||||
|
||||
#if (MATRIX_COLS <= 8)
|
||||
# define ROW_SHIFTER ((uint8_t)1)
|
||||
#elif (MATRIX_COLS <= 16)
|
||||
# define ROW_SHIFTER ((uint16_t)1)
|
||||
#elif (MATRIX_COLS <= 32)
|
||||
# define ROW_SHIFTER ((uint32_t)1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define debounce_counter_t uint8_t
|
||||
|
||||
static debounce_counter_t *debounce_counters;
|
||||
|
||||
#define DEBOUNCE_ELAPSED 251
|
||||
#define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1)
|
||||
|
||||
void update_debounce_counters(uint8_t num_rows, uint8_t current_time);
|
||||
void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time);
|
||||
|
||||
//we use num_rows rather than MATRIX_ROWS to support split keyboards
|
||||
void debounce_init(uint8_t num_rows)
|
||||
{
|
||||
debounce_counters = (debounce_counter_t*)malloc(num_rows*MATRIX_COLS * sizeof(debounce_counter_t));
|
||||
int i = 0;
|
||||
for (uint8_t r = 0; r < num_rows; r++)
|
||||
{
|
||||
for (uint8_t c = 0; c < MATRIX_COLS; c++)
|
||||
{
|
||||
debounce_counters[i++] = DEBOUNCE_ELAPSED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
|
||||
{
|
||||
uint8_t current_time = timer_read() % MAX_DEBOUNCE;
|
||||
update_debounce_counters(num_rows, current_time);
|
||||
transfer_matrix_values(raw, cooked, num_rows, current_time);
|
||||
}
|
||||
|
||||
//If the current time is > debounce counter, set the counter to enable input.
|
||||
void update_debounce_counters(uint8_t num_rows, uint8_t current_time)
|
||||
{
|
||||
debounce_counter_t *debounce_pointer = debounce_counters;
|
||||
for (uint8_t row = 0; row < num_rows; row++)
|
||||
{
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++)
|
||||
{
|
||||
if (*debounce_pointer != DEBOUNCE_ELAPSED)
|
||||
{
|
||||
if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) {
|
||||
*debounce_pointer = DEBOUNCE_ELAPSED;
|
||||
}
|
||||
}
|
||||
debounce_pointer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// upload from raw_matrix to final matrix;
|
||||
void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time)
|
||||
{
|
||||
debounce_counter_t *debounce_pointer = debounce_counters;
|
||||
for (uint8_t row = 0; row < num_rows; row++)
|
||||
{
|
||||
matrix_row_t existing_row = cooked[row];
|
||||
matrix_row_t raw_row = raw[row];
|
||||
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++)
|
||||
{
|
||||
matrix_row_t col_mask = (ROW_SHIFTER << col);
|
||||
bool final_value = raw_row & col_mask;
|
||||
bool existing_value = existing_row & col_mask;
|
||||
if (*debounce_pointer == DEBOUNCE_ELAPSED &&
|
||||
(existing_value != final_value))
|
||||
{
|
||||
*debounce_pointer = current_time;
|
||||
existing_row ^= col_mask; //flip the bit.
|
||||
}
|
||||
debounce_pointer++;
|
||||
}
|
||||
cooked[row] = existing_row;
|
||||
}
|
||||
}
|
||||
|
||||
bool debounce_active(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright 2017 Alex Ong<the.onga@gmail.com>
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
Basic global debounce algorithm. Used in 99% of keyboards at time of implementation
|
||||
When no state changes have occured for DEBOUNCE milliseconds, we push the state.
|
||||
*/
|
||||
#include "matrix.h"
|
||||
#include "timer.h"
|
||||
#include "quantum.h"
|
||||
#ifndef DEBOUNCE
|
||||
#define DEBOUNCE 5
|
||||
#endif
|
||||
|
||||
void debounce_init(uint8_t num_rows) {}
|
||||
static bool debouncing = false;
|
||||
|
||||
#if DEBOUNCE > 0
|
||||
static uint16_t debouncing_time;
|
||||
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
|
||||
{
|
||||
if (changed) {
|
||||
debouncing = true;
|
||||
debouncing_time = timer_read();
|
||||
}
|
||||
|
||||
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
|
||||
for (int i = 0; i < num_rows; i++) {
|
||||
cooked[i] = raw[i];
|
||||
}
|
||||
debouncing = false;
|
||||
}
|
||||
}
|
||||
#else //no debouncing.
|
||||
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
|
||||
{
|
||||
for (int i = 0; i < num_rows; i++) {
|
||||
cooked[i] = raw[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool debounce_active(void) {
|
||||
return debouncing;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
Debounce algorithms belong in this folder.
|
||||
Here are a few ideas
|
||||
|
||||
1) Global vs Per-Key vs Per-Row
|
||||
* Global - one timer for all keys. Any key change state affects global timer
|
||||
* Per key - one timer per key
|
||||
* Per row - one timer per row
|
||||
|
||||
2) Eager vs symmetric vs assymetric
|
||||
* Eager - any key change is reported immediately. All further inputs for DEBOUNCE ms are ignored.
|
||||
* Symmetric - wait for no changes for DEBOUNCE ms before reporting change
|
||||
* Assymetric - wait for different times depending on key-down/key-up. E.g. Eager key-down, DEBOUNCE ms key up.
|
||||
|
||||
3) Timestamp vs cycles
|
||||
* old old old code waits n cycles, decreasing count by one each matrix_scan
|
||||
* newer code stores the millisecond the change occurred, and does subraction to figure out time elapsed.
|
||||
* Timestamps are superior, i don't think cycles will ever be used again once upgraded.
|
||||
|
||||
The default algorithm is symmetric and global.
|
||||
Here are a few that could be implemented:
|
||||
|
||||
debounce_sym_g.c
|
||||
debounce_sym_pk.c
|
||||
debounce_sym_pr.c
|
||||
debounce_sym_pr_cycles.c //currently used in ergo-dox
|
||||
debounce_eager_g.c
|
||||
debounce_eager_pk.c
|
||||
debounce_eager_pr.c //could be used in ergo-dox!
|
||||
@@ -127,7 +127,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
|
||||
action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
|
||||
break;
|
||||
case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
|
||||
mod = keycode & 0xF;
|
||||
mod = mod_config(keycode & 0xF);
|
||||
action_layer = (keycode >> 4) & 0xF;
|
||||
action.code = ACTION_LAYER_MODS(action_layer, mod);
|
||||
break;
|
||||
|
||||
@@ -67,7 +67,7 @@ const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
|
||||
/* P Q R S T U V W */
|
||||
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
|
||||
/* X Y Z [ \ ] ^ _ */
|
||||
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, DE_CIRC, DE_MINS,
|
||||
KC_X, DE_Y, DE_Z, KC_LBRC, KC_BSLS, KC_RBRC, DE_CIRC, DE_MINS,
|
||||
/* ` a b c d e f g */
|
||||
DE_ACUT, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
|
||||
/* h i j k l m n o */
|
||||
@@ -75,7 +75,7 @@ const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
|
||||
/* p q r s t u v w */
|
||||
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
|
||||
/* x y z { | } ~ DELETE */
|
||||
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
|
||||
KC_X, DE_Y, DE_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Copyright 2019 Rys Sommefeldt
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* SEND_STRING() LUTs for UK layouts */
|
||||
|
||||
#ifndef SENDSTRING_UK
|
||||
#define SENDSTRING_UK
|
||||
|
||||
const bool ascii_to_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,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
0, 1, 1, 1, 1, 1, 1, 0,
|
||||
1, 1, 1, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 1, 0, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 0, 0, 0, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 1, 1, 1, 1, 0
|
||||
};
|
||||
|
||||
const uint8_t ascii_to_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,
|
||||
0, 0, 0, KC_ESC, 0, 0, 0, 0,
|
||||
|
||||
KC_SPC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
|
||||
KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
|
||||
KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
|
||||
KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
|
||||
KC_QUOT, 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,
|
||||
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
|
||||
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
|
||||
KC_GRV, 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,
|
||||
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
|
||||
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,391 @@
|
||||
/* Copyright 2017 Jason Williams
|
||||
* Copyright 2017 Jack Humbert
|
||||
* Copyright 2018 Yiancar
|
||||
* Copyright 2019 Clueboard
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "quantum.h"
|
||||
#include "ledmatrix.h"
|
||||
#include "progmem.h"
|
||||
#include "config.h"
|
||||
#include "eeprom.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
led_config_t led_matrix_config;
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a) < (b)? (a): (b))
|
||||
#endif
|
||||
|
||||
#ifndef LED_DISABLE_AFTER_TIMEOUT
|
||||
#define LED_DISABLE_AFTER_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
#ifndef LED_DISABLE_WHEN_USB_SUSPENDED
|
||||
#define LED_DISABLE_WHEN_USB_SUSPENDED false
|
||||
#endif
|
||||
|
||||
#ifndef EECONFIG_LED_MATRIX
|
||||
#define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT
|
||||
#endif
|
||||
|
||||
#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255
|
||||
#define LED_MATRIX_MAXIMUM_BRIGHTNESS 255
|
||||
#endif
|
||||
|
||||
bool g_suspend_state = false;
|
||||
|
||||
// Global tick at 20 Hz
|
||||
uint32_t g_tick = 0;
|
||||
|
||||
// Ticks since this key was last hit.
|
||||
uint8_t g_key_hit[LED_DRIVER_LED_COUNT];
|
||||
|
||||
// Ticks since any key was last hit.
|
||||
uint32_t g_any_key_hit = 0;
|
||||
|
||||
uint32_t eeconfig_read_led_matrix(void) {
|
||||
return eeprom_read_dword(EECONFIG_LED_MATRIX);
|
||||
}
|
||||
|
||||
void eeconfig_update_led_matrix(uint32_t config_value) {
|
||||
eeprom_update_dword(EECONFIG_LED_MATRIX, config_value);
|
||||
}
|
||||
|
||||
void eeconfig_update_led_matrix_default(void) {
|
||||
dprintf("eeconfig_update_led_matrix_default\n");
|
||||
led_matrix_config.enable = 1;
|
||||
led_matrix_config.mode = LED_MATRIX_UNIFORM_BRIGHTNESS;
|
||||
led_matrix_config.val = 128;
|
||||
led_matrix_config.speed = 0;
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void eeconfig_debug_led_matrix(void) {
|
||||
dprintf("led_matrix_config eeprom\n");
|
||||
dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable);
|
||||
dprintf("led_matrix_config.mode = %d\n", led_matrix_config.mode);
|
||||
dprintf("led_matrix_config.val = %d\n", led_matrix_config.val);
|
||||
dprintf("led_matrix_config.speed = %d\n", led_matrix_config.speed);
|
||||
}
|
||||
|
||||
// Last led hit
|
||||
#ifndef LED_HITS_TO_REMEMBER
|
||||
#define LED_HITS_TO_REMEMBER 8
|
||||
#endif
|
||||
uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255};
|
||||
uint8_t g_last_led_count = 0;
|
||||
|
||||
void map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) {
|
||||
led_matrix led;
|
||||
*led_count = 0;
|
||||
|
||||
for (uint8_t i = 0; i < LED_DRIVER_LED_COUNT; i++) {
|
||||
// map_index_to_led(i, &led);
|
||||
led = g_leds[i];
|
||||
if (row == led.matrix_co.row && column == led.matrix_co.col) {
|
||||
led_i[*led_count] = i;
|
||||
(*led_count)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void led_matrix_update_pwm_buffers(void) {
|
||||
led_matrix_driver.flush();
|
||||
}
|
||||
|
||||
void led_matrix_set_index_value(int index, uint8_t value) {
|
||||
led_matrix_driver.set_value(index, value);
|
||||
}
|
||||
|
||||
void led_matrix_set_index_value_all(uint8_t value) {
|
||||
led_matrix_driver.set_value_all(value);
|
||||
}
|
||||
|
||||
bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
uint8_t led[8], led_count;
|
||||
map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count);
|
||||
if (led_count > 0) {
|
||||
for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) {
|
||||
g_last_led_hit[i - 1] = g_last_led_hit[i - 2];
|
||||
}
|
||||
g_last_led_hit[0] = led[0];
|
||||
g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1);
|
||||
}
|
||||
for(uint8_t i = 0; i < led_count; i++)
|
||||
g_key_hit[led[i]] = 0;
|
||||
g_any_key_hit = 0;
|
||||
} else {
|
||||
#ifdef LED_MATRIX_KEYRELEASES
|
||||
uint8_t led[8], led_count;
|
||||
map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count);
|
||||
for(uint8_t i = 0; i < led_count; i++)
|
||||
g_key_hit[led[i]] = 255;
|
||||
|
||||
g_any_key_hit = 255;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void led_matrix_set_suspend_state(bool state) {
|
||||
g_suspend_state = state;
|
||||
}
|
||||
|
||||
// All LEDs off
|
||||
void led_matrix_all_off(void) {
|
||||
led_matrix_set_index_value_all(0);
|
||||
}
|
||||
|
||||
// Uniform brightness
|
||||
void led_matrix_uniform_brightness(void) {
|
||||
led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_config.val);
|
||||
}
|
||||
|
||||
void led_matrix_custom(void) {}
|
||||
|
||||
void led_matrix_task(void) {
|
||||
if (!led_matrix_config.enable) {
|
||||
led_matrix_all_off();
|
||||
led_matrix_indicators();
|
||||
return;
|
||||
}
|
||||
|
||||
g_tick++;
|
||||
|
||||
if (g_any_key_hit < 0xFFFFFFFF) {
|
||||
g_any_key_hit++;
|
||||
}
|
||||
|
||||
for (int led = 0; led < LED_DRIVER_LED_COUNT; led++) {
|
||||
if (g_key_hit[led] < 255) {
|
||||
if (g_key_hit[led] == 254)
|
||||
g_last_led_count = MAX(g_last_led_count - 1, 0);
|
||||
g_key_hit[led]++;
|
||||
}
|
||||
}
|
||||
|
||||
// Ideally we would also stop sending zeros to the LED driver PWM buffers
|
||||
// while suspended and just do a software shutdown. This is a cheap hack for now.
|
||||
bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) ||
|
||||
(LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20));
|
||||
uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode;
|
||||
|
||||
// this gets ticked at 20 Hz.
|
||||
// each effect can opt to do calculations
|
||||
// and/or request PWM buffer updates.
|
||||
switch (effect) {
|
||||
case LED_MATRIX_UNIFORM_BRIGHTNESS:
|
||||
led_matrix_uniform_brightness();
|
||||
break;
|
||||
default:
|
||||
led_matrix_custom();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!suspend_backlight) {
|
||||
led_matrix_indicators();
|
||||
}
|
||||
|
||||
// Tell the LED driver to update its state
|
||||
led_matrix_driver.flush();
|
||||
}
|
||||
|
||||
void led_matrix_indicators(void) {
|
||||
led_matrix_indicators_kb();
|
||||
led_matrix_indicators_user();
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
void led_matrix_indicators_kb(void) {}
|
||||
|
||||
__attribute__((weak))
|
||||
void led_matrix_indicators_user(void) {}
|
||||
|
||||
|
||||
// void led_matrix_set_indicator_index(uint8_t *index, uint8_t row, uint8_t column)
|
||||
// {
|
||||
// if (row >= MATRIX_ROWS)
|
||||
// {
|
||||
// // Special value, 255=none, 254=all
|
||||
// *index = row;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // This needs updated to something like
|
||||
// // uint8_t led[8], led_count;
|
||||
// // map_row_column_to_led(row,column,led,&led_count);
|
||||
// // for(uint8_t i = 0; i < led_count; i++)
|
||||
// map_row_column_to_led(row, column, index);
|
||||
// }
|
||||
// }
|
||||
|
||||
void led_matrix_init(void) {
|
||||
led_matrix_driver.init();
|
||||
|
||||
// Wait half a second for the driver to finish initializing
|
||||
wait_ms(500);
|
||||
|
||||
// clear the key hits
|
||||
for (int led=0; led<LED_DRIVER_LED_COUNT; led++) {
|
||||
g_key_hit[led] = 255;
|
||||
}
|
||||
|
||||
if (!eeconfig_is_enabled()) {
|
||||
dprintf("led_matrix_init_drivers eeconfig is not enabled.\n");
|
||||
eeconfig_init();
|
||||
eeconfig_update_led_matrix_default();
|
||||
}
|
||||
|
||||
led_matrix_config.raw = eeconfig_read_led_matrix();
|
||||
|
||||
if (!led_matrix_config.mode) {
|
||||
dprintf("led_matrix_init_drivers led_matrix_config.mode = 0. Write default values to EEPROM.\n");
|
||||
eeconfig_update_led_matrix_default();
|
||||
led_matrix_config.raw = eeconfig_read_led_matrix();
|
||||
}
|
||||
|
||||
eeconfig_debug_led_matrix(); // display current eeprom values
|
||||
}
|
||||
|
||||
// Deals with the messy details of incrementing an integer
|
||||
static uint8_t increment(uint8_t value, uint8_t step, uint8_t min, uint8_t max) {
|
||||
int16_t new_value = value;
|
||||
new_value += step;
|
||||
return MIN(MAX(new_value, min), max);
|
||||
}
|
||||
|
||||
static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) {
|
||||
int16_t new_value = value;
|
||||
new_value -= step;
|
||||
return MIN(MAX(new_value, min), max);
|
||||
}
|
||||
|
||||
// void *backlight_get_custom_key_value_eeprom_address(uint8_t led) {
|
||||
// // 3 bytes per value
|
||||
// return EECONFIG_LED_MATRIX + (led * 3);
|
||||
// }
|
||||
|
||||
// void backlight_get_key_value(uint8_t led, uint8_t *value) {
|
||||
// void *address = backlight_get_custom_key_value_eeprom_address(led);
|
||||
// value = eeprom_read_byte(address);
|
||||
// }
|
||||
|
||||
// void backlight_set_key_value(uint8_t row, uint8_t column, uint8_t value) {
|
||||
// uint8_t led[8], led_count;
|
||||
// map_row_column_to_led(row,column,led,&led_count);
|
||||
// for(uint8_t i = 0; i < led_count; i++) {
|
||||
// if (led[i] < LED_DRIVER_LED_COUNT) {
|
||||
// void *address = backlight_get_custom_key_value_eeprom_address(led[i]);
|
||||
// eeprom_update_byte(address, value);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
uint32_t led_matrix_get_tick(void) {
|
||||
return g_tick;
|
||||
}
|
||||
|
||||
void led_matrix_toggle(void) {
|
||||
led_matrix_config.enable ^= 1;
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_enable(void) {
|
||||
led_matrix_config.enable = 1;
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_enable_noeeprom(void) {
|
||||
led_matrix_config.enable = 1;
|
||||
}
|
||||
|
||||
void led_matrix_disable(void) {
|
||||
led_matrix_config.enable = 0;
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_disable_noeeprom(void) {
|
||||
led_matrix_config.enable = 0;
|
||||
}
|
||||
|
||||
void led_matrix_step(void) {
|
||||
led_matrix_config.mode++;
|
||||
if (led_matrix_config.mode >= LED_MATRIX_EFFECT_MAX) {
|
||||
led_matrix_config.mode = 1;
|
||||
}
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_step_reverse(void) {
|
||||
led_matrix_config.mode--;
|
||||
if (led_matrix_config.mode < 1) {
|
||||
led_matrix_config.mode = LED_MATRIX_EFFECT_MAX - 1;
|
||||
}
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_increase_val(void) {
|
||||
led_matrix_config.val = increment(led_matrix_config.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_decrease_val(void) {
|
||||
led_matrix_config.val = decrement(led_matrix_config.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void led_matrix_increase_speed(void) {
|
||||
led_matrix_config.speed = increment(led_matrix_config.speed, 1, 0, 3);
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);//EECONFIG needs to be increased to support this
|
||||
}
|
||||
|
||||
void led_matrix_decrease_speed(void) {
|
||||
led_matrix_config.speed = decrement(led_matrix_config.speed, 1, 0, 3);
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);//EECONFIG needs to be increased to support this
|
||||
}
|
||||
|
||||
void led_matrix_mode(uint8_t mode, bool eeprom_write) {
|
||||
led_matrix_config.mode = mode;
|
||||
if (eeprom_write) {
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t led_matrix_get_mode(void) {
|
||||
return led_matrix_config.mode;
|
||||
}
|
||||
|
||||
void led_matrix_set_value_noeeprom(uint8_t val) {
|
||||
led_matrix_config.val = val;
|
||||
}
|
||||
|
||||
void led_matrix_set_value(uint8_t val) {
|
||||
led_matrix_set_value_noeeprom(val);
|
||||
eeconfig_update_led_matrix(led_matrix_config.raw);
|
||||
}
|
||||
|
||||
void backlight_set(uint8_t val) {
|
||||
led_matrix_set_value(val);
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/* Copyright 2018 James Laird-Wah
|
||||
* Copyright 2019 Clueboard
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "quantum.h"
|
||||
#include "ledmatrix.h"
|
||||
|
||||
/* Each driver needs to define a struct:
|
||||
*
|
||||
* const led_matrix_driver_t led_matrix_driver;
|
||||
*
|
||||
* All members must be provided. Keyboard custom drivers must define this
|
||||
* in their own files.
|
||||
*/
|
||||
|
||||
#if defined(IS31FL3731) || defined(IS31FL3733)
|
||||
|
||||
#if defined(IS31FL3731)
|
||||
#include "is31fl3731-simple.h"
|
||||
#endif
|
||||
|
||||
#include "i2c_master.h"
|
||||
|
||||
static void init(void) {
|
||||
i2c_init();
|
||||
#ifdef IS31FL3731
|
||||
#ifdef LED_DRIVER_ADDR_1
|
||||
IS31FL3731_init(LED_DRIVER_ADDR_1);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_2
|
||||
IS31FL3731_init(LED_DRIVER_ADDR_2);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_3
|
||||
IS31FL3731_init(LED_DRIVER_ADDR_3);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_4
|
||||
IS31FL3731_init(LED_DRIVER_ADDR_4);
|
||||
#endif
|
||||
#else
|
||||
#ifdef LED_DRIVER_ADDR_1
|
||||
IS31FL3733_init(LED_DRIVER_ADDR_1);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_2
|
||||
IS31FL3733_init(LED_DRIVER_ADDR_2);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_3
|
||||
IS31FL3733_init(LED_DRIVER_ADDR_3);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_4
|
||||
IS31FL3733_init(LED_DRIVER_ADDR_4);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
for (int index = 0; index < LED_DRIVER_LED_COUNT; index++) {
|
||||
#ifdef IS31FL3731
|
||||
IS31FL3731_set_led_control_register(index, true);
|
||||
#else
|
||||
IS31FL3733_set_led_control_register(index, true);
|
||||
#endif
|
||||
}
|
||||
// This actually updates the LED drivers
|
||||
#ifdef IS31FL3731
|
||||
#ifdef LED_DRIVER_ADDR_1
|
||||
IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_2
|
||||
IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_3
|
||||
IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_4
|
||||
IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
|
||||
#endif
|
||||
#else
|
||||
#ifdef LED_DRIVER_ADDR_1
|
||||
IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_2
|
||||
IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_3
|
||||
IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_4
|
||||
IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void flush(void) {
|
||||
#ifdef IS31FL3731
|
||||
#ifdef LED_DRIVER_ADDR_1
|
||||
IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_2
|
||||
IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_3
|
||||
IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_4
|
||||
IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
|
||||
#endif
|
||||
#else
|
||||
#ifdef LED_DRIVER_ADDR_1
|
||||
IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_2
|
||||
IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_3
|
||||
IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
|
||||
#endif
|
||||
#ifdef LED_DRIVER_ADDR_4
|
||||
IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
const led_matrix_driver_t led_matrix_driver = {
|
||||
.init = init,
|
||||
.flush = flush,
|
||||
#ifdef IS31FL3731
|
||||
.set_value = IS31FL3731_set_value,
|
||||
.set_value_all = IS31FL3731_set_value_all,
|
||||
#else
|
||||
.set_value = IS31FL3733_set_value,
|
||||
.set_value_all = IS31FL3733_set_value_all,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,129 @@
|
||||
/* Copyright 2017 Jason Williams
|
||||
* Copyright 2017 Jack Humbert
|
||||
* Copyright 2018 Yiancar
|
||||
* Copyright 2019 Clueboard
|
||||
*
|
||||
* 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 LED_MATRIX_H
|
||||
#define LED_MATRIX_H
|
||||
|
||||
|
||||
#ifndef BACKLIGHT_ENABLE
|
||||
#error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct Point {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} __attribute__((packed)) Point;
|
||||
|
||||
typedef struct led_matrix {
|
||||
union {
|
||||
uint8_t raw;
|
||||
struct {
|
||||
uint8_t row:4; // 16 max
|
||||
uint8_t col:4; // 16 max
|
||||
};
|
||||
} matrix_co;
|
||||
Point point;
|
||||
uint8_t modifier:1;
|
||||
} __attribute__((packed)) led_matrix;
|
||||
|
||||
extern const led_matrix g_leds[LED_DRIVER_LED_COUNT];
|
||||
|
||||
typedef struct {
|
||||
uint8_t index;
|
||||
uint8_t value;
|
||||
} led_indicator;
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
bool enable :1;
|
||||
uint8_t mode :6;
|
||||
uint8_t hue :8; // Unused by led_matrix
|
||||
uint8_t sat :8; // Unused by led_matrix
|
||||
uint8_t val :8;
|
||||
uint8_t speed :8;//EECONFIG needs to be increased to support this
|
||||
};
|
||||
} led_config_t;
|
||||
|
||||
enum led_matrix_effects {
|
||||
LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
|
||||
// All new effects go above this line
|
||||
LED_MATRIX_EFFECT_MAX
|
||||
};
|
||||
|
||||
void led_matrix_set_index_value(int index, uint8_t value);
|
||||
void led_matrix_set_index_value_all(uint8_t value);
|
||||
|
||||
// This runs after another backlight effect and replaces
|
||||
// colors already set
|
||||
void led_matrix_indicators(void);
|
||||
void led_matrix_indicators_kb(void);
|
||||
void led_matrix_indicators_user(void);
|
||||
|
||||
void led_matrix_init(void);
|
||||
void led_matrix_setup_drivers(void);
|
||||
|
||||
void led_matrix_set_suspend_state(bool state);
|
||||
void led_matrix_set_indicator_state(uint8_t state);
|
||||
|
||||
void led_matrix_task(void);
|
||||
|
||||
// This should not be called from an interrupt
|
||||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void led_matrix_update_pwm_buffers(void);
|
||||
|
||||
bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
uint32_t led_matrix_get_tick(void);
|
||||
|
||||
void led_matrix_toggle(void);
|
||||
void led_matrix_enable(void);
|
||||
void led_matrix_enable_noeeprom(void);
|
||||
void led_matrix_disable(void);
|
||||
void led_matrix_disable_noeeprom(void);
|
||||
void led_matrix_step(void);
|
||||
void led_matrix_step_reverse(void);
|
||||
void led_matrix_increase_val(void);
|
||||
void led_matrix_decrease_val(void);
|
||||
void led_matrix_increase_speed(void);
|
||||
void led_matrix_decrease_speed(void);
|
||||
void led_matrix_mode(uint8_t mode, bool eeprom_write);
|
||||
void led_matrix_mode_noeeprom(uint8_t mode);
|
||||
uint8_t led_matrix_get_mode(void);
|
||||
void led_matrix_set_value(uint8_t mode);
|
||||
void led_matrix_set_value_noeeprom(uint8_t mode);
|
||||
|
||||
typedef struct {
|
||||
/* Perform any initialisation required for the other driver functions to work. */
|
||||
void (*init)(void);
|
||||
|
||||
/* Set the brightness of a single LED in the buffer. */
|
||||
void (*set_value)(int index, uint8_t value);
|
||||
/* Set the brightness of all LEDS on the keyboard in the buffer. */
|
||||
void (*set_value_all)(uint8_t value);
|
||||
/* Flush any buffered changes to the hardware. */
|
||||
void (*flush)(void);
|
||||
} led_matrix_driver_t;
|
||||
|
||||
extern const led_matrix_driver_t led_matrix_driver;
|
||||
|
||||
#endif
|
||||
+3
-28
@@ -51,10 +51,8 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
||||
#endif
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static matrix_row_t raw_matrix[MATRIX_ROWS];
|
||||
|
||||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
|
||||
static matrix_row_t raw_matrix[MATRIX_ROWS]; //raw values
|
||||
static matrix_row_t matrix[MATRIX_ROWS]; //debounced values
|
||||
|
||||
#if (DIODE_DIRECTION == COL2ROW)
|
||||
static void init_cols(void);
|
||||
@@ -108,30 +106,6 @@ uint8_t matrix_cols(void) {
|
||||
return MATRIX_COLS;
|
||||
}
|
||||
|
||||
// void matrix_power_up(void) {
|
||||
// #if (DIODE_DIRECTION == COL2ROW)
|
||||
// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
|
||||
// /* DDRxn */
|
||||
// _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
|
||||
// toggle_row(r);
|
||||
// }
|
||||
// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
|
||||
// /* PORTxn */
|
||||
// _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
|
||||
// }
|
||||
// #elif (DIODE_DIRECTION == ROW2COL)
|
||||
// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
|
||||
// /* DDRxn */
|
||||
// _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
|
||||
// toggle_col(c);
|
||||
// }
|
||||
// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
|
||||
// /* PORTxn */
|
||||
// _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF);
|
||||
// }
|
||||
// #endif
|
||||
// }
|
||||
|
||||
void matrix_init(void) {
|
||||
|
||||
// initialize row and col
|
||||
@@ -175,6 +149,7 @@ uint8_t matrix_scan(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Deprecated.
|
||||
bool matrix_is_modified(void)
|
||||
{
|
||||
if (debounce_active()) return false;
|
||||
|
||||
@@ -32,7 +32,7 @@ extern bool midi_activated;
|
||||
|
||||
void clicky_play(void) {
|
||||
#ifndef NO_MUSIC_MODE
|
||||
if (music_activated || midi_activated) return;
|
||||
if (music_activated || midi_activated || !audio_config.enable) return;
|
||||
#endif // !NO_MUSIC_MODE
|
||||
clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
||||
clicky_song[1][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
||||
@@ -73,27 +73,29 @@ void clicky_off(void) {
|
||||
}
|
||||
|
||||
bool is_clicky_on(void) {
|
||||
return (audio_config.clicky_enable != 0);
|
||||
return (audio_config.clicky_enable != 0);
|
||||
}
|
||||
|
||||
bool process_clicky(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); }
|
||||
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); }
|
||||
|
||||
if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); }
|
||||
if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); }
|
||||
if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); }
|
||||
if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); }
|
||||
|
||||
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }
|
||||
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }
|
||||
|
||||
if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
|
||||
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
|
||||
if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
|
||||
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
|
||||
|
||||
|
||||
if ( audio_config.clicky_enable ) {
|
||||
if (record->event.pressed) {
|
||||
clicky_play();;
|
||||
if (audio_config.enable && audio_config.clicky_enable) {
|
||||
if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
|
||||
if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
|
||||
clicky_play();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //AUDIO_CLICKY
|
||||
|
||||
@@ -114,13 +114,13 @@ static void send_steno_chord(void) {
|
||||
if (send_steno_chord_user(mode, chord)) {
|
||||
switch(mode) {
|
||||
case STENO_MODE_BOLT:
|
||||
send_steno_state(BOLT_STATE_SIZE, false);
|
||||
virtser_send(0); // terminating byte
|
||||
break;
|
||||
send_steno_state(BOLT_STATE_SIZE, false);
|
||||
virtser_send(0); // terminating byte
|
||||
break;
|
||||
case STENO_MODE_GEMINI:
|
||||
chord[0] |= 0x80; // Indicate start of packet
|
||||
send_steno_state(GEMINI_STATE_SIZE, true);
|
||||
break;
|
||||
chord[0] |= 0x80; // Indicate start of packet
|
||||
send_steno_state(GEMINI_STATE_SIZE, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
steno_clear_state();
|
||||
@@ -161,7 +161,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
case QK_STENO_BOLT:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
steno_set_mode(STENO_MODE_BOLT);
|
||||
@@ -170,7 +170,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
case QK_STENO_GEMINI:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
steno_set_mode(STENO_MODE_GEMINI);
|
||||
@@ -179,25 +179,27 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
case STN__MIN...STN__MAX:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
switch(mode) {
|
||||
case STENO_MODE_BOLT:
|
||||
update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
case STENO_MODE_GEMINI:
|
||||
update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
case STENO_MODE_BOLT:
|
||||
update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
break;
|
||||
case STENO_MODE_GEMINI:
|
||||
update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
break;
|
||||
}
|
||||
// allow postprocessing hooks
|
||||
if (postprocess_steno_user(keycode, record, mode, chord, pressed)) {
|
||||
if (IS_PRESSED(record->event)) {
|
||||
++pressed;
|
||||
} else {
|
||||
--pressed;
|
||||
if (pressed <= 0) {
|
||||
pressed = 0;
|
||||
send_steno_chord();
|
||||
}
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
++pressed;
|
||||
} else {
|
||||
--pressed;
|
||||
if (pressed <= 0) {
|
||||
pressed = 0;
|
||||
send_steno_chord();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
#include "process_unicodemap.h"
|
||||
#include "process_unicode_common.h"
|
||||
|
||||
__attribute__((weak))
|
||||
const uint32_t PROGMEM unicode_map[] = {};
|
||||
|
||||
void register_hex32(uint32_t hex) {
|
||||
bool onzerostart = true;
|
||||
for(int i = 7; i >= 0; i--) {
|
||||
|
||||
@@ -19,5 +19,7 @@
|
||||
#include "quantum.h"
|
||||
#include "process_unicode_common.h"
|
||||
|
||||
extern const uint32_t PROGMEM unicode_map[];
|
||||
|
||||
void unicodemap_input_error(void);
|
||||
bool process_unicodemap(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
+78
-6
@@ -47,6 +47,13 @@ extern backlight_config_t backlight_config;
|
||||
#include "process_midi.h"
|
||||
#endif
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
#include "velocikey.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAPTIC_ENABLE
|
||||
#include "haptic.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENCODER_ENABLE
|
||||
#include "encoder.h"
|
||||
@@ -179,6 +186,9 @@ void reset_keyboard(void) {
|
||||
shutdown_user();
|
||||
wait_ms(250);
|
||||
#endif
|
||||
#ifdef HAPTIC_ENABLE
|
||||
haptic_shutdown();
|
||||
#endif
|
||||
// this is also done later in bootloader.c - not sure if it's neccesary here
|
||||
#ifdef BOOTLOADER_CATERINA
|
||||
*(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
|
||||
@@ -195,6 +205,13 @@ void reset_keyboard(void) {
|
||||
#define RSPC_KEY KC_0
|
||||
#endif
|
||||
|
||||
#ifndef LSPO_MOD
|
||||
#define LSPO_MOD KC_LSFT
|
||||
#endif
|
||||
#ifndef RSPC_MOD
|
||||
#define RSPC_MOD KC_RSFT
|
||||
#endif
|
||||
|
||||
// Shift / Enter setup
|
||||
#ifndef SFTENT_KEY
|
||||
#define SFTENT_KEY KC_ENT
|
||||
@@ -238,6 +255,10 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); }
|
||||
#endif
|
||||
|
||||
#ifdef TAP_DANCE_ENABLE
|
||||
preprocess_tap_dance(keycode, record);
|
||||
#endif
|
||||
@@ -250,6 +271,9 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
|
||||
process_clicky(keycode, record) &&
|
||||
#endif //AUDIO_CLICKY
|
||||
#ifdef HAPTIC_ENABLE
|
||||
process_haptic(keycode, record) &&
|
||||
#endif //HAPTIC_ENABLE
|
||||
process_record_kb(keycode, record) &&
|
||||
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES)
|
||||
process_rgb_matrix(keycode, record) &&
|
||||
@@ -552,7 +576,14 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
#endif
|
||||
return false;
|
||||
#endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
||||
#ifdef PROTOCOL_LUFA
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
case VLK_TOG:
|
||||
if (record->event.pressed) {
|
||||
velocikey_toggle();
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
#ifdef PROTOCOL_LUFA
|
||||
case OUT_AUTO:
|
||||
if (record->event.pressed) {
|
||||
set_output(OUTPUT_AUTO);
|
||||
@@ -674,14 +705,27 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
}
|
||||
else {
|
||||
#ifdef DISABLE_SPACE_CADET_ROLLOVER
|
||||
if (get_mods() & MOD_BIT(KC_RSFT)) {
|
||||
if (get_mods() & MOD_BIT(RSPC_MOD)) {
|
||||
shift_interrupted[0] = true;
|
||||
shift_interrupted[1] = true;
|
||||
}
|
||||
#endif
|
||||
if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) {
|
||||
#ifdef DISABLE_SPACE_CADET_MODIFIER
|
||||
unregister_mods(MOD_BIT(KC_LSFT));
|
||||
#else
|
||||
if( LSPO_MOD != KC_LSFT ){
|
||||
unregister_mods(MOD_BIT(KC_LSFT));
|
||||
register_mods(MOD_BIT(LSPO_MOD));
|
||||
}
|
||||
#endif
|
||||
register_code(LSPO_KEY);
|
||||
unregister_code(LSPO_KEY);
|
||||
#ifndef DISABLE_SPACE_CADET_MODIFIER
|
||||
if( LSPO_MOD != KC_LSFT ){
|
||||
unregister_mods(MOD_BIT(LSPO_MOD));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
unregister_mods(MOD_BIT(KC_LSFT));
|
||||
}
|
||||
@@ -696,14 +740,27 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
}
|
||||
else {
|
||||
#ifdef DISABLE_SPACE_CADET_ROLLOVER
|
||||
if (get_mods() & MOD_BIT(KC_LSFT)) {
|
||||
if (get_mods() & MOD_BIT(LSPO_MOD)) {
|
||||
shift_interrupted[0] = true;
|
||||
shift_interrupted[1] = true;
|
||||
}
|
||||
#endif
|
||||
if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) {
|
||||
#ifdef DISABLE_SPACE_CADET_MODIFIER
|
||||
unregister_mods(MOD_BIT(KC_RSFT));
|
||||
#else
|
||||
if( RSPC_MOD != KC_RSFT ){
|
||||
unregister_mods(MOD_BIT(KC_RSFT));
|
||||
register_mods(MOD_BIT(RSPC_MOD));
|
||||
}
|
||||
#endif
|
||||
register_code(RSPC_KEY);
|
||||
unregister_code(RSPC_KEY);
|
||||
#ifndef DISABLE_SPACE_CADET_MODIFIER
|
||||
if ( RSPC_MOD != KC_RSFT ){
|
||||
unregister_mods(MOD_BIT(RSPC_MOD));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
unregister_mods(MOD_BIT(KC_RSFT));
|
||||
}
|
||||
@@ -998,7 +1055,11 @@ void matrix_init_quantum() {
|
||||
eeconfig_init();
|
||||
}
|
||||
#ifdef BACKLIGHT_ENABLE
|
||||
backlight_init_ports();
|
||||
#ifdef LED_MATRIX_ENABLE
|
||||
led_matrix_init();
|
||||
#else
|
||||
backlight_init_ports();
|
||||
#endif
|
||||
#endif
|
||||
#ifdef AUDIO_ENABLE
|
||||
audio_init();
|
||||
@@ -1012,6 +1073,9 @@ void matrix_init_quantum() {
|
||||
#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
|
||||
unicode_input_mode_init();
|
||||
#endif
|
||||
#ifdef HAPTIC_ENABLE
|
||||
haptic_init();
|
||||
#endif
|
||||
matrix_init_kb();
|
||||
}
|
||||
|
||||
@@ -1034,8 +1098,12 @@ void matrix_scan_quantum() {
|
||||
matrix_scan_combo();
|
||||
#endif
|
||||
|
||||
#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
|
||||
backlight_task();
|
||||
#if defined(BACKLIGHT_ENABLE)
|
||||
#if defined(LED_MATRIX_ENABLE)
|
||||
led_matrix_task();
|
||||
#elif defined(BACKLIGHT_PIN)
|
||||
backlight_task();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
@@ -1050,6 +1118,10 @@ void matrix_scan_quantum() {
|
||||
encoder_read();
|
||||
#endif
|
||||
|
||||
#ifdef HAPTIC_ENABLE
|
||||
haptic_task();
|
||||
#endif
|
||||
|
||||
matrix_scan_kb();
|
||||
}
|
||||
#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
|
||||
|
||||
+9
-1
@@ -28,7 +28,11 @@
|
||||
#include "matrix.h"
|
||||
#include "keymap.h"
|
||||
#ifdef BACKLIGHT_ENABLE
|
||||
#include "backlight.h"
|
||||
#ifdef LED_MATRIX_ENABLE
|
||||
#include "ledmatrix.h"
|
||||
#else
|
||||
#include "backlight.h"
|
||||
#endif
|
||||
#endif
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
#include "rgblight.h"
|
||||
@@ -135,6 +139,10 @@ extern uint32_t default_layer_state;
|
||||
#include "hd44780.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAPTIC_ENABLE
|
||||
#include "haptic.h"
|
||||
#endif
|
||||
|
||||
//Function substitutions to ease GPIO manipulation
|
||||
#ifdef __AVR__
|
||||
#define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
|
||||
|
||||
@@ -422,6 +422,9 @@ enum quantum_keycodes {
|
||||
RGB_MODE_GRADIENT,
|
||||
RGB_MODE_RGBTEST,
|
||||
|
||||
//Momentum matching toggle
|
||||
VLK_TOG,
|
||||
|
||||
// Left shift, open paren
|
||||
KC_LSPO,
|
||||
|
||||
@@ -455,13 +458,23 @@ enum quantum_keycodes {
|
||||
|
||||
UNICODE_MODE_FORWARD,
|
||||
UNICODE_MODE_REVERSE,
|
||||
|
||||
UNICODE_MODE_OSX,
|
||||
UNICODE_MODE_LNX,
|
||||
UNICODE_MODE_WIN,
|
||||
UNICODE_MODE_BSD,
|
||||
UNICODE_MODE_WINC,
|
||||
|
||||
HPT_ON,
|
||||
HPT_OFF,
|
||||
HPT_TOG,
|
||||
HPT_RST,
|
||||
HPT_FBK,
|
||||
HPT_BUZ,
|
||||
HPT_MODI,
|
||||
HPT_MODD,
|
||||
HPT_DWLI,
|
||||
HPT_DWLD,
|
||||
|
||||
// always leave at the end
|
||||
SAFE_RANGE
|
||||
};
|
||||
|
||||
+114
-10
@@ -30,9 +30,8 @@
|
||||
#include "rgblight.h"
|
||||
#include "debug.h"
|
||||
#include "led_tables.h"
|
||||
|
||||
#ifndef RGBLIGHT_LIMIT_VAL
|
||||
#define RGBLIGHT_LIMIT_VAL 255
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
#include "velocikey.h"
|
||||
#endif
|
||||
|
||||
#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym,
|
||||
@@ -58,6 +57,7 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
|
||||
#endif
|
||||
|
||||
rgblight_config_t rgblight_config;
|
||||
bool is_rgblight_initialized = false;
|
||||
|
||||
LED_TYPE led[RGBLED_NUM];
|
||||
bool rgblight_timer_enabled = false;
|
||||
@@ -123,6 +123,35 @@ void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
|
||||
(*led1).b = b;
|
||||
}
|
||||
|
||||
void rgblight_check_config(void) {
|
||||
/* Add some out of bound checks for RGB light config */
|
||||
|
||||
if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) {
|
||||
rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
|
||||
}
|
||||
else if (rgblight_config.mode > RGBLIGHT_MODES) {
|
||||
rgblight_config.mode = RGBLIGHT_MODES;
|
||||
}
|
||||
|
||||
if (rgblight_config.hue < 0) {
|
||||
rgblight_config.hue = 0;
|
||||
} else if (rgblight_config.hue > 360) {
|
||||
rgblight_config.hue %= 360;
|
||||
}
|
||||
|
||||
if (rgblight_config.sat < 0) {
|
||||
rgblight_config.sat = 0;
|
||||
} else if (rgblight_config.sat > 255) {
|
||||
rgblight_config.sat = 255;
|
||||
}
|
||||
|
||||
if (rgblight_config.val < 0) {
|
||||
rgblight_config.val = 0;
|
||||
} else if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) {
|
||||
rgblight_config.val = RGBLIGHT_LIMIT_VAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32_t eeconfig_read_rgblight(void) {
|
||||
#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
|
||||
@@ -131,13 +160,14 @@ uint32_t eeconfig_read_rgblight(void) {
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void eeconfig_update_rgblight(uint32_t val) {
|
||||
#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
|
||||
if (eeconfig_read_rgblight() != val) {
|
||||
rgblight_check_config();
|
||||
eeprom_update_dword(EECONFIG_RGBLIGHT, val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void eeconfig_update_rgblight_default(void) {
|
||||
//dprintf("eeconfig_update_rgblight_default\n");
|
||||
rgblight_config.enable = 1;
|
||||
@@ -148,6 +178,7 @@ void eeconfig_update_rgblight_default(void) {
|
||||
rgblight_config.speed = 0;
|
||||
eeconfig_update_rgblight(rgblight_config.raw);
|
||||
}
|
||||
|
||||
void eeconfig_debug_rgblight(void) {
|
||||
dprintf("rgblight_config eprom\n");
|
||||
dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
|
||||
@@ -159,6 +190,11 @@ void eeconfig_debug_rgblight(void) {
|
||||
}
|
||||
|
||||
void rgblight_init(void) {
|
||||
/* if already initialized, don't do it again.
|
||||
If you must do it again, extern this and set to false, first.
|
||||
This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */
|
||||
if (is_rgblight_initialized) { return; }
|
||||
|
||||
debug_enable = 1; // Debug ON!
|
||||
dprintf("rgblight_init called.\n");
|
||||
dprintf("rgblight_init start!\n");
|
||||
@@ -173,6 +209,8 @@ void rgblight_init(void) {
|
||||
eeconfig_update_rgblight_default();
|
||||
rgblight_config.raw = eeconfig_read_rgblight();
|
||||
}
|
||||
rgblight_check_config();
|
||||
|
||||
eeconfig_debug_rgblight(); // display current eeprom values
|
||||
|
||||
#ifdef RGBLIGHT_USE_TIMER
|
||||
@@ -182,6 +220,9 @@ void rgblight_init(void) {
|
||||
if (rgblight_config.enable) {
|
||||
rgblight_mode_noeeprom(rgblight_config.mode);
|
||||
}
|
||||
|
||||
is_rgblight_initialized = true;
|
||||
|
||||
}
|
||||
|
||||
void rgblight_update_dword(uint32_t dword) {
|
||||
@@ -569,6 +610,55 @@ void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) {
|
||||
rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
|
||||
}
|
||||
|
||||
#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \
|
||||
|| defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
|
||||
|
||||
static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
|
||||
return
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
|
||||
#endif
|
||||
pgm_read_byte(default_interval_address);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
|
||||
if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; }
|
||||
|
||||
for (uint8_t i = start; i < end; i++) {
|
||||
led[i].r = r;
|
||||
led[i].g = g;
|
||||
led[i].b = b;
|
||||
}
|
||||
rgblight_set();
|
||||
wait_ms(1);
|
||||
}
|
||||
|
||||
void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
|
||||
if (!rgblight_config.enable) { return; }
|
||||
|
||||
LED_TYPE tmp_led;
|
||||
sethsv(hue, sat, val, &tmp_led);
|
||||
rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
|
||||
}
|
||||
|
||||
void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) {
|
||||
rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2);
|
||||
}
|
||||
|
||||
void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) {
|
||||
rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
|
||||
}
|
||||
|
||||
void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val) {
|
||||
rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2);
|
||||
}
|
||||
|
||||
void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) {
|
||||
rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
|
||||
}
|
||||
|
||||
#ifndef RGBLIGHT_CUSTOM_DRIVER
|
||||
void rgblight_set(void) {
|
||||
if (rgblight_config.enable) {
|
||||
@@ -633,6 +723,7 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
|
||||
}
|
||||
|
||||
void rgblight_task(void) {
|
||||
|
||||
if (rgblight_timer_enabled) {
|
||||
// static light mode, do nothing here
|
||||
if ( 1 == 0 ) { //dummy
|
||||
@@ -704,7 +795,9 @@ void rgblight_effect_breathing(uint8_t interval) {
|
||||
static uint16_t last_timer = 0;
|
||||
float val;
|
||||
|
||||
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) {
|
||||
uint8_t interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[interval], 1, 100);
|
||||
|
||||
if (timer_elapsed(last_timer) < interval_time) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@@ -724,7 +817,9 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
|
||||
static uint16_t current_hue = 0;
|
||||
static uint16_t last_timer = 0;
|
||||
|
||||
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) {
|
||||
uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100);
|
||||
|
||||
if (timer_elapsed(last_timer) < interval_time) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@@ -746,7 +841,10 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
|
||||
static uint16_t last_timer = 0;
|
||||
uint16_t hue;
|
||||
uint8_t i;
|
||||
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2])) {
|
||||
|
||||
uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
|
||||
|
||||
if (timer_elapsed(last_timer) < interval_time) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@@ -781,7 +879,10 @@ void rgblight_effect_snake(uint8_t interval) {
|
||||
if (interval % 2) {
|
||||
increment = -1;
|
||||
}
|
||||
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2])) {
|
||||
|
||||
uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200);
|
||||
|
||||
if (timer_elapsed(last_timer) < interval_time) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@@ -818,7 +919,10 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
|
||||
|
||||
void rgblight_effect_knight(uint8_t interval) {
|
||||
static uint16_t last_timer = 0;
|
||||
if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
|
||||
|
||||
uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100);
|
||||
|
||||
if (timer_elapsed(last_timer) < interval_time) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
|
||||
@@ -121,6 +121,9 @@ enum RGBLIGHT_EFFECT_MODE {
|
||||
#ifndef RGBLIGHT_VAL_STEP
|
||||
#define RGBLIGHT_VAL_STEP 17
|
||||
#endif
|
||||
#ifndef RGBLIGHT_LIMIT_VAL
|
||||
#define RGBLIGHT_LIMIT_VAL 255
|
||||
#endif
|
||||
|
||||
#define RGBLED_TIMER_TOP F_CPU/(256*64)
|
||||
// #define RGBLED_TIMER_TOP 0xFF10
|
||||
@@ -146,6 +149,7 @@ extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM;
|
||||
extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM;
|
||||
extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM;
|
||||
extern const uint16_t RGBLED_RGBTEST_INTERVALS[1] PROGMEM;
|
||||
extern bool is_rgblight_initialized;
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
@@ -186,6 +190,12 @@ uint8_t rgblight_get_val(void);
|
||||
void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
|
||||
void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index);
|
||||
void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index);
|
||||
void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end);
|
||||
void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end);
|
||||
void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b);
|
||||
void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b);
|
||||
void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val);
|
||||
void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val);
|
||||
|
||||
uint32_t eeconfig_read_rgblight(void);
|
||||
void eeconfig_update_rgblight(uint32_t val);
|
||||
|
||||
@@ -143,8 +143,8 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||
#elif (DIODE_DIRECTION == COL2ROW)
|
||||
|
||||
static void select_row(uint8_t row) {
|
||||
writePinLow(row_pins[row]);
|
||||
setPinOutput(row_pins[row]);
|
||||
writePinLow(row_pins[row]);
|
||||
}
|
||||
|
||||
static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
|
||||
@@ -188,8 +188,8 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||
#elif (DIODE_DIRECTION == ROW2COL)
|
||||
|
||||
static void select_col(uint8_t col) {
|
||||
writePinLow(col_pins[col]);
|
||||
setPinOutput(col_pins[col]);
|
||||
writePinLow(col_pins[col]);
|
||||
}
|
||||
|
||||
static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); }
|
||||
|
||||
@@ -45,7 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define MATRIX_COL_PINS { F1, F0, B0 }
|
||||
#define UNUSED_PINS
|
||||
|
||||
/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
|
||||
/* COL2ROW, ROW2COL*/
|
||||
#define DIODE_DIRECTION COL2ROW
|
||||
|
||||
/*
|
||||
@@ -143,8 +143,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
|
||||
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
|
||||
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
|
||||
//#define MAGIC_KEY_HELP1 H
|
||||
//#define MAGIC_KEY_HELP2 SLASH
|
||||
//#define MAGIC_KEY_HELP H
|
||||
//#define MAGIC_KEY_HELP_ALT SLASH
|
||||
//#define MAGIC_KEY_DEBUG D
|
||||
//#define MAGIC_KEY_DEBUG_MATRIX X
|
||||
//#define MAGIC_KEY_DEBUG_KBD K
|
||||
@@ -152,9 +152,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//#define MAGIC_KEY_VERSION V
|
||||
//#define MAGIC_KEY_STATUS S
|
||||
//#define MAGIC_KEY_CONSOLE C
|
||||
//#define MAGIC_KEY_LAYER0_ALT1 ESC
|
||||
//#define MAGIC_KEY_LAYER0_ALT2 GRAVE
|
||||
//#define MAGIC_KEY_LAYER0 0
|
||||
//#define MAGIC_KEY_LAYER0_ALT GRAVE
|
||||
//#define MAGIC_KEY_LAYER1 1
|
||||
//#define MAGIC_KEY_LAYER2 2
|
||||
//#define MAGIC_KEY_LAYER3 3
|
||||
@@ -164,9 +163,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//#define MAGIC_KEY_LAYER7 7
|
||||
//#define MAGIC_KEY_LAYER8 8
|
||||
//#define MAGIC_KEY_LAYER9 9
|
||||
//#define MAGIC_KEY_BOOTLOADER PAUSE
|
||||
//#define MAGIC_KEY_BOOTLOADER B
|
||||
//#define MAGIC_KEY_BOOTLOADER_ALT ESC
|
||||
//#define MAGIC_KEY_LOCK CAPS
|
||||
//#define MAGIC_KEY_EEPROM E
|
||||
//#define MAGIC_KEY_EEPROM_CLEAR BSPACE
|
||||
//#define MAGIC_KEY_NKRO N
|
||||
//#define MAGIC_KEY_SLEEP_LED Z
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "velocikey.h"
|
||||
#include "timer.h"
|
||||
#include "eeconfig.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#define TYPING_SPEED_MAX_VALUE 200
|
||||
uint8_t typing_speed = 0;
|
||||
|
||||
bool velocikey_enabled(void) {
|
||||
return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1;
|
||||
}
|
||||
|
||||
void velocikey_toggle(void) {
|
||||
if (velocikey_enabled())
|
||||
eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
|
||||
else
|
||||
eeprom_update_byte(EECONFIG_VELOCIKEY, 1);
|
||||
}
|
||||
|
||||
void velocikey_accelerate(void) {
|
||||
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
|
||||
}
|
||||
|
||||
void velocikey_decelerate(void) {
|
||||
static uint16_t decay_timer = 0;
|
||||
|
||||
if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
|
||||
if (typing_speed > 0) typing_speed -= 1;
|
||||
//Decay a little faster at half of max speed
|
||||
if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
|
||||
//Decay even faster at 3/4 of max speed
|
||||
if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
|
||||
decay_timer = timer_read();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
|
||||
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef VELOCIKEY_H
|
||||
#define VELOCIKEY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool velocikey_enabled(void);
|
||||
void velocikey_toggle(void);
|
||||
void velocikey_accelerate(void);
|
||||
void velocikey_decelerate(void);
|
||||
uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user