at32f415_cmp.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. **************************************************************************
  3. * @file at32f415_cmp.h
  4. * @brief at32f415 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 __AT32F415_CMP_H
  26. #define __AT32F415_CMP_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* includes ------------------------------------------------------------------*/
  31. #include "at32f415.h"
  32. /** @addtogroup AT32F415_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_PA7 = 0x00, /*!< comparator1/2 non-inverting connect to pa5/pa7 */
  47. CMP_NON_INVERTING_PA1_PA3 = 0x01, /*!< comparator1/2 non-inverting connect to pa1/pa3 */
  48. CMP_NON_INVERTING_PA0_PA2 = 0x02, /*!< comparator1/2 non-inverting connect to pa0/pa2 */
  49. } cmp_non_inverting_type;
  50. /**
  51. * @brief cmp inverting type
  52. */
  53. typedef enum
  54. {
  55. CMP_INVERTING_1_4VREFINT = 0x00, /*!< comparator inverting connect to 1_4vrefint */
  56. CMP_INVERTING_1_2VREFINT = 0x01, /*!< comparator inverting connect to 1_2vrefint */
  57. CMP_INVERTING_3_4VREFINT = 0x02, /*!< comparator inverting connect to 3_4vrefint */
  58. CMP_INVERTING_VREFINT = 0x03, /*!< comparator inverting connect to vrefint */
  59. CMP_INVERTING_PA4 = 0x04, /*!< comparator inverting connect to pa4 */
  60. CMP_INVERTING_PA5 = 0x05, /*!< comparator inverting connect to pa5 */
  61. CMP_INVERTING_PA0_PA2 = 0x06, /*!< comparator1/2 inverting connect to pa0/pa2 */
  62. } cmp_inverting_type;
  63. /**
  64. * @brief cmp speed type
  65. */
  66. typedef enum
  67. {
  68. CMP_SPEED_FAST = 0x00, /*!< comparator selected fast speed */
  69. CMP_SPEED_SLOW = 0x01, /*!< comparator selected slow speed */
  70. } cmp_speed_type;
  71. #define CMP_OUTPUT_TMR1CXORAW_OFF CMP_OUTPUT_TMR1CHCLR
  72. #define CMP_OUTPUT_TMR2CXORAW_OFF CMP_OUTPUT_TMR2CHCLR
  73. #define CMP_OUTPUT_TMR3CXORAW_OFF CMP_OUTPUT_TMR3CHCLR
  74. /**
  75. * @brief cmp output type
  76. */
  77. typedef enum
  78. {
  79. CMP_OUTPUT_NONE = 0x00, /*!< comparator has no output */
  80. CMP_OUTPUT_TMR1BRK = 0x01, /*!< comparator output connect to tmr1brk */
  81. CMP_OUTPUT_TMR1CH1 = 0x02, /*!< comparator output connect to tmr1ch1 */
  82. CMP_OUTPUT_TMR1CHCLR = 0x03, /*!< comparator output connect to tmr1chclr */
  83. CMP_OUTPUT_TMR2CH4 = 0x04, /*!< comparator output connect to tmr1chclr */
  84. CMP_OUTPUT_TMR2CHCLR = 0x05, /*!< comparator output connect to tmr1chclr */
  85. CMP_OUTPUT_TMR3CH1 = 0x06, /*!< comparator output connect to tmr3ch1 */
  86. CMP_OUTPUT_TMR3CHCLR = 0x07 /*!< comparator output connect to tmr3chclr */
  87. } cmp_output_type;
  88. /**
  89. * @brief cmp polarity type
  90. */
  91. typedef enum
  92. {
  93. CMP_POL_NON_INVERTING = 0x00, /*!< comparator polarity non-inverting */
  94. CMP_POL_INVERTING = 0x01, /*!< comparator polarity inverting */
  95. } cmp_polarity_type;
  96. /**
  97. * @brief cmp hysteresis type
  98. */
  99. typedef enum
  100. {
  101. CMP_HYSTERESIS_NONE = 0x00, /*!< comparator selected no hysteresis */
  102. CMP_HYSTERESIS_LOW = 0x01, /*!< comparator selected low hysteresis */
  103. CMP_HYSTERESIS_MEDIUM = 0x02, /*!< comparator selected medium hysteresis */
  104. CMP_HYSTERESIS_HIGH = 0x03 /*!< comparator selected high hysteresis */
  105. } cmp_hysteresis_type;
  106. /**
  107. * @brief cmp selection type
  108. */
  109. typedef enum
  110. {
  111. CMP1_SELECTION = 0x00, /*!< select comparator 1 */
  112. CMP2_SELECTION = 0x01, /*!< select comparator 2 */
  113. } cmp_sel_type;
  114. /**
  115. * @brief cmp init type
  116. */
  117. typedef struct
  118. {
  119. cmp_non_inverting_type cmp_non_inverting; /*!< comparator non-inverting input selection */
  120. cmp_inverting_type cmp_inverting; /*!< comparator inverting selection */
  121. cmp_speed_type cmp_speed; /*!< comparator speed selection */
  122. cmp_output_type cmp_output; /*!< comparator output target selection */
  123. cmp_polarity_type cmp_polarity; /*!< comparator polarity selection */
  124. cmp_hysteresis_type cmp_hysteresis; /*!< comparator hysteresis selection */
  125. }cmp_init_type;
  126. /**
  127. * @brief type define cmp register all
  128. */
  129. typedef struct
  130. {
  131. /**
  132. * @brief cmp control and status register1, offset:0x00
  133. */
  134. union
  135. {
  136. __IO uint32_t ctrlsts1;
  137. struct
  138. {
  139. __IO uint32_t cmp1en : 1; /* [0] */
  140. __IO uint32_t cmp1is : 1; /* [1] */
  141. __IO uint32_t cmp1ssel : 1; /* [2] */
  142. __IO uint32_t reserved1 : 1; /* [3] */
  143. __IO uint32_t cmp1invsel : 3; /* [6:4] */
  144. __IO uint32_t reserved2 : 1; /* [7] */
  145. __IO uint32_t cmp1tag : 3; /* [10:8] */
  146. __IO uint32_t cmp1p : 1; /* [11] */
  147. __IO uint32_t cmp1hyst : 2; /* [13:12] */
  148. __IO uint32_t cmp1value : 1; /* [14] */
  149. __IO uint32_t cmp1wp : 1; /* [15] */
  150. __IO uint32_t cmp2en : 1; /* [16] */
  151. __IO uint32_t reserved3 : 1; /* [17] */
  152. __IO uint32_t cmp2ssel : 1; /* [18] */
  153. __IO uint32_t reserved4 : 1; /* [19] */
  154. __IO uint32_t cmp2invsel : 3; /* [22:20] */
  155. __IO uint32_t dcmpen : 1; /* [23] */
  156. __IO uint32_t cmp2tag : 3; /* [26:24] */
  157. __IO uint32_t cmp2p : 1; /* [27] */
  158. __IO uint32_t cmp2hyst : 2; /* [29:28] */
  159. __IO uint32_t cmp2value : 1; /* [30] */
  160. __IO uint32_t cmp2wp : 1; /* [31] */
  161. } ctrlsts1_bit;
  162. };
  163. /**
  164. * @brief cmp control and status register2, offset:0x04
  165. */
  166. union
  167. {
  168. __IO uint32_t ctrlsts2;
  169. struct
  170. {
  171. __IO uint32_t cmp1ninvsel : 2; /* [1:0] */
  172. __IO uint32_t reserved1 : 14;/* [15:2] */
  173. __IO uint32_t cmp2ninvsel : 2; /* [17:16] */
  174. __IO uint32_t reserved2 : 14;/* [31:18] */
  175. } ctrlsts2_bit;
  176. };
  177. } cmp_type;
  178. /**
  179. * @}
  180. */
  181. #define CMP ((cmp_type *) (CMP_BASE))
  182. /** @defgroup CMP_exported_functions
  183. * @{
  184. */
  185. void cmp_reset(void);
  186. void cmp_init(cmp_sel_type cmp_sel, cmp_init_type* cmp_init_struct);
  187. void cmp_default_para_init(cmp_init_type *cmp_init_struct);
  188. void cmp_enable(cmp_sel_type cmp_sel, confirm_state new_state);
  189. void cmp_input_shift_enable(confirm_state new_state);
  190. uint32_t cmp_output_value_get(cmp_sel_type cmp_sel);
  191. void cmp_write_protect_enable(cmp_sel_type cmp_sel);
  192. void cmp_double_mode_enable(confirm_state new_state);
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. /**
  200. * @}
  201. */
  202. #ifdef __cplusplus
  203. }
  204. #endif
  205. #endif