apm32f4xx_dac.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F4XX_DAC_H
  27. #define __APM32F4XX_DAC_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f4xx.h"
  33. /** @addtogroup APM32F4xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup DAC_Driver
  37. @{
  38. */
  39. /** @defgroup DAC_Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief DAC Channel selection
  44. */
  45. typedef enum
  46. {
  47. DAC_CHANNEL_1 = 0x00000000, /*!< DAC channel 1 */
  48. DAC_CHANNEL_2 = 0x00000010 /*!< DAC channel 2 */
  49. } DAC_CHANNEL_T;
  50. /**
  51. * @brief DAC trigger selection
  52. */
  53. typedef enum
  54. {
  55. DAC_TRIGGER_NONE = 0x00000000, /*!< DAC channel trigger disable */
  56. DAC_TRIGGER_TMR6_TRGO = 0x00000004, /*!< Enable trigger and select TMR6 TRGO event to trigger */
  57. DAC_TRIGGER_TMR8_TRGO = 0x0000000C, /*!< Enable trigger and select TMR8 TRGO event to trigger */
  58. DAC_TRIGGER_TMR7_TRGO = 0x00000014, /*!< Enable trigger and select TMR7 TRGO event to trigger */
  59. DAC_TRIGGER_TMR5_TRGO = 0x0000001C, /*!< Enable trigger and select TMR5 TRGO event to trigger */
  60. DAC_TRIGGER_TMR2_TRGO = 0x00000024, /*!< Enable trigger and select TMR2 TRGO event to trigger */
  61. DAC_TRIGGER_TMR4_TRGO = 0x0000002C, /*!< Enable trigger and select TMR4 TRGO event to trigger */
  62. DAC_TRIGGER_EINT9 = 0x00000034, /*!< Enable trigger and select EINT9 to trigger */
  63. DAC_TRIGGER_SOFT = 0x0000003C /*!< Enable trigger and select software to trigger */
  64. } DAC_TRIGGER_T;
  65. /**
  66. * @brief DAC wave generation
  67. */
  68. typedef enum
  69. {
  70. DAC_WAVE_GENERATION_NONE = 0x00000000, /*!< Disable wave generation */
  71. DAC_WAVE_GENERATION_NOISE = 0x00000040, /*!< Enable generate noise wave */
  72. DAC_WAVE_GENERATION_TRIANGLE = 0x00000080 /*!< Enable generate triangle wave */
  73. } DAC_WAVE_GENERATION_T;
  74. /**
  75. * @brief DAC channelx mask/amplitude selector
  76. */
  77. typedef enum
  78. {
  79. DAC_LFSR_MASK_BIT11_1 = 0x00000000, /*!< Mask bit[11:1] of LFSR for noise wave generation */
  80. DAC_LFSR_MASK_BIT11_2 = 0x00000100, /*!< Mask bit[11:2] of LFSR for noise wave generation */
  81. DAC_LFSR_MASK_BIT11_3 = 0x00000200, /*!< Mask bit[11:3] of LFSR for noise wave generation */
  82. DAC_LFSR_MASK_BIT11_4 = 0x00000300, /*!< Mask bit[11:4] of LFSR for noise wave generation */
  83. DAC_LFSR_MASK_BIT11_5 = 0x00000400, /*!< Mask bit[11:5] of LFSR for noise wave generation */
  84. DAC_LFSR_MASK_BIT11_6 = 0x00000500, /*!< Mask bit[11:6] of LFSR for noise wave generation */
  85. DAC_LFSR_MASK_BIT11_7 = 0x00000600, /*!< Mask bit[11:7] of LFSR for noise wave generation */
  86. DAC_LFSR_MASK_BIT11_8 = 0x00000700, /*!< Mask bit[11:8] of LFSR for noise wave generation */
  87. DAC_LFSR_MASK_BIT11_9 = 0x00000800, /*!< Mask bit[11:9] of LFSR for noise wave generation */
  88. DAC_LFSR_MASK_BIT11_10 = 0x00000900, /*!< Mask bit[11:10] of LFSR for noise wave generation */
  89. DAC_LFSR_MASK_BIT11 = 0x00000A00, /*!< Mask bit11 of LFSR for noise wave generation */
  90. DAC_LFSR_MASK_NONE = 0x00000B00, /*!< Mask none bit of LFSR for noise wave generation */
  91. DAC_TRIANGLE_AMPLITUDE_1 = 0x00000000, /*!< Triangle amplitude equal to 1 */
  92. DAC_TRIANGLE_AMPLITUDE_3 = 0x00000100, /*!< Triangle amplitude equal to 3 */
  93. DAC_TRIANGLE_AMPLITUDE_7 = 0x00000200, /*!< Triangle amplitude equal to 7 */
  94. DAC_TRIANGLE_AMPLITUDE_15 = 0x00000300, /*!< Triangle amplitude equal to 15 */
  95. DAC_TRIANGLE_AMPLITUDE_31 = 0x00000400, /*!< Triangle amplitude equal to 31 */
  96. DAC_TRIANGLE_AMPLITUDE_63 = 0x00000500, /*!< Triangle amplitude equal to 63 */
  97. DAC_TRIANGLE_AMPLITUDE_127 = 0x00000600, /*!< Triangle amplitude equal to 127 */
  98. DAC_TRIANGLE_AMPLITUDE_255 = 0x00000700, /*!< Triangle amplitude equal to 255 */
  99. DAC_TRIANGLE_AMPLITUDE_511 = 0x00000800, /*!< Triangle amplitude equal to 511 */
  100. DAC_TRIANGLE_AMPLITUDE_1023 = 0x00000900, /*!< Triangle amplitude equal to 1023 */
  101. DAC_TRIANGLE_AMPLITUDE_2047 = 0x00000A00, /*!< Triangle amplitude equal to 2047 */
  102. DAC_TRIANGLE_AMPLITUDE_4095 = 0x00000B00 /*!< Triangle amplitude equal to 4095 */
  103. } DAC_MASK_AMPLITUDE_SEL_T;
  104. /**
  105. * @brief DAC output buffer
  106. */
  107. typedef enum
  108. {
  109. DAC_OUTPUT_BUFFER_ENBALE = 0x00000000, /*!< DAC Channel Output Buffer Enable */
  110. DAC_OUTPUT_BUFFER_DISABLE = 0x00000002 /*!< DAC Channel1 Output Buffer Disable */
  111. } DAC_OUTPUT_BUFFER_T;
  112. /**
  113. * @brief DAC data align
  114. */
  115. typedef enum
  116. {
  117. DAC_ALIGN_12BIT_R = 0x00000000, /*!< 12-bit right-aligned data */
  118. DAC_ALIGN_12BIT_L = 0x00000004, /*!< 12-bit left-aligned data */
  119. DAC_ALIGN_8BIT_R = 0x00000008 /*!< 8-bit right-aligned data */
  120. } DAC_ALIGN_T;
  121. /**@} end of group DAC_Enumerations*/
  122. /** @addtogroup DAC_Structure Data Structure
  123. @{
  124. */
  125. /**
  126. * @brief DAC Config structure definition
  127. */
  128. typedef struct
  129. {
  130. DAC_TRIGGER_T trigger; /*!< DAC trigger selection */
  131. DAC_OUTPUT_BUFFER_T outputBuffer; /*!< DAC output buffer configuration */
  132. DAC_WAVE_GENERATION_T waveGeneration; /*!< DAC wave generation configuration*/
  133. DAC_MASK_AMPLITUDE_SEL_T maskAmplitudeSelect; /*!< DAC channelx mask/amplitude selector */
  134. } DAC_Config_T;
  135. /**@} end of group DAC_Structure*/
  136. /** @defgroup DAC_Functions
  137. @{
  138. */
  139. /* DAC Reset and Configuration */
  140. void DAC_Reset(void);
  141. void DAC_Config(uint32_t channel, DAC_Config_T* dacConfig);
  142. void DAC_ConfigStructInit(DAC_Config_T* dacConfig);
  143. void DAC_Enable(DAC_CHANNEL_T channel);
  144. void DAC_Disable(DAC_CHANNEL_T channel);
  145. /* DAC channel for DAM */
  146. void DAC_DMA_Enable(DAC_CHANNEL_T channel);
  147. void DAC_DMA_Disable(DAC_CHANNEL_T channel);
  148. /* DAC channel software trigger */
  149. void DAC_EnableSoftwareTrigger(DAC_CHANNEL_T channel);
  150. void DAC_DisableSoftwareTrigger(DAC_CHANNEL_T channel);
  151. void DAC_EnableDualSoftwareTrigger(void);
  152. void DAC_DisableDualSoftwareTrigger(void);
  153. /* DAC channel wave generation */
  154. void DAC_EnableWaveGeneration(DAC_CHANNEL_T channel, DAC_WAVE_GENERATION_T wave);
  155. void DAC_DisableWaveGeneration(DAC_CHANNEL_T channel, DAC_WAVE_GENERATION_T wave);
  156. /* DAC set channel data */
  157. void DAC_ConfigChannel1Data(DAC_ALIGN_T align, uint16_t data);
  158. void DAC_ConfigChannel2Data(DAC_ALIGN_T align, uint16_t data);
  159. void DAC_ConfigDualChannelData(DAC_ALIGN_T align, uint16_t data2, uint16_t data1);
  160. /* DAC read data output value */
  161. uint16_t DAC_ReadDataOutputValue(DAC_CHANNEL_T channel);
  162. /* DAC Interrupts and flag */
  163. void DAC_EnableInterrupt(DAC_CHANNEL_T channel);
  164. void DAC_DisableInterrupt(DAC_CHANNEL_T channel);
  165. uint8_t DAC_ReadStatusFlag(DAC_CHANNEL_T channel);
  166. void DAC_ClearStatusFlag(DAC_CHANNEL_T channel);
  167. uint8_t DAC_ReadIntFlag(DAC_CHANNEL_T channel);
  168. void DAC_ClearIntFlag(DAC_CHANNEL_T channel);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* __APM32F4XX_DAC_H */
  173. /**@} end of group DAC_Enumerations */
  174. /**@} end of group DAC_Driver */
  175. /**@} end of group APM32F4xx_StdPeriphDriver */