1 /******************************************************************************
2 * Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
3 *
4 * This software is owned and published by:
5 * Huada Semiconductor Co.,Ltd ("HDSC").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with HDSC
11 * components. This software is licensed by HDSC to be adapted only
12 * for use in systems utilizing HDSC components. HDSC shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. HDSC is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * Disclaimer:
19 * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
20 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
21 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
22 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
23 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
24 * WARRANTY OF NONINFRINGEMENT.
25 * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
26 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
27 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
28 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
29 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
31 * SAVINGS OR PROFITS,
32 * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
34 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
35 * FROM, THE SOFTWARE.
36 *
37 * This software may be replicated in part or whole for the licensed use,
38 * with the restriction that this Disclaimer and Copyright notice must be
39 * included with each copy of this software, whether used in part or whole,
40 * at all times.
41 */
42 /******************************************************************************/
43 /** \file dac.h
44  **
45  ** Header file for dac Converter functions
46  ** @link DAC Group Some description @endlink
47  **
48  **   - 2019-04-10      First Version
49  **
50  ******************************************************************************/
51 #ifndef __DAC_H__
52 #define __DAC_H__
53 
54 /******************************************************************************/
55 /* Include files                                                              */
56 /******************************************************************************/
57 #include "ddl.h"
58 
59 /* C binding of definitions if building with C++ compiler */
60 #ifdef __cplusplus
61 extern "C"
62 {
63 #endif
64 
65 /**
66  ******************************************************************************
67  ** \brief 使能或者禁止指令
68  ******************************************************************************/
69 typedef enum
70 {
71     DacDisable  = 0u,         //禁止
72     DacEnable   = 1u          //使能
73 }en_en_state_t;
74 
75 /**
76  ******************************************************************************
77  ** \brief 使能或者禁止DAC0通道输出缓冲器         DAC_CR0:BOFF0
78  ******************************************************************************/
79 typedef enum
80 {
81     DacBoffDisable = 1u,
82     DacBoffEnable  = 0u
83 }en_dac_boff_t;
84 
85 /**
86  ******************************************************************************
87  ** \brief 使能或者禁止DAC0通道触发使能           DAC_CR0: TEN0
88  ******************************************************************************/
89 typedef enum
90 {
91     DacTenDisable = 0u,
92     DacTenEnable  = 1u
93 }en_dac_ten_t;
94 
95 /**
96  ******************************************************************************
97  ** \brief DAC0通道触发选择                       DAC_CR0: TSEL0
98  ******************************************************************************/
99 typedef enum
100 {
101     DacTim0Tradc = 0u,      //TIM0_TRADC触发
102     DacTim1Tradc = 1u,      //TIM1_TRADC触发
103     DacTim2Tradc = 2u,      //TIM2_TRADC触发
104     DacTim3Tradc = 3u,      //TIM3_TRADC触发
105     DacTim4Tradc = 4u,      //TIM4_TRADC触发
106     DacTim5Tradc = 5u,      //TIM5_TRADC触发
107     DacSwTriger  = 6u,      //软件触发
108     DacExPortTriger = 7u    //外部端口触发
109 }en_dac_tsel_t;
110 
111 /**
112  ******************************************************************************
113  ** \brief DAC0通道噪声/三角波生产使能或禁止      DAC_CR0: WAVE0
114  ******************************************************************************/
115 typedef enum
116 {
117     DacWaveDisable  = 0u,   //禁止生产波
118     DacNoiseEnable  = 1u,   //使能生成噪声波
119     DacTrWaveEnable = 2u    //使能生产三角波
120 }en_dac_wave_t;
121 
122 /**
123  ******************************************************************************
124  ** \brief DACx通道掩码/振幅选择器                DAC_CR0: MAMP0 & MAMP1
125  ******************************************************************************/
126 typedef enum
127 {
128     DacMemp01   = 0u,
129     DacMenp03   = 1u,
130     DacMenp07   = 2u,
131     DacMenp15   = 3u,
132     DacMenp31   = 4u,
133     DacMenp63   = 5u,
134     DacMenp127  = 6u,
135     DacMenp255  = 7u,
136     DacMenp511  = 8u,
137     DacMenp1023 = 9u,
138     DacMenp2047 = 10u,
139     DacMenp4095 = 11u
140 }en_dac_mamp_t;
141 
142 /**
143  ******************************************************************************
144  ** \brief DACx通道DMA使能或禁止                 DAC_CR0: DMAEN0 & DMAEN1
145  ******************************************************************************/
146 
147 /**
148  ******************************************************************************
149  ** \brief DACx通道DMA下溢中断使能或禁止         DAC_CR0: DMAUDRIE0 & DMAUDRIE1
150  ******************************************************************************/
151 
152 /**
153  ******************************************************************************
154  ** \brief DACx参考电压选择                       DAC_CR0: SREF0 & SREF1
155  ******************************************************************************/
156 typedef enum
157 {
158     DacVoltage1V5   = 0u,   //内部1.5V
159     DacVoltage2V5   = 1u,   //内部2.5V
160     DacVoltageExRef = 2u,   //外部参考电压ExRef(PB01)
161     DacVoltageAvcc  = 3u    //AVCC电压
162 }en_dac_sref_t;
163 
164 /**
165  ******************************************************************************
166  ** \brief DACx触发选择寄存器DAC_ETRS              DAC_ETRS
167  ******************************************************************************/
168 typedef enum
169 {
170     DacPortTrigPA9 = 0u,      //触发端口为PA9
171     DacPortTrigPB9 = 1u,      //触发端口为PB9
172     DacPortTrigPC9 = 2u,      //触发端口为PC9
173     DacPortTrigPD9 = 3u,      //触发端口为PD9
174     DacPortTrigPE9 = 4u,      //触发端口为PE9
175     DacPortTrigPF9 = 5u       //触发端口为PF9
176 }en_port_trig_t;
177 
178 /**
179  ******************************************************************************
180  ** \brief 对齐方式
181  ******************************************************************************/
182 typedef enum
183 {
184     DacRightAlign = 0u,        //右对齐
185     DacLeftAlign  = 1u         //左对齐
186 }en_align_t;
187 
188 /**
189  ******************************************************************************
190  ** \brief 数据位数
191  ******************************************************************************/
192 typedef enum
193 {
194     DacBit8  = 0u,               //8位
195     DacBit12 = 1u                //12位
196 }en_bitno_t;
197 
198 /**
199  ******************************************************************************
200  ** \brief 初始化配置结构体
201  ******************************************************************************/
202 typedef struct
203 {
204     en_dac_boff_t  boff_t;
205     en_dac_ten_t   ten_t;
206     en_dac_tsel_t  tsel_t;
207     en_dac_wave_t  wave_t;
208     en_dac_mamp_t  mamp_t;
209     en_dac_sref_t  sref_t;
210     en_port_trig_t port_trig_t;
211     en_align_t     align;
212     uint16_t       dhr12;
213     uint8_t        dhr8;
214 }stc_dac_cfg_t;
215 
216 
217 
218 extern void Dac_DmaCmd(boolean_t NewState);
219 extern void Dac_DmaITCfg(boolean_t NewState);
220 extern boolean_t Dac_GetITStatus(void);
221 extern void Dac_Cmd(boolean_t NewState);
222 extern void Dac_SoftwareTriggerCmd(void);
223 extern void Dac_Init(stc_dac_cfg_t* DAC_InitStruct);
224 extern void Dac_SetChannelData(en_align_t DAC_Align, en_bitno_t DAC_Bit, uint16_t Data);
225 extern uint16_t Dac_GetDataOutputValue(void);
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 #endif //__DAC_H__
231 
232 /******************************************************************************/
233 /* EOF (not truncated)                                                        */
234 /******************************************************************************/
235