HAL_COMP.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ******************************************************************************
  3. * @file HAL_COMP.h
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief Header file of COMP HAL module.
  7. ******************************************************************************
  8. */
  9. #ifndef __HAL_COMP_H__
  10. #define __HAL_COMP_H__
  11. #include "ACM32Fxx_HAL.h"
  12. #define COMP1 (0x01)
  13. #define COMP2 (0x02)
  14. /**************** Bit definition for COMP_CR1 and COMP_CR2 register **************************/
  15. #define COMP_CR_LOCK (BIT31)
  16. #define COMP_CR_BLANKTIME_POS (29U)
  17. #define COMP_CR_BLANKTIME_MASK (BIT30|BIT29)
  18. #define COMP_CR_CRV_CFG_POS (25U)
  19. #define COMP_CR_CRV_CFG_MASK (BIT28|BIT27|BIT26|BIT25)
  20. #define COMP_CR_CRV_SEL (BIT24)
  21. #define COMP_CR_CRV_EN (BIT23)
  22. #define COMP_CR_WINMODE (BIT22)
  23. #define COMP_CR_WINOUT (BIT21)
  24. #define COMP_CR_POLARITY (BIT20)
  25. #define COMP_CR_FLTEN (BIT19)
  26. #define COMP_CR_FLTTIME_POS (16U)
  27. #define COMP_CR_FLTTIME_MASK (BIT18|BIT17|BIT16)
  28. #define COMP_CR_BLANKSEL_POS (12U)
  29. #define COMP_CR_BLANKSEL_MASK (BIT15|BIT14|BIT13|BIT12)
  30. #define COMP_CR_INPSEL_POS (8U)
  31. #define COMP_CR_INPSEL_MASK (BIT11|BIT10|BIT9|BIT8)
  32. #define COMP_CR_INMSEL_POS (4U)
  33. #define COMP_CR_INMSEL_MASK (BIT7|BIT6|BIT5|BIT4)
  34. #define COMP_CR_HYS_POS (1U)
  35. #define COMP_CR_HYS_MASK (BIT3|BIT2|BIT1)
  36. #define COMP_CR_EN (BIT0)
  37. /**************** Bit definition for COMP_SR register **************************/
  38. #define COMP_SR_VCOUT2_ORG (BIT3)
  39. #define COMP_SR_VCOUT1_ORG (BIT2)
  40. #define COMP_SR_VCOUT2 (BIT1)
  41. #define COMP_SR_VCOUT1 (BIT0)
  42. /**
  43. * @brief COMP Configuration Structure definition
  44. */
  45. typedef struct
  46. {
  47. uint8_t Comparator; /*!< Specify witch comparator be selected */
  48. uint32_t Crv_En;
  49. uint32_t BlankTime;
  50. uint32_t Crv_Sel;
  51. uint32_t Crv_Cfg;
  52. uint32_t WinMode;
  53. uint32_t WinOut;
  54. uint32_t Polarity;
  55. uint32_t FltEn;
  56. uint32_t FltTime;
  57. uint32_t BlankSel;
  58. uint32_t InPSel;
  59. uint32_t InMSel;
  60. uint32_t HYS;
  61. }COMP_InitTypeDef;
  62. /**
  63. * @brief COMP handle Structure definition
  64. */
  65. typedef struct
  66. {
  67. COMP_TypeDef *Instance; /*!< Register base address */
  68. COMP_InitTypeDef Init; /*!< COMP required parameters */
  69. uint8_t OutputLevel_Org; /*!< COMP OutputLevel original */
  70. uint8_t OutputLevel; /*!< COMP OutputLevel with filter */
  71. } COMP_HandleTypeDef;
  72. #define COMP_CR_CRV_EN_DISABLE (0U)
  73. #define COMP_CR_CRV_EN_ENABLE (1U)
  74. #define COMP_CR_CRV_SEL_AVDD (0U)
  75. #define COMP_CR_CRV_SEL_VREF (1U)
  76. #define COMP_CR1_WINMODE_COMP1_INPSEL (0U)
  77. #define COMP_CR1_WINMODE_COMP2_INPSEL (1U)
  78. #define COMP_CR2_WINMODE_COMP2_INPSEL (0U)
  79. #define COMP_CR2_WINMODE_COMP1_INPSEL (1U)
  80. #define COMP_CR1_WINOUT_VCOUT1 (0U)
  81. #define COMP_CR2_WINOUT_VCOUT2 (0U)
  82. #define COMP_CR_WINOUT_VCOUT12 (1U)
  83. #define COMP_CR_POLARITY_P (0U)
  84. #define COMP_CR_POLARITY_N (1U)
  85. #define COMP_CR_FLTEN_DISABLE (0U)
  86. #define COMP_CR_FLTEN_ENABLE (1U)
  87. #define COMP_CR_FLTTIME_1_CLK (0U)
  88. #define COMP_CR_FLTTIME_2_CLK (1U)
  89. #define COMP_CR_FLTTIME_4_CLK (2U)
  90. #define COMP_CR_FLTTIME_16_CLK (3U)
  91. #define COMP_CR_FLTTIME_64_CLK (4U)
  92. #define COMP_CR_FLTTIME_256_CLK (5U)
  93. #define COMP_CR_FLTTIME_1024_CLK (6U)
  94. #define COMP_CR_FLTTIME_4095_CLK (7U)
  95. #define COMP_CR_BLANKTIME_32_CLK (0U)
  96. #define COMP_CR_BLANKTIME_64_CLK (1U)
  97. #define COMP_CR_BLANKTIME_128_CLK (2U)
  98. #define COMP_CR_BLANKTIME_256_CLK (3U)
  99. #define COMP_CR_BLANKSEL_NONE (0U)
  100. #define COMP_CR_BLANKSEL_1 (1U)
  101. #define COMP_CR_BLANKSEL_2 (2U)
  102. #define COMP_CR_BLANKSEL_3 (4U)
  103. #define COMP_CR_BLANKSEL_4 (8U)
  104. #define COMP_CR_INPSEL_0 (0U)
  105. #define COMP_CR_INPSEL_1 (1U)
  106. #define COMP_CR_INPSEL_2 (2U)
  107. #define COMP_CR_INMSEL_0 (0U)
  108. #define COMP_CR_INMSEL_1 (1U)
  109. #define COMP_CR_INMSEL_2 (2U)
  110. #define COMP_CR_INMSEL_3 (3U)
  111. #define COMP_CR_HYS_DISABLE (0U)
  112. #define COMP_CR_HYS_1 (4U)
  113. #define COMP_CR_HYS_2 (5U)
  114. #define COMP_CR_HYS_3 (6U)
  115. #define COMP_CR_HYS_4 (7U)
  116. /******************************** COMP Instances *******************************/
  117. #define IS_COMP_ALL_INSTANCE(INSTANCE) ((INSTANCE) == COMP)
  118. #define IS_COMP_ALL_COMP(_COMP) (((_COMP) == COMP1) || \
  119. ((_COMP) == COMP2))
  120. #define IS_COMP_ALL_CRV_EN(_CRV_EN) (((_CRV_EN) == COMP_CR_CRV_EN_DISABLE) || \
  121. ((_CRV_EN) == COMP_CR_CRV_EN_ENABLE))
  122. #define IS_COMP_ALL_CRV_SEL(_CRV_SEL) (((_CRV_SEL) == COMP_CR_CRV_SEL_AVDD) || \
  123. ((_CRV_SEL) == COMP_CR_CRV_SEL_VREF))
  124. #define IS_COMP_ALL_CRV_CFG(_CRV_CFG) ((_CRV_CFG) <= 15U)
  125. #define IS_COMP_ALL_WINMODE(WINMODE) (((WINMODE) == COMP_CR1_WINMODE_COMP1_INPSEL) || \
  126. ((WINMODE) == COMP_CR1_WINMODE_COMP2_INPSEL) || \
  127. ((WINMODE) == COMP_CR2_WINMODE_COMP2_INPSEL) || \
  128. ((WINMODE) == COMP_CR2_WINMODE_COMP1_INPSEL))
  129. #define IS_COMP_ALL_WINOUT(_WINOUT) (((_WINOUT) == COMP_CR1_WINOUT_VCOUT1) || \
  130. ((_WINOUT) == COMP_CR2_WINOUT_VCOUT2) || \
  131. ((_WINOUT) == COMP_CR_WINOUT_VCOUT12))
  132. #define IS_COMP_ALL_POLARITY(POLARITY) (((POLARITY) == COMP_CR_POLARITY_N) || \
  133. ((POLARITY) == COMP_CR_POLARITY_P))
  134. #define IS_COMP_ALL_FLTEN(FLTEN) (((FLTEN) == COMP_CR_FLTEN_DISABLE) || \
  135. ((FLTEN) == COMP_CR_FLTEN_ENABLE))
  136. #define IS_COMP_ALL_FLTTIME(FLTTIME) (((FLTTIME) == COMP_CR_FLTTIME_1_CLK) || \
  137. ((FLTTIME) == COMP_CR_FLTTIME_2_CLK) || \
  138. ((FLTTIME) == COMP_CR_FLTTIME_4_CLK) || \
  139. ((FLTTIME) == COMP_CR_FLTTIME_16_CLK) || \
  140. ((FLTTIME) == COMP_CR_FLTTIME_64_CLK) || \
  141. ((FLTTIME) == COMP_CR_FLTTIME_256_CLK) || \
  142. ((FLTTIME) == COMP_CR_FLTTIME_1024_CLK) || \
  143. ((FLTTIME) == COMP_CR_FLTTIME_4095_CLK))
  144. #define IS_COMP_ALL_BLANKTIME(BLANKTIME) (((BLANKTIME) == COMP_CR_BLANKTIME_32_CLK) || \
  145. ((BLANKTIME) == COMP_CR_BLANKTIME_64_CLK) || \
  146. ((BLANKTIME) == COMP_CR_BLANKTIME_128_CLK) || \
  147. ((BLANKTIME) == COMP_CR_BLANKTIME_256_CLK))
  148. #define IS_COMP_ALL_BLANKSEL(BLANKSEL) (((BLANKSEL) == COMP_CR_BLANKSEL_NONE) || \
  149. ((BLANKSEL) == COMP_CR_BLANKSEL_1) || \
  150. ((BLANKSEL) == COMP_CR_BLANKSEL_2) || \
  151. ((BLANKSEL) == COMP_CR_BLANKSEL_3) || \
  152. ((BLANKSEL) == COMP_CR_BLANKSEL_4))
  153. #define IS_COMP_ALL_INPSEL(INPSEL) (((INPSEL) == COMP_CR_INPSEL_0) || \
  154. ((INPSEL) == COMP_CR_INPSEL_1) || \
  155. ((INPSEL) == COMP_CR_INPSEL_2))
  156. #define IS_COMP_ALL_INMSEL(INMSEL) (((INMSEL) == COMP_CR_INMSEL_0 ) || \
  157. ((INMSEL) == COMP_CR_INMSEL_1 ) || \
  158. ((INMSEL) == COMP_CR_INMSEL_2 ) || \
  159. ((INMSEL) == COMP_CR_INMSEL_3 ))
  160. #define IS_COMP_ALL_HYS(_HYS) (((_HYS) == COMP_CR_HYS_DISABLE) || \
  161. ((_HYS) == COMP_CR_HYS_1) || \
  162. ((_HYS) == COMP_CR_HYS_2) || \
  163. ((_HYS) == COMP_CR_HYS_3) || \
  164. ((_HYS) == COMP_CR_HYS_4))
  165. /* Function */
  166. void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp);
  167. void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp);
  168. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef* hcomp);
  169. HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef* hcomp);
  170. HAL_StatusTypeDef HAL_COMP_Enable(COMP_HandleTypeDef* hcomp);
  171. HAL_StatusTypeDef HAL_COMP_Disable(COMP_HandleTypeDef* hcomp);
  172. HAL_StatusTypeDef HAL_COMP_GetOutputLevel(COMP_HandleTypeDef* hcomp);
  173. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef* hcomp);
  174. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  175. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  176. #endif