You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

426 lines
21 KiB

Audio system overhaul (#11820) * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commits bundles the changes from the arm-dac-work branch focused on audio/audio_arm.* into one commit (leaving out the test-keyboard) f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both -> only the changes on audio_arm_.*, the keyboard related parts are split off to a separate commit bfe468ef1 start morphing wavetable 474d100b5 refined a bit 208bee10f play_notes working 3e6478b0b start in-place documentation of dac settings 3e1826a33 fixed blip (rounding error), other waves, added key selection (left/right) 73853d651 5 voices at 44.1khz dfb401b95 limit voices to working number 9632b3379 configuration for the ez 6241f3f3b notes working in a new way * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commit splits off the plank example keymap from commit f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both * refactoring: rename audio_ to reflect their supported hardware-platform and audio-generation method: avr vs arm, and pwm vs dac * refactoring: deducplicate ISR code to update the pwm duty-cycle and period in the avr-pwm-implementation pulls three copies of the same code into one function which should improve readability and maintainability :-) * refactoring: move common code of arm and avr implementation into a separate/new file * refactoring: audio_avr_pwm, renaming defines to decouple them from actually used timers, registers and ISRs * refactoring: audio_avr_pwm - replacing function defines with plain register defines aligns better with other existing qmk code (and the new audio_arm_pwm) doing similar pwm thing * add audio-arm-pwm since not all STM32 have a DAC onboard (STM32F2xx and STM32F3xx), pwm-audio is an alternative (STM32F1xx) this code works on a "BluePill" clone, with an STM32F103C8B * clang-format changes on quantum/audio/* only * audio_arm_dac: stopping the notes caused screeching when using the DAC audio paths * audio_arm_pwm: use pushpull on the pin; so that a piezzo can be hooked up direclty without additional components (opendrain would require an external pullup) * refactoring: remove unused file from/for atmel-avr chips * refactoring: remove unused (avr) wavetable file * audio_arm_dac: adapt dac_end callback to changed chibios DAC api the previous chibios (17.6.0) passed along a pointer into the buffer plus a sample_count (which are/already where included in the DACDrivre object) - the current chibios (19.1.0) only passes the driver object. this patch ports more or less exactly what the previous chibios ISR code did: either have the user-callback work the first or second half of the buffer (dacsample_t pointer, with half the DAC_BUFFER_SIZE samples) by adjusting the pointer and sample count * audio-arm-dac: show a compile-warning on undefined audio-pins Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio_arm_dac: switch from exemplary wavetable generation to sine only sine+triangle+squrare is exemplary, and not realy fit for "production" use 'stairs' are usefull for debugging (hardware, with an oscilloscope) * audio_arm_dac: enable output buffers in the STM32 to drive external loads without any additional ciruitry - external opamps and such * audio: prevent out-of-bounds array access * audio_arm_dac: add output-frequency correcting factor * audio_arm_pwm: get both the alternate-function and pm-callback variants back into working condition and do some code-cleanup, refine documentation, ... * audio_arm_pwm: increase pwm frequency for "higher fidelity" on the previous .frequency=100000 higher frequency musical notes came out wrong (frequency measured on a Tektronix TDS2014B) note | freq | arm-pwm C2 | 65.4 | 65.491 C5 | 523.25 | 523.93 C6 | 1046.5 | 1053.38 C7 | 2093 | 2129 C8 | 4186 | 4350.91 with .frequency = 500000 C8 | 4186 | 4204.6 * audio refactoring: remove unused variables * audio_arm_dac: calibrate note tempo: with a tempo of 60beats-per-second a whole-note should last for exactly one second * audio: allow feature selection in rules.mk so the user can switch the audio driver between DAC and PWM on STM32 boards which support both (STM32F2 and up) or select the "pin alternate" pwm mode, for example on STM32F103 * audio-refactoring: move codeblocks in audio.[ch] into more coherent groups and add some inline documentation * audio-refactoring: cleanup and streamline common code between audio_arm_[dac|pwm] untangeling the relation between audio.c and the two drivers and adding more documenting comments :-) * audio_avr_pwm: getting it back into working condition, and cleanup+refactor * audio-refactoring: documentation and typo fixes Co-Authored-By: Nick Brassel <nick@tzarc.org> * audio-refactoring: cleanup defines, inludes and remove debug-prints * audio_chibios_dac: define&use a minimal sampling rate, based on the available tone-range to ease up on the cpu-load, while still rendering the higher notes/tones sufficiently also reenable the lower tones, since with the new implementation there is no evidence of them still beeing 'bugged' * audio-refactoring: one common AUDIO_MAX_VOICES define for all audio-drivers * audio-chibios-pwm: pwm-pin-allternate: make the the timer, timer-channel and alternate function user-#definable * audio_chibios_dac: math.h has fmod for this * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback update Jack Humberts dac-example keymaps for the slight changes in the audio-dac interface * audio-refactoring: use a common AUDIO_PIN configuration switch instead of defines have the user select a pin by configuration in rules.mk instead of a define in config.h has the advantage of beeing in a common form/pattern across all audio-driver implementations * audio-refactoring: switch backlight_avr.c to the new AUDIO_PIN defines * audio-common: have advance_note return a boolean if the note changed, to the next one in the melody beeing played * audio-chibios-pwm: fix issue with ~130ms silence between note/frequency changes while playing a SONG through trial,error and a scope/logic analyzer figured out Chibios-PWMDriver (at least in the current version) misbehaves if the initial period is set to zero (or one; two seems to work); when thats the case subsequent calls to 'pwmChhangePeriod' + pwmEnableChannel took ~135ms of silence, before the PWM continued with the new frequency... * audio-refactoring: get 'play_note' working again with a limited number of available voices (say AUDIO_VOICES_MAX=1) allow new frequencies to be played, by discarding the oldest one in the 'frequencies' queue * audio: set the fallback driver to DAC for chibios and PWM for all others (==avr at the moment) * audio-refactoring: moore documentation and some cleanup * audio-avr-pwm: no fallback on unset AUDIO_PIN this seems to be the expected behaviour by some keyboards (looking at ckeys/handwire_101:default) which otherwise fail to build because the firmware-image ends up beeing too large for the atmega... so we fail silently instead to keep travis happy * audio-refactoring: untangling terminology: voice->tone the code actually was working on tones (combination of pitch/frequency, duration, timbre, intensity/volume) and not voices (characteristic sound of an instrument; think piano vs guitar, which can be played together, each having its own "track" = voice on a music sheet) * audio-pwm: allow freq=0 aka a pause/rest in a SONG continue processing, but do not enable pwm units, since freq=0 wouldn't produce any sound anyway (and lead to division by zero on that occasion) * audio-refactoring: audio_advance_note -> audio_advance_state since it does not only affect 'one note', but the internally kept state as a whole * audio-refactoring: untangling terminology: polyphony the feature om the "inherited" avr code has little to do with polyphony (see wikipedia), but is more a time-multiplexing feature, to work around hardware limitations - like only having one pwm channel, that could on its own only reproduce one voice/instrument at a time * audio-chibios-dac: add zero-crossing feature have tones only change/stop when the waveform approaches zero - to avoid audible clicks note that this also requires the samples to start at zero, since the internally kept index into the samples is reset to zero too * audio-refactoring: feature: time-multiplexing of tones on a single output channel this feature was in the original avr-pwm implementation misnomed as "polyphony" with polyphony_rate and so on; did the same thing though: time-multiplexing multiple active notes so that a single output channel could reproduce more than one note at a time (which is not the same as a polyphony - see wikipedia :-) ) * audio-avr-pwm: get music-mode working (again) on AVRs with both pwm channels, or either one of the two :-) play_notes worked already - but music_mode uses play_note * audio-refactoring: split define MAX_SIMULTANEOUS_TONES -> TONE_STACKSIZE since the two cases are independant from one another, the hardware might impose limitations on the number of simultaneously reproducable tones, but the audio state should be able to track an unrelated number of notes recently started by play_note * audio-arm-dac: per define selectable sample-luts plus generation script in ./util * audio-refactoring: heh, avr has a MIN... * audio-refactoring: add basic dac audio-driver based on the current/master implementation whereas current=d96380e65496912e0f68e6531565f4b45efd1623 which is the state of things before this whole audio-refactoring branch boiled down to interface with the refactored audio system = removing all redundant state-managing and frequency calculation * audio-refactoring: rename audio-drivers to driver_$PLATFORM_$DRIVER * audio-arm-pwm: split the software/hardware implementations into separate files which saves us partially from a 'define hell', with the tradeoff that now two somewhat similar chibios_pwm implementations have to be maintained * audio-refactoring: update documentation * audio-arm-dac: apply AUDIO_PIN defines to driver_chibios_dac_basic * audio-arm-dac: dac_additive: stop the hardware when the last sample completed the audio system calls for a driver_stop, which is delayed until the current sample conversion finishes * audio-refactoring: make function-namespace consistent - all (public) audio functions start with audio_ - also refactoring play*_notes/tones to play*_melody, to visually distance it a bit from play*_tone/_note * audio-refactoring: consistent define namespace: DAC_ -> AUDIO_DAC_ * audio-arm-dac: update (inline) documentation regarding MAX for sample values * audio-chibios-dac: remove zero-crossing feature didn't quite work as intended anyway, and stopping the hardware on close-to-zero seems to be enought anyway * audio-arm-dac: dac_basic: respect the configured sample-rate * audio-arm-pwm: have 'note_timbre' influence the pwm-duty cycle like it already does in the avr implementation * audio-refactoring: get VIBRATO working (again) with all drivers (verified with chibios_[dac|pwm]) * audio-arm-dac: zero-crossing feature (Mk II) wait for the generated waveform to approach 'zero' before either turning off the output+timer or switching to the current set of active_tones * audio-refactoring: re-add note-resting -> introduce short_rest inbetween - introduce a short pause/rest between two notes of the same frequency, to separate them audibly - also updating the refactoring comments * audio-refactoring: cleanup refactoring remnants remove the former avr-isr code block - since all its features are now refactored into the different parts of the current system also updates the TODOS * audio-refactoring: reserve negative numbers as unitialized frequencies to allow the valid tone/frequency f=0Hz == rest/pause * audio-refactoring: FIX: first note of melody was missing the first note was missing because 'goto_next_note'=false overrode a state_change=true of the initial play_tone and some code-indentations/cleanup of related parts * audio-arm-dac: fix hardware init-click due to wron .init= value * audio-refactoring: new conveniance function: audio_play_click which can be used to further refactor/remove fauxclicky (avr only) and/or the 'clicky' features * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: consecutive notes of the same frequency get a pause inserted inbetween by audio.c * audio-refactoring: use milliseconds instead of seconds for 'click' parameters clicks are supposed to be short, seconds make little sense * audio-refactoring: use timer ticks instead of counters local counters were used in the original (avr)ISR to advance an index into the lookup tables (for vibrato), and something similar was used for the tone-multiplexing feature decoupling these from the (possibly irregular) calls to advance_state made sesne, since those counters/lookups need to be in relation to a wall-time anyway * audio-refactoring: voices.c: drop 'envelope_index' counter in favour of timer ticks * audio-refactoring: move vibrato and timbre related parts from audio.c to voices.c also drops the now (globally) unused AUDIO_VIBRATO/AUDIO_ENABLE_VIBRATO defines * audio.c: use system-ticks instead of counters the drivers have to take care of for the internal state posision since there already is a system-tick with ms resolution, keeping count separatly with each driver implementation makes little sense; especially since they had to take special care to call audio_advance_state with the correct step/end parameters for the audio state to advance regularly and with the correct pace * audio.c: stop notes after new ones have been started avoids brief states of with no notes playing that would otherwise stop the hardware and might lead to clicks * audio.c: bugfix: actually play a pause instead of just idling/stopping which lead the pwm drivers to stop entirely... * audio-arm-pwm: pwm-software: add inverted output new define AUDIO_PIN_ALT_AS_NEGATIVE will generate an inverted signal on the alternate pin, which boosts the volume if a piezo is connected to both AUDIO_PIN and AUDIO_PIN_ALT * audio-arm-dac: basic: handle piezo configured&wired to both audio pins * audio-refactoring: docs: update for AUDIO_PIN_ALT_AS_NEGATIVE and piezo wiring * audio.c: bugfix: use timer_elapsed32 instad of keeping timestamps avoids running into issues when the uint32 of the timer overflows * audio-refactoring: add 'pragma once' and remove deprecated NOTE_REST * audio_arm_dac: basic: add missing bracket * audio.c: fix delta calculation was in the wrong place, needs to use the 'last_timestamp' before it was reset * audio-refactoring: buildfix: wrong legacy macro for set_timbre * audio.c: 16bit timerstamps suffice * audio-refactoring: separate includes for AVR and chibios * audio-refactoring: timbre: use uint8 instead of float * audio-refactoring: duration: use uint16 for internal per-tone/note state * audio-refactoring: tonemultiplexing: use uint16 instead of float * audio-arm-dac: additive: set second pin output-low used when a piezo is connected to AUDIO_PIN and AUDIO_PIN_ALT, with PIN_ALT_AS_NEGATIVE * audio-refactoring: move AUDIO_PIN selection from rules.mk to config.h to be consistent with how other features are handled in QMK * audio-refactoring: buildfix: wrong legacy macro for set_tempo * audio-arm-dac: additive: set second pin output-low -- FIXUP * audio.c: do duration<>ms conversion in uint instead of float on AVR, to save a couple of bytes in the firmware size * audio-refactoring: cleanup eeprom defines/usage for ARM, avr is handled automagically through the avr libc and common_features.mk Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio.h: throw an error if OFF is larger than MAX * audio-arm-dac: basic: actually stop the dac-conversion on a audio_driver_stop to put the output pin in a known state == AUDIO_DAC_OFF_VALUE, instead of just leaving them where the last conversion was... with AUDIO_PIN_ALT_AS_NEGATIVE this meant one output was left HIGH while the other was left LOW one CAVEAT: due to this change the opposing squarewave when using both A4 and A5 with AUDIO_PIN_ALT_AS_NEGATIVE show extra pulses at the beginning/end on one of the outputs, the two waveforms are in sync otherwise. the extra pusles probably matter little, since this is no high-fidelity sound generation :P * audio-arm-dac: additive: move zero-crossing code out of dac_value_generate which is/should be user-overridable == simple, and doing one thing: providing sample values state-transitions necessary for the zero crossing are better handled in the surrounding loop in the dac_end callback * audio-arm-dac: dac-additive: zero-crossing: ramping up or down after a start trigger ramp up: generate values until zero=OFF_VALUE is reached, then continue normally same in reverse for strop trigger: output values until zero is reached/crossed, then keep OFF_VALUE on the output * audio-arm-dac: dac-additive: BUGFIX: return OFF_VALUE when a pause is playing fixes a bug during SONG playback, which suddenly stopped when it encoutnered a pause * audio-arm-dac: set a sensible default for AUDIO_DAC_VALUE_OFF 1/2 MAX was probably exemplary, can't think of a setup where that would make sense :-P * audio-arm-dac: update synth_sample/_wavetable for new pin-defines * audio-arm-dac: default for AUDIO_DAC_VALUE_OFF turned out that zero or max are bad default choices: when multiple tones are played (>>5) and released at the same time (!), due to the complex waveform never reaching 'zero' the output can take quite a while to reach zero, and hence the zero-crossing code only "releases" the output waaay to late * audio-arm-dac: additive: use DAC for negative pin instead of PAL, which only allows the pin to be configured as output; LOW or HIGH * audio-arm-dac: more compile-time configuration checks * audio-refactoring: typo fixed * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: add defines for B-pin as primary/only speaker also updates documentation. * audio-refactoring: update documentation with proton-c config.h example * audio-refactoring: move glissando (TODO) to voices.c refactored/saved from the original glissando implementation in then upstream-master:audio_avr.c still needs some work though, as it is now the calculation *should* work, but the start-frequency needs to be tracked somewhere/somehow; not only during a SONG playback but also with user input? * audio-refactoring: cleanup: one round of aspell -c * audio-avr-pwm: back to AUDIO_PIN since config_common.h expands them to plain integers, the AUDIO_PIN define can directly be compared to e.g. B5 so there is no need to deal with separate defines like AUDIO_PIN_B5 * audio-refactoring: add technical documentation audio_driver.md which moves some in-code documentation there * audio-arm-dac: move AUDIO_PIN checks into c-code instead of doing everything with the preprocessor, since A4/A5 do not expand to simple integers, preprocessor int-comparison is not possible. but necessary to get a consistent configuration scheme going throughout the audio-code... solution: let c-code handle the different AUDIO_PIN configurations instead (and leave code/size optimizations to the compiler) * audio-arm-dac: compile-fix: set AUDIO_PIN if unset workaround to get the build going again, and be backwarts compatible to arm-keyboards which not yet set the AUDIO_PIN define. until the define is enforced through an '#error" * audio-refactoring: document tone-multiplexing feature * audio-refactoring: Apply suggestions from documentation review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-refactoring: Update docs/audio_driver.md * audio-refactoring: docs: fix markdown newlines Terminating a line in Markdown with <space>-<space>-<linebreak> creates an HTML single-line break (<br>). Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-arm-dac: additive: fix AUDIO_PIN_ALT handling * audio-arm-pwm: align define naming with other drivers Co-authored-by: Joel Challis <git@zvecr.com> * audio-refactoring: set detault tempo to 120 and add documentation for the override * audio-refactoring: update backlight define checks to new AUDIO_PIN names * audio-refactoring: reworking PWM related defines to be more consistent with other QMK code Co-authored-by: Joel Challis <git@zvecr.com> * audio-arm: have the state-update-timer user configurable defaulting to GPTD6 or GPTD8 for stm32f2+ (=proton-c) stm32f1 might need to set this to GPTD4, since 6 and 8 are not available * audio-refactoring: PLAY_NOTE_ARRAY was already removed in master * Add prototype for startup * Update chibiOS dac basic to disable pins on stop * Add defaults for Proton C * avoid hanging audio if note is completely missed * Don't redefine pins if they're already defined * Define A4 and A5 for CTPC support * Add license headers to keymap files * Remove figlet? comments * Add DAC config to audio driver docs * Apply suggestions from code review Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Add license header to py files * correct license header * Add JohSchneider's name to modified files AKA credit where credit's due * Set executable permission and change interpeter * Add 'wave' to pip requirements * Improve documentation * Add some settings I missed * Strip AUDIO_DRIVER to parse the name correctly * fix depreciated * Update util/audio_generate_dac_lut.py Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Fix type in clueboard config * Apply suggestions from tzarc Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Johannes <you@example.com> Co-authored-by: JohSchneider <JohSchneider@googlemail.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Joshua Diamond <josh@windowoffire.com> Co-authored-by: Jack Humbert <jack.humb@gmail.com>
3 years ago
Audio system overhaul (#11820) * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commits bundles the changes from the arm-dac-work branch focused on audio/audio_arm.* into one commit (leaving out the test-keyboard) f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both -> only the changes on audio_arm_.*, the keyboard related parts are split off to a separate commit bfe468ef1 start morphing wavetable 474d100b5 refined a bit 208bee10f play_notes working 3e6478b0b start in-place documentation of dac settings 3e1826a33 fixed blip (rounding error), other waves, added key selection (left/right) 73853d651 5 voices at 44.1khz dfb401b95 limit voices to working number 9632b3379 configuration for the ez 6241f3f3b notes working in a new way * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commit splits off the plank example keymap from commit f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both * refactoring: rename audio_ to reflect their supported hardware-platform and audio-generation method: avr vs arm, and pwm vs dac * refactoring: deducplicate ISR code to update the pwm duty-cycle and period in the avr-pwm-implementation pulls three copies of the same code into one function which should improve readability and maintainability :-) * refactoring: move common code of arm and avr implementation into a separate/new file * refactoring: audio_avr_pwm, renaming defines to decouple them from actually used timers, registers and ISRs * refactoring: audio_avr_pwm - replacing function defines with plain register defines aligns better with other existing qmk code (and the new audio_arm_pwm) doing similar pwm thing * add audio-arm-pwm since not all STM32 have a DAC onboard (STM32F2xx and STM32F3xx), pwm-audio is an alternative (STM32F1xx) this code works on a "BluePill" clone, with an STM32F103C8B * clang-format changes on quantum/audio/* only * audio_arm_dac: stopping the notes caused screeching when using the DAC audio paths * audio_arm_pwm: use pushpull on the pin; so that a piezzo can be hooked up direclty without additional components (opendrain would require an external pullup) * refactoring: remove unused file from/for atmel-avr chips * refactoring: remove unused (avr) wavetable file * audio_arm_dac: adapt dac_end callback to changed chibios DAC api the previous chibios (17.6.0) passed along a pointer into the buffer plus a sample_count (which are/already where included in the DACDrivre object) - the current chibios (19.1.0) only passes the driver object. this patch ports more or less exactly what the previous chibios ISR code did: either have the user-callback work the first or second half of the buffer (dacsample_t pointer, with half the DAC_BUFFER_SIZE samples) by adjusting the pointer and sample count * audio-arm-dac: show a compile-warning on undefined audio-pins Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio_arm_dac: switch from exemplary wavetable generation to sine only sine+triangle+squrare is exemplary, and not realy fit for "production" use 'stairs' are usefull for debugging (hardware, with an oscilloscope) * audio_arm_dac: enable output buffers in the STM32 to drive external loads without any additional ciruitry - external opamps and such * audio: prevent out-of-bounds array access * audio_arm_dac: add output-frequency correcting factor * audio_arm_pwm: get both the alternate-function and pm-callback variants back into working condition and do some code-cleanup, refine documentation, ... * audio_arm_pwm: increase pwm frequency for "higher fidelity" on the previous .frequency=100000 higher frequency musical notes came out wrong (frequency measured on a Tektronix TDS2014B) note | freq | arm-pwm C2 | 65.4 | 65.491 C5 | 523.25 | 523.93 C6 | 1046.5 | 1053.38 C7 | 2093 | 2129 C8 | 4186 | 4350.91 with .frequency = 500000 C8 | 4186 | 4204.6 * audio refactoring: remove unused variables * audio_arm_dac: calibrate note tempo: with a tempo of 60beats-per-second a whole-note should last for exactly one second * audio: allow feature selection in rules.mk so the user can switch the audio driver between DAC and PWM on STM32 boards which support both (STM32F2 and up) or select the "pin alternate" pwm mode, for example on STM32F103 * audio-refactoring: move codeblocks in audio.[ch] into more coherent groups and add some inline documentation * audio-refactoring: cleanup and streamline common code between audio_arm_[dac|pwm] untangeling the relation between audio.c and the two drivers and adding more documenting comments :-) * audio_avr_pwm: getting it back into working condition, and cleanup+refactor * audio-refactoring: documentation and typo fixes Co-Authored-By: Nick Brassel <nick@tzarc.org> * audio-refactoring: cleanup defines, inludes and remove debug-prints * audio_chibios_dac: define&use a minimal sampling rate, based on the available tone-range to ease up on the cpu-load, while still rendering the higher notes/tones sufficiently also reenable the lower tones, since with the new implementation there is no evidence of them still beeing 'bugged' * audio-refactoring: one common AUDIO_MAX_VOICES define for all audio-drivers * audio-chibios-pwm: pwm-pin-allternate: make the the timer, timer-channel and alternate function user-#definable * audio_chibios_dac: math.h has fmod for this * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback update Jack Humberts dac-example keymaps for the slight changes in the audio-dac interface * audio-refactoring: use a common AUDIO_PIN configuration switch instead of defines have the user select a pin by configuration in rules.mk instead of a define in config.h has the advantage of beeing in a common form/pattern across all audio-driver implementations * audio-refactoring: switch backlight_avr.c to the new AUDIO_PIN defines * audio-common: have advance_note return a boolean if the note changed, to the next one in the melody beeing played * audio-chibios-pwm: fix issue with ~130ms silence between note/frequency changes while playing a SONG through trial,error and a scope/logic analyzer figured out Chibios-PWMDriver (at least in the current version) misbehaves if the initial period is set to zero (or one; two seems to work); when thats the case subsequent calls to 'pwmChhangePeriod' + pwmEnableChannel took ~135ms of silence, before the PWM continued with the new frequency... * audio-refactoring: get 'play_note' working again with a limited number of available voices (say AUDIO_VOICES_MAX=1) allow new frequencies to be played, by discarding the oldest one in the 'frequencies' queue * audio: set the fallback driver to DAC for chibios and PWM for all others (==avr at the moment) * audio-refactoring: moore documentation and some cleanup * audio-avr-pwm: no fallback on unset AUDIO_PIN this seems to be the expected behaviour by some keyboards (looking at ckeys/handwire_101:default) which otherwise fail to build because the firmware-image ends up beeing too large for the atmega... so we fail silently instead to keep travis happy * audio-refactoring: untangling terminology: voice->tone the code actually was working on tones (combination of pitch/frequency, duration, timbre, intensity/volume) and not voices (characteristic sound of an instrument; think piano vs guitar, which can be played together, each having its own "track" = voice on a music sheet) * audio-pwm: allow freq=0 aka a pause/rest in a SONG continue processing, but do not enable pwm units, since freq=0 wouldn't produce any sound anyway (and lead to division by zero on that occasion) * audio-refactoring: audio_advance_note -> audio_advance_state since it does not only affect 'one note', but the internally kept state as a whole * audio-refactoring: untangling terminology: polyphony the feature om the "inherited" avr code has little to do with polyphony (see wikipedia), but is more a time-multiplexing feature, to work around hardware limitations - like only having one pwm channel, that could on its own only reproduce one voice/instrument at a time * audio-chibios-dac: add zero-crossing feature have tones only change/stop when the waveform approaches zero - to avoid audible clicks note that this also requires the samples to start at zero, since the internally kept index into the samples is reset to zero too * audio-refactoring: feature: time-multiplexing of tones on a single output channel this feature was in the original avr-pwm implementation misnomed as "polyphony" with polyphony_rate and so on; did the same thing though: time-multiplexing multiple active notes so that a single output channel could reproduce more than one note at a time (which is not the same as a polyphony - see wikipedia :-) ) * audio-avr-pwm: get music-mode working (again) on AVRs with both pwm channels, or either one of the two :-) play_notes worked already - but music_mode uses play_note * audio-refactoring: split define MAX_SIMULTANEOUS_TONES -> TONE_STACKSIZE since the two cases are independant from one another, the hardware might impose limitations on the number of simultaneously reproducable tones, but the audio state should be able to track an unrelated number of notes recently started by play_note * audio-arm-dac: per define selectable sample-luts plus generation script in ./util * audio-refactoring: heh, avr has a MIN... * audio-refactoring: add basic dac audio-driver based on the current/master implementation whereas current=d96380e65496912e0f68e6531565f4b45efd1623 which is the state of things before this whole audio-refactoring branch boiled down to interface with the refactored audio system = removing all redundant state-managing and frequency calculation * audio-refactoring: rename audio-drivers to driver_$PLATFORM_$DRIVER * audio-arm-pwm: split the software/hardware implementations into separate files which saves us partially from a 'define hell', with the tradeoff that now two somewhat similar chibios_pwm implementations have to be maintained * audio-refactoring: update documentation * audio-arm-dac: apply AUDIO_PIN defines to driver_chibios_dac_basic * audio-arm-dac: dac_additive: stop the hardware when the last sample completed the audio system calls for a driver_stop, which is delayed until the current sample conversion finishes * audio-refactoring: make function-namespace consistent - all (public) audio functions start with audio_ - also refactoring play*_notes/tones to play*_melody, to visually distance it a bit from play*_tone/_note * audio-refactoring: consistent define namespace: DAC_ -> AUDIO_DAC_ * audio-arm-dac: update (inline) documentation regarding MAX for sample values * audio-chibios-dac: remove zero-crossing feature didn't quite work as intended anyway, and stopping the hardware on close-to-zero seems to be enought anyway * audio-arm-dac: dac_basic: respect the configured sample-rate * audio-arm-pwm: have 'note_timbre' influence the pwm-duty cycle like it already does in the avr implementation * audio-refactoring: get VIBRATO working (again) with all drivers (verified with chibios_[dac|pwm]) * audio-arm-dac: zero-crossing feature (Mk II) wait for the generated waveform to approach 'zero' before either turning off the output+timer or switching to the current set of active_tones * audio-refactoring: re-add note-resting -> introduce short_rest inbetween - introduce a short pause/rest between two notes of the same frequency, to separate them audibly - also updating the refactoring comments * audio-refactoring: cleanup refactoring remnants remove the former avr-isr code block - since all its features are now refactored into the different parts of the current system also updates the TODOS * audio-refactoring: reserve negative numbers as unitialized frequencies to allow the valid tone/frequency f=0Hz == rest/pause * audio-refactoring: FIX: first note of melody was missing the first note was missing because 'goto_next_note'=false overrode a state_change=true of the initial play_tone and some code-indentations/cleanup of related parts * audio-arm-dac: fix hardware init-click due to wron .init= value * audio-refactoring: new conveniance function: audio_play_click which can be used to further refactor/remove fauxclicky (avr only) and/or the 'clicky' features * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: consecutive notes of the same frequency get a pause inserted inbetween by audio.c * audio-refactoring: use milliseconds instead of seconds for 'click' parameters clicks are supposed to be short, seconds make little sense * audio-refactoring: use timer ticks instead of counters local counters were used in the original (avr)ISR to advance an index into the lookup tables (for vibrato), and something similar was used for the tone-multiplexing feature decoupling these from the (possibly irregular) calls to advance_state made sesne, since those counters/lookups need to be in relation to a wall-time anyway * audio-refactoring: voices.c: drop 'envelope_index' counter in favour of timer ticks * audio-refactoring: move vibrato and timbre related parts from audio.c to voices.c also drops the now (globally) unused AUDIO_VIBRATO/AUDIO_ENABLE_VIBRATO defines * audio.c: use system-ticks instead of counters the drivers have to take care of for the internal state posision since there already is a system-tick with ms resolution, keeping count separatly with each driver implementation makes little sense; especially since they had to take special care to call audio_advance_state with the correct step/end parameters for the audio state to advance regularly and with the correct pace * audio.c: stop notes after new ones have been started avoids brief states of with no notes playing that would otherwise stop the hardware and might lead to clicks * audio.c: bugfix: actually play a pause instead of just idling/stopping which lead the pwm drivers to stop entirely... * audio-arm-pwm: pwm-software: add inverted output new define AUDIO_PIN_ALT_AS_NEGATIVE will generate an inverted signal on the alternate pin, which boosts the volume if a piezo is connected to both AUDIO_PIN and AUDIO_PIN_ALT * audio-arm-dac: basic: handle piezo configured&wired to both audio pins * audio-refactoring: docs: update for AUDIO_PIN_ALT_AS_NEGATIVE and piezo wiring * audio.c: bugfix: use timer_elapsed32 instad of keeping timestamps avoids running into issues when the uint32 of the timer overflows * audio-refactoring: add 'pragma once' and remove deprecated NOTE_REST * audio_arm_dac: basic: add missing bracket * audio.c: fix delta calculation was in the wrong place, needs to use the 'last_timestamp' before it was reset * audio-refactoring: buildfix: wrong legacy macro for set_timbre * audio.c: 16bit timerstamps suffice * audio-refactoring: separate includes for AVR and chibios * audio-refactoring: timbre: use uint8 instead of float * audio-refactoring: duration: use uint16 for internal per-tone/note state * audio-refactoring: tonemultiplexing: use uint16 instead of float * audio-arm-dac: additive: set second pin output-low used when a piezo is connected to AUDIO_PIN and AUDIO_PIN_ALT, with PIN_ALT_AS_NEGATIVE * audio-refactoring: move AUDIO_PIN selection from rules.mk to config.h to be consistent with how other features are handled in QMK * audio-refactoring: buildfix: wrong legacy macro for set_tempo * audio-arm-dac: additive: set second pin output-low -- FIXUP * audio.c: do duration<>ms conversion in uint instead of float on AVR, to save a couple of bytes in the firmware size * audio-refactoring: cleanup eeprom defines/usage for ARM, avr is handled automagically through the avr libc and common_features.mk Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio.h: throw an error if OFF is larger than MAX * audio-arm-dac: basic: actually stop the dac-conversion on a audio_driver_stop to put the output pin in a known state == AUDIO_DAC_OFF_VALUE, instead of just leaving them where the last conversion was... with AUDIO_PIN_ALT_AS_NEGATIVE this meant one output was left HIGH while the other was left LOW one CAVEAT: due to this change the opposing squarewave when using both A4 and A5 with AUDIO_PIN_ALT_AS_NEGATIVE show extra pulses at the beginning/end on one of the outputs, the two waveforms are in sync otherwise. the extra pusles probably matter little, since this is no high-fidelity sound generation :P * audio-arm-dac: additive: move zero-crossing code out of dac_value_generate which is/should be user-overridable == simple, and doing one thing: providing sample values state-transitions necessary for the zero crossing are better handled in the surrounding loop in the dac_end callback * audio-arm-dac: dac-additive: zero-crossing: ramping up or down after a start trigger ramp up: generate values until zero=OFF_VALUE is reached, then continue normally same in reverse for strop trigger: output values until zero is reached/crossed, then keep OFF_VALUE on the output * audio-arm-dac: dac-additive: BUGFIX: return OFF_VALUE when a pause is playing fixes a bug during SONG playback, which suddenly stopped when it encoutnered a pause * audio-arm-dac: set a sensible default for AUDIO_DAC_VALUE_OFF 1/2 MAX was probably exemplary, can't think of a setup where that would make sense :-P * audio-arm-dac: update synth_sample/_wavetable for new pin-defines * audio-arm-dac: default for AUDIO_DAC_VALUE_OFF turned out that zero or max are bad default choices: when multiple tones are played (>>5) and released at the same time (!), due to the complex waveform never reaching 'zero' the output can take quite a while to reach zero, and hence the zero-crossing code only "releases" the output waaay to late * audio-arm-dac: additive: use DAC for negative pin instead of PAL, which only allows the pin to be configured as output; LOW or HIGH * audio-arm-dac: more compile-time configuration checks * audio-refactoring: typo fixed * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: add defines for B-pin as primary/only speaker also updates documentation. * audio-refactoring: update documentation with proton-c config.h example * audio-refactoring: move glissando (TODO) to voices.c refactored/saved from the original glissando implementation in then upstream-master:audio_avr.c still needs some work though, as it is now the calculation *should* work, but the start-frequency needs to be tracked somewhere/somehow; not only during a SONG playback but also with user input? * audio-refactoring: cleanup: one round of aspell -c * audio-avr-pwm: back to AUDIO_PIN since config_common.h expands them to plain integers, the AUDIO_PIN define can directly be compared to e.g. B5 so there is no need to deal with separate defines like AUDIO_PIN_B5 * audio-refactoring: add technical documentation audio_driver.md which moves some in-code documentation there * audio-arm-dac: move AUDIO_PIN checks into c-code instead of doing everything with the preprocessor, since A4/A5 do not expand to simple integers, preprocessor int-comparison is not possible. but necessary to get a consistent configuration scheme going throughout the audio-code... solution: let c-code handle the different AUDIO_PIN configurations instead (and leave code/size optimizations to the compiler) * audio-arm-dac: compile-fix: set AUDIO_PIN if unset workaround to get the build going again, and be backwarts compatible to arm-keyboards which not yet set the AUDIO_PIN define. until the define is enforced through an '#error" * audio-refactoring: document tone-multiplexing feature * audio-refactoring: Apply suggestions from documentation review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-refactoring: Update docs/audio_driver.md * audio-refactoring: docs: fix markdown newlines Terminating a line in Markdown with <space>-<space>-<linebreak> creates an HTML single-line break (<br>). Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-arm-dac: additive: fix AUDIO_PIN_ALT handling * audio-arm-pwm: align define naming with other drivers Co-authored-by: Joel Challis <git@zvecr.com> * audio-refactoring: set detault tempo to 120 and add documentation for the override * audio-refactoring: update backlight define checks to new AUDIO_PIN names * audio-refactoring: reworking PWM related defines to be more consistent with other QMK code Co-authored-by: Joel Challis <git@zvecr.com> * audio-arm: have the state-update-timer user configurable defaulting to GPTD6 or GPTD8 for stm32f2+ (=proton-c) stm32f1 might need to set this to GPTD4, since 6 and 8 are not available * audio-refactoring: PLAY_NOTE_ARRAY was already removed in master * Add prototype for startup * Update chibiOS dac basic to disable pins on stop * Add defaults for Proton C * avoid hanging audio if note is completely missed * Don't redefine pins if they're already defined * Define A4 and A5 for CTPC support * Add license headers to keymap files * Remove figlet? comments * Add DAC config to audio driver docs * Apply suggestions from code review Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Add license header to py files * correct license header * Add JohSchneider's name to modified files AKA credit where credit's due * Set executable permission and change interpeter * Add 'wave' to pip requirements * Improve documentation * Add some settings I missed * Strip AUDIO_DRIVER to parse the name correctly * fix depreciated * Update util/audio_generate_dac_lut.py Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Fix type in clueboard config * Apply suggestions from tzarc Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Johannes <you@example.com> Co-authored-by: JohSchneider <JohSchneider@googlemail.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Joshua Diamond <josh@windowoffire.com> Co-authored-by: Jack Humbert <jack.humb@gmail.com>
3 years ago
Audio system overhaul (#11820) * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commits bundles the changes from the arm-dac-work branch focused on audio/audio_arm.* into one commit (leaving out the test-keyboard) f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both -> only the changes on audio_arm_.*, the keyboard related parts are split off to a separate commit bfe468ef1 start morphing wavetable 474d100b5 refined a bit 208bee10f play_notes working 3e6478b0b start in-place documentation of dac settings 3e1826a33 fixed blip (rounding error), other waves, added key selection (left/right) 73853d651 5 voices at 44.1khz dfb401b95 limit voices to working number 9632b3379 configuration for the ez 6241f3f3b notes working in a new way * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commit splits off the plank example keymap from commit f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both * refactoring: rename audio_ to reflect their supported hardware-platform and audio-generation method: avr vs arm, and pwm vs dac * refactoring: deducplicate ISR code to update the pwm duty-cycle and period in the avr-pwm-implementation pulls three copies of the same code into one function which should improve readability and maintainability :-) * refactoring: move common code of arm and avr implementation into a separate/new file * refactoring: audio_avr_pwm, renaming defines to decouple them from actually used timers, registers and ISRs * refactoring: audio_avr_pwm - replacing function defines with plain register defines aligns better with other existing qmk code (and the new audio_arm_pwm) doing similar pwm thing * add audio-arm-pwm since not all STM32 have a DAC onboard (STM32F2xx and STM32F3xx), pwm-audio is an alternative (STM32F1xx) this code works on a "BluePill" clone, with an STM32F103C8B * clang-format changes on quantum/audio/* only * audio_arm_dac: stopping the notes caused screeching when using the DAC audio paths * audio_arm_pwm: use pushpull on the pin; so that a piezzo can be hooked up direclty without additional components (opendrain would require an external pullup) * refactoring: remove unused file from/for atmel-avr chips * refactoring: remove unused (avr) wavetable file * audio_arm_dac: adapt dac_end callback to changed chibios DAC api the previous chibios (17.6.0) passed along a pointer into the buffer plus a sample_count (which are/already where included in the DACDrivre object) - the current chibios (19.1.0) only passes the driver object. this patch ports more or less exactly what the previous chibios ISR code did: either have the user-callback work the first or second half of the buffer (dacsample_t pointer, with half the DAC_BUFFER_SIZE samples) by adjusting the pointer and sample count * audio-arm-dac: show a compile-warning on undefined audio-pins Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio_arm_dac: switch from exemplary wavetable generation to sine only sine+triangle+squrare is exemplary, and not realy fit for "production" use 'stairs' are usefull for debugging (hardware, with an oscilloscope) * audio_arm_dac: enable output buffers in the STM32 to drive external loads without any additional ciruitry - external opamps and such * audio: prevent out-of-bounds array access * audio_arm_dac: add output-frequency correcting factor * audio_arm_pwm: get both the alternate-function and pm-callback variants back into working condition and do some code-cleanup, refine documentation, ... * audio_arm_pwm: increase pwm frequency for "higher fidelity" on the previous .frequency=100000 higher frequency musical notes came out wrong (frequency measured on a Tektronix TDS2014B) note | freq | arm-pwm C2 | 65.4 | 65.491 C5 | 523.25 | 523.93 C6 | 1046.5 | 1053.38 C7 | 2093 | 2129 C8 | 4186 | 4350.91 with .frequency = 500000 C8 | 4186 | 4204.6 * audio refactoring: remove unused variables * audio_arm_dac: calibrate note tempo: with a tempo of 60beats-per-second a whole-note should last for exactly one second * audio: allow feature selection in rules.mk so the user can switch the audio driver between DAC and PWM on STM32 boards which support both (STM32F2 and up) or select the "pin alternate" pwm mode, for example on STM32F103 * audio-refactoring: move codeblocks in audio.[ch] into more coherent groups and add some inline documentation * audio-refactoring: cleanup and streamline common code between audio_arm_[dac|pwm] untangeling the relation between audio.c and the two drivers and adding more documenting comments :-) * audio_avr_pwm: getting it back into working condition, and cleanup+refactor * audio-refactoring: documentation and typo fixes Co-Authored-By: Nick Brassel <nick@tzarc.org> * audio-refactoring: cleanup defines, inludes and remove debug-prints * audio_chibios_dac: define&use a minimal sampling rate, based on the available tone-range to ease up on the cpu-load, while still rendering the higher notes/tones sufficiently also reenable the lower tones, since with the new implementation there is no evidence of them still beeing 'bugged' * audio-refactoring: one common AUDIO_MAX_VOICES define for all audio-drivers * audio-chibios-pwm: pwm-pin-allternate: make the the timer, timer-channel and alternate function user-#definable * audio_chibios_dac: math.h has fmod for this * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback update Jack Humberts dac-example keymaps for the slight changes in the audio-dac interface * audio-refactoring: use a common AUDIO_PIN configuration switch instead of defines have the user select a pin by configuration in rules.mk instead of a define in config.h has the advantage of beeing in a common form/pattern across all audio-driver implementations * audio-refactoring: switch backlight_avr.c to the new AUDIO_PIN defines * audio-common: have advance_note return a boolean if the note changed, to the next one in the melody beeing played * audio-chibios-pwm: fix issue with ~130ms silence between note/frequency changes while playing a SONG through trial,error and a scope/logic analyzer figured out Chibios-PWMDriver (at least in the current version) misbehaves if the initial period is set to zero (or one; two seems to work); when thats the case subsequent calls to 'pwmChhangePeriod' + pwmEnableChannel took ~135ms of silence, before the PWM continued with the new frequency... * audio-refactoring: get 'play_note' working again with a limited number of available voices (say AUDIO_VOICES_MAX=1) allow new frequencies to be played, by discarding the oldest one in the 'frequencies' queue * audio: set the fallback driver to DAC for chibios and PWM for all others (==avr at the moment) * audio-refactoring: moore documentation and some cleanup * audio-avr-pwm: no fallback on unset AUDIO_PIN this seems to be the expected behaviour by some keyboards (looking at ckeys/handwire_101:default) which otherwise fail to build because the firmware-image ends up beeing too large for the atmega... so we fail silently instead to keep travis happy * audio-refactoring: untangling terminology: voice->tone the code actually was working on tones (combination of pitch/frequency, duration, timbre, intensity/volume) and not voices (characteristic sound of an instrument; think piano vs guitar, which can be played together, each having its own "track" = voice on a music sheet) * audio-pwm: allow freq=0 aka a pause/rest in a SONG continue processing, but do not enable pwm units, since freq=0 wouldn't produce any sound anyway (and lead to division by zero on that occasion) * audio-refactoring: audio_advance_note -> audio_advance_state since it does not only affect 'one note', but the internally kept state as a whole * audio-refactoring: untangling terminology: polyphony the feature om the "inherited" avr code has little to do with polyphony (see wikipedia), but is more a time-multiplexing feature, to work around hardware limitations - like only having one pwm channel, that could on its own only reproduce one voice/instrument at a time * audio-chibios-dac: add zero-crossing feature have tones only change/stop when the waveform approaches zero - to avoid audible clicks note that this also requires the samples to start at zero, since the internally kept index into the samples is reset to zero too * audio-refactoring: feature: time-multiplexing of tones on a single output channel this feature was in the original avr-pwm implementation misnomed as "polyphony" with polyphony_rate and so on; did the same thing though: time-multiplexing multiple active notes so that a single output channel could reproduce more than one note at a time (which is not the same as a polyphony - see wikipedia :-) ) * audio-avr-pwm: get music-mode working (again) on AVRs with both pwm channels, or either one of the two :-) play_notes worked already - but music_mode uses play_note * audio-refactoring: split define MAX_SIMULTANEOUS_TONES -> TONE_STACKSIZE since the two cases are independant from one another, the hardware might impose limitations on the number of simultaneously reproducable tones, but the audio state should be able to track an unrelated number of notes recently started by play_note * audio-arm-dac: per define selectable sample-luts plus generation script in ./util * audio-refactoring: heh, avr has a MIN... * audio-refactoring: add basic dac audio-driver based on the current/master implementation whereas current=d96380e65496912e0f68e6531565f4b45efd1623 which is the state of things before this whole audio-refactoring branch boiled down to interface with the refactored audio system = removing all redundant state-managing and frequency calculation * audio-refactoring: rename audio-drivers to driver_$PLATFORM_$DRIVER * audio-arm-pwm: split the software/hardware implementations into separate files which saves us partially from a 'define hell', with the tradeoff that now two somewhat similar chibios_pwm implementations have to be maintained * audio-refactoring: update documentation * audio-arm-dac: apply AUDIO_PIN defines to driver_chibios_dac_basic * audio-arm-dac: dac_additive: stop the hardware when the last sample completed the audio system calls for a driver_stop, which is delayed until the current sample conversion finishes * audio-refactoring: make function-namespace consistent - all (public) audio functions start with audio_ - also refactoring play*_notes/tones to play*_melody, to visually distance it a bit from play*_tone/_note * audio-refactoring: consistent define namespace: DAC_ -> AUDIO_DAC_ * audio-arm-dac: update (inline) documentation regarding MAX for sample values * audio-chibios-dac: remove zero-crossing feature didn't quite work as intended anyway, and stopping the hardware on close-to-zero seems to be enought anyway * audio-arm-dac: dac_basic: respect the configured sample-rate * audio-arm-pwm: have 'note_timbre' influence the pwm-duty cycle like it already does in the avr implementation * audio-refactoring: get VIBRATO working (again) with all drivers (verified with chibios_[dac|pwm]) * audio-arm-dac: zero-crossing feature (Mk II) wait for the generated waveform to approach 'zero' before either turning off the output+timer or switching to the current set of active_tones * audio-refactoring: re-add note-resting -> introduce short_rest inbetween - introduce a short pause/rest between two notes of the same frequency, to separate them audibly - also updating the refactoring comments * audio-refactoring: cleanup refactoring remnants remove the former avr-isr code block - since all its features are now refactored into the different parts of the current system also updates the TODOS * audio-refactoring: reserve negative numbers as unitialized frequencies to allow the valid tone/frequency f=0Hz == rest/pause * audio-refactoring: FIX: first note of melody was missing the first note was missing because 'goto_next_note'=false overrode a state_change=true of the initial play_tone and some code-indentations/cleanup of related parts * audio-arm-dac: fix hardware init-click due to wron .init= value * audio-refactoring: new conveniance function: audio_play_click which can be used to further refactor/remove fauxclicky (avr only) and/or the 'clicky' features * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: consecutive notes of the same frequency get a pause inserted inbetween by audio.c * audio-refactoring: use milliseconds instead of seconds for 'click' parameters clicks are supposed to be short, seconds make little sense * audio-refactoring: use timer ticks instead of counters local counters were used in the original (avr)ISR to advance an index into the lookup tables (for vibrato), and something similar was used for the tone-multiplexing feature decoupling these from the (possibly irregular) calls to advance_state made sesne, since those counters/lookups need to be in relation to a wall-time anyway * audio-refactoring: voices.c: drop 'envelope_index' counter in favour of timer ticks * audio-refactoring: move vibrato and timbre related parts from audio.c to voices.c also drops the now (globally) unused AUDIO_VIBRATO/AUDIO_ENABLE_VIBRATO defines * audio.c: use system-ticks instead of counters the drivers have to take care of for the internal state posision since there already is a system-tick with ms resolution, keeping count separatly with each driver implementation makes little sense; especially since they had to take special care to call audio_advance_state with the correct step/end parameters for the audio state to advance regularly and with the correct pace * audio.c: stop notes after new ones have been started avoids brief states of with no notes playing that would otherwise stop the hardware and might lead to clicks * audio.c: bugfix: actually play a pause instead of just idling/stopping which lead the pwm drivers to stop entirely... * audio-arm-pwm: pwm-software: add inverted output new define AUDIO_PIN_ALT_AS_NEGATIVE will generate an inverted signal on the alternate pin, which boosts the volume if a piezo is connected to both AUDIO_PIN and AUDIO_PIN_ALT * audio-arm-dac: basic: handle piezo configured&wired to both audio pins * audio-refactoring: docs: update for AUDIO_PIN_ALT_AS_NEGATIVE and piezo wiring * audio.c: bugfix: use timer_elapsed32 instad of keeping timestamps avoids running into issues when the uint32 of the timer overflows * audio-refactoring: add 'pragma once' and remove deprecated NOTE_REST * audio_arm_dac: basic: add missing bracket * audio.c: fix delta calculation was in the wrong place, needs to use the 'last_timestamp' before it was reset * audio-refactoring: buildfix: wrong legacy macro for set_timbre * audio.c: 16bit timerstamps suffice * audio-refactoring: separate includes for AVR and chibios * audio-refactoring: timbre: use uint8 instead of float * audio-refactoring: duration: use uint16 for internal per-tone/note state * audio-refactoring: tonemultiplexing: use uint16 instead of float * audio-arm-dac: additive: set second pin output-low used when a piezo is connected to AUDIO_PIN and AUDIO_PIN_ALT, with PIN_ALT_AS_NEGATIVE * audio-refactoring: move AUDIO_PIN selection from rules.mk to config.h to be consistent with how other features are handled in QMK * audio-refactoring: buildfix: wrong legacy macro for set_tempo * audio-arm-dac: additive: set second pin output-low -- FIXUP * audio.c: do duration<>ms conversion in uint instead of float on AVR, to save a couple of bytes in the firmware size * audio-refactoring: cleanup eeprom defines/usage for ARM, avr is handled automagically through the avr libc and common_features.mk Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio.h: throw an error if OFF is larger than MAX * audio-arm-dac: basic: actually stop the dac-conversion on a audio_driver_stop to put the output pin in a known state == AUDIO_DAC_OFF_VALUE, instead of just leaving them where the last conversion was... with AUDIO_PIN_ALT_AS_NEGATIVE this meant one output was left HIGH while the other was left LOW one CAVEAT: due to this change the opposing squarewave when using both A4 and A5 with AUDIO_PIN_ALT_AS_NEGATIVE show extra pulses at the beginning/end on one of the outputs, the two waveforms are in sync otherwise. the extra pusles probably matter little, since this is no high-fidelity sound generation :P * audio-arm-dac: additive: move zero-crossing code out of dac_value_generate which is/should be user-overridable == simple, and doing one thing: providing sample values state-transitions necessary for the zero crossing are better handled in the surrounding loop in the dac_end callback * audio-arm-dac: dac-additive: zero-crossing: ramping up or down after a start trigger ramp up: generate values until zero=OFF_VALUE is reached, then continue normally same in reverse for strop trigger: output values until zero is reached/crossed, then keep OFF_VALUE on the output * audio-arm-dac: dac-additive: BUGFIX: return OFF_VALUE when a pause is playing fixes a bug during SONG playback, which suddenly stopped when it encoutnered a pause * audio-arm-dac: set a sensible default for AUDIO_DAC_VALUE_OFF 1/2 MAX was probably exemplary, can't think of a setup where that would make sense :-P * audio-arm-dac: update synth_sample/_wavetable for new pin-defines * audio-arm-dac: default for AUDIO_DAC_VALUE_OFF turned out that zero or max are bad default choices: when multiple tones are played (>>5) and released at the same time (!), due to the complex waveform never reaching 'zero' the output can take quite a while to reach zero, and hence the zero-crossing code only "releases" the output waaay to late * audio-arm-dac: additive: use DAC for negative pin instead of PAL, which only allows the pin to be configured as output; LOW or HIGH * audio-arm-dac: more compile-time configuration checks * audio-refactoring: typo fixed * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: add defines for B-pin as primary/only speaker also updates documentation. * audio-refactoring: update documentation with proton-c config.h example * audio-refactoring: move glissando (TODO) to voices.c refactored/saved from the original glissando implementation in then upstream-master:audio_avr.c still needs some work though, as it is now the calculation *should* work, but the start-frequency needs to be tracked somewhere/somehow; not only during a SONG playback but also with user input? * audio-refactoring: cleanup: one round of aspell -c * audio-avr-pwm: back to AUDIO_PIN since config_common.h expands them to plain integers, the AUDIO_PIN define can directly be compared to e.g. B5 so there is no need to deal with separate defines like AUDIO_PIN_B5 * audio-refactoring: add technical documentation audio_driver.md which moves some in-code documentation there * audio-arm-dac: move AUDIO_PIN checks into c-code instead of doing everything with the preprocessor, since A4/A5 do not expand to simple integers, preprocessor int-comparison is not possible. but necessary to get a consistent configuration scheme going throughout the audio-code... solution: let c-code handle the different AUDIO_PIN configurations instead (and leave code/size optimizations to the compiler) * audio-arm-dac: compile-fix: set AUDIO_PIN if unset workaround to get the build going again, and be backwarts compatible to arm-keyboards which not yet set the AUDIO_PIN define. until the define is enforced through an '#error" * audio-refactoring: document tone-multiplexing feature * audio-refactoring: Apply suggestions from documentation review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-refactoring: Update docs/audio_driver.md * audio-refactoring: docs: fix markdown newlines Terminating a line in Markdown with <space>-<space>-<linebreak> creates an HTML single-line break (<br>). Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-arm-dac: additive: fix AUDIO_PIN_ALT handling * audio-arm-pwm: align define naming with other drivers Co-authored-by: Joel Challis <git@zvecr.com> * audio-refactoring: set detault tempo to 120 and add documentation for the override * audio-refactoring: update backlight define checks to new AUDIO_PIN names * audio-refactoring: reworking PWM related defines to be more consistent with other QMK code Co-authored-by: Joel Challis <git@zvecr.com> * audio-arm: have the state-update-timer user configurable defaulting to GPTD6 or GPTD8 for stm32f2+ (=proton-c) stm32f1 might need to set this to GPTD4, since 6 and 8 are not available * audio-refactoring: PLAY_NOTE_ARRAY was already removed in master * Add prototype for startup * Update chibiOS dac basic to disable pins on stop * Add defaults for Proton C * avoid hanging audio if note is completely missed * Don't redefine pins if they're already defined * Define A4 and A5 for CTPC support * Add license headers to keymap files * Remove figlet? comments * Add DAC config to audio driver docs * Apply suggestions from code review Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Add license header to py files * correct license header * Add JohSchneider's name to modified files AKA credit where credit's due * Set executable permission and change interpeter * Add 'wave' to pip requirements * Improve documentation * Add some settings I missed * Strip AUDIO_DRIVER to parse the name correctly * fix depreciated * Update util/audio_generate_dac_lut.py Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Fix type in clueboard config * Apply suggestions from tzarc Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Johannes <you@example.com> Co-authored-by: JohSchneider <JohSchneider@googlemail.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Joshua Diamond <josh@windowoffire.com> Co-authored-by: Jack Humbert <jack.humb@gmail.com>
3 years ago
Audio system overhaul (#11820) * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commits bundles the changes from the arm-dac-work branch focused on audio/audio_arm.* into one commit (leaving out the test-keyboard) f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both -> only the changes on audio_arm_.*, the keyboard related parts are split off to a separate commit bfe468ef1 start morphing wavetable 474d100b5 refined a bit 208bee10f play_notes working 3e6478b0b start in-place documentation of dac settings 3e1826a33 fixed blip (rounding error), other waves, added key selection (left/right) 73853d651 5 voices at 44.1khz dfb401b95 limit voices to working number 9632b3379 configuration for the ez 6241f3f3b notes working in a new way * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commit splits off the plank example keymap from commit f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both * refactoring: rename audio_ to reflect their supported hardware-platform and audio-generation method: avr vs arm, and pwm vs dac * refactoring: deducplicate ISR code to update the pwm duty-cycle and period in the avr-pwm-implementation pulls three copies of the same code into one function which should improve readability and maintainability :-) * refactoring: move common code of arm and avr implementation into a separate/new file * refactoring: audio_avr_pwm, renaming defines to decouple them from actually used timers, registers and ISRs * refactoring: audio_avr_pwm - replacing function defines with plain register defines aligns better with other existing qmk code (and the new audio_arm_pwm) doing similar pwm thing * add audio-arm-pwm since not all STM32 have a DAC onboard (STM32F2xx and STM32F3xx), pwm-audio is an alternative (STM32F1xx) this code works on a "BluePill" clone, with an STM32F103C8B * clang-format changes on quantum/audio/* only * audio_arm_dac: stopping the notes caused screeching when using the DAC audio paths * audio_arm_pwm: use pushpull on the pin; so that a piezzo can be hooked up direclty without additional components (opendrain would require an external pullup) * refactoring: remove unused file from/for atmel-avr chips * refactoring: remove unused (avr) wavetable file * audio_arm_dac: adapt dac_end callback to changed chibios DAC api the previous chibios (17.6.0) passed along a pointer into the buffer plus a sample_count (which are/already where included in the DACDrivre object) - the current chibios (19.1.0) only passes the driver object. this patch ports more or less exactly what the previous chibios ISR code did: either have the user-callback work the first or second half of the buffer (dacsample_t pointer, with half the DAC_BUFFER_SIZE samples) by adjusting the pointer and sample count * audio-arm-dac: show a compile-warning on undefined audio-pins Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio_arm_dac: switch from exemplary wavetable generation to sine only sine+triangle+squrare is exemplary, and not realy fit for "production" use 'stairs' are usefull for debugging (hardware, with an oscilloscope) * audio_arm_dac: enable output buffers in the STM32 to drive external loads without any additional ciruitry - external opamps and such * audio: prevent out-of-bounds array access * audio_arm_dac: add output-frequency correcting factor * audio_arm_pwm: get both the alternate-function and pm-callback variants back into working condition and do some code-cleanup, refine documentation, ... * audio_arm_pwm: increase pwm frequency for "higher fidelity" on the previous .frequency=100000 higher frequency musical notes came out wrong (frequency measured on a Tektronix TDS2014B) note | freq | arm-pwm C2 | 65.4 | 65.491 C5 | 523.25 | 523.93 C6 | 1046.5 | 1053.38 C7 | 2093 | 2129 C8 | 4186 | 4350.91 with .frequency = 500000 C8 | 4186 | 4204.6 * audio refactoring: remove unused variables * audio_arm_dac: calibrate note tempo: with a tempo of 60beats-per-second a whole-note should last for exactly one second * audio: allow feature selection in rules.mk so the user can switch the audio driver between DAC and PWM on STM32 boards which support both (STM32F2 and up) or select the "pin alternate" pwm mode, for example on STM32F103 * audio-refactoring: move codeblocks in audio.[ch] into more coherent groups and add some inline documentation * audio-refactoring: cleanup and streamline common code between audio_arm_[dac|pwm] untangeling the relation between audio.c and the two drivers and adding more documenting comments :-) * audio_avr_pwm: getting it back into working condition, and cleanup+refactor * audio-refactoring: documentation and typo fixes Co-Authored-By: Nick Brassel <nick@tzarc.org> * audio-refactoring: cleanup defines, inludes and remove debug-prints * audio_chibios_dac: define&use a minimal sampling rate, based on the available tone-range to ease up on the cpu-load, while still rendering the higher notes/tones sufficiently also reenable the lower tones, since with the new implementation there is no evidence of them still beeing 'bugged' * audio-refactoring: one common AUDIO_MAX_VOICES define for all audio-drivers * audio-chibios-pwm: pwm-pin-allternate: make the the timer, timer-channel and alternate function user-#definable * audio_chibios_dac: math.h has fmod for this * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback update Jack Humberts dac-example keymaps for the slight changes in the audio-dac interface * audio-refactoring: use a common AUDIO_PIN configuration switch instead of defines have the user select a pin by configuration in rules.mk instead of a define in config.h has the advantage of beeing in a common form/pattern across all audio-driver implementations * audio-refactoring: switch backlight_avr.c to the new AUDIO_PIN defines * audio-common: have advance_note return a boolean if the note changed, to the next one in the melody beeing played * audio-chibios-pwm: fix issue with ~130ms silence between note/frequency changes while playing a SONG through trial,error and a scope/logic analyzer figured out Chibios-PWMDriver (at least in the current version) misbehaves if the initial period is set to zero (or one; two seems to work); when thats the case subsequent calls to 'pwmChhangePeriod' + pwmEnableChannel took ~135ms of silence, before the PWM continued with the new frequency... * audio-refactoring: get 'play_note' working again with a limited number of available voices (say AUDIO_VOICES_MAX=1) allow new frequencies to be played, by discarding the oldest one in the 'frequencies' queue * audio: set the fallback driver to DAC for chibios and PWM for all others (==avr at the moment) * audio-refactoring: moore documentation and some cleanup * audio-avr-pwm: no fallback on unset AUDIO_PIN this seems to be the expected behaviour by some keyboards (looking at ckeys/handwire_101:default) which otherwise fail to build because the firmware-image ends up beeing too large for the atmega... so we fail silently instead to keep travis happy * audio-refactoring: untangling terminology: voice->tone the code actually was working on tones (combination of pitch/frequency, duration, timbre, intensity/volume) and not voices (characteristic sound of an instrument; think piano vs guitar, which can be played together, each having its own "track" = voice on a music sheet) * audio-pwm: allow freq=0 aka a pause/rest in a SONG continue processing, but do not enable pwm units, since freq=0 wouldn't produce any sound anyway (and lead to division by zero on that occasion) * audio-refactoring: audio_advance_note -> audio_advance_state since it does not only affect 'one note', but the internally kept state as a whole * audio-refactoring: untangling terminology: polyphony the feature om the "inherited" avr code has little to do with polyphony (see wikipedia), but is more a time-multiplexing feature, to work around hardware limitations - like only having one pwm channel, that could on its own only reproduce one voice/instrument at a time * audio-chibios-dac: add zero-crossing feature have tones only change/stop when the waveform approaches zero - to avoid audible clicks note that this also requires the samples to start at zero, since the internally kept index into the samples is reset to zero too * audio-refactoring: feature: time-multiplexing of tones on a single output channel this feature was in the original avr-pwm implementation misnomed as "polyphony" with polyphony_rate and so on; did the same thing though: time-multiplexing multiple active notes so that a single output channel could reproduce more than one note at a time (which is not the same as a polyphony - see wikipedia :-) ) * audio-avr-pwm: get music-mode working (again) on AVRs with both pwm channels, or either one of the two :-) play_notes worked already - but music_mode uses play_note * audio-refactoring: split define MAX_SIMULTANEOUS_TONES -> TONE_STACKSIZE since the two cases are independant from one another, the hardware might impose limitations on the number of simultaneously reproducable tones, but the audio state should be able to track an unrelated number of notes recently started by play_note * audio-arm-dac: per define selectable sample-luts plus generation script in ./util * audio-refactoring: heh, avr has a MIN... * audio-refactoring: add basic dac audio-driver based on the current/master implementation whereas current=d96380e65496912e0f68e6531565f4b45efd1623 which is the state of things before this whole audio-refactoring branch boiled down to interface with the refactored audio system = removing all redundant state-managing and frequency calculation * audio-refactoring: rename audio-drivers to driver_$PLATFORM_$DRIVER * audio-arm-pwm: split the software/hardware implementations into separate files which saves us partially from a 'define hell', with the tradeoff that now two somewhat similar chibios_pwm implementations have to be maintained * audio-refactoring: update documentation * audio-arm-dac: apply AUDIO_PIN defines to driver_chibios_dac_basic * audio-arm-dac: dac_additive: stop the hardware when the last sample completed the audio system calls for a driver_stop, which is delayed until the current sample conversion finishes * audio-refactoring: make function-namespace consistent - all (public) audio functions start with audio_ - also refactoring play*_notes/tones to play*_melody, to visually distance it a bit from play*_tone/_note * audio-refactoring: consistent define namespace: DAC_ -> AUDIO_DAC_ * audio-arm-dac: update (inline) documentation regarding MAX for sample values * audio-chibios-dac: remove zero-crossing feature didn't quite work as intended anyway, and stopping the hardware on close-to-zero seems to be enought anyway * audio-arm-dac: dac_basic: respect the configured sample-rate * audio-arm-pwm: have 'note_timbre' influence the pwm-duty cycle like it already does in the avr implementation * audio-refactoring: get VIBRATO working (again) with all drivers (verified with chibios_[dac|pwm]) * audio-arm-dac: zero-crossing feature (Mk II) wait for the generated waveform to approach 'zero' before either turning off the output+timer or switching to the current set of active_tones * audio-refactoring: re-add note-resting -> introduce short_rest inbetween - introduce a short pause/rest between two notes of the same frequency, to separate them audibly - also updating the refactoring comments * audio-refactoring: cleanup refactoring remnants remove the former avr-isr code block - since all its features are now refactored into the different parts of the current system also updates the TODOS * audio-refactoring: reserve negative numbers as unitialized frequencies to allow the valid tone/frequency f=0Hz == rest/pause * audio-refactoring: FIX: first note of melody was missing the first note was missing because 'goto_next_note'=false overrode a state_change=true of the initial play_tone and some code-indentations/cleanup of related parts * audio-arm-dac: fix hardware init-click due to wron .init= value * audio-refactoring: new conveniance function: audio_play_click which can be used to further refactor/remove fauxclicky (avr only) and/or the 'clicky' features * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: consecutive notes of the same frequency get a pause inserted inbetween by audio.c * audio-refactoring: use milliseconds instead of seconds for 'click' parameters clicks are supposed to be short, seconds make little sense * audio-refactoring: use timer ticks instead of counters local counters were used in the original (avr)ISR to advance an index into the lookup tables (for vibrato), and something similar was used for the tone-multiplexing feature decoupling these from the (possibly irregular) calls to advance_state made sesne, since those counters/lookups need to be in relation to a wall-time anyway * audio-refactoring: voices.c: drop 'envelope_index' counter in favour of timer ticks * audio-refactoring: move vibrato and timbre related parts from audio.c to voices.c also drops the now (globally) unused AUDIO_VIBRATO/AUDIO_ENABLE_VIBRATO defines * audio.c: use system-ticks instead of counters the drivers have to take care of for the internal state posision since there already is a system-tick with ms resolution, keeping count separatly with each driver implementation makes little sense; especially since they had to take special care to call audio_advance_state with the correct step/end parameters for the audio state to advance regularly and with the correct pace * audio.c: stop notes after new ones have been started avoids brief states of with no notes playing that would otherwise stop the hardware and might lead to clicks * audio.c: bugfix: actually play a pause instead of just idling/stopping which lead the pwm drivers to stop entirely... * audio-arm-pwm: pwm-software: add inverted output new define AUDIO_PIN_ALT_AS_NEGATIVE will generate an inverted signal on the alternate pin, which boosts the volume if a piezo is connected to both AUDIO_PIN and AUDIO_PIN_ALT * audio-arm-dac: basic: handle piezo configured&wired to both audio pins * audio-refactoring: docs: update for AUDIO_PIN_ALT_AS_NEGATIVE and piezo wiring * audio.c: bugfix: use timer_elapsed32 instad of keeping timestamps avoids running into issues when the uint32 of the timer overflows * audio-refactoring: add 'pragma once' and remove deprecated NOTE_REST * audio_arm_dac: basic: add missing bracket * audio.c: fix delta calculation was in the wrong place, needs to use the 'last_timestamp' before it was reset * audio-refactoring: buildfix: wrong legacy macro for set_timbre * audio.c: 16bit timerstamps suffice * audio-refactoring: separate includes for AVR and chibios * audio-refactoring: timbre: use uint8 instead of float * audio-refactoring: duration: use uint16 for internal per-tone/note state * audio-refactoring: tonemultiplexing: use uint16 instead of float * audio-arm-dac: additive: set second pin output-low used when a piezo is connected to AUDIO_PIN and AUDIO_PIN_ALT, with PIN_ALT_AS_NEGATIVE * audio-refactoring: move AUDIO_PIN selection from rules.mk to config.h to be consistent with how other features are handled in QMK * audio-refactoring: buildfix: wrong legacy macro for set_tempo * audio-arm-dac: additive: set second pin output-low -- FIXUP * audio.c: do duration<>ms conversion in uint instead of float on AVR, to save a couple of bytes in the firmware size * audio-refactoring: cleanup eeprom defines/usage for ARM, avr is handled automagically through the avr libc and common_features.mk Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio.h: throw an error if OFF is larger than MAX * audio-arm-dac: basic: actually stop the dac-conversion on a audio_driver_stop to put the output pin in a known state == AUDIO_DAC_OFF_VALUE, instead of just leaving them where the last conversion was... with AUDIO_PIN_ALT_AS_NEGATIVE this meant one output was left HIGH while the other was left LOW one CAVEAT: due to this change the opposing squarewave when using both A4 and A5 with AUDIO_PIN_ALT_AS_NEGATIVE show extra pulses at the beginning/end on one of the outputs, the two waveforms are in sync otherwise. the extra pusles probably matter little, since this is no high-fidelity sound generation :P * audio-arm-dac: additive: move zero-crossing code out of dac_value_generate which is/should be user-overridable == simple, and doing one thing: providing sample values state-transitions necessary for the zero crossing are better handled in the surrounding loop in the dac_end callback * audio-arm-dac: dac-additive: zero-crossing: ramping up or down after a start trigger ramp up: generate values until zero=OFF_VALUE is reached, then continue normally same in reverse for strop trigger: output values until zero is reached/crossed, then keep OFF_VALUE on the output * audio-arm-dac: dac-additive: BUGFIX: return OFF_VALUE when a pause is playing fixes a bug during SONG playback, which suddenly stopped when it encoutnered a pause * audio-arm-dac: set a sensible default for AUDIO_DAC_VALUE_OFF 1/2 MAX was probably exemplary, can't think of a setup where that would make sense :-P * audio-arm-dac: update synth_sample/_wavetable for new pin-defines * audio-arm-dac: default for AUDIO_DAC_VALUE_OFF turned out that zero or max are bad default choices: when multiple tones are played (>>5) and released at the same time (!), due to the complex waveform never reaching 'zero' the output can take quite a while to reach zero, and hence the zero-crossing code only "releases" the output waaay to late * audio-arm-dac: additive: use DAC for negative pin instead of PAL, which only allows the pin to be configured as output; LOW or HIGH * audio-arm-dac: more compile-time configuration checks * audio-refactoring: typo fixed * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: add defines for B-pin as primary/only speaker also updates documentation. * audio-refactoring: update documentation with proton-c config.h example * audio-refactoring: move glissando (TODO) to voices.c refactored/saved from the original glissando implementation in then upstream-master:audio_avr.c still needs some work though, as it is now the calculation *should* work, but the start-frequency needs to be tracked somewhere/somehow; not only during a SONG playback but also with user input? * audio-refactoring: cleanup: one round of aspell -c * audio-avr-pwm: back to AUDIO_PIN since config_common.h expands them to plain integers, the AUDIO_PIN define can directly be compared to e.g. B5 so there is no need to deal with separate defines like AUDIO_PIN_B5 * audio-refactoring: add technical documentation audio_driver.md which moves some in-code documentation there * audio-arm-dac: move AUDIO_PIN checks into c-code instead of doing everything with the preprocessor, since A4/A5 do not expand to simple integers, preprocessor int-comparison is not possible. but necessary to get a consistent configuration scheme going throughout the audio-code... solution: let c-code handle the different AUDIO_PIN configurations instead (and leave code/size optimizations to the compiler) * audio-arm-dac: compile-fix: set AUDIO_PIN if unset workaround to get the build going again, and be backwarts compatible to arm-keyboards which not yet set the AUDIO_PIN define. until the define is enforced through an '#error" * audio-refactoring: document tone-multiplexing feature * audio-refactoring: Apply suggestions from documentation review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-refactoring: Update docs/audio_driver.md * audio-refactoring: docs: fix markdown newlines Terminating a line in Markdown with <space>-<space>-<linebreak> creates an HTML single-line break (<br>). Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-arm-dac: additive: fix AUDIO_PIN_ALT handling * audio-arm-pwm: align define naming with other drivers Co-authored-by: Joel Challis <git@zvecr.com> * audio-refactoring: set detault tempo to 120 and add documentation for the override * audio-refactoring: update backlight define checks to new AUDIO_PIN names * audio-refactoring: reworking PWM related defines to be more consistent with other QMK code Co-authored-by: Joel Challis <git@zvecr.com> * audio-arm: have the state-update-timer user configurable defaulting to GPTD6 or GPTD8 for stm32f2+ (=proton-c) stm32f1 might need to set this to GPTD4, since 6 and 8 are not available * audio-refactoring: PLAY_NOTE_ARRAY was already removed in master * Add prototype for startup * Update chibiOS dac basic to disable pins on stop * Add defaults for Proton C * avoid hanging audio if note is completely missed * Don't redefine pins if they're already defined * Define A4 and A5 for CTPC support * Add license headers to keymap files * Remove figlet? comments * Add DAC config to audio driver docs * Apply suggestions from code review Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Add license header to py files * correct license header * Add JohSchneider's name to modified files AKA credit where credit's due * Set executable permission and change interpeter * Add 'wave' to pip requirements * Improve documentation * Add some settings I missed * Strip AUDIO_DRIVER to parse the name correctly * fix depreciated * Update util/audio_generate_dac_lut.py Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Fix type in clueboard config * Apply suggestions from tzarc Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Johannes <you@example.com> Co-authored-by: JohSchneider <JohSchneider@googlemail.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Joshua Diamond <josh@windowoffire.com> Co-authored-by: Jack Humbert <jack.humb@gmail.com>
3 years ago
Audio system overhaul (#11820) * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commits bundles the changes from the arm-dac-work branch focused on audio/audio_arm.* into one commit (leaving out the test-keyboard) f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both -> only the changes on audio_arm_.*, the keyboard related parts are split off to a separate commit bfe468ef1 start morphing wavetable 474d100b5 refined a bit 208bee10f play_notes working 3e6478b0b start in-place documentation of dac settings 3e1826a33 fixed blip (rounding error), other waves, added key selection (left/right) 73853d651 5 voices at 44.1khz dfb401b95 limit voices to working number 9632b3379 configuration for the ez 6241f3f3b notes working in a new way * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commit splits off the plank example keymap from commit f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both * refactoring: rename audio_ to reflect their supported hardware-platform and audio-generation method: avr vs arm, and pwm vs dac * refactoring: deducplicate ISR code to update the pwm duty-cycle and period in the avr-pwm-implementation pulls three copies of the same code into one function which should improve readability and maintainability :-) * refactoring: move common code of arm and avr implementation into a separate/new file * refactoring: audio_avr_pwm, renaming defines to decouple them from actually used timers, registers and ISRs * refactoring: audio_avr_pwm - replacing function defines with plain register defines aligns better with other existing qmk code (and the new audio_arm_pwm) doing similar pwm thing * add audio-arm-pwm since not all STM32 have a DAC onboard (STM32F2xx and STM32F3xx), pwm-audio is an alternative (STM32F1xx) this code works on a "BluePill" clone, with an STM32F103C8B * clang-format changes on quantum/audio/* only * audio_arm_dac: stopping the notes caused screeching when using the DAC audio paths * audio_arm_pwm: use pushpull on the pin; so that a piezzo can be hooked up direclty without additional components (opendrain would require an external pullup) * refactoring: remove unused file from/for atmel-avr chips * refactoring: remove unused (avr) wavetable file * audio_arm_dac: adapt dac_end callback to changed chibios DAC api the previous chibios (17.6.0) passed along a pointer into the buffer plus a sample_count (which are/already where included in the DACDrivre object) - the current chibios (19.1.0) only passes the driver object. this patch ports more or less exactly what the previous chibios ISR code did: either have the user-callback work the first or second half of the buffer (dacsample_t pointer, with half the DAC_BUFFER_SIZE samples) by adjusting the pointer and sample count * audio-arm-dac: show a compile-warning on undefined audio-pins Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio_arm_dac: switch from exemplary wavetable generation to sine only sine+triangle+squrare is exemplary, and not realy fit for "production" use 'stairs' are usefull for debugging (hardware, with an oscilloscope) * audio_arm_dac: enable output buffers in the STM32 to drive external loads without any additional ciruitry - external opamps and such * audio: prevent out-of-bounds array access * audio_arm_dac: add output-frequency correcting factor * audio_arm_pwm: get both the alternate-function and pm-callback variants back into working condition and do some code-cleanup, refine documentation, ... * audio_arm_pwm: increase pwm frequency for "higher fidelity" on the previous .frequency=100000 higher frequency musical notes came out wrong (frequency measured on a Tektronix TDS2014B) note | freq | arm-pwm C2 | 65.4 | 65.491 C5 | 523.25 | 523.93 C6 | 1046.5 | 1053.38 C7 | 2093 | 2129 C8 | 4186 | 4350.91 with .frequency = 500000 C8 | 4186 | 4204.6 * audio refactoring: remove unused variables * audio_arm_dac: calibrate note tempo: with a tempo of 60beats-per-second a whole-note should last for exactly one second * audio: allow feature selection in rules.mk so the user can switch the audio driver between DAC and PWM on STM32 boards which support both (STM32F2 and up) or select the "pin alternate" pwm mode, for example on STM32F103 * audio-refactoring: move codeblocks in audio.[ch] into more coherent groups and add some inline documentation * audio-refactoring: cleanup and streamline common code between audio_arm_[dac|pwm] untangeling the relation between audio.c and the two drivers and adding more documenting comments :-) * audio_avr_pwm: getting it back into working condition, and cleanup+refactor * audio-refactoring: documentation and typo fixes Co-Authored-By: Nick Brassel <nick@tzarc.org> * audio-refactoring: cleanup defines, inludes and remove debug-prints * audio_chibios_dac: define&use a minimal sampling rate, based on the available tone-range to ease up on the cpu-load, while still rendering the higher notes/tones sufficiently also reenable the lower tones, since with the new implementation there is no evidence of them still beeing 'bugged' * audio-refactoring: one common AUDIO_MAX_VOICES define for all audio-drivers * audio-chibios-pwm: pwm-pin-allternate: make the the timer, timer-channel and alternate function user-#definable * audio_chibios_dac: math.h has fmod for this * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback update Jack Humberts dac-example keymaps for the slight changes in the audio-dac interface * audio-refactoring: use a common AUDIO_PIN configuration switch instead of defines have the user select a pin by configuration in rules.mk instead of a define in config.h has the advantage of beeing in a common form/pattern across all audio-driver implementations * audio-refactoring: switch backlight_avr.c to the new AUDIO_PIN defines * audio-common: have advance_note return a boolean if the note changed, to the next one in the melody beeing played * audio-chibios-pwm: fix issue with ~130ms silence between note/frequency changes while playing a SONG through trial,error and a scope/logic analyzer figured out Chibios-PWMDriver (at least in the current version) misbehaves if the initial period is set to zero (or one; two seems to work); when thats the case subsequent calls to 'pwmChhangePeriod' + pwmEnableChannel took ~135ms of silence, before the PWM continued with the new frequency... * audio-refactoring: get 'play_note' working again with a limited number of available voices (say AUDIO_VOICES_MAX=1) allow new frequencies to be played, by discarding the oldest one in the 'frequencies' queue * audio: set the fallback driver to DAC for chibios and PWM for all others (==avr at the moment) * audio-refactoring: moore documentation and some cleanup * audio-avr-pwm: no fallback on unset AUDIO_PIN this seems to be the expected behaviour by some keyboards (looking at ckeys/handwire_101:default) which otherwise fail to build because the firmware-image ends up beeing too large for the atmega... so we fail silently instead to keep travis happy * audio-refactoring: untangling terminology: voice->tone the code actually was working on tones (combination of pitch/frequency, duration, timbre, intensity/volume) and not voices (characteristic sound of an instrument; think piano vs guitar, which can be played together, each having its own "track" = voice on a music sheet) * audio-pwm: allow freq=0 aka a pause/rest in a SONG continue processing, but do not enable pwm units, since freq=0 wouldn't produce any sound anyway (and lead to division by zero on that occasion) * audio-refactoring: audio_advance_note -> audio_advance_state since it does not only affect 'one note', but the internally kept state as a whole * audio-refactoring: untangling terminology: polyphony the feature om the "inherited" avr code has little to do with polyphony (see wikipedia), but is more a time-multiplexing feature, to work around hardware limitations - like only having one pwm channel, that could on its own only reproduce one voice/instrument at a time * audio-chibios-dac: add zero-crossing feature have tones only change/stop when the waveform approaches zero - to avoid audible clicks note that this also requires the samples to start at zero, since the internally kept index into the samples is reset to zero too * audio-refactoring: feature: time-multiplexing of tones on a single output channel this feature was in the original avr-pwm implementation misnomed as "polyphony" with polyphony_rate and so on; did the same thing though: time-multiplexing multiple active notes so that a single output channel could reproduce more than one note at a time (which is not the same as a polyphony - see wikipedia :-) ) * audio-avr-pwm: get music-mode working (again) on AVRs with both pwm channels, or either one of the two :-) play_notes worked already - but music_mode uses play_note * audio-refactoring: split define MAX_SIMULTANEOUS_TONES -> TONE_STACKSIZE since the two cases are independant from one another, the hardware might impose limitations on the number of simultaneously reproducable tones, but the audio state should be able to track an unrelated number of notes recently started by play_note * audio-arm-dac: per define selectable sample-luts plus generation script in ./util * audio-refactoring: heh, avr has a MIN... * audio-refactoring: add basic dac audio-driver based on the current/master implementation whereas current=d96380e65496912e0f68e6531565f4b45efd1623 which is the state of things before this whole audio-refactoring branch boiled down to interface with the refactored audio system = removing all redundant state-managing and frequency calculation * audio-refactoring: rename audio-drivers to driver_$PLATFORM_$DRIVER * audio-arm-pwm: split the software/hardware implementations into separate files which saves us partially from a 'define hell', with the tradeoff that now two somewhat similar chibios_pwm implementations have to be maintained * audio-refactoring: update documentation * audio-arm-dac: apply AUDIO_PIN defines to driver_chibios_dac_basic * audio-arm-dac: dac_additive: stop the hardware when the last sample completed the audio system calls for a driver_stop, which is delayed until the current sample conversion finishes * audio-refactoring: make function-namespace consistent - all (public) audio functions start with audio_ - also refactoring play*_notes/tones to play*_melody, to visually distance it a bit from play*_tone/_note * audio-refactoring: consistent define namespace: DAC_ -> AUDIO_DAC_ * audio-arm-dac: update (inline) documentation regarding MAX for sample values * audio-chibios-dac: remove zero-crossing feature didn't quite work as intended anyway, and stopping the hardware on close-to-zero seems to be enought anyway * audio-arm-dac: dac_basic: respect the configured sample-rate * audio-arm-pwm: have 'note_timbre' influence the pwm-duty cycle like it already does in the avr implementation * audio-refactoring: get VIBRATO working (again) with all drivers (verified with chibios_[dac|pwm]) * audio-arm-dac: zero-crossing feature (Mk II) wait for the generated waveform to approach 'zero' before either turning off the output+timer or switching to the current set of active_tones * audio-refactoring: re-add note-resting -> introduce short_rest inbetween - introduce a short pause/rest between two notes of the same frequency, to separate them audibly - also updating the refactoring comments * audio-refactoring: cleanup refactoring remnants remove the former avr-isr code block - since all its features are now refactored into the different parts of the current system also updates the TODOS * audio-refactoring: reserve negative numbers as unitialized frequencies to allow the valid tone/frequency f=0Hz == rest/pause * audio-refactoring: FIX: first note of melody was missing the first note was missing because 'goto_next_note'=false overrode a state_change=true of the initial play_tone and some code-indentations/cleanup of related parts * audio-arm-dac: fix hardware init-click due to wron .init= value * audio-refactoring: new conveniance function: audio_play_click which can be used to further refactor/remove fauxclicky (avr only) and/or the 'clicky' features * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: consecutive notes of the same frequency get a pause inserted inbetween by audio.c * audio-refactoring: use milliseconds instead of seconds for 'click' parameters clicks are supposed to be short, seconds make little sense * audio-refactoring: use timer ticks instead of counters local counters were used in the original (avr)ISR to advance an index into the lookup tables (for vibrato), and something similar was used for the tone-multiplexing feature decoupling these from the (possibly irregular) calls to advance_state made sesne, since those counters/lookups need to be in relation to a wall-time anyway * audio-refactoring: voices.c: drop 'envelope_index' counter in favour of timer ticks * audio-refactoring: move vibrato and timbre related parts from audio.c to voices.c also drops the now (globally) unused AUDIO_VIBRATO/AUDIO_ENABLE_VIBRATO defines * audio.c: use system-ticks instead of counters the drivers have to take care of for the internal state posision since there already is a system-tick with ms resolution, keeping count separatly with each driver implementation makes little sense; especially since they had to take special care to call audio_advance_state with the correct step/end parameters for the audio state to advance regularly and with the correct pace * audio.c: stop notes after new ones have been started avoids brief states of with no notes playing that would otherwise stop the hardware and might lead to clicks * audio.c: bugfix: actually play a pause instead of just idling/stopping which lead the pwm drivers to stop entirely... * audio-arm-pwm: pwm-software: add inverted output new define AUDIO_PIN_ALT_AS_NEGATIVE will generate an inverted signal on the alternate pin, which boosts the volume if a piezo is connected to both AUDIO_PIN and AUDIO_PIN_ALT * audio-arm-dac: basic: handle piezo configured&wired to both audio pins * audio-refactoring: docs: update for AUDIO_PIN_ALT_AS_NEGATIVE and piezo wiring * audio.c: bugfix: use timer_elapsed32 instad of keeping timestamps avoids running into issues when the uint32 of the timer overflows * audio-refactoring: add 'pragma once' and remove deprecated NOTE_REST * audio_arm_dac: basic: add missing bracket * audio.c: fix delta calculation was in the wrong place, needs to use the 'last_timestamp' before it was reset * audio-refactoring: buildfix: wrong legacy macro for set_timbre * audio.c: 16bit timerstamps suffice * audio-refactoring: separate includes for AVR and chibios * audio-refactoring: timbre: use uint8 instead of float * audio-refactoring: duration: use uint16 for internal per-tone/note state * audio-refactoring: tonemultiplexing: use uint16 instead of float * audio-arm-dac: additive: set second pin output-low used when a piezo is connected to AUDIO_PIN and AUDIO_PIN_ALT, with PIN_ALT_AS_NEGATIVE * audio-refactoring: move AUDIO_PIN selection from rules.mk to config.h to be consistent with how other features are handled in QMK * audio-refactoring: buildfix: wrong legacy macro for set_tempo * audio-arm-dac: additive: set second pin output-low -- FIXUP * audio.c: do duration<>ms conversion in uint instead of float on AVR, to save a couple of bytes in the firmware size * audio-refactoring: cleanup eeprom defines/usage for ARM, avr is handled automagically through the avr libc and common_features.mk Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio.h: throw an error if OFF is larger than MAX * audio-arm-dac: basic: actually stop the dac-conversion on a audio_driver_stop to put the output pin in a known state == AUDIO_DAC_OFF_VALUE, instead of just leaving them where the last conversion was... with AUDIO_PIN_ALT_AS_NEGATIVE this meant one output was left HIGH while the other was left LOW one CAVEAT: due to this change the opposing squarewave when using both A4 and A5 with AUDIO_PIN_ALT_AS_NEGATIVE show extra pulses at the beginning/end on one of the outputs, the two waveforms are in sync otherwise. the extra pusles probably matter little, since this is no high-fidelity sound generation :P * audio-arm-dac: additive: move zero-crossing code out of dac_value_generate which is/should be user-overridable == simple, and doing one thing: providing sample values state-transitions necessary for the zero crossing are better handled in the surrounding loop in the dac_end callback * audio-arm-dac: dac-additive: zero-crossing: ramping up or down after a start trigger ramp up: generate values until zero=OFF_VALUE is reached, then continue normally same in reverse for strop trigger: output values until zero is reached/crossed, then keep OFF_VALUE on the output * audio-arm-dac: dac-additive: BUGFIX: return OFF_VALUE when a pause is playing fixes a bug during SONG playback, which suddenly stopped when it encoutnered a pause * audio-arm-dac: set a sensible default for AUDIO_DAC_VALUE_OFF 1/2 MAX was probably exemplary, can't think of a setup where that would make sense :-P * audio-arm-dac: update synth_sample/_wavetable for new pin-defines * audio-arm-dac: default for AUDIO_DAC_VALUE_OFF turned out that zero or max are bad default choices: when multiple tones are played (>>5) and released at the same time (!), due to the complex waveform never reaching 'zero' the output can take quite a while to reach zero, and hence the zero-crossing code only "releases" the output waaay to late * audio-arm-dac: additive: use DAC for negative pin instead of PAL, which only allows the pin to be configured as output; LOW or HIGH * audio-arm-dac: more compile-time configuration checks * audio-refactoring: typo fixed * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: add defines for B-pin as primary/only speaker also updates documentation. * audio-refactoring: update documentation with proton-c config.h example * audio-refactoring: move glissando (TODO) to voices.c refactored/saved from the original glissando implementation in then upstream-master:audio_avr.c still needs some work though, as it is now the calculation *should* work, but the start-frequency needs to be tracked somewhere/somehow; not only during a SONG playback but also with user input? * audio-refactoring: cleanup: one round of aspell -c * audio-avr-pwm: back to AUDIO_PIN since config_common.h expands them to plain integers, the AUDIO_PIN define can directly be compared to e.g. B5 so there is no need to deal with separate defines like AUDIO_PIN_B5 * audio-refactoring: add technical documentation audio_driver.md which moves some in-code documentation there * audio-arm-dac: move AUDIO_PIN checks into c-code instead of doing everything with the preprocessor, since A4/A5 do not expand to simple integers, preprocessor int-comparison is not possible. but necessary to get a consistent configuration scheme going throughout the audio-code... solution: let c-code handle the different AUDIO_PIN configurations instead (and leave code/size optimizations to the compiler) * audio-arm-dac: compile-fix: set AUDIO_PIN if unset workaround to get the build going again, and be backwarts compatible to arm-keyboards which not yet set the AUDIO_PIN define. until the define is enforced through an '#error" * audio-refactoring: document tone-multiplexing feature * audio-refactoring: Apply suggestions from documentation review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-refactoring: Update docs/audio_driver.md * audio-refactoring: docs: fix markdown newlines Terminating a line in Markdown with <space>-<space>-<linebreak> creates an HTML single-line break (<br>). Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-arm-dac: additive: fix AUDIO_PIN_ALT handling * audio-arm-pwm: align define naming with other drivers Co-authored-by: Joel Challis <git@zvecr.com> * audio-refactoring: set detault tempo to 120 and add documentation for the override * audio-refactoring: update backlight define checks to new AUDIO_PIN names * audio-refactoring: reworking PWM related defines to be more consistent with other QMK code Co-authored-by: Joel Challis <git@zvecr.com> * audio-arm: have the state-update-timer user configurable defaulting to GPTD6 or GPTD8 for stm32f2+ (=proton-c) stm32f1 might need to set this to GPTD4, since 6 and 8 are not available * audio-refactoring: PLAY_NOTE_ARRAY was already removed in master * Add prototype for startup * Update chibiOS dac basic to disable pins on stop * Add defaults for Proton C * avoid hanging audio if note is completely missed * Don't redefine pins if they're already defined * Define A4 and A5 for CTPC support * Add license headers to keymap files * Remove figlet? comments * Add DAC config to audio driver docs * Apply suggestions from code review Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Add license header to py files * correct license header * Add JohSchneider's name to modified files AKA credit where credit's due * Set executable permission and change interpeter * Add 'wave' to pip requirements * Improve documentation * Add some settings I missed * Strip AUDIO_DRIVER to parse the name correctly * fix depreciated * Update util/audio_generate_dac_lut.py Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Fix type in clueboard config * Apply suggestions from tzarc Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Johannes <you@example.com> Co-authored-by: JohSchneider <JohSchneider@googlemail.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Joshua Diamond <josh@windowoffire.com> Co-authored-by: Jack Humbert <jack.humb@gmail.com>
3 years ago
Audio system overhaul (#11820) * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commits bundles the changes from the arm-dac-work branch focused on audio/audio_arm.* into one commit (leaving out the test-keyboard) f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both -> only the changes on audio_arm_.*, the keyboard related parts are split off to a separate commit bfe468ef1 start morphing wavetable 474d100b5 refined a bit 208bee10f play_notes working 3e6478b0b start in-place documentation of dac settings 3e1826a33 fixed blip (rounding error), other waves, added key selection (left/right) 73853d651 5 voices at 44.1khz dfb401b95 limit voices to working number 9632b3379 configuration for the ez 6241f3f3b notes working in a new way * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback changes by Jack Humbert on an implementation for DAC audio on arm/chibios platforms this commit splits off the plank example keymap from commit f52faeb5d (origin/arm-dac-work) add sample and wavetable examples, parsers for both * refactoring: rename audio_ to reflect their supported hardware-platform and audio-generation method: avr vs arm, and pwm vs dac * refactoring: deducplicate ISR code to update the pwm duty-cycle and period in the avr-pwm-implementation pulls three copies of the same code into one function which should improve readability and maintainability :-) * refactoring: move common code of arm and avr implementation into a separate/new file * refactoring: audio_avr_pwm, renaming defines to decouple them from actually used timers, registers and ISRs * refactoring: audio_avr_pwm - replacing function defines with plain register defines aligns better with other existing qmk code (and the new audio_arm_pwm) doing similar pwm thing * add audio-arm-pwm since not all STM32 have a DAC onboard (STM32F2xx and STM32F3xx), pwm-audio is an alternative (STM32F1xx) this code works on a "BluePill" clone, with an STM32F103C8B * clang-format changes on quantum/audio/* only * audio_arm_dac: stopping the notes caused screeching when using the DAC audio paths * audio_arm_pwm: use pushpull on the pin; so that a piezzo can be hooked up direclty without additional components (opendrain would require an external pullup) * refactoring: remove unused file from/for atmel-avr chips * refactoring: remove unused (avr) wavetable file * audio_arm_dac: adapt dac_end callback to changed chibios DAC api the previous chibios (17.6.0) passed along a pointer into the buffer plus a sample_count (which are/already where included in the DACDrivre object) - the current chibios (19.1.0) only passes the driver object. this patch ports more or less exactly what the previous chibios ISR code did: either have the user-callback work the first or second half of the buffer (dacsample_t pointer, with half the DAC_BUFFER_SIZE samples) by adjusting the pointer and sample count * audio-arm-dac: show a compile-warning on undefined audio-pins Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio_arm_dac: switch from exemplary wavetable generation to sine only sine+triangle+squrare is exemplary, and not realy fit for "production" use 'stairs' are usefull for debugging (hardware, with an oscilloscope) * audio_arm_dac: enable output buffers in the STM32 to drive external loads without any additional ciruitry - external opamps and such * audio: prevent out-of-bounds array access * audio_arm_dac: add output-frequency correcting factor * audio_arm_pwm: get both the alternate-function and pm-callback variants back into working condition and do some code-cleanup, refine documentation, ... * audio_arm_pwm: increase pwm frequency for "higher fidelity" on the previous .frequency=100000 higher frequency musical notes came out wrong (frequency measured on a Tektronix TDS2014B) note | freq | arm-pwm C2 | 65.4 | 65.491 C5 | 523.25 | 523.93 C6 | 1046.5 | 1053.38 C7 | 2093 | 2129 C8 | 4186 | 4350.91 with .frequency = 500000 C8 | 4186 | 4204.6 * audio refactoring: remove unused variables * audio_arm_dac: calibrate note tempo: with a tempo of 60beats-per-second a whole-note should last for exactly one second * audio: allow feature selection in rules.mk so the user can switch the audio driver between DAC and PWM on STM32 boards which support both (STM32F2 and up) or select the "pin alternate" pwm mode, for example on STM32F103 * audio-refactoring: move codeblocks in audio.[ch] into more coherent groups and add some inline documentation * audio-refactoring: cleanup and streamline common code between audio_arm_[dac|pwm] untangeling the relation between audio.c and the two drivers and adding more documenting comments :-) * audio_avr_pwm: getting it back into working condition, and cleanup+refactor * audio-refactoring: documentation and typo fixes Co-Authored-By: Nick Brassel <nick@tzarc.org> * audio-refactoring: cleanup defines, inludes and remove debug-prints * audio_chibios_dac: define&use a minimal sampling rate, based on the available tone-range to ease up on the cpu-load, while still rendering the higher notes/tones sufficiently also reenable the lower tones, since with the new implementation there is no evidence of them still beeing 'bugged' * audio-refactoring: one common AUDIO_MAX_VOICES define for all audio-drivers * audio-chibios-pwm: pwm-pin-allternate: make the the timer, timer-channel and alternate function user-#definable * audio_chibios_dac: math.h has fmod for this * Redo Arm DAC implementation for additive, wavetable synthesis, sample playback update Jack Humberts dac-example keymaps for the slight changes in the audio-dac interface * audio-refactoring: use a common AUDIO_PIN configuration switch instead of defines have the user select a pin by configuration in rules.mk instead of a define in config.h has the advantage of beeing in a common form/pattern across all audio-driver implementations * audio-refactoring: switch backlight_avr.c to the new AUDIO_PIN defines * audio-common: have advance_note return a boolean if the note changed, to the next one in the melody beeing played * audio-chibios-pwm: fix issue with ~130ms silence between note/frequency changes while playing a SONG through trial,error and a scope/logic analyzer figured out Chibios-PWMDriver (at least in the current version) misbehaves if the initial period is set to zero (or one; two seems to work); when thats the case subsequent calls to 'pwmChhangePeriod' + pwmEnableChannel took ~135ms of silence, before the PWM continued with the new frequency... * audio-refactoring: get 'play_note' working again with a limited number of available voices (say AUDIO_VOICES_MAX=1) allow new frequencies to be played, by discarding the oldest one in the 'frequencies' queue * audio: set the fallback driver to DAC for chibios and PWM for all others (==avr at the moment) * audio-refactoring: moore documentation and some cleanup * audio-avr-pwm: no fallback on unset AUDIO_PIN this seems to be the expected behaviour by some keyboards (looking at ckeys/handwire_101:default) which otherwise fail to build because the firmware-image ends up beeing too large for the atmega... so we fail silently instead to keep travis happy * audio-refactoring: untangling terminology: voice->tone the code actually was working on tones (combination of pitch/frequency, duration, timbre, intensity/volume) and not voices (characteristic sound of an instrument; think piano vs guitar, which can be played together, each having its own "track" = voice on a music sheet) * audio-pwm: allow freq=0 aka a pause/rest in a SONG continue processing, but do not enable pwm units, since freq=0 wouldn't produce any sound anyway (and lead to division by zero on that occasion) * audio-refactoring: audio_advance_note -> audio_advance_state since it does not only affect 'one note', but the internally kept state as a whole * audio-refactoring: untangling terminology: polyphony the feature om the "inherited" avr code has little to do with polyphony (see wikipedia), but is more a time-multiplexing feature, to work around hardware limitations - like only having one pwm channel, that could on its own only reproduce one voice/instrument at a time * audio-chibios-dac: add zero-crossing feature have tones only change/stop when the waveform approaches zero - to avoid audible clicks note that this also requires the samples to start at zero, since the internally kept index into the samples is reset to zero too * audio-refactoring: feature: time-multiplexing of tones on a single output channel this feature was in the original avr-pwm implementation misnomed as "polyphony" with polyphony_rate and so on; did the same thing though: time-multiplexing multiple active notes so that a single output channel could reproduce more than one note at a time (which is not the same as a polyphony - see wikipedia :-) ) * audio-avr-pwm: get music-mode working (again) on AVRs with both pwm channels, or either one of the two :-) play_notes worked already - but music_mode uses play_note * audio-refactoring: split define MAX_SIMULTANEOUS_TONES -> TONE_STACKSIZE since the two cases are independant from one another, the hardware might impose limitations on the number of simultaneously reproducable tones, but the audio state should be able to track an unrelated number of notes recently started by play_note * audio-arm-dac: per define selectable sample-luts plus generation script in ./util * audio-refactoring: heh, avr has a MIN... * audio-refactoring: add basic dac audio-driver based on the current/master implementation whereas current=d96380e65496912e0f68e6531565f4b45efd1623 which is the state of things before this whole audio-refactoring branch boiled down to interface with the refactored audio system = removing all redundant state-managing and frequency calculation * audio-refactoring: rename audio-drivers to driver_$PLATFORM_$DRIVER * audio-arm-pwm: split the software/hardware implementations into separate files which saves us partially from a 'define hell', with the tradeoff that now two somewhat similar chibios_pwm implementations have to be maintained * audio-refactoring: update documentation * audio-arm-dac: apply AUDIO_PIN defines to driver_chibios_dac_basic * audio-arm-dac: dac_additive: stop the hardware when the last sample completed the audio system calls for a driver_stop, which is delayed until the current sample conversion finishes * audio-refactoring: make function-namespace consistent - all (public) audio functions start with audio_ - also refactoring play*_notes/tones to play*_melody, to visually distance it a bit from play*_tone/_note * audio-refactoring: consistent define namespace: DAC_ -> AUDIO_DAC_ * audio-arm-dac: update (inline) documentation regarding MAX for sample values * audio-chibios-dac: remove zero-crossing feature didn't quite work as intended anyway, and stopping the hardware on close-to-zero seems to be enought anyway * audio-arm-dac: dac_basic: respect the configured sample-rate * audio-arm-pwm: have 'note_timbre' influence the pwm-duty cycle like it already does in the avr implementation * audio-refactoring: get VIBRATO working (again) with all drivers (verified with chibios_[dac|pwm]) * audio-arm-dac: zero-crossing feature (Mk II) wait for the generated waveform to approach 'zero' before either turning off the output+timer or switching to the current set of active_tones * audio-refactoring: re-add note-resting -> introduce short_rest inbetween - introduce a short pause/rest between two notes of the same frequency, to separate them audibly - also updating the refactoring comments * audio-refactoring: cleanup refactoring remnants remove the former avr-isr code block - since all its features are now refactored into the different parts of the current system also updates the TODOS * audio-refactoring: reserve negative numbers as unitialized frequencies to allow the valid tone/frequency f=0Hz == rest/pause * audio-refactoring: FIX: first note of melody was missing the first note was missing because 'goto_next_note'=false overrode a state_change=true of the initial play_tone and some code-indentations/cleanup of related parts * audio-arm-dac: fix hardware init-click due to wron .init= value * audio-refactoring: new conveniance function: audio_play_click which can be used to further refactor/remove fauxclicky (avr only) and/or the 'clicky' features * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: consecutive notes of the same frequency get a pause inserted inbetween by audio.c * audio-refactoring: use milliseconds instead of seconds for 'click' parameters clicks are supposed to be short, seconds make little sense * audio-refactoring: use timer ticks instead of counters local counters were used in the original (avr)ISR to advance an index into the lookup tables (for vibrato), and something similar was used for the tone-multiplexing feature decoupling these from the (possibly irregular) calls to advance_state made sesne, since those counters/lookups need to be in relation to a wall-time anyway * audio-refactoring: voices.c: drop 'envelope_index' counter in favour of timer ticks * audio-refactoring: move vibrato and timbre related parts from audio.c to voices.c also drops the now (globally) unused AUDIO_VIBRATO/AUDIO_ENABLE_VIBRATO defines * audio.c: use system-ticks instead of counters the drivers have to take care of for the internal state posision since there already is a system-tick with ms resolution, keeping count separatly with each driver implementation makes little sense; especially since they had to take special care to call audio_advance_state with the correct step/end parameters for the audio state to advance regularly and with the correct pace * audio.c: stop notes after new ones have been started avoids brief states of with no notes playing that would otherwise stop the hardware and might lead to clicks * audio.c: bugfix: actually play a pause instead of just idling/stopping which lead the pwm drivers to stop entirely... * audio-arm-pwm: pwm-software: add inverted output new define AUDIO_PIN_ALT_AS_NEGATIVE will generate an inverted signal on the alternate pin, which boosts the volume if a piezo is connected to both AUDIO_PIN and AUDIO_PIN_ALT * audio-arm-dac: basic: handle piezo configured&wired to both audio pins * audio-refactoring: docs: update for AUDIO_PIN_ALT_AS_NEGATIVE and piezo wiring * audio.c: bugfix: use timer_elapsed32 instad of keeping timestamps avoids running into issues when the uint32 of the timer overflows * audio-refactoring: add 'pragma once' and remove deprecated NOTE_REST * audio_arm_dac: basic: add missing bracket * audio.c: fix delta calculation was in the wrong place, needs to use the 'last_timestamp' before it was reset * audio-refactoring: buildfix: wrong legacy macro for set_timbre * audio.c: 16bit timerstamps suffice * audio-refactoring: separate includes for AVR and chibios * audio-refactoring: timbre: use uint8 instead of float * audio-refactoring: duration: use uint16 for internal per-tone/note state * audio-refactoring: tonemultiplexing: use uint16 instead of float * audio-arm-dac: additive: set second pin output-low used when a piezo is connected to AUDIO_PIN and AUDIO_PIN_ALT, with PIN_ALT_AS_NEGATIVE * audio-refactoring: move AUDIO_PIN selection from rules.mk to config.h to be consistent with how other features are handled in QMK * audio-refactoring: buildfix: wrong legacy macro for set_tempo * audio-arm-dac: additive: set second pin output-low -- FIXUP * audio.c: do duration<>ms conversion in uint instead of float on AVR, to save a couple of bytes in the firmware size * audio-refactoring: cleanup eeprom defines/usage for ARM, avr is handled automagically through the avr libc and common_features.mk Co-Authored-By: Drashna Jaelre <drashna@live.com> * audio.h: throw an error if OFF is larger than MAX * audio-arm-dac: basic: actually stop the dac-conversion on a audio_driver_stop to put the output pin in a known state == AUDIO_DAC_OFF_VALUE, instead of just leaving them where the last conversion was... with AUDIO_PIN_ALT_AS_NEGATIVE this meant one output was left HIGH while the other was left LOW one CAVEAT: due to this change the opposing squarewave when using both A4 and A5 with AUDIO_PIN_ALT_AS_NEGATIVE show extra pulses at the beginning/end on one of the outputs, the two waveforms are in sync otherwise. the extra pusles probably matter little, since this is no high-fidelity sound generation :P * audio-arm-dac: additive: move zero-crossing code out of dac_value_generate which is/should be user-overridable == simple, and doing one thing: providing sample values state-transitions necessary for the zero crossing are better handled in the surrounding loop in the dac_end callback * audio-arm-dac: dac-additive: zero-crossing: ramping up or down after a start trigger ramp up: generate values until zero=OFF_VALUE is reached, then continue normally same in reverse for strop trigger: output values until zero is reached/crossed, then keep OFF_VALUE on the output * audio-arm-dac: dac-additive: BUGFIX: return OFF_VALUE when a pause is playing fixes a bug during SONG playback, which suddenly stopped when it encoutnered a pause * audio-arm-dac: set a sensible default for AUDIO_DAC_VALUE_OFF 1/2 MAX was probably exemplary, can't think of a setup where that would make sense :-P * audio-arm-dac: update synth_sample/_wavetable for new pin-defines * audio-arm-dac: default for AUDIO_DAC_VALUE_OFF turned out that zero or max are bad default choices: when multiple tones are played (>>5) and released at the same time (!), due to the complex waveform never reaching 'zero' the output can take quite a while to reach zero, and hence the zero-crossing code only "releases" the output waaay to late * audio-arm-dac: additive: use DAC for negative pin instead of PAL, which only allows the pin to be configured as output; LOW or HIGH * audio-arm-dac: more compile-time configuration checks * audio-refactoring: typo fixed * audio-refactoring: clang-format on quantum/audio/* * audio-avr-pwm: add defines for B-pin as primary/only speaker also updates documentation. * audio-refactoring: update documentation with proton-c config.h example * audio-refactoring: move glissando (TODO) to voices.c refactored/saved from the original glissando implementation in then upstream-master:audio_avr.c still needs some work though, as it is now the calculation *should* work, but the start-frequency needs to be tracked somewhere/somehow; not only during a SONG playback but also with user input? * audio-refactoring: cleanup: one round of aspell -c * audio-avr-pwm: back to AUDIO_PIN since config_common.h expands them to plain integers, the AUDIO_PIN define can directly be compared to e.g. B5 so there is no need to deal with separate defines like AUDIO_PIN_B5 * audio-refactoring: add technical documentation audio_driver.md which moves some in-code documentation there * audio-arm-dac: move AUDIO_PIN checks into c-code instead of doing everything with the preprocessor, since A4/A5 do not expand to simple integers, preprocessor int-comparison is not possible. but necessary to get a consistent configuration scheme going throughout the audio-code... solution: let c-code handle the different AUDIO_PIN configurations instead (and leave code/size optimizations to the compiler) * audio-arm-dac: compile-fix: set AUDIO_PIN if unset workaround to get the build going again, and be backwarts compatible to arm-keyboards which not yet set the AUDIO_PIN define. until the define is enforced through an '#error" * audio-refactoring: document tone-multiplexing feature * audio-refactoring: Apply suggestions from documentation review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-refactoring: Update docs/audio_driver.md * audio-refactoring: docs: fix markdown newlines Terminating a line in Markdown with <space>-<space>-<linebreak> creates an HTML single-line break (<br>). Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * audio-arm-dac: additive: fix AUDIO_PIN_ALT handling * audio-arm-pwm: align define naming with other drivers Co-authored-by: Joel Challis <git@zvecr.com> * audio-refactoring: set detault tempo to 120 and add documentation for the override * audio-refactoring: update backlight define checks to new AUDIO_PIN names * audio-refactoring: reworking PWM related defines to be more consistent with other QMK code Co-authored-by: Joel Challis <git@zvecr.com> * audio-arm: have the state-update-timer user configurable defaulting to GPTD6 or GPTD8 for stm32f2+ (=proton-c) stm32f1 might need to set this to GPTD4, since 6 and 8 are not available * audio-refactoring: PLAY_NOTE_ARRAY was already removed in master * Add prototype for startup * Update chibiOS dac basic to disable pins on stop * Add defaults for Proton C * avoid hanging audio if note is completely missed * Don't redefine pins if they're already defined * Define A4 and A5 for CTPC support * Add license headers to keymap files * Remove figlet? comments * Add DAC config to audio driver docs * Apply suggestions from code review Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Add license header to py files * correct license header * Add JohSchneider's name to modified files AKA credit where credit's due * Set executable permission and change interpeter * Add 'wave' to pip requirements * Improve documentation * Add some settings I missed * Strip AUDIO_DRIVER to parse the name correctly * fix depreciated * Update util/audio_generate_dac_lut.py Co-authored-by: Jack Humbert <jack.humb@gmail.com> * Fix type in clueboard config * Apply suggestions from tzarc Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Johannes <you@example.com> Co-authored-by: JohSchneider <JohSchneider@googlemail.com> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Joshua Diamond <josh@windowoffire.com> Co-authored-by: Jack Humbert <jack.humb@gmail.com>
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
Simplify split_common Code significantly (#4772) * Eliminate separate slave loop Both master and slave run the standard keyboard_task main loop now. * Refactor i2c/serial specific code Simplify some of the preprocessor mess by using common function names. * Fix missing #endif * Move direct pin mapping support from miniaxe to split_common For boards with more pins than sense--sorry, switches. * Reordering and reformatting only * Don't run matrix_scan_quantum on slave side * Clean up the offset/slaveOffset calculations * Cut undebounced matrix size in half * Refactor debouncing * Minor fixups * Split split_common transport and debounce code into their own files Can now be replaced with custom versions per keyboard using CUSTOM_TRANSPORT = yes and CUSTOM_DEBOUNCE = yes * Refactor debounce for non-split keyboards too * Update handwired/xealous to build using new split_common * Fix debounce breaking basic test * Dodgy method to allow a split kb to only include one of i2c/serial SPLIT_TRANSPORT = serial or SPLIT_TRANSPORT = i2c will include only that driver code in the binary. SPLIT_TRANSPORT = custom (or anything else) will include neither, the keyboard must supply it's own code if SPLIT_TRANSPORT is not defined then the original behaviour (include both avr i2c and serial code) is maintained. This could be better but it would require explicitly updating all the existing split keyboards. * Enable LTO to get lets_split/sockets under the line * Add docs for SPLIT_TRANSPORT, CUSTOM_MATRIX, CUSTOM_DEBOUNCE * Remove avr-specific sei() from split matrix_setup Not needed now that slave doesn't have a separate main loop. Both sides (on avr) call sei() in lufa's main() after exiting keyboard_setup(). * Fix QUANTUM_LIB_SRC references and simplify SPLIT_TRANSPORT. * Add comments and fix formatting.
5 years ago
Change split_common to use RGBLIGHT_SPLIT (#5509) * add I2C_slave_buffer_t to quantum/split_common/transport.c Improvements to ease the maintenance of the I2C slave buffer layout. And this commit does not change the compilation results. * add temporary pdhelix(Patched Helix) code * temporary cherry-pick from #5020 add new version(#5020) quantum/rgblight.[ch], quantum/rgblight_modes.h * add post_config.h support to build_keyboard.mk * add quantum/rgblight_post_config.h, quantum/split_common/post_config.h Add quantum/rgblight_post_config.h and quantum/split_common/post_config.h using POST_CONFIG_H variable of build_keyboard.mk. quantum/rgblight_post_config.h additionally defines RGBLIGHT_SPLIT if RGBLED_SPIT is defined. quantum/split_common/post_config.h defines RGBLIGHT_SPLIT additionally when master-slave communication is I2C. * Change split_common's transport.c I2C to use the synchronization feature of rgblight.c * Change split_common's transport.c serial to use the synchronization feature of rgblight.c * test RGBLIGHT_SPLIT on keyboards/handwired/pdhelix * Test End Revert "test RGBLIGHT_SPLIT on keyboards/handwired/pdhelix" This reverts commit 80118a6bbd3d9fc4c7797fef0c34bc67aa73aa98. [x] make RGBLIGHT_TEST=1 handwired/pdhelix/i2c:default [x] make RGBLIGHT_TEST=2 handwired/pdhelix/i2c:default (same RGBLIGHT_TEST=3) [x] make RGBLIGHT_TEST=3 handwired/pdhelix/i2c:default [x] make RGBLIGHT_TEST=1 handwired/pdhelix/pd2:default [x] make RGBLIGHT_TEST=2 handwired/pdhelix/pd2:default [x] make RGBLIGHT_TEST=3 handwired/pdhelix/pd2:default [x] make RGBLIGHT_TEST=1 handwired/pdhelix/pd2_2oled:default [x] make RGBLIGHT_TEST=2 handwired/pdhelix/pd2_2oled:default [x] make RGBLIGHT_TEST=3 handwired/pdhelix/pd2_2oled:default * Test End, Revert "temporary cherry-pick from #5020" This reverts commit d35069f68bda0c50370442a5c7aae60c2f4ce5c0. * Test End, Revert "add temporary pdhelix(Patched Helix) code" This reverts commit aebddfc1a879796afae297ef0723a4fe73af3660. * temporarily cherry-pick from #5020 to see if it passes the travis-ci test. add new version(#5020) quantum/rgblight.[ch], quantum/rgblight_modes.h * Passed the travis-ci test. Revert "temporarily cherry-pick from #5020 to see if it passes the travis-ci test." This reverts commit 647c0a9755eb6a05f76d09b2d59bce67b85a841f. * update docs/config_options.md * update split_common/transport.c, improves maintainability of serial transaction IDs. No change in build result. * temporary cherry-pick from #5020 * fix build fail keebio/iris/rev3:default * fix build fail lets_split_eh/eh:default * Revert "temporary cherry-pick from #5020" This reverts commit be48ca1b4515366a097af8dd1cd7b28b7ee09947. * temporary cherry-pick from #5020 (0.6.336) * Revert "temporary cherry-pick from #5020 (0.6.336)" This reverts commit 978d26a8b3cf0acc485838a7d76d6128b77c630c. * temporary cherry-pick from #5020 (0.6.336)
5 years ago
Change split_common to use RGBLIGHT_SPLIT (#5509) * add I2C_slave_buffer_t to quantum/split_common/transport.c Improvements to ease the maintenance of the I2C slave buffer layout. And this commit does not change the compilation results. * add temporary pdhelix(Patched Helix) code * temporary cherry-pick from #5020 add new version(#5020) quantum/rgblight.[ch], quantum/rgblight_modes.h * add post_config.h support to build_keyboard.mk * add quantum/rgblight_post_config.h, quantum/split_common/post_config.h Add quantum/rgblight_post_config.h and quantum/split_common/post_config.h using POST_CONFIG_H variable of build_keyboard.mk. quantum/rgblight_post_config.h additionally defines RGBLIGHT_SPLIT if RGBLED_SPIT is defined. quantum/split_common/post_config.h defines RGBLIGHT_SPLIT additionally when master-slave communication is I2C. * Change split_common's transport.c I2C to use the synchronization feature of rgblight.c * Change split_common's transport.c serial to use the synchronization feature of rgblight.c * test RGBLIGHT_SPLIT on keyboards/handwired/pdhelix * Test End Revert "test RGBLIGHT_SPLIT on keyboards/handwired/pdhelix" This reverts commit 80118a6bbd3d9fc4c7797fef0c34bc67aa73aa98. [x] make RGBLIGHT_TEST=1 handwired/pdhelix/i2c:default [x] make RGBLIGHT_TEST=2 handwired/pdhelix/i2c:default (same RGBLIGHT_TEST=3) [x] make RGBLIGHT_TEST=3 handwired/pdhelix/i2c:default [x] make RGBLIGHT_TEST=1 handwired/pdhelix/pd2:default [x] make RGBLIGHT_TEST=2 handwired/pdhelix/pd2:default [x] make RGBLIGHT_TEST=3 handwired/pdhelix/pd2:default [x] make RGBLIGHT_TEST=1 handwired/pdhelix/pd2_2oled:default [x] make RGBLIGHT_TEST=2 handwired/pdhelix/pd2_2oled:default [x] make RGBLIGHT_TEST=3 handwired/pdhelix/pd2_2oled:default * Test End, Revert "temporary cherry-pick from #5020" This reverts commit d35069f68bda0c50370442a5c7aae60c2f4ce5c0. * Test End, Revert "add temporary pdhelix(Patched Helix) code" This reverts commit aebddfc1a879796afae297ef0723a4fe73af3660. * temporarily cherry-pick from #5020 to see if it passes the travis-ci test. add new version(#5020) quantum/rgblight.[ch], quantum/rgblight_modes.h * Passed the travis-ci test. Revert "temporarily cherry-pick from #5020 to see if it passes the travis-ci test." This reverts commit 647c0a9755eb6a05f76d09b2d59bce67b85a841f. * update docs/config_options.md * update split_common/transport.c, improves maintainability of serial transaction IDs. No change in build result. * temporary cherry-pick from #5020 * fix build fail keebio/iris/rev3:default * fix build fail lets_split_eh/eh:default * Revert "temporary cherry-pick from #5020" This reverts commit be48ca1b4515366a097af8dd1cd7b28b7ee09947. * temporary cherry-pick from #5020 (0.6.336) * Revert "temporary cherry-pick from #5020 (0.6.336)" This reverts commit 978d26a8b3cf0acc485838a7d76d6128b77c630c. * temporary cherry-pick from #5020 (0.6.336)
5 years ago
Lets split eh (#3120) * Line ending stuff again * Added Let's Split Eh? Files and updated #USE_IC2 checks to also include th EH revision (can only be used in I2C) * Added personal keymap, updated some of the EH files * Created new keyboard file for testing "lets_split_eh" will merge into lets_split once fully functional * Added split code from lets_split, removed pro micro imports and LED code THIS IS WORKING CODE, WITHOUT RGB AND BACKLIGHT * Took back original Lets Slit files for the lets_split keyboard, working in the lets_split_eh folder for now * Updated eh.c * More rework of the I2C code, added global flags for split boards. * Introduced RGB over I2C, having weird edge case issues at the moment though * Fixed weird I2C edgecase with RGB, although still would like to track down route cause.. * Changed RGB keycodes (static ones) to activate on key-up instead of key-down to elimate weird ghosting issue over I2C * Lots of changes, mainly externalized the Split keyboard code and added logic for only including when needed. - Added makefile option "SPLIT_KEYBOARD" that when = yes will include the split keyboard files and custom matrix - Split keyboard files placed into quantum/split_common/ - Added define option for config files "SPLIT_HAND_PIN" FOr using high/low pin to determine handedness, low = right hand, high = left hand - Cleaned up split logic for RGB and Backlight so it is only exectuted / included when needed * Updated documentation for the new makefile options and #defines specific to split keyboards * Added a bit more info to docs, so people aren't confused * Modifed Let's Split to use externalized code, also added left and right hand eeprom files to the split_common folder * Removed some debugging from eh.c * Small changes to keyboard configs. Also added a default keymap (just a copy of my that_canadian keymap). * Added a README file to the Let's Split Eh? * Changed it so RGB static updates are done on key-up ONLY for split boards rather than all boards. Also fixed leftover un-used variable in rgblight.c * Updated default keymap and my keymap for Let's Split Eh? Updated the comments so it reflects RGB control, and removed audio functions. * Fixed lets_split_eh not having a default version * Removed "eh" references from lets_split folder for now * Took lets_split folder from master to fix travis build errors, weird my local was overriding. * Changed LAYOUT_ortho_4x12_kc -> LAYOUT_kc_ortho_4x12 to match bakingpy and others * Removed rules.mk from my lets_split keymap, not needed * Updated the config_options doc to better explain the usage of "#define SPLIT_HAND_PIN"
5 years ago
Simplify split_common Code significantly (#4772) * Eliminate separate slave loop Both master and slave run the standard keyboard_task main loop now. * Refactor i2c/serial specific code Simplify some of the preprocessor mess by using common function names. * Fix missing #endif * Move direct pin mapping support from miniaxe to split_common For boards with more pins than sense--sorry, switches. * Reordering and reformatting only * Don't run matrix_scan_quantum on slave side * Clean up the offset/slaveOffset calculations * Cut undebounced matrix size in half * Refactor debouncing * Minor fixups * Split split_common transport and debounce code into their own files Can now be replaced with custom versions per keyboard using CUSTOM_TRANSPORT = yes and CUSTOM_DEBOUNCE = yes * Refactor debounce for non-split keyboards too * Update handwired/xealous to build using new split_common * Fix debounce breaking basic test * Dodgy method to allow a split kb to only include one of i2c/serial SPLIT_TRANSPORT = serial or SPLIT_TRANSPORT = i2c will include only that driver code in the binary. SPLIT_TRANSPORT = custom (or anything else) will include neither, the keyboard must supply it's own code if SPLIT_TRANSPORT is not defined then the original behaviour (include both avr i2c and serial code) is maintained. This could be better but it would require explicitly updating all the existing split keyboards. * Enable LTO to get lets_split/sockets under the line * Add docs for SPLIT_TRANSPORT, CUSTOM_MATRIX, CUSTOM_DEBOUNCE * Remove avr-specific sei() from split matrix_setup Not needed now that slave doesn't have a separate main loop. Both sides (on avr) call sei() in lufa's main() after exiting keyboard_setup(). * Fix QUANTUM_LIB_SRC references and simplify SPLIT_TRANSPORT. * Add comments and fix formatting.
5 years ago
Simplify split_common Code significantly (#4772) * Eliminate separate slave loop Both master and slave run the standard keyboard_task main loop now. * Refactor i2c/serial specific code Simplify some of the preprocessor mess by using common function names. * Fix missing #endif * Move direct pin mapping support from miniaxe to split_common For boards with more pins than sense--sorry, switches. * Reordering and reformatting only * Don't run matrix_scan_quantum on slave side * Clean up the offset/slaveOffset calculations * Cut undebounced matrix size in half * Refactor debouncing * Minor fixups * Split split_common transport and debounce code into their own files Can now be replaced with custom versions per keyboard using CUSTOM_TRANSPORT = yes and CUSTOM_DEBOUNCE = yes * Refactor debounce for non-split keyboards too * Update handwired/xealous to build using new split_common * Fix debounce breaking basic test * Dodgy method to allow a split kb to only include one of i2c/serial SPLIT_TRANSPORT = serial or SPLIT_TRANSPORT = i2c will include only that driver code in the binary. SPLIT_TRANSPORT = custom (or anything else) will include neither, the keyboard must supply it's own code if SPLIT_TRANSPORT is not defined then the original behaviour (include both avr i2c and serial code) is maintained. This could be better but it would require explicitly updating all the existing split keyboards. * Enable LTO to get lets_split/sockets under the line * Add docs for SPLIT_TRANSPORT, CUSTOM_MATRIX, CUSTOM_DEBOUNCE * Remove avr-specific sei() from split matrix_setup Not needed now that slave doesn't have a separate main loop. Both sides (on avr) call sei() in lufa's main() after exiting keyboard_setup(). * Fix QUANTUM_LIB_SRC references and simplify SPLIT_TRANSPORT. * Add comments and fix formatting.
5 years ago
Lets split eh (#3120) * Line ending stuff again * Added Let's Split Eh? Files and updated #USE_IC2 checks to also include th EH revision (can only be used in I2C) * Added personal keymap, updated some of the EH files * Created new keyboard file for testing "lets_split_eh" will merge into lets_split once fully functional * Added split code from lets_split, removed pro micro imports and LED code THIS IS WORKING CODE, WITHOUT RGB AND BACKLIGHT * Took back original Lets Slit files for the lets_split keyboard, working in the lets_split_eh folder for now * Updated eh.c * More rework of the I2C code, added global flags for split boards. * Introduced RGB over I2C, having weird edge case issues at the moment though * Fixed weird I2C edgecase with RGB, although still would like to track down route cause.. * Changed RGB keycodes (static ones) to activate on key-up instead of key-down to elimate weird ghosting issue over I2C * Lots of changes, mainly externalized the Split keyboard code and added logic for only including when needed. - Added makefile option "SPLIT_KEYBOARD" that when = yes will include the split keyboard files and custom matrix - Split keyboard files placed into quantum/split_common/ - Added define option for config files "SPLIT_HAND_PIN" FOr using high/low pin to determine handedness, low = right hand, high = left hand - Cleaned up split logic for RGB and Backlight so it is only exectuted / included when needed * Updated documentation for the new makefile options and #defines specific to split keyboards * Added a bit more info to docs, so people aren't confused * Modifed Let's Split to use externalized code, also added left and right hand eeprom files to the split_common folder * Removed some debugging from eh.c * Small changes to keyboard configs. Also added a default keymap (just a copy of my that_canadian keymap). * Added a README file to the Let's Split Eh? * Changed it so RGB static updates are done on key-up ONLY for split boards rather than all boards. Also fixed leftover un-used variable in rgblight.c * Updated default keymap and my keymap for Let's Split Eh? Updated the comments so it reflects RGB control, and removed audio functions. * Fixed lets_split_eh not having a default version * Removed "eh" references from lets_split folder for now * Took lets_split folder from master to fix travis build errors, weird my local was overriding. * Changed LAYOUT_ortho_4x12_kc -> LAYOUT_kc_ortho_4x12 to match bakingpy and others * Removed rules.mk from my lets_split keymap, not needed * Updated the config_options doc to better explain the usage of "#define SPLIT_HAND_PIN"
5 years ago
Make quantum/split_common/serial.[ch] configurable (#4419) * add temporary compile test shell script * add 'CONFIG_H += serial_backward_compatibility.h' into common_features.mk:SPLIT_KEYBOARD block * add quantum/split_common/serial_backward_compatibility.h SERIAL_PIN_PORT and other PIN define move to serial_backward_compatibility.h SERIAL_BACKLIT_START move to split_util.h * quantum/split_common/serial.c change to helix-serial.c style serial configuration * add temporary file quantum/split_common/split-keyboards-list.txt * add '#define SOFT_SERIAL_PIN D0' to keyboards/6lit/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/divergetm2/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/ergotravel/rev1/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/foobar/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/handwired/dactyl_manuform/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/handwired/qc60/config.h * add '//#define SOFT_SERIAL_PIN D0' to keyboards/handwired/xealous/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/iris/rev*/config.h * add '//#define SOFT_SERIAL_PIN D0' to keyboards/lets_split_eh/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/levinson/rev*/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/miniaxe/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/nyquist/rev?/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/quefrency/rev1/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/qwertyydox/config.h,keyboards/qwertyydox/rev1/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/redox/rev1/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/rorschach/rev1/config.h * remove '#define SOFT_SERIAL_PIN D0' from quantum/split_common/serial_backward_compatibility.h * remove temporary file quantum/split_common/split-keyboards-list.txt * remove temporary compile test shell script * Revert "remove temporary compile test shell script" This reverts commit 15b0021b4092127b8d8a21f572642ad3702b46d4. * update quantum/split_common/compile_split_test.sh for new keyboard test * add '#define SOFT_SERIAL_PIN D0' to keyboards/diverge3/config.h * add '#define SOFT_SERIAL_PIN D0' to keyboards/40percentclub/25/config.h * remove temporary compile test shell script * update docs/config_options.md, quantum/template/avr/config.h * fix quantum/template/avr/config.h * fix typo docs/config_options.md
5 years ago
Lets split eh (#3120) * Line ending stuff again * Added Let's Split Eh? Files and updated #USE_IC2 checks to also include th EH revision (can only be used in I2C) * Added personal keymap, updated some of the EH files * Created new keyboard file for testing "lets_split_eh" will merge into lets_split once fully functional * Added split code from lets_split, removed pro micro imports and LED code THIS IS WORKING CODE, WITHOUT RGB AND BACKLIGHT * Took back original Lets Slit files for the lets_split keyboard, working in the lets_split_eh folder for now * Updated eh.c * More rework of the I2C code, added global flags for split boards. * Introduced RGB over I2C, having weird edge case issues at the moment though * Fixed weird I2C edgecase with RGB, although still would like to track down route cause.. * Changed RGB keycodes (static ones) to activate on key-up instead of key-down to elimate weird ghosting issue over I2C * Lots of changes, mainly externalized the Split keyboard code and added logic for only including when needed. - Added makefile option "SPLIT_KEYBOARD" that when = yes will include the split keyboard files and custom matrix - Split keyboard files placed into quantum/split_common/ - Added define option for config files "SPLIT_HAND_PIN" FOr using high/low pin to determine handedness, low = right hand, high = left hand - Cleaned up split logic for RGB and Backlight so it is only exectuted / included when needed * Updated documentation for the new makefile options and #defines specific to split keyboards * Added a bit more info to docs, so people aren't confused * Modifed Let's Split to use externalized code, also added left and right hand eeprom files to the split_common folder * Removed some debugging from eh.c * Small changes to keyboard configs. Also added a default keymap (just a copy of my that_canadian keymap). * Added a README file to the Let's Split Eh? * Changed it so RGB static updates are done on key-up ONLY for split boards rather than all boards. Also fixed leftover un-used variable in rgblight.c * Updated default keymap and my keymap for Let's Split Eh? Updated the comments so it reflects RGB control, and removed audio functions. * Fixed lets_split_eh not having a default version * Removed "eh" references from lets_split folder for now * Took lets_split folder from master to fix travis build errors, weird my local was overriding. * Changed LAYOUT_ortho_4x12_kc -> LAYOUT_kc_ortho_4x12 to match bakingpy and others * Removed rules.mk from my lets_split keymap, not needed * Updated the config_options doc to better explain the usage of "#define SPLIT_HAND_PIN"
5 years ago
Simplify split_common Code significantly (#4772) * Eliminate separate slave loop Both master and slave run the standard keyboard_task main loop now. * Refactor i2c/serial specific code Simplify some of the preprocessor mess by using common function names. * Fix missing #endif * Move direct pin mapping support from miniaxe to split_common For boards with more pins than sense--sorry, switches. * Reordering and reformatting only * Don't run matrix_scan_quantum on slave side * Clean up the offset/slaveOffset calculations * Cut undebounced matrix size in half * Refactor debouncing * Minor fixups * Split split_common transport and debounce code into their own files Can now be replaced with custom versions per keyboard using CUSTOM_TRANSPORT = yes and CUSTOM_DEBOUNCE = yes * Refactor debounce for non-split keyboards too * Update handwired/xealous to build using new split_common * Fix debounce breaking basic test * Dodgy method to allow a split kb to only include one of i2c/serial SPLIT_TRANSPORT = serial or SPLIT_TRANSPORT = i2c will include only that driver code in the binary. SPLIT_TRANSPORT = custom (or anything else) will include neither, the keyboard must supply it's own code if SPLIT_TRANSPORT is not defined then the original behaviour (include both avr i2c and serial code) is maintained. This could be better but it would require explicitly updating all the existing split keyboards. * Enable LTO to get lets_split/sockets under the line * Add docs for SPLIT_TRANSPORT, CUSTOM_MATRIX, CUSTOM_DEBOUNCE * Remove avr-specific sei() from split matrix_setup Not needed now that slave doesn't have a separate main loop. Both sides (on avr) call sei() in lufa's main() after exiting keyboard_setup(). * Fix QUANTUM_LIB_SRC references and simplify SPLIT_TRANSPORT. * Add comments and fix formatting.
5 years ago
Use a single endpoint for HID reports (#3951) * Unify multiple HID interfaces into one This reduces the number of USB endpoints required, which frees them up for other things. NKRO and EXTRAKEY always use the shared endpoint. By default, MOUSEKEY also uses it. This means it won't work as a Boot Procotol mouse in some BIOSes, etc. If you really think your keyboard needs to work as a mouse in your BIOS, set MOUSE_SHARED_EP = no in your rules.mk. By default, the core keyboard does not use the shared endpoint, as not all BIOSes are standards compliant and that's one place you don't want to find out your keyboard doesn't work.. If you are really confident, you can set KEYBOARD_SHARED_EP = yes to use the shared endpoint here too. * unify endpoints: ChibiOS protocol implementation * fixup: missing #ifdef EXTRAKEY_ENABLEs broke build on AVR with EXTRAKEY disabled * endpoints: restore error when too many endpoints required * lufa: wait up to 10ms to send keyboard input This avoids packets being dropped when two reports are sent in quick succession (eg. releasing a dual role key). * endpoints: fix compile on ARM_ATSAM * endpoint: ARM_ATSAM fixes No longer use wrong or unexpected endpoint IDs * endpoints: accommodate VUSB protocol V-USB has its own, understandably simple ideas about the report formats. It already blasts the mouse and extrakeys through one endpoint with report IDs. We just stay out of its way. * endpoints: document new endpoint configuration options * endpoints: respect keyboard_report->mods in NKRO The caller(s) of host_keyboard_send expect to be able to just drop modifiers in the mods field and not worry about whether NKRO is in use. This is a good thing. So we just shift it over if needs be. * endpoints: report.c: update for new keyboard_report format
5 years ago
  1. # Configuring QMK
  2. QMK is nearly infinitely configurable. Wherever possible we err on the side of allowing users to customize their keyboard, even at the expense of code size. That level of flexibility makes for a daunting configuration experience, however.
  3. There are two main types of configuration files in QMK- `config.h` and `rules.mk`. These files exist at various levels in QMK and all files of the same type are combined to build the final configuration. The levels, from lowest priority to highest priority, are:
  4. * QMK Default
  5. * Keyboard
  6. * Folders (Up to 5 levels deep)
  7. * Keymap
  8. ## QMK Default
  9. Every available setting in QMK has a default. If that setting is not set at the Keyboard, Folder, or Keymap level this is the setting that will be used.
  10. ## Keyboard
  11. This level contains config options that should apply to the whole keyboard. Some settings won't change in revisions, or most keymaps. Other settings are merely defaults for this keyboard and can be overridden by folders and/or keymaps.
  12. ## Folders
  13. Some keyboards have folders and sub-folders to allow for different hardware configurations. Most keyboards only go 1 folder deep, but QMK supports structures up to 5 folders deep. Each folder can have its own `config.h` and `rules.mk` files that are incorporated into the final configuration.
  14. ## Keymap
  15. This level contains all of the options for that particular keymap. If you wish to override a previous declaration, you can use `#undef <variable>` to undefine it, where you can then redefine it without an error.
  16. # The `config.h` File
  17. This is a C header file that is one of the first things included, and will persist over the whole project (if included). Lots of variables can be set here and accessed elsewhere. The `config.h` file shouldn't be including other `config.h` files, or anything besides this:
  18. ```c
  19. #include "config_common.h"
  20. ```
  21. ## Hardware Options
  22. * `#define VENDOR_ID 0x1234`
  23. * defines your VID, and for most DIY projects, can be whatever you want
  24. * `#define PRODUCT_ID 0x5678`
  25. * defines your PID, and for most DIY projects, can be whatever you want
  26. * `#define DEVICE_VER 0`
  27. * defines the device version (often used for revisions)
  28. * `#define MANUFACTURER Me`
  29. * generally who/whatever brand produced the board
  30. * `#define PRODUCT Board`
  31. * the name of the keyboard
  32. * `#define MATRIX_ROWS 5`
  33. * the number of rows in your keyboard's matrix
  34. * `#define MATRIX_COLS 15`
  35. * the number of columns in your keyboard's matrix
  36. * `#define MATRIX_ROW_PINS { D0, D5, B5, B6 }`
  37. * pins of the rows, from top to bottom
  38. * `#define MATRIX_COL_PINS { F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 }`
  39. * pins of the columns, from left to right
  40. * `#define MATRIX_IO_DELAY 30`
  41. * the delay in microseconds when between changing matrix pin state and reading values
  42. * `#define UNUSED_PINS { D1, D2, D3, B1, B2, B3 }`
  43. * pins unused by the keyboard for reference
  44. * `#define MATRIX_HAS_GHOST`
  45. * define is matrix has ghost (unlikely)
  46. * `#define DIODE_DIRECTION COL2ROW`
  47. * COL2ROW or ROW2COL - how your matrix is configured. COL2ROW means the black mark on your diode is facing to the rows, and between the switch and the rows.
  48. * `#define DIRECT_PINS { { F1, F0, B0, C7 }, { F4, F5, F6, F7 } }`
  49. * pins mapped to rows and columns, from left to right. Defines a matrix where each switch is connected to a separate pin and ground.
  50. * `#define AUDIO_VOICES`
  51. * turns on the alternate audio voices (to cycle through)
  52. * `#define C4_AUDIO`
  53. * enables audio on pin C4
  54. * Deprecated. Use `#define AUDIO_PIN C4`
  55. * `#define C5_AUDIO`
  56. * enables audio on pin C5
  57. * Deprecated. Use `#define AUDIO_PIN C5`
  58. * `#define C6_AUDIO`
  59. * enables audio on pin C6
  60. * Deprecated. Use `#define AUDIO_PIN C6`
  61. * `#define B5_AUDIO`
  62. * enables audio on pin B5 (duophony is enabled if one of B pins is enabled along with one of C pins)
  63. * Deprecated. Use `#define AUDIO_PIN B5`, or use `#define AUDIO_PIN_ALT B5` if a `C` pin is enabled with `AUDIO_PIN`
  64. * `#define B6_AUDIO`
  65. * enables audio on pin B5 (duophony is enabled if one of B pins is enabled along with one of C pins)
  66. * Deprecated. Use `#define AUDIO_PIN B6`, or use `#define AUDIO_PIN_ALT B6` if a `C` pin is enabled with `AUDIO_PIN`
  67. * `#define B7_AUDIO`
  68. * enables audio on pin B5 (duophony is enabled if one of B pins is enabled along with one of C pins)
  69. * Deprecated. Use `#define AUDIO_PIN B7`, or use `#define AUDIO_PIN_ALT B7` if a `C` pin is enabled with `AUDIO_PIN`
  70. * `#define BACKLIGHT_PIN B7`
  71. * pin of the backlight
  72. * `#define BACKLIGHT_LEVELS 3`
  73. * number of levels your backlight will have (maximum 31 excluding off)
  74. * `#define BACKLIGHT_BREATHING`
  75. * enables backlight breathing
  76. * `#define BREATHING_PERIOD 6`
  77. * the length of one backlight "breath" in seconds
  78. * `#define DEBOUNCE 5`
  79. * the delay when reading the value of the pin (5 is default)
  80. * `#define LOCKING_SUPPORT_ENABLE`
  81. * mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap
  82. * `#define LOCKING_RESYNC_ENABLE`
  83. * tries to keep switch state consistent with keyboard LED state
  84. * `#define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT)`
  85. * key combination that allows the use of magic commands (useful for debugging)
  86. * `#define USB_MAX_POWER_CONSUMPTION 500`
  87. * sets the maximum power (in mA) over USB for the device (default: 500)
  88. * `#define USB_POLLING_INTERVAL_MS 10`
  89. * sets the USB polling rate in milliseconds for the keyboard, mouse, and shared (NKRO/media keys) interfaces
  90. * `#define USB_SUSPEND_WAKEUP_DELAY 200`
  91. * set the number of milliseconde to pause after sending a wakeup packet
  92. * `#define F_SCL 100000L`
  93. * sets the I2C clock rate speed for keyboards using I2C. The default is `400000L`, except for keyboards using `split_common`, where the default is `100000L`.
  94. ## Features That Can Be Disabled
  95. If you define these options you will disable the associated feature, which can save on code size.
  96. * `#define NO_DEBUG`
  97. * disable debugging
  98. * `#define NO_PRINT`
  99. * disable printing/debugging using hid_listen
  100. * `#define NO_ACTION_LAYER`
  101. * disable layers
  102. * `#define NO_ACTION_TAPPING`
  103. * disable tap dance and other tapping features
  104. * `#define NO_ACTION_ONESHOT`
  105. * disable one-shot modifiers
  106. * `#define NO_ACTION_MACRO`
  107. * disable old-style macro handling using `MACRO()`, `action_get_macro()` _(deprecated)_
  108. * `#define NO_ACTION_FUNCTION`
  109. * disable old-style function handling using `fn_actions`, `action_function()` _(deprecated)_
  110. ## Features That Can Be Enabled
  111. If you define these options you will enable the associated feature, which may increase your code size.
  112. * `#define FORCE_NKRO`
  113. * NKRO by default requires to be turned on, this forces it on during keyboard startup regardless of EEPROM setting. NKRO can still be turned off but will be turned on again if the keyboard reboots.
  114. * `#define STRICT_LAYER_RELEASE`
  115. * force a key release to be evaluated using the current layer stack instead of remembering which layer it came from (used for advanced cases)
  116. ## Behaviors That Can Be Configured
  117. * `#define TAPPING_TERM 200`
  118. * how long before a tap becomes a hold, if set above 500, a key tapped during the tapping term will turn it into a hold too
  119. * `#define TAPPING_TERM_PER_KEY`
  120. * enables handling for per key `TAPPING_TERM` settings
  121. * `#define RETRO_TAPPING`
  122. * tap anyway, even after TAPPING_TERM, if there was no other key interruption between press and release
  123. * See [Retro Tapping](tap_hold.md#retro-tapping) for details
  124. * `#define RETRO_TAPPING_PER_KEY`
  125. * enables handling for per key `RETRO_TAPPING` settings
  126. * `#define TAPPING_TOGGLE 2`
  127. * how many taps before triggering the toggle
  128. * `#define PERMISSIVE_HOLD`
  129. * makes tap and hold keys trigger the hold if another key is pressed before releasing, even if it hasn't hit the `TAPPING_TERM`
  130. * See [Permissive Hold](tap_hold.md#permissive-hold) for details
  131. * `#define PERMISSIVE_HOLD_PER_KEY`
  132. * enabled handling for per key `PERMISSIVE_HOLD` settings
  133. * `#define IGNORE_MOD_TAP_INTERRUPT`
  134. * makes it possible to do rolling combos (zx) with keys that convert to other keys on hold, by enforcing the `TAPPING_TERM` for both keys.
  135. * See [Ignore Mod Tap Interrupt](tap_hold.md#ignore-mod-tap-interrupt) for details
  136. * `#define IGNORE_MOD_TAP_INTERRUPT_PER_KEY`
  137. * enables handling for per key `IGNORE_MOD_TAP_INTERRUPT` settings
  138. * `#define TAPPING_FORCE_HOLD`
  139. * makes it possible to use a dual role key as modifier shortly after having been tapped
  140. * See [Tapping Force Hold](tap_hold.md#tapping-force-hold)
  141. * Breaks any Tap Toggle functionality (`TT` or the One Shot Tap Toggle)
  142. * `#define TAPPING_FORCE_HOLD_PER_KEY`
  143. * enables handling for per key `TAPPING_FORCE_HOLD` settings
  144. * `#define LEADER_TIMEOUT 300`
  145. * how long before the leader key times out
  146. * If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped.
  147. * `#define LEADER_PER_KEY_TIMING`
  148. * sets the timer for leader key chords to run on each key press rather than overall
  149. * `#define LEADER_KEY_STRICT_KEY_PROCESSING`
  150. * Disables keycode filtering for Mod-Tap and Layer-Tap keycodes. Eg, if you enable this, you would need to specify `MT(MOD_CTL, KC_A)` if you want to use `KC_A`.
  151. * `#define ONESHOT_TIMEOUT 300`
  152. * how long before oneshot times out
  153. * `#define ONESHOT_TAP_TOGGLE 2`
  154. * how many taps before oneshot toggle is triggered
  155. * `#define QMK_KEYS_PER_SCAN 4`
  156. * Allows sending more than one key per scan. By default, only one key event gets
  157. sent via `process_record()` per scan. This has little impact on most typing, but
  158. if you're doing a lot of chords, or your scan rate is slow to begin with, you can
  159. have some delay in processing key events. Each press and release is a separate
  160. event. For a keyboard with 1ms or so scan times, even a very fast typist isn't
  161. going to produce the 500 keystrokes a second needed to actually get more than a
  162. few ms of delay from this. But if you're doing chording on something with 3-4ms
  163. scan times? You probably want this.
  164. * `#define COMBO_COUNT 2`
  165. * Set this to the number of combos that you're using in the [Combo](feature_combo.md) feature.
  166. * `#define COMBO_TERM 200`
  167. * how long for the Combo keys to be detected. Defaults to `TAPPING_TERM` if not defined.
  168. * `#define TAP_CODE_DELAY 100`
  169. * Sets the delay between `register_code` and `unregister_code`, if you're having issues with it registering properly (common on VUSB boards). The value is in milliseconds.
  170. * `#define TAP_HOLD_CAPS_DELAY 80`
  171. * Sets the delay for Tap Hold keys (`LT`, `MT`) when using `KC_CAPSLOCK` keycode, as this has some special handling on MacOS. The value is in milliseconds, and defaults to 80 ms if not defined. For macOS, you may want to set this to 200 or higher.
  172. ## RGB Light Configuration
  173. * `#define RGB_DI_PIN D7`
  174. * pin the DI on the WS2812 is hooked-up to
  175. * `#define RGBLIGHT_ANIMATIONS`
  176. * run RGB animations
  177. * `#define RGBLIGHT_LAYERS`
  178. * Lets you define [lighting layers](feature_rgblight.md?id=lighting-layers) that can be toggled on or off. Great for showing the current keyboard layer or caps lock state.
  179. * `#define RGBLIGHT_MAX_LAYERS`
  180. * Defaults to 8. Can be expanded up to 32 if more [lighting layers](feature_rgblight.md?id=lighting-layers) are needed.
  181. * Note: Increasing the maximum will increase the firmware size and slow sync on split keyboards.
  182. * `#define RGBLIGHT_LAYER_BLINK`
  183. * Adds ability to [blink](feature_rgblight.md?id=lighting-layer-blink) a lighting layer for a specified number of milliseconds (e.g. to acknowledge an action).
  184. * `#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF`
  185. * If defined, then [lighting layers](feature_rgblight?id=overriding-rgb-lighting-onoff-status) will be shown even if RGB Light is off.
  186. * `#define RGBLED_NUM 12`
  187. * number of LEDs
  188. * `#define RGBLIGHT_SPLIT`
  189. * Needed if both halves of the board have RGB LEDs wired directly to the RGB output pin on the controllers instead of passing the output of the left half to the input of the right half
  190. * `#define RGBLED_SPLIT { 6, 6 }`
  191. * number of LEDs connected that are directly wired to `RGB_DI_PIN` on each half of a split keyboard
  192. * First value indicates number of LEDs for left half, second value is for the right half
  193. * When RGBLED_SPLIT is defined, RGBLIGHT_SPLIT is implicitly defined.
  194. * `#define RGBLIGHT_HUE_STEP 12`
  195. * units to step when in/decreasing hue
  196. * `#define RGBLIGHT_SAT_STEP 25`
  197. * units to step when in/decreasing saturation
  198. * `#define RGBLIGHT_VAL_STEP 12`
  199. * units to step when in/decreasing value (brightness)
  200. * `#define RGBW`
  201. * Enables RGBW LED support
  202. ## Mouse Key Options
  203. * `#define MOUSEKEY_INTERVAL 20`
  204. * `#define MOUSEKEY_DELAY 0`
  205. * `#define MOUSEKEY_TIME_TO_MAX 60`
  206. * `#define MOUSEKEY_MAX_SPEED 7`
  207. * `#define MOUSEKEY_WHEEL_DELAY 0`
  208. ## Split Keyboard Options
  209. Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk
  210. * `SPLIT_TRANSPORT = custom`
  211. * Allows replacing the standard split communication routines with a custom one. ARM based split keyboards must use this at present.
  212. ### Setting Handedness
  213. One thing to remember, the side that the USB port is plugged into is always the master half. The side not plugged into USB is the slave.
  214. There are a few different ways to set handedness for split keyboards (listed in order of precedence):
  215. 1. Set `SPLIT_HAND_PIN`: Reads a pin to determine handedness. If pin is high, it's the left side, if low, the half is determined to be the right side
  216. 2. Set `EE_HANDS` and flash `eeprom-lefthand.eep`/`eeprom-righthand.eep` to each half
  217. * For boards with DFU bootloader you can use `:dfu-split-left`/`:dfu-split-right` to flash these EEPROM files
  218. * For boards with Caterina bootloader (like stock Pro Micros), use `:avrdude-split-left`/`:avrdude-split-right`
  219. * For boards with ARM DFU bootloader (like Proton C), use `:dfu-util-split-left`/`:dfu-util-split-right`
  220. 3. Set `MASTER_RIGHT`: Half that is plugged into the USB port is determined to be the master and right half (inverse of the default)
  221. 4. Default: The side that is plugged into the USB port is the master half and is assumed to be the left half. The slave side is the right half
  222. #### Defines for handedness
  223. * `#define SPLIT_HAND_PIN B7`
  224. * For using high/low pin to determine handedness, low = right hand, high = left hand. Replace `B7` with the pin you are using. This is optional, and if you leave `SPLIT_HAND_PIN` undefined, then you can still use the EE_HANDS method or MASTER_LEFT / MASTER_RIGHT defines like the stock Let's Split uses.
  225. * `#define SPLIT_HAND_MATRIX_GRID <out_pin>,<in_pin>`
  226. * The handedness is determined by using the intersection of the keyswitches in the key matrix, which does not exist. Normally, when this intersection is shorted (level low), it is considered left. If you define `#define SPLIT_HAND_MATRIX_GRID_LOW_IS_RIGHT`, it is determined to be right when the level is low.
  227. * `#define EE_HANDS` (only works if `SPLIT_HAND_PIN` and `SPLIT_HAND_MATRIX_GRID` are not defined)
  228. * Reads the handedness value stored in the EEPROM after `eeprom-lefthand.eep`/`eeprom-righthand.eep` has been flashed to their respective halves.
  229. * `#define MASTER_RIGHT`
  230. * Master half is defined to be the right half.
  231. ### Other Options
  232. * `#define USE_I2C`
  233. * For using I2C instead of Serial (defaults to serial)
  234. * `#define SOFT_SERIAL_PIN D0`
  235. * When using serial, define this. `D0` or `D1`,`D2`,`D3`,`E6`.
  236. * `#define MATRIX_ROW_PINS_RIGHT { <row pins> }`
  237. * `#define MATRIX_COL_PINS_RIGHT { <col pins> }`
  238. * If you want to specify a different pinout for the right half than the left half, you can define `MATRIX_ROW_PINS_RIGHT`/`MATRIX_COL_PINS_RIGHT`. Currently, the size of `MATRIX_ROW_PINS` must be the same as `MATRIX_ROW_PINS_RIGHT` and likewise for the definition of columns.
  239. * `#define DIRECT_PINS_RIGHT { { F1, F0, B0, C7 }, { F4, F5, F6, F7 } }`
  240. * If you want to specify a different direct pinout for the right half than the left half, you can define `DIRECT_PINS_RIGHT`. Currently, the size of `DIRECT_PINS` must be the same as `DIRECT_PINS_RIGHT`.
  241. * `#define RGBLED_SPLIT { 6, 6 }`
  242. * See [RGB Light Configuration](#rgb-light-configuration)
  243. * `#define SELECT_SOFT_SERIAL_SPEED <speed>` (default speed is 1)
  244. * Sets the protocol speed when using serial communication
  245. * Speeds:
  246. * 0: about 189kbps (Experimental only)
  247. * 1: about 137kbps (default)
  248. * 2: about 75kbps
  249. * 3: about 39kbps
  250. * 4: about 26kbps
  251. * 5: about 20kbps
  252. * `#define SPLIT_USB_DETECT`
  253. * Detect (with timeout) USB connection when delegating master/slave
  254. * Default behavior for ARM
  255. * Required for AVR Teensy
  256. * `#define SPLIT_USB_TIMEOUT 2000`
  257. * Maximum timeout when detecting master/slave when using `SPLIT_USB_DETECT`
  258. * `#define SPLIT_USB_TIMEOUT_POLL 10`
  259. * Poll frequency when detecting master/slave when using `SPLIT_USB_DETECT`
  260. # The `rules.mk` File
  261. This is a [make](https://www.gnu.org/software/make/manual/make.html) file that is included by the top-level `Makefile`. It is used to set some information about the MCU that we will be compiling for as well as enabling and disabling certain features.
  262. ## Build Options
  263. * `DEFAULT_FOLDER`
  264. * Used to specify a default folder when a keyboard has more than one sub-folder.
  265. * `FIRMWARE_FORMAT`
  266. * Defines which format (bin, hex) is copied to the root `qmk_firmware` folder after building.
  267. * `SRC`
  268. * Used to add files to the compilation/linking list.
  269. * `LIB_SRC`
  270. * Used to add files as a library to the compilation/linking list.
  271. The files specified by `LIB_SRC` is linked after the files specified by `SRC`.
  272. For example, if you specify:
  273. ```
  274. SRC += a.c
  275. LIB_SRC += lib_b.c
  276. SRC += c.c
  277. LIB_SRC += lib_d.c
  278. ```
  279. The link order is as follows.
  280. ```
  281. ... a.o c.o ... lib_b.a lib_d.a ...
  282. ```
  283. * `LAYOUTS`
  284. * A list of [layouts](feature_layouts.md) this keyboard supports.
  285. * `LTO_ENABLE`
  286. * Enables Link Time Optimization (LTO) when compiling the keyboard. This makes the process take longer, but it can significantly reduce the compiled size (and since the firmware is small, the added time is not noticeable).
  287. However, this will automatically disable the legacy TMK Macros and Functions features, as these break when LTO is enabled. It does this by automatically defining `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION`. (Note: This does not affect QMK [Macros](feature_macros.md) and [Layers](feature_layers.md).)
  288. ## AVR MCU Options
  289. * `MCU = atmega32u4`
  290. * `F_CPU = 16000000`
  291. * `ARCH = AVR8`
  292. * `F_USB = $(F_CPU)`
  293. * `OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT`
  294. * `BOOTLOADER = atmel-dfu` with the following options:
  295. * `atmel-dfu`
  296. * `lufa-dfu`
  297. * `qmk-dfu`
  298. * `halfkay`
  299. * `caterina`
  300. * `bootloadHID`
  301. * `USBasp`
  302. ## Feature Options :id=feature-options
  303. Use these to enable or disable building certain features. The more you have enabled the bigger your firmware will be, and you run the risk of building a firmware too large for your MCU.
  304. * `BOOTMAGIC_ENABLE`
  305. * Virtual DIP switch configuration
  306. * `MOUSEKEY_ENABLE`
  307. * Mouse keys
  308. * `EXTRAKEY_ENABLE`
  309. * Audio control and System control
  310. * `CONSOLE_ENABLE`
  311. * Console for debug
  312. * `COMMAND_ENABLE`
  313. * Commands for debug and configuration
  314. * `COMBO_ENABLE`
  315. * Key combo feature
  316. * `NKRO_ENABLE`
  317. * USB N-Key Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
  318. * `AUDIO_ENABLE`
  319. * Enable the audio subsystem.
  320. * `RGBLIGHT_ENABLE`
  321. * Enable keyboard underlight functionality
  322. * `LEADER_ENABLE`
  323. * Enable leader key chording
  324. * `MIDI_ENABLE`
  325. * MIDI controls
  326. * `UNICODE_ENABLE`
  327. * Unicode
  328. * `BLUETOOTH`
  329. * Current options are AdafruitBLE, RN42
  330. * `SPLIT_KEYBOARD`
  331. * Enables split keyboard support (dual MCU like the let's split and bakingpy's boards) and includes all necessary files located at quantum/split_common
  332. * `CUSTOM_MATRIX`
  333. * Allows replacing the standard matrix scanning routine with a custom one.
  334. * `DEBOUNCE_TYPE`
  335. * Allows replacing the standard key debouncing routine with an alternative or custom one.
  336. * `WAIT_FOR_USB`
  337. * Forces the keyboard to wait for a USB connection to be established before it starts up
  338. * `NO_USB_STARTUP_CHECK`
  339. * Disables usb suspend check after keyboard startup. Usually the keyboard waits for the host to wake it up before any tasks are performed. This is useful for split keyboards as one half will not get a wakeup call but must send commands to the master.
  340. ## USB Endpoint Limitations
  341. In order to provide services over USB, QMK has to use USB endpoints.
  342. These are a finite resource: each microcontroller has only a certain number.
  343. This limits what features can be enabled together.
  344. If the available endpoints are exceeded, a build error is thrown.
  345. The following features can require separate endpoints:
  346. * `MOUSEKEY_ENABLE`
  347. * `EXTRAKEY_ENABLE`
  348. * `CONSOLE_ENABLE`
  349. * `NKRO_ENABLE`
  350. * `MIDI_ENABLE`
  351. * `RAW_ENABLE`
  352. * `VIRTSER_ENABLE`
  353. In order to improve utilisation of the endpoints, the HID features can be combined to use a single endpoint.
  354. By default, `MOUSEKEY`, `EXTRAKEY`, and `NKRO` are combined into a single endpoint.
  355. The base keyboard functionality can also be combined into the endpoint,
  356. by setting `KEYBOARD_SHARED_EP = yes`.
  357. This frees up one more endpoint,
  358. but it can prevent the keyboard working in some BIOSes,
  359. as they do not implement Boot Keyboard protocol switching.
  360. Combining the mouse also breaks Boot Mouse compatibility.
  361. The mouse can be uncombined by setting `MOUSE_SHARED_EP = no` if this functionality is required.