cpu/stm32/perip/dac: Move DAC implementation to stm32_common/periph since all STM32 DAC's have the same basics
This commit is contained in:
parent
6e9f36c0c5
commit
bd9b3a269c
@ -53,6 +53,13 @@ extern "C" {
|
|||||||
#define ADC_NUMOF (0)
|
#define ADC_NUMOF (0)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -131,6 +131,13 @@ static const uart_conf_t uart_config[] = {
|
|||||||
#define SPI_0_MISO_PIN GPIO_PIN(PORT_A,6)
|
#define SPI_0_MISO_PIN GPIO_PIN(PORT_A,6)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Real time counter configuration
|
* @name Real time counter configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -44,6 +44,13 @@ extern "C" {
|
|||||||
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY
|
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -109,6 +109,13 @@ extern "C" {
|
|||||||
#define ADC_NUMOF (0)
|
#define ADC_NUMOF (0)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -56,6 +56,13 @@ extern "C" {
|
|||||||
#define ADC_NUMOF (0)
|
#define ADC_NUMOF (0)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -40,6 +40,13 @@ extern "C" {
|
|||||||
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
|
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -39,6 +39,13 @@ extern "C" {
|
|||||||
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
|
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -43,6 +43,13 @@ extern "C" {
|
|||||||
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY
|
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -46,6 +46,13 @@
|
|||||||
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_2
|
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_2
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name ADC configuration
|
* @name ADC configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -109,6 +109,13 @@ extern "C" {
|
|||||||
#define ADC_NUMOF (6)
|
#define ADC_NUMOF (6)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_NUMOF (0)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name SPI configuration
|
* @name SPI configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
# Put defined MCU peripherals here (in alphabetical order)
|
# Put defined MCU peripherals here (in alphabetical order)
|
||||||
FEATURES_PROVIDED += periph_cpuid
|
FEATURES_PROVIDED += periph_cpuid
|
||||||
|
FEATURES_PROVIDED += periph_dac
|
||||||
FEATURES_PROVIDED += periph_gpio
|
FEATURES_PROVIDED += periph_gpio
|
||||||
FEATURES_PROVIDED += periph_i2c
|
FEATURES_PROVIDED += periph_i2c
|
||||||
FEATURES_PROVIDED += periph_pwm
|
FEATURES_PROVIDED += periph_pwm
|
||||||
|
|||||||
@ -38,6 +38,17 @@ extern "C" {
|
|||||||
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
|
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DAC_CONFIG { \
|
||||||
|
{ GPIO_PIN(PORT_A, 4), 0, 0 }, \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DAC_NUMOF (1)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -140,9 +140,9 @@ static const uart_conf_t uart_config[] = {
|
|||||||
* PIN, DAC channel
|
* PIN, DAC channel
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define DAC_CONFIG { \
|
#define DAC_CONFIG { \
|
||||||
{GPIO_PIN(PORT_A, 4), 0}, \
|
{ GPIO_PIN(PORT_A, 4), 0 }, \
|
||||||
{GPIO_PIN(PORT_A, 5), 1} \
|
{ GPIO_PIN(PORT_A, 5), 1 }, \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DAC_NUMOF (2)
|
#define DAC_NUMOF (2)
|
||||||
|
|||||||
@ -81,6 +81,13 @@ void periph_clk_en(uint8_t bus, uint32_t mask);
|
|||||||
*/
|
*/
|
||||||
void periph_clk_dis(uint8_t bus, uint32_t mask);
|
void periph_clk_dis(uint8_t bus, uint32_t mask);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configure the given pin to be used as ADC input
|
||||||
|
*
|
||||||
|
* @param[in] pin pin to configure
|
||||||
|
*/
|
||||||
|
void gpio_init_analog(gpio_t pin);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup cpu_stm32f4
|
* @ingroup cpu_stm32_common
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
@ -25,7 +25,13 @@
|
|||||||
#include "periph_conf.h"
|
#include "periph_conf.h"
|
||||||
|
|
||||||
/* only compile this, if the CPU has a DAC */
|
/* 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)
|
* @brief Get the DAC configuration from the board (if configured)
|
||||||
@ -47,7 +53,16 @@ int8_t dac_init(dac_t line)
|
|||||||
/* configure pin */
|
/* configure pin */
|
||||||
gpio_init_analog(dac_config[line].pin);
|
gpio_init_analog(dac_config[line].pin);
|
||||||
/* enable the DAC's clock */
|
/* 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;
|
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* reset output and enable the line's channel */
|
/* reset output and enable the line's channel */
|
||||||
dac_set(line, 0);
|
dac_set(line, 0);
|
||||||
dac_poweron(line);
|
dac_poweron(line);
|
||||||
@ -57,12 +72,18 @@ int8_t dac_init(dac_t line)
|
|||||||
void dac_set(dac_t line, uint16_t value)
|
void dac_set(dac_t line, uint16_t value)
|
||||||
{
|
{
|
||||||
value = (value >> 4); /* scale to 12-bit */
|
value = (value >> 4); /* scale to 12-bit */
|
||||||
|
#ifdef DAC_DHR12R2_DACC2DHR
|
||||||
if (dac_config[line].chan) {
|
if (dac_config[line].chan) {
|
||||||
DAC->DHR12R2 = value;
|
_DAC(line)->DHR12R2 = value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DAC->DHR12R1 = value;
|
_DAC(line)->DHR12R1 = value;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void) line;
|
||||||
|
|
||||||
|
_DAC(line)->DHR12R1 = value;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dac_poweron(dac_t line)
|
void dac_poweron(dac_t line)
|
||||||
@ -20,7 +20,6 @@
|
|||||||
#define PERIPH_CPU_H
|
#define PERIPH_CPU_H
|
||||||
|
|
||||||
#include "periph_cpu_common.h"
|
#include "periph_cpu_common.h"
|
||||||
#include "cpu.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -107,6 +106,14 @@ typedef struct {
|
|||||||
uint8_t chan; /**< internal channel the pin is connected to */
|
uint8_t chan; /**< internal channel the pin is connected to */
|
||||||
} adc_conf_t;
|
} adc_conf_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC line configuration data
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
gpio_t pin; /**< pin connected to the line */
|
||||||
|
uint8_t chan; /**< DAC device used for this line */
|
||||||
|
} dac_conf_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configure the alternate function for the given pin
|
* @brief Configure the alternate function for the given pin
|
||||||
*
|
*
|
||||||
@ -117,13 +124,6 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
void gpio_init_af(gpio_t pin, gpio_af_t af);
|
void gpio_init_af(gpio_t pin, gpio_af_t af);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configure the given pin to be used as ADC input
|
|
||||||
*
|
|
||||||
* @param[in] pin pin to configure
|
|
||||||
*/
|
|
||||||
void gpio_init_analog(gpio_t pin);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -147,6 +147,14 @@ typedef struct {
|
|||||||
uint8_t irqn; /**< interrupt number */
|
uint8_t irqn; /**< interrupt number */
|
||||||
} uart_conf_t;
|
} uart_conf_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC line configuration data
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
gpio_t pin; /**< pin connected to the line */
|
||||||
|
uint8_t chan; /**< DAC device used for this line */
|
||||||
|
} dac_conf_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configure the alternate function for the given pin
|
* @brief Configure the alternate function for the given pin
|
||||||
*
|
*
|
||||||
@ -157,13 +165,6 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
void gpio_init_af(gpio_t pin, gpio_af_out_t af);
|
void gpio_init_af(gpio_t pin, gpio_af_out_t af);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configure the given pin to be used as ADC input
|
|
||||||
*
|
|
||||||
* @param[in] pin pin to configure
|
|
||||||
*/
|
|
||||||
void gpio_init_analog(gpio_t pin);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -85,6 +85,15 @@ typedef enum {
|
|||||||
GPIO_AF15 /**< use alternate function 14 */
|
GPIO_AF15 /**< use alternate function 14 */
|
||||||
} gpio_af_t;
|
} gpio_af_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC line configuration support
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
gpio_t pin; /**< pin connected to the line */
|
||||||
|
uint8_t dac; /**< The DAC to use, 0 or 1 */
|
||||||
|
uint8_t chan; /**< DAC device used for this line */
|
||||||
|
} dac_conf_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -146,6 +146,15 @@ void gpio_init_af(gpio_t pin, gpio_af_t af)
|
|||||||
port->AFR[(pin_num > 7) ? 1 : 0] |= (af << ((pin_num & 0x07) * 4));
|
port->AFR[(pin_num > 7) ? 1 : 0] |= (af << ((pin_num & 0x07) * 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gpio_init_analog(gpio_t pin)
|
||||||
|
{
|
||||||
|
/* enable clock, needed as this function can be used without calling
|
||||||
|
* gpio_init first */
|
||||||
|
RCC->AHBENR |= (RCC_AHBENR_GPIOAEN << _port_num(pin));
|
||||||
|
/* set to analog mode */
|
||||||
|
_port(pin)->MODER |= (0x3 << (2 * _pin_num(pin)));
|
||||||
|
}
|
||||||
|
|
||||||
void gpio_irq_enable(gpio_t pin)
|
void gpio_irq_enable(gpio_t pin)
|
||||||
{
|
{
|
||||||
EXTI->IMR |= (1 << _pin_num(pin));
|
EXTI->IMR |= (1 << _pin_num(pin));
|
||||||
|
|||||||
@ -163,13 +163,6 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
void gpio_init_af(gpio_t pin, gpio_af_t af);
|
void gpio_init_af(gpio_t pin, gpio_af_t af);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configure the given pin to be used as ADC input
|
|
||||||
*
|
|
||||||
* @param[in] pin pin to configure
|
|
||||||
*/
|
|
||||||
void gpio_init_analog(gpio_t pin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Power on the DMA device the given stream belongs to
|
* @brief Power on the DMA device the given stream belongs to
|
||||||
*
|
*
|
||||||
|
|||||||
@ -87,6 +87,14 @@ typedef enum {
|
|||||||
GPIO_AF14 /**< use alternate function 14 */
|
GPIO_AF14 /**< use alternate function 14 */
|
||||||
} gpio_af_t;
|
} gpio_af_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DAC line configuration data
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
gpio_t pin; /**< pin connected to the line */
|
||||||
|
uint8_t chan; /**< DAC device used for this line */
|
||||||
|
} dac_conf_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configure the alternate function for the given pin
|
* @brief Configure the alternate function for the given pin
|
||||||
*
|
*
|
||||||
|
|||||||
@ -148,6 +148,15 @@ void gpio_init_af(gpio_t pin, gpio_af_t af)
|
|||||||
port->AFR[(pin_num > 7) ? 1 : 0] |= (af << ((pin_num & 0x07) * 4));
|
port->AFR[(pin_num > 7) ? 1 : 0] |= (af << ((pin_num & 0x07) * 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gpio_init_analog(gpio_t pin)
|
||||||
|
{
|
||||||
|
/* enable clock, needed as this function can be used without calling
|
||||||
|
* gpio_init first */
|
||||||
|
RCC->AHBENR |= (RCC_AHBENR_GPIOAEN << _port_num(pin));
|
||||||
|
/* set to analog mode */
|
||||||
|
_port(pin)->MODER |= (0x3 << (2 * _pin_num(pin)));
|
||||||
|
}
|
||||||
|
|
||||||
void gpio_irq_enable(gpio_t pin)
|
void gpio_irq_enable(gpio_t pin)
|
||||||
{
|
{
|
||||||
EXTI->IMR |= (1 << _pin_num(pin));
|
EXTI->IMR |= (1 << _pin_num(pin));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user