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