at32f421_cmp.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. #define CMP_OUTPUT_TMR1CXORAW_OFF CMP_OUTPUT_TMR1CHCLR
  76. #define CMP_OUTPUT_TMR3CXORAW_OFF CMP_OUTPUT_TMR3CHCLR
  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_TMR3CH1 = 0x06, /*!< comparator output connect to tmr3ch1 */
  87. CMP_OUTPUT_TMR3CHCLR = 0x07 /*!< comparator output connect to tmr3chclr */
  88. } cmp_output_type;
  89. /**
  90. * @brief cmp polarity type
  91. */
  92. typedef enum
  93. {
  94. CMP_POL_NON_INVERTING = 0x00, /*!< comparator polarity non-inverting */
  95. CMP_POL_INVERTING = 0x01, /*!< comparator polarity inverting */
  96. } cmp_polarity_type;
  97. /**
  98. * @brief cmp hysteresis type
  99. */
  100. typedef enum
  101. {
  102. CMP_HYSTERESIS_NONE = 0x00, /*!< comparator selected no hysteresis */
  103. CMP_HYSTERESIS_LOW = 0x01, /*!< comparator selected low hysteresis */
  104. CMP_HYSTERESIS_MEDIUM = 0x02, /*!< comparator selected medium hysteresis */
  105. CMP_HYSTERESIS_HIGH = 0x03 /*!< comparator selected high hysteresis */
  106. } cmp_hysteresis_type;
  107. /**
  108. * @brief cmp blanking type
  109. */
  110. typedef enum
  111. {
  112. CMP_BLANKING_NONE = 0x00, /*!< comparator no blanking */
  113. CMP_BLANKING_TMR1_CH4 = 0x01, /*!< comparator selected tmr1 ch4 as blanking */
  114. CMP_BLANKING_TMR3_CH3 = 0x03, /*!< comparator selected tmr3 ch3 as blanking */
  115. CMP_BLANKING_TMR15_CH2 = 0x04, /*!< comparator selected tmr15 ch2 as blanking */
  116. CMP_BLANKING_TMR15_CH1 = 0x06 /*!< comparator selected tmr15 ch1 as blanking */
  117. } cmp_blanking_type;
  118. /**
  119. * @brief cmp scale voltage and voltage bridge type
  120. */
  121. typedef enum
  122. {
  123. CMP_SCAL_BRG_00 = 0x00, /*!< comparator selected vrefint = 3/4 vrefint = 1/2 vrefint = 1/4 vrefint = 0v */
  124. CMP_SCAL_BRG_10 = 0x02, /*!< comparator selected vrefint = 3/4 vrefint = 1/2 vrefint = 1/4 vrefint = 1.2v */
  125. 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 */
  126. } cmp_scal_brg_type;
  127. /**
  128. * @brief cmp selection type
  129. */
  130. typedef enum
  131. {
  132. CMP1_SELECTION = 0x00, /*!< select comparator 1 */
  133. } cmp_sel_type;
  134. /**
  135. * @brief cmp init type
  136. */
  137. typedef struct
  138. {
  139. cmp_non_inverting_type cmp_non_inverting; /*!< comparator non-inverting input selection */
  140. cmp_inverting_type cmp_inverting; /*!< comparator inverting selection */
  141. cmp_speed_type cmp_speed; /*!< comparator speed selection */
  142. cmp_output_type cmp_output; /*!< comparator output target selection */
  143. cmp_polarity_type cmp_polarity; /*!< comparator polarity selection */
  144. cmp_hysteresis_type cmp_hysteresis; /*!< comparator hysteresis selection */
  145. }cmp_init_type;
  146. /**
  147. * @brief type define cmp register all
  148. */
  149. typedef struct
  150. {
  151. /**
  152. * @brief cmp control and status register, offset:0x1C
  153. */
  154. union
  155. {
  156. __IO uint32_t ctrlsts;
  157. struct
  158. {
  159. __IO uint32_t cmpen : 1; /* [0] */
  160. __IO uint32_t cmpis : 1; /* [1] */
  161. __IO uint32_t cmpssel : 2; /* [3:2] */
  162. __IO uint32_t cmpinvsel : 3; /* [6:4] */
  163. __IO uint32_t cmpninvsel : 2; /* [8:7] */
  164. __IO uint32_t reserved1 : 1; /* [9] */
  165. __IO uint32_t cmptag : 3; /* [12:10] */
  166. __IO uint32_t reserved2 : 2; /* [14:13] */
  167. __IO uint32_t cmpp : 1; /* [15] */
  168. __IO uint32_t cmphyst : 2; /* [17:16] */
  169. __IO uint32_t cmpblanking : 3; /* [20:18] */
  170. __IO uint32_t reserved3 : 1; /* [21] */
  171. __IO uint32_t brgen : 1; /* [22] */
  172. __IO uint32_t scalen : 1; /* [23] */
  173. __IO uint32_t reserved4 : 6; /* [29:24] */
  174. __IO uint32_t cmpvalue : 1; /* [30] */
  175. __IO uint32_t cmpwp : 1; /* [31] */
  176. } ctrlsts_bit;
  177. };
  178. /**
  179. * @brief crm reserved1 register, offset:0x20
  180. */
  181. __IO uint32_t reserved1;
  182. /**
  183. * @brief cmp Glitch filter enable register, offset:0x24
  184. */
  185. union
  186. {
  187. __IO uint32_t g_filter_en;
  188. struct
  189. {
  190. __IO uint32_t gfe : 1; /* [0] */
  191. __IO uint32_t reserved1 : 31;/* [31:1] */
  192. } g_filter_en_bit;
  193. };
  194. /**
  195. * @brief cmp high pulse count register, offset:0x28
  196. */
  197. union
  198. {
  199. __IO uint32_t high_pulse;
  200. struct
  201. {
  202. __IO uint32_t h_pulse_cnt : 6; /* [5:0] */
  203. __IO uint32_t reserved1 : 26;/* [31:6] */
  204. } high_pulse_bit;
  205. };
  206. /**
  207. * @brief cmp low pulse count register, offset:0x2C
  208. */
  209. union
  210. {
  211. __IO uint32_t low_pulse;
  212. struct
  213. {
  214. __IO uint32_t l_pulse_cnt : 6; /* [5:0] */
  215. __IO uint32_t reserved1 : 26;/* [31:6] */
  216. } low_pulse_bit;
  217. };
  218. } cmp_type;
  219. /**
  220. * @}
  221. */
  222. #define CMP ((cmp_type *) (SCFG_CMP_BASE + 0x1C))
  223. /** @defgroup CMP_exported_functions
  224. * @{
  225. */
  226. void cmp_reset(void);
  227. void cmp_init(cmp_sel_type cmp_sel, cmp_init_type* cmp_init_struct);
  228. void cmp_default_para_init(cmp_init_type *cmp_init_struct);
  229. void cmp_enable(cmp_sel_type cmp_sel, confirm_state new_state);
  230. void cmp_input_shift_enable(confirm_state new_state);
  231. uint32_t cmp_output_value_get(cmp_sel_type cmp_sel);
  232. void cmp_write_protect_enable(cmp_sel_type cmp_sel);
  233. void cmp_filter_config(uint16_t high_pulse_cnt, uint16_t low_pulse_cnt, confirm_state new_state);
  234. void cmp_blanking_config(cmp_blanking_type blank_sel);
  235. void cmp_scal_brg_config(cmp_scal_brg_type scal_brg);
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif