summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio/audio.c774
-rw-r--r--quantum/audio/audio.h18
-rw-r--r--quantum/audio/audio_pwm.c643
-rw-r--r--quantum/audio/frequency_lut.h357
-rw-r--r--quantum/audio/luts.c382
-rw-r--r--quantum/audio/luts.h15
-rw-r--r--quantum/audio/vibrato_lut.h28
-rw-r--r--quantum/audio/voices.c50
-rw-r--r--quantum/audio/voices.h3
-rw-r--r--quantum/config_common.h125
-rw-r--r--quantum/keymap_common.c46
-rw-r--r--quantum/keymap_common.h126
-rw-r--r--quantum/keymap_extras/keymap_german_ch.h102
-rw-r--r--quantum/keymap_midi.h10
-rw-r--r--quantum/keymap_unicode.c61
-rw-r--r--quantum/matrix.c374
-rw-r--r--quantum/quantum.c484
-rw-r--r--quantum/quantum.h76
-rw-r--r--quantum/quantum.mk17
-rw-r--r--quantum/template/Makefile46
-rw-r--r--quantum/template/config.h17
-rw-r--r--quantum/template/template.c68
-rw-r--r--quantum/template/template.h7
-rw-r--r--quantum/tools/README.md4
-rw-r--r--quantum/unicode.h128
25 files changed, 2640 insertions, 1321 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index e85370d958..3ca249fdf5 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <string.h>
-#include <math.h>
+//#include <math.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/io.h>
@@ -10,30 +10,28 @@
#include "eeconfig.h"
-#ifdef VIBRATO_ENABLE
- #include "vibrato_lut.h"
-#endif
+#define CPU_PRESCALER 8
-#define PI 3.14159265
+// -----------------------------------------------------------------------------
+// Timer Abstractions
+// -----------------------------------------------------------------------------
-#define CPU_PRESCALER 8
+// 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 PWM_AUDIO
- #include "wave.h"
- #define SAMPLE_DIVIDER 39
- #define SAMPLE_RATE (2000000.0/SAMPLE_DIVIDER/2048)
- // Resistor value of 1/ (2 * PI * 10nF * (2000000 hertz / SAMPLE_DIVIDER / 10)) for 10nF cap
+// 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));
- float places[8] = {0, 0, 0, 0, 0, 0, 0, 0};
- uint16_t place_int = 0;
- bool repeat = true;
-#endif
+// Fast PWM Mode Controls
+#define TIMER_3_PERIOD ICR3
+#define TIMER_3_DUTY_CYCLE OCR3A
+
+// -----------------------------------------------------------------------------
-void delay_us(int count) {
- while(count--) {
- _delay_us(1);
- }
-}
int voices = 0;
int voice_place = 0;
@@ -45,26 +43,23 @@ float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
bool sliding = false;
-int max = 0xFF;
-float sum = 0;
float place = 0;
uint8_t * sample;
uint16_t sample_length = 0;
-// float freq = 0;
-
-bool notes = false;
-bool note = false;
-float note_frequency = 0;
-float note_length = 0;
-float note_tempo = TEMPO_DEFAULT;
-float note_timbre = TIMBRE_DEFAULT;
+
+bool playing_notes = false;
+bool playing_note = false;
+float note_frequency = 0;
+float note_length = 0;
+uint8_t note_tempo = TEMPO_DEFAULT;
+float note_timbre = TIMBRE_DEFAULT;
uint16_t note_position = 0;
float (* notes_pointer)[][2];
uint16_t notes_count;
-bool notes_repeat;
-float notes_rest;
-bool note_resting = false;
+bool notes_repeat;
+float notes_rest;
+bool note_resting = false;
uint8_t current_note = 0;
uint8_t rest_counter = 0;
@@ -77,175 +72,65 @@ float vibrato_rate = 0.125;
float polyphony_rate = 0;
-bool inited = false;
+static bool audio_initialized = false;
audio_config_t audio_config;
uint16_t envelope_index = 0;
-void audio_toggle(void) {
- audio_config.enable ^= 1;
- eeconfig_update_audio(audio_config.raw);
-}
-
-void audio_on(void) {
- audio_config.enable = 1;
- eeconfig_update_audio(audio_config.raw);
-}
-
-void audio_off(void) {
- audio_config.enable = 0;
- eeconfig_update_audio(audio_config.raw);
-}
-
-#ifdef VIBRATO_ENABLE
-// Vibrato rate functions
-
-void set_vibrato_rate(float rate) {
- vibrato_rate = rate;
-}
-
-void increase_vibrato_rate(float change) {
- vibrato_rate *= change;
-}
-
-void decrease_vibrato_rate(float change) {
- vibrato_rate /= change;
-}
-
-#ifdef VIBRATO_STRENGTH_ENABLE
-
-void set_vibrato_strength(float strength) {
- vibrato_strength = strength;
-}
-
-void increase_vibrato_strength(float change) {
- vibrato_strength *= change;
-}
-
-void decrease_vibrato_strength(float change) {
- vibrato_strength /= change;
-}
-
-#endif
-
-#endif
-
-// Polyphony functions
-
-void set_polyphony_rate(float rate) {
- polyphony_rate = rate;
-}
-
-void enable_polyphony() {
- polyphony_rate = 5;
-}
-
-void disable_polyphony() {
- polyphony_rate = 0;
-}
-
-void increase_polyphony_rate(float change) {
- polyphony_rate *= change;
-}
-
-void decrease_polyphony_rate(float change) {
- polyphony_rate /= change;
-}
-
-// Timbre function
-
-void set_timbre(float timbre) {
- note_timbre = timbre;
-}
-
-// Tempo functions
-
-void set_tempo(float tempo) {
- note_tempo = tempo;
-}
-
-void decrease_tempo(uint8_t tempo_change) {
- note_tempo += (float) tempo_change;
-}
-
-void increase_tempo(uint8_t tempo_change) {
- if (note_tempo - (float) tempo_change < 10) {
- note_tempo = 10;
- } else {
- note_tempo -= (float) tempo_change;
- }
-}
-
-void audio_init() {
+void audio_init()
+{
- /* check signature */
- if (!eeconfig_is_enabled()) {
+ // Check EEPROM
+ if (!eeconfig_is_enabled())
+ {
eeconfig_init();
}
audio_config.raw = eeconfig_read_audio();
- #ifdef PWM_AUDIO
- PLLFRQ = _BV(PDIV2);
- PLLCSR = _BV(PLLE);
- while(!(PLLCSR & _BV(PLOCK)));
- PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */
+ // Set port PC6 (OC3A and /OC4A) as output
+ DDRC |= _BV(PORTC6);
- /* Init a fast PWM on Timer4 */
- TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */
- TCCR4B = _BV(CS40); /* No prescaling => f = PCK/256 = 187500Hz */
- OCR4A = 0;
+ DISABLE_AUDIO_COUNTER_3_ISR;
- /* Enable the OC4A output */
- DDRC |= _BV(PORTC6);
-
- TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs
-
- TCCR3A = 0x0; // Options not needed
- TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC
- OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback
- #else
- DDRC |= _BV(PORTC6);
+ // 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);
- TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs
-
- TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
- TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
- #endif
-
- inited = true;
+ audio_initialized = true;
}
-void stop_all_notes() {
- if (!inited) {
+void stop_all_notes()
+{
+ if (!audio_initialized) {
audio_init();
}
voices = 0;
- #ifdef PWM_AUDIO
- TIMSK3 &= ~_BV(OCIE3A);
- #else
- TIMSK3 &= ~_BV(OCIE3A);
- TCCR3A &= ~_BV(COM3A1);
- #endif
- notes = false;
- note = false;
+
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ DISABLE_AUDIO_COUNTER_3_OUTPUT;
+
+ playing_notes = false;
+ playing_note = false;
frequency = 0;
volume = 0;
- for (int i = 0; i < 8; i++) {
+ for (uint8_t i = 0; i < 8; i++)
+ {
frequencies[i] = 0;
volumes[i] = 0;
}
}
-void stop_note(float freq) {
- if (note) {
- if (!inited) {
+void stop_note(float freq)
+{
+ if (playing_note) {
+ if (!audio_initialized) {
audio_init();
}
- #ifdef PWM_AUDIO
- freq = freq / SAMPLE_RATE;
- #endif
for (int i = 7; i >= 0; i--) {
if (frequencies[i] == freq) {
frequencies[i] = 0;
@@ -266,15 +151,11 @@ void stop_note(float freq) {
voice_place = 0;
}
if (voices == 0) {
- #ifdef PWM_AUDIO
- TIMSK3 &= ~_BV(OCIE3A);
- #else
- TIMSK3 &= ~_BV(OCIE3A);
- TCCR3A &= ~_BV(COM3A1);
- #endif
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ DISABLE_AUDIO_COUNTER_3_OUTPUT;
frequency = 0;
volume = 0;
- note = false;
+ playing_note = false;
}
}
}
@@ -289,9 +170,9 @@ float mod(float a, int b)
float vibrato(float average_freq) {
#ifdef VIBRATO_STRENGTH_ENABLE
- float vibrated_freq = average_freq * pow(VIBRATO_LUT[(int)vibrato_counter], vibrato_strength);
+ float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
#else
- float vibrated_freq = average_freq * VIBRATO_LUT[(int)vibrato_counter];
+ 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;
@@ -299,309 +180,298 @@ float vibrato(float average_freq) {
#endif
-ISR(TIMER3_COMPA_vect) {
- if (note) {
- #ifdef PWM_AUDIO
- if (voices == 1) {
- // SINE
- OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
-
- // SQUARE
- // if (((int)place) >= 1024){
- // OCR4A = 0xFF >> 2;
- // } else {
- // OCR4A = 0x00;
- // }
-
- // SAWTOOTH
- // OCR4A = (int)place / 4;
-
- // TRIANGLE
- // if (((int)place) >= 1024) {
- // OCR4A = (int)place / 2;
- // } else {
- // OCR4A = 2048 - (int)place / 2;
- // }
-
- place += frequency;
-
- if (place >= SINE_LENGTH)
- place -= SINE_LENGTH;
-
- } else {
- int sum = 0;
- for (int i = 0; i < voices; i++) {
- // SINE
- sum += pgm_read_byte(&sinewave[(uint16_t)places[i]]) >> 2;
-
- // SQUARE
- // if (((int)places[i]) >= 1024){
- // sum += 0xFF >> 2;
- // } else {
- // sum += 0x00;
- // }
-
- places[i] += frequencies[i];
-
- if (places[i] >= SINE_LENGTH)
- places[i] -= SINE_LENGTH;
- }
- OCR4A = sum;
- }
- #else
- if (voices > 0) {
- float freq;
- 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 {
- #else
- {
- #endif
- freq = frequencies[voice_place];
- }
- } 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 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];
- }
-
-
- #ifdef VIBRATO_ENABLE
- if (vibrato_strength > 0) {
- freq = vibrato(frequency);
- } else {
- #else
- {
- #endif
- freq = frequency;
- }
- }
+ISR(TIMER3_COMPA_vect)
+{
+ float freq;
+
+ 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 (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];
+ }
+
+ #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_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+ TIMER_3_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_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+ TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
+ } else {
+ TIMER_3_PERIOD = 0;
+ TIMER_3_DUTY_CYCLE = 0;
+ }
+
+ note_position++;
+ bool end_of_note = false;
+ if (TIMER_3_PERIOD > 0) {
+ end_of_note = (note_position >= (note_length / TIMER_3_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_3_ISR;
+ DISABLE_AUDIO_COUNTER_3_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;
+ }
+}
- if (envelope_index < 65535) {
- envelope_index++;
- }
- freq = voice_envelope(freq);
+void play_note(float freq, int vol) {
- if (freq < 30.517578125)
- freq = 30.52;
- ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
- OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
- }
- #endif
+ if (!audio_initialized) {
+ audio_init();
}
- // SAMPLE
- // OCR4A = pgm_read_byte(&sample[(uint16_t)place_int]);
-
- // place_int++;
-
- // if (place_int >= sample_length)
- // if (repeat)
- // place_int -= sample_length;
- // else
- // TIMSK3 &= ~_BV(OCIE3A);
-
-
- if (notes) {
- #ifdef PWM_AUDIO
- OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 0;
-
- place += note_frequency;
- if (place >= SINE_LENGTH)
- place -= SINE_LENGTH;
- #else
- if (note_frequency > 0) {
- float freq;
-
- #ifdef VIBRATO_ENABLE
- if (vibrato_strength > 0) {
- freq = vibrato(note_frequency);
- } else {
- #else
- {
- #endif
- freq = note_frequency;
- }
+ if (audio_config.enable && voices < 8) {
+ DISABLE_AUDIO_COUNTER_3_ISR;
- if (envelope_index < 65535) {
- envelope_index++;
- }
- freq = voice_envelope(freq);
+ // Cancel notes if notes are playing
+ if (playing_notes)
+ stop_all_notes();
- ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
- OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
- } else {
- ICR3 = 0;
- OCR3A = 0;
- }
- #endif
-
-
- note_position++;
- bool end_of_note = false;
- if (ICR3 > 0)
- end_of_note = (note_position >= (note_length / ICR3 * 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 {
- #ifdef PWM_AUDIO
- TIMSK3 &= ~_BV(OCIE3A);
- #else
- TIMSK3 &= ~_BV(OCIE3A);
- TCCR3A &= ~_BV(COM3A1);
- #endif
- 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;
- #ifdef PWM_AUDIO
- note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
- note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
- #else
- envelope_index = 0;
- note_frequency = (*notes_pointer)[current_note][0];
- note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
- #endif
- }
- note_position = 0;
- }
+ playing_note = true;
- }
+ envelope_index = 0;
+
+ if (freq > 0) {
+ frequencies[voices] = freq;
+ volumes[voices] = vol;
+ voices++;
+ }
+
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ ENABLE_AUDIO_COUNTER_3_OUTPUT;
+ }
- if (!audio_config.enable) {
- notes = false;
- note = false;
- }
}
-void play_note(float freq, int vol) {
+void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
+{
- if (!inited) {
+ if (!audio_initialized) {
audio_init();
}
-if (audio_config.enable && voices < 8) {
- TIMSK3 &= ~_BV(OCIE3A);
- // Cancel notes if notes are playing
- if (notes)
- stop_all_notes();
- note = true;
- envelope_index = 0;
- #ifdef PWM_AUDIO
- freq = freq / SAMPLE_RATE;
- #endif
- if (freq > 0) {
- frequencies[voices] = freq;
- volumes[voices] = vol;
- voices++;
- }
+ if (audio_config.enable) {
+
+ DISABLE_AUDIO_COUNTER_3_ISR;
+
+ // Cancel note if a note is playing
+ if (playing_note)
+ stop_all_notes();
+
+ playing_notes = true;
+
+ notes_pointer = np;
+ notes_count = n_count;
+ notes_repeat = n_repeat;
+ notes_rest = n_rest;
+
+ 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;
+
+
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ ENABLE_AUDIO_COUNTER_3_OUTPUT;
+ }
- #ifdef PWM_AUDIO
- TIMSK3 |= _BV(OCIE3A);
- #else
- TIMSK3 |= _BV(OCIE3A);
- TCCR3A |= _BV(COM3A1);
- #endif
}
+bool is_playing_notes(void) {
+ return playing_notes;
}
-void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) {
+bool is_audio_on(void) {
+ return (audio_config.enable != 0);
+}
- if (!inited) {
- audio_init();
- }
+void audio_toggle(void) {
+ audio_config.enable ^= 1;
+ eeconfig_update_audio(audio_config.raw);
+ if (audio_config.enable)
+ audio_on_user();
+}
-if (audio_config.enable) {
- TIMSK3 &= ~_BV(OCIE3A);
- // Cancel note if a note is playing
- if (note)
- stop_all_notes();
- notes = true;
-
- notes_pointer = np;
- notes_count = n_count;
- notes_repeat = n_repeat;
- notes_rest = n_rest;
-
- place = 0;
- current_note = 0;
- #ifdef PWM_AUDIO
- note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
- note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
- #else
- note_frequency = (*notes_pointer)[current_note][0];
- note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
- #endif
- note_position = 0;
+void audio_on(void) {
+ 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);
+}
- #ifdef PWM_AUDIO
- TIMSK3 |= _BV(OCIE3A);
- #else
- TIMSK3 |= _BV(OCIE3A);
- TCCR3A |= _BV(COM3A1);
- #endif
+#ifdef VIBRATO_ENABLE
+
+// Vibrato rate functions
+
+void set_vibrato_rate(float rate) {
+ vibrato_rate = rate;
}
+void increase_vibrato_rate(float change) {
+ vibrato_rate *= change;
}
-#ifdef PWM_AUDIO
-void play_sample(uint8_t * s, uint16_t l, bool r) {
- if (!inited) {
- audio_init();
- }
+void decrease_vibrato_rate(float change) {
+ vibrato_rate /= change;
+}
- if (audio_config.enable) {
- TIMSK3 &= ~_BV(OCIE3A);
- stop_all_notes();
- place_int = 0;
- sample = s;
- sample_length = l;
- repeat = r;
+#ifdef VIBRATO_STRENGTH_ENABLE
- TIMSK3 |= _BV(OCIE3A);
- }
+void set_vibrato_strength(float strength) {
+ vibrato_strength = strength;
}
-#endif
-//------------------------------------------------------------------------------
-// Override these functions in your keymap file to play different tunes on
-// startup and bootloader jump
-__attribute__ ((weak))
-void play_startup_tone()
-{
+void increase_vibrato_strength(float change) {
+ vibrato_strength *= change;
}
+void decrease_vibrato_strength(float change) {
+ vibrato_strength /= change;
+}
+#endif /* VIBRATO_STRENGTH_ENABLE */
-__attribute__ ((weak))
-void play_goodbye_tone()
-{
+#endif /* VIBRATO_ENABLE */
+
+// Polyphony functions
+
+void set_polyphony_rate(float rate) {
+ polyphony_rate = rate;
+}
+void enable_polyphony() {
+ polyphony_rate = 5;
+}
+
+void disable_polyphony() {
+ polyphony_rate = 0;
+}
+
+void increase_polyphony_rate(float change) {
+ polyphony_rate *= change;
+}
+
+void decrease_polyphony_rate(float change) {
+ polyphony_rate /= change;
+}
+
+// Timbre function
+
+void set_timbre(float timbre) {
+ note_timbre = timbre;
+}
+
+// Tempo functions
+
+void set_tempo(uint8_t tempo) {
+ note_tempo = tempo;
+}
+
+void decrease_tempo(uint8_t 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;
+ }
}
-//------------------------------------------------------------------------------
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index 89769507e1..00d45f7ac1 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -5,6 +5,7 @@
#include "musical_notes.h"
#include "song_list.h"
#include "voices.h"
+#include "quantum.h"
#ifndef AUDIO_H
#define AUDIO_H
@@ -25,6 +26,7 @@ typedef union {
};
} audio_config_t;
+bool is_audio_on(void);
void audio_toggle(void);
void audio_on(void);
void audio_off(void);
@@ -56,7 +58,7 @@ void increase_polyphony_rate(float change);
void decrease_polyphony_rate(float change);
void set_timbre(float timbre);
-void set_tempo(float tempo);
+void set_tempo(uint8_t tempo);
void increase_tempo(uint8_t tempo_change);
void decrease_tempo(uint8_t tempo_change);
@@ -71,11 +73,11 @@ void stop_note(float freq);
void stop_all_notes(void);
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest);
-#define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
- 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
- 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
- 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
- 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
+#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
+ 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
+ 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
+ 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
+ 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
// These macros are used to allow play_notes to play an array of indeterminate
// length. This works around the limitation of C's sizeof operation on pointers.
@@ -83,7 +85,7 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
#define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
#define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style));
-void play_goodbye_tone(void);
-void play_startup_tone(void);
+
+bool is_playing_notes(void);
#endif \ No newline at end of file
diff --git a/quantum/audio/audio_pwm.c b/quantum/audio/audio_pwm.c
new file mode 100644
index 0000000000..328a253a7e
--- /dev/null
+++ b/quantum/audio/audio_pwm.c
@@ -0,0 +1,643 @@
+#include <stdio.h>
+#include <string.h>
+//#include <math.h>
+#include <avr/pgmspace.h>
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include "print.h"
+#include "audio.h"
+#include "keymap_common.h"
+
+#include "eeconfig.h"
+
+#define PI 3.14159265
+
+#define CPU_PRESCALER 8
+
+
+// Timer Abstractions
+
+// 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)
+
+
+// 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));
+
+
+#define NOTE_PERIOD ICR3
+#define NOTE_DUTY_CYCLE OCR3A
+
+
+#ifdef PWM_AUDIO
+ #include "wave.h"
+ #define SAMPLE_DIVIDER 39
+ #define SAMPLE_RATE (2000000.0/SAMPLE_DIVIDER/2048)
+ // Resistor value of 1/ (2 * PI * 10nF * (2000000 hertz / SAMPLE_DIVIDER / 10)) for 10nF cap
+
+ float places[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+ uint16_t place_int = 0;
+ bool repeat = true;
+#endif
+
+void delay_us(int count) {
+ while(count--) {
+ _delay_us(1);
+ }
+}
+
+int voices = 0;
+int voice_place = 0;
+float frequency = 0;
+int volume = 0;
+long position = 0;
+
+float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+bool sliding = false;
+
+float place = 0;
+
+uint8_t * sample;
+uint16_t sample_length = 0;
+// float freq = 0;
+
+bool playing_notes = false;
+bool playing_note = false;
+float note_frequency = 0;
+float note_length = 0;
+uint8_t note_tempo = TEMPO_DEFAULT;
+float note_timbre = TIMBRE_DEFAULT;
+uint16_t note_position = 0;
+float (* notes_pointer)[][2];
+uint16_t notes_count;
+bool notes_repeat;
+float notes_rest;
+bool note_resting = false;
+
+uint8_t current_note = 0;
+uint8_t rest_counter = 0;
+
+#ifdef VIBRATO_ENABLE
+float vibrato_counter = 0;
+float vibrato_strength = .5;
+float vibrato_rate = 0.125;
+#endif
+
+float polyphony_rate = 0;
+
+static bool audio_initialized = false;
+
+audio_config_t audio_config;
+
+uint16_t envelope_index = 0;
+
+void audio_init() {
+
+ // Check EEPROM
+ if (!eeconfig_is_enabled())
+ {
+ eeconfig_init();
+ }
+ audio_config.raw = eeconfig_read_audio();
+
+ #ifdef PWM_AUDIO
+
+ PLLFRQ = _BV(PDIV2);
+ PLLCSR = _BV(PLLE);
+ while(!(PLLCSR & _BV(PLOCK)));
+ PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */
+
+ /* Init a fast PWM on Timer4 */
+ TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */
+ TCCR4B = _BV(CS40); /* No prescaling => f = PCK/256 = 187500Hz */
+ OCR4A = 0;
+
+ /* Enable the OC4A output */
+ DDRC |= _BV(PORTC6);
+
+ DISABLE_AUDIO_COUNTER_3_ISR; // Turn off 3A interputs
+
+ TCCR3A = 0x0; // Options not needed
+ TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC
+ OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback
+
+ #else
+
+ // Set port PC6 (OC3A and /OC4A) as output
+ DDRC |= _BV(PORTC6);
+
+ DISABLE_AUDIO_COUNTER_3_ISR;
+
+ // 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);
+
+ #endif
+
+ audio_initialized = true;
+}
+
+void stop_all_notes() {
+ if (!audio_initialized) {
+ audio_init();
+ }
+ voices = 0;
+ #ifdef PWM_AUDIO
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ #else
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ DISABLE_AUDIO_COUNTER_3_OUTPUT;
+ #endif
+
+ playing_notes = false;
+ playing_note = false;
+ frequency = 0;
+ volume = 0;
+
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ frequencies[i] = 0;
+ volumes[i] = 0;
+ }
+}
+
+void stop_note(float freq)
+{
+ if (playing_note) {
+ if (!audio_initialized) {
+ audio_init();
+ }
+ #ifdef PWM_AUDIO
+ freq = freq / SAMPLE_RATE;
+ #endif
+ 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) {
+ #ifdef PWM_AUDIO
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ #else
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ DISABLE_AUDIO_COUNTER_3_OUTPUT;
+ #endif
+ frequency = 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 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;
+}
+
+#endif
+
+ISR(TIMER3_COMPA_vect)
+{
+ if (playing_note) {
+ #ifdef PWM_AUDIO
+ if (voices == 1) {
+ // SINE
+ OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
+
+ // SQUARE
+ // if (((int)place) >= 1024){
+ // OCR4A = 0xFF >> 2;
+ // } else {
+ // OCR4A = 0x00;
+ // }
+
+ // SAWTOOTH
+ // OCR4A = (int)place / 4;
+
+ // TRIANGLE
+ // if (((int)place) >= 1024) {
+ // OCR4A = (int)place / 2;
+ // } else {
+ // OCR4A = 2048 - (int)place / 2;
+ // }
+
+ place += frequency;
+
+ if (place >= SINE_LENGTH)
+ place -= SINE_LENGTH;
+
+ } else {
+ int sum = 0;
+ for (int i = 0; i < voices; i++) {
+ // SINE
+ sum += pgm_read_byte(&sinewave[(uint16_t)places[i]]) >> 2;
+
+ // SQUARE
+ // if (((int)places[i]) >= 1024){
+ // sum += 0xFF >> 2;
+ // } else {
+ // sum += 0x00;
+ // }
+
+ places[i] += frequencies[i];
+
+ if (places[i] >= SINE_LENGTH)
+ places[i] -= SINE_LENGTH;
+ }
+ OCR4A = sum;
+ }
+ #else
+ if (voices > 0) {
+ float freq;
+ 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 {
+ #else
+ {
+ #endif
+ freq = frequencies[voice_place];
+ }
+ } 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 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];
+ }
+
+
+ #ifdef VIBRATO_ENABLE
+ if (vibrato_strength > 0) {
+ freq = vibrato(frequency);
+ } else {
+ #else
+ {
+ #endif
+ freq = frequency;
+ }
+ }
+
+ if (envelope_index < 65535) {
+ envelope_index++;
+ }
+ freq = voice_envelope(freq);
+
+ if (freq < 30.517578125)
+ freq = 30.52;
+ NOTE_PERIOD = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
+ NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+ }
+ #endif
+ }
+
+ // SAMPLE
+ // OCR4A = pgm_read_byte(&sample[(uint16_t)place_int]);
+
+ // place_int++;
+
+ // if (place_int >= sample_length)
+ // if (repeat)
+ // place_int -= sample_length;
+ // else
+ // DISABLE_AUDIO_COUNTER_3_ISR;
+
+
+ if (playing_notes) {
+ #ifdef PWM_AUDIO
+ OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 0;
+
+ place += note_frequency;
+ if (place >= SINE_LENGTH)
+ place -= SINE_LENGTH;
+ #else
+ if (note_frequency > 0) {
+ float freq;
+
+ #ifdef VIBRATO_ENABLE
+ if (vibrato_strength > 0) {
+ freq = vibrato(note_frequency);
+ } else {
+ #else
+ {
+ #endif
+ freq = note_frequency;
+ }
+
+ if (envelope_index < 65535) {
+ envelope_index++;
+ }
+ freq = voice_envelope(freq);
+
+ NOTE_PERIOD = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
+ NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+ } else {
+ NOTE_PERIOD = 0;
+ NOTE_DUTY_CYCLE = 0;
+ }
+ #endif
+
+
+ note_position++;
+ bool end_of_note = false;
+ if (NOTE_PERIOD > 0)
+ end_of_note = (note_position >= (note_length / NOTE_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 {
+ #ifdef PWM_AUDIO
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ #else
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ DISABLE_AUDIO_COUNTER_3_OUTPUT;
+ #endif
+ 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;
+ #ifdef PWM_AUDIO
+ note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
+ note_length = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
+ #else
+ envelope_index = 0;
+ note_frequency = (*notes_pointer)[current_note][0];
+ note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+ #endif
+ }
+ note_position = 0;
+ }
+
+ }
+
+ if (!audio_config.enable) {
+ playing_notes = false;
+ playing_note = false;
+ }
+}
+
+void play_note(float freq, int vol) {
+
+ if (!audio_initialized) {
+ audio_init();
+ }
+
+ if (audio_config.enable && voices < 8) {
+ DISABLE_AUDIO_COUNTER_3_ISR;
+
+ // Cancel notes if notes are playing
+ if (playing_notes)
+ stop_all_notes();
+
+ playing_note = true;
+
+ envelope_index = 0;
+
+ #ifdef PWM_AUDIO
+ freq = freq / SAMPLE_RATE;
+ #endif
+ if (freq > 0) {
+ frequencies[voices] = freq;
+ volumes[voices] = vol;
+ voices++;
+ }
+
+ #ifdef PWM_AUDIO
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ #else
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ ENABLE_AUDIO_COUNTER_3_OUTPUT;
+ #endif
+ }
+
+}
+
+void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
+{
+
+ if (!audio_initialized) {
+ audio_init();
+ }
+
+ if (audio_config.enable) {
+
+ DISABLE_AUDIO_COUNTER_3_ISR;
+
+ // Cancel note if a note is playing
+ if (playing_note)
+ stop_all_notes();
+
+ playing_notes = true;
+
+ notes_pointer = np;
+ notes_count = n_count;
+ notes_repeat = n_repeat;
+ notes_rest = n_rest;
+
+ place = 0;
+ current_note = 0;
+
+ #ifdef PWM_AUDIO
+ note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
+ note_length = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
+ #else
+ note_frequency = (*notes_pointer)[current_note][0];
+ note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+ #endif
+ note_position = 0;
+
+
+ #ifdef PWM_AUDIO
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ #else
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ ENABLE_AUDIO_COUNTER_3_OUTPUT;
+ #endif
+ }
+
+}
+
+#ifdef PWM_AUDIO
+void play_sample(uint8_t * s, uint16_t l, bool r) {
+ if (!audio_initialized) {
+ audio_init();
+ }
+
+ if (audio_config.enable) {
+ DISABLE_AUDIO_COUNTER_3_ISR;
+ stop_all_notes();
+ place_int = 0;
+ sample = s;
+ sample_length = l;
+ repeat = r;
+
+ ENABLE_AUDIO_COUNTER_3_ISR;
+ }
+}
+#endif
+
+
+void audio_toggle(void) {
+ audio_config.enable ^= 1;
+ eeconfig_update_audio(audio_config.raw);
+}
+
+void audio_on(void) {
+ audio_config.enable = 1;
+ eeconfig_update_audio(audio_config.raw);
+}
+
+void audio_off(void) {
+ audio_config.enable = 0;
+ eeconfig_update_audio(audio_config.raw);
+}
+
+#ifdef VIBRATO_ENABLE
+
+// Vibrato rate functions
+
+void set_vibrato_rate(float rate) {
+ vibrato_rate = rate;
+}
+
+void increase_vibrato_rate(float change) {
+ vibrato_rate *= change;
+}
+
+void decrease_vibrato_rate(float change) {
+ vibrato_rate /= change;
+}
+
+#ifdef VIBRATO_STRENGTH_ENABLE
+
+void set_vibrato_strength(float strength) {
+ vibrato_strength = strength;
+}
+
+void increase_vibrato_strength(float change) {
+ vibrato_strength *= change;
+}
+
+void decrease_vibrato_strength(float change) {
+ vibrato_strength /= change;
+}
+
+#endif /* VIBRATO_STRENGTH_ENABLE */
+
+#endif /* VIBRATO_ENABLE */
+
+// Polyphony functions
+
+void set_polyphony_rate(float rate) {
+ polyphony_rate = rate;
+}
+
+void enable_polyphony() {
+ polyphony_rate = 5;
+}
+
+void disable_polyphony() {
+ polyphony_rate = 0;
+}
+
+void increase_polyphony_rate(float change) {
+ polyphony_rate *= change;
+}
+
+void decrease_polyphony_rate(float change) {
+ polyphony_rate /= change;
+}
+
+// Timbre function
+
+void set_timbre(float timbre) {
+ note_timbre = timbre;
+}
+
+// Tempo functions
+
+void set_tempo(uint8_t tempo) {
+ note_tempo = tempo;
+}
+
+void decrease_tempo(uint8_t 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;
+ }
+}
+
+
+//------------------------------------------------------------------------------
+// Override these functions in your keymap file to play different tunes on
+// startup and bootloader jump
+__attribute__ ((weak))
+void play_startup_tone()
+{
+}
+
+__attribute__ ((weak))
+void play_goodbye_tone()
+{
+}
+//------------------------------------------------------------------------------
diff --git a/quantum/audio/frequency_lut.h b/quantum/audio/frequency_lut.h
deleted file mode 100644
index e62da5be4e..0000000000
--- a/quantum/audio/frequency_lut.h
+++ /dev/null
@@ -1,357 +0,0 @@
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <avr/pgmspace.h>
-
-#define FREQUENCY_LUT_LENGTH 349
-
-const uint16_t FREQUENCY_LUT[FREQUENCY_LUT_LENGTH] = {
-0x8E0B,
-0x8C02,
-0x8A00,
-0x8805,
-0x8612,
-0x8426,
-0x8241,
-0x8063,
-0x7E8C,
-0x7CBB,
-0x7AF2,
-0x792E,
-0x7772,
-0x75BB,
-0x740B,
-0x7261,
-0x70BD,
-0x6F20,
-0x6D88,
-0x6BF6,
-0x6A69,
-0x68E3,
-0x6762,
-0x65E6,
-0x6470,
-0x6300,
-0x6194,
-0x602E,
-0x5ECD,
-0x5D71,
-0x5C1A,
-0x5AC8,
-0x597B,
-0x5833,
-0x56EF,
-0x55B0,
-0x5475,
-0x533F,
-0x520E,
-0x50E1,
-0x4FB8,
-0x4E93,
-0x4D73,
-0x4C57,
-0x4B3E,
-0x4A2A,
-0x491A,
-0x480E,
-0x4705,
-0x4601,
-0x4500,
-0x4402,
-0x4309,
-0x4213,
-0x4120,
-0x4031,
-0x3F46,
-0x3E5D,
-0x3D79,
-0x3C97,
-0x3BB9,
-0x3ADD,
-0x3A05,
-0x3930,
-0x385E,
-0x3790,
-0x36C4,
-0x35FB,
-0x3534,
-0x3471,
-0x33B1,
-0x32F3,
-0x3238,
-0x3180,
-0x30CA,
-0x3017,
-0x2F66,
-0x2EB8,
-0x2E0D,
-0x2D64,
-0x2CBD,
-0x2C19,
-0x2B77,
-0x2AD8,
-0x2A3A,
-0x299F,
-0x2907,
-0x2870,
-0x27DC,
-0x2749,
-0x26B9,
-0x262B,
-0x259F,
-0x2515,
-0x248D,
-0x2407,
-0x2382,
-0x2300,
-0x2280,
-0x2201,
-0x2184,
-0x2109,
-0x2090,
-0x2018,
-0x1FA3,
-0x1F2E,
-0x1EBC,
-0x1E4B,
-0x1DDC,
-0x1D6E,
-0x1D02,
-0x1C98,
-0x1C2F,
-0x1BC8,
-0x1B62,
-0x1AFD,
-0x1A9A,
-0x1A38,
-0x19D8,
-0x1979,
-0x191C,
-0x18C0,
-0x1865,
-0x180B,
-0x17B3,
-0x175C,
-0x1706,
-0x16B2,
-0x165E,
-0x160C,
-0x15BB,
-0x156C,
-0x151D,
-0x14CF,
-0x1483,
-0x1438,
-0x13EE,
-0x13A4,
-0x135C,
-0x1315,
-0x12CF,
-0x128A,
-0x1246,
-0x1203,
-0x11C1,
-0x1180,
-0x1140,
-0x1100,
-0x10C2,
-0x1084,
-0x1048,
-0x100C,
-0xFD1,
-0xF97,
-0xF5E,
-0xF25,
-0xEEE,
-0xEB7,
-0xE81,
-0xE4C,
-0xE17,
-0xDE4,
-0xDB1,
-0xD7E,
-0xD4D,
-0xD1C,
-0xCEC,
-0xCBC,
-0xC8E,
-0xC60,
-0xC32,
-0xC05,
-0xBD9,
-0xBAE,
-0xB83,
-0xB59,
-0xB2F,
-0xB06,
-0xADD,
-0xAB6,
-0xA8E,
-0xA67,
-0xA41,
-0xA1C,
-0x9F7,
-0x9D2,
-0x9AE,
-0x98A,
-0x967,
-0x945,
-0x923,
-0x901,
-0x8E0,
-0x8C0,
-0x8A0,
-0x880,
-0x861,
-0x842,
-0x824,
-0x806,
-0x7E8,
-0x7CB,
-0x7AF,
-0x792,
-0x777,
-0x75B,
-0x740,
-0x726,
-0x70B,
-0x6F2,
-0x6D8,
-0x6BF,
-0x6A6,
-0x68E,
-0x676,
-0x65E,
-0x647,
-0x630,
-0x619,
-0x602,
-0x5EC,
-0x5D7,
-0x5C1,
-0x5AC,
-0x597,
-0x583,
-0x56E,
-0x55B,
-0x547,
-0x533,
-0x520,
-0x50E,
-0x4FB,
-0x4E9,
-0x4D7,
-0x4C5,
-0x4B3,
-0x4A2,
-0x491,
-0x480,
-0x470,
-0x460,
-0x450,
-0x440,
-0x430,
-0x421,
-0x412,
-0x403,
-0x3F4,
-0x3E5,
-0x3D7,
-0x3C9,
-0x3BB,
-0x3AD,
-0x3A0,
-0x393,
-0x385,
-0x379,
-0x36C,
-0x35F,
-0x353,
-0x347,
-0x33B,
-0x32F,
-0x323,
-0x318,
-0x30C,
-0x301,
-0x2F6,
-0x2EB,
-0x2E0,
-0x2D6,
-0x2CB,
-0x2C1,
-0x2B7,
-0x2AD,
-0x2A3,
-0x299,
-0x290,
-0x287,
-0x27D,
-0x274,
-0x26B,
-0x262,
-0x259,
-0x251,
-0x248,
-0x240,
-0x238,
-0x230,
-0x228,
-0x220,
-0x218,
-0x210,
-0x209,
-0x201,
-0x1FA,
-0x1F2,
-0x1EB,
-0x1E4,
-0x1DD,
-0x1D6,
-0x1D0,
-0x1C9,
-0x1C2,
-0x1BC,
-0x1B6,
-0x1AF,
-0x1A9,
-0x1A3,
-0x19D,
-0x197,
-0x191,
-0x18C,
-0x186,
-0x180,
-0x17B,
-0x175,
-0x170,
-0x16B,
-0x165,
-0x160,
-0x15B,
-0x156,
-0x151,
-0x14C,
-0x148,
-0x143,
-0x13E,
-0x13A,
-0x135,
-0x131,
-0x12C,
-0x128,
-0x124,
-0x120,
-0x11C,
-0x118,
-0x114,
-0x110,
-0x10C,
-0x108,
-0x104,
-0x100,
-0xFD,
-0xF9,
-0xF5,
-0xF2,
-0xEE
-}; \ No newline at end of file
diff --git a/quantum/audio/luts.c b/quantum/audio/luts.c
new file mode 100644
index 0000000000..9f3de9a05c
--- /dev/null
+++ b/quantum/audio/luts.c
@@ -0,0 +1,382 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include "luts.h"
+
+const float vibrato_lut[VIBRATO_LUT_LENGTH] =
+{
+ 1.0022336811487,
+ 1.0042529943610,
+ 1.0058584256028,
+ 1.0068905285205,
+ 1.0072464122237,
+ 1.0068905285205,
+ 1.0058584256028,
+ 1.0042529943610,
+ 1.0022336811487,
+ 1.0000000000000,
+ 0.9977712970630,
+ 0.9957650169978,
+ 0.9941756956510,
+ 0.9931566259436,
+ 0.9928057204913,
+ 0.9931566259436,
+ 0.9941756956510,
+ 0.9957650169978,
+ 0.9977712970630,
+ 1.0000000000000,
+};
+
+const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH] =
+{
+ 0x8E0B,
+ 0x8C02,
+ 0x8A00,
+ 0x8805,
+ 0x8612,
+ 0x8426,
+ 0x8241,
+ 0x8063,
+ 0x7E8C,
+ 0x7CBB,
+ 0x7AF2,
+ 0x792E,
+ 0x7772,
+ 0x75BB,
+ 0x740B,
+ 0x7261,
+ 0x70BD,
+ 0x6F20,
+ 0x6D88,
+ 0x6BF6,
+ 0x6A69,
+ 0x68E3,
+ 0x6762,
+ 0x65E6,
+ 0x6470,
+ 0x6300,
+ 0x6194,
+ 0x602E,
+ 0x5ECD,
+ 0x5D71,
+ 0x5C1A,
+ 0x5AC8,
+ 0x597B,
+ 0x5833,
+ 0x56EF,
+ 0x55B0,
+ 0x5475,
+ 0x533F,
+ 0x520E,
+ 0x50E1,
+ 0x4FB8,
+ 0x4E93,
+ 0x4D73,
+ 0x4C57,
+ 0x4B3E,
+ 0x4A2A,
+ 0x491A,
+ 0x480E,
+ 0x4705,
+ 0x4601,
+ 0x4500,
+ 0x4402,
+ 0x4309,
+ 0x4213,
+ 0x4120,
+ 0x4031,
+ 0x3F46,
+ 0x3E5D,
+ 0x3D79,
+ 0x3C97,
+ 0x3BB9,
+ 0x3ADD,
+ 0x3A05,
+ 0x3930,
+ 0x385E,
+ 0x3790,
+ 0x36C4,
+ 0x35FB,
+ 0x3534,
+ 0x3471,
+ 0x33B1,
+ 0x32F3,
+ 0x3238,
+ 0x3180,
+ 0x30CA,
+ 0x3017,
+ 0x2F66,
+ 0x2EB8,
+ 0x2E0D,
+ 0x2D64,
+ 0x2CBD,
+ 0x2C19,
+ 0x2B77,
+ 0x2AD8,
+ 0x2A3A,
+ 0x299F,
+ 0x2907,
+ 0x2870,
+ 0x27DC,
+ 0x2749,
+ 0x26B9,
+ 0x262B,
+ 0x259F,
+ 0x2515,
+ 0x248D,
+ 0x2407,
+ 0x2382,
+ 0x2300,
+ 0x2280,
+ 0x2201,
+ 0x2184,
+ 0x2109,
+ 0x2090,
+ 0x2018,
+ 0x1FA3,
+ 0x1F2E,
+ 0x1EBC,
+ 0x1E4B,
+ 0x1DDC,
+ 0x1D6E,
+ 0x1D02,
+ 0x1C98,
+ 0x1C2F,
+ 0x1BC8,
+ 0x1B62,
+ 0x1AFD,
+ 0x1A9A,
+ 0x1A38,
+ 0x19D8,
+ 0x1979,
+ 0x191C,
+ 0x18C0,
+ 0x1865,
+ 0x180B,
+ 0x17B3,
+ 0x175C,
+ 0x1706,
+ 0x16B2,
+ 0x165E,
+ 0x160C,
+ 0x15BB,
+ 0x156C,
+ 0x151D,
+ 0x14CF,
+ 0x1483,
+ 0x1438,
+ 0x13EE,
+ 0x13A4,
+ 0x135C,
+ 0x1315,
+ 0x12CF,
+ 0x128A,
+ 0x1246,
+ 0x1203,
+ 0x11C1,
+ 0x1180,
+ 0x1140,
+ 0x1100,
+ 0x10C2,
+ 0x1084,
+ 0x1048,
+ 0x100C,
+ 0xFD1,
+ 0xF97,
+ 0xF5E,
+ 0xF25,
+ 0xEEE,
+ 0xEB7,
+ 0xE81,
+ 0xE4C,
+ 0xE17,
+ 0xDE4,
+ 0xDB1,
+ 0xD7E,
+ 0xD4D,
+ 0xD1C,
+ 0xCEC,
+ 0xCBC,
+ 0xC8E,
+ 0xC60,
+ 0xC32,
+ 0xC05,
+ 0xBD9,
+ 0xBAE,
+ 0xB83,
+ 0xB59,
+ 0xB2F,
+ 0xB06,
+ 0xADD,
+ 0xAB6,
+ 0xA8E,
+ 0xA67,
+ 0xA41,
+ 0xA1C,
+ 0x9F7,
+ 0x9D2,
+ 0x9AE,
+ 0x98A,
+ 0x967,
+ 0x945,
+ 0x923,
+ 0x901,
+ 0x8E0,
+ 0x8C0,
+ 0x8A0,
+ 0x880,
+ 0x861,
+ 0x842,
+ 0x824,
+ 0x806,
+ 0x7E8,
+ 0x7CB,
+ 0x7AF,
+ 0x792,
+ 0x777,
+ 0x75B,
+ 0x740,
+ 0x726,
+ 0x70B,
+ 0x6F2,
+ 0x6D8,
+ 0x6BF,
+ 0x6A6,
+ 0x68E,
+ 0x676,
+ 0x65E,
+ 0x647,
+ 0x630,
+ 0x619,
+ 0x602,
+ 0x5EC,
+ 0x5D7,
+ 0x5C1,
+ 0x5AC,
+ 0x597,
+ 0x583,
+ 0x56E,
+ 0x55B,
+ 0x547,
+ 0x533,
+ 0x520,
+ 0x50E,
+ 0x4FB,
+ 0x4E9,
+ 0x4D7,
+ 0x4C5,
+ 0x4B3,
+ 0x4A2,
+ 0x491,
+ 0x480,
+ 0x470,
+ 0x460,
+ 0x450,
+ 0x440,
+ 0x430,
+ 0x421,
+ 0x412,
+ 0x403,
+ 0x3F4,
+ 0x3E5,
+ 0x3D7,
+ 0x3C9,
+ 0x3BB,
+ 0x3AD,
+ 0x3A0,
+ 0x393,
+ 0x385,
+ 0x379,
+ 0x36C,
+ 0x35F,
+ 0x353,
+ 0x347,
+ 0x33B,
+ 0x32F,
+ 0x323,
+ 0x318,
+ 0x30C,
+ 0x301,
+ 0x2F6,
+ 0x2EB,
+ 0x2E0,
+ 0x2D6,
+ 0x2CB,
+ 0x2C1,
+ 0x2B7,
+ 0x2AD,
+ 0x2A3,
+ 0x299,
+ 0x290,
+ 0x287,
+ 0x27D,
+ 0x274,
+ 0x26B,
+ 0x262,
+ 0x259,
+ 0x251,
+ 0x248,
+ 0x240,
+ 0x238,
+ 0x230,
+ 0x228,
+ 0x220,
+ 0x218,
+ 0x210,
+ 0x209,
+ 0x201,
+ 0x1FA,
+ 0x1F2,
+ 0x1EB,
+ 0x1E4,
+ 0x1DD,
+ 0x1D6,
+ 0x1D0,
+ 0x1C9,
+ 0x1C2,
+ 0x1BC,
+ 0x1B6,
+ 0x1AF,
+ 0x1A9,
+ 0x1A3,
+ 0x19D,
+ 0x197,
+ 0x191,
+ 0x18C,
+ 0x186,
+ 0x180,
+ 0x17B,
+ 0x175,
+ 0x170,
+ 0x16B,
+ 0x165,
+ 0x160,
+ 0x15B,
+ 0x156,
+ 0x151,
+ 0x14C,
+ 0x148,
+ 0x143,
+ 0x13E,
+ 0x13A,
+ 0x135,
+ 0x131,
+ 0x12C,
+ 0x128,
+ 0x124,
+ 0x120,
+ 0x11C,
+ 0x118,
+ 0x114,
+ 0x110,
+ 0x10C,
+ 0x108,
+ 0x104,
+ 0x100,
+ 0xFD,
+ 0xF9,
+ 0xF5,
+ 0xF2,
+ 0xEE,
+};
+
diff --git a/quantum/audio/luts.h b/quantum/audio/luts.h
new file mode 100644
index 0000000000..7df3078a7f
--- /dev/null
+++ b/quantum/audio/luts.h
@@ -0,0 +1,15 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+
+#ifndef LUTS_H
+#define LUTS_H
+
+#define VIBRATO_LUT_LENGTH 20
+
+#define FREQUENCY_LUT_LENGTH 349
+
+extern const float vibrato_lut[VIBRATO_LUT_LENGTH];
+extern const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH];
+
+#endif /* LUTS_H */ \ No newline at end of file
diff --git a/quantum/audio/vibrato_lut.h b/quantum/audio/vibrato_lut.h
deleted file mode 100644
index a2b1f3e5ce..0000000000
--- a/quantum/audio/vibrato_lut.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <avr/pgmspace.h>
-
-#define VIBRATO_LUT_LENGTH 20
-
-const float VIBRATO_LUT[VIBRATO_LUT_LENGTH] = { \
-1.00223368114872,
-1.00425299436105,
-1.00585842560279,
-1.00689052852052,
-1.0072464122237,
-1.00689052852052,
-1.00585842560279,
-1.00425299436105,
-1.00223368114872,
-1,
-0.99777129706302,
-0.99576501699778,
-0.994175695650927,
-0.993156625943589,
-0.992805720491269,
-0.993156625943589,
-0.994175695650927,
-0.99576501699778,
-0.99777129706302,
-1
-}; \ No newline at end of file
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c
index 0921bd5931..6d4172a06c 100644
--- a/quantum/audio/voices.c
+++ b/quantum/audio/voices.c
@@ -1,6 +1,6 @@
#include "voices.h"
+#include "audio.h"
#include "stdlib.h"
-#include "vibrato_lut.h"
// these are imported from audio.c
extern uint16_t envelope_index;
@@ -54,28 +54,28 @@ float voice_envelope(float frequency) {
}
break;
- case octave_crunch:
- polyphony_rate = 0;
- switch (compensated_index) {
- case 0 ... 9:
- case 20 ... 24:
- case 30 ... 32:
- frequency = frequency / 2;
- note_timbre = TIMBRE_12;
- break;
-
- case 10 ... 19:
- case 25 ... 29:
- case 33 ... 35:
- frequency = frequency * 2;
- note_timbre = TIMBRE_12;
- break;
+ // case octave_crunch:
+ // polyphony_rate = 0;
+ // switch (compensated_index) {
+ // case 0 ... 9:
+ // case 20 ... 24:
+ // case 30 ... 32:
+ // frequency = frequency / 2;
+ // note_timbre = TIMBRE_12;
+ // break;
+
+ // case 10 ... 19:
+ // case 25 ... 29:
+ // case 33 ... 35:
+ // frequency = frequency * 2;
+ // note_timbre = TIMBRE_12;
+ // break;
- default:
- note_timbre = TIMBRE_12;
- break;
- }
- break;
+ // default:
+ // note_timbre = TIMBRE_12;
+ // break;
+ // }
+ // break;
case duty_osc:
// This slows the loop down a substantial amount, so higher notes may freeze
@@ -109,7 +109,7 @@ float voice_envelope(float frequency) {
case 0 ... VOICE_VIBRATO_DELAY:
break;
default:
- frequency = frequency * VIBRATO_LUT[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
+ frequency = frequency * vibrato_lut[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
break;
}
break;
@@ -160,4 +160,6 @@ float voice_envelope(float frequency) {
}
return frequency;
-} \ No newline at end of file
+}
+
+
diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h
index 74c873f42f..b2495b23b5 100644
--- a/quantum/audio/voices.h
+++ b/quantum/audio/voices.h
@@ -2,8 +2,7 @@
#include <stdbool.h>
#include <avr/io.h>
#include <util/delay.h>
-#include "musical_notes.h"
-#include "song_list.h"
+#include "luts.h"
#ifndef VOICES_H
#define VOICES_H
diff --git a/quantum/config_common.h b/quantum/config_common.h
index da53fce89b..02f11d979c 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -1,70 +1,74 @@
#ifndef CONFIG_DEFINITIONS_H
#define CONFIG_DEFINITIONS_H
-#define B0 0x20
-#define B1 0x21
-#define B2 0x22
-#define B3 0x23
-#define B4 0x24
-#define B5 0x25
-#define B6 0x26
-#define B7 0x27
-#define C0 0x30
-#define C1 0x31
-#define C2 0x32
-#define C3 0x33
-#define C4 0x34
-#define C5 0x35
-#define C6 0x36
-#define C7 0x37
-#define D0 0x40
-#define D1 0x41
-#define D2 0x42
-#define D3 0x43
-#define D4 0x44
-#define D5 0x45
-#define D6 0x46
-#define D7 0x47
-#define E0 0x50
-#define E1 0x51
-#define E2 0x52
-#define E3 0x53
-#define E4 0x54
-#define E5 0x55
-#define E6 0x56
-#define E7 0x57
-#define F0 0x60
-#define F1 0x61
-#define F2 0x62
-#define F3 0x63
-#define F4 0x64
-#define F5 0x65
-#define F6 0x66
-#define F7 0x67
-
-#define COL2ROW 0x0
-#define ROW2COL 0x1
+/* diode directions */
+#define COL2ROW 0
+#define ROW2COL 1
+/* I/O pins */
+#define B0 { .input_addr = 3, .bit = 0 }
+#define B1 { .input_addr = 3, .bit = 1 }
+#define B2 { .input_addr = 3, .bit = 2 }
+#define B3 { .input_addr = 3, .bit = 3 }
+#define B4 { .input_addr = 3, .bit = 4 }
+#define B5 { .input_addr = 3, .bit = 5 }
+#define B6 { .input_addr = 3, .bit = 6 }
+#define B7 { .input_addr = 3, .bit = 7 }
+#define C0 { .input_addr = 6, .bit = 0 }
+#define C1 { .input_addr = 6, .bit = 1 }
+#define C2 { .input_addr = 6, .bit = 2 }
+#define C3 { .input_addr = 6, .bit = 3 }
+#define C4 { .input_addr = 6, .bit = 4 }
+#define C5 { .input_addr = 6, .bit = 5 }
+#define C6 { .input_addr = 6, .bit = 6 }
+#define C7 { .input_addr = 6, .bit = 7 }
+#define D0 { .input_addr = 9, .bit = 0 }
+#define D1 { .input_addr = 9, .bit = 1 }
+#define D2 { .input_addr = 9, .bit = 2 }
+#define D3 { .input_addr = 9, .bit = 3 }
+#define D4 { .input_addr = 9, .bit = 4 }
+#define D5 { .input_addr = 9, .bit = 5 }
+#define D6 { .input_addr = 9, .bit = 6 }
+#define D7 { .input_addr = 9, .bit = 7 }
+#define E0 { .input_addr = 0xC, .bit = 0 }
+#define E1 { .input_addr = 0xC, .bit = 1 }
+#define E2 { .input_addr = 0xC, .bit = 2 }
+#define E3 { .input_addr = 0xC, .bit = 3 }
+#define E4 { .input_addr = 0xC, .bit = 4 }
+#define E5 { .input_addr = 0xC, .bit = 5 }
+#define E6 { .input_addr = 0xC, .bit = 6 }
+#define E7 { .input_addr = 0xC, .bit = 7 }
+#define F0 { .input_addr = 0xF, .bit = 0 }
+#define F1 { .input_addr = 0xF, .bit = 1 }
+#define F2 { .input_addr = 0xF, .bit = 2 }
+#define F3 { .input_addr = 0xF, .bit = 3 }
+#define F4 { .input_addr = 0xF, .bit = 4 }
+#define F5 { .input_addr = 0xF, .bit = 5 }
+#define F6 { .input_addr = 0xF, .bit = 6 }
+#define F7 { .input_addr = 0xF, .bit = 7 }
+/* USART configuration */
#ifdef BLUETOOTH_ENABLE
-#ifdef __AVR_ATmega32U4__
- #define SERIAL_UART_BAUD 9600
- #define SERIAL_UART_DATA UDR1
- #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
- #define SERIAL_UART_RXD_VECT USART1_RX_vect
- #define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
- #define SERIAL_UART_INIT() do { \
- UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \
- UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \
- UCSR1B = (1<<TXEN1); /* TX: enable */ \
- UCSR1C = (0<<UPM11) | (0<<UPM10) | /* parity: none(00), even(01), odd(11) */ \
- (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10); /* data-8bit(011) */ \
- sei(); \
- } while(0)
-#else
-# error "USART configuration is needed."
+# ifdef __AVR_ATmega32U4__
+# define SERIAL_UART_BAUD 9600
+# define SERIAL_UART_DATA UDR1
+# define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
+# define SERIAL_UART_RXD_VECT USART1_RX_vect
+# define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
+# define SERIAL_UART_INIT() do { \
+ /* baud rate */ \
+ UBRR1L = SERIAL_UART_UBRR; \
+ /* baud rate */ \
+ UBRR1H = SERIAL_UART_UBRR >> 8; \
+ /* enable TX */ \
+ UCSR1B = _BV(TXEN1); \
+ /* 8-bit data */ \
+ UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
+ sei(); \
+ } while(0)
+# else
+# error "USART configuration is needed."
#endif
-
// I'm fairly sure these aren't needed, but oh well - Jack
/*
@@ -113,4 +117,3 @@
#endif
#endif
-
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 4b4bd62109..ba7269388b 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -24,9 +24,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action_macro.h"
#include "debug.h"
#include "backlight.h"
-#include "keymap_midi.h"
#include "bootloader.h"
#include "eeconfig.h"
+#include "quantum.h"
+
+#ifdef MIDI_ENABLE
+ #include "keymap_midi.h"
+#endif
extern keymap_config_t keymap_config;
@@ -150,20 +154,22 @@ static action_t keycode_to_action(uint16_t keycode)
case KC_TRNS:
action.code = ACTION_TRANSPARENT;
break;
- case 0x0100 ... 0x1FFF: ;
+ case LCTL(0) ... 0x1FFF: ;
// Has a modifier
// Split it up
action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
break;
- case 0x2000 ... 0x2FFF:
+ case FUNC(0) ... FUNC(0xFFF): ;
// Is a shortcut for function layer, pull last 12bits
// This means we have 4,096 FN macros at our disposal
return keymap_func_to_action(keycode & 0xFFF);
break;
- case 0x3000 ... 0x3FFF: ;
- // When the code starts with 3, it's an action macro.
+ case M(0) ... M(0xFF):
action.code = ACTION_MACRO(keycode & 0xFF);
break;
+ case LT(0, 0) ... LT(0xFF, 0xF):
+ action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
+ break;
#ifdef BACKLIGHT_ENABLE
case BL_0 ... BL_15:
action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
@@ -185,7 +191,7 @@ static action_t keycode_to_action(uint16_t keycode)
clear_keyboard();
#ifdef AUDIO_ENABLE
stop_all_notes();
- play_goodbye_tone();
+ shutdown_user();
#endif
_delay_ms(250);
#ifdef ATREUS_ASTAR
@@ -197,7 +203,7 @@ static action_t keycode_to_action(uint16_t keycode)
print("\nDEBUG: enabled.\n");
debug_enable = true;
break;
- case 0x5002 ... 0x50FF:
+ case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
// MAGIC actions (BOOTMAGIC without the boot)
if (!eeconfig_is_enabled()) {
eeconfig_init();
@@ -247,7 +253,7 @@ static action_t keycode_to_action(uint16_t keycode)
}
eeconfig_update_keymap(keymap_config.raw);
break;
- case 0x5100 ... 0x5FFF: ;
+ case TO(0, 1) ... OSM(0xFF): ;
// Layer movement shortcuts
// See .h to see constraints/usage
int type = (keycode >> 0x8) & 0xF;
@@ -268,25 +274,19 @@ static action_t keycode_to_action(uint16_t keycode)
// Set default layer
int layer = keycode & 0xFF;
action.code = ACTION_LAYER_TOGGLE(layer);
+ } else if (type == 0x5) {
+ // OSL(layer) - One-shot layer
+ int layer = keycode & 0xFF;
+ action.code = ACTION_LAYER_ONESHOT(layer);
+ } else if (type == 0x6) {
+ // OSM(mod) - One-shot mod
+ int mod = keycode & 0xFF;
+ action.code = ACTION_MODS_ONESHOT(mod);
}
break;
- #ifdef MIDI_ENABLE
- case 0x6000 ... 0x6FFF:
- action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
- break;
- #endif
- case 0x7000 ... 0x7FFF:
+ case MT(0, 0) ... MT(0xF, 0xFF):
action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
break;
- case 0x8000 ... 0x8FFF:
- action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
- break;
- #ifdef UNICODE_ENABLE
- case 0x8000000 ... 0x8FFFFFF:
- uint16_t unicode = keycode & ~(0x8000);
- action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
- break;
- #endif
default:
action.code = ACTION_NO;
break;
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 0ede0296b9..91d5c09c1c 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -67,6 +67,9 @@ extern const uint16_t fn_actions[];
#define MEH(kc) kc | 0x0700
#define LCAG(kc) kc | 0x0D00 // Modifier Ctrl Alt and GUI
+#define MOD_HYPR 0xf
+#define MOD_MEH 0x7
+
#define RCTL(kc) kc | 0x1100
#define RSFT(kc) kc | 0x1200
#define RALT(kc) kc | 0x1400
@@ -84,8 +87,11 @@ extern const uint16_t fn_actions[];
#define KC_EXCLAIM KC_EXLM
#define KC_AT LSFT(KC_2) // @
+
+
#define KC_HASH LSFT(KC_3) // #
+
#define KC_DLR LSFT(KC_4) // $
#define KC_DOLLAR KC_DLR
@@ -107,22 +113,43 @@ extern const uint16_t fn_actions[];
#define KC_RPRN LSFT(KC_0) // )
#define KC_RIGHT_PAREN KC_RPRN
+
#define KC_UNDS LSFT(KC_MINS) // _
#define KC_UNDERSCORE KC_UNDS
#define KC_PLUS LSFT(KC_EQL) // +
+
#define KC_LCBR LSFT(KC_LBRC) // {
#define KC_LEFT_CURLY_BRACE KC_LCBR
#define KC_RCBR LSFT(KC_RBRC) // }
#define KC_RIGHT_CURLY_BRACE KC_RCBR
+#define KC_LABK LSFT(KC_COMM) // <
+#define KC_LEFT_ANGLE_BRACKET KC_LABK
+
+#define KC_RABK LSFT(KC_DOT) // >
+#define KC_RIGHT_ANGLE_BRACKET KC_RABK
+
#define KC_COLN LSFT(KC_SCLN) // :
#define KC_COLON KC_COLN
#define KC_PIPE LSFT(KC_BSLS) // |
+#define KC_LT LSFT(KC_COMM) // <
+
+
+#define KC_GT LSFT(KC_DOT) // >
+
+
+#define KC_QUES LSFT(KC_SLSH) // ?
+#define KC_QUESTION KC_QUES
+
+
+#define KC_DQT LSFT(KC_QUOT) // "
+#define KC_DOUBLE_QUOTE KC_DQT
+
#define KC_DELT KC_DELETE // Del key (four letter code)
// Alias for function layers than expand past FN31
@@ -132,35 +159,14 @@ extern const uint16_t fn_actions[];
#define S(kc) LSFT(kc)
#define F(kc) FUNC(kc)
-#define M(kc) kc | 0x3000
+#define M(kc) (kc | 0x3000)
#define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
-// These affect the backlight (if your keyboard has one).
-// We don't need to comment them out if your keyboard doesn't have a backlight,
-// since they don't take up any space.
-#define BL_ON 0x4009
-#define BL_OFF 0x4000
-#define BL_0 0x4000
-#define BL_1 0x4001
-#define BL_2 0x4002
-#define BL_3 0x4003
-#define BL_4 0x4004
-#define BL_5 0x4005
-#define BL_6 0x4006
-#define BL_7 0x4007
-#define BL_8 0x4008
-#define BL_9 0x4009
-#define BL_10 0x400A
-#define BL_11 0x400B
-#define BL_12 0x400C
-#define BL_13 0x400D
-#define BL_14 0x400E
-#define BL_15 0x400F
-#define BL_DEC 0x4010
-#define BL_INC 0x4011
-#define BL_TOGG 0x4012
-#define BL_STEP 0x4013
+// 0x3100+ is free
+
+// L-ayer, T-ap - 256 keycode max, 16 layer max
+#define LT(layer, kc) (kc | 0x4000 | ((layer & 0xF) << 8))
#define RESET 0x5000
#define DEBUG 0x5001
@@ -188,6 +194,51 @@ extern const uint16_t fn_actions[];
#define AG_SWAP MAGIC_SWAP_ALT_GUI
#define AG_NORM MAGIC_UNSWAP_ALT_GUI
+#define KC_LEAD 0x5014
+
+// Audio on/off
+#define AU_ON 0x5020
+#define AU_OFF 0x5021
+#define AU_TOG 0x5022
+
+// Music mode on/off
+#define MU_ON 0x5023
+#define MU_OFF 0x5024
+#define MU_TOG 0x5025
+
+// Music voice iterate
+#define MUV_IN 0x5026
+#define MUV_DE 0x5027
+
+// Midi mode on/off
+#define MI_ON 0x5028
+#define MI_OFF 0x5029
+
+// These affect the backlight (if your keyboard has one).
+// We don't need to comment them out if your keyboard doesn't have a backlight,
+// since they don't take up any space.
+#define BL_ON 0x5079
+#define BL_OFF 0x5070
+#define BL_0 0x5070
+#define BL_1 0x5071
+#define BL_2 0x5072
+#define BL_3 0x5073
+#define BL_4 0x5074
+#define BL_5 0x5075
+#define BL_6 0x5076
+#define BL_7 0x5077
+#define BL_8 0x5078
+#define BL_9 0x5079
+#define BL_10 0x507A
+#define BL_11 0x507B
+#define BL_12 0x507C
+#define BL_13 0x507D
+#define BL_14 0x507E
+#define BL_15 0x507F
+#define BL_DEC 0x5080
+#define BL_INC 0x5081
+#define BL_TOGG 0x5082
+#define BL_STEP 0x5083
// GOTO layer - 16 layers max
// when:
@@ -205,6 +256,14 @@ extern const uint16_t fn_actions[];
// Toggle to layer - 256 layer max
#define TG(layer) (layer | 0x5400)
+// One-shot layer - 256 layer max
+#define OSL(layer) (layer | 0x5500)
+
+// One-shot mod
+#define OSM(layer) (layer | 0x5600)
+
+// chording is currently at 0x57xx
+
// M-od, T-ap - 256 keycode max
#define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
#define CTL_T(kc) MT(0x1, kc)
@@ -220,14 +279,13 @@ extern const uint16_t fn_actions[];
#define KC_HYPR HYPR(KC_NO)
#define KC_MEH MEH(KC_NO)
-// L-ayer, T-ap - 256 keycode max, 16 layer max
-#define LT(layer, kc) (kc | 0x8000 | ((layer & 0xF) << 8))
-
-// For sending unicode codes.
-// You may not send codes over 1FFF -- this supports most of UTF8.
-// To have a key that sends out Å’, go UC(0x0152)
-#define UNICODE(n) (n | 0x8000)
-#define UC(n) UNICODE(n)
+#ifdef UNICODE_ENABLE
+ // For sending unicode codes.
+ // You may not send codes over 7FFF -- this supports most of UTF8.
+ // To have a key that sends out Å’, go UC(0x0152)
+ #define UNICODE(n) (n | 0x8000)
+ #define UC(n) UNICODE(n)
+#endif
// For tri-layer
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
diff --git a/quantum/keymap_extras/keymap_german_ch.h b/quantum/keymap_extras/keymap_german_ch.h
new file mode 100644
index 0000000000..0874abf7dd
--- /dev/null
+++ b/quantum/keymap_extras/keymap_german_ch.h
@@ -0,0 +1,102 @@
+#ifndef KEYMAP_SWISS_GERMAN
+#define KEYMAP_SWISS_GERMAN
+
+#include "keymap_common.h"
+
+// Alt gr
+#define ALGR(kc) kc | 0x1400
+#define CH_ALGR KC_RALT
+
+// normal characters
+#define CH_Z KC_Y
+#define CH_Y KC_Z
+
+#define CH_A KC_A
+#define CH_B KC_B
+#define CH_C KC_C
+#define CH_D KC_D
+#define CH_E KC_E
+#define CH_F KC_F
+#define CH_G KC_G
+#define CH_H KC_H
+#define CH_I KC_I
+#define CH_J KC_J
+#define CH_K KC_K
+#define CH_L KC_L
+#define CH_M KC_M
+#define CH_N KC_N
+#define CH_O KC_O
+#define CH_P KC_P
+#define CH_Q KC_Q
+#define CH_R KC_R
+#define CH_S KC_S
+#define CH_T KC_T
+#define CH_U KC_U
+#define CH_V KC_V
+#define CH_W KC_W
+#define CH_X KC_X
+
+#define CH_0 KC_0
+#define CH_1 KC_1
+#define CH_2 KC_2
+#define CH_3 KC_3
+#define CH_4 KC_4
+#define CH_5 KC_5
+#define CH_6 KC_6
+#define CH_7 KC_7
+#define CH_8 KC_8
+#define CH_9 KC_9
+
+#define CH_DOT KC_DOT
+#define CH_COMM KC_COMM
+
+#define CH_QUOT KC_MINS // ' ? ´
+#define CH_AE KC_QUOT
+#define CH_UE KC_LBRC
+#define CH_OE KC_SCLN
+
+#define CH_PARA KC_GRAVE // secction sign § and °
+#define CH_CARR KC_EQL // carret ^ ` ~
+#define CH_DIER KC_RBRC // dieresis ¨ ! ]
+#define CH_DLR KC_BSLS // $ £ }
+#define CH_LESS KC_NUBS // < and > and backslash
+#define CH_MINS KC_SLSH // - and _
+
+// shifted characters
+#define CH_RING LSFT(CH_PARA) // °
+#define CH_PLUS LSFT(KC_1) // +
+#define CH_DQOT LSFT(KC_2) // "
+#define CH_PAST LSFT(KC_3) // *
+#define CH_CELA LSFT(KC_4) // ç
+#define CH_PERC LSFT(KC_5) // %
+#define CH_AMPR LSFT(KC_6) // &
+#define CH_SLSH LSFT(KC_7) // /
+#define CH_LPRN LSFT(KC_8) // (
+#define CH_RPRN LSFT(KC_9) // )
+#define CH_EQL LSFT(KC_0) // =
+#define CH_QST LSFT(CH_QUOT) // ?
+#define CH_GRV LSFT(CH_CARR) // `
+#define CH_EXLM LSFT(CH_DIER) // !
+#define CH_POND LSFT(CH_DLR) // £
+#define CH_MORE LSFT(CH_LESS) // >
+#define CH_COLN LSFT(KC_DOT) // :
+#define CH_SCLN LSFT(KC_COMM) // ;
+#define CH_UNDS LSFT(CH_MINS) // _
+
+// Alt Gr-ed characters
+#define CH_BRBR ALGR(KC_1) // ¦ brocken bar
+#define CH_AT ALGR(KC_2) // @
+#define CH_HASH ALGR(KC_3) // #
+#define CH_NOTL ALGR(KC_6) // ¬ negative logic
+#define CH_PIPE ALGR(KC_7) // |
+#define CH_CENT ALGR(KC_8) // ¢ cent
+#define CH_ACUT ALGR(CH_QUOT) // ´
+#define CH_TILD ALGR(CH_CARR) // ~
+#define CH_EURO ALGR(KC_E) // €
+#define CH_LBRC ALGR(CH_UE) // [
+#define CH_RBRC ALGR(CH_DIER) // ]
+#define CH_LCBR ALGR(CH_AE) // {
+#define CH_RCBR ALGR(CH_DLR) // }
+#define CH_BSLS ALGR(CH_LESS) // backslash
+
+#endif
diff --git a/quantum/keymap_midi.h b/quantum/keymap_midi.h
index 795f26380e..3a2bf3afff 100644
--- a/quantum/keymap_midi.h
+++ b/quantum/keymap_midi.h
@@ -25,11 +25,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define CHNL(note, channel) (note + (channel << 8))
-#define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
- 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
- 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
- 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
- 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
+#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
+ 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
+ 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
+ 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
+ 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
#define N_CN1 (0x600C + (12 * -1) + 0 )
#define N_CN1S (0x600C + (12 * -1) + 1 )
diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c
deleted file mode 100644
index a44965e611..0000000000
--- a/quantum/keymap_unicode.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-Copyright 2015 Jack Humbert <jack.humb@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/>.
-*/
-
-#include "keymap_common.h"
-
-uint16_t hextokeycode(int hex) {
- if (hex == 0x0) {
- return KC_0;
- } else if (hex < 0xA) {
- return KC_1 + (hex - 0x1);
- } else {
- return KC_A + (hex - 0xA);
- }
-}
-
-void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-
- // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input
-
- if (record->event.pressed) {
- uint16_t unicode = (opt << 8) | id;
- register_code(KC_LALT);
-
- register_code(hextokeycode((unicode & 0xF000) >> 12));
- unregister_code(hextokeycode((unicode & 0xF000) >> 12));
- register_code(hextokeycode((unicode & 0x0F00) >> 8));
- unregister_code(hextokeycode((unicode & 0x0F00) >> 8));
- register_code(hextokeycode((unicode & 0x00F0) >> 4));
- unregister_code(hextokeycode((unicode & 0x00F0) >> 4));
- register_code(hextokeycode((unicode & 0x000F)));
- unregister_code(hextokeycode((unicode & 0x000F)));
-
- /* Test 'a' */
- // register_code(hextokeycode(0x0));
- // unregister_code(hextokeycode(0x0));
- // register_code(hextokeycode(0x0));
- // unregister_code(hextokeycode(0x0));
- // register_code(hextokeycode(0x6));
- // unregister_code(hextokeycode(0x6));
- // register_code(hextokeycode(0x1));
- // unregister_code(hextokeycode(0x1));
-
- unregister_code(KC_LALT);
- }
- return;
-} \ No newline at end of file
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 2dab6ae941..d5fd7def8a 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -1,6 +1,6 @@
/*
-Copyright 2012 Jun Wako
-Generated by planckkeyboard.com (2014 Jack Humbert)
+Copyright 2012 Jun Wako
+Copyright 2014 Jack Humbert
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
@@ -15,293 +15,211 @@ 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/>.
*/
-
-/*
- * scan matrix
- */
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
-#include <util/delay.h>
+#include "wait.h"
#include "print.h"
#include "debug.h"
#include "util.h"
#include "matrix.h"
-#ifndef DEBOUNCE
-# define DEBOUNCE 10
+#ifdef MATRIX_HAS_GHOST
+# error "The universal matrix.c file cannot be used for this keyboard."
#endif
-static uint8_t debouncing = DEBOUNCE;
-/* matrix state(1:on, 0:off) */
-static matrix_row_t matrix[MATRIX_ROWS];
-static matrix_row_t matrix_debouncing[MATRIX_ROWS];
+#ifndef DEBOUNCING_DELAY
+# define DEBOUNCING_DELAY 5
+#endif
-#if DIODE_DIRECTION == ROW2COL
- static matrix_row_t matrix_reversed[MATRIX_COLS];
- static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS];
+static const io_pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
+static const io_pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
+/* matrix state */
+#if DIODE_DIRECTION == COL2ROW
+static matrix_row_t matrix[MATRIX_ROWS];
+#else
+static matrix_col_t matrix[MATRIX_COLS];
#endif
+static int8_t debouncing_delay = -1;
+#if DIODE_DIRECTION == COL2ROW
+static void toggle_row(uint8_t row);
static matrix_row_t read_cols(void);
-static void init_cols(void);
-static void unselect_rows(void);
-static void select_row(uint8_t row);
+#else
+static void toggle_col(uint8_t col);
+static matrix_col_t read_rows(void);
+#endif
__attribute__ ((weak))
-void matrix_init_kb(void) {
-
+void matrix_init_quantum(void) {
}
__attribute__ ((weak))
-void matrix_scan_kb(void) {
-
+void matrix_scan_quantum(void) {
}
-inline
-uint8_t matrix_rows(void)
-{
+uint8_t matrix_rows(void) {
return MATRIX_ROWS;
}
-inline
-uint8_t matrix_cols(void)
-{
+uint8_t matrix_cols(void) {
return MATRIX_COLS;
}
-void matrix_init(void)
-{
- // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
- MCUCR |= (1<<JTD);
- MCUCR |= (1<<JTD);
-
-
- // initialize row and col
- unselect_rows();
- init_cols();
-
- // initialize matrix state: all keys off
- for (uint8_t i=0; i < MATRIX_ROWS; i++) {
- matrix[i] = 0;
- matrix_debouncing[i] = 0;
- }
-
- matrix_init_kb();
-}
-
-
-uint8_t matrix_scan(void)
-{
-
+void matrix_init(void) {
+ /* frees PORTF by setting the JTD bit twice within four cycles */
+ MCUCR |= _BV(JTD);
+ MCUCR |= _BV(JTD);
+ /* initializes the I/O pins */
#if DIODE_DIRECTION == COL2ROW
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- select_row(i);
- _delay_us(30); // without this wait read unstable value.
- matrix_row_t cols = read_cols();
- if (matrix_debouncing[i] != cols) {
- matrix_debouncing[i] = cols;
- if (debouncing) {
- debug("bounce!: "); debug_hex(debouncing); debug("\n");
- }
- debouncing = DEBOUNCE;
- }
- unselect_rows();
+ for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
+ /* DDRxn */
+ _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit);
+ toggle_row(r);
}
-
- if (debouncing) {
- if (--debouncing) {
- _delay_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- matrix[i] = matrix_debouncing[i];
- }
- }
+ for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+ /* PORTxn */
+ _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit);
}
#else
- for (uint8_t i = 0; i < MATRIX_COLS; i++) {
- select_row(i);
- _delay_us(30); // without this wait read unstable value.
- matrix_row_t rows = read_cols();
- if (matrix_reversed_debouncing[i] != rows) {
- matrix_reversed_debouncing[i] = rows;
- if (debouncing) {
- debug("bounce!: "); debug_hex(debouncing); debug("\n");
- }
- debouncing = DEBOUNCE;
- }
- unselect_rows();
+ for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+ /* DDRxn */
+ _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit);
+ toggle_col(c);
+ }
+ for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
+ /* PORTxn */
+ _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit);
}
+#endif
+ matrix_init_quantum();
+}
- if (debouncing) {
- if (--debouncing) {
- _delay_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_COLS; i++) {
- matrix_reversed[i] = matrix_reversed_debouncing[i];
- }
+#if DIODE_DIRECTION == COL2ROW
+uint8_t matrix_scan(void) {
+ static matrix_row_t debouncing_matrix[MATRIX_ROWS];
+ for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
+ toggle_row(r);
+ matrix_row_t state = read_cols();
+ if (debouncing_matrix[r] != state) {
+ debouncing_matrix[r] = state;
+ debouncing_delay = DEBOUNCING_DELAY;
}
+ toggle_row(r);
}
- for (uint8_t y = 0; y < MATRIX_ROWS; y++) {
- matrix_row_t row = 0;
- for (uint8_t x = 0; x < MATRIX_COLS; x++) {
- row |= ((matrix_reversed[x] & (1<<y)) >> y) << x;
+ if (debouncing_delay >= 0) {
+ dprintf("Debouncing delay remaining: %X\n", debouncing_delay);
+ --debouncing_delay;
+ if (debouncing_delay >= 0) {
+ wait_ms(1);
+ }
+ else {
+ for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
+ matrix[r] = debouncing_matrix[r];
+ }
}
- matrix[y] = row;
}
-#endif
-
- matrix_scan_kb();
-
+ matrix_scan_quantum();
return 1;
}
-bool matrix_is_modified(void)
-{
- if (debouncing) return false;
- return true;
+static void toggle_row(uint8_t row) {
+ /* PINxn */
+ _SFR_IO8(row_pins[row].input_addr) = _BV(row_pins[row].bit);
}
-inline
-bool matrix_is_on(uint8_t row, uint8_t col)
-{
- return (matrix[row] & ((matrix_row_t)1<col));
+static matrix_row_t read_cols(void) {
+ matrix_row_t state = 0;
+ for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+ /* PINxn */
+ if (!(_SFR_IO8(col_pins[c].input_addr) & _BV(col_pins[c].bit))) {
+ state |= (matrix_row_t)1 << c;
+ }
+ }
+ return state;
}
-inline
-matrix_row_t matrix_get_row(uint8_t row)
-{
+matrix_row_t matrix_get_row(uint8_t row) {
return matrix[row];
}
-void matrix_print(void)
-{
- print("\nr/c 0123456789ABCDEF\n");
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- phex(row); print(": ");
- pbin_reverse16(matrix_get_row(row));
- print("\n");
+#else
+uint8_t matrix_scan(void) {
+ static matrix_col_t debouncing_matrix[MATRIX_COLS];
+ for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+ toggle_col(c);
+ matrix_col_t state = read_rows();
+ if (debouncing_matrix[c] != state) {
+ debouncing_matrix[c] = state;
+ debouncing_delay = DEBOUNCING_DELAY;
+ }
+ toggle_col(c);
}
-}
-
-uint8_t matrix_key_count(void)
-{
- uint8_t count = 0;
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- count += bitpop16(matrix[i]);
+ if (debouncing_delay >= 0) {
+ dprintf("Debouncing delay remaining: %X\n", debouncing_delay);
+ --debouncing_delay;
+ if (debouncing_delay >= 0) {
+ wait_ms(1);
+ }
+ else {
+ for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+ matrix[c] = debouncing_matrix[c];
+ }
+ }
}
- return count;
+ matrix_scan_quantum();
+ return 1;
}
-static void init_cols(void)
-{
- int B = 0, C = 0, D = 0, E = 0, F = 0;
+static void toggle_col(uint8_t col) {
+ /* PINxn */
+ _SFR_IO8(col_pins[col].input_addr) = _BV(col_pins[col].bit);
+}
-#if DIODE_DIRECTION == COL2ROW
- for(int x = 0; x < MATRIX_COLS; x++) {
- int col = COLS[x];
-#else
- for(int x = 0; x < MATRIX_ROWS; x++) {
- int col = ROWS[x];
-#endif
- if ((col & 0xF0) == 0x20) {
- B |= (1<<(col & 0x0F));
- } else if ((col & 0xF0) == 0x30) {
- C |= (1<<(col & 0x0F));
- } else if ((col & 0xF0) == 0x40) {
- D |= (1<<(col & 0x0F));
- } else if ((col & 0xF0) == 0x50) {
- E |= (1<<(col & 0x0F));
- } else if ((col & 0xF0) == 0x60) {
- F |= (1<<(col & 0x0F));
- }
+static matrix_col_t read_rows(void) {
+ matrix_col_t state = 0;
+ for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
+ /* PINxn */
+ if (!(_SFR_IO8(row_pins[r].input_addr) & _BV(row_pins[r].bit))) {
+ state |= (matrix_col_t)1 << r;
+ }
}
- DDRB &= ~(B); PORTB |= (B);
- DDRC &= ~(C); PORTC |= (C);
- DDRD &= ~(D); PORTD |= (D);
- DDRE &= ~(E); PORTE |= (E);
- DDRF &= ~(F); PORTF |= (F);
+ return state;
}
-static matrix_row_t read_cols(void)
-{
- matrix_row_t result = 0;
+matrix_row_t matrix_get_row(uint8_t row) {
+ matrix_row_t state = 0;
+ matrix_col_t mask = (matrix_col_t)1 << row;
+ for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+ if (matrix[c] & mask) {
+ state |= (matrix_row_t)1 << c;
+ }
+ }
+ return state;
+}
-#if DIODE_DIRECTION == COL2ROW
- for(int x = 0; x < MATRIX_COLS; x++) {
- int col = COLS[x];
-#else
- for(int x = 0; x < MATRIX_ROWS; x++) {
- int col = ROWS[x];
#endif
- if ((col & 0xF0) == 0x20) {
- result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x));
- } else if ((col & 0xF0) == 0x30) {
- result |= (PINC&(1<<(col & 0x0F)) ? 0 : (1<<x));
- } else if ((col & 0xF0) == 0x40) {
- result |= (PIND&(1<<(col & 0x0F)) ? 0 : (1<<x));
- } else if ((col & 0xF0) == 0x50) {
- result |= (PINE&(1<<(col & 0x0F)) ? 0 : (1<<x));
- } else if ((col & 0xF0) == 0x60) {
- result |= (PINF&(1<<(col & 0x0F)) ? 0 : (1<<x));
- }
- }
- return result;
+bool matrix_is_modified(void) {
+ if (debouncing_delay >= 0) return false;
+ return true;
}
-static void unselect_rows(void)
-{
- int B = 0, C = 0, D = 0, E = 0, F = 0;
+bool matrix_is_on(uint8_t row, uint8_t col) {
+ return matrix_get_row(row) & (matrix_row_t)1 << col;
+}
-#if DIODE_DIRECTION == COL2ROW
- for(int x = 0; x < MATRIX_ROWS; x++) {
- int row = ROWS[x];
-#else
- for(int x = 0; x < MATRIX_COLS; x++) {
- int row = COLS[x];
-#endif
- if ((row & 0xF0) == 0x20) {
- B |= (1<<(row & 0x0F));
- } else if ((row & 0xF0) == 0x30) {
- C |= (1<<(row & 0x0F));
- } else if ((row & 0xF0) == 0x40) {
- D |= (1<<(row & 0x0F));
- } else if ((row & 0xF0) == 0x50) {
- E |= (1<<(row & 0x0F));
- } else if ((row & 0xF0) == 0x60) {
- F |= (1<<(row & 0x0F));
- }
+void matrix_print(void) {
+ dprintln("Human-readable matrix state:");
+ for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
+ dprintf("State of row %X: %016b\n", r, bitrev16(matrix_get_row(r)));
}
- DDRB &= ~(B); PORTB |= (B);
- DDRC &= ~(C); PORTC |= (C);
- DDRD &= ~(D); PORTD |= (D);
- DDRE &= ~(E); PORTE |= (E);
- DDRF &= ~(F); PORTF |= (F);
}
-static void select_row(uint8_t row)
-{
-
-#if DIODE_DIRECTION == COL2ROW
- int row_pin = ROWS[row];
-#else
- int row_pin = COLS[row];
-#endif
-
- if ((row_pin & 0xF0) == 0x20) {
- DDRB |= (1<<(row_pin & 0x0F));
- PORTB &= ~(1<<(row_pin & 0x0F));
- } else if ((row_pin & 0xF0) == 0x30) {
- DDRC |= (1<<(row_pin & 0x0F));
- PORTC &= ~(1<<(row_pin & 0x0F));
- } else if ((row_pin & 0xF0) == 0x40) {
- DDRD |= (1<<(row_pin & 0x0F));
- PORTD &= ~(1<<(row_pin & 0x0F));
- } else if ((row_pin & 0xF0) == 0x50) {
- DDRE |= (1<<(row_pin & 0x0F));
- PORTE &= ~(1<<(row_pin & 0x0F));
- } else if ((row_pin & 0xF0) == 0x60) {
- DDRF |= (1<<(row_pin & 0x0F));
- PORTF &= ~(1<<(row_pin & 0x0F));
- }
-} \ No newline at end of file
+uint8_t matrix_key_count(void) {
+ uint8_t count = 0;
+ for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
+ count += bitpop16(matrix_get_row(r));
+ }
+ return count;
+}
diff --git a/quantum/quantum.c b/quantum/quantum.c
new file mode 100644
index 0000000000..eb64a99a4d
--- /dev/null
+++ b/quantum/quantum.c
@@ -0,0 +1,484 @@
+#include "quantum.h"
+#include "timer.h"
+
+__attribute__ ((weak))
+void matrix_init_kb(void) {}
+
+__attribute__ ((weak))
+void matrix_scan_kb(void) {}
+
+__attribute__ ((weak))
+bool process_action_kb(keyrecord_t *record) {
+ return true;
+}
+
+__attribute__ ((weak))
+void leader_start(void) {}
+
+__attribute__ ((weak))
+void leader_end(void) {}
+
+uint8_t starting_note = 0x0C;
+int offset = 7;
+
+#ifdef AUDIO_ENABLE
+ bool music_activated = false;
+
+// music sequencer
+static bool music_sequence_recording = false;
+static bool music_sequence_playing = false;
+static float music_sequence[16] = {0};
+static uint8_t music_sequence_count = 0;
+static uint8_t music_sequence_position = 0;
+
+static uint16_t music_sequence_timer = 0;
+static uint16_t music_sequence_interval = 100;
+
+#endif
+
+#ifdef MIDI_ENABLE
+ bool midi_activated = false;
+#endif
+
+// Leader key stuff
+bool leading = false;
+uint16_t leader_time = 0;
+
+uint16_t leader_sequence[3] = {0, 0, 0};
+uint8_t leader_sequence_size = 0;
+
+// Chording stuff
+#define CHORDING_MAX 4
+bool chording = false;
+
+uint8_t chord_keys[CHORDING_MAX] = {0};
+uint8_t chord_key_count = 0;
+uint8_t chord_key_down = 0;
+
+#ifdef UNICODE_ENABLE
+ static uint8_t input_mode;
+#endif
+
+bool keys_chord(uint8_t keys[]) {
+ uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
+ bool pass = true;
+ uint8_t in = 0;
+ for (uint8_t i = 0; i < chord_key_count; i++) {
+ bool found = false;
+ for (uint8_t j = 0; j < keys_size; j++) {
+ if (chord_keys[i] == (keys[j] & 0xFF)) {
+ in++; // detects key in chord
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ continue;
+ if (chord_keys[i] != 0) {
+ pass = false; // makes sure rest are blank
+ }
+ }
+ return (pass && (in == keys_size));
+}
+
+#ifdef UNICODE_ENABLE
+
+uint16_t hex_to_keycode(uint8_t hex)
+{
+ if (hex == 0x0) {
+ return KC_0;
+ } else if (hex < 0xA) {
+ return KC_1 + (hex - 0x1);
+ } else {
+ return KC_A + (hex - 0xA);
+ }
+}
+
+void set_unicode_mode(uint8_t os_target)
+{
+ input_mode = os_target;
+}
+
+#endif
+
+bool process_record_quantum(keyrecord_t *record) {
+
+ /* This gets the keycode from the key pressed */
+ keypos_t key = record->event.key;
+ uint16_t keycode;
+
+ #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
+ uint8_t layer;
+
+ if (record->event.pressed) {
+ layer = layer_switch_get_layer(key);
+ update_source_layers_cache(key, layer);
+ } else {
+ layer = read_source_layers_cache(key);
+ }
+ keycode = keymap_key_to_keycode(layer, key);
+ #else
+ keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
+ #endif
+
+ // This is how you use actions here
+ // if (keycode == KC_LEAD) {
+ // action_t action;
+ // action.code = ACTION_DEFAULT_LAYER_SET(0);
+ // process_action(record, action);
+ // return false;
+ // }
+
+ #ifdef MIDI_ENABLE
+ if (keycode == MI_ON && record->event.pressed) {
+ midi_activated = true;
+ music_scale_user();
+ return false;
+ }
+
+ if (keycode == MI_OFF && record->event.pressed) {
+ midi_activated = false;
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ return false;
+ }
+
+ if (midi_activated) {
+ if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
+ if (record->event.pressed) {
+ starting_note++; // Change key
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ // midi_send_cc(&midi_device, 1, 0x7B, 0);
+ // midi_send_cc(&midi_device, 2, 0x7B, 0);
+ // midi_send_cc(&midi_device, 3, 0x7B, 0);
+ // midi_send_cc(&midi_device, 4, 0x7B, 0);
+ }
+ return false;
+ }
+ if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
+ if (record->event.pressed) {
+ starting_note--; // Change key
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ // midi_send_cc(&midi_device, 1, 0x7B, 0);
+ // midi_send_cc(&midi_device, 2, 0x7B, 0);
+ // midi_send_cc(&midi_device, 3, 0x7B, 0);
+ // midi_send_cc(&midi_device, 4, 0x7B, 0);
+ }
+ return false;
+ }
+ if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
+ offset++; // Change scale
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ // midi_send_cc(&midi_device, 1, 0x7B, 0);
+ // midi_send_cc(&midi_device, 2, 0x7B, 0);
+ // midi_send_cc(&midi_device, 3, 0x7B, 0);
+ // midi_send_cc(&midi_device, 4, 0x7B, 0);
+ return false;
+ }
+ if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
+ offset--; // Change scale
+ midi_send_cc(&midi_device, 0, 0x7B, 0);
+ // midi_send_cc(&midi_device, 1, 0x7B, 0);
+ // midi_send_cc(&midi_device, 2, 0x7B, 0);
+ // midi_send_cc(&midi_device, 3, 0x7B, 0);
+ // midi_send_cc(&midi_device, 4, 0x7B, 0);
+ return false;
+ }
+ // basic
+ // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
+ // advanced
+ // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
+ // guitar
+ uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
+ // violin
+ // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
+
+ if (record->event.pressed) {
+ // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
+ midi_send_noteon(&midi_device, 0, note, 127);
+ } else {
+ // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
+ midi_send_noteoff(&midi_device, 0, note, 127);
+ }
+
+ if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
+ return false;
+ }
+ #endif
+
+ #ifdef AUDIO_ENABLE
+ if (keycode == AU_ON && record->event.pressed) {
+ audio_on();
+ return false;
+ }
+
+ if (keycode == AU_OFF && record->event.pressed) {
+ audio_off();
+ return false;
+ }
+
+ if (keycode == AU_TOG && record->event.pressed) {
+ if (is_audio_on())
+ {
+ audio_off();
+ }
+ else
+ {
+ audio_on();
+ }
+ return false;
+ }
+
+ if (keycode == MU_ON && record->event.pressed) {
+ music_on();
+ return false;
+ }
+
+ if (keycode == MU_OFF && record->event.pressed) {
+ music_off();
+ return false;
+ }
+
+ if (keycode == MU_TOG && record->event.pressed) {
+ if (music_activated)
+ {
+ music_off();
+ }
+ else
+ {
+ music_on();
+ }
+ return false;
+ }
+
+ if (keycode == MUV_IN && record->event.pressed) {
+ voice_iterate();
+ music_scale_user();
+ return false;
+ }
+
+ if (keycode == MUV_DE && record->event.pressed) {
+ voice_deiterate();
+ music_scale_user();
+ return false;
+ }
+
+ if (music_activated) {
+
+ if (keycode == KC_LCTL && record->event.pressed) { // Start recording
+ stop_all_notes();
+ music_sequence_recording = true;
+ music_sequence_playing = false;
+ music_sequence_count = 0;
+ return false;
+ }
+
+ if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
+ stop_all_notes();
+ music_sequence_recording = false;
+ music_sequence_playing = false;
+ return false;
+ }
+
+ if (keycode == KC_LGUI && record->event.pressed) { // Start playing
+ stop_all_notes();
+ music_sequence_recording = false;
+ music_sequence_playing = true;
+ music_sequence_position = 0;
+ music_sequence_timer = 0;
+ return false;
+ }
+
+ if (keycode == KC_UP) {
+ if (record->event.pressed)
+ music_sequence_interval-=10;
+ return false;
+ }
+
+ if (keycode == KC_DOWN) {
+ if (record->event.pressed)
+ music_sequence_interval+=10;
+ return false;
+ }
+
+ float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
+ if (record->event.pressed) {
+ play_note(freq, 0xF);
+ if (music_sequence_recording) {
+ music_sequence[music_sequence_count] = freq;
+ music_sequence_count++;
+ }
+ } else {
+ stop_note(freq);
+ }
+
+ if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
+ return false;
+ }
+ #endif
+
+#ifndef DISABLE_LEADER
+ // Leader key set-up
+ if (record->event.pressed) {
+ if (!leading && keycode == KC_LEAD) {
+ leader_start();
+ leading = true;
+ leader_time = timer_read();
+ leader_sequence_size = 0;
+ leader_sequence[0] = 0;
+ leader_sequence[1] = 0;
+ leader_sequence[2] = 0;
+ return false;
+ }
+ if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
+ leader_sequence[leader_sequence_size] = keycode;
+ leader_sequence_size++;
+ return false;
+ }
+ }
+#endif
+
+#define DISABLE_CHORDING
+#ifndef DISABLE_CHORDING
+
+ if (keycode >= 0x5700 && keycode <= 0x57FF) {
+ if (record->event.pressed) {
+ if (!chording) {
+ chording = true;
+ for (uint8_t i = 0; i < CHORDING_MAX; i++)
+ chord_keys[i] = 0;
+ chord_key_count = 0;
+ chord_key_down = 0;
+ }
+ chord_keys[chord_key_count] = (keycode & 0xFF);
+ chord_key_count++;
+ chord_key_down++;
+ return false;
+ } else {
+ if (chording) {
+ chord_key_down--;
+ if (chord_key_down == 0) {
+ chording = false;
+ // Chord Dictionary
+ if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
+ register_code(KC_A);
+ unregister_code(KC_A);
+ return false;
+ }
+ for (uint8_t i = 0; i < chord_key_count; i++) {
+ register_code(chord_keys[i]);
+ unregister_code(chord_keys[i]);
+ return false;
+ }
+ }
+ }
+ }
+ }
+
+#endif
+
+#ifdef UNICODE_ENABLE
+
+ if (keycode > UNICODE(0) && record->event.pressed) {
+ uint16_t unicode = keycode & 0x7FFF;
+ switch(input_mode) {
+ case UC_OSX:
+ register_code(KC_LALT);
+ break;
+ case UC_LNX:
+ register_code(KC_LCTL);
+ register_code(KC_LSFT);
+ register_code(KC_U);
+ unregister_code(KC_U);
+ break;
+ case UC_WIN:
+ register_code(KC_LALT);
+ register_code(KC_PPLS);
+ unregister_code(KC_PPLS);
+ break;
+ }
+ for(int i = 3; i >= 0; i--) {
+ uint8_t digit = ((unicode >> (i*4)) & 0xF);
+ register_code(hex_to_keycode(digit));
+ unregister_code(hex_to_keycode(digit));
+ }
+ switch(input_mode) {
+ case UC_OSX:
+ case UC_WIN:
+ unregister_code(KC_LALT);
+ break;
+ case UC_LNX:
+ unregister_code(KC_LCTL);
+ unregister_code(KC_LSFT);
+ break;
+ }
+ }
+
+#endif
+
+ return process_action_kb(record);
+}
+
+void matrix_init_quantum() {
+ matrix_init_kb();
+}
+
+void matrix_scan_quantum() {
+ #ifdef AUDIO_ENABLE
+ if (music_sequence_playing) {
+ if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
+ music_sequence_timer = timer_read();
+ stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
+ play_note(music_sequence[music_sequence_position], 0xF);
+ music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
+ }
+ }
+
+ #endif
+
+ matrix_scan_kb();
+}
+#ifdef AUDIO_ENABLE
+ bool is_music_on(void) {
+ return (music_activated != 0);
+ }
+
+ void music_toggle(void) {
+ if (!music_activated) {
+ music_on();
+ } else {
+ music_off();
+ }
+ }
+
+ void music_on(void) {
+ music_activated = 1;
+ music_on_user();
+ }
+
+ void music_off(void) {
+ music_activated = 0;
+ stop_all_notes();
+ }
+
+#endif
+
+//------------------------------------------------------------------------------
+// Override these functions in your keymap file to play different tunes on
+// different events such as startup and bootloader jump
+
+__attribute__ ((weak))
+void startup_user() {}
+
+__attribute__ ((weak))
+void shutdown_user() {}
+
+__attribute__ ((weak))
+void music_on_user() {}
+
+__attribute__ ((weak))
+void audio_on_user() {}
+
+__attribute__ ((weak))
+void music_scale_user() {}
+
+//------------------------------------------------------------------------------ \ No newline at end of file
diff --git a/quantum/quantum.h b/quantum/quantum.h
new file mode 100644
index 0000000000..69a0d8126a
--- /dev/null
+++ b/quantum/quantum.h
@@ -0,0 +1,76 @@
+#ifndef QUANTUM_H
+#define QUANTUM_H
+
+#include "matrix.h"
+#include "keymap_common.h"
+#ifdef BACKLIGHT_ENABLE
+ #include "backlight.h"
+#endif
+#ifdef RGBLIGHT_ENABLE
+ #include "rgblight.h"
+#endif
+#ifdef AUDIO_ENABLE
+ #include "audio.h"
+#endif
+#ifdef MIDI_ENABLE
+ #include <lufa.h>
+#endif
+#ifdef UNICODE_ENABLE
+ #include "unicode.h"
+#endif
+
+#include "action_layer.h"
+#include "eeconfig.h"
+#include <stddef.h>
+#include <avr/io.h>
+
+extern uint32_t default_layer_state;
+
+#ifndef NO_ACTION_LAYER
+ extern uint32_t layer_state;
+#endif
+
+#ifdef AUDIO_ENABLE
+ bool music_activated;
+#endif
+
+#ifdef UNICODE_ENABLE
+ #define UC_OSX 0
+ #define UC_LNX 1
+ #define UC_WIN 2
+ #define UC_BSD 3
+
+ void set_unicode_input_mode(uint8_t os_target);
+#endif
+
+#ifndef DISABLE_LEADER
+ void leader_start(void);
+ void leader_end(void);
+
+ #ifndef LEADER_TIMEOUT
+ #define LEADER_TIMEOUT 200
+ #endif
+ #define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0)
+ #define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0)
+ #define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3))
+
+ #define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size
+ #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
+#endif
+
+void matrix_init_kb(void);
+void matrix_scan_kb(void);
+bool process_action_kb(keyrecord_t *record);
+
+bool is_music_on(void);
+void music_toggle(void);
+void music_on(void);
+void music_off(void);
+
+void startup_user(void);
+void shutdown_user(void);
+void audio_on_user(void);
+void music_on_user(void);
+void music_scale_user(void);
+
+#endif \ No newline at end of file
diff --git a/quantum/quantum.mk b/quantum/quantum.mk
index 83c4f1d1db..c099d67939 100644
--- a/quantum/quantum.mk
+++ b/quantum/quantum.mk
@@ -1,7 +1,8 @@
QUANTUM_DIR = quantum
# # project specific files
-SRC += $(QUANTUM_DIR)/keymap_common.c \
+SRC += $(QUANTUM_DIR)/quantum.c \
+ $(QUANTUM_DIR)/keymap_common.c \
$(QUANTUM_DIR)/led.c
# ifdef KEYMAP_FILE
@@ -23,16 +24,14 @@ ifndef CUSTOM_MATRIX
SRC += $(QUANTUM_DIR)/matrix.c
endif
-ifeq ($(strip $(MIDI_ENABLE)), yes)
- SRC += $(QUANTUM_DIR)/keymap_midi.c
-endif
+#ifeq ($(strip $(MIDI_ENABLE)), yes)
+# SRC += $(QUANTUM_DIR)/keymap_midi.c
+#endif
ifeq ($(strip $(AUDIO_ENABLE)), yes)
- SRC += $(QUANTUM_DIR)/audio/audio.c $(QUANTUM_DIR)/audio/voices.c
-endif
-
-ifeq ($(strip $(UNICODE_ENABLE)), yes)
- SRC += $(QUANTUM_DIR)/keymap_unicode.c
+ SRC += $(QUANTUM_DIR)/audio/audio.c
+ SRC += $(QUANTUM_DIR)/audio/voices.c
+ SRC += $(QUANTUM_DIR)/audio/luts.c
endif
ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
diff --git a/quantum/template/Makefile b/quantum/template/Makefile
index 4fa195468d..1a535ef2cb 100644
--- a/quantum/template/Makefile
+++ b/quantum/template/Makefile
@@ -111,23 +111,41 @@ OPT_DEFS += -DBOOTLOADER_SIZE=512
# Build Options
-# comment out to disable the options.
-#
-BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
-MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
-EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
-CONSOLE_ENABLE = yes # Console for debug(+400)
-COMMAND_ENABLE = yes # Commands for debug and configuration
-KEYBOARD_LOCK_ENABLE = yes # Allow locking of keyboard via magic key
+# change yes to no to disable
+#
+BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
+MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
+EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
+CONSOLE_ENABLE = yes # Console for debug(+400)
+COMMAND_ENABLE = yes # Commands for debug and configuration
+KEYBOARD_LOCK_ENABLE = yes # Allow locking of keyboard via magic key
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
-# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
-#NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
-# BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
-# MIDI_ENABLE = YES # MIDI controls
-# UNICODE_ENABLE = YES # Unicode
-# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
+SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
+# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
+NKRO_ENABLE = no # USB Nkey Rollover
+BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
+MIDI_ENABLE = no # MIDI controls
+UNICODE_ENABLE = no # Unicode
+BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
+AUDIO_ENABLE = no # Audio output on port C6
+ifdef KEYMAP
+
+ifeq ("$(wildcard keymaps/$(KEYMAP).c)","")
+ifneq ("$(wildcard keymaps/$(KEYMAP)/makefile.mk)","")
+ include keymaps/$(KEYMAP)/makefile.mk
+endif
+endif
+
+else
+
+ifneq ("$(wildcard keymaps/default/makefile.mk)","")
+ include keymaps/default/makefile.mk
+endif
+
+endif
+
# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax
diff --git a/quantum/template/config.h b/quantum/template/config.h
index e6fb7866c6..cad3e3260a 100644
--- a/quantum/template/config.h
+++ b/quantum/template/config.h
@@ -41,15 +41,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
*
-*/
-#define COLS (int []){ F1, F0, B0 }
-#define ROWS (int []){ D0, D5 }
+*/
+#define MATRIX_ROW_PINS { D0, D5 }
+#define MATRIX_COL_PINS { F1, F0, B0 }
+#define UNUSED_PINS
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
-#define DEBOUNCE 5
+#define DEBOUNCING_DELAY 5
/* define if matrix has ghost (lacks anti-ghosting diodes) */
//#define MATRIX_HAS_GHOST
@@ -62,17 +63,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE
-/*
+/*
* Force NKRO
*
- * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
+ * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
* makefile for this to work.)
*
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
* until the next keyboard reset.
*
- * NKRO may prevent your keystrokes from being detected in the BIOS, but it is
+ * NKRO may prevent your keystrokes from being detected in the BIOS, but it is
* fully operational during normal computer usage.
*
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
@@ -90,7 +91,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* the keyboard. They are best used in combination with the HID Listen program,
* found here: https://www.pjrc.com/teensy/hid_listen.html
*
- * The options below allow the magic key functionality to be changed. This is
+ * The options below allow the magic key functionality to be changed. This is
* useful if your keyboard/keypad is missing keys and you want magic key support.
*
*/
diff --git a/quantum/template/template.c b/quantum/template/template.c
index cc52e496ff..649072eb2e 100644
--- a/quantum/template/template.c
+++ b/quantum/template/template.c
@@ -11,8 +11,9 @@ void matrix_scan_user(void) {
}
__attribute__ ((weak))
-void process_action_user(keyrecord_t *record) {
+bool process_action_user(keyrecord_t *record) {
// leave this function blank - it can be defined in a keymap file
+ return true;
}
__attribute__ ((weak))
@@ -34,11 +35,11 @@ void matrix_scan_kb(void) {
matrix_scan_user();
}
-void process_action_kb(keyrecord_t *record) {
+bool process_action_kb(keyrecord_t *record) {
// put your per-action keyboard code here
// runs for every action, just before processing by the firmware
- process_action_user(record);
+ return process_action_user(record);
}
void led_set_kb(uint8_t usb_led) {
@@ -46,3 +47,64 @@ void led_set_kb(uint8_t usb_led) {
led_set_user(usb_led);
}
+
+#ifdef BACKLIGHT_ENABLE
+#define CHANNEL OCR1C
+
+void backlight_init_ports()
+{
+
+ // Setup PB7 as output and output low.
+ DDRB |= (1<<7);
+ PORTB &= ~(1<<7);
+
+ // Use full 16-bit resolution.
+ ICR1 = 0xFFFF;
+
+ // I could write a wall of text here to explain... but TL;DW
+ // Go read the ATmega32u4 datasheet.
+ // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
+
+ // Pin PB7 = OCR1C (Timer 1, Channel C)
+ // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
+ // (i.e. start high, go low when counter matches.)
+ // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
+ // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
+
+ TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010;
+ TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
+
+ backlight_init();
+}
+
+void backlight_set(uint8_t level)
+{
+ if ( level == 0 )
+ {
+ // Turn off PWM control on PB7, revert to output low.
+ TCCR1A &= ~(_BV(COM1C1));
+ CHANNEL = 0x0;
+ // Prevent backlight blink on lowest level
+ PORTB &= ~(_BV(PORTB7));
+ }
+ else if ( level == BACKLIGHT_LEVELS )
+ {
+ // Prevent backlight blink on lowest level
+ PORTB &= ~(_BV(PORTB7));
+ // Turn on PWM control of PB7
+ TCCR1A |= _BV(COM1C1);
+ // Set the brightness
+ CHANNEL = 0xFFFF;
+ }
+ else
+ {
+ // Prevent backlight blink on lowest level
+ PORTB &= ~(_BV(PORTB7));
+ // Turn on PWM control of PB7
+ TCCR1A |= _BV(COM1C1);
+ // Set the brightness
+ CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/quantum/template/template.h b/quantum/template/template.h
index b1c34d3cbe..8537e3b4be 100644
--- a/quantum/template/template.h
+++ b/quantum/template/template.h
@@ -3,7 +3,10 @@
#include "matrix.h"
#include "keymap_common.h"
-#include "backlight.h"
+#ifdef BACKLIGHT_ENABLE
+ #include "backlight.h"
+#endif
+#include <avr/io.h>
#include <stddef.h>
// This a shortcut to help you visually see your layout.
@@ -21,7 +24,7 @@
void matrix_init_user(void);
void matrix_scan_user(void);
-void process_action_user(keyrecord_t *record);
+bool process_action_user(keyrecord_t *record);
void led_set_user(uint8_t usb_led);
#endif
diff --git a/quantum/tools/README.md b/quantum/tools/README.md
index 0702144238..5f355256de 100644
--- a/quantum/tools/README.md
+++ b/quantum/tools/README.md
@@ -1,6 +1,6 @@
`eeprom_reset.hex` is to reset the eeprom on the Atmega32u4, like this:
dfu-programmer atmega32u4 erase
- dfu-programmer atmega32u4 flash --eeprom eeprom-reset.bin
+ dfu-programmer atmega32u4 flash --eeprom eeprom_reset.hex
- You'll need to reflash afterwards, because DFU requires the flash to be erased before messing with the eeprom. \ No newline at end of file
+ You'll need to reflash afterwards, because DFU requires the flash to be erased before messing with the eeprom.
diff --git a/quantum/unicode.h b/quantum/unicode.h
new file mode 100644
index 0000000000..756ec8bc3f
--- /dev/null
+++ b/quantum/unicode.h
@@ -0,0 +1,128 @@
+/*
+Copyright 2016 Jack Humbert <jack.humb@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/>.
+*/
+
+#ifndef UNICODE_H
+#define UNICODE_H
+
+#include "quantum.h"
+#include <math.h>
+
+#define UC_BSPC UC(0x0008)
+
+#define UC_SPC UC(0x0020)
+
+#define UC_EXLM UC(0x0021)
+#define UC_DQUT UC(0x0022)
+#define UC_HASH UC(0x0023)
+#define UC_DLR UC(0x0024)
+#define UC_PERC UC(0x0025)
+#define UC_AMPR UC(0x0026)
+#define UC_QUOT UC(0x0027)
+#define UC_LPRN UC(0x0028)
+#define UC_RPRN UC(0x0029)
+#define UC_ASTR UC(0x002A)
+#define UC_PLUS UC(0x002B)
+#define UC_COMM UC(0x002C)
+#define UC_DASH UC(0x002D)
+#define UC_DOT UC(0x002E)
+#define UC_SLSH UC(0x002F)
+
+#define UC_0 UC(0x0030)
+#define UC_1 UC(0x0031)
+#define UC_2 UC(0x0032)
+#define UC_3 UC(0x0033)
+#define UC_4 UC(0x0034)
+#define UC_5 UC(0x0035)
+#define UC_6 UC(0x0036)
+#define UC_7 UC(0x0037)
+#define UC_8 UC(0x0038)
+#define UC_9 UC(0x0039)
+
+#define UC_COLN UC(0x003A)
+#define UC_SCLN UC(0x003B)
+#define UC_LT UC(0x003C)
+#define UC_EQL UC(0x003D)
+#define UC_GT UC(0x003E)
+#define UC_QUES UC(0x003F)
+#define UC_AT UC(0x0040)
+
+#define UC_A UC(0x0041)
+#define UC_B UC(0x0042)
+#define UC_C UC(0x0043)
+#define UC_D UC(0x0044)
+#define UC_E UC(0x0045)
+#define UC_F UC(0x0046)
+#define UC_G UC(0x0047)
+#define UC_H UC(0x0048)
+#define UC_I UC(0x0049)
+#define UC_J UC(0x004A)
+#define UC_K UC(0x004B)
+#define UC_L UC(0x004C)
+#define UC_M UC(0x004D)
+#define UC_N UC(0x004E)
+#define UC_O UC(0x004F)
+#define UC_P UC(0x0050)
+#define UC_Q UC(0x0051)
+#define UC_R UC(0x0052)
+#define UC_S UC(0x0053)
+#define UC_T UC(0x0054)
+#define UC_U UC(0x0055)
+#define UC_V UC(0x0056)
+#define UC_W UC(0x0057)
+#define UC_X UC(0x0058)
+#define UC_Y UC(0x0059)
+#define UC_Z UC(0x005A)
+
+#define UC_LBRC UC(0x005B)
+#define UC_BSLS UC(0x005C)
+#define UC_RBRC UC(0x005D)
+#define UC_CIRM UC(0x005E)
+#define UC_UNDR UC(0x005F)
+
+#define UC_GRV UC(0x0060)
+
+#define UC_a UC(0x0061)
+#define UC_b UC(0x0062)
+#define UC_c UC(0x0063)
+#define UC_d UC(0x0064)
+#define UC_e UC(0x0065)
+#define UC_f UC(0x0066)
+#define UC_g UC(0x0067)
+#define UC_h UC(0x0068)
+#define UC_i UC(0x0069)
+#define UC_j UC(0x006A)
+#define UC_k UC(0x006B)
+#define UC_l UC(0x006C)
+#define UC_m UC(0x006D)
+#define UC_n UC(0x006E)
+#define UC_o UC(0x006F)
+#define UC_p UC(0x0070)
+#define UC_q UC(0x0071)
+#define UC_r UC(0x0072)
+#define UC_s UC(0x0073)
+#define UC_t UC(0x0074)
+#define UC_u UC(0x0075)
+#define UC_v UC(0x0076)
+#define UC_w UC(0x0077)
+#define UC_x UC(0x0078)
+#define UC_y UC(0x0079)
+#define UC_z UC(0x007A)
+
+#define UC_LCBR UC(0x007B)
+#define UC_PIPE UC(0x007C)
+#define UC_RCBR UC(0x007D)
+#define UC_TILD UC(0x007E)
+#define UC_DEL UC(0x007F)
+
+#endif \ No newline at end of file