ch32v00X_adc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v00X_adc.h
  3. * Author : WCH
  4. * Version : V1.0.1
  5. * Date : 2024/12/23
  6. * Description : This file contains all the functions prototypes for the
  7. * ADC firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V00X_ADC_H
  14. #define __CH32V00X_ADC_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <ch32v00X.h>
  19. /* ADC Init structure definition */
  20. typedef struct
  21. {
  22. uint32_t ADC_Mode; /* Configures the ADC to operate in independent or
  23. dual mode.
  24. This parameter can be a value of @ref ADC_mode */
  25. FunctionalState ADC_ScanConvMode; /* Specifies whether the conversion is performed in
  26. Scan (multichannels) or Single (one channel) mode.
  27. This parameter can be set to ENABLE or DISABLE */
  28. FunctionalState ADC_ContinuousConvMode; /* Specifies whether the conversion is performed in
  29. Continuous or Single mode.
  30. This parameter can be set to ENABLE or DISABLE. */
  31. uint32_t ADC_ExternalTrigConv; /* Defines the external trigger used to start the analog
  32. to digital conversion of regular channels. This parameter
  33. can be a value of @ref ADC_external_trigger_sources_for_regular_channels_conversion */
  34. uint32_t ADC_DataAlign; /* Specifies whether the ADC data alignment is left or right.
  35. This parameter can be a value of @ref ADC_data_align */
  36. uint8_t ADC_NbrOfChannel; /* Specifies the number of ADC channels that will be converted
  37. using the sequencer for regular channel group.
  38. This parameter must range from 1 to 16. */
  39. } ADC_InitTypeDef;
  40. /* ADC_mode */
  41. #define ADC_Mode_Independent ((uint32_t)0x00000000)
  42. /* ADC_external_trigger_sources_for_regular_channels_conversion */
  43. #define ADC_ExternalTrigConv_T1_TRGO ((uint32_t)0x00000000)
  44. #define ADC_ExternalTrigConv_T1_CC1 ((uint32_t)0x00020000)
  45. #define ADC_ExternalTrigConv_T1_CC2 ((uint32_t)0x00040000)
  46. #define ADC_ExternalTrigConv_T2_TRGO ((uint32_t)0x00060000)
  47. #define ADC_ExternalTrigConv_T2_CC1 ((uint32_t)0x00080000)
  48. #define ADC_ExternalTrigConv_T2_CC2 ((uint32_t)0x000A0000)
  49. #define ADC_ExternalTrigConv_Ext_PD3_PC2_OPA ((uint32_t)0x000C0000)
  50. #define ADC_ExternalTrigConv_None ((uint32_t)0x000E0000)
  51. /* ADC_data_align */
  52. #define ADC_DataAlign_Right ((uint32_t)0x00000000)
  53. #define ADC_DataAlign_Left ((uint32_t)0x00000800)
  54. /* ADC_channels */
  55. #define ADC_Channel_0 ((uint8_t)0x00)
  56. #define ADC_Channel_1 ((uint8_t)0x01)
  57. #define ADC_Channel_2 ((uint8_t)0x02)
  58. #define ADC_Channel_3 ((uint8_t)0x03)
  59. #define ADC_Channel_4 ((uint8_t)0x04)
  60. #define ADC_Channel_5 ((uint8_t)0x05)
  61. #define ADC_Channel_6 ((uint8_t)0x06)
  62. #define ADC_Channel_7 ((uint8_t)0x07)
  63. #define ADC_Channel_8 ((uint8_t)0x08)
  64. #define ADC_Channel_9 ((uint8_t)0x09)
  65. #define ADC_Channel_Vrefint ((uint8_t)ADC_Channel_8)
  66. #define ADC_Channel_OPA ((uint8_t)ADC_Channel_9)
  67. /* ADC_sampling_time */
  68. #define ADC_SampleTime_CyclesMode0 ((uint8_t)0x00)
  69. #define ADC_SampleTime_CyclesMode1 ((uint8_t)0x01)
  70. #define ADC_SampleTime_CyclesMode2 ((uint8_t)0x02)
  71. #define ADC_SampleTime_CyclesMode3 ((uint8_t)0x03)
  72. #define ADC_SampleTime_CyclesMode4 ((uint8_t)0x04)
  73. #define ADC_SampleTime_CyclesMode5 ((uint8_t)0x05)
  74. #define ADC_SampleTime_CyclesMode6 ((uint8_t)0x06)
  75. #define ADC_SampleTime_CyclesMode7 ((uint8_t)0x07)
  76. /* ADC_external_trigger_sources_for_injected_channels_conversion */
  77. #define ADC_ExternalTrigInjecConv_T1_CC3 ((uint32_t)0x00000000)
  78. #define ADC_ExternalTrigInjecConv_T1_CC4 ((uint32_t)0x00001000)
  79. #define ADC_ExternalTrigInjecConv_T2_CC3 ((uint32_t)0x00002000)
  80. #define ADC_ExternalTrigInjecConv_T2_CC4 ((uint32_t)0x00003000)
  81. #define ADC_ExternalTrigInjecConv_T3_CC1 ((uint32_t)0x00004000)
  82. #define ADC_ExternalTrigInjecConv_T3_CC2 ((uint32_t)0x00005000)
  83. #define ADC_ExternalTrigInjecConv_Ext_PD1_PA2_OPA ((uint32_t)0x00006000)
  84. #define ADC_ExternalTrigInjecConv_None ((uint32_t)0x00007000)
  85. /* ADC_injected_channel_selection */
  86. #define ADC_InjectedChannel_1 ((uint8_t)0x14)
  87. #define ADC_InjectedChannel_2 ((uint8_t)0x18)
  88. #define ADC_InjectedChannel_3 ((uint8_t)0x1C)
  89. #define ADC_InjectedChannel_4 ((uint8_t)0x20)
  90. /* ADC_analog_watchdog_selection */
  91. #define ADC_AnalogWatchdog_SingleRegEnable ((uint32_t)0x00800200)
  92. #define ADC_AnalogWatchdog_SingleInjecEnable ((uint32_t)0x00400200)
  93. #define ADC_AnalogWatchdog_SingleRegOrInjecEnable ((uint32_t)0x00C00200)
  94. #define ADC_AnalogWatchdog_AllRegEnable ((uint32_t)0x00800000)
  95. #define ADC_AnalogWatchdog_AllInjecEnable ((uint32_t)0x00400000)
  96. #define ADC_AnalogWatchdog_AllRegAllInjecEnable ((uint32_t)0x00C00000)
  97. #define ADC_AnalogWatchdog_None ((uint32_t)0x00000000)
  98. /* ADC_interrupts_definition */
  99. #define ADC_IT_EOC ((uint16_t)0x0220)
  100. #define ADC_IT_AWD ((uint16_t)0x0140)
  101. #define ADC_IT_JEOC ((uint16_t)0x0480)
  102. /* ADC_flags_definition */
  103. #define ADC_FLAG_AWD ((uint8_t)0x01)
  104. #define ADC_FLAG_EOC ((uint8_t)0x02)
  105. #define ADC_FLAG_JEOC ((uint8_t)0x04)
  106. #define ADC_FLAG_JSTRT ((uint8_t)0x08)
  107. #define ADC_FLAG_STRT ((uint8_t)0x10)
  108. /* ADC_TKey_Current_definition */
  109. #define ADC_TKey_Current_mode0 ((uint32_t)0x00000000)
  110. #define ADC_TKey_Current_mode1 ((uint32_t)0x02000000)
  111. /* ADC_RegularExTrigConv_definition */
  112. #define ADC_RegularExTrigConv_PD3_PC2 ((uint32_t)0x00000000)
  113. #define ADC_RegularExTrigConv_OPA ((uint32_t)0x00000010)
  114. /* ADC_InjectedExTrigConv_definition */
  115. #define ADC_InjectedExTrigConv_PD1_PA2 ((uint32_t)0x00000000)
  116. #define ADC_InjectedExTrigConv_OPA ((uint32_t)0x00000020)
  117. /* ADC_Sample_mode_definition */
  118. #define ADC_Sample_Over_1M_Mode ((uint32_t)0x00000000)
  119. #define ADC_Sample_NoOver_1M_Mode ((uint32_t)0x00000001)
  120. /* ADC_analog_watchdog_flags_definition */
  121. #define ADC_AnalogWatchdog_0_FLAG ((uint32_t)0x00000100)
  122. #define ADC_AnalogWatchdog_1_FLAG ((uint32_t)0x00000200)
  123. #define ADC_AnalogWatchdog_2_FLAG ((uint32_t)0x00000400)
  124. /* ADC_analog_watchdog_reset_enable_selection */
  125. #define ADC_AnalogWatchdog_0_RST_EN ((uint32_t)0x00000010)
  126. #define ADC_AnalogWatchdog_1_RST_EN ((uint32_t)0x00000020)
  127. #define ADC_AnalogWatchdog_2_RST_EN ((uint32_t)0x00000040)
  128. void ADC_DeInit(ADC_TypeDef *ADCx);
  129. void ADC_Init(ADC_TypeDef *ADCx, ADC_InitTypeDef *ADC_InitStruct);
  130. void ADC_StructInit(ADC_InitTypeDef *ADC_InitStruct);
  131. void ADC_Cmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  132. void ADC_DMACmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  133. void ADC_ITConfig(ADC_TypeDef *ADCx, uint16_t ADC_IT, FunctionalState NewState);
  134. void ADC_SoftwareStartConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  135. FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef *ADCx);
  136. void ADC_DiscModeChannelCountConfig(ADC_TypeDef *ADCx, uint8_t Number);
  137. void ADC_DiscModeCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  138. void ADC_RegularChannelConfig(ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  139. void ADC_ExternalTrigConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  140. uint16_t ADC_GetConversionValue(ADC_TypeDef *ADCx);
  141. void ADC_AutoInjectedConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  142. void ADC_InjectedDiscModeCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  143. void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef *ADCx, uint32_t ADC_ExternalTrigInjecConv);
  144. void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  145. void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  146. FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef *ADCx);
  147. void ADC_InjectedChannelConfig(ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  148. void ADC_InjectedSequencerLengthConfig(ADC_TypeDef *ADCx, uint8_t Length);
  149. void ADC_SetInjectedOffset(ADC_TypeDef *ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
  150. uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef *ADCx, uint8_t ADC_InjectedChannel);
  151. void ADC_AnalogWatchdogCmd(ADC_TypeDef *ADCx, uint32_t ADC_AnalogWatchdog);
  152. void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef *ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
  153. void ADC_AnalogWatchdog1ThresholdsConfig(ADC_TypeDef *ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
  154. void ADC_AnalogWatchdog2ThresholdsConfig(ADC_TypeDef *ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
  155. void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef *ADCx, uint8_t ADC_Channel);
  156. FlagStatus ADC_GetFlagStatus(ADC_TypeDef *ADCx, uint8_t ADC_FLAG);
  157. void ADC_ClearFlag(ADC_TypeDef *ADCx, uint8_t ADC_FLAG);
  158. ITStatus ADC_GetITStatus(ADC_TypeDef *ADCx, uint16_t ADC_IT);
  159. void ADC_ClearITPendingBit(ADC_TypeDef *ADCx, uint16_t ADC_IT);
  160. void ADC_BufferCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  161. void ADC_TKeyCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  162. void ADC_Tkey_CurrentConfig(ADC_TypeDef *ADCx, uint32_t TKey_CurrentMode);
  163. void ADC_RegularExTrigConvConfig(ADC_TypeDef *ADCx, uint32_t RegularExTrigConv);
  164. void ADC_InjectedExTrigConvConfig(ADC_TypeDef *ADCx, uint32_t InjectedExTrigConv);
  165. void ADC_TKey_ChannelxMulShieldCmd(ADC_TypeDef *ADCx, uint8_t ADC_Channel, FunctionalState NewState);
  166. void ADC_TKey_MulShieldCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  167. void ADC_Sample_ModeConfig(ADC_TypeDef *ADCx, uint32_t ADC_Sample_Mode);
  168. void ADC_DutyDelayCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  169. FlagStatus ADC_GetAnalogWatchdogFlagStatus(ADC_TypeDef *ADCx, uint32_t AnalogWatchdog_FLAG);
  170. void ADC_ClearAnalogWatchdogFlag(ADC_TypeDef *ADCx, uint32_t AnalogWatchdog_FLAG);
  171. void ADC_AnalogWatchdogResetCmd(ADC_TypeDef *ADCx, uint32_t ADC_AnalogWatchdog_x, FunctionalState NewState);
  172. void ADC_AnalogWatchdogScanCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176. #endif /*__CH32V00X_ADC_H */