|
|
|
@ -8,7 +8,7 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup cpu_stm32f4
|
|
|
|
|
* @ingroup cpu_stm32_common
|
|
|
|
|
* @{
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
@ -25,7 +25,13 @@
|
|
|
|
|
#include "periph_conf.h"
|
|
|
|
|
|
|
|
|
|
/* only compile this, if the CPU has a DAC */
|
|
|
|
|
#ifdef DAC
|
|
|
|
|
#if defined(DAC) || defined(DAC1)
|
|
|
|
|
|
|
|
|
|
#ifdef DAC2
|
|
|
|
|
#define _DAC(line) (dac_config[line].dac ? DAC2 : DAC1)
|
|
|
|
|
#else
|
|
|
|
|
#define _DAC(line) DAC
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get the DAC configuration from the board (if configured)
|
|
|
|
@ -47,7 +53,16 @@ int8_t dac_init(dac_t line)
|
|
|
|
|
/* configure pin */
|
|
|
|
|
gpio_init_analog(dac_config[line].pin);
|
|
|
|
|
/* enable the DAC's clock */
|
|
|
|
|
#if defined(DAC2)
|
|
|
|
|
RCC->APB1ENR |= dac_config[line].dac
|
|
|
|
|
? RCC_APB1ENR_DAC2EN
|
|
|
|
|
: RCC_APB1ENR_DAC1EN;
|
|
|
|
|
#elif defined(DAC1)
|
|
|
|
|
RCC->APB1ENR |= RCC_APB1ENR_DAC1EN;
|
|
|
|
|
#else
|
|
|
|
|
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* reset output and enable the line's channel */
|
|
|
|
|
dac_set(line, 0);
|
|
|
|
|
dac_poweron(line);
|
|
|
|
@ -57,12 +72,18 @@ int8_t dac_init(dac_t line)
|
|
|
|
|
void dac_set(dac_t line, uint16_t value)
|
|
|
|
|
{
|
|
|
|
|
value = (value >> 4); /* scale to 12-bit */
|
|
|
|
|
#ifdef DAC_DHR12R2_DACC2DHR
|
|
|
|
|
if (dac_config[line].chan) {
|
|
|
|
|
DAC->DHR12R2 = value;
|
|
|
|
|
_DAC(line)->DHR12R2 = value;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
DAC->DHR12R1 = value;
|
|
|
|
|
_DAC(line)->DHR12R1 = value;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
(void) line;
|
|
|
|
|
|
|
|
|
|
_DAC(line)->DHR12R1 = value;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dac_poweron(dac_t line)
|