acmp.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**************************************************************************//**
  2. * @file acmp.h
  3. * @version V3.00
  4. * $Revision: 6 $
  5. * $Date: 1/28/14 11:32a $
  6. * @brief M051 series Analog Comparator(ACMP) driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __ACMP_H__
  12. #define __ACMP_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup M051_Device_Driver M051 Device Driver
  18. @{
  19. */
  20. /** @addtogroup M051_ACMP_Driver ACMP Driver
  21. @{
  22. */
  23. /** @addtogroup M051_ACMP_EXPORTED_CONSTANTS ACMP Exported Constants
  24. @{
  25. */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. /* ACMP_CR constant definitions */
  28. /*---------------------------------------------------------------------------------------------------------*/
  29. #define ACMP_CR_OUTPUT_INV (1UL << ACMP_CR_ACMPOINV_Pos) /*!< ACMP_CR setting for ACMP output inverse function. */
  30. #define ACMP_CR_VNEG_BANDGAP (1UL << ACMP_CR_NEGSEL_Pos) /*!< ACMP_CR setting for selecting band-gap voltage as the source of ACMP V-. */
  31. #define ACMP_CR_VNEG_PIN (0UL << ACMP_CR_NEGSEL_Pos) /*!< ACMP_CR setting for selecting the voltage of ACMP negative input pin as the source of ACMP V-. */
  32. #define ACMP_CR_HYSTERESIS_ENABLE (1UL << ACMP_CR_HYSEN_Pos) /*!< ACMP_CR setting for enabling the hysteresis function. */
  33. #define ACMP_CR_HYSTERESIS_DISABLE (0UL << ACMP_CR_HYSEN_Pos) /*!< ACMP_CR setting for disabling the hysteresis function. */
  34. #define ACMP_CR_INT_ENABLE (1UL << ACMP_CR_ACMPIE_Pos) /*!< ACMP_CR setting for enabling the interrupt function. */
  35. #define ACMP_CR_INT_DISABLE (0UL << ACMP_CR_ACMPIE_Pos) /*!< ACMP_CR setting for disabling the interrupt function. */
  36. #define ACMP_CR_ACMP_ENABLE (1UL << ACMP_CR_ACMPEN_Pos) /*!< ACMP_CR setting for enabling the ACMP analog circuit. */
  37. #define ACMP_CR_ACMP_DISABLE (0UL << ACMP_CR_ACMPEN_Pos) /*!< ACMP_CR setting for disabling the ACMP analog circuit. */
  38. /*@}*/ /* end of group M051_ACMP_EXPORTED_CONSTANTS */
  39. /** @addtogroup M051_ACMP_EXPORTED_FUNCTIONS ACMP Exported Functions
  40. @{
  41. */
  42. /**
  43. * @brief This macro is used to enable output inverse
  44. * @param[in] acmp The base address of ACMP module
  45. * @param[in] u32ChNum The ACMP number
  46. * @return None
  47. */
  48. #define ACMP_ENABLE_OUTPUT_INVERSE(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] |= ACMP_CR_ACMPOINV_Msk)
  49. /**
  50. * @brief This macro is used to disable output inverse
  51. * @param[in] acmp The base address of ACMP module
  52. * @param[in] u32ChNum The ACMP number
  53. * @return None
  54. */
  55. #define ACMP_DISABLE_OUTPUT_INVERSE(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] &= ~ACMP_CR_ACMPOINV_Msk)
  56. /**
  57. * @brief This macro is used to select ACMP negative input source
  58. * @param[in] acmp The base address of ACMP module
  59. * @param[in] u32ChNum The ACMP number
  60. * @param[in] u32Src is comparator0 negative input selection. Including :
  61. * - \ref ACMP_CR_VNEG_PIN
  62. * - \ref ACMP_CR_VNEG_BANDGAP
  63. * @return None
  64. */
  65. #define ACMP_SET_NEG_SRC(acmp, u32ChNum, u32Src) ((acmp)->CR[(u32ChNum)%2] = ((acmp)->CR[(u32ChNum)%2] & ~ACMP_CR_NEGSEL_Msk) | (u32Src))
  66. /**
  67. * @brief This macro is used to enable hysteresis function
  68. * @param[in] acmp The base address of ACMP module
  69. * @param[in] u32ChNum The ACMP number
  70. * @return None
  71. */
  72. #define ACMP_ENABLE_HYSTERESIS(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] |= ACMP_CR_HYSEN_Msk)
  73. /**
  74. * @brief This macro is used to disable hysteresis function
  75. * @param[in] acmp The base address of ACMP module
  76. * @param[in] u32ChNum The ACMP number
  77. * @return None
  78. */
  79. #define ACMP_DISABLE_HYSTERESIS(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] &= ~ACMP_CR_HYSEN_Msk)
  80. /**
  81. * @brief This macro is used to enable interrupt
  82. * @param[in] acmp The base address of ACMP module
  83. * @param[in] u32ChNum The ACMP number
  84. * @return None
  85. */
  86. #define ACMP_ENABLE_INT(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] |= ACMP_CR_ACMPIE_Msk)
  87. /**
  88. * @brief This macro is used to disable interrupt
  89. * @param[in] acmp The base address of ACMP module
  90. * @param[in] u32ChNum The ACMP number
  91. * @return None
  92. */
  93. #define ACMP_DISABLE_INT(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] &= ~ACMP_CR_ACMPIE_Msk)
  94. /**
  95. * @brief This macro is used to enable ACMP
  96. * @param[in] acmp The base address of ACMP module
  97. * @param[in] u32ChNum The ACMP number
  98. * @return None
  99. */
  100. #define ACMP_ENABLE(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] |= ACMP_CR_ACMPEN_Msk)
  101. /**
  102. * @brief This macro is used to disable ACMP
  103. * @param[in] acmp The base address of ACMP module
  104. * @param[in] u32ChNum The ACMP number
  105. * @return None
  106. */
  107. #define ACMP_DISABLE(acmp, u32ChNum) ((acmp)->CR[(u32ChNum)%2] &= ~ACMP_CR_ACMPEN_Msk)
  108. /**
  109. * @brief This macro is used to get ACMP output value
  110. * @param[in] acmp The base address of ACMP module
  111. * @param[in] u32ChNum The ACMP number
  112. * @return 1 or 0
  113. */
  114. #define ACMP_GET_OUTPUT(acmp, u32ChNum) (((acmp)->SR & (ACMP_SR_ACMPO0_Msk<<((u32ChNum)%2)))?1:0)
  115. /**
  116. * @brief This macro is used to get ACMP interrupt flag
  117. * @param[in] acmp The base address of ACMP module
  118. * @param[in] u32ChNum The ACMP number
  119. * @return ACMP interrupt occurred or not
  120. */
  121. #define ACMP_GET_INT_FLAG(acmp, u32ChNum) (((acmp)->SR & (ACMP_SR_ACMPF0_Msk<<((u32ChNum)%2)))?1:0)
  122. /**
  123. * @brief This macro is used to clear ACMP interrupt flag
  124. * @param[in] acmp The base address of ACMP module
  125. * @param[in] u32ChNum The ACMP number
  126. * @return None
  127. */
  128. #define ACMP_CLR_INT_FLAG(acmp, u32ChNum) ((acmp)->SR = (ACMP_SR_ACMPF0_Msk<<((u32ChNum)%2)))
  129. void ACMP_Open(ACMP_T *, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysteresisEn);
  130. void ACMP_Close(ACMP_T *, uint32_t u32ChNum);
  131. /*@}*/ /* end of group M051_ACMP_EXPORTED_FUNCTIONS */
  132. /*@}*/ /* end of group M051_ACMP_Driver */
  133. /*@}*/ /* end of group M051_Device_Driver */
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif //__ACMP_H__
  138. /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/