Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/efm32/periph: add DAC support for EFM32 Series 1 (VDAC) #19887

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/sltb009a/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ config BOARD_SLTB009A
select BOARD_COMMON_SILABS
select CPU_MODEL_EFM32GG12B810F1024GM64
select HAS_PERIPH_ADC
select HAS_PERIPH_DAC
select HAS_PERIPH_I2C
select HAS_PERIPH_RTC
select HAS_PERIPH_RTT
Expand Down
1 change: 1 addition & 0 deletions boards/sltb009a/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CPU_MODEL = efm32gg12b810f1024gm64

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_dac
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_rtt
Expand Down
23 changes: 23 additions & 0 deletions boards/sltb009a/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ static const adc_chan_conf_t adc_channel_config[] = {
#define ADC_NUMOF ARRAY_SIZE(adc_channel_config)
/** @} */

/**
* @name DAC configuration
* @{
*/
static const dac_conf_t dac_config[] = {
{
.dev = VDAC0,
.ref = vdacRefAvdd,
.cmu = cmuClock_VDAC0,
},
};

static const dac_chan_conf_t dac_channel_config[] = {
{
.dev = 0,
.index = 0,
},
};

#define DAC_DEV_NUMOF ARRAY_SIZE(dac_config)
#define DAC_NUMOF ARRAY_SIZE(dac_channel_config)
/** @} */

/**
* @name I2C configuration
* @{
Expand Down
1 change: 1 addition & 0 deletions cpu/efm32/families/efm32gg12b/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
******************************************************************************/

#include <stdint.h>
#include "periph_conf.h"
#include "em_device.h"

/*******************************************************************************
Expand Down
20 changes: 20 additions & 0 deletions cpu/efm32/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "em_rtc.h"
#if defined(_SILICON_LABS_32B_SERIES_0)
#include "em_dac.h"
#elif defined (_SILICON_LABS_32B_SERIES_1) || defined(_SILICON_LABS_32B_SERIES_2)
#include "em_vdac.h"
#endif

#ifdef __cplusplus
Expand Down Expand Up @@ -90,6 +92,24 @@ typedef struct {
uint8_t dev; /**< device index */
uint8_t index; /**< channel index */
} dac_chan_conf_t;

#elif defined(VDAC_COUNT) && VDAC_COUNT > 0
/**
* @brief DAC device configuration (VDAC configuration of EFM32 Series 1)
*/
typedef struct {
VDAC_TypeDef *dev; /**< DAC device used */
VDAC_Ref_TypeDef ref; /**< DAC voltage reference */
CMU_Clock_TypeDef cmu; /**< the device CMU channel */
} dac_conf_t;

/**
* @brief DAC channel configuration (VDAC configuration of EFM32 Series 1)
*/
typedef struct {
uint8_t dev; /**< device index */
uint8_t index; /**< channel index */
} dac_chan_conf_t;
#endif

/**
Expand Down
22 changes: 22 additions & 0 deletions cpu/efm32/periph/dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,31 @@
*/

#include "cpu.h"
#include "macros/units.h"

#include "periph_conf.h"
#include "periph/dac.h"

#include "em_cmu.h"
#if defined(DAC_COUNT) && DAC_COUNT > 0
#include "em_dac.h"
#elif defined(VDAC_COUNT) && VDAC_COUNT > 0
#include "em_vdac.h"
#endif

/* DAC implementation can be used for VDAC by mapping the symbols */
#if defined(VDAC_COUNT) && VDAC_COUNT > 0

#define DAC_INIT_DEFAULT VDAC_INIT_DEFAULT
#define DAC_INITCHANNEL_DEFAULT VDAC_INITCHANNEL_DEFAULT

#define DAC_Init_TypeDef VDAC_Init_TypeDef
#define DAC_InitChannel_TypeDef VDAC_InitChannel_TypeDef
#define DAC_Reset VDAC_Reset
#define DAC_Init VDAC_Init
#define DAC_InitChannel VDAC_InitChannel
#define DAC_ChannelOutputSet VDAC_ChannelOutputSet

#endif

int8_t dac_init(dac_t line)
Expand All @@ -45,7 +63,11 @@ int8_t dac_init(dac_t line)
/* reset and initialize peripheral */
DAC_Init_TypeDef init = DAC_INIT_DEFAULT;

#if defined(VDAC_COUNT)
init.reference = dac_config[dev].ref;
init.prescaler = VDAC_PrescaleCalc(MHZ(1000000), true, 0);
#endif

DAC_Reset(dac_config[dev].dev);
DAC_Init(dac_config[dev].dev, &init);

Expand Down