at32f415_cmp.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /**
  2. **************************************************************************
  3. * @file at32f415_cmp.h
  4. * @version v2.0.5
  5. * @date 2022-05-20
  6. * @brief at32f415 cmp header file
  7. **************************************************************************
  8. * Copyright notice & Disclaimer
  9. *
  10. * The software Board Support Package (BSP) that is made available to
  11. * download from Artery official website is the copyrighted work of Artery.
  12. * Artery authorizes customers to use, copy, and distribute the BSP
  13. * software and its related documentation for the purpose of design and
  14. * development in conjunction with Artery microcontrollers. Use of the
  15. * software is governed by this copyright notice and the following disclaimer.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  18. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  19. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  20. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  21. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  23. *
  24. **************************************************************************
  25. */
  26. /* define to prevent recursive inclusion -------------------------------------*/
  27. #ifndef __AT32F415_CMP_H
  28. #define __AT32F415_CMP_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* includes ------------------------------------------------------------------*/
  33. #include "at32f415.h"
  34. /** @addtogroup AT32F415_periph_driver
  35. * @{
  36. */
  37. /** @addtogroup CMP
  38. * @{
  39. */
  40. /** @defgroup CMP_exported_types
  41. * @{
  42. */
  43. /**
  44. * @brief cmp non-inverting type
  45. */
  46. typedef enum
  47. {
  48. CMP_NON_INVERTING_PA5 = 0x00, /*!< comparator non-inverting connect to pa5 */
  49. CMP_NON_INVERTING_PA1 = 0x01, /*!< comparator non-inverting connect to pa1 */
  50. CMP_NON_INVERTING_PA0 = 0x02, /*!< comparator non-inverting connect to pa0 */
  51. CMP_NON_INVERTING_VSSA = 0x03 /*!< comparator non-inverting connect to vssa */
  52. } cmp_non_inverting_type;
  53. /**
  54. * @brief cmp inverting type
  55. */
  56. typedef enum
  57. {
  58. CMP_INVERTING_1_4VREFINT = 0x00, /*!< comparator inverting connect to 1_4vrefint */
  59. CMP_INVERTING_1_2VREFINT = 0x01, /*!< comparator inverting connect to 1_2vrefint */
  60. CMP_INVERTING_3_4VREFINT = 0x02, /*!< comparator inverting connect to 3_4vrefint */
  61. CMP_INVERTING_VREFINT = 0x03, /*!< comparator inverting connect to vrefint */
  62. CMP_INVERTING_PA4 = 0x04, /*!< comparator inverting connect to pa4 */
  63. CMP_INVERTING_PA5 = 0x05, /*!< comparator inverting connect to pa5 */
  64. CMP_INVERTING_PA0 = 0x06, /*!< comparator inverting connect to pa0 */
  65. CMP_INVERTING_PA2 = 0x07 /*!< comparator inverting connect to pa2 */
  66. } cmp_inverting_type;
  67. /**
  68. * @brief cmp speed type
  69. */
  70. typedef enum
  71. {
  72. CMP_SPEED_FAST = 0x00, /*!< comparator selected fast speed */
  73. CMP_SPEED_MEDIUM = 0x01, /*!< comparator selected medium speed */
  74. CMP_SPEED_SLOW = 0x02, /*!< comparator selected slow speed */
  75. CMP_SPEED_ULTRALOW = 0x03 /*!< comparator selected ultralow speed */
  76. } cmp_speed_type;
  77. /**
  78. * @brief cmp output type
  79. */
  80. typedef enum
  81. {
  82. CMP_OUTPUT_NONE = 0x00, /*!< comparator has no output */
  83. CMP_OUTPUT_TMR1BRK = 0x01, /*!< comparator output connect to tmr1brk */
  84. CMP_OUTPUT_TMR1CH1 = 0x02, /*!< comparator output connect to tmr1ch1 */
  85. CMP_OUTPUT_TMR1CHCLR = 0x03, /*!< comparator output connect to tmr1chclr */
  86. CMP_OUTPUT_TMR2CH4 = 0x04, /*!< comparator output connect to tmr1chclr */
  87. CMP_OUTPUT_TMR2CHCLR = 0x05, /*!< comparator output connect to tmr1chclr */
  88. CMP_OUTPUT_TMR3CH1 = 0x06, /*!< comparator output connect to tmr3ch1 */
  89. CMP_OUTPUT_TMR3CHCLR = 0x07 /*!< comparator output connect to tmr3chclr */
  90. } cmp_output_type;
  91. /**
  92. * @brief cmp polarity type
  93. */
  94. typedef enum
  95. {
  96. CMP_POL_NON_INVERTING = 0x00, /*!< comparator polarity non-inverting */
  97. CMP_POL_INVERTING = 0x01, /*!< comparator polarity inverting */
  98. } cmp_polarity_type;
  99. /**
  100. * @brief cmp hysteresis type
  101. */
  102. typedef enum
  103. {
  104. CMP_HYSTERESIS_NONE = 0x00, /*!< comparator selected no hysteresis */
  105. CMP_HYSTERESIS_LOW = 0x01, /*!< comparator selected low hysteresis */
  106. CMP_HYSTERESIS_MEDIUM = 0x02, /*!< comparator selected medium hysteresis */
  107. CMP_HYSTERESIS_HIGH = 0x03 /*!< comparator selected high hysteresis */
  108. } cmp_hysteresis_type;
  109. /**
  110. * @brief cmp selection type
  111. */
  112. typedef enum
  113. {
  114. CMP1_SELECTION = 0x00, /*!< select comparator 1 */
  115. CMP2_SELECTION = 0x01, /*!< select comparator 2 */
  116. } cmp_sel_type;
  117. /**
  118. * @brief cmp init type
  119. */
  120. typedef struct
  121. {
  122. cmp_non_inverting_type cmp_non_inverting; /*!< comparator non-inverting input selection */
  123. cmp_inverting_type cmp_inverting; /*!< comparator inverting selection */
  124. cmp_speed_type cmp_speed; /*!< comparator speed selection */
  125. cmp_output_type cmp_output; /*!< comparator output target selection */
  126. cmp_polarity_type cmp_polarity; /*!< comparator polarity selection */
  127. cmp_hysteresis_type cmp_hysteresis; /*!< comparator hysteresis selection */
  128. }cmp_init_type;
  129. /**
  130. * @brief type define cmp register all
  131. */
  132. typedef struct
  133. {
  134. /**
  135. * @brief cmp control and status register1, offset:0x00
  136. */
  137. union
  138. {
  139. __IO uint32_t ctrlsts1;
  140. struct
  141. {
  142. __IO uint32_t cmp1en : 1; /* [0] */
  143. __IO uint32_t cmp1is : 1; /* [1] */
  144. __IO uint32_t cmp1ssel : 1; /* [2] */
  145. __IO uint32_t reserved1 : 1; /* [3] */
  146. __IO uint32_t cmp1invsel : 3; /* [6:4] */
  147. __IO uint32_t reserved2 : 1; /* [7] */
  148. __IO uint32_t cmp1tag : 3; /* [10:8] */
  149. __IO uint32_t cmp1p : 1; /* [11] */
  150. __IO uint32_t cmp1hyst : 2; /* [13:12] */
  151. __IO uint32_t cmp1value : 1; /* [14] */
  152. __IO uint32_t cmp1wp : 1; /* [15] */
  153. __IO uint32_t cmp2en : 1; /* [16] */
  154. __IO uint32_t reserved3 : 1; /* [17] */
  155. __IO uint32_t cmp2ssel : 1; /* [18] */
  156. __IO uint32_t reserved4 : 1; /* [19] */
  157. __IO uint32_t cmp2invsel : 3; /* [22:20] */
  158. __IO uint32_t dcmpen : 1; /* [23] */
  159. __IO uint32_t cmp2tag : 3; /* [26:24] */
  160. __IO uint32_t cmp2p : 1; /* [27] */
  161. __IO uint32_t cmp2hyst : 2; /* [29:28] */
  162. __IO uint32_t cmp2value : 1; /* [30] */
  163. __IO uint32_t cmp2wp : 1; /* [31] */
  164. } ctrlsts1_bit;
  165. };
  166. /**
  167. * @brief cmp control and status register2, offset:0x04
  168. */
  169. union
  170. {
  171. __IO uint32_t ctrlsts2;
  172. struct
  173. {
  174. __IO uint32_t cmp1ninvsel : 2; /* [1:0] */
  175. __IO uint32_t reserved1 : 14;/* [15:2] */
  176. __IO uint32_t cmp2ninvsel : 2; /* [17:16] */
  177. __IO uint32_t reserved2 : 14;/* [31:18] */
  178. } ctrlsts2_bit;
  179. };
  180. } cmp_type;
  181. /**
  182. * @}
  183. */
  184. #define CMP ((cmp_type *) (CMP_BASE))
  185. /** @defgroup CMP_exported_functions
  186. * @{
  187. */
  188. void cmp_reset(void);
  189. void cmp_init(cmp_sel_type cmp_sel, cmp_init_type* cmp_init_struct);
  190. void cmp_default_para_init(cmp_init_type *cmp_init_struct);
  191. void cmp_enable(cmp_sel_type cmp_sel, confirm_state new_state);
  192. void cmp_input_shift_enable(confirm_state new_state);
  193. uint32_t cmp_output_value_get(cmp_sel_type cmp_sel);
  194. void cmp_write_protect_enable(cmp_sel_type cmp_sel);
  195. /**
  196. * @}
  197. */
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif