Stm32 DAC: moved parameter for idle level from config to init function argument
This commit is contained in:
parent
fc1fc41f14
commit
fe3c54153e
|
|
@ -43,7 +43,7 @@ static const uint8_t pathCompatibilityMatrix[9][9] =
|
|||
const struct audioDevice outputDevices[] =
|
||||
{
|
||||
{NULL, 0, 0, SINK_MCU},
|
||||
{&stm32_dac_audio_driver, (const void *) 2048, STM32_DAC_CH1, SINK_RTX},
|
||||
{&stm32_dac_audio_driver, 0, STM32_DAC_CH1, SINK_RTX},
|
||||
{&stm32_dac_audio_driver, 0, STM32_DAC_CH2, SINK_SPK},
|
||||
};
|
||||
|
||||
|
|
@ -67,8 +67,8 @@ void audio_init()
|
|||
gpio_clearPin(MIC_MUTE); // Off = logic low
|
||||
max9814_setGain(0); // 40 dB gain
|
||||
|
||||
stm32dac_init(STM32_DAC_CH1);
|
||||
stm32dac_init(STM32_DAC_CH2);
|
||||
stm32dac_init(STM32_DAC_CH1, 2048);
|
||||
stm32dac_init(STM32_DAC_CH2, 2048);
|
||||
stm32adc_init(STM32_ADC_ADC2);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ void __attribute__((used)) DMA1_Stream6_IRQHandler()
|
|||
|
||||
|
||||
|
||||
void stm32dac_init(const uint8_t instance)
|
||||
void stm32dac_init(const uint8_t instance, const uint16_t idleLevel)
|
||||
{
|
||||
// Enable peripherals
|
||||
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
|
||||
|
|
@ -122,6 +122,7 @@ void stm32dac_init(const uint8_t instance)
|
|||
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
|
||||
__DSB();
|
||||
|
||||
DAC->DHR12R1 = idleLevel;
|
||||
DAC->CR |= DAC_CR_DMAEN1 // Enable DMA
|
||||
| 0x00 // TIM6 as trigger source for CH1
|
||||
| DAC_CR_TEN1 // Enable trigger input
|
||||
|
|
@ -134,6 +135,7 @@ void stm32dac_init(const uint8_t instance)
|
|||
RCC->APB1ENR |= RCC_APB1ENR_TIM7EN;
|
||||
__DSB();
|
||||
|
||||
DAC->DHR12R2 = idleLevel;
|
||||
DAC->CR |= DAC_CR_DMAEN2 // Enable DMA
|
||||
| DAC_CR_TSEL2_1 // TIM7 as trigger source for CH2
|
||||
| DAC_CR_TEN2 // Enable trigger input
|
||||
|
|
@ -145,6 +147,7 @@ void stm32dac_init(const uint8_t instance)
|
|||
break;
|
||||
}
|
||||
|
||||
chState[instance].idleLevel = idleLevel;
|
||||
chState[instance].stream.setEndTransferCallback(std::bind(stopTransfer, instance));
|
||||
}
|
||||
|
||||
|
|
@ -169,6 +172,8 @@ void stm32dac_terminate()
|
|||
static int stm32dac_start(const uint8_t instance, const void *config,
|
||||
struct streamCtx *ctx)
|
||||
{
|
||||
(void) config;
|
||||
|
||||
if((ctx == NULL) || (ctx->running != 0))
|
||||
return -EINVAL;
|
||||
|
||||
|
|
@ -181,7 +186,6 @@ static int stm32dac_start(const uint8_t instance, const void *config,
|
|||
|
||||
ctx->priv = &chState[instance];
|
||||
chState[instance].ctx = ctx;
|
||||
chState[instance].idleLevel = reinterpret_cast< uint32_t >(config);
|
||||
|
||||
/*
|
||||
* Convert buffer elements from int16_t to unsigned 12 bit values as required
|
||||
|
|
|
|||
|
|
@ -60,8 +60,9 @@ extern const struct audioDriver stm32_dac_audio_driver;
|
|||
* Initialize the driver and the peripherals.
|
||||
*
|
||||
* @param instance: DAC instance number.
|
||||
* @param idleLevel: DAC output level when idle.
|
||||
*/
|
||||
void stm32dac_init(const uint8_t instance);
|
||||
void stm32dac_init(const uint8_t instance, const uint16_t idleLevel);
|
||||
|
||||
/**
|
||||
* Shutdown the driver and the peripherals.
|
||||
|
|
|
|||
Loading…
Reference in New Issue