1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

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:
DipSwitch 2016-03-15 10:49:48 +01:00
parent 6e9f36c0c5
commit bd9b3a269c
22 changed files with 168 additions and 29 deletions

View File

@ -53,6 +53,13 @@ extern "C" {
#define ADC_NUMOF (0)
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @brief Timer configuration
* @{

View File

@ -131,6 +131,13 @@ static const uart_conf_t uart_config[] = {
#define SPI_0_MISO_PIN GPIO_PIN(PORT_A,6)
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @name Real time counter configuration
* @{

View File

@ -44,6 +44,13 @@ extern "C" {
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @brief Timer configuration
* @{

View File

@ -109,6 +109,13 @@ extern "C" {
#define ADC_NUMOF (0)
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
#ifdef __cplusplus
}
#endif

View File

@ -56,6 +56,13 @@ extern "C" {
#define ADC_NUMOF (0)
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @brief Timer configuration
* @{

View File

@ -40,6 +40,13 @@ extern "C" {
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @brief Timer configuration
* @{

View File

@ -39,6 +39,13 @@ extern "C" {
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @brief Timer configuration
* @{

View File

@ -43,6 +43,13 @@ extern "C" {
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @brief Timer configuration
* @{

View File

@ -46,6 +46,13 @@
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_2
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @name ADC configuration
* @{

View File

@ -109,6 +109,13 @@ extern "C" {
#define ADC_NUMOF (6)
/** @} */
/**
* @brief DAC configuration
* @{
*/
#define DAC_NUMOF (0)
/** @} */
/**
* @name SPI configuration
* @{

View File

@ -1,5 +1,6 @@
# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_dac
FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm

View File

@ -38,6 +38,17 @@ extern "C" {
#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
* @{

View File

@ -140,9 +140,9 @@ static const uart_conf_t uart_config[] = {
* PIN, DAC channel
* @{
*/
#define DAC_CONFIG { \
{GPIO_PIN(PORT_A, 4), 0}, \
{GPIO_PIN(PORT_A, 5), 1} \
#define DAC_CONFIG { \
{ GPIO_PIN(PORT_A, 4), 0 }, \
{ GPIO_PIN(PORT_A, 5), 1 }, \
}
#define DAC_NUMOF (2)

View File

@ -81,6 +81,13 @@ void periph_clk_en(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
}
#endif

View File

@ -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)

View File

@ -20,7 +20,6 @@
#define PERIPH_CPU_H
#include "periph_cpu_common.h"
#include "cpu.h"
#ifdef __cplusplus
extern "C" {
@ -107,6 +106,14 @@ typedef struct {
uint8_t chan; /**< internal channel the pin is connected to */
} 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
*
@ -117,13 +124,6 @@ typedef struct {
*/
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
}
#endif

View File

@ -147,6 +147,14 @@ typedef struct {
uint8_t irqn; /**< interrupt number */
} 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
*
@ -157,13 +165,6 @@ typedef struct {
*/
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
}
#endif

View File

@ -85,6 +85,15 @@ typedef enum {
GPIO_AF15 /**< use alternate function 14 */
} 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
}
#endif

View File

@ -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));
}
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)
{
EXTI->IMR |= (1 << _pin_num(pin));

View File

@ -163,13 +163,6 @@ typedef struct {
*/
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
*

View File

@ -87,6 +87,14 @@ typedef enum {
GPIO_AF14 /**< use alternate function 14 */
} 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
*

View File

@ -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));
}
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)
{
EXTI->IMR |= (1 << _pin_num(pin));