1 /*!
2  * @file        apm32f4xx_dac.h
3  *
4  * @brief       This file contains all the functions prototypes for the DAC firmware library
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-06-23
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be usefull and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Define to prevent recursive inclusion */
27 #ifndef __APM32F4XX_DAC_H
28 #define __APM32F4XX_DAC_H
29 
30 #ifdef __cplusplus
31   extern "C" {
32 #endif
33 
34 /* Includes */
35 #include "apm32f4xx.h"
36 
37 /** @addtogroup APM32F4xx_StdPeriphDriver
38   @{
39 */
40 
41 /** @addtogroup DAC_Driver
42   @{
43 */
44 
45 /** @defgroup DAC_Enumerations
46   @{
47 */
48 
49 /**
50  * @brief DAC Channel selection
51  */
52 typedef enum
53 {
54     DAC_CHANNEL_1 = 0x00000000, /*!< DAC channel 1 */
55     DAC_CHANNEL_2 = 0x00000010  /*!< DAC channel 2 */
56 } DAC_CHANNEL_T;
57 
58 /**
59  * @brief DAC trigger selection
60  */
61 typedef enum
62 {
63     DAC_TRIGGER_NONE       = 0x00000000,    /*!< DAC channel trigger disable */
64     DAC_TRIGGER_TMR6_TRGO  = 0x00000004,    /*!< Enable trigger and select TMR6 TRGO event to trigger */
65     DAC_TRIGGER_TMR8_TRGO  = 0x0000000C,    /*!< Enable trigger and select TMR8 TRGO event to trigger */
66     DAC_TRIGGER_TMR7_TRGO  = 0x00000014,    /*!< Enable trigger and select TMR7 TRGO event to trigger */
67     DAC_TRIGGER_TMR5_TRGO  = 0x0000001C,    /*!< Enable trigger and select TMR5 TRGO event to trigger */
68     DAC_TRIGGER_TMR2_TRGO  = 0x00000024,    /*!< Enable trigger and select TMR2 TRGO event to trigger */
69     DAC_TRIGGER_TMR4_TRGO  = 0x0000002C,    /*!< Enable trigger and select TMR4 TRGO event to trigger */
70     DAC_TRIGGER_EINT9      = 0x00000034,    /*!< Enable trigger and select EINT9 to trigger */
71     DAC_TRIGGER_SOFT       = 0x0000003C     /*!< Enable trigger and select software to trigger */
72 } DAC_TRIGGER_T;
73 
74 /**
75  * @brief DAC wave generation
76  */
77 typedef enum
78 {
79     DAC_WAVE_GENERATION_NONE     = 0x00000000,  /*!< Disable wave generation */
80     DAC_WAVE_GENERATION_NOISE    = 0x00000040,  /*!< Enable generate noise wave */
81     DAC_WAVE_GENERATION_TRIANGLE = 0x00000080   /*!< Enable generate triangle wave */
82 } DAC_WAVE_GENERATION_T;
83 
84 /**
85  * @brief DAC channelx mask/amplitude selector
86  */
87 typedef enum
88 {
89     DAC_LFSR_MASK_BIT11_1  = 0x00000000, /*!< Mask bit[11:1] of LFSR for noise wave generation */
90     DAC_LFSR_MASK_BIT11_2  = 0x00000100, /*!< Mask bit[11:2] of LFSR for noise wave generation */
91     DAC_LFSR_MASK_BIT11_3  = 0x00000200, /*!< Mask bit[11:3] of LFSR for noise wave generation */
92     DAC_LFSR_MASK_BIT11_4  = 0x00000300, /*!< Mask bit[11:4] of LFSR for noise wave generation */
93     DAC_LFSR_MASK_BIT11_5  = 0x00000400, /*!< Mask bit[11:5] of LFSR for noise wave generation */
94     DAC_LFSR_MASK_BIT11_6  = 0x00000500, /*!< Mask bit[11:6] of LFSR for noise wave generation */
95     DAC_LFSR_MASK_BIT11_7  = 0x00000600, /*!< Mask bit[11:7] of LFSR for noise wave generation */
96     DAC_LFSR_MASK_BIT11_8  = 0x00000700, /*!< Mask bit[11:8] of LFSR for noise wave generation */
97     DAC_LFSR_MASK_BIT11_9  = 0x00000800, /*!< Mask bit[11:9] of LFSR for noise wave generation */
98     DAC_LFSR_MASK_BIT11_10 = 0x00000900, /*!< Mask bit[11:10] of LFSR for noise wave generation */
99     DAC_LFSR_MASK_BIT11    = 0x00000A00, /*!< Mask bit11 of LFSR for noise wave generation */
100     DAC_LFSR_MASK_NONE     = 0x00000B00, /*!< Mask none bit of LFSR for noise wave generation */
101 
102     DAC_TRIANGLE_AMPLITUDE_1    = 0x00000000, /*!< Triangle amplitude equal to 1 */
103     DAC_TRIANGLE_AMPLITUDE_3    = 0x00000100, /*!< Triangle amplitude equal to 3 */
104     DAC_TRIANGLE_AMPLITUDE_7    = 0x00000200, /*!< Triangle amplitude equal to 7 */
105     DAC_TRIANGLE_AMPLITUDE_15   = 0x00000300, /*!< Triangle amplitude equal to 15 */
106     DAC_TRIANGLE_AMPLITUDE_31   = 0x00000400, /*!< Triangle amplitude equal to 31 */
107     DAC_TRIANGLE_AMPLITUDE_63   = 0x00000500, /*!< Triangle amplitude equal to 63 */
108     DAC_TRIANGLE_AMPLITUDE_127  = 0x00000600, /*!< Triangle amplitude equal to 127 */
109     DAC_TRIANGLE_AMPLITUDE_255  = 0x00000700, /*!< Triangle amplitude equal to 255 */
110     DAC_TRIANGLE_AMPLITUDE_511  = 0x00000800, /*!< Triangle amplitude equal to 511 */
111     DAC_TRIANGLE_AMPLITUDE_1023 = 0x00000900, /*!< Triangle amplitude equal to 1023 */
112     DAC_TRIANGLE_AMPLITUDE_2047 = 0x00000A00, /*!< Triangle amplitude equal to 2047 */
113     DAC_TRIANGLE_AMPLITUDE_4095 = 0x00000B00  /*!< Triangle amplitude equal to 4095 */
114 } DAC_MASK_AMPLITUDE_SEL_T;
115 
116 /**
117  * @brief DAC output buffer
118  */
119 typedef enum
120 {
121     DAC_OUTPUT_BUFFER_ENBALE  = 0x00000000, /*!< DAC Channel Output Buffer Enable */
122     DAC_OUTPUT_BUFFER_DISABLE = 0x00000002  /*!< DAC Channel1 Output Buffer Disable */
123 } DAC_OUTPUT_BUFFER_T;
124 
125 /**
126  * @brief DAC data align
127  */
128 typedef enum
129 {
130     DAC_ALIGN_12BIT_R = 0x00000000, /*!< 12-bit right-aligned data */
131     DAC_ALIGN_12BIT_L = 0x00000004, /*!< 12-bit left-aligned data */
132     DAC_ALIGN_8BIT_R  = 0x00000008  /*!< 8-bit right-aligned data */
133 } DAC_ALIGN_T;
134 
135 /**@} end of group DAC_Enumerations*/
136 
137 /** @addtogroup DAC_Structure Data Structure
138   @{
139 */
140 
141 /**
142  * @brief DAC Config structure definition
143  */
144 typedef struct
145 {
146     DAC_TRIGGER_T               trigger;                /*!< DAC trigger selection */
147     DAC_OUTPUT_BUFFER_T         outputBuffer;           /*!< DAC output buffer configuration */
148     DAC_WAVE_GENERATION_T       waveGeneration;         /*!< DAC wave generation configuration*/
149     DAC_MASK_AMPLITUDE_SEL_T    maskAmplitudeSelect;    /*!< DAC channelx mask/amplitude selector */
150 } DAC_Config_T;
151 
152 /**@} end of group DAC_Structure*/
153 
154 /** @defgroup DAC_Functions
155   @{
156 */
157 
158 /* DAC Reset and Configuration */
159 void DAC_Reset(void);
160 void DAC_Config(uint32_t channel, DAC_Config_T* dacConfig);
161 void DAC_ConfigStructInit(DAC_Config_T* dacConfig);
162 void DAC_Enable(DAC_CHANNEL_T channel);
163 void DAC_Disable(DAC_CHANNEL_T channel);
164 
165 /* DAC channel for DAM */
166 void DAC_DMA_Enable(DAC_CHANNEL_T channel);
167 void DAC_DMA_Disable(DAC_CHANNEL_T channel);
168 
169 /* DAC channel software trigger */
170 void DAC_EnableSoftwareTrigger(DAC_CHANNEL_T channel);
171 void DAC_DisableSoftwareTrigger(DAC_CHANNEL_T channel);
172 void DAC_EnableDualSoftwareTrigger(void);
173 void DAC_DisableDualSoftwareTrigger(void);
174 
175 /* DAC channel wave generation */
176 void DAC_EnableWaveGeneration(DAC_CHANNEL_T channel, DAC_WAVE_GENERATION_T wave);
177 void DAC_DisableWaveGeneration(DAC_CHANNEL_T channel, DAC_WAVE_GENERATION_T wave);
178 
179 /* DAC set channel data */
180 void DAC_ConfigChannel1Data(DAC_ALIGN_T align, uint16_t data);
181 void DAC_ConfigChannel2Data(DAC_ALIGN_T align, uint16_t data);
182 void DAC_ConfigDualChannelData(DAC_ALIGN_T align, uint16_t data2, uint16_t data1);
183 
184 /* DAC read data output value */
185 uint16_t DAC_ReadDataOutputValue(DAC_CHANNEL_T channel);
186 
187 /* DAC Interrupts and flag */
188 void DAC_EnableInterrupt(DAC_CHANNEL_T channel);
189 void DAC_DisableInterrupt(DAC_CHANNEL_T channel);
190 uint8_t DAC_ReadStatusFlag(DAC_CHANNEL_T channel);
191 void DAC_ClearStatusFlag(DAC_CHANNEL_T channel);
192 uint8_t DAC_ReadIntFlag(DAC_CHANNEL_T channel);
193 void DAC_ClearIntFlag(DAC_CHANNEL_T channel);
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif /* __APM32F4XX_DAC_H */
200 
201 /**@} end of group DAC_Enumerations */
202 /**@} end of group DAC_Driver */
203 /**@} end of group APM32F4xx_StdPeriphDriver */
204