reg_comp.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file reg_comp.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE SERIES OF
  5. /// MM32 FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __REG_COMP_H
  20. #define __REG_COMP_H
  21. // Files includes
  22. #include <stdint.h>
  23. #include <stdbool.h>
  24. #include "types.h"
  25. #if defined ( __CC_ARM )
  26. #pragma anon_unions
  27. #endif
  28. ////////////////////////////////////////////////////////////////////////////////
  29. /// @brief COMP Base Address Definition
  30. ////////////////////////////////////////////////////////////////////////////////
  31. #define COMP_BASE (APB2PERIPH_BASE + 0x4000) ///< Base Address: 0x40014000
  32. ////////////////////////////////////////////////////////////////////////////////
  33. /// @brief Comparators Register Structure Definition
  34. ////////////////////////////////////////////////////////////////////////////////
  35. typedef struct {
  36. __IO u32 RESERVED1; ///< offset: 0x00
  37. __IO u32 RESERVED2; ///< offset: 0x04
  38. __IO u32 RESERVED3; ///< offset: 0x08
  39. union {
  40. __IO u32 CSR1; ///< COMP1 Control Status Register offset: 0x0C
  41. __IO u32 COMP1_CSR;
  42. };
  43. union {
  44. __IO u32 CSR2; ///< COMP2 Control Status Register offset: 0x10
  45. __IO u32 COMP2_CSR;
  46. };
  47. __IO u32 RESERVED4; ///< offset: 0x14
  48. union {
  49. __IO u32 CRV; ///< COMP external reference voltage register offset: 0x18
  50. __IO u32 COMP_CRV;
  51. };
  52. union {
  53. __IO u32 POLL1; ///< COMP1 polling register offset: 0x1C
  54. __IO u32 COMP1_POLL;
  55. };
  56. union {
  57. __IO u32 POLL2; ///< COMP2 polling register offset: 0x20
  58. __IO u32 COMP2_POLL;
  59. };
  60. } COMP_TypeDef;
  61. ////////////////////////////////////////////////////////////////////////////////
  62. /// @brief COMP type pointer Definition
  63. ////////////////////////////////////////////////////////////////////////////////
  64. #define COMP ((COMP_TypeDef*) COMP_BASE)
  65. ////////////////////////////////////////////////////////////////////////////////
  66. /// @brief COMP_CSR Register Bit Definition
  67. ////////////////////////////////////////////////////////////////////////////////
  68. #define COMP_CSR_EN_Pos (0)
  69. #define COMP_CSR_EN (0x01U << COMP_CSR_EN_Pos) ///< Comparator enable
  70. #define COMP_CSR_MODE_Pos (2)
  71. #define COMP_CSR_MODE (0x03U << COMP_CSR_MODE_Pos) ///< Comparator mode
  72. #define COMP_CSR_MODE_LOWESTPOWER (0x00U << COMP_CSR_MODE_Pos) ///< Comparator lowest power mode
  73. #define COMP_CSR_MODE_LOWPOWER (0x01U << COMP_CSR_MODE_Pos) ///< Comparator low power mode
  74. #define COMP_CSR_MODE_MEDIUMRATE (0x02U << COMP_CSR_MODE_Pos) ///< Comparator medium rate mode
  75. #define COMP_CSR_MODE_HIGHRATE (0x03U << COMP_CSR_MODE_Pos) ///< Comparator high rate mode
  76. #define COMP_CSR_INM_Pos (4)
  77. #define COMP_CSR_INM (0x03U << COMP_CSR_INM_Pos) ///< Comparator inverting input selection
  78. #define COMP_CSR_INM_0 (0x00U << COMP_CSR_INM_Pos) ///< INM0 as COMP inverting input
  79. #define COMP_CSR_INM_1 (0x01U << COMP_CSR_INM_Pos) ///< INM1 as COMP inverting input
  80. #define COMP_CSR_INM_2 (0x02U << COMP_CSR_INM_Pos) ///< INM2 as COMP inverting input
  81. #define COMP_CSR_INM_3 (0x03U << COMP_CSR_INM_Pos) ///< INM3 as COMP inverting input
  82. #define COMP_CSR_INP_Pos (7)
  83. #define COMP_CSR_INP (0x03U << COMP_CSR_INP_Pos) ///< Comparator non-inverting input selection
  84. #define COMP_CSR_INP_INP0 (0x00U << COMP_CSR_INP_Pos) ///< INP0 as COMP non-inverting input
  85. #define COMP_CSR_INP_INP1 (0x01U << COMP_CSR_INP_Pos) ///< INP1 as COMP non-inverting input
  86. #define COMP_CSR_INP_INP2 (0x02U << COMP_CSR_INP_Pos) ///< INP2 as COMP non-inverting input
  87. #define COMP_CSR_INP_INP3 (0x03U << COMP_CSR_INP_Pos) ///< INP3 as COMP non-inverting input
  88. #define COMP_CSR_OUT_Pos (10)
  89. #define COMP_CSR_OUT (0x0FU << COMP_CSR_OUT_Pos) ///< Comparator output selection
  90. #define COMP_CSR_OUT_TIM1_BRAKE (0x02U << COMP_CSR_OUT_Pos) ///< Timer1 brake input
  91. #define COMP_CSR_OUT_TIM8_BRAKE (0x03U << COMP_CSR_OUT_Pos) ///< Timer8 brake input
  92. #define COMP_CSR_OUT_TIM1_OCREFCLR (0x06U << COMP_CSR_OUT_Pos) ///< Timer1 ocrefclear input
  93. #define COMP_CSR_OUT_TIM1_CAPTURE1 (0x07U << COMP_CSR_OUT_Pos) ///< Timer1 input capture 1
  94. #define COMP_CSR_OUT_TIM2_CAPTURE4 (0x08U << COMP_CSR_OUT_Pos) ///< Timer2 input capture 4
  95. #define COMP_CSR_OUT_TIM2_OCREFCLR (0x09U << COMP_CSR_OUT_Pos) ///< Timer2 ocrefclear input
  96. #define COMP_CSR_OUT_TIM3_CAPTURE1 (0x0AU << COMP_CSR_OUT_Pos) ///< Timer3 input capture 1
  97. #define COMP_CSR_OUT_TIM3_OCREFCLR (0x0BU << COMP_CSR_OUT_Pos) ///< Timer3 ocrefclear input
  98. #define COMP_CSR_OUT_TIM8_OCREFCLR (0x0FU << COMP_CSR_OUT_Pos) ///< Timer8 ocrefclear input
  99. #define COMP_CSR_POL_Pos (15)
  100. #define COMP_CSR_POL (0x01U << COMP_CSR_POL_Pos) ///< Comparator output polarity
  101. #define COMP_CSR_HYST_Pos (16)
  102. #define COMP_CSR_HYST (0x03U << COMP_CSR_HYST_Pos) ///< Comparator hysteresis
  103. #define COMP_CSR_HYST_0 (0x00U << COMP_CSR_HYST_Pos) ///< Hysteresis Voltage: 0mV
  104. #define COMP_CSR_HYST_15 (0x01U << COMP_CSR_HYST_Pos) ///< Hysteresis Voltage: 15mV
  105. #define COMP_CSR_HYST_30 (0x02U << COMP_CSR_HYST_Pos) ///< Hysteresis Voltage: 30mV
  106. #define COMP_CSR_HYST_90 (0x03U << COMP_CSR_HYST_Pos) ///< Hysteresis Voltage: 90mV
  107. #define COMP_CSR_OFLT_Pos (18)
  108. #define COMP_CSR_OFLT (0x07U << COMP_CSR_OFLT_Pos) ///< Comparator output filter
  109. #define COMP_CSR_OFLT_0 (0x00U << COMP_CSR_OFLT_Pos) ///< 0 clock cycle
  110. #define COMP_CSR_OFLT_1 (0x01U << COMP_CSR_OFLT_Pos) ///< 2 clock cycle
  111. #define COMP_CSR_OFLT_2 (0x02U << COMP_CSR_OFLT_Pos) ///< 4 clock cycle
  112. #define COMP_CSR_OFLT_3 (0x03U << COMP_CSR_OFLT_Pos) ///< 8 clock cycle
  113. #define COMP_CSR_OFLT_4 (0x04U << COMP_CSR_OFLT_Pos) ///< 16 clock cycle
  114. #define COMP_CSR_OFLT_5 (0x05U << COMP_CSR_OFLT_Pos) ///< 32 clock cycle
  115. #define COMP_CSR_OFLT_6 (0x06U << COMP_CSR_OFLT_Pos) ///< 64 clock cycle
  116. #define COMP_CSR_OFLT_7 (0x07U << COMP_CSR_OFLT_Pos) ///< 128 clock cycle
  117. #define COMP_CSR_STA_Pos (30)
  118. #define COMP_CSR_STA (0x01U << COMP_CSR_STA_Pos) ///< Comparator output status
  119. #define COMP_CSR_LOCK_Pos (31)
  120. #define COMP_CSR_LOCK (0x01U << COMP_CSR_LOCK_Pos) ///< Comparator lock
  121. ////////////////////////////////////////////////////////////////////////////////
  122. /// @brief COMP_CRV Register Bit Definition
  123. ////////////////////////////////////////////////////////////////////////////////
  124. #define COMP_CRV_Pos (0)
  125. #define COMP_CRV_MASK (0x0FU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  126. #define COMP_CRV_1_20 (0x00U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  127. #define COMP_CRV_2_20 (0x01U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  128. #define COMP_CRV_3_20 (0x02U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  129. #define COMP_CRV_4_20 (0x03U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  130. #define COMP_CRV_5_20 (0x04U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  131. #define COMP_CRV_6_20 (0x05U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  132. #define COMP_CRV_7_20 (0x06U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  133. #define COMP_CRV_8_20 (0x07U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  134. #define COMP_CRV_9_20 (0x08U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  135. #define COMP_CRV_10_20 (0x09U << COMP_CRV_Pos) ///< Comparator external reference voltage select
  136. #define COMP_CRV_11_20 (0x0AU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  137. #define COMP_CRV_12_20 (0x0BU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  138. #define COMP_CRV_13_20 (0x0CU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  139. #define COMP_CRV_14_20 (0x0DU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  140. #define COMP_CRV_15_20 (0x0EU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  141. #define COMP_CRV_16_20 (0x0FU << COMP_CRV_Pos) ///< Comparator external reference voltage select
  142. #define COMP_CRV_EN_Pos (4)
  143. #define COMP_CRV_EN (0x01U << COMP_CRV_EN_Pos) ///< Comparator external reference voltage enable
  144. #define COMP_CRV_EN_DISABLE (0x00U << COMP_CRV_EN_Pos) ///< Disable comparator external reference voltage
  145. #define COMP_CRV_EN_ENABLE (0x01U << COMP_CRV_EN_Pos) ///< Enable comparator external reference voltage
  146. #define COMP_CRV_SRC_Pos (5)
  147. #define COMP_CRV_SRC (0x01U << COMP_CRV_SRC_Pos) ///< Comparator external reference voltage source select
  148. #define COMP_CRV_SRC_VREF (0x00U << COMP_CRV_SRC_Pos) ///< Select VREF
  149. #define COMP_CRV_SRC_AVDD (0x01U << COMP_CRV_SRC_Pos) ///< Select AVDD
  150. ////////////////////////////////////////////////////////////////////////////////
  151. /// @brief COMP_POL Register Bit Definition
  152. ////////////////////////////////////////////////////////////////////////////////
  153. #define COMP_POLL_EN_Pos (0)
  154. #define COMP_POLL_EN (0x01U << COMP_POLL_EN_Pos) ///< Comparator polling enable
  155. #define COMP_POLL_EN_DISABLE (0x00U << COMP_POLL_EN_Pos) ///< Disable comparator polling mode
  156. #define COMP_POLL_EN_ENABLE (0x01U << COMP_POLL_EN_Pos) ///< Enable comparator polling mode
  157. #define COMP_POLL_CH_Pos (1)
  158. #define COMP_POLL_CH (0x01U << COMP_POLL_CH_Pos) ///< Comparator polling channel
  159. #define COMP_POLL_CH_1_2 (0x00U << COMP_POLL_CH_Pos) ///< Polling channel 1/2
  160. #define COMP_POLL_CH_1_2_3 (0x01U << COMP_POLL_CH_Pos) ///< Polling channel 1/2/3
  161. #define COMP_POLL_FIXN_Pos (2)
  162. #define COMP_POLL_FIXN (0x01U << COMP_POLL_FIXN_Pos) ///< Polling inverting input fix
  163. #define COMP_POLL_FIXN_NOTFIXED (0x00U << COMP_POLL_FIXN_Pos) ///< Polling channel inverting input is not fixed
  164. #define COMP_POLL_FIXN_FIXED (0x01U << COMP_POLL_FIXN_Pos) ///< Polling channel inverting input fixed
  165. #define COMP_POLL_PERIOD_Pos (4)
  166. #define COMP_POLL_PERIOD (0x07U << COMP_POLL_PERIOD_Pos) ///< polling wait cycle
  167. #define COMP_POLL_PERIOD_1 (0x00U << COMP_POLL_PERIOD_Pos) ///< 1 clock cycle
  168. #define COMP_POLL_PERIOD_2 (0x01U << COMP_POLL_PERIOD_Pos) ///< 2 clock cycle
  169. #define COMP_POLL_PERIOD_4 (0x02U << COMP_POLL_PERIOD_Pos) ///< 4 clock cycle
  170. #define COMP_POLL_PERIOD_8 (0x03U << COMP_POLL_PERIOD_Pos) ///< 8 clock cycle
  171. #define COMP_POLL_PERIOD_16 (0x04U << COMP_POLL_PERIOD_Pos) ///< 16 clock cycle
  172. #define COMP_POLL_PERIOD_32 (0x05U << COMP_POLL_PERIOD_Pos) ///< 32 clock cycle
  173. #define COMP_POLL_PERIOD_64 (0x06U << COMP_POLL_PERIOD_Pos) ///< 64 clock cycle
  174. #define COMP_POLL_PERIOD_128 (0x07U << COMP_POLL_PERIOD_Pos) ///< 128 clock cycle
  175. #define COMP_POLL_POUT_Pos (8)
  176. #define COMP_POLL_POUT (0x07U << COMP_POLL_POUT_Pos) ///< Polling output
  177. #define COMP_POLL_POUT_Low (0x00U << COMP_POLL_POUT_Pos) ///< Non-inverting input is lower than inverting input
  178. #define COMP_POLL_POUT_High (0x01U << COMP_POLL_POUT_Pos) ///< Non-inverting input is higher than inverting input
  179. /// @}
  180. /// @}
  181. /// @}
  182. ////////////////////////////////////////////////////////////////////////////////
  183. #endif
  184. ////////////////////////////////////////////////////////////////////////////////