at32f421_cmp.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**
  2. **************************************************************************
  3. * @file at32f421_cmp.h
  4. * @brief at32f421 cmp header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F421_CMP_H
  26. #define __AT32F421_CMP_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* includes ------------------------------------------------------------------*/
  31. #include "at32f421.h"
  32. /** @addtogroup AT32F421_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup CMP
  36. * @{
  37. */
  38. /** @defgroup CMP_exported_types
  39. * @{
  40. */
  41. /**
  42. * @brief cmp non-inverting type
  43. */
  44. typedef enum
  45. {
  46. CMP_NON_INVERTING_PA5 = 0x00, /*!< comparator non-inverting connect to pa5 */
  47. CMP_NON_INVERTING_PA1 = 0x01, /*!< comparator non-inverting connect to pa1 */
  48. CMP_NON_INVERTING_PA0 = 0x02, /*!< comparator non-inverting connect to pa0 */
  49. CMP_NON_INVERTING_VSSA = 0x03 /*!< comparator non-inverting connect to vssa */
  50. } cmp_non_inverting_type;
  51. /**
  52. * @brief cmp inverting type
  53. */
  54. typedef enum
  55. {
  56. CMP_INVERTING_1_4VREFINT = 0x00, /*!< comparator inverting connect to 1_4vrefint */
  57. CMP_INVERTING_1_2VREFINT = 0x01, /*!< comparator inverting connect to 1_2vrefint */
  58. CMP_INVERTING_3_4VREFINT = 0x02, /*!< comparator inverting connect to 3_4vrefint */
  59. CMP_INVERTING_VREFINT = 0x03, /*!< comparator inverting connect to vrefint */
  60. CMP_INVERTING_PA4 = 0x04, /*!< comparator inverting connect to pa4 */
  61. CMP_INVERTING_PA5 = 0x05, /*!< comparator inverting connect to pa5 */
  62. CMP_INVERTING_PA0 = 0x06, /*!< comparator inverting connect to pa0 */
  63. CMP_INVERTING_PA2 = 0x07 /*!< comparator inverting connect to pa2 */
  64. } cmp_inverting_type;
  65. /**
  66. * @brief cmp speed type
  67. */
  68. typedef enum
  69. {
  70. CMP_SPEED_FAST = 0x00, /*!< comparator selected fast speed */
  71. CMP_SPEED_MEDIUM = 0x01, /*!< comparator selected medium speed */
  72. CMP_SPEED_SLOW = 0x02, /*!< comparator selected slow speed */
  73. CMP_SPEED_ULTRALOW = 0x03 /*!< comparator selected ultralow speed */
  74. } cmp_speed_type;
  75. /**
  76. * @brief cmp output type
  77. */
  78. typedef enum
  79. {
  80. CMP_OUTPUT_NONE = 0x00, /*!< comparator has no output */
  81. CMP_OUTPUT_TMR1BRK = 0x01, /*!< comparator output connect to tmr1brk */
  82. CMP_OUTPUT_TMR1CH1 = 0x02, /*!< comparator output connect to tmr1ch1 */
  83. CMP_OUTPUT_TMR1CHCLR = 0x03, /*!< comparator output connect to tmr1chclr */
  84. CMP_OUTPUT_TMR3CH1 = 0x06, /*!< comparator output connect to tmr3ch1 */
  85. CMP_OUTPUT_TMR3CHCLR = 0x07 /*!< comparator output connect to tmr3chclr */
  86. } cmp_output_type;
  87. /**
  88. * @brief cmp polarity type
  89. */
  90. typedef enum
  91. {
  92. CMP_POL_NON_INVERTING = 0x00, /*!< comparator polarity non-inverting */
  93. CMP_POL_INVERTING = 0x01, /*!< comparator polarity inverting */
  94. } cmp_polarity_type;
  95. /**
  96. * @brief cmp hysteresis type
  97. */
  98. typedef enum
  99. {
  100. CMP_HYSTERESIS_NONE = 0x00, /*!< comparator selected no hysteresis */
  101. CMP_HYSTERESIS_LOW = 0x01, /*!< comparator selected low hysteresis */
  102. CMP_HYSTERESIS_MEDIUM = 0x02, /*!< comparator selected medium hysteresis */
  103. CMP_HYSTERESIS_HIGH = 0x03 /*!< comparator selected high hysteresis */
  104. } cmp_hysteresis_type;
  105. /**
  106. * @brief cmp blanking type
  107. */
  108. typedef enum
  109. {
  110. CMP_BLANKING_NONE = 0x00, /*!< comparator no blanking */
  111. CMP_BLANKING_TMR1_CH4 = 0x01, /*!< comparator selected tmr1 ch4 as blanking */
  112. CMP_BLANKING_TMR3_CH3 = 0x03, /*!< comparator selected tmr3 ch3 as blanking */
  113. CMP_BLANKING_TMR15_CH2 = 0x04, /*!< comparator selected tmr15 ch2 as blanking */
  114. CMP_BLANKING_TMR15_CH1 = 0x06 /*!< comparator selected tmr15 ch1 as blanking */
  115. } cmp_blanking_type;
  116. /**
  117. * @brief cmp scale voltage and voltage bridge type
  118. */
  119. typedef enum
  120. {
  121. CMP_SCAL_BRG_00 = 0x00, /*!< comparator selected vrefint = 3/4 vrefint = 1/2 vrefint = 1/4 vrefint = 0v */
  122. CMP_SCAL_BRG_10 = 0x02, /*!< comparator selected vrefint = 3/4 vrefint = 1/2 vrefint = 1/4 vrefint = 1.2v */
  123. CMP_SCAL_BRG_11 = 0x03 /*!< comparator selected vrefint = 1.2v, 3/4 vrefint = 0.9v, 1/2 vrefint = 0.6v, 1/4 vrefint = 0.3v */
  124. } cmp_scal_brg_type;
  125. /**
  126. * @brief cmp selection type
  127. */
  128. typedef enum
  129. {
  130. CMP1_SELECTION = 0x00, /*!< select comparator 1 */
  131. } cmp_sel_type;
  132. /**
  133. * @brief cmp init type
  134. */
  135. typedef struct
  136. {
  137. cmp_non_inverting_type cmp_non_inverting; /*!< comparator non-inverting input selection */
  138. cmp_inverting_type cmp_inverting; /*!< comparator inverting selection */
  139. cmp_speed_type cmp_speed; /*!< comparator speed selection */
  140. cmp_output_type cmp_output; /*!< comparator output target selection */
  141. cmp_polarity_type cmp_polarity; /*!< comparator polarity selection */
  142. cmp_hysteresis_type cmp_hysteresis; /*!< comparator hysteresis selection */
  143. }cmp_init_type;
  144. /**
  145. * @brief type define cmp register all
  146. */
  147. typedef struct
  148. {
  149. /**
  150. * @brief cmp control and status register, offset:0x1C
  151. */
  152. union
  153. {
  154. __IO uint32_t ctrlsts;
  155. struct
  156. {
  157. __IO uint32_t cmpen : 1; /* [0] */
  158. __IO uint32_t cmpis : 1; /* [1] */
  159. __IO uint32_t cmpssel : 2; /* [3:2] */
  160. __IO uint32_t cmpinvsel : 3; /* [6:4] */
  161. __IO uint32_t cmpninvsel : 2; /* [8:7] */
  162. __IO uint32_t reserved1 : 1; /* [9] */
  163. __IO uint32_t cmptag : 3; /* [12:10] */
  164. __IO uint32_t reserved2 : 2; /* [14:13] */
  165. __IO uint32_t cmpp : 1; /* [15] */
  166. __IO uint32_t cmphyst : 2; /* [17:16] */
  167. __IO uint32_t cmpblanking : 3; /* [20:18] */
  168. __IO uint32_t reserved3 : 1; /* [21] */
  169. __IO uint32_t brgen : 1; /* [22] */
  170. __IO uint32_t scalen : 1; /* [23] */
  171. __IO uint32_t reserved4 : 6; /* [29:24] */
  172. __IO uint32_t cmpvalue : 1; /* [30] */
  173. __IO uint32_t cmpwp : 1; /* [31] */
  174. } ctrlsts_bit;
  175. };
  176. /**
  177. * @brief crm reserved1 register, offset:0x20
  178. */
  179. __IO uint32_t reserved1;
  180. /**
  181. * @brief cmp Glitch filter enable register, offset:0x24
  182. */
  183. union
  184. {
  185. __IO uint32_t g_filter_en;
  186. struct
  187. {
  188. __IO uint32_t gfe : 1; /* [0] */
  189. __IO uint32_t reserved1 : 31;/* [31:1] */
  190. } g_filter_en_bit;
  191. };
  192. /**
  193. * @brief cmp high pulse count register, offset:0x28
  194. */
  195. union
  196. {
  197. __IO uint32_t high_pulse;
  198. struct
  199. {
  200. __IO uint32_t h_pulse_cnt : 6; /* [5:0] */
  201. __IO uint32_t reserved1 : 26;/* [31:6] */
  202. } high_pulse_bit;
  203. };
  204. /**
  205. * @brief cmp low pulse count register, offset:0x2C
  206. */
  207. union
  208. {
  209. __IO uint32_t low_pulse;
  210. struct
  211. {
  212. __IO uint32_t l_pulse_cnt : 6; /* [5:0] */
  213. __IO uint32_t reserved1 : 26;/* [31:6] */
  214. } low_pulse_bit;
  215. };
  216. } cmp_type;
  217. /**
  218. * @}
  219. */
  220. #define CMP ((cmp_type *) (SCFG_CMP_BASE + 0x1C))
  221. /** @defgroup CMP_exported_functions
  222. * @{
  223. */
  224. void cmp_reset(void);
  225. void cmp_init(cmp_sel_type cmp_sel, cmp_init_type* cmp_init_struct);
  226. void cmp_default_para_init(cmp_init_type *cmp_init_struct);
  227. void cmp_enable(cmp_sel_type cmp_sel, confirm_state new_state);
  228. void cmp_input_shift_enable(confirm_state new_state);
  229. uint32_t cmp_output_value_get(cmp_sel_type cmp_sel);
  230. void cmp_write_protect_enable(cmp_sel_type cmp_sel);
  231. void cmp_filter_config(uint16_t high_pulse_cnt, uint16_t low_pulse_cnt, confirm_state new_state);
  232. void cmp_blanking_config(cmp_blanking_type blank_sel);
  233. void cmp_scal_brg_config(uint32_t scal_brg);
  234. /**
  235. * @}
  236. */
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246. #endif