1 /** 2 ****************************************************************************** 3 * @file HAL_comp.h 4 * @author AE Team 5 * @version V2.0.0 6 * @date 22/08/2017 7 * @brief This file contains all the functions prototypes for the COMP firmware 8 * library. 9 ****************************************************************************** 10 * @attention 11 * 12 * <h2><center>© 2017 MindMotion</center></h2> 13 ****************************************************************************** 14 */ 15 16 /* Define to prevent recursive inclusion -------------------------------------*/ 17 #ifndef __HAL_COMP_H 18 #define __HAL_COMP_H 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /* Includes ------------------------------------------------------------------*/ 25 #include "HAL_device.h" 26 27 /** @addtogroup 28 * @{ 29 */ 30 31 /** @addtogroup COMP 32 * @{ 33 */ 34 35 /* Exported types ------------------------------------------------------------*/ 36 37 /** 38 * @brief COMP Init structure definition 39 */ 40 41 typedef struct 42 { 43 44 uint32_t COMP_InvertingInput; /*!< Selects the inverting input of the comparator. 45 This parameter can be a value of @ref COMP_InvertingInput */ 46 47 uint32_t COMP_NonInvertingInput; /*!< Selects the non inverting input of the comparator. 48 This parameter can be a value of @ref COMP_NonInvertingInput */ 49 50 uint32_t COMP_Output; /*!< Selects the output redirection of the comparator. 51 This parameter can be a value of @ref COMP_Output */ 52 53 uint32_t COMP_BlankingSrce; /*!< Selects the output blanking source of the comparator. 54 This parameter can be a value of @ref COMP_BlankingSrce */ 55 56 uint32_t COMP_OutputPol; /*!< Selects the output polarity of the comparator. 57 This parameter can be a value of @ref COMP_OutputPoloarity */ 58 59 uint32_t COMP_Hysteresis; /*!< Selects the hysteresis voltage of the comparator. 60 This parameter can be a value of @ref COMP_Hysteresis */ 61 62 uint32_t COMP_Mode; /*!< Selects the operating mode of the comparator 63 and allows to adjust the speed/consumption. 64 This parameter can be a value of @ref COMP_Mode */ 65 66 }COMP_InitTypeDef; 67 68 /* Exported constants --------------------------------------------------------*/ 69 70 /** @defgroup COMP_Exported_Constants 71 * @{ 72 */ 73 74 /** @defgroup COMP_Selection 75 * @{ 76 */ 77 78 #define COMP_Selection_COMP1 ((uint32_t)0x00000000) /*!< COMP1 Selection */ 79 #define COMP_Selection_COMP2 ((uint32_t)0x00000004) /*!< COMP2 Selection */ 80 81 82 #define IS_COMP_ALL_PERIPH(PERIPH) (((PERIPH) == COMP_Selection_COMP1) || \ 83 ((PERIPH) == COMP_Selection_COMP2)) 84 85 /** 86 * @} 87 */ 88 89 /** @defgroup COMP_InvertingInput 90 * @{ 91 */ 92 93 #define COMP_InvertingInput_1_4VREFINT ((uint32_t)0x00000000) /*!< 1/4 VREFINT connected to comparator inverting input */ 94 #define COMP_InvertingInput_1_2VREFINT ((uint32_t)0x00000010) /*!< 1/2 VREFINT connected to comparator inverting input */ 95 #define COMP_InvertingInput_3_4VREFINT ((uint32_t)0x00000020) /*!< 3/4 VREFINT connected to comparator inverting input */ 96 #define COMP_InvertingInput_VREFINT ((uint32_t)0x00000030) /*!< VREFINT connected to comparator inverting input */ 97 #define COMP_InvertingInput_DAC1 ((uint32_t)0x00000040) /*!< DAC1_OUT (PA4) connected to comparator inverting input */ 98 #define COMP_InvertingInput_DAC2 ((uint32_t)0x00000050) /*!< DAC2_OUT (PA5) connected to comparator inverting input */ 99 #define COMP_InvertingInput_IO1 ((uint32_t)0x00000060) /*!< I/O1 (PA0 for COMP1, PA2 for COMP2) connected to comparator inverting input */ 100 #define COMP_InvertingInput_IO2 ((uint32_t)0x00000070) /*!< I/O2 (PA6 for COMP1, PA6 for COMP2) connected to comparator inverting input */ 101 102 103 #define IS_COMP_INVERTING_INPUT(INPUT) (((INPUT) == COMP_InvertingInput_1_4VREFINT) || \ 104 ((INPUT) == COMP_InvertingInput_1_2VREFINT) || \ 105 ((INPUT) == COMP_InvertingInput_3_4VREFINT) || \ 106 ((INPUT) == COMP_InvertingInput_VREFINT) || \ 107 ((INPUT) == COMP_InvertingInput_DAC1) || \ 108 ((INPUT) == COMP_InvertingInput_DAC2) || \ 109 ((INPUT) == COMP_InvertingInput_IO1) || \ 110 ((INPUT) == COMP_InvertingInput_IO2)) 111 /** 112 * @} 113 */ 114 115 /** @defgroup COMP_NonInvertingInput 116 * @{ 117 */ 118 119 #define COMP_NonInvertingInput_IO1 ((uint32_t)0x00000000) /*!< I/O1 (PA0 for COMP1, PA0 for COMP2) connected to comparator non inverting input */ 120 121 #define COMP_NonInvertingInput_IO2 ((uint32_t)0x00000080) /*!< I/O2 (PA1 for COMP1, PA1 for COMP2) connected to comparator non inverting input */ 122 123 #define COMP_NonInvertingInput_IO3 ((uint32_t)0x00000100) /*!< I/O2 (PA2 for COMP1, PA2 for COMP2) connected to comparator non inverting input */ 124 125 #define COMP_NonInvertingInput_IO4 ((uint32_t)0x00000180) /*!< I/O2 (PA3 for COMP1, PA3 for COMP2) connected to comparator non inverting input */ 126 127 #define COMP_NonInvertingInput_IO5 ((uint32_t)0x00000200) /*!< I/O2 (PA4 for COMP1, PA4 for COMP2) connected to comparator non inverting input */ 128 129 #define COMP_NonInvertingInput_IO6 ((uint32_t)0x00000280) /*!< I/O2 (PA5 for COMP1, PA5 for COMP2) connected to comparator non inverting input */ 130 131 #define COMP_NonInvertingInput_IO7 ((uint32_t)0x00000300) /*!< I/O2 (PA6 for COMP1, PA6 for COMP2) connected to comparator non inverting input */ 132 133 #define COMP_NonInvertingInput_IO8 ((uint32_t)0x00000380) /*!< I/O2 (PA7 for COMP1, PA7 for COMP2) connected to comparator non inverting input */ 134 135 #define IS_COMP_NONINVERTING_INPUT(INPUT) (((INPUT) == COMP_NonInvertingInput_IO1) || \ 136 ((INPUT) == COMP_NonInvertingInput_IO1) || \ 137 ((INPUT) == COMP_NonInvertingInput_IO2) || \ 138 ((INPUT) == COMP_NonInvertingInput_IO3) || \ 139 ((INPUT) == COMP_NonInvertingInput_IO4) || \ 140 ((INPUT) == COMP_NonInvertingInput_IO5) || \ 141 ((INPUT) == COMP_NonInvertingInput_IO6) || \ 142 ((INPUT) == COMP_NonInvertingInput_IO7) || \ 143 ((INPUT) == COMP_NonInvertingInput_IO8)) 144 145 /** 146 * @} 147 */ 148 149 /** @defgroup COMP_Output 150 * @{ 151 */ 152 153 #define COMP_Output_None ((uint32_t)0x00000000) /*!< COMP output isn't connected to other peripherals */ 154 155 /* Output Redirection common for all comparators COMP1...COMP2 */ 156 #define COMP_Output_TIM1BKIN ((uint32_t)0x00000800) /*!< COMP output connected to TIM1 Break Input (BKIN) */ 157 158 /* Output Redirection common for COMP1 and COMP2 */ 159 #define COMP_Output_TIM1OCREFCLR ((uint32_t)0x00001800) /*!< COMP output connected to TIM1 OCREF Clear */ 160 #define COMP_Output_TIM1IC1 ((uint32_t)0x00001C00) /*!< COMP output connected to TIM1 Input Capture 1 */ 161 #define COMP_Output_TIM2IC4 ((uint32_t)0x00002000) /*!< COMP output connected to TIM2 Input Capture 4 */ 162 #define COMP_Output_TIM2OCREFCLR ((uint32_t)0x00002400) /*!< COMP output connected to TIM2 OCREF Clear */ 163 #define COMP_Output_TIM3IC1 ((uint32_t)0x00002800) /*!< COMP output connected to TIM3 Input Capture 1 */ 164 #define COMP_Output_TIM3OCREFCLR ((uint32_t)0x00002C00) /*!< COMP output connected to TIM3 OCREF Clear */ 165 166 167 #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_Output_None) || \ 168 ((OUTPUT) == COMP_Output_TIM1BKIN) || \ 169 ((OUTPUT) == COMP_Output_TIM1IC1) || \ 170 ((OUTPUT) == COMP_Output_TIM1OCREFCLR) || \ 171 ((OUTPUT) == COMP_Output_TIM2IC4) || \ 172 ((OUTPUT) == COMP_Output_TIM2OCREFCLR) || \ 173 ((OUTPUT) == COMP_Output_TIM3IC1) || \ 174 ((OUTPUT) == COMP_Output_TIM3OCREFCLR)) 175 176 /** 177 * @} 178 */ 179 180 /** @defgroup COMP_BlankingSrce 181 * @{ 182 */ 183 184 /* No blanking source can be selected for all comparators */ 185 #define COMP_BlankingSrce_None ((uint32_t)0x00000000) /*!< No blanking source */ 186 187 188 #define IS_COMP_BLANKING_SOURCE(SOURCE) (((SOURCE) == COMP_BlankingSrce_None)) 189 190 /** 191 * @} 192 */ 193 194 /** @defgroup COMP_OutputPoloarity 195 * @{ 196 */ 197 #define COMP_OutputPol_NonInverted ((uint32_t)0x00000000) /*!< COMP output on GPIO isn't inverted */ 198 #define COMP_OutputPol_Inverted ((uint32_t)0x00008000) /*!< COMP output on GPIO is inverted */ 199 200 #define IS_COMP_OUTPUT_POL(POL) (((POL) == COMP_OutputPol_NonInverted) || \ 201 ((POL) == COMP_OutputPol_Inverted)) 202 203 /** 204 * @} 205 */ 206 207 /** @defgroup COMP_Hysteresis 208 * @{ 209 */ 210 /* Please refer to the electrical characteristics in the device datasheet for 211 the hysteresis level */ 212 #define COMP_Hysteresis_No 0x00000000 /*!< No hysteresis */ 213 #define COMP_Hysteresis_Low ((uint32_t)0x00010000) /*!< Hysteresis level low */ 214 #define COMP_Hysteresis_Medium ((uint32_t)0x00020000) /*!< Hysteresis level medium */ 215 #define COMP_Hysteresis_High ((uint32_t)0x00030000) /*!< Hysteresis level high */ 216 217 #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_Hysteresis_No) || \ 218 ((HYSTERESIS) == COMP_Hysteresis_Low) || \ 219 ((HYSTERESIS) == COMP_Hysteresis_Medium) || \ 220 ((HYSTERESIS) == COMP_Hysteresis_High)) 221 /** 222 * @} 223 */ 224 225 /** @defgroup COMP_Mode 226 * @{ 227 */ 228 /* Please refer to the electrical characteristics in the device datasheet for 229 the power consumption values */ 230 #define COMP_Mode_HighSpeed ((uint32_t)0x0000000C) /*!< High Speed */ 231 #define COMP_Mode_MediumSpeed ((uint32_t)0x00000008) /*!< Medium Speed */ 232 #define COMP_Mode_LowPower ((uint32_t)0x00000004) /*!< Low power mode */ 233 #define COMP_Mode_UltraLowPower 0x00000000 /*!< Ultra-low power mode */ 234 235 #define IS_COMP_MODE(MODE) (((MODE) == COMP_Mode_UltraLowPower) || \ 236 ((MODE) == COMP_Mode_LowPower) || \ 237 ((MODE) == COMP_Mode_MediumSpeed) || \ 238 ((MODE) == COMP_Mode_HighSpeed)) 239 /** 240 * @} 241 */ 242 243 /** @defgroup COMP_OutputLevel 244 * @{ 245 */ 246 /* When output polarity is not inverted, comparator output is high when 247 the non-inverting input is at a higher voltage than the inverting input */ 248 #define COMP_OutputLevel_High ((uint32_t)0x40000000) 249 /* When output polarity is not inverted, comparator output is low when 250 the non-inverting input is at a lower voltage than the inverting input*/ 251 #define COMP_OutputLevel_Low ((uint32_t)0x00000000) 252 253 /** 254 * @} 255 */ 256 257 /** @defgroup COMP_WindowMode 258 * @{ 259 */ 260 #define IS_COMP_WINDOW(WINDOW) (((WINDOW) == COMP_Selection_COMP2) || \ 261 ((WINDOW) == COMP_Selection_COMP4) || \ 262 ((WINDOW) == COMP_Selection_COMP6)) 263 /** 264 * @} 265 */ 266 267 /** 268 * @} 269 */ 270 271 /* Exported macro ------------------------------------------------------------*/ 272 /* Exported functions ------------------------------------------------------- */ 273 274 /* Function used to set the COMP configuration to the default reset state ****/ 275 void COMP_DeInit(uint32_t COMP_Selection); 276 277 /* Initialization and Configuration functions *********************************/ 278 void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct); 279 void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct); 280 void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState); 281 void COMP_SwitchCmd(uint32_t COMP_Selection, FunctionalState NewState); 282 uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection); 283 284 /* COMP configuration locking function ****************************************/ 285 void COMP_LockConfig(uint32_t COMP_Selection); 286 287 #ifdef __cplusplus 288 } 289 #endif 290 291 #endif /*__HAL_COMP_H */ 292 293 /** 294 * @} 295 */ 296 297 /** 298 * @} 299 */ 300 301 /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/ 302