2014-07-26 09:24:53 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2014-07-26 09:24:53 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file STM32/DACv1/dac_lld.c
|
|
|
|
* @brief STM32 DAC subsystem low level driver source.
|
|
|
|
*
|
|
|
|
* @addtogroup DAC
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#if HAL_USE_DAC || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
/* Because ST headers naming inconsistencies.*/
|
2014-07-26 09:24:53 +00:00
|
|
|
#if !defined(DAC1)
|
|
|
|
#define DAC1 DAC
|
|
|
|
#endif
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
#define DAC1_CH1_DMA_CHANNEL \
|
|
|
|
STM32_DMA_GETCHANNEL(STM32_DAC1_CH1_DMA_STREAM, \
|
|
|
|
STM32_DAC1_CH1_DMA_CHN)
|
2014-07-26 09:24:53 +00:00
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
#define DAC1_CH2_DMA_CHANNEL \
|
|
|
|
STM32_DMA_GETCHANNEL(STM32_DAC1_CH2_DMA_STREAM, \
|
|
|
|
STM32_DAC1_CH2_DMA_CHN)
|
|
|
|
|
|
|
|
#define DAC2_CH1_DMA_CHANNEL \
|
|
|
|
STM32_DMA_GETCHANNEL(STM32_DAC2_CH1_DMA_STREAM, \
|
|
|
|
STM32_DAC2_CH1_DMA_CHN)
|
|
|
|
|
|
|
|
#define DAC2_CH2_DMA_CHANNEL \
|
|
|
|
STM32_DMA_GETCHANNEL(STM32_DAC2_CH2_DMA_STREAM, \
|
|
|
|
STM32_DAC2_CH2_DMA_CHN)
|
|
|
|
|
2015-05-02 09:11:13 +00:00
|
|
|
#define CHANNEL_DATA_OFFSET 12U
|
2014-07-26 09:24:53 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
/** @brief DAC1 CH1 driver identifier.*/
|
|
|
|
#if STM32_DAC_USE_DAC1_CH1 || defined(__DOXYGEN__)
|
2014-07-26 09:24:53 +00:00
|
|
|
DACDriver DACD1;
|
|
|
|
#endif
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
/** @brief DAC1 CH2 driver identifier.*/
|
|
|
|
#if (STM32_DAC_USE_DAC1_CH2 && !STM32_DAC_DUAL_MODE) || defined(__DOXYGEN__)
|
2014-07-26 09:24:53 +00:00
|
|
|
DACDriver DACD2;
|
|
|
|
#endif
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
/** @brief DAC2 CH1 driver identifier.*/
|
|
|
|
#if STM32_DAC_USE_DAC2_CH1 || defined(__DOXYGEN__)
|
2014-07-26 09:24:53 +00:00
|
|
|
DACDriver DACD3;
|
|
|
|
#endif
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
/** @brief DAC2 CH2 driver identifier.*/
|
|
|
|
#if (STM32_DAC_USE_DAC2_CH2 && !STM32_DAC_DUAL_MODE) || defined(__DOXYGEN__)
|
|
|
|
DACDriver DACD4;
|
|
|
|
#endif
|
|
|
|
|
2014-07-26 09:24:53 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-05-02 09:11:13 +00:00
|
|
|
#if STM32_DAC_USE_DAC1_CH1 == TRUE
|
|
|
|
static const dacparams_t dma1_ch1_params = {
|
|
|
|
dac: DAC1,
|
|
|
|
dataoffset: 0U,
|
|
|
|
regshift: 0U,
|
|
|
|
regmask: 0xFFFF0000U,
|
|
|
|
dma: STM32_DMA_STREAM(STM32_DAC1_CH1_DMA_STREAM),
|
|
|
|
dmamode: STM32_DMA_CR_CHSEL(DAC1_CH1_DMA_CHANNEL) |
|
|
|
|
STM32_DMA_CR_PL(STM32_DAC1_CH1_DMA_PRIORITY) |
|
|
|
|
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_DIR_M2P |
|
|
|
|
STM32_DMA_CR_DMEIE | STM32_DMA_CR_TEIE | STM32_DMA_CR_HTIE |
|
|
|
|
STM32_DMA_CR_TCIE,
|
|
|
|
dmairqprio: STM32_DAC1_CH1_IRQ_PRIORITY
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC1_CH2 == TRUE
|
|
|
|
static const dacparams_t dma1_ch2_params = {
|
|
|
|
dac: DAC1,
|
|
|
|
dataoffset: CHANNEL_DATA_OFFSET,
|
|
|
|
regshift: 16U,
|
|
|
|
regmask: 0x0000FFFFU,
|
|
|
|
dma: STM32_DMA_STREAM(STM32_DAC1_CH2_DMA_STREAM),
|
|
|
|
dmamode: STM32_DMA_CR_CHSEL(DAC1_CH2_DMA_CHANNEL) |
|
|
|
|
STM32_DMA_CR_PL(STM32_DAC1_CH2_DMA_PRIORITY) |
|
|
|
|
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_DIR_M2P |
|
|
|
|
STM32_DMA_CR_DMEIE | STM32_DMA_CR_TEIE | STM32_DMA_CR_HTIE |
|
|
|
|
STM32_DMA_CR_TCIE,
|
|
|
|
dmairqprio: STM32_DAC1_CH2_IRQ_PRIORITY
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC2_CH1 == TRUE
|
|
|
|
static const dacparams_t dma2_ch1_params = {
|
|
|
|
dac: DAC2,
|
|
|
|
dataoffset: 0U,
|
|
|
|
regshift: 0U,
|
|
|
|
regmask: 0xFFFF0000U,
|
|
|
|
dma: STM32_DMA_STREAM(STM32_DAC2_CH1_DMA_STREAM),
|
|
|
|
dmamode: STM32_DMA_CR_CHSEL(DAC2_CH1_DMA_CHANNEL) |
|
|
|
|
STM32_DMA_CR_PL(STM32_DAC2_CH1_DMA_PRIORITY) |
|
|
|
|
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_DIR_M2P |
|
|
|
|
STM32_DMA_CR_DMEIE | STM32_DMA_CR_TEIE | STM32_DMA_CR_HTIE |
|
|
|
|
STM32_DMA_CR_TCIE,
|
|
|
|
dmairqprio: STM32_DAC2_CH1_IRQ_PRIORITY
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC2_CH2 == TRUE
|
|
|
|
static const dacparams_t dma1_ch2_params = {
|
|
|
|
dac: DAC2,
|
|
|
|
dataoffset: CHANNEL_DATA_OFFSET,
|
|
|
|
regshift: 16U,
|
|
|
|
regmask: 0x0000FFFFU,
|
|
|
|
dma: STM32_DMA_STREAM(STM32_DAC2_CH2_DMA_STREAM),
|
|
|
|
dmamode: STM32_DMA_CR_CHSEL(DAC2_CH2_DMA_CHANNEL) |
|
|
|
|
STM32_DMA_CR_PL(STM32_DAC2_CH2_DMA_PRIORITY) |
|
|
|
|
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_DIR_M2P |
|
|
|
|
STM32_DMA_CR_DMEIE | STM32_DMA_CR_TEIE | STM32_DMA_CR_HTIE |
|
|
|
|
STM32_DMA_CR_TCIE,
|
|
|
|
dmairqprio: STM32_DAC2_CH2_IRQ_PRIORITY
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2014-07-26 09:24:53 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Shared end/half-of-tx service routine.
|
|
|
|
*
|
|
|
|
* @param[in] dacp pointer to the @p DACDriver object
|
|
|
|
* @param[in] flags pre-shifted content of the ISR register
|
|
|
|
*/
|
|
|
|
static void dac_lld_serve_tx_interrupt(DACDriver *dacp, uint32_t flags) {
|
|
|
|
|
|
|
|
if ((flags & (STM32_DMA_ISR_TEIF | STM32_DMA_ISR_DMEIF)) != 0) {
|
|
|
|
/* DMA errors handling.*/
|
2015-05-01 16:03:03 +00:00
|
|
|
_dac_isr_error_code(dacp, DAC_ERR_DMAFAILURE);
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((flags & STM32_DMA_ISR_HTIF) != 0) {
|
|
|
|
/* Half transfer processing.*/
|
2015-05-01 16:03:03 +00:00
|
|
|
_dac_isr_half_code(dacp);
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
if ((flags & STM32_DMA_ISR_TCIF) != 0) {
|
|
|
|
/* Transfer complete processing.*/
|
2015-05-01 16:03:03 +00:00
|
|
|
_dac_isr_full_code(dacp);
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver interrupt handlers. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Low level DAC driver initialization.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void dac_lld_init(void) {
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
#if STM32_DAC_USE_DAC1_CH1
|
2014-07-26 09:24:53 +00:00
|
|
|
dacObjectInit(&DACD1);
|
2015-05-02 09:11:13 +00:00
|
|
|
DACD1.params = &dma1_ch1_params;
|
2014-07-26 09:24:53 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
#if STM32_DAC_USE_DAC1_CH2
|
2014-07-26 09:24:53 +00:00
|
|
|
dacObjectInit(&DACD2);
|
2015-05-02 09:11:13 +00:00
|
|
|
DACD2.params = &dma1_ch2_params;
|
2014-07-26 09:24:53 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
#if STM32_DAC_USE_DAC2_CH1
|
2014-07-26 09:24:53 +00:00
|
|
|
dacObjectInit(&DACD3);
|
2015-05-02 09:11:13 +00:00
|
|
|
DACD3.params = &dma2_ch1_params;
|
2015-05-01 16:03:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC2_CH2
|
|
|
|
dacObjectInit(&DACD4);
|
2015-05-02 09:11:13 +00:00
|
|
|
DACD4.params = &dma2_ch2_params;
|
2014-07-26 09:24:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configures and activates the DAC peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] dacp pointer to the @p DACDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void dac_lld_start(DACDriver *dacp) {
|
|
|
|
bool b;
|
2015-05-01 16:03:03 +00:00
|
|
|
|
2015-05-02 09:11:13 +00:00
|
|
|
/* If the driver is in DAC_STOP state then a full initialization is
|
|
|
|
required.*/
|
|
|
|
if (dacp->state == DAC_STOP) {
|
|
|
|
/* Allocating the DMA channel.*/
|
|
|
|
b = dmaStreamAllocate(dacp->params->dma, dacp->params->dmairqprio,
|
|
|
|
(stm32_dmaisr_t)dac_lld_serve_tx_interrupt,
|
|
|
|
(void *)dacp);
|
|
|
|
osalDbgAssert(!b, "stream already allocated");
|
2015-05-01 16:03:03 +00:00
|
|
|
|
2015-05-02 09:11:13 +00:00
|
|
|
/* Enabling the clock source.*/
|
|
|
|
#if STM32_DAC_USE_DAC1_CH1
|
|
|
|
if (&DACD1 == dacp) {
|
|
|
|
rccEnableDAC1(false);
|
|
|
|
}
|
2014-07-26 09:24:53 +00:00
|
|
|
#endif
|
2015-05-01 16:03:03 +00:00
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC1_CH2
|
2014-07-26 09:24:53 +00:00
|
|
|
if (&DACD2 == dacp) {
|
2015-05-02 09:11:13 +00:00
|
|
|
rccEnableDAC1(false);
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-05-01 16:03:03 +00:00
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC2_CH1
|
2014-07-26 09:24:53 +00:00
|
|
|
if (&DACD3 == dacp) {
|
2015-05-02 09:11:13 +00:00
|
|
|
rccEnableDAC2(false);
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-05-01 16:03:03 +00:00
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC2_CH2
|
|
|
|
if (&DACD3 == dacp) {
|
2015-05-02 09:11:13 +00:00
|
|
|
rccEnableDAC2(false);
|
2015-05-01 16:03:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-02 12:28:09 +00:00
|
|
|
/* Enabling DAC in SW triggering mode initially, initializing data to
|
|
|
|
zero.*/
|
2015-05-01 16:03:03 +00:00
|
|
|
#if STM32_DAC_DUAL_MODE == FALSE
|
2015-05-02 12:28:09 +00:00
|
|
|
dacp->params->dac->CR &= dacp->params->regmask;
|
|
|
|
dacp->params->dac->CR |= DAC_CR_EN1 << dacp->params->regshift;
|
|
|
|
*(&dacp->params->dac->DHR12R1 + dacp->params->dataoffset) = 0U;
|
2015-05-01 16:03:03 +00:00
|
|
|
#else
|
2015-05-02 12:28:09 +00:00
|
|
|
dacp->params->dac->CR = DAC_CR_EN2 | DAC_CR_EN1;
|
|
|
|
dacp->params->dac->DAC_DHR12RD = 0U;
|
2014-07-26 09:24:53 +00:00
|
|
|
#endif
|
2015-05-02 12:28:09 +00:00
|
|
|
}
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deactivates the DAC peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] dacp pointer to the @p DACDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void dac_lld_stop(DACDriver *dacp) {
|
|
|
|
|
|
|
|
/* If in ready state then disables the DAC clock.*/
|
|
|
|
if (dacp->state == DAC_READY) {
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
/* DMA channel released.*/
|
2015-05-02 09:11:13 +00:00
|
|
|
dmaStreamRelease(dacp->params->dma);
|
2014-07-26 09:24:53 +00:00
|
|
|
|
2015-05-02 12:28:09 +00:00
|
|
|
/* Disabling DAC.*/
|
|
|
|
dacp->params->dac->CR &= dacp->params->regmask;
|
|
|
|
|
2015-05-01 16:03:03 +00:00
|
|
|
#if STM32_DAC_USE_DAC1_CH1
|
2014-07-26 09:24:53 +00:00
|
|
|
if (&DACD1 == dacp) {
|
2015-05-02 09:11:13 +00:00
|
|
|
if ((dacp->params->dac->CR & DAC_CR_EN2) == 0U) {
|
2015-05-01 16:03:03 +00:00
|
|
|
rccDisableDAC1(false);
|
|
|
|
}
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-05-01 16:03:03 +00:00
|
|
|
|
|
|
|
#if STM32_DAC_USE_DAC1_CH2
|
2014-07-26 09:24:53 +00:00
|
|
|
if (&DACD2 == dacp) {
|
2015-05-02 09:11:13 +00:00
|
|
|
if ((dacp->params->dac->CR & DAC_CR_EN1) == 0U) {
|
2015-05-01 16:03:03 +00:00
|
|
|
rccDisableDAC1(false);
|
|
|
|
}
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
2015-05-01 16:03:03 +00:00
|
|
|
#endif
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-02 20:26:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Outputs a value directly on a DAC channel.
|
|
|
|
*
|
|
|
|
* @param[in] dacp pointer to the @p DACDriver object
|
|
|
|
* @param[in] channel DAC channel number
|
|
|
|
* @param[in] sample value to be output
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void dac_lld_put_channel(DACDriver *dacp,
|
|
|
|
dacchannel_t channel,
|
|
|
|
dacsample_t sample) {
|
|
|
|
|
|
|
|
(void)dacp;
|
|
|
|
(void)channel;
|
|
|
|
(void)sample;
|
|
|
|
}
|
|
|
|
|
2014-07-26 09:24:53 +00:00
|
|
|
/**
|
2015-05-01 16:03:03 +00:00
|
|
|
* @brief Starts a DAC conversion.
|
|
|
|
* @details Starts an asynchronous conversion operation.
|
2014-07-26 09:24:53 +00:00
|
|
|
*
|
|
|
|
* @param[in] dacp pointer to the @p DACDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void dac_lld_start_conversion(DACDriver *dacp) {
|
2015-05-02 09:11:13 +00:00
|
|
|
uint32_t cr, dmamode;
|
|
|
|
|
|
|
|
#if STM32_DAC_DUAL_MODE == FALSE
|
2015-05-02 20:26:17 +00:00
|
|
|
switch (dacp->config->datamode) {
|
2015-05-02 09:11:13 +00:00
|
|
|
/* Sets the DAC data register */
|
|
|
|
case DAC_DHRM_12BIT_RIGHT:
|
|
|
|
dmaStreamSetPeripheral(dacp->params->dma, &dacp->params->dac->DHR12R1 +
|
|
|
|
dacp->params->dataoffset);
|
|
|
|
dmamode = dacp->params->dmamode |
|
|
|
|
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
|
|
|
|
break;
|
|
|
|
case DAC_DHRM_12BIT_LEFT:
|
|
|
|
dmaStreamSetPeripheral(dacp->params->dma, &dacp->params->dac->DHR12L1 +
|
|
|
|
dacp->params->dataoffset);
|
|
|
|
dmamode = dacp->params->dmamode |
|
|
|
|
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
|
|
|
|
break;
|
|
|
|
case DAC_DHRM_8BIT_RIGHT:
|
|
|
|
dmaStreamSetPeripheral(dacp->params->dma, &dacp->params->dac->DHR8R1 +
|
|
|
|
dacp->params->dataoffset);
|
|
|
|
dmamode = dacp->params->dmamode |
|
|
|
|
STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
chDbgAssert(false, "unexpected DAC mode");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#if defined(STM32_HAS_DAC_CHN2) && STM32_HAS_DAC_CHN2
|
|
|
|
case DAC_DHRM_12BIT_RIGHT_DUAL:
|
|
|
|
dmaStreamSetPeripheral(dacp->dma, &dacp->dac->DHR12RD);
|
|
|
|
dacp->dmamode = (dacp->dmamode & ~STM32_DMA_CR_SIZE_MASK) |
|
|
|
|
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
|
|
|
|
break;
|
|
|
|
case DAC_DHRM_12BIT_LEFT_DUAL:
|
|
|
|
dmaStreamSetPeripheral(dacp->dma, &dacp->dac->DHR12LD);
|
|
|
|
dacp->dmamode = (dacp->dmamode & ~STM32_DMA_CR_SIZE_MASK) |
|
|
|
|
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
|
|
|
|
break;
|
|
|
|
case DAC_DHRM_8BIT_RIGHT_DUAL:
|
|
|
|
dmaStreamSetPeripheral(dacp->dma, &dacp->dac->DHR8RD);
|
|
|
|
dacp->dmamode = (dacp->dmamode & ~STM32_DMA_CR_SIZE_MASK) |
|
|
|
|
STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#endif
|
2015-05-01 16:03:03 +00:00
|
|
|
|
2015-05-02 09:11:13 +00:00
|
|
|
dmaStreamSetMemory0(dacp->params->dma, dacp->samples);
|
|
|
|
dmaStreamSetTransactionSize(dacp->params->dma, dacp->depth);
|
|
|
|
dmaStreamSetMode(dacp->params->dma, dmamode |
|
2015-05-01 16:03:03 +00:00
|
|
|
STM32_DMA_CR_DMEIE | STM32_DMA_CR_TEIE |
|
|
|
|
STM32_DMA_CR_HTIE | STM32_DMA_CR_TCIE);
|
2015-05-02 09:11:13 +00:00
|
|
|
dmaStreamEnable(dacp->params->dma);
|
|
|
|
|
|
|
|
/* DAC configuration.*/
|
|
|
|
#if STM32_DAC_DUAL_MODE == FALSE
|
2015-05-02 12:28:09 +00:00
|
|
|
cr = DAC_CR_DMAEN1 | (dacp->grpp->trigger << 3) | DAC_CR_TEN1 | DAC_CR_EN1;
|
|
|
|
dacp->params->dac->CR &= dacp->params->regmask;
|
|
|
|
dacp->params->dac->CR |= cr << dacp->params->regshift;
|
2015-05-02 09:11:13 +00:00
|
|
|
#else
|
|
|
|
/* TODO: Dual.*/
|
|
|
|
#endif
|
2015-05-01 16:03:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stops an ongoing conversion.
|
|
|
|
* @details This function stops the currently ongoing conversion and returns
|
|
|
|
* the driver in the @p DAC_READY state. If there was no conversion
|
|
|
|
* being processed then the function does nothing.
|
|
|
|
*
|
|
|
|
* @param[in] dacp pointer to the @p DACDriver object
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void dac_lld_stop_conversion(DACDriver *dacp) {
|
|
|
|
|
2015-05-02 09:11:13 +00:00
|
|
|
dmaStreamDisable(dacp->params->dma);
|
|
|
|
#if STM32_DAC_DUAL_MODE == FALSE
|
2015-05-02 12:28:09 +00:00
|
|
|
dacp->params->dac->CR = dacp->params->regmask;
|
|
|
|
dacp->params->dac->CR |= DAC_CR_EN1 << dacp->params->regshift;
|
|
|
|
*(&dacp->params->dac->DHR12R1 + dacp->params->dataoffset) = 0U;
|
2015-05-02 09:11:13 +00:00
|
|
|
#else
|
2015-05-02 12:28:09 +00:00
|
|
|
dacp->params->dac->CR = DAC_CR_EN2 | DAC_CR_EN1;
|
|
|
|
dacp->params->dac->DAC_DHR12RD = 0U;
|
2015-05-02 09:11:13 +00:00
|
|
|
#endif
|
2014-07-26 09:24:53 +00:00
|
|
|
}
|
2015-05-01 16:03:03 +00:00
|
|
|
|
2014-07-26 09:24:53 +00:00
|
|
|
#endif /* HAL_USE_DAC */
|
|
|
|
|
|
|
|
/** @} */
|