apm32f0xx_dac.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*!
  2. * @file apm32f0xx_dac.h
  3. *
  4. * @brief This file contains all the functions prototypes for the DAC firmware library
  5. *
  6. * @note It's only for APM32F051,APM32F072,APM32F091 devices
  7. *
  8. * @version V1.0.3
  9. *
  10. * @date 2022-02-21
  11. *
  12. * @attention
  13. *
  14. * Copyright (C) 2020-2022 Geehy Semiconductor
  15. *
  16. * You may not use this file except in compliance with the
  17. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  18. *
  19. * The program is only for reference, which is distributed in the hope
  20. * that it will be useful and instructional for customers to develop
  21. * their software. Unless required by applicable law or agreed to in
  22. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  23. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  25. * and limitations under the License.
  26. */
  27. /* Define to prevent recursive inclusion */
  28. #ifndef __APM32F0XX_DAC_H
  29. #define __APM32F0XX_DAC_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* Includes */
  34. #include "apm32f0xx.h"
  35. /** @addtogroup APM32F0xx_StdPeriphDriver
  36. @{
  37. */
  38. /** @addtogroup DAC_Driver DAC Driver
  39. @{
  40. */
  41. /** @defgroup DAC_Macros Macros
  42. @{
  43. */
  44. /* Macros description */
  45. #define CTRL_CLEAR_MASK ((uint32_t)0x00000FFE) /*!< DAC CTRL register clear mask */
  46. #define DUAL_SWTRIG_SET ((uint32_t)0x00000003) /*!< Enable software trigger for DAC's Channel1 and Channel2 */
  47. #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC) /*!< Disable software trigger for DAC's Channel1 and Channel2 */
  48. #define DH12RCH1_OFFSET ((uint32_t)0x00000008) /*!< DAC channel1 data holding register address offset */
  49. #define DH12RCH2_OFFSET ((uint32_t)0x00000014) /*!< DAC channel2 data holding register address offset */
  50. #define DH12RD_OFFSET ((uint32_t)0x00000020) /*!< DAC dual channel data holding register address offset */
  51. #define DATOUT_OFFSET ((uint32_t)0x0000002C) /*!< DAC data output register address offset */
  52. /**@} end of group DAC_Macros*/
  53. /** @defgroup DAC_Enumerations Enumerations
  54. @{
  55. */
  56. /**
  57. * @brief DAC_Trigger
  58. */
  59. typedef enum
  60. {
  61. DAC_TRIGGER_NONE = ((uint32_t)0x00000000), /*!< None DAC Trigger */
  62. DAC_TRIGGER_T2_TRGO = ((uint32_t)0x00000024), /*!< Timer 2 TRGO event */
  63. DAC_TRIGGER_T3_TRGO = ((uint32_t)0x0000000C), /*!< Timer 3 TRGO event */
  64. DAC_TRIGGER_T6_TRGO = ((uint32_t)0x00000004), /*!< Timer 6 TRGO event */
  65. DAC_TRIGGER_T7_TRGO = ((uint32_t)0x00000014), /*!< Timer 7 TRGO event, applicable only for APM32F072 devices */
  66. DAC_TRIGGER_T15_TRGO = ((uint32_t)0x0000001C), /*!< Timer 15 TRGO event */
  67. DAC_TRIGGER_EINT_IT9 = ((uint32_t)0x00000034), /*!< EINT line9 */
  68. DAC_TRIGGER_SOFTWARE = ((uint32_t)0x0000003C) /*!< Software trigger */
  69. } DAC_TRIGGER_T;
  70. /**
  71. * @brief DAC_wave_generation, only applicable for APM32F072 devices
  72. */
  73. typedef enum
  74. {
  75. DAC_WAVE_GENERATION_NONE = ((uint32_t)0x00000000), /*!< Wave generation disabled */
  76. DAC_WAVE_GENERATION_NOISE = ((uint32_t)0x00000040), /*!< Noise wave generation enabled */
  77. DAC_WAVE_GENERATION_TRIANGLE = ((uint32_t)0x00000080) /*!< Triangle wave generation enabled */
  78. } DAC_WAVE_GENERATION_T;
  79. /**
  80. * @brief DAC channelx mask/amplitude selector, only applicable for APM32F072 devices
  81. */
  82. typedef enum
  83. {
  84. DAC_LFSRUNAMASK_BIT0 = ((uint32_t)0x00000000), /*!< Unmask bit0 of LFSR/ triangle amplitude equal to 1 */
  85. DAC_LFSRUNAMASK_BITS1_0 = ((uint32_t)0x00000100), /*!< Unmask bits[1:0] of LFSR to 3 */
  86. DAC_LFSRUNAMASK_BITS2_0 = ((uint32_t)0x00000200), /*!< Unmask bits[2:0] of LFSR to 7 */
  87. DAC_LFSRUNAMASK_BITS3_0 = ((uint32_t)0x00000300), /*!< Unmask bits[3:0] of LFSR to 15 */
  88. DAC_LFSRUNAMASK_BITS4_0 = ((uint32_t)0x00000400), /*!< Unmask bits[4:0] of LFSR to 31 */
  89. DAC_LFSRUNAMASK_BITS5_0 = ((uint32_t)0x00000500), /*!< Unmask bits[5:0] of LFSR to 63 */
  90. DAC_LFSRUNAMASK_BITS6_0 = ((uint32_t)0x00000600), /*!< Unmask bits[6:0] of LFSR to 127 */
  91. DAC_LFSRUNAMASK_BITS7_0 = ((uint32_t)0x00000700), /*!< Unmask bits[7:0] of LFSR to 255 */
  92. DAC_LFSRUNAMASK_BITS8_0 = ((uint32_t)0x00000800), /*!< Unmask bits[8:0] of LFSR to 511 */
  93. DAC_LFSRUNAMASK_BITS9_0 = ((uint32_t)0x00000900), /*!< Unmask bits[9:0] of LFSR to 1023 */
  94. DAC_LFSRUNAMASK_BITS10_0 = ((uint32_t)0x00000A00), /*!< Unmask bits[10:0] of LFS to 2047 */
  95. DAC_LFSRUNAMASK_BITS11_0 = ((uint32_t)0x00000B00), /*!< Unmask bits[11:0] of LFS to 4095 */
  96. DAC_TRIANGLEAMPLITUDE_1 = ((uint32_t)0x00000000), /*!< Select max triangle amplitude of 1 */
  97. DAC_TRIANGLEAMPLITUDE_3 = ((uint32_t)0x00000100), /*!< Select max triangle amplitude of 3 */
  98. DAC_TRIANGLEAMPLITUDE_7 = ((uint32_t)0x00000200), /*!< Select max triangle amplitude of 7 */
  99. DAC_TRIANGLEAMPLITUDE_15 = ((uint32_t)0x00000300), /*!< Select max triangle amplitude of 15 */
  100. DAC_TRIANGLEAMPLITUDE_31 = ((uint32_t)0x00000400), /*!< Select max triangle amplitude of 31 */
  101. DAC_TRIANGLEAMPLITUDE_63 = ((uint32_t)0x00000500), /*!< Select max triangle amplitude of 63 */
  102. DAC_TRIANGLEAMPLITUDE_127 = ((uint32_t)0x00000600), /*!< Select max triangle amplitude of 127 */
  103. DAC_TRIANGLEAMPLITUDE_255 = ((uint32_t)0x00000700), /*!< Select max triangle amplitude of 255 */
  104. DAC_TRIANGLEAMPLITUDE_511 = ((uint32_t)0x00000800), /*!< Select max triangle amplitude of 511 */
  105. DAC_TRIANGLEAMPLITUDE_1023 = ((uint32_t)0x00000900), /*!< Select max triangle amplitude of 1023 */
  106. DAC_TRIANGLEAMPLITUDE_2047 = ((uint32_t)0x00000A00), /*!< Select max triangle amplitude of 2047 */
  107. DAC_TRIANGLEAMPLITUDE_4095 = ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
  108. } DAC_MASK_AMPLITUDE_SEL_T;
  109. /**
  110. * @brief DAC_OutputBuffer
  111. */
  112. typedef enum
  113. {
  114. DAC_OUTPUTBUFF_ENABLE = ((uint32_t)0x00000000), /*!< DAC channel1 output buffer enabledDAC channel1 output buffer disabled */
  115. DAC_OUTPUTBUFF_DISABLE = ((uint32_t)0x00000002) /*!< DAC channel1 output buffer enabledDAC channel1 output buffer disabled */
  116. } DAC_OUTPUTBUFF_T;
  117. /**
  118. * @brief DAC_Channel_selection
  119. */
  120. typedef enum
  121. {
  122. DAC_CHANNEL_1 = ((uint32_t)0x00000000), /*!< DAC channel1 */
  123. DAC_CHANNEL_2 = ((uint32_t)0x00000010) /*!< DAC channel2 */
  124. } DAC_CHANNEL_T;
  125. /**
  126. * @brief DAC_data_alignment
  127. */
  128. typedef enum
  129. {
  130. DAC_ALIGN_12B_R = ((uint32_t)0x00000000), /*!< DAC 12-bit right-aligned data */
  131. DAC_ALIGN_12B_L = ((uint32_t)0x00000004), /*!< DAC 12-bit left-aligned data */
  132. DAC_ALIGN_8B_R = ((uint32_t)0x00000008) /*!< DAC 8-bit right-aligned data */
  133. } DAC_DATA_ALIGN_T;
  134. /**
  135. * @brief DAC_interrupts_definition
  136. */
  137. typedef enum
  138. {
  139. DAC_INT_CH1_DMAUDR = ((uint32_t)0x00002000), /*!< DAC channel1 DMA Underrun Interrupt */
  140. DAC_INT_CH2_DMAUDR = ((uint32_t)0x20000000) /*!< DAC channel2 DMA Underrun Interrupt */
  141. } DAC_INT_T;
  142. /**
  143. * @brief DAC_flags_definition
  144. */
  145. typedef enum
  146. {
  147. DAC_FLAG_CH1_DMAUDR = ((uint32_t)0x00002000), /*!< DAC channel1 DMA Underrun Flag */
  148. DAC_FLAG_CH2_DMAUDR = ((uint32_t)0x20000000) /*!< DAC channel2 DMA Underrun Flag */
  149. } DAC_FLAG_T;
  150. /**@} end of group DAC_Enumerations */
  151. /** @defgroup DAC_Structures Structures
  152. @{
  153. */
  154. /**
  155. * @brief DAC Config structure definition
  156. */
  157. typedef struct
  158. {
  159. DAC_TRIGGER_T trigger; /*!< DAC trigger selection */
  160. DAC_OUTPUTBUFF_T outputBuff; /*!< DAC output buffer disable */
  161. DAC_WAVE_GENERATION_T waveGeneration; /*!< DAC noise/triangle wave generation selection */
  162. DAC_MASK_AMPLITUDE_SEL_T maskAmplitudeSelect; /*!< DAC mask/amplitude selector */
  163. } DAC_Config_T;
  164. /**@} end of group DAC_Structures */
  165. /** @defgroup DAC_Variables Variables
  166. @{
  167. */
  168. /**@} end of group DAC_Variables */
  169. /** @defgroup DAC_Functions Functions
  170. @{
  171. */
  172. /* DAC reset and configuration */
  173. void DAC_Reset(void);
  174. void DAC_Config(uint32_t channel, DAC_Config_T* dacConfig);
  175. void DAC_ConfigStructInit(DAC_Config_T* dacConfig);
  176. void DAC_Enable(DAC_CHANNEL_T channel);
  177. void DAC_Disable(DAC_CHANNEL_T channel);
  178. void DAC_EnableSoftwareTrigger(DAC_CHANNEL_T channel);
  179. void DAC_DisableSoftwareTrigger(DAC_CHANNEL_T channel);
  180. void DAC_EnableDualSoftwareTrigger(void); /*!< Only for APM32F072 and APM32F091 devices */
  181. void DAC_DisableDualSoftwareTrigger(void); /*!< Only for APM32F072 and APM32F091 devices */
  182. void DAC_EnableWaveGeneration(DAC_CHANNEL_T channel, DAC_WAVE_GENERATION_T wave); /*!< Only for APM32F072 and APM32F091 devices */
  183. void DAC_DisableWaveGeneration(DAC_CHANNEL_T channel, DAC_WAVE_GENERATION_T wave); /*!< Only for APM32F072 and APM32F091 devices */
  184. /* Read data */
  185. void DAC_ConfigChannel1Data(DAC_DATA_ALIGN_T dataAlign, uint16_t data);
  186. void DAC_ConfigChannel2Data(DAC_DATA_ALIGN_T dataAlign, uint16_t data); /*!< Only for APM32F072 and APM32F091 devices */
  187. void DAC_ConfigDualChannelData(DAC_DATA_ALIGN_T dataAlign, uint16_t data2, uint16_t data1); /*!< Only for APM32F072 and APM32F091 devices */
  188. uint16_t DAC_ReadDataOutputValue(DAC_CHANNEL_T channel);
  189. /* DMA */
  190. void DAC_EnableDMA(DAC_CHANNEL_T channel);
  191. void DAC_DisableDMA(DAC_CHANNEL_T channel);
  192. /* Interrupt and flag */
  193. void DAC_EnableInterrupt(DAC_CHANNEL_T channel);
  194. void DAC_DisableInterrupt(DAC_CHANNEL_T channel);
  195. uint8_t DAC_ReadStatusFlag(DAC_FLAG_T flag);
  196. void DAC_ClearStatusFlag(DAC_FLAG_T flag);
  197. uint8_t DAC_ReadIntFlag(DAC_INT_T intFlag);
  198. void DAC_ClearIntFlag(DAC_INT_T intFlag);
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* __APM32F0XX_DAC_H */
  203. /**@} end of group DAC_Functions */
  204. /**@} end of group DAC_Driver */
  205. /**@} end of group APM32F0xx_StdPeriphDriver */