nu_acmp.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. /**************************************************************************//**
  2. * @file ACMP.h
  3. * @version V1.00
  4. * @brief M480 Series ACMP Driver Header File
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
  8. ******************************************************************************/
  9. #ifndef __NU_ACMP_H__
  10. #define __NU_ACMP_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup ACMP_Driver ACMP Driver
  19. @{
  20. */
  21. /** @addtogroup ACMP_EXPORTED_CONSTANTS ACMP Exported Constants
  22. @{
  23. */
  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* ACMP_CTL constant definitions */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. #define ACMP_CTL_FILTSEL_OFF (0UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for filter function disabled. \hideinitializer */
  28. #define ACMP_CTL_FILTSEL_1PCLK (1UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 1 PCLK filter count. \hideinitializer */
  29. #define ACMP_CTL_FILTSEL_2PCLK (2UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 2 PCLK filter count. \hideinitializer */
  30. #define ACMP_CTL_FILTSEL_4PCLK (3UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 4 PCLK filter count. \hideinitializer */
  31. #define ACMP_CTL_FILTSEL_8PCLK (4UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 8 PCLK filter count. \hideinitializer */
  32. #define ACMP_CTL_FILTSEL_16PCLK (5UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 16 PCLK filter count. \hideinitializer */
  33. #define ACMP_CTL_FILTSEL_32PCLK (6UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 32 PCLK filter count. \hideinitializer */
  34. #define ACMP_CTL_FILTSEL_64PCLK (7UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 64 PCLK filter count. \hideinitializer */
  35. #define ACMP_CTL_INTPOL_RF (0UL << ACMP_CTL_INTPOL_Pos) /*!< ACMP_CTL setting for selecting rising edge and falling edge as interrupt condition. \hideinitializer */
  36. #define ACMP_CTL_INTPOL_R (1UL << ACMP_CTL_INTPOL_Pos) /*!< ACMP_CTL setting for selecting rising edge as interrupt condition. \hideinitializer */
  37. #define ACMP_CTL_INTPOL_F (2UL << ACMP_CTL_INTPOL_Pos) /*!< ACMP_CTL setting for selecting falling edge as interrupt condition. \hideinitializer */
  38. #define ACMP_CTL_POSSEL_P0 (0UL << ACMP_CTL_POSSEL_Pos) /*!< ACMP_CTL setting for selecting ACMPx_P0 pin as the source of ACMP V+. \hideinitializer */
  39. #define ACMP_CTL_POSSEL_P1 (1UL << ACMP_CTL_POSSEL_Pos) /*!< ACMP_CTL setting for selecting ACMPx_P1 pin as the source of ACMP V+. \hideinitializer */
  40. #define ACMP_CTL_POSSEL_P2 (2UL << ACMP_CTL_POSSEL_Pos) /*!< ACMP_CTL setting for selecting ACMPx_P2 pin as the source of ACMP V+. \hideinitializer */
  41. #define ACMP_CTL_POSSEL_P3 (3UL << ACMP_CTL_POSSEL_Pos) /*!< ACMP_CTL setting for selecting ACMPx_P3 pin as the source of ACMP V+. \hideinitializer */
  42. #define ACMP_CTL_NEGSEL_PIN (0UL << ACMP_CTL_NEGSEL_Pos) /*!< ACMP_CTL setting for selecting the voltage of ACMP negative input pin as the source of ACMP V-. \hideinitializer */
  43. #define ACMP_CTL_NEGSEL_CRV (1UL << ACMP_CTL_NEGSEL_Pos) /*!< ACMP_CTL setting for selecting internal comparator reference voltage as the source of ACMP V-. \hideinitializer */
  44. #define ACMP_CTL_NEGSEL_VBG (2UL << ACMP_CTL_NEGSEL_Pos) /*!< ACMP_CTL setting for selecting internal Band-gap voltage as the source of ACMP V-. \hideinitializer */
  45. #define ACMP_CTL_NEGSEL_DAC (3UL << ACMP_CTL_NEGSEL_Pos) /*!< ACMP_CTL setting for selecting DAC output voltage as the source of ACMP V-. \hideinitializer */
  46. #define ACMP_CTL_HYSTERESIS_30MV (3UL << ACMP_CTL_HYSSEL_Pos) /*!< ACMP_CTL setting for enabling the hysteresis function at 30mV. \hideinitializer */
  47. #define ACMP_CTL_HYSTERESIS_20MV (2UL << ACMP_CTL_HYSSEL_Pos) /*!< ACMP_CTL setting for enabling the hysteresis function at 20mV. \hideinitializer */
  48. #define ACMP_CTL_HYSTERESIS_10MV (1UL << ACMP_CTL_HYSSEL_Pos) /*!< ACMP_CTL setting for enabling the hysteresis function at 10mV. \hideinitializer */
  49. #define ACMP_CTL_HYSTERESIS_DISABLE (0UL << ACMP_CTL_HYSSEL_Pos) /*!< ACMP_CTL setting for disabling the hysteresis function. \hideinitializer */
  50. /*---------------------------------------------------------------------------------------------------------*/
  51. /* ACMP_VREF constant definitions */
  52. /*---------------------------------------------------------------------------------------------------------*/
  53. #define ACMP_VREF_CRV0SSEL_VDDA (0UL << ACMP_VREF_CRV0SSEL_Pos) /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV0 source voltage \hideinitializer */
  54. #define ACMP_VREF_CRV0SSEL_INTVREF (1UL << ACMP_VREF_CRV0SSEL_Pos) /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV0 source voltage \hideinitializer */
  55. #define ACMP_VREF_CRV1SSEL_VDDA (0UL << ACMP_VREF_CRV1SSEL_Pos) /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV1 source voltage \hideinitializer */
  56. #define ACMP_VREF_CRV1SSEL_INTVREF (1UL << ACMP_VREF_CRV1SSEL_Pos) /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV1 source voltage \hideinitializer */
  57. #define ACMP_VREF_CRV2SSEL_VDDA (0UL << ACMP_VREF_CRV2SSEL_Pos) /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV2 source voltage \hideinitializer */
  58. #define ACMP_VREF_CRV2SSEL_INTVREF (1UL << ACMP_VREF_CRV2SSEL_Pos) /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV2 source voltage \hideinitializer */
  59. #define ACMP_VREF_CRV3SSEL_VDDA (0UL << ACMP_VREF_CRV3SSEL_Pos) /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV3 source voltage \hideinitializer */
  60. #define ACMP_VREF_CRV3SSEL_INTVREF (1UL << ACMP_VREF_CRV3SSEL_Pos) /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV3 source voltage \hideinitializer */
  61. /*@}*/ /* end of group ACMP_EXPORTED_CONSTANTS */
  62. /** @addtogroup ACMP_EXPORTED_FUNCTIONS ACMP Exported Functions
  63. @{
  64. */
  65. /*---------------------------------------------------------------------------------------------------------*/
  66. /* Define Macros and functions */
  67. /*---------------------------------------------------------------------------------------------------------*/
  68. /**
  69. * @brief This macro is used to enable output inverse function
  70. * @param[in] acmp The pointer of the specified ACMP module
  71. * @param[in] u32ChNum The ACMP number
  72. * @return None
  73. * @details This macro will set ACMPOINV bit of ACMP_CTL register to enable output inverse function.
  74. * \hideinitializer
  75. */
  76. #define ACMP_ENABLE_OUTPUT_INVERSE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_ACMPOINV_Msk)
  77. /**
  78. * @brief This macro is used to disable output inverse function
  79. * @param[in] acmp The pointer of the specified ACMP module
  80. * @param[in] u32ChNum The ACMP number
  81. * @return None
  82. * @details This macro will clear ACMPOINV bit of ACMP_CTL register to disable output inverse function.
  83. * \hideinitializer
  84. */
  85. #define ACMP_DISABLE_OUTPUT_INVERSE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_ACMPOINV_Msk)
  86. /**
  87. * @brief This macro is used to select ACMP negative input source
  88. * @param[in] acmp The pointer of the specified ACMP module
  89. * @param[in] u32ChNum The ACMP number
  90. * @param[in] u32Src is comparator negative input selection. Including:
  91. * - \ref ACMP_CTL_NEGSEL_PIN
  92. * - \ref ACMP_CTL_NEGSEL_CRV
  93. * - \ref ACMP_CTL_NEGSEL_VBG
  94. * - \ref ACMP_CTL_NEGSEL_DAC
  95. * @return None
  96. * @details This macro will set NEGSEL (ACMP_CTL[5:4]) to determine the source of negative input.
  97. * \hideinitializer
  98. */
  99. #define ACMP_SET_NEG_SRC(acmp, u32ChNum, u32Src) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_NEGSEL_Msk) | (u32Src))
  100. /**
  101. * @brief This macro is used to enable hysteresis function and set hysteresis to 30mV
  102. * @param[in] acmp The pointer of the specified ACMP module
  103. * @param[in] u32ChNum The ACMP number
  104. * @return None
  105. * \hideinitializer
  106. */
  107. #define ACMP_ENABLE_HYSTERESIS(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_HYSTERESIS_30MV)
  108. /**
  109. * @brief This macro is used to disable hysteresis function
  110. * @param[in] acmp The pointer of the specified ACMP module
  111. * @param[in] u32ChNum The ACMP number
  112. * @return None
  113. * @details This macro will clear HYSEL bits of ACMP_CTL register to disable hysteresis function.
  114. * \hideinitializer
  115. */
  116. #define ACMP_DISABLE_HYSTERESIS(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_HYSSEL_Msk)
  117. /**
  118. * @brief This macro is used to select hysteresis level
  119. * @param[in] acmp The pointer of the specified ACMP module
  120. * @param[in] u32ChNum The ACMP number
  121. * @param[in] u32HysSel The hysteresis function option. Including:
  122. * - \ref ACMP_CTL_HYSTERESIS_30MV
  123. * - \ref ACMP_CTL_HYSTERESIS_20MV
  124. * - \ref ACMP_CTL_HYSTERESIS_10MV
  125. * - \ref ACMP_CTL_HYSTERESIS_DISABLE
  126. * \hideinitializer
  127. * @return None
  128. */
  129. #define ACMP_CONFIG_HYSTERESIS(acmp, u32ChNum, u32HysSel) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_HYSSEL_Msk) | (u32HysSel))
  130. /**
  131. * @brief This macro is used to enable interrupt
  132. * @param[in] acmp The pointer of the specified ACMP module
  133. * @param[in] u32ChNum The ACMP number
  134. * @return None
  135. * @details This macro will set ACMPIE bit of ACMP_CTL register to enable interrupt function.
  136. * If wake-up function is enabled, the wake-up interrupt will be enabled as well.
  137. * \hideinitializer
  138. */
  139. #define ACMP_ENABLE_INT(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_ACMPIE_Msk)
  140. /**
  141. * @brief This macro is used to disable interrupt
  142. * @param[in] acmp The pointer of the specified ACMP module
  143. * @param[in] u32ChNum The ACMP number
  144. * @return None
  145. * @details This macro will clear ACMPIE bit of ACMP_CTL register to disable interrupt function.
  146. * \hideinitializer
  147. */
  148. #define ACMP_DISABLE_INT(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_ACMPIE_Msk)
  149. /**
  150. * @brief This macro is used to enable ACMP
  151. * @param[in] acmp The pointer of the specified ACMP module
  152. * @param[in] u32ChNum The ACMP number
  153. * @return None
  154. * @details This macro will set ACMPEN bit of ACMP_CTL register to enable analog comparator.
  155. * \hideinitializer
  156. */
  157. #define ACMP_ENABLE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_ACMPEN_Msk)
  158. /**
  159. * @brief This macro is used to disable ACMP
  160. * @param[in] acmp The pointer of the specified ACMP module
  161. * @param[in] u32ChNum The ACMP number
  162. * @return None
  163. * @details This macro will clear ACMPEN bit of ACMP_CTL register to disable analog comparator.
  164. * \hideinitializer
  165. */
  166. #define ACMP_DISABLE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_ACMPEN_Msk)
  167. /**
  168. * @brief This macro is used to get ACMP output value
  169. * @param[in] acmp The pointer of the specified ACMP module
  170. * @param[in] u32ChNum The ACMP number
  171. * @return ACMP output value
  172. * @details This macro will return the ACMP output value.
  173. * \hideinitializer
  174. */
  175. #define ACMP_GET_OUTPUT(acmp, u32ChNum) (((acmp)->STATUS & (ACMP_STATUS_ACMPO0_Msk<<((u32ChNum))))?1:0)
  176. /**
  177. * @brief This macro is used to get ACMP interrupt flag
  178. * @param[in] acmp The pointer of the specified ACMP module
  179. * @param[in] u32ChNum The ACMP number
  180. * @return ACMP interrupt occurred (1) or not (0)
  181. * @details This macro will return the ACMP interrupt flag.
  182. * \hideinitializer
  183. */
  184. #define ACMP_GET_INT_FLAG(acmp, u32ChNum) (((acmp)->STATUS & (ACMP_STATUS_ACMPIF0_Msk<<((u32ChNum))))?1:0)
  185. /**
  186. * @brief This macro is used to clear ACMP interrupt flag
  187. * @param[in] acmp The pointer of the specified ACMP module
  188. * @param[in] u32ChNum The ACMP number
  189. * @return None
  190. * @details This macro will write 1 to ACMPIFn bit of ACMP_STATUS register to clear interrupt flag.
  191. * \hideinitializer
  192. */
  193. #define ACMP_CLR_INT_FLAG(acmp, u32ChNum) ((acmp)->STATUS = (ACMP_STATUS_ACMPIF0_Msk<<((u32ChNum))))
  194. /**
  195. * @brief This macro is used to clear ACMP wake-up interrupt flag
  196. * @param[in] acmp The pointer of the specified ACMP module
  197. * @param[in] u32ChNum The ACMP number
  198. * @return None
  199. * @details This macro will write 1 to WKIFn bit of ACMP_STATUS register to clear interrupt flag.
  200. * \hideinitializer
  201. */
  202. #define ACMP_CLR_WAKEUP_INT_FLAG(acmp, u32ChNum) ((acmp)->STATUS = (ACMP_STATUS_WKIF0_Msk<<((u32ChNum))))
  203. /**
  204. * @brief This macro is used to enable ACMP wake-up function
  205. * @param[in] acmp The pointer of the specified ACMP module
  206. * @param[in] u32ChNum The ACMP number
  207. * @return None
  208. * @details This macro will set WKEN (ACMP_CTL[16]) to enable ACMP wake-up function.
  209. * \hideinitializer
  210. */
  211. #define ACMP_ENABLE_WAKEUP(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_WKEN_Msk)
  212. /**
  213. * @brief This macro is used to disable ACMP wake-up function
  214. * @param[in] acmp The pointer of the specified ACMP module
  215. * @param[in] u32ChNum The ACMP number
  216. * @return None
  217. * @details This macro will clear WKEN (ACMP_CTL[16]) to disable ACMP wake-up function.
  218. * \hideinitializer
  219. */
  220. #define ACMP_DISABLE_WAKEUP(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_WKEN_Msk)
  221. /**
  222. * @brief This macro is used to select ACMP positive input pin
  223. * @param[in] acmp The pointer of the specified ACMP module
  224. * @param[in] u32ChNum The ACMP number
  225. * @param[in] u32Pin Comparator positive pin selection. Including:
  226. * - \ref ACMP_CTL_POSSEL_P0
  227. * - \ref ACMP_CTL_POSSEL_P1
  228. * - \ref ACMP_CTL_POSSEL_P2
  229. * - \ref ACMP_CTL_POSSEL_P3
  230. * @return None
  231. * @details This macro will set POSSEL (ACMP_CTL[7:6]) to determine the comparator positive input pin.
  232. * \hideinitializer
  233. */
  234. #define ACMP_SELECT_P(acmp, u32ChNum, u32Pin) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_POSSEL_Msk) | (u32Pin))
  235. /**
  236. * @brief This macro is used to enable ACMP filter function
  237. * @param[in] acmp The pointer of the specified ACMP module
  238. * @param[in] u32ChNum The ACMP number
  239. * @return None
  240. * @details This macro will set OUTSEL (ACMP_CTL[12]) to enable output filter function.
  241. * \hideinitializer
  242. */
  243. #define ACMP_ENABLE_FILTER(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_OUTSEL_Msk)
  244. /**
  245. * @brief This macro is used to disable ACMP filter function
  246. * @param[in] acmp The pointer of the specified ACMP module
  247. * @param[in] u32ChNum The ACMP number
  248. * @return None
  249. * @details This macro will clear OUTSEL (ACMP_CTL[12]) to disable output filter function.
  250. * \hideinitializer
  251. */
  252. #define ACMP_DISABLE_FILTER(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_OUTSEL_Msk)
  253. /**
  254. * @brief This macro is used to set ACMP filter function
  255. * @param[in] acmp The pointer of the specified ACMP module
  256. * @param[in] u32ChNum The ACMP number
  257. * @param[in] u32Cnt is comparator filter count setting.
  258. * - \ref ACMP_CTL_FILTSEL_OFF
  259. * - \ref ACMP_CTL_FILTSEL_1PCLK
  260. * - \ref ACMP_CTL_FILTSEL_2PCLK
  261. * - \ref ACMP_CTL_FILTSEL_4PCLK
  262. * - \ref ACMP_CTL_FILTSEL_8PCLK
  263. * - \ref ACMP_CTL_FILTSEL_16PCLK
  264. * - \ref ACMP_CTL_FILTSEL_32PCLK
  265. * - \ref ACMP_CTL_FILTSEL_64PCLK
  266. * @return None
  267. * @details When ACMP output filter function is enabled, the output sampling count is determined by FILTSEL (ACMP_CTL[15:13]).
  268. * \hideinitializer
  269. */
  270. #define ACMP_SET_FILTER(acmp, u32ChNum, u32Cnt) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_FILTSEL_Msk) | (u32Cnt))
  271. /**
  272. * @brief This macro is used to select comparator reference voltage
  273. * @param[in] acmp The pointer of the specified ACMP module
  274. * @param[in] u32Level The comparator reference voltage setting.
  275. * The formula is:
  276. * comparator reference voltage = CRV source voltage x (1/6 + u32Level/24)
  277. * The range of u32Level is 0 ~ 15.
  278. * @return None
  279. * @details When CRV is selected as ACMP negative input source, the CRV level is determined by CRVCTL (ACMP_VREF[3:0]).
  280. * \hideinitializer
  281. */
  282. #define ACMP_CRV_SEL(acmp, u32Level) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SEL_Msk) | ((u32Level)<<ACMP_VREF_CRV0SEL_Pos))
  283. #define ACMP_CRV0_SEL(acmp, u32Level) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SEL_Msk) | ((u32Level)<<ACMP_VREF_CRV0SEL_Pos))
  284. #define ACMP_CRV1_SEL(acmp, u32Level) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV1SEL_Msk) | ((u32Level)<<ACMP_VREF_CRV1SEL_Pos))
  285. /**
  286. * @brief This macro is used to enable comparator reference voltage
  287. * @param[in] acmp The pointer of the specified ACMP module
  288. * @return None
  289. * @details CRV must be enabled before using it.
  290. * \hideinitializer
  291. */
  292. #define ACMP_ENABLE_CRV0(acmp) ((acmp)->VREF |= ACMP_VREF_CRV0EN_Msk)
  293. #define ACMP_ENABLE_CRV1(acmp) ((acmp)->VREF |= ACMP_VREF_CRV1EN_Msk)
  294. /**
  295. * @brief This macro is used to disable comparator reference voltage
  296. * @param[in] acmp The pointer of the specified ACMP module
  297. * @return None
  298. * @details Disable CRV.
  299. * \hideinitializer
  300. */
  301. #define ACMP_DISABLE_CRV0(acmp) ((acmp)->VREF &= ~ACMP_VREF_CRV0EN_Msk)
  302. #define ACMP_DISABLE_CRV1(acmp) ((acmp)->VREF &= ~ACMP_VREF_CRV1EN_Msk)
  303. /**
  304. * @brief This macro is used to select the source of CRV
  305. * @param[in] acmp The pointer of the specified ACMP module
  306. * @param[in] u32Src is the source of CRV. Including:
  307. * - \ref ACMP_VREF_CRV0SSEL_VDDA
  308. * - \ref ACMP_VREF_CRV0SSEL_INTVREF
  309. * - \ref ACMP_VREF_CRV1SSEL_VDDA
  310. * - \ref ACMP_VREF_CRV1SSEL_INTVREF
  311. * - \ref ACMP_VREF_CRV2SSEL_VDDA
  312. * - \ref ACMP_VREF_CRV2SSEL_INTVREF
  313. * - \ref ACMP_VREF_CRV3SSEL_VDDA
  314. * - \ref ACMP_VREF_CRV3SSEL_INTVREF
  315. * @return None
  316. * @details The source of CRV can be VDDA or internal reference voltage. The internal reference voltage level is determined by SYS_VREFCTL register.
  317. * \hideinitializer
  318. */
  319. #define ACMP_SELECT_CRV_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SSEL_Msk) | (u32Src))
  320. #define ACMP_SELECT_CRV0_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SSEL_Msk) | (u32Src))
  321. #define ACMP_SELECT_CRV1_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV1SSEL_Msk) | (u32Src))
  322. #define ACMP_SELECT_CRV2_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SSEL_Msk) | (u32Src))
  323. #define ACMP_SELECT_CRV3_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV1SSEL_Msk) | (u32Src))
  324. /**
  325. * @brief This macro is used to select ACMP interrupt condition
  326. * @param[in] acmp The pointer of the specified ACMP module
  327. * @param[in] u32ChNum The ACMP number
  328. * @param[in] u32Cond Comparator interrupt condition selection. Including:
  329. * - \ref ACMP_CTL_INTPOL_RF
  330. * - \ref ACMP_CTL_INTPOL_R
  331. * - \ref ACMP_CTL_INTPOL_F
  332. * @return None
  333. * @details The ACMP output interrupt condition can be rising edge, falling edge or any edge.
  334. * \hideinitializer
  335. */
  336. #define ACMP_SELECT_INT_COND(acmp, u32ChNum, u32Cond) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_INTPOL_Msk) | (u32Cond))
  337. /**
  338. * @brief This macro is used to enable ACMP window latch mode
  339. * @param[in] acmp The pointer of the specified ACMP module
  340. * @param[in] u32ChNum The ACMP number
  341. * @return None
  342. * @details This macro will set WLATEN (ACMP_CTL[17]) to enable ACMP window latch mode.
  343. * When ACMP0/1_WLAT pin is at high level, ACMPO0/1 passes through window latch
  344. * block; when ACMP0/1_WLAT pin is at low level, the output of window latch block,
  345. * WLATOUT, is frozen.
  346. * \hideinitializer
  347. */
  348. #define ACMP_ENABLE_WINDOW_LATCH(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_WLATEN_Msk)
  349. /**
  350. * @brief This macro is used to disable ACMP window latch mode
  351. * @param[in] acmp The pointer of the specified ACMP module
  352. * @param[in] u32ChNum The ACMP number
  353. * @return None
  354. * @details This macro will clear WLATEN (ACMP_CTL[17]) to disable ACMP window latch mode.
  355. * \hideinitializer
  356. */
  357. #define ACMP_DISABLE_WINDOW_LATCH(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_WLATEN_Msk)
  358. /**
  359. * @brief This macro is used to enable ACMP window compare mode
  360. * @param[in] acmp The pointer of the specified ACMP module
  361. * @param[in] u32ChNum The ACMP number
  362. * @return None
  363. * @details This macro will set WCMPSEL (ACMP_CTL[18]) to enable ACMP window compare mode.
  364. * When window compare mode is enabled, user can connect the specific analog voltage
  365. * source to either the positive inputs of both comparators or the negative inputs of
  366. * both comparators. The upper bound and lower bound of the designated range are
  367. * determined by the voltages applied to the other inputs of both comparators. If the
  368. * output of a comparator is low and the other comparator outputs high, which means two
  369. * comparators implies the upper and lower bound. User can directly monitor a specific
  370. * analog voltage source via ACMPWO (ACMP_STATUS[16]).
  371. * \hideinitializer
  372. */
  373. #define ACMP_ENABLE_WINDOW_COMPARE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_WCMPSEL_Msk)
  374. /**
  375. * @brief This macro is used to disable ACMP window compare mode
  376. * @param[in] acmp The pointer of the specified ACMP module
  377. * @param[in] u32ChNum The ACMP number
  378. * @return None
  379. * @details This macro will clear WCMPSEL (ACMP_CTL[18]) to disable ACMP window compare mode.
  380. * \hideinitializer
  381. */
  382. #define ACMP_DISABLE_WINDOW_COMPARE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_WCMPSEL_Msk)
  383. /* Function prototype declaration */
  384. void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysSel);
  385. void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum);
  386. /*@}*/ /* end of group ACMP_EXPORTED_FUNCTIONS */
  387. /*@}*/ /* end of group ACMP_Driver */
  388. /*@}*/ /* end of group Standard_Driver */
  389. #ifdef __cplusplus
  390. }
  391. #endif
  392. #endif /* __NU_ACMP_H__ */
  393. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/