diff --git a/meson.build b/meson.build index e9f2eb14..c76d79c6 100644 --- a/meson.build +++ b/meson.build @@ -225,6 +225,7 @@ stm32f405_src = ['platform/mcu/STM32F4xx/boot/startup.cpp', 'platform/mcu/STM32F4xx/drivers/flash.c', 'platform/drivers/audio/stm32_dac.cpp', 'platform/drivers/audio/stm32_adc.cpp', + 'platform/drivers/audio/stm32_pwm.cpp', 'platform/mcu/CMSIS/Device/ST/STM32F4xx/Source/system_stm32f4xx.c'] stm32f405_inc = ['platform/mcu/CMSIS/Include', diff --git a/platform/drivers/audio/audio_MDx.c b/platform/drivers/audio/audio_MDx.c index ab4f9e6a..014f1e80 100644 --- a/platform/drivers/audio/audio_MDx.c +++ b/platform/drivers/audio/audio_MDx.c @@ -23,6 +23,9 @@ #include #include #include +#include "toneGenerator_MDx.h" +#include "stm32_pwm.h" +#include "stm32_adc.h" #define PATH(x,y) ((x << 4) | y) @@ -41,10 +44,46 @@ static const uint8_t pathCompatibilityMatrix[9][9] = }; +static void stm32pwm_startCbk() +{ + toneGen_lockBeep(); + TIM3->CCER |= TIM_CCER_CC3E; + TIM3->CR1 |= TIM_CR1_CEN; +} + +static void stm32pwm_stopCbk() +{ + TIM3->CCER &= ~TIM_CCER_CC3E; + toneGen_unlockBeep(); +} + +static const struct PwmChannelCfg stm32pwm_cfg = +{ + &(TIM3->CCR3), + stm32pwm_startCbk, + stm32pwm_stopCbk +}; + +const struct audioDevice outputDevices[] = +{ + {NULL, NULL, 0, SINK_MCU}, + {&stm32_pwm_audio_driver, &stm32pwm_cfg, 0, SINK_SPK}, + {&stm32_pwm_audio_driver, &stm32pwm_cfg, 0, SINK_RTX}, +}; + +const struct audioDevice inputDevices[] = +{ + {NULL, 0, 0, SOURCE_MCU}, + {&stm32_adc_audio_driver, (const void *) 13, STM32_ADC_ADC2, SOURCE_RTX}, + {&stm32_adc_audio_driver, (const void *) 3, STM32_ADC_ADC2, SOURCE_MIC}, +}; + void audio_init() { - gpio_setMode(SPK_MUTE, OUTPUT); + gpio_setMode(AIN_MIC, INPUT_ANALOG); + gpio_setMode(SPK_MUTE, OUTPUT); #ifndef PLATFORM_MD9600 + gpio_setMode(AIN_RTX, INPUT_ANALOG); gpio_setMode(AUDIO_AMP_EN, OUTPUT); #ifndef MDx_ENABLE_SWD gpio_setMode(MIC_PWR, OUTPUT); @@ -60,6 +99,9 @@ void audio_init() gpio_clearPin(MIC_PWR); // Mic preamp. off #endif #endif + + stm32pwm_init(); + stm32adc_init(STM32_ADC_ADC2); } void audio_terminate() @@ -71,6 +113,9 @@ void audio_terminate() gpio_clearPin(MIC_PWR); // Mic preamp. off #endif #endif + + stm32pwm_terminate(); + stm32adc_terminate(); } void audio_connect(const enum AudioSource source, const enum AudioSink sink) diff --git a/platform/targets/MD-3x0/hwconfig.h b/platform/targets/MD-3x0/hwconfig.h index 2bfcfcac..09887cca 100644 --- a/platform/targets/MD-3x0/hwconfig.h +++ b/platform/targets/MD-3x0/hwconfig.h @@ -76,6 +76,7 @@ extern "C" { #define AIN_VBAT GPIOA,1 #define AIN_MIC GPIOA,3 #define AIN_RSSI GPIOB,0 +#define AIN_RTX GPIOC,3 /* Channel selection rotary encoder */ #define CH_SELECTOR_0 GPIOE,14 diff --git a/platform/targets/MD-UV3x0/hwconfig.h b/platform/targets/MD-UV3x0/hwconfig.h index 3b7ca86c..c8d23fce 100644 --- a/platform/targets/MD-UV3x0/hwconfig.h +++ b/platform/targets/MD-UV3x0/hwconfig.h @@ -69,6 +69,7 @@ extern "C" { #define AIN_VOLUME GPIOA,0 #define AIN_VBAT GPIOA,1 #define AIN_MIC GPIOA,3 +#define AIN_RTX GPIOC,3 /* Channel selection rotary encoder */ #define CH_SELECTOR_0 GPIOE,14