ft32f0xx_comp.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_comp.h
  4. * @author FMD AE
  5. * @brief This file contains all the functions prototypes for the COMP firmware
  6. * library
  7. * @version V1.0.0
  8. * @data 2021-07-01
  9. ******************************************************************************
  10. */
  11. /* Define to prevent recursive inclusion -------------------------------------*/
  12. #ifndef __FT32F0XX_COMP_H
  13. #define __FT32F0XX_COMP_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /* Includes ------------------------------------------------------------------*/
  18. #include "ft32f0xx.h"
  19. /** @addtogroup COMP
  20. * @{
  21. */
  22. /* Exported types ------------------------------------------------------------*/
  23. /**
  24. * @brief COMP Init structure definition
  25. */
  26. typedef struct
  27. {
  28. uint32_t COMP_VipSel; /*!< Select the positive input of the comparator.
  29. This parameter can be a value of @ref COMP_VipSel */
  30. uint32_t COMP_VinSel; /*!< Select the negative input of the comparator.
  31. This parameter can be a value of @ref COMP_VinSel */
  32. uint32_t COMP_OutputSel; /*!< Selects The output selection of the comparator.
  33. This parameter can be a value of @ref COMP_OutputSel */
  34. uint32_t COMP_Pol; /*!< Select the output polarity of the comparator.
  35. This parameter can be a value of @ref COMP_Pol */
  36. }COMP_InitTypeDef;
  37. /* Exported constants --------------------------------------------------------*/
  38. /** @defgroup COMP_Exported_Constants
  39. * @{
  40. */
  41. /** @defgroup COMP_Selection
  42. * @{
  43. */
  44. #define NCOMP_Selection_COMP ((uint32_t)0x00000000) /*!< NCOMP Selection */
  45. #define PCOMP_Selection_COMP ((uint32_t)0x00000010) /*!< PCOMP Selection */
  46. #define COMP_Selection_COMP3 ((uint32_t)0x00000001) /*!< PCOMP Selection */
  47. #define IS_COMP_ALL_PERIPH(PERIPH) (((PERIPH) == NCOMP_Selection_COMP) || \
  48. ((PERIPH) == PCOMP_Selection_COMP))
  49. #define COMP_Selection_COMP1 NCOMP_Selection_COMP
  50. #define COMP_Selection_COMP2 PCOMP_Selection_COMP
  51. /**
  52. * @}
  53. */
  54. /** @defgroup COMP_VipSel
  55. * @{
  56. */
  57. #define NCOMP_VIP_SEL_1WIRE ((uint32_t)0x00000000)
  58. #define NCOMP_VIP_SEL_PAD_PA1 ((uint32_t)0x00000002)
  59. #define NCOMP_VIP_SEL_PAD_PA4 ((uint32_t)0x00000004)
  60. #define NCOMP_VIP_SEL_PAD_PA13 ((uint32_t)0x00000006)
  61. #define NCOMP_VIP_SEL_PAD_PB12 ((uint32_t)0x00000008)
  62. #define PCOMP_VIP_SEL_PAD_PA3 ((uint32_t)0x00000000)
  63. #define PCOMP_VIP_SEL_PAD_PA4 ((uint32_t)0x00020000)
  64. #define PCOMP_VIP_SEL_PAD_PA13 ((uint32_t)0x00040000)
  65. #define PCOMP_VIP_SEL_PAD_PB12 ((uint32_t)0x00060000)
  66. #define COMP3_VIP_SEL_PAD_PF5 ((uint32_t)0x00000000)
  67. #define COMP3_VIP_SEL_PAD_PB12 ((uint32_t)0x00000002)
  68. #define COMP3_VIP_SEL_PAD_PA13 ((uint32_t)0x00000004)
  69. #define COMP3_VIP_SEL_PAD_PA4 ((uint32_t)0x00000006)
  70. #define IS_COMP_VIP_SEL(INPUT) (((INPUT) == NCOMP_VIP_SEL_1WIRE) || \
  71. ((INPUT) == NCOMP_VIP_SEL_PAD_PA1) || \
  72. ((INPUT) == NCOMP_VIP_SEL_PAD_PA4) || \
  73. ((INPUT) == NCOMP_VIP_SEL_PAD_PA13) || \
  74. ((INPUT) == NCOMP_VIP_SEL_PAD_PB12) || \
  75. ((INPUT) == PCOMP_VIP_SEL_PAD_PA3) || \
  76. ((INPUT) == PCOMP_VIP_SEL_PAD_PA4) || \
  77. ((INPUT) == PCOMP_VIP_SEL_PAD_PA13) || \
  78. ((INPUT) == PCOMP_VIP_SEL_PAD_PB12) )
  79. /**
  80. * @}
  81. */
  82. /** @defgroup COMP_VinSel
  83. * @{
  84. */
  85. #define NCOMP_VIN_SEL_DAC1_OUT ((uint32_t)0x00000000)
  86. #define NCOMP_VIN_SEL_PAD_PA0 ((uint32_t)0x00000010)
  87. #define NCOMP_VIN_SEL_PAD_PA4 ((uint32_t)0x00000020)
  88. #define NCOMP_VIN_SEL_PAD_PA5 ((uint32_t)0x00000030)
  89. #define PCOMP_VIN_SEL_DAC2_OUT ((uint32_t)0x00000000)
  90. #define PCOMP_VIN_SEL_PAD_PA2 ((uint32_t)0x00080000)
  91. #define PCOMP_VIN_SEL_PAD_PA4 ((uint32_t)0x00100000)
  92. #define PCOMP_VIN_SEL_PAD_PA5 ((uint32_t)0x00180000)
  93. #define COMP3_VIN_SEL_PAD_PF4 ((uint32_t)0x00000000)
  94. #define COMP3_VIN_SEL_DAC2_OUT ((uint32_t)0x00000010)
  95. #define COMP3_VIN_SEL_PAD_PA4 ((uint32_t)0x00000020)
  96. #define COMP3_VIN_SEL_PAD_PA5 ((uint32_t)0x00000030)
  97. #define IS_COMP_VINSEL(INPUT) (((INPUT) == NCOMP_VIN_SEL_DAC1_OUT) || \
  98. ((INPUT) == NCOMP_VIN_SEL_PAD_PA0) || \
  99. ((INPUT) == NCOMP_VIN_SEL_PAD_PA4) || \
  100. ((INPUT) == NCOMP_VIN_SEL_PAD_PA5) || \
  101. ((INPUT) == PCOMP_VIN_SEL_DAC2_OUT)|| \
  102. ((INPUT) == PCOMP_VIN_SEL_PAD_PA2) || \
  103. ((INPUT) == PCOMP_VIN_SEL_PAD_PA4) || \
  104. ((INPUT) == PCOMP_VIN_SEL_PAD_PA5) )
  105. /**
  106. * @}
  107. */
  108. /** @defgroup COMP_OutputSel
  109. * @{
  110. */
  111. #define COMP_OUTPUT_NO_SELECTION ((uint32_t)0x00000000)
  112. #define NCOMP_OUTPUT_SEL_TIM1_CAPTURE1 ((uint32_t)0x00000200)
  113. #define NCOMP_OUTPUT_SEL_TIM1_OCREFCLEAR ((uint32_t)0x00000300)
  114. #define NCOMP_OUTPUT_SEL_TIM3_CAPTURE1 ((uint32_t)0x00000600)
  115. #define NCOMP_OUTPUT_SEL_TIM3_OCREFCLEAR ((uint32_t)0x00000700)
  116. #define PCOMP_OUTPUT_SEL_TIM1_BREAK ((uint32_t)0x01000000)
  117. #define PCOMP_OUTPUT_SEL_TIM1_CAPTURE1 ((uint32_t)0x02000000)
  118. #define PCOMP_OUTPUT_SEL_TIM1_OCREFCLEAR ((uint32_t)0x03000000)
  119. #define PCOMP_OUTPUT_SEL_TIM3_CAPTURE1 ((uint32_t)0x06000000)
  120. #define PCOMP_OUTPUT_SEL_TIM3_OCREFCLEAR ((uint32_t)0x07000000)
  121. #define COMP3_OUTPUT_SEL_TIM1_CAPTURE1 ((uint32_t)0x00000200)
  122. #define COMP3_OUTPUT_SEL_TIM1_OCREFCLEAR ((uint32_t)0x00000300)
  123. #define COMP3_OUTPUT_SEL_TIM3_CAPTURE1 ((uint32_t)0x00000600)
  124. #define COMP3_OUTPUT_SEL_TIM3_OCREFCLEAR ((uint32_t)0x00000700)
  125. #define IS_COMP_OUTPUT_SEL(SEL) ( ((SEL) == NCOMP_OUTPUT_SEL_TIM1_CAPTURE1) || \
  126. ((SEL) == NCOMP_OUTPUT_SEL_TIM1_OCREFCLEAR) ||\
  127. ((SEL) == NCOMP_OUTPUT_SEL_TIM3_CAPTURE1) ||\
  128. ((SEL) == NCOMP_OUTPUT_SEL_TIM3_OCREFCLEAR) ||\
  129. ((SEL) == PCOMP_OUTPUT_SEL_TIM1_BREAK) ||\
  130. ((SEL) == PCOMP_OUTPUT_SEL_TIM1_CAPTURE1) ||\
  131. ((SEL) == PCOMP_OUTPUT_SEL_TIM1_OCREFCLEAR) ||\
  132. ((SEL) == PCOMP_OUTPUT_SEL_TIM3_CAPTURE1) ||\
  133. ((SEL) == PCOMP_OUTPUT_SEL_TIM3_OCREFCLEAR) ||\
  134. ((SEL) == COMP_OUTPUT_NO_SELECTION) )
  135. /**
  136. * @}
  137. */
  138. /** @defgroup COMP_Pol
  139. * @{
  140. */
  141. #define NCOMP_POL_NOT_INVERT ((uint32_t)0x00000000)
  142. #define NCOMP_POL_INVERT ((uint32_t)0x00000800)
  143. #define PCOMP_POL_NOT_INVERT ((uint32_t)0x00000000)
  144. #define PCOMP_POL_INVERT ((uint32_t)0x08000000)
  145. #define COMP3_POL_NOT_INVERT ((uint32_t)0x00000000)
  146. #define COMP3_POL_INVERT ((uint32_t)0x00000800)
  147. #define IS_COMP_POL(POL) ( ((POL) == NCOMP_POL_NOT_INVERT) || \
  148. ((POL) == NCOMP_POL_INVERT) || \
  149. ((POL) == PCOMP_POL_NOT_INVERT) || \
  150. ((POL) == PCOMP_POL_INVERT) )
  151. /**
  152. * @}
  153. */
  154. /**
  155. * @}
  156. */
  157. /** @defgroup COMP_OutputLevel
  158. * @{
  159. */
  160. /* When output polarity is not inverted, comparator output is high when
  161. the non-inverting input is at a higher voltage than the inverting input */
  162. #define COMP_OutputLevel_High COMP_CSR_COMP1OUT
  163. /* When output polarity is not inverted, comparator output is low when
  164. the non-inverting input is at a lower voltage than the inverting input*/
  165. #define COMP_OutputLevel_Low ((uint32_t)0x00000000)
  166. #define IS_COMP_OUTPUT_LEVEL(LEVEL) (((LEVEL) == COMP_CSR_COMP1OUT) || \
  167. ((LEVEL) == COMP_CSR_COMP2OUT))
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. /* Exported macro ------------------------------------------------------------*/
  175. /* Exported functions ------------------------------------------------------- */
  176. /* Function used to set the COMP configuration to the default reset state ****/
  177. void COMP_DeInit(void);
  178. /* Initialization and Configuration functions *********************************/
  179. void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct);
  180. void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct);
  181. void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState);
  182. uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection);
  183. /* Window mode control function ***********************************************/
  184. void COMP_WindowCmd(FunctionalState NewState);
  185. /* COMP configuration locking function ****************************************/
  186. void COMP_LockConfig(uint32_t COMP_Selection);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif /*__FT32F0XX_COMP_H */
  191. /**
  192. * @}
  193. */
  194. /**
  195. * @}
  196. */
  197. /************************ (C) COPYRIGHT FMD *****END OF FILE****/