n32g45x_adc.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_adc.h
  29. * @author Nations
  30. * @version v1.0.3
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __N32G45X_ADC_H__
  35. #define __N32G45X_ADC_H__
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "n32g45x.h"
  40. #include <stdbool.h>
  41. /** @addtogroup N32G45X_StdPeriph_Driver
  42. * @{
  43. */
  44. #define VREF1P2_CTRL (*(uint32_t*)(0x40001800+0x20))
  45. #define _EnVref1p2() do{VREF1P2_CTRL|=(1<<10);}while(0);
  46. #define _DisVref1p2() do{VREF1P2_CTRL&=~(1<<10);}while(0);
  47. /** @addtogroup ADC
  48. * @{
  49. */
  50. /** @addtogroup ADC_Exported_Types
  51. * @{
  52. */
  53. /**
  54. * @brief ADC Init structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t WorkMode; /*!< Configures the ADC to operate in independent or
  59. dual mode.
  60. This parameter can be a value of @ref ADC_mode */
  61. FunctionalState MultiChEn; /*!< Specifies whether the conversion is performed in
  62. Scan (multichannels) or Single (one channel) mode.
  63. This parameter can be set to ENABLE or DISABLE */
  64. FunctionalState ContinueConvEn; /*!< Specifies whether the conversion is performed in
  65. Continuous or Single mode.
  66. This parameter can be set to ENABLE or DISABLE. */
  67. uint32_t ExtTrigSelect; /*!< Defines the external trigger used to start the analog
  68. to digital conversion of regular channels. This parameter
  69. can be a value of @ref
  70. ADC_external_trigger_sources_for_regular_channels_conversion */
  71. uint32_t DatAlign; /*!< Specifies whether the ADC data alignment is left or right.
  72. This parameter can be a value of @ref ADC_data_align */
  73. uint8_t ChsNumber; /*!< Specifies the number of ADC channels that will be converted
  74. using the sequencer for regular channel group.
  75. This parameter must range from 1 to 16. */
  76. } ADC_InitType;
  77. /**
  78. * @}
  79. */
  80. /** @addtogroup ADC_Exported_Constants
  81. * @{
  82. */
  83. #define IsAdcModule(PERIPH) (((PERIPH) == ADC1) || ((PERIPH) == ADC2) || ((PERIPH) == ADC3) || ((PERIPH) == ADC4))
  84. #define IsAdcDmaModule(PERIPH) (((PERIPH) == ADC1) || ((PERIPH) == ADC2) || ((PERIPH) == ADC3) || ((PERIPH) == ADC4))
  85. /** @addtogroup ADC_mode
  86. * @{
  87. */
  88. #define ADC_WORKMODE_INDEPENDENT ((uint32_t)0x00000000)
  89. #define ADC_WORKMODE_REG_INJECT_SIMULT ((uint32_t)0x00010000)
  90. #define ADC_WORKMODE_REG_SIMULT_ALTER_TRIG ((uint32_t)0x00020000)
  91. #define ADC_WORKMODE_INJ_SIMULT_FAST_INTERL ((uint32_t)0x00030000)
  92. #define ADC_WORKMODE_INJ_SIMULT_SLOW_INTERL ((uint32_t)0x00040000)
  93. #define ADC_WORKMODE_INJ_SIMULT ((uint32_t)0x00050000)
  94. #define ADC_WORKMODE_REG_SIMULT ((uint32_t)0x00060000)
  95. #define ADC_WORKMODE_FAST_INTERL ((uint32_t)0x00070000)
  96. #define ADC_WORKMODE_SLOW_INTERL ((uint32_t)0x00080000)
  97. #define ADC_WORKMODE_ALTER_TRIG ((uint32_t)0x00090000)
  98. #define IsAdcWorkMode(MODE) \
  99. (((MODE) == ADC_WORKMODE_INDEPENDENT) || ((MODE) == ADC_WORKMODE_REG_INJECT_SIMULT) \
  100. || ((MODE) == ADC_WORKMODE_REG_SIMULT_ALTER_TRIG) || ((MODE) == ADC_WORKMODE_INJ_SIMULT_FAST_INTERL) \
  101. || ((MODE) == ADC_WORKMODE_INJ_SIMULT_SLOW_INTERL) || ((MODE) == ADC_WORKMODE_INJ_SIMULT) \
  102. || ((MODE) == ADC_WORKMODE_REG_SIMULT) || ((MODE) == ADC_WORKMODE_FAST_INTERL) \
  103. || ((MODE) == ADC_WORKMODE_SLOW_INTERL) || ((MODE) == ADC_WORKMODE_ALTER_TRIG))
  104. /**
  105. * @}
  106. */
  107. /** @addtogroup ADC_external_trigger_sources_for_regular_channels_conversion
  108. * @{
  109. */
  110. #define ADC_EXT_TRIGCONV_T1_CC1 ((uint32_t)0x00000000) /*!< For ADC1 and ADC2 */
  111. #define ADC_EXT_TRIGCONV_T1_CC2 ((uint32_t)0x00020000) /*!< For ADC1 and ADC2 */
  112. #define ADC_EXT_TRIGCONV_T2_CC2 ((uint32_t)0x00060000) /*!< For ADC1 and ADC2 */
  113. #define ADC_EXT_TRIGCONV_T3_TRGO ((uint32_t)0x00080000) /*!< For ADC1 and ADC2 */
  114. #define ADC_EXT_TRIGCONV_T4_CC4 ((uint32_t)0x000A0000) /*!< For ADC1 and ADC2 */
  115. #define ADC_EXT_TRIGCONV_EXT_INT11_TIM8_TRGO ((uint32_t)0x000C0000) /*!< For ADC1 and ADC2 */
  116. #define ADC_EXT_TRIGCONV_T1_CC3 ((uint32_t)0x00040000) /*!< For ADC1, ADC2 , ADC3 and ADC4 */
  117. #define ADC_EXT_TRIGCONV_NONE ((uint32_t)0x000E0000) /*!< For ADC1, ADC2 , ADC3 and ADC4 */
  118. #define ADC_EXT_TRIGCONV_T3_CC1 ((uint32_t)0x00000000) /*!< For ADC3 and ADC4 */
  119. #define ADC_EXT_TRIGCONV_T2_CC3 ((uint32_t)0x00020000) /*!< For ADC3 and ADC4 */
  120. #define ADC_EXT_TRIGCONV_T8_CC1 ((uint32_t)0x00060000) /*!< For ADC3 and ADC4 */
  121. #define ADC_EXT_TRIGCONV_T8_TRGO ((uint32_t)0x00080000) /*!< For ADC3 and ADC4 */
  122. #define ADC_EXT_TRIGCONV_T5_CC1 ((uint32_t)0x000A0000) /*!< For ADC3 and ADC4 */
  123. #define ADC_EXT_TRIGCONV_EXT_INT10_T5_CC3 ((uint32_t)0x000C0000) /*!< For ADC3 and ADC4 */
  124. #define IsAdcExtTrig(REGTRIG) \
  125. (((REGTRIG) == ADC_EXT_TRIGCONV_T1_CC1) || ((REGTRIG) == ADC_EXT_TRIGCONV_T1_CC2) \
  126. || ((REGTRIG) == ADC_EXT_TRIGCONV_T1_CC3) || ((REGTRIG) == ADC_EXT_TRIGCONV_T2_CC2) \
  127. || ((REGTRIG) == ADC_EXT_TRIGCONV_T3_TRGO) || ((REGTRIG) == ADC_EXT_TRIGCONV_T4_CC4) \
  128. || ((REGTRIG) == ADC_EXT_TRIGCONV_EXT_INT11_TIM8_TRGO) || ((REGTRIG) == ADC_EXT_TRIGCONV_NONE) \
  129. || ((REGTRIG) == ADC_EXT_TRIGCONV_T3_CC1) || ((REGTRIG) == ADC_EXT_TRIGCONV_T2_CC3) \
  130. || ((REGTRIG) == ADC_EXT_TRIGCONV_T8_CC1) || ((REGTRIG) == ADC_EXT_TRIGCONV_T8_TRGO) \
  131. || ((REGTRIG) == ADC_EXT_TRIGCONV_T5_CC1) || ((REGTRIG) == ADC_EXT_TRIGCONV_EXT_INT10_T5_CC3))
  132. /**
  133. * @}
  134. */
  135. /** @addtogroup ADC_data_align
  136. * @{
  137. */
  138. #define ADC_DAT_ALIGN_R ((uint32_t)0x00000000)
  139. #define ADC_DAT_ALIGN_L ((uint32_t)0x00000800)
  140. #define IsAdcDatAlign(ALIGN) (((ALIGN) == ADC_DAT_ALIGN_R) || ((ALIGN) == ADC_DAT_ALIGN_L))
  141. /**
  142. * @}
  143. */
  144. /** @addtogroup ADC_channels
  145. * @{
  146. */
  147. #define ADC_CH_0 ((uint8_t)0x00)
  148. #define ADC_CH_1 ((uint8_t)0x01)
  149. #define ADC_CH_2 ((uint8_t)0x02)
  150. #define ADC_CH_3 ((uint8_t)0x03)
  151. #define ADC_CH_4 ((uint8_t)0x04)
  152. #define ADC_CH_5 ((uint8_t)0x05)
  153. #define ADC_CH_6 ((uint8_t)0x06)
  154. #define ADC_CH_7 ((uint8_t)0x07)
  155. #define ADC_CH_8 ((uint8_t)0x08)
  156. #define ADC_CH_9 ((uint8_t)0x09)
  157. #define ADC_CH_10 ((uint8_t)0x0A)
  158. #define ADC_CH_11 ((uint8_t)0x0B)
  159. #define ADC_CH_12 ((uint8_t)0x0C)
  160. #define ADC_CH_13 ((uint8_t)0x0D)
  161. #define ADC_CH_14 ((uint8_t)0x0E)
  162. #define ADC_CH_15 ((uint8_t)0x0F)
  163. #define ADC_CH_16 ((uint8_t)0x10)
  164. #define ADC_CH_17 ((uint8_t)0x11)
  165. #define ADC_CH_18 ((uint8_t)0x12)
  166. #define ADC_CH_TEMP_SENSOR ((uint8_t)ADC_CH_16)
  167. #define ADC_CH_INT_VREF ((uint8_t)ADC_CH_18)
  168. #define IsAdcChannel(CHANNEL) \
  169. (((CHANNEL) == ADC_CH_0) || ((CHANNEL) == ADC_CH_1) || ((CHANNEL) == ADC_CH_2) || ((CHANNEL) == ADC_CH_3) \
  170. || ((CHANNEL) == ADC_CH_4) || ((CHANNEL) == ADC_CH_5) || ((CHANNEL) == ADC_CH_6) || ((CHANNEL) == ADC_CH_7) \
  171. || ((CHANNEL) == ADC_CH_8) || ((CHANNEL) == ADC_CH_9) || ((CHANNEL) == ADC_CH_10) || ((CHANNEL) == ADC_CH_11) \
  172. || ((CHANNEL) == ADC_CH_12) || ((CHANNEL) == ADC_CH_13) || ((CHANNEL) == ADC_CH_14) || ((CHANNEL) == ADC_CH_15) \
  173. || ((CHANNEL) == ADC_CH_16) || ((CHANNEL) == ADC_CH_17) || ((CHANNEL) == ADC_CH_18))
  174. /**
  175. * @}
  176. */
  177. /** @addtogroup ADC_sampling_time
  178. * @{
  179. */
  180. #define ADC_SAMP_TIME_1CYCLES5 ((uint8_t)0x00)
  181. #define ADC_SAMP_TIME_7CYCLES5 ((uint8_t)0x01)
  182. #define ADC_SAMP_TIME_13CYCLES5 ((uint8_t)0x02)
  183. #define ADC_SAMP_TIME_28CYCLES5 ((uint8_t)0x03)
  184. #define ADC_SAMP_TIME_41CYCLES5 ((uint8_t)0x04)
  185. #define ADC_SAMP_TIME_55CYCLES5 ((uint8_t)0x05)
  186. #define ADC_SAMP_TIME_71CYCLES5 ((uint8_t)0x06)
  187. #define ADC_SAMP_TIME_239CYCLES5 ((uint8_t)0x07)
  188. #define IsAdcSampleTime(TIME) \
  189. (((TIME) == ADC_SAMP_TIME_1CYCLES5) || ((TIME) == ADC_SAMP_TIME_7CYCLES5) || ((TIME) == ADC_SAMP_TIME_13CYCLES5) \
  190. || ((TIME) == ADC_SAMP_TIME_28CYCLES5) || ((TIME) == ADC_SAMP_TIME_41CYCLES5) \
  191. || ((TIME) == ADC_SAMP_TIME_55CYCLES5) || ((TIME) == ADC_SAMP_TIME_71CYCLES5) \
  192. || ((TIME) == ADC_SAMP_TIME_239CYCLES5))
  193. /**
  194. * @}
  195. */
  196. /** @addtogroup ADC_external_trigger_sources_for_injected_channels_conversion
  197. * @{
  198. */
  199. #define ADC_EXT_TRIG_INJ_CONV_T2_TRGO ((uint32_t)0x00002000) /*!< For ADC1 and ADC2 */
  200. #define ADC_EXT_TRIG_INJ_CONV_T2_CC1 ((uint32_t)0x00003000) /*!< For ADC1 and ADC2 */
  201. #define ADC_EXT_TRIG_INJ_CONV_T3_CC4 ((uint32_t)0x00004000) /*!< For ADC1 and ADC2 */
  202. #define ADC_EXT_TRIG_INJ_CONV_T4_TRGO ((uint32_t)0x00005000) /*!< For ADC1 and ADC2 */
  203. #define ADC_EXT_TRIG_INJ_CONV_EXT_INT15_TIM8_CC4 ((uint32_t)0x00006000) /*!< For ADC1 and ADC2 */
  204. #define ADC_EXT_TRIG_INJ_CONV_T1_TRGO ((uint32_t)0x00000000) /*!< For ADC1, ADC2, ADC3 and ADC4 */
  205. #define ADC_EXT_TRIG_INJ_CONV_T1_CC4 ((uint32_t)0x00001000) /*!< For ADC1, ADC2, ADC3 and ADC4 */
  206. #define ADC_EXT_TRIG_INJ_CONV_NONE ((uint32_t)0x00007000) /*!< For ADC1, ADC2, ADC3 and ADC4 */
  207. #define ADC_EXT_TRIG_INJ_CONV_T4_CC3 ((uint32_t)0x00002000) /*!< For ADC3 and ADC4 */
  208. #define ADC_EXT_TRIG_INJ_CONV_T8_CC2 ((uint32_t)0x00003000) /*!< For ADC3 and ADC4 */
  209. #define ADC_EXT_TRIG_INJ_CONV_T8_CC4 ((uint32_t)0x00004000) /*!< For ADC3 and ADC4 */
  210. #define ADC_EXT_TRIG_INJ_CONV_T5_TRGO ((uint32_t)0x00005000) /*!< For ADC3 and ADC4 */
  211. #define ADC_EXT_TRIG_INJ_CONV_EXT_INT14_T5_CC4 ((uint32_t)0x00006000) /*!< For ADC3 and ADC4 */
  212. #define IsAdcExtInjTrig(INJTRIG) \
  213. (((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T1_TRGO) || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T1_CC4) \
  214. || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T2_TRGO) || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T2_CC1) \
  215. || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T3_CC4) || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T4_TRGO) \
  216. || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_EXT_INT15_TIM8_CC4) || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_NONE) \
  217. || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T4_CC3) || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T8_CC2) \
  218. || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T8_CC4) || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_T5_TRGO) \
  219. || ((INJTRIG) == ADC_EXT_TRIG_INJ_CONV_EXT_INT14_T5_CC4))
  220. /**
  221. * @}
  222. */
  223. /** @addtogroup ADC_injected_channel_selection
  224. * @{
  225. */
  226. #define ADC_INJ_CH_1 ((uint8_t)0x14)
  227. #define ADC_INJ_CH_2 ((uint8_t)0x18)
  228. #define ADC_INJ_CH_3 ((uint8_t)0x1C)
  229. #define ADC_INJ_CH_4 ((uint8_t)0x20)
  230. #define IsAdcInjCh(CHANNEL) \
  231. (((CHANNEL) == ADC_INJ_CH_1) || ((CHANNEL) == ADC_INJ_CH_2) || ((CHANNEL) == ADC_INJ_CH_3) \
  232. || ((CHANNEL) == ADC_INJ_CH_4))
  233. /**
  234. * @}
  235. */
  236. /** @addtogroup ADC_analog_watchdog_selection
  237. * @{
  238. */
  239. #define ADC_ANALOG_WTDG_SINGLEREG_ENABLE ((uint32_t)0x00800200)
  240. #define ADC_ANALOG_WTDG_SINGLEINJEC_ENABLE ((uint32_t)0x00400200)
  241. #define ADC_ANALOG_WTDG_SINGLEREG_OR_INJEC_ENABLE ((uint32_t)0x00C00200)
  242. #define ADC_ANALOG_WTDG_ALLREG_ENABLE ((uint32_t)0x00800000)
  243. #define ADC_ANALOG_WTDG_ALLINJEC_ENABLE ((uint32_t)0x00400000)
  244. #define ADC_ANALOG_WTDG_ALLREG_ALLINJEC_ENABLE ((uint32_t)0x00C00000)
  245. #define ADC_ANALOG_WTDG_NONE ((uint32_t)0x00000000)
  246. #define IsAdcAnalogWatchdog(WATCHDOG) \
  247. (((WATCHDOG) == ADC_ANALOG_WTDG_SINGLEREG_ENABLE) || ((WATCHDOG) == ADC_ANALOG_WTDG_SINGLEINJEC_ENABLE) \
  248. || ((WATCHDOG) == ADC_ANALOG_WTDG_SINGLEREG_OR_INJEC_ENABLE) || ((WATCHDOG) == ADC_ANALOG_WTDG_ALLREG_ENABLE) \
  249. || ((WATCHDOG) == ADC_ANALOG_WTDG_ALLINJEC_ENABLE) || ((WATCHDOG) == ADC_ANALOG_WTDG_ALLREG_ALLINJEC_ENABLE) \
  250. || ((WATCHDOG) == ADC_ANALOG_WTDG_NONE))
  251. /**
  252. * @}
  253. */
  254. /** @addtogroup ADC_interrupts_definition
  255. * @{
  256. */
  257. #define ADC_INT_ENDC ((uint16_t)0x0220)
  258. #define ADC_INT_AWD ((uint16_t)0x0140)
  259. #define ADC_INT_JENDC ((uint16_t)0x0480)
  260. #define IsAdcInt(IT) ((((IT) & (uint16_t)0xF81F) == 0x00) && ((IT) != 0x00))
  261. #define IsAdcGetInt(IT) (((IT) == ADC_INT_ENDC) || ((IT) == ADC_INT_AWD) || ((IT) == ADC_INT_JENDC))
  262. /**
  263. * @}
  264. */
  265. /** @addtogroup ADC_flags_definition
  266. * @{
  267. */
  268. #define ADC_FLAG_AWDG ((uint8_t)0x01)
  269. #define ADC_FLAG_ENDC ((uint8_t)0x02)
  270. #define ADC_FLAG_JENDC ((uint8_t)0x04)
  271. #define ADC_FLAG_JSTR ((uint8_t)0x08)
  272. #define ADC_FLAG_STR ((uint8_t)0x10)
  273. #define ADC_FLAG_EOC_ANY ((uint8_t)0x20)
  274. #define ADC_FLAG_JEOC_ANY ((uint8_t)0x40)
  275. #define IsAdcClrFlag(FLAG) ((((FLAG) & (uint8_t)0x80) == 0x00) && ((FLAG) != 0x00))
  276. #define IsAdcGetFlag(FLAG) \
  277. (((FLAG) == ADC_FLAG_AWDG) || ((FLAG) == ADC_FLAG_ENDC) || ((FLAG) == ADC_FLAG_JENDC) || ((FLAG) == ADC_FLAG_JSTR) \
  278. || ((FLAG) == ADC_FLAG_STR) || ((FLAG) == ADC_FLAG_EOC_ANY) || ((FLAG) == ADC_FLAG_JEOC_ANY))
  279. /**
  280. * @}
  281. */
  282. /** @addtogroup ADC_thresholds
  283. * @{
  284. */
  285. #define IsAdcValid(THRESHOLD) ((THRESHOLD) <= 0xFFF)
  286. /**
  287. * @}
  288. */
  289. /** @addtogroup ADC_injected_offset
  290. * @{
  291. */
  292. #define IsAdcOffsetValid(OFFSET) ((OFFSET) <= 0xFFF)
  293. /**
  294. * @}
  295. */
  296. /** @addtogroup ADC_injected_length
  297. * @{
  298. */
  299. #define IsAdcInjLenValid(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4))
  300. /**
  301. * @}
  302. */
  303. /** @addtogroup ADC_injected_rank
  304. * @{
  305. */
  306. #define IsAdcInjRankValid(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4))
  307. /**
  308. * @}
  309. */
  310. /** @addtogroup ADC_regular_length
  311. * @{
  312. */
  313. #define IsAdcSeqLenValid(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10))
  314. /**
  315. * @}
  316. */
  317. /** @addtogroup ADC_regular_rank
  318. * @{
  319. */
  320. #define IsAdcReqRankValid(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10))
  321. /**
  322. * @}
  323. */
  324. /** @addtogroup ADC_regular_discontinuous_mode_number
  325. * @{
  326. */
  327. #define IsAdcSeqDiscNumberValid(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8))
  328. /**
  329. * @}
  330. */
  331. /************************** fllowing bit seg in ex register **********************/
  332. /**@addtogroup ADC_channels_ex_style
  333. * @{
  334. */
  335. #define ADC1_Channel_01_PA0 ((uint8_t)0x01)
  336. #define ADC1_Channel_02_PA1 ((uint8_t)0x02)
  337. #define ADC1_Channel_03_PA6 ((uint8_t)0x03)
  338. #define ADC1_Channel_04_PA3 ((uint8_t)0x04)
  339. #define ADC1_Channel_05_PF4 ((uint8_t)0x05)
  340. #define ADC1_Channel_06_PC0 ((uint8_t)0x06)
  341. #define ADC1_Channel_07_PC1 ((uint8_t)0x07)
  342. #define ADC1_Channel_08_PC2 ((uint8_t)0x08)
  343. #define ADC1_Channel_09_PC3 ((uint8_t)0x09)
  344. #define ADC1_Channel_10_PF2 ((uint8_t)0x0A)
  345. #define ADC1_Channel_11_PA2 ((uint8_t)0x0B)
  346. #define ADC2_Channel_01_PA4 ((uint8_t)0x01)
  347. #define ADC2_Channel_02_PA5 ((uint8_t)0x02)
  348. #define ADC2_Channel_03_PB1 ((uint8_t)0x03)
  349. #define ADC2_Channel_04_PA7 ((uint8_t)0x04)
  350. #define ADC2_Channel_05_PC4 ((uint8_t)0x05)
  351. #define ADC2_Channel_06_PC0 ((uint8_t)0x06)
  352. #define ADC2_Channel_07_PC1 ((uint8_t)0x07)
  353. #define ADC2_Channel_08_PC2 ((uint8_t)0x08)
  354. #define ADC2_Channel_09_PC3 ((uint8_t)0x09)
  355. #define ADC2_Channel_10_PF2 ((uint8_t)0x0A)
  356. #define ADC2_Channel_11_PA2 ((uint8_t)0x0B)
  357. #define ADC2_Channel_12_PC5 ((uint8_t)0x0C)
  358. #define ADC2_Channel_13_PB2 ((uint8_t)0x0D)
  359. #define ADC3_Channel_01_PB11 ((uint8_t)0x01)
  360. #define ADC3_Channel_02_PE9 ((uint8_t)0x02)
  361. #define ADC3_Channel_03_PE13 ((uint8_t)0x03)
  362. #define ADC3_Channel_04_PE12 ((uint8_t)0x04)
  363. #define ADC3_Channel_05_PB13 ((uint8_t)0x05)
  364. #define ADC3_Channel_06_PE8 ((uint8_t)0x06)
  365. #define ADC3_Channel_07_PD10 ((uint8_t)0x07)
  366. #define ADC3_Channel_08_PD11 ((uint8_t)0x08)
  367. #define ADC3_Channel_09_PD12 ((uint8_t)0x09)
  368. #define ADC3_Channel_10_PD13 ((uint8_t)0x0A)
  369. #define ADC3_Channel_11_PD14 ((uint8_t)0x0B)
  370. #define ADC3_Channel_12_PB0 ((uint8_t)0x0C)
  371. #define ADC3_Channel_13_PE7 ((uint8_t)0x0D)
  372. #define ADC3_Channel_14_PE10 ((uint8_t)0x0E)
  373. #define ADC3_Channel_15_PE11 ((uint8_t)0x0F)
  374. #define ADC4_Channel_01_PE14 ((uint8_t)0x01)
  375. #define ADC4_Channel_02_PE15 ((uint8_t)0x02)
  376. #define ADC4_Channel_03_PB12 ((uint8_t)0x03)
  377. #define ADC4_Channel_04_PB14 ((uint8_t)0x04)
  378. #define ADC4_Channel_05_PB15 ((uint8_t)0x05)
  379. #define ADC4_Channel_06_PE8 ((uint8_t)0x06)
  380. #define ADC4_Channel_07_PD10 ((uint8_t)0x07)
  381. #define ADC4_Channel_08_PD11 ((uint8_t)0x08)
  382. #define ADC4_Channel_09_PD12 ((uint8_t)0x09)
  383. #define ADC4_Channel_10_PD13 ((uint8_t)0x0A)
  384. #define ADC4_Channel_11_PD14 ((uint8_t)0x0B)
  385. #define ADC4_Channel_12_PD8 ((uint8_t)0x0C)
  386. #define ADC4_Channel_13_PD9 ((uint8_t)0x0D)
  387. #define ADC_CH_0 ((uint8_t)0x00)
  388. #define ADC_CH_1 ((uint8_t)0x01)
  389. #define ADC_CH_2 ((uint8_t)0x02)
  390. #define ADC_CH_3 ((uint8_t)0x03)
  391. #define ADC_CH_4 ((uint8_t)0x04)
  392. #define ADC_CH_5 ((uint8_t)0x05)
  393. #define ADC_CH_6 ((uint8_t)0x06)
  394. #define ADC_CH_7 ((uint8_t)0x07)
  395. #define ADC_CH_8 ((uint8_t)0x08)
  396. #define ADC_CH_9 ((uint8_t)0x09)
  397. #define ADC_CH_10 ((uint8_t)0x0A)
  398. #define ADC_CH_11 ((uint8_t)0x0B)
  399. #define ADC_CH_12 ((uint8_t)0x0C)
  400. #define ADC_CH_13 ((uint8_t)0x0D)
  401. #define ADC_CH_14 ((uint8_t)0x0E)
  402. #define ADC_CH_15 ((uint8_t)0x0F)
  403. #define ADC_CH_16 ((uint8_t)0x10)
  404. #define ADC_CH_17 ((uint8_t)0x11)
  405. #define ADC_CH_18 ((uint8_t)0x12)
  406. /**
  407. * @}
  408. */
  409. /**@addtogroup ADC_dif_sel_ch_definition
  410. * @{
  411. */
  412. #define ADC_DIFSEL_CHS_MASK ((uint32_t)0x0007FFFE)
  413. #define ADC_DIFSEL_CHS_1 ((uint32_t)0x00000002)
  414. #define ADC_DIFSEL_CHS_2 ((uint32_t)0x00000004)
  415. #define ADC_DIFSEL_CHS_3 ((uint32_t)0x00000008)
  416. #define ADC_DIFSEL_CHS_4 ((uint32_t)0x00000010)
  417. #define ADC_DIFSEL_CHS_5 ((uint32_t)0x00000020)
  418. #define ADC_DIFSEL_CHS_6 ((uint32_t)0x00000040)
  419. #define ADC_DIFSEL_CHS_7 ((uint32_t)0x00000080)
  420. #define ADC_DIFSEL_CHS_8 ((uint32_t)0x00000100)
  421. #define ADC_DIFSEL_CHS_9 ((uint32_t)0x00000200)
  422. #define ADC_DIFSEL_CHS_10 ((uint32_t)0x00000400)
  423. #define ADC_DIFSEL_CHS_11 ((uint32_t)0x00000800)
  424. #define ADC_DIFSEL_CHS_12 ((uint32_t)0x00001000)
  425. #define ADC_DIFSEL_CHS_13 ((uint32_t)0x00002000)
  426. #define ADC_DIFSEL_CHS_14 ((uint32_t)0x00004000)
  427. #define ADC_DIFSEL_CHS_15 ((uint32_t)0x00008000)
  428. #define ADC_DIFSEL_CHS_16 ((uint32_t)0x00010000)
  429. #define ADC_DIFSEL_CHS_17 ((uint32_t)0x00020000)
  430. #define ADC_DIFSEL_CHS_18 ((uint32_t)0x00040000)
  431. /**
  432. * @}
  433. */
  434. /**@addtogroup ADC_calfact_definition
  435. * @{
  436. */
  437. #define ADC_CALFACT_CALFACTD_MSK ((uint32_t)0x3FL << 16)
  438. #define ADC_CALFACT_CALFACTS_MSK ((uint32_t)0x3FL << 0)
  439. /**
  440. * @}
  441. */
  442. /**@addtogroup ADC_ctrl3_definition
  443. * @{
  444. */
  445. #define ADC_CTRL3_VABTMEN_MSK ((uint32_t)0x01L << 11)
  446. #define ADC_CTRL3_DPWMOD_MSK ((uint32_t)0x01L << 10)
  447. #define ADC_CTRL3_JENDCAIEN_MSK ((uint32_t)0x01L << 9)
  448. #define ADC_CTRL3_ENDCAIEN_MSK ((uint32_t)0x01L << 8)
  449. #define ADC_CTRL3_BPCAL_MSK ((uint32_t)0x01L << 7)
  450. #define ADC_CTRL3_PDRDY_MSK ((uint32_t)0x01L << 6)
  451. #define ADC_CTRL3_RDY_MSK ((uint32_t)0x01L << 5)
  452. #define ADC_CTRL3_CKMOD_MSK ((uint32_t)0x01L << 4)
  453. #define ADC_CTRL3_CALALD_MSK ((uint32_t)0x01L << 3)
  454. #define ADC_CTRL3_CALDIF_MSK ((uint32_t)0x01L << 2)
  455. #define ADC_CTRL3_RES_MSK ((uint32_t)0x03L << 0)
  456. /**
  457. * @}
  458. */
  459. #define ADC_CLOCK_PLL ((uint32_t)ADC_CTRL3_CKMOD_MSK)
  460. #define ADC_CLOCK_AHB ((uint32_t)(~ADC_CTRL3_CKMOD_MSK))
  461. /**@addtogroup ADC_sampt3_definition
  462. * @{
  463. */
  464. #define ADC_SAMPT3_SAMPSEL_MSK ((uint32_t)0x01L << 3)
  465. /**
  466. * @}
  467. */
  468. typedef enum
  469. {
  470. ADC_CTRL3_CKMOD_AHB = 0,
  471. ADC_CTRL3_CKMOD_PLL = 1,
  472. } ADC_CTRL3_CKMOD;
  473. typedef enum
  474. {
  475. ADC_CTRL3_RES_12BIT = 3,
  476. ADC_CTRL3_RES_10BIT = 2,
  477. ADC_CTRL3_RES_8BIT = 1,
  478. ADC_CTRL3_RES_6BIT = 0,
  479. } ADC_CTRL3_RES;
  480. typedef struct
  481. {
  482. FunctionalState VbatMinitEn;
  483. FunctionalState DeepPowerModEn;
  484. FunctionalState JendcIntEn;
  485. FunctionalState EndcIntEn;
  486. ADC_CTRL3_CKMOD ClkMode;
  487. FunctionalState CalAtuoLoadEn;
  488. bool DifModCal;
  489. ADC_CTRL3_RES ResBit;
  490. bool SampSecondStyle;
  491. } ADC_InitTypeEx;
  492. /**
  493. * @}
  494. */
  495. /*ADC_SAMPT3 only have samp time and smp18[2:0],samp18 is refint ch, change to row function*/
  496. /*ADC_IPTST reseverd register ,not to do it*/
  497. /**@addtogroup ADC_bit_num_definition
  498. * @{
  499. */
  500. #define ADC_RST_BIT_12 ((uint32_t)0x03)
  501. #define ADC_RST_BIT_10 ((uint32_t)0x02)
  502. #define ADC_RST_BIT_8 ((uint32_t)0x01)
  503. #define ADC_RESULT_BIT_6 ((uint32_t)0x00)
  504. /**
  505. * @}
  506. */
  507. /** @addtogroup ADC_flags_ex_definition
  508. * @{
  509. */
  510. #define ADC_FLAG_RDY ((uint8_t)0x20)
  511. #define ADC_FLAG_PD_RDY ((uint8_t)0x40)
  512. #define IS_ADC_GET_READY(FLAG) (((FLAG) == ADC_FLAG_RDY) || ((FLAG) == ADC_FLAG_PD_RDY)
  513. /**
  514. * @}
  515. */
  516. /**
  517. * @}
  518. */
  519. /** @addtogroup ADC_Exported_Functions
  520. * @{
  521. */
  522. void ADC_DeInit(ADC_Module* ADCx);
  523. void ADC_Init(ADC_Module* ADCx, ADC_InitType* ADC_InitStruct);
  524. void ADC_InitStruct(ADC_InitType* ADC_InitStruct);
  525. void ADC_Enable(ADC_Module* ADCx, FunctionalState Cmd);
  526. void ADC_EnableDMA(ADC_Module* ADCx, FunctionalState Cmd);
  527. void ADC_ConfigInt(ADC_Module* ADCx, uint16_t ADC_IT, FunctionalState Cmd);
  528. void ADC_StartCalibration(ADC_Module* ADCx);
  529. FlagStatus ADC_GetCalibrationStatus(ADC_Module* ADCx);
  530. void ADC_EnableSoftwareStartConv(ADC_Module* ADCx, FunctionalState Cmd);
  531. FlagStatus ADC_GetSoftwareStartConvStatus(ADC_Module* ADCx);
  532. void ADC_ConfigDiscModeChannelCount(ADC_Module* ADCx, uint8_t Number);
  533. void ADC_EnableDiscMode(ADC_Module* ADCx, FunctionalState Cmd);
  534. void ADC_ConfigRegularChannel(ADC_Module* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  535. void ADC_EnableExternalTrigConv(ADC_Module* ADCx, FunctionalState Cmd);
  536. uint16_t ADC_GetDat(ADC_Module* ADCx);
  537. uint32_t ADC_GetDualModeConversionDat(ADC_Module* ADCx);
  538. void ADC_EnableAutoInjectedConv(ADC_Module* ADCx, FunctionalState Cmd);
  539. void ADC_EnableInjectedDiscMode(ADC_Module* ADCx, FunctionalState Cmd);
  540. void ADC_ConfigExternalTrigInjectedConv(ADC_Module* ADCx, uint32_t ADC_ExternalTrigInjecConv);
  541. void ADC_EnableExternalTrigInjectedConv(ADC_Module* ADCx, FunctionalState Cmd);
  542. void ADC_EnableSoftwareStartInjectedConv(ADC_Module* ADCx, FunctionalState Cmd);
  543. FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_Module* ADCx);
  544. void ADC_ConfigInjectedChannel(ADC_Module* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  545. void ADC_ConfigInjectedSequencerLength(ADC_Module* ADCx, uint8_t Length);
  546. void ADC_SetInjectedOffsetDat(ADC_Module* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
  547. uint16_t ADC_GetInjectedConversionDat(ADC_Module* ADCx, uint8_t ADC_InjectedChannel);
  548. void ADC_ConfigAnalogWatchdogWorkChannelType(ADC_Module* ADCx, uint32_t ADC_AnalogWatchdog);
  549. void ADC_ConfigAnalogWatchdogThresholds(ADC_Module* ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
  550. void ADC_ConfigAnalogWatchdogSingleChannel(ADC_Module* ADCx, uint8_t ADC_Channel);
  551. void ADC_EnableTempSensorVrefint(FunctionalState Cmd);
  552. FlagStatus ADC_GetFlagStatus(ADC_Module* ADCx, uint8_t ADC_FLAG);
  553. void ADC_ClearFlag(ADC_Module* ADCx, uint8_t ADC_FLAG);
  554. INTStatus ADC_GetIntStatus(ADC_Module* ADCx, uint16_t ADC_IT);
  555. void ADC_ClearIntPendingBit(ADC_Module* ADCx, uint16_t ADC_IT);
  556. void ADC_InitEx(ADC_Module* ADCx, ADC_InitTypeEx* ADC_InitStructEx);
  557. void ADC_SetDifChs(ADC_Module* ADCx,uint32_t DifChs);
  558. FlagStatus ADC_GetFlagStatusNew(ADC_Module* ADCx, uint8_t ADC_FLAG_NEW);
  559. void ADC_SetBypassCalibration(ADC_Module* ADCx, FunctionalState en);
  560. void ADC_SetConvResultBitNum(ADC_Module* ADCx, uint32_t ResultBitNum);
  561. void ADC_ConfigClk(ADC_CTRL3_CKMOD ADC_ClkMode, uint32_t RCC_ADCHCLKPrescaler);
  562. /**
  563. * @}
  564. */
  565. #ifdef __cplusplus
  566. }
  567. #endif
  568. #endif /*__N32G45X_ADC_H__ */
  569. /**
  570. * @}
  571. */
  572. /**
  573. * @}
  574. */