diff --git a/boards/b-l072z-lrwan1/include/periph_conf.h b/boards/b-l072z-lrwan1/include/periph_conf.h index 068a44c18a..4edcc92c40 100644 --- a/boards/b-l072z-lrwan1/include/periph_conf.h +++ b/boards/b-l072z-lrwan1/include/periph_conf.h @@ -158,14 +158,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ - -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/f4vi1/include/periph_conf.h b/boards/f4vi1/include/periph_conf.h index ef172b9a19..ccf2dbb455 100644 --- a/boards/f4vi1/include/periph_conf.h +++ b/boards/f4vi1/include/periph_conf.h @@ -110,13 +110,6 @@ static const uart_conf_t uart_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/fox/include/periph_conf.h b/boards/fox/include/periph_conf.h index ee8127cb3f..b3e120db27 100644 --- a/boards/fox/include/periph_conf.h +++ b/boards/fox/include/periph_conf.h @@ -66,13 +66,6 @@ extern "C" { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/iotlab-common/include/periph_conf_common.h b/boards/iotlab-common/include/periph_conf_common.h index 9283ef57bc..96dea56282 100644 --- a/boards/iotlab-common/include/periph_conf_common.h +++ b/boards/iotlab-common/include/periph_conf_common.h @@ -128,13 +128,6 @@ static const uart_conf_t uart_config[] = { #define UART_NUMOF (sizeof(uart_config) / sizeof(uart_config[0])) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Real time counter configuration * @{ diff --git a/boards/limifrog-v1/include/periph_conf.h b/boards/limifrog-v1/include/periph_conf.h index ca761b300d..d7e36ce08f 100644 --- a/boards/limifrog-v1/include/periph_conf.h +++ b/boards/limifrog-v1/include/periph_conf.h @@ -49,13 +49,6 @@ extern "C" { #define CLOCK_APB1 (CLOCK_CORECLOCK / 1) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/maple-mini/include/periph_conf.h b/boards/maple-mini/include/periph_conf.h index 81f92d458f..8e3e413897 100644 --- a/boards/maple-mini/include/periph_conf.h +++ b/boards/maple-mini/include/periph_conf.h @@ -66,13 +66,6 @@ extern "C" { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/msbiot/include/periph_conf.h b/boards/msbiot/include/periph_conf.h index ee72d7b700..e3045332e6 100644 --- a/boards/msbiot/include/periph_conf.h +++ b/boards/msbiot/include/periph_conf.h @@ -110,18 +110,15 @@ static const pwm_conf_t pwm_config[] = { /** @} */ /** - * @name DAC configuration - * - * We need to define the following fields: - * PIN, DAC channel + * @name DAC configuration * @{ */ -#define DAC_CONFIG { \ - {GPIO_PIN(PORT_A, 4), 0}, \ - {GPIO_PIN(PORT_A, 5), 1} \ -} +static const dac_conf_t dac_config[] = { + { .pin = GPIO_PIN(PORT_A, 4), .chan = 0 }, + { .pin = GPIO_PIN(PORT_A, 5), .chan = 1 } +}; -#define DAC_NUMOF (2) +#define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0])) /** @} */ /** diff --git a/boards/nucleo-f030/include/periph_conf.h b/boards/nucleo-f030/include/periph_conf.h index 4eac0dc6f2..4f836f34ae 100644 --- a/boards/nucleo-f030/include/periph_conf.h +++ b/boards/nucleo-f030/include/periph_conf.h @@ -141,13 +141,6 @@ static const pwm_conf_t pwm_config[] = { #define ADC_NUMOF (6) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo-f070/include/periph_conf.h b/boards/nucleo-f070/include/periph_conf.h index 61aadad892..e886fd0047 100644 --- a/boards/nucleo-f070/include/periph_conf.h +++ b/boards/nucleo-f070/include/periph_conf.h @@ -153,13 +153,6 @@ static const pwm_conf_t pwm_config[] = { #define ADC_NUMOF (6) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo-f072/include/periph_conf.h b/boards/nucleo-f072/include/periph_conf.h index 47b6141eb4..4b34d5f1c6 100644 --- a/boards/nucleo-f072/include/periph_conf.h +++ b/boards/nucleo-f072/include/periph_conf.h @@ -201,13 +201,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (6) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo-f091/include/periph_conf.h b/boards/nucleo-f091/include/periph_conf.h index f00eca16f3..0a32cdfa12 100644 --- a/boards/nucleo-f091/include/periph_conf.h +++ b/boards/nucleo-f091/include/periph_conf.h @@ -203,12 +203,6 @@ static const pwm_conf_t pwm_config[] = { #define ADC_NUMOF (6) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ #ifdef __cplusplus } diff --git a/boards/nucleo-f103/include/periph_conf.h b/boards/nucleo-f103/include/periph_conf.h index ba9e54ffca..1b8c2d17a9 100644 --- a/boards/nucleo-f103/include/periph_conf.h +++ b/boards/nucleo-f103/include/periph_conf.h @@ -66,13 +66,6 @@ extern "C" { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/nucleo-f302/include/periph_conf.h b/boards/nucleo-f302/include/periph_conf.h index 2eef01dd34..9e9f6cff84 100755 --- a/boards/nucleo-f302/include/periph_conf.h +++ b/boards/nucleo-f302/include/periph_conf.h @@ -56,13 +56,6 @@ extern "C" { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/nucleo-f303/include/periph_conf.h b/boards/nucleo-f303/include/periph_conf.h index dcb3ba81ee..1998a9294a 100755 --- a/boards/nucleo-f303/include/periph_conf.h +++ b/boards/nucleo-f303/include/periph_conf.h @@ -47,13 +47,6 @@ extern "C" { #define CLOCK_APB1 (CLOCK_CORECLOCK / 2) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/nucleo-f334/include/periph_conf.h b/boards/nucleo-f334/include/periph_conf.h index 6b556a7c53..1660d784d0 100644 --- a/boards/nucleo-f334/include/periph_conf.h +++ b/boards/nucleo-f334/include/periph_conf.h @@ -46,20 +46,6 @@ extern "C" { #define CLOCK_APB1 (CLOCK_CORECLOCK / 2) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/nucleo-f401/include/periph_conf.h b/boards/nucleo-f401/include/periph_conf.h index c0f63397b9..ae5ce5ccfb 100644 --- a/boards/nucleo-f401/include/periph_conf.h +++ b/boards/nucleo-f401/include/periph_conf.h @@ -251,13 +251,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo-f410/include/periph_conf.h b/boards/nucleo-f410/include/periph_conf.h index 7cbcac9bc4..1f2f29edb8 100644 --- a/boards/nucleo-f410/include/periph_conf.h +++ b/boards/nucleo-f410/include/periph_conf.h @@ -200,13 +200,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo-f411/include/periph_conf.h b/boards/nucleo-f411/include/periph_conf.h index 029bec69c6..4ce6b7fb12 100644 --- a/boards/nucleo-f411/include/periph_conf.h +++ b/boards/nucleo-f411/include/periph_conf.h @@ -246,13 +246,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo-f446/include/periph_conf.h b/boards/nucleo-f446/include/periph_conf.h index 1ed2804b4a..62ba179169 100644 --- a/boards/nucleo-f446/include/periph_conf.h +++ b/boards/nucleo-f446/include/periph_conf.h @@ -275,13 +275,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo-l053/include/periph_conf.h b/boards/nucleo-l053/include/periph_conf.h index 2e47c8a218..86c6cbe150 100644 --- a/boards/nucleo-l053/include/periph_conf.h +++ b/boards/nucleo-l053/include/periph_conf.h @@ -170,14 +170,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ - -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo-l073/include/periph_conf.h b/boards/nucleo-l073/include/periph_conf.h index 29e405f86f..05f0a30d34 100644 --- a/boards/nucleo-l073/include/periph_conf.h +++ b/boards/nucleo-l073/include/periph_conf.h @@ -181,14 +181,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ - -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name I2C configuration * @{ diff --git a/boards/nucleo-l1/include/periph_conf.h b/boards/nucleo-l1/include/periph_conf.h index ab587432a4..8e7e31edf2 100644 --- a/boards/nucleo-l1/include/periph_conf.h +++ b/boards/nucleo-l1/include/periph_conf.h @@ -236,14 +236,15 @@ static const i2c_conf_t i2c_config[] = { * @name DAC configuration * @{ */ -#define DAC_CONFIG { \ - { GPIO_PIN(PORT_A, 4), 1}, \ - { GPIO_PIN(PORT_A, 5), 2}, \ -} +static const dac_conf_t dac_config[] = { + { .pin = GPIO_PIN(PORT_A, 4), .chan = 0 }, + { .pin = GPIO_PIN(PORT_A, 5), .chan = 1 } +}; -#define DAC_NUMOF (2U) +#define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0])) /** @} */ + #ifdef __cplusplus } #endif diff --git a/boards/nucleo-l476/include/periph_conf.h b/boards/nucleo-l476/include/periph_conf.h index 4962c50f22..0c7d1b77a5 100644 --- a/boards/nucleo-l476/include/periph_conf.h +++ b/boards/nucleo-l476/include/periph_conf.h @@ -227,13 +227,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTT configuration * diff --git a/boards/nucleo144-f207/include/periph_conf.h b/boards/nucleo144-f207/include/periph_conf.h index 0d5b00cce9..47b12acd23 100644 --- a/boards/nucleo144-f207/include/periph_conf.h +++ b/boards/nucleo144-f207/include/periph_conf.h @@ -259,14 +259,6 @@ static const spi_conf_t spi_config[] = { {GPIO_PIN(PORT_C, 0), 1, 0} \ } #define ADC_NUMOF (2) - -/** @} */ - -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) /** @} */ /** diff --git a/boards/nucleo144-f303/include/periph_conf.h b/boards/nucleo144-f303/include/periph_conf.h index f92697bf6f..4d8c5a2a9b 100644 --- a/boards/nucleo144-f303/include/periph_conf.h +++ b/boards/nucleo144-f303/include/periph_conf.h @@ -208,13 +208,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo144-f412/include/periph_conf.h b/boards/nucleo144-f412/include/periph_conf.h index 2b0d8c3ac9..842baa7fb2 100644 --- a/boards/nucleo144-f412/include/periph_conf.h +++ b/boards/nucleo144-f412/include/periph_conf.h @@ -246,13 +246,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo144-f413/include/periph_conf.h b/boards/nucleo144-f413/include/periph_conf.h index e392cead39..c478221890 100644 --- a/boards/nucleo144-f413/include/periph_conf.h +++ b/boards/nucleo144-f413/include/periph_conf.h @@ -246,14 +246,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ - -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo144-f429/include/periph_conf.h b/boards/nucleo144-f429/include/periph_conf.h index 29eb74722b..3679d69232 100644 --- a/boards/nucleo144-f429/include/periph_conf.h +++ b/boards/nucleo144-f429/include/periph_conf.h @@ -244,13 +244,6 @@ static const spi_conf_t spi_config[] = { } /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo144-f446/include/periph_conf.h b/boards/nucleo144-f446/include/periph_conf.h index 30d20c1550..70905380ed 100644 --- a/boards/nucleo144-f446/include/periph_conf.h +++ b/boards/nucleo144-f446/include/periph_conf.h @@ -230,13 +230,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo144-f746/include/periph_conf.h b/boards/nucleo144-f746/include/periph_conf.h index f1004e400e..46cc3540c6 100644 --- a/boards/nucleo144-f746/include/periph_conf.h +++ b/boards/nucleo144-f746/include/periph_conf.h @@ -132,13 +132,6 @@ static const uart_conf_t uart_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo144-f767/include/periph_conf.h b/boards/nucleo144-f767/include/periph_conf.h index 8c6bce13b7..0242bc2c45 100644 --- a/boards/nucleo144-f767/include/periph_conf.h +++ b/boards/nucleo144-f767/include/periph_conf.h @@ -132,13 +132,6 @@ static const uart_conf_t uart_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo32-f031/include/periph_conf.h b/boards/nucleo32-f031/include/periph_conf.h index 590d516acc..0b9e9161f3 100644 --- a/boards/nucleo32-f031/include/periph_conf.h +++ b/boards/nucleo32-f031/include/periph_conf.h @@ -189,13 +189,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (5) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo32-f042/include/periph_conf.h b/boards/nucleo32-f042/include/periph_conf.h index 14285cf01e..48efd63a96 100644 --- a/boards/nucleo32-f042/include/periph_conf.h +++ b/boards/nucleo32-f042/include/periph_conf.h @@ -199,13 +199,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (5) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo32-f303/include/periph_conf.h b/boards/nucleo32-f303/include/periph_conf.h index 0b3441cb5a..703f0af2ef 100644 --- a/boards/nucleo32-f303/include/periph_conf.h +++ b/boards/nucleo32-f303/include/periph_conf.h @@ -181,13 +181,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nucleo32-l031/include/periph_conf.h b/boards/nucleo32-l031/include/periph_conf.h index 720b91f2c7..130eb4d951 100644 --- a/boards/nucleo32-l031/include/periph_conf.h +++ b/boards/nucleo32-l031/include/periph_conf.h @@ -156,13 +156,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/boards/nucleo32-l432/include/periph_conf.h b/boards/nucleo32-l432/include/periph_conf.h index e1161b6604..4fde7270e5 100644 --- a/boards/nucleo32-l432/include/periph_conf.h +++ b/boards/nucleo32-l432/include/periph_conf.h @@ -190,13 +190,6 @@ static const spi_conf_t spi_config[] = { #define ADC_NUMOF (0U) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0U) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nz32-sc151/include/periph_conf.h b/boards/nz32-sc151/include/periph_conf.h index c8c89fb7cc..78948985d0 100644 --- a/boards/nz32-sc151/include/periph_conf.h +++ b/boards/nz32-sc151/include/periph_conf.h @@ -237,17 +237,18 @@ static const i2c_conf_t i2c_config[] = { /** @} */ /** - * @name DAC configuration + * @name DAC configuration * @{ */ -#define DAC_CONFIG { \ - { GPIO_PIN(PORT_A, 4), 1}, \ - { GPIO_PIN(PORT_A, 5), 2}, \ -} +static const dac_conf_t dac_config[] = { + { .pin = GPIO_PIN(PORT_A, 4), .chan = 0 }, + { .pin = GPIO_PIN(PORT_A, 5), .chan = 1 } +}; -#define DAC_NUMOF (2) +#define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0])) /** @} */ + #ifdef __cplusplus } #endif diff --git a/boards/opencm904/include/periph_conf.h b/boards/opencm904/include/periph_conf.h index 324f535968..abf50ca7c4 100644 --- a/boards/opencm904/include/periph_conf.h +++ b/boards/opencm904/include/periph_conf.h @@ -66,13 +66,6 @@ extern "C" { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name Timer configuration * @{ diff --git a/boards/spark-core/include/periph_conf.h b/boards/spark-core/include/periph_conf.h index 25f671f026..6b7da05320 100644 --- a/boards/spark-core/include/periph_conf.h +++ b/boards/spark-core/include/periph_conf.h @@ -59,13 +59,6 @@ #define CLOCK_APB1 (CLOCK_CORECLOCK / 2) /** @} */ - /** - * @name DAC configuration - * @{ - */ - #define DAC_NUMOF (0) - /** @} */ - /** * @name ADC configuration * @{ diff --git a/boards/stm32f0discovery/include/periph_conf.h b/boards/stm32f0discovery/include/periph_conf.h index 707713bd50..b7c9cb449e 100644 --- a/boards/stm32f0discovery/include/periph_conf.h +++ b/boards/stm32f0discovery/include/periph_conf.h @@ -112,13 +112,6 @@ static const uart_conf_t uart_config[] = { #define ADC_NUMOF (6) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name SPI configuration * @{ diff --git a/boards/stm32f3discovery/include/periph_conf.h b/boards/stm32f3discovery/include/periph_conf.h index 75a42f86a2..8036a92e84 100644 --- a/boards/stm32f3discovery/include/periph_conf.h +++ b/boards/stm32f3discovery/include/periph_conf.h @@ -49,11 +49,11 @@ extern "C" { * @name DAC configuration * @{ */ -#define DAC_CONFIG { \ - { GPIO_PIN(PORT_A, 4), 0, 0 }, \ -} +static const dac_conf_t dac_config[] = { + { .pin = GPIO_PIN(PORT_A, 4), .chan = 0 } +}; -#define DAC_NUMOF (1) +#define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0])) /** @} */ /** diff --git a/boards/stm32f4discovery/include/periph_conf.h b/boards/stm32f4discovery/include/periph_conf.h index 260293ed15..c1ab8c8afb 100644 --- a/boards/stm32f4discovery/include/periph_conf.h +++ b/boards/stm32f4discovery/include/periph_conf.h @@ -137,17 +137,14 @@ static const uart_conf_t uart_config[] = { /** * @name DAC configuration - * - * We need to define the following fields: - * PIN, DAC channel * @{ */ -#define DAC_CONFIG { \ - { GPIO_PIN(PORT_A, 4), 0 }, \ - { GPIO_PIN(PORT_A, 5), 1 }, \ -} +static const dac_conf_t dac_config[] = { + { .pin = GPIO_PIN(PORT_A, 4), .chan = 0 }, + { .pin = GPIO_PIN(PORT_A, 5), .chan = 1 } +}; -#define DAC_NUMOF (2) +#define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0])) /** @} */ /** diff --git a/boards/stm32f7discovery/include/periph_conf.h b/boards/stm32f7discovery/include/periph_conf.h index c6e4fd2181..95eaaf5f98 100644 --- a/boards/stm32f7discovery/include/periph_conf.h +++ b/boards/stm32f7discovery/include/periph_conf.h @@ -100,13 +100,6 @@ static const uart_conf_t uart_config[] = { #define ADC_NUMOF (0) /** @} */ -/** - * @name DAC configuration - * @{ - */ -#define DAC_NUMOF (0) -/** @} */ - /** * @name RTC configuration * @{ diff --git a/cpu/stm32_common/include/periph_cpu_common.h b/cpu/stm32_common/include/periph_cpu_common.h index 07e5e2f6d3..be57a48462 100644 --- a/cpu/stm32_common/include/periph_cpu_common.h +++ b/cpu/stm32_common/include/periph_cpu_common.h @@ -190,6 +190,14 @@ typedef enum { #endif /* ndef DOXYGEN */ #endif /* ndef CPU_FAM_STM32F1 */ +/** + * @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 Timer configuration */ diff --git a/cpu/stm32_common/periph/dac.c b/cpu/stm32_common/periph/dac.c index a7d3fd846b..fc78dca322 100644 --- a/cpu/stm32_common/periph/dac.c +++ b/cpu/stm32_common/periph/dac.c @@ -9,7 +9,7 @@ /** * @ingroup cpu_cortexm_common - * @ingroup drivers_periph_adc + * @ingroup drivers_periph_dac * @{ * * @file @@ -22,22 +22,37 @@ */ #include "cpu.h" +#include "assert.h" #include "periph/dac.h" -#include "periph_conf.h" /* only compile this, if the CPU has a DAC */ -#if (defined(DAC) || defined(DAC1)) && defined(DAC_CONFIG) +#ifdef DAC_NUMOF -#ifdef DAC2 -#define _DAC(line) (dac_config[line].dac ? DAC2 : DAC1) +/* DAC channel enable bits */ +#ifdef DAC_CR_EN2 +#define EN_MASK (DAC_CR_EN1 | DAC_CR_EN2) #else -#define _DAC(line) DAC +#define EN_MASK (DAC_CR_EN1) #endif -/** - * @brief Get the DAC configuration from the board config - */ -static const dac_conf_t dac_config[] = DAC_CONFIG; +/* get RCC bit */ +#ifdef RCC_APB1ENR_DAC1EN +#define RCC_BIT (RCC_APB1ENR_DAC1EN) +#else +#define RCC_BIT (RCC_APB1ENR_DACEN) +#endif + +/* deduct DAC device from given line channel */ +static inline DAC_TypeDef *dev(dac_t line) +{ +#if defined(DAC2) + return (dac_config[line].chan > 1) ? DAC2 : DAC1; +#elif defined (DAC1) + return DAC1; +#else + return DAC; +#endif +} int8_t dac_init(dac_t line) { @@ -47,46 +62,65 @@ int8_t dac_init(dac_t line) /* configure pin */ gpio_init_analog(dac_config[line].pin); - /* enable the DAC's clock */ -#if defined(DAC2) - periph_clk_en(APB1, dac_config[line].dac ? - RCC_APB1ENR_DAC2EN : RCC_APB1ENR_DAC1EN); -#elif defined(DAC1) - periph_clk_en(APB1, RCC_APB1ENR_DAC1EN); -#else - periph_clk_en(APB1, RCC_APB1ENR_DACEN); -#endif + /* reset output and enable the line's channel */ - dac_set(line, 0); dac_poweron(line); + dac_set(line, 0); + return DAC_OK; } void dac_set(dac_t line, uint16_t value) { - value = (value >> 4); /* scale to 12-bit */ + assert(line < DAC_NUMOF); + + /* scale set value to 12-bit */ + value = (value >> 4); + #ifdef DAC_DHR12R2_DACC2DHR - if (dac_config[line].chan) { - _DAC(line)->DHR12R2 = value; + if (dac_config[line].chan & 0x01) { + dev(line)->DHR12R2 = value; } else { - _DAC(line)->DHR12R1 = value; + dev(line)->DHR12R1 = value; } #else - (void) line; - - _DAC(line)->DHR12R1 = value; + dev(line)->DHR12R1 = value; #endif } void dac_poweron(dac_t line) { - DAC->CR |= (1 << (16 * dac_config[line].chan)); + assert(line < DAC_NUMOF); + + /* enable the DAC's clock */ +#if defined(DAC2) + periph_clk_en(APB1, (dac_config[line].chan > 1) ? + RCC_APB1ENR_DAC2EN : RCC_APB1ENR_DAC1EN); +#else + periph_clk_en(APB1, RCC_BIT); +#endif + + /* enable corresponding DAC channel */ + dev(line)->CR |= (1 << (16 * (dac_config[line].chan & 0x01))); } void dac_poweroff(dac_t line) { - DAC->CR &= ~(1 << (16 * dac_config[line].chan)); + assert(line < DAC_NUMOF); + + /* disable corresponding channel */ + dev(line)->CR &= ~(1 << (16 * (dac_config[line].chan & 0x01))); + + /* disable the DAC's clock in case no channel is active anymore */ + if (!(dev(line)->CR & EN_MASK)) { +#if defined(DAC2) + periph_clk_dis(APB1, (dac_config[line].chan > 1) ? + RCC_APB1ENR_DAC2EN : RCC_APB1ENR_DAC1EN); +#else + periph_clk_dis(APB1, RCC_BIT); +#endif + } } #else diff --git a/cpu/stm32f0/include/periph_cpu.h b/cpu/stm32f0/include/periph_cpu.h index 01c6404ec9..50dcb32c65 100644 --- a/cpu/stm32f0/include/periph_cpu.h +++ b/cpu/stm32f0/include/periph_cpu.h @@ -62,14 +62,6 @@ 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; - #ifdef __cplusplus } #endif diff --git a/cpu/stm32f1/include/periph_cpu.h b/cpu/stm32f1/include/periph_cpu.h index 3e1158d4ce..042a3d4d5e 100644 --- a/cpu/stm32f1/include/periph_cpu.h +++ b/cpu/stm32f1/include/periph_cpu.h @@ -129,14 +129,6 @@ typedef struct { uint8_t chan; /**< CPU ADC channel connected to the pin */ } 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; - #ifdef __cplusplus } #endif diff --git a/cpu/stm32f2/include/periph_cpu.h b/cpu/stm32f2/include/periph_cpu.h index 80614883a3..eb8f34a09e 100644 --- a/cpu/stm32f2/include/periph_cpu.h +++ b/cpu/stm32f2/include/periph_cpu.h @@ -71,14 +71,6 @@ typedef enum { } adc_res_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 Power on the DMA device the given stream belongs to * diff --git a/cpu/stm32f2/periph/dac.c b/cpu/stm32f2/periph/dac.c deleted file mode 100644 index 823eca7bb0..0000000000 --- a/cpu/stm32f2/periph/dac.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2015 Engineering-Spirit - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup cpu_stm32f2 - * @ingroup drivers_periph_dac - * @{ - * - * @file - * @brief Low-level DAC driver implementation - * - * @author Nick v. IJzendoorn - * - * @} - */ - -#include "cpu.h" -#include "periph/dac.h" -#include "periph_conf.h" - -/* guard in case that no DAC device is defined */ -#if DAC_NUMOF - -/** - * @brief Get the DAC configuration from the board (if configured) - * @{ - */ -#ifdef DAC_CONFIG -static const dac_conf_t dac_config[] = DAC_CONFIG; -#else -static const dac_conf_t dac_config[] = {}; -#endif -/** @} */ - -int8_t dac_init(dac_t line) -{ - if (line >= DAC_NUMOF) { - return DAC_NOLINE; - } - - /* configure pin */ - gpio_init_analog(dac_config[line].pin); - /* enable the DAC's clock */ - periph_clk_en(APB1, RCC_APB1ENR_DACEN); - /* reset output and enable the line's channel */ - dac_set(line, 0); - dac_poweron(line); - return DAC_OK; -} - -void dac_set(dac_t line, uint16_t value) -{ - value = (value >> 4); /* scale to 12-bit */ - if (dac_config[line].chan) { - DAC->DHR12R2 = value; - } - else { - DAC->DHR12R1 = value; - } -} - -void dac_poweron(dac_t line) -{ - DAC->CR |= (1 << (16 * dac_config[line].chan)); -} - -void dac_poweroff(dac_t line) -{ - DAC->CR &= ~(1 << (16 * dac_config[line].chan)); -} - -#endif /* DAC_NUMOF */ diff --git a/cpu/stm32f3/include/periph_cpu.h b/cpu/stm32f3/include/periph_cpu.h index b81d3157c7..d0cc7f6d3e 100644 --- a/cpu/stm32f3/include/periph_cpu.h +++ b/cpu/stm32f3/include/periph_cpu.h @@ -39,15 +39,6 @@ enum { PORT_H = 7, /**< port H */ }; -/** - * @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 diff --git a/cpu/stm32f4/include/periph_cpu.h b/cpu/stm32f4/include/periph_cpu.h index b09d9f3430..35ba7613a7 100644 --- a/cpu/stm32f4/include/periph_cpu.h +++ b/cpu/stm32f4/include/periph_cpu.h @@ -75,14 +75,6 @@ typedef struct { uint8_t chan; /**< CPU ADC channel connected to the pin */ } 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 Power on the DMA device the given stream belongs to * diff --git a/cpu/stm32l0/include/periph_cpu.h b/cpu/stm32l0/include/periph_cpu.h index 9c5df6fc69..9720f2184d 100644 --- a/cpu/stm32l0/include/periph_cpu.h +++ b/cpu/stm32l0/include/periph_cpu.h @@ -65,14 +65,6 @@ 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 I2C configuration data structure */ diff --git a/cpu/stm32l1/include/periph_cpu.h b/cpu/stm32l1/include/periph_cpu.h index 2c947a8218..5fb4285795 100644 --- a/cpu/stm32l1/include/periph_cpu.h +++ b/cpu/stm32l1/include/periph_cpu.h @@ -41,15 +41,6 @@ enum { PORT_H = 5, /**< port H */ }; -/** - * @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 ADC channel configuration data */ diff --git a/cpu/stm32l4/include/periph_cpu.h b/cpu/stm32l4/include/periph_cpu.h index c709372159..c5f9e32362 100644 --- a/cpu/stm32l4/include/periph_cpu.h +++ b/cpu/stm32l4/include/periph_cpu.h @@ -65,14 +65,6 @@ 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; - #ifdef __cplusplus } #endif