From 8ef6b58caa8ff5ff49128838d384a078bf97dc4c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 10 Aug 2017 00:22:06 -0400 Subject: [PATCH] gpt audio implementation started, not working --- common_features.mk | 6 +- keyboards/clueboard60/clueboard60.c | 109 ---------------------------- keyboards/clueboard60/rules.mk | 2 +- quantum/audio/audio.h | 7 +- quantum/audio/luts.c | 3 - quantum/audio/luts.h | 11 ++- quantum/audio/voices.h | 6 +- 7 files changed, 23 insertions(+), 121 deletions(-) diff --git a/common_features.mk b/common_features.mk index f405d5c0..8c04e872 100644 --- a/common_features.mk +++ b/common_features.mk @@ -34,7 +34,11 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes) OPT_DEFS += -DAUDIO_ENABLE MUSIC_ENABLE := 1 SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c - SRC += $(QUANTUM_DIR)/audio/audio.c + ifeq ($(PLATFORM),AVR) + SRC += $(QUANTUM_DIR)/audio/audio.c + else + SRC += $(QUANTUM_DIR)/audio/audio_arm.c + endif SRC += $(QUANTUM_DIR)/audio/voices.c SRC += $(QUANTUM_DIR)/audio/luts.c endif diff --git a/keyboards/clueboard60/clueboard60.c b/keyboards/clueboard60/clueboard60.c index 2e830962..6b166996 100644 --- a/keyboards/clueboard60/clueboard60.c +++ b/keyboards/clueboard60/clueboard60.c @@ -14,118 +14,9 @@ * along with this program. If not, see . */ #include "clueboard60.h" -#include "ch.h" -#include "hal.h" - -/* - * DAC streaming callback. - */ -size_t nx = 0, ny = 0, nz = 0; - - -static void gpt_cb6(GPTDriver *gptp); -static void gpt_cb7(GPTDriver *gptp); -static void gpt_cb8(GPTDriver *gptp); -float frequency[2] = { 440.00, 523.25 }; - -/* - * GPT6 configuration. - */ -GPTConfig gpt6cfg1 = { - .frequency = 440.00, - // .frequency = 1000000, - .callback = gpt_cb6, - // .callback = NULL, - .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */ - .dier = 0U -}; - -GPTConfig gpt7cfg1 = { - .frequency = 523.25, - .callback = gpt_cb7, - // .callback = NULL, - .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */ - .dier = 0U -}; - -GPTConfig gpt8cfg1 = { - .frequency = 44100, - .callback = gpt_cb8, - .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */ - .dier = 0U -}; - -static void gpt_cb6(GPTDriver *gptp) { - palTogglePad(GPIOA, 4); - - // nz++; - - // if ((nz % 1000) == 0) { - // palTogglePad(GPIOB, 7); - // nz = 0; - // gpt6cfg1.frequency *= 1.05946; - // gptStopTimer(&GPTD6); - - // gptStart(&GPTD6, &gpt6cfg1); - // gptStartContinuous(&GPTD6, 2U); - - // gpt7cfg1.frequency *= 1.05946; - // gptStopTimer(&GPTD7); - - // gptStart(&GPTD7, &gpt7cfg1); - // gptStartContinuous(&GPTD7, 2U); - // } -} - -static void gpt_cb7(GPTDriver *gptp) { - palTogglePad(GPIOA, 5); - - // ny++; - - // if ((ny % 1000) == 0) { - // palTogglePad(GPIOB, 7); - // ny = 0; - // } -} - -static void gpt_cb8(GPTDriver *gptp) { - - nz++; - - if (nz == 5000) { - palTogglePad(GPIOB, 7); - nz = 0; - frequency[0] *= 1.05946; - frequency[1] *= 1.05946; - - gpt6cfg1.frequency = frequency[0]; - gptStopTimer(&GPTD6); - - gptStart(&GPTD6, &gpt6cfg1); - gptStartContinuous(&GPTD6, 2U); - - - gpt7cfg1.frequency = frequency[1]; - gptStopTimer(&GPTD7); - - gptStart(&GPTD7, &gpt7cfg1); - gptStartContinuous(&GPTD7, 2U); - } -} - void matrix_init_kb(void) { - palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); - - gptStart(&GPTD6, &gpt6cfg1); - gptStart(&GPTD7, &gpt7cfg1); - gptStart(&GPTD8, &gpt8cfg1); - - gptStartContinuous(&GPTD6, 2U); - gptStartContinuous(&GPTD7, 2U); - gptStartContinuous(&GPTD8, 2U); } void matrix_scan_kb(void) { diff --git a/keyboards/clueboard60/rules.mk b/keyboards/clueboard60/rules.mk index 2914a125..5e9b9f39 100644 --- a/keyboards/clueboard60/rules.mk +++ b/keyboards/clueboard60/rules.mk @@ -48,5 +48,5 @@ COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover CUSTOM_MATRIX = yes # Custom matrix file -# AUDIO_ENABLE = yes +AUDIO_ENABLE = yes # SERIAL_LINK_ENABLE = yes \ No newline at end of file diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index 79e0da22..da09b2bc 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -18,12 +18,15 @@ #include #include -#include -#include +#if defined(__AVR__) + #include +#endif +#include "wait.h" #include "musical_notes.h" #include "song_list.h" #include "voices.h" #include "quantum.h" +#include // Largely untested PWM audio mode (doesn't sound as good) // #define PWM_AUDIO diff --git a/quantum/audio/luts.c b/quantum/audio/luts.c index 57f2d592..4404aff4 100644 --- a/quantum/audio/luts.c +++ b/quantum/audio/luts.c @@ -14,9 +14,6 @@ * along with this program. If not, see . */ -#include -#include -#include #include "luts.h" const float vibrato_lut[VIBRATO_LUT_LENGTH] = diff --git a/quantum/audio/luts.h b/quantum/audio/luts.h index 155e34e8..a377a6c8 100644 --- a/quantum/audio/luts.h +++ b/quantum/audio/luts.h @@ -14,9 +14,14 @@ * along with this program. If not, see . */ -#include -#include -#include +#if defined(__AVR__) + #include + #include + #include +#else + #include "ch.h" + #include "hal.h" +#endif #ifndef LUTS_H #define LUTS_H diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h index 9403a6b5..1cf33095 100644 --- a/quantum/audio/voices.h +++ b/quantum/audio/voices.h @@ -15,8 +15,10 @@ */ #include #include -#include -#include +#if defined(__AVR__) + #include +#endif +#include "wait.h" #include "luts.h" #ifndef VOICES_H