summaryrefslogtreecommitdiff
path: root/bsp/stm32/libraries
diff options
context:
space:
mode:
authorchenjh <[email protected]>2020-11-18 23:05:18 +0800
committerchenjh <[email protected]>2020-11-18 23:05:18 +0800
commit3fa1f523df361fce3da202b60c7de168227d72b4 (patch)
tree8400414d59528c2c7bfe16a884d811383e58b950 /bsp/stm32/libraries
parente1e585a95a112141ee8dd1ec92c08d62d63e4a92 (diff)
add dac driver for stm32l4
Diffstat (limited to 'bsp/stm32/libraries')
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/config/l4/dac_config.h42
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_config.h1
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_dac.c8
-rw-r--r--bsp/stm32/libraries/STM32L4xx_HAL/SConscript4
4 files changed, 51 insertions, 4 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/config/l4/dac_config.h b/bsp/stm32/libraries/HAL_Drivers/config/l4/dac_config.h
new file mode 100644
index 0000000000..6ca3932831
--- /dev/null
+++ b/bsp/stm32/libraries/HAL_Drivers/config/l4/dac_config.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-06-16 thread-liu first version
+ */
+
+#ifndef __DAC_CONFIG_H__
+#define __DAC_CONFIG_H__
+
+#include <rtthread.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef BSP_USING_DAC1
+#ifndef DAC1_CONFIG
+#define DAC1_CONFIG \
+ { \
+ .Instance = DAC1, \
+ }
+#endif /* DAC2_CONFIG */
+#endif /* BSP_USING_DAC2 */
+
+#ifdef BSP_USING_DAC2
+#ifndef DAC2_CONFIG
+#define DAC2_CONFIG \
+ { \
+ .Instance = DAC2, \
+ }
+#endif /* DAC2_CONFIG */
+#endif /* BSP_USING_DAC2 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DAC_CONFIG_H__ */
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_config.h b/bsp/stm32/libraries/HAL_Drivers/drv_config.h
index 95c1440560..a31ed7f16c 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_config.h
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_config.h
@@ -73,6 +73,7 @@ extern "C" {
#include "l4/spi_config.h"
#include "l4/qspi_config.h"
#include "l4/adc_config.h"
+#include "l4/dac_config.h"
#include "l4/tim_config.h"
#include "l4/sdio_config.h"
#include "l4/pwm_config.h"
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_dac.c b/bsp/stm32/libraries/HAL_Drivers/drv_dac.c
index e4462b0e78..23d392150d 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_dac.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_dac.c
@@ -43,7 +43,7 @@ static rt_err_t stm32_dac_enabled(struct rt_dac_device *device, rt_uint32_t chan
RT_ASSERT(device != RT_NULL);
stm32_dac_handler = device->parent.user_data;
-#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
+#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4)
HAL_DAC_Start(stm32_dac_handler, channel);
#endif
@@ -56,7 +56,7 @@ static rt_err_t stm32_dac_disabled(struct rt_dac_device *device, rt_uint32_t cha
RT_ASSERT(device != RT_NULL);
stm32_dac_handler = device->parent.user_data;
-#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
+#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4)
HAL_DAC_Stop(stm32_dac_handler, channel);
#endif
@@ -96,7 +96,7 @@ static rt_err_t stm32_set_dac_value(struct rt_dac_device *device, rt_uint32_t ch
rt_memset(&DAC_ChanConf, 0, sizeof(DAC_ChanConf));
-#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
+#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4)
if ((channel <= 2) && (channel > 0))
{
/* set stm32 dac channel */
@@ -109,7 +109,7 @@ static rt_err_t stm32_set_dac_value(struct rt_dac_device *device, rt_uint32_t ch
}
#endif
-#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
+#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4)
DAC_ChanConf.DAC_Trigger = DAC_TRIGGER_NONE;
DAC_ChanConf.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
#endif
diff --git a/bsp/stm32/libraries/STM32L4xx_HAL/SConscript b/bsp/stm32/libraries/STM32L4xx_HAL/SConscript
index 037f91893e..46b9aa7bf7 100644
--- a/bsp/stm32/libraries/STM32L4xx_HAL/SConscript
+++ b/bsp/stm32/libraries/STM32L4xx_HAL/SConscript
@@ -59,6 +59,10 @@ if GetDepend(['RT_USING_ADC']):
src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c']
src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c']
+if GetDepend(['RT_USING_DAC']):
+ src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac.c']
+ src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dac_ex.c']
+
if GetDepend(['RT_USING_RTC']):
src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rtc.c']
src += ['STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rtc_ex.c']