1 /*********************************************************************************************************//** 2 * @file ht32f5xxxx_cmp.h 3 * @version $Rev:: 8260 $ 4 * @date $Date:: 2024-11-05 #$ 5 * @brief The header file of the CMP library. 6 ************************************************************************************************************* 7 * @attention 8 * 9 * Firmware Disclaimer Information 10 * 11 * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the 12 * code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the 13 * proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and 14 * other intellectual property laws. 15 * 16 * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the 17 * code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties 18 * other than HOLTEK and the customer. 19 * 20 * 3. The program technical documentation, including the code, is provided "as is" and for customer reference 21 * only. After delivery by HOLTEK, the customer shall use the program technical documentation, including 22 * the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including 23 * the warranties of merchantability, satisfactory quality and fitness for a particular purpose. 24 * 25 * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2> 26 ************************************************************************************************************/ 27 28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/ 29 #ifndef __HT32F5XXXX_CMP_H 30 #define __HT32F5XXXX_CMP_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* Includes ------------------------------------------------------------------------------------------------*/ 37 #include "ht32.h" 38 39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver 40 * @{ 41 */ 42 43 /** @addtogroup CMP 44 * @{ 45 */ 46 47 48 /* Exported types ------------------------------------------------------------------------------------------*/ 49 /** @defgroup CMP_Exported_Types CMP exported types 50 * @{ 51 */ 52 53 typedef struct 54 { 55 u32 CMP_Wakeup; 56 u32 CMP_OutputSelection; 57 u32 CMP_ScalerSource; 58 u32 CMP_ScalerOutputBuf; 59 u32 CMP_ScalerEnable; 60 u32 CMP_CoutSync; 61 u32 CMP_OutputPol; 62 #if (LIBCFG_CMP_65x_66x_VER) 63 u32 CMP_InputSelection; 64 #endif 65 u32 CMP_InvInputSelection; 66 u32 CMP_Hysteresis; 67 u32 CMP_Speed; 68 } CMP_InitTypeDef; 69 70 #if (LIBCFG_CMP_CO) 71 typedef enum 72 { 73 CMP_SYNCOUT_CMPnO = 0, 74 CMP_SYNCOUT_MCTM_CH0O = 1, 75 CMP_SYNCOUT_MCTM_CH0NO = 2, 76 CMP_SYNCOUT_MCTM_CH1O = 3, 77 CMP_SYNCOUT_MCTM_CH1NO = 4, 78 CMP_SYNCOUT_MCTM_CH2O = 5, 79 CMP_SYNCOUT_MCTM_CH2NO = 6, 80 CMP_SYNCOUT_MCTM_CH3O = 7, 81 CMP_SYNCOUT_MCTM_CH3OB = 8, // Inverted of MCTM_CH3O 82 } CMP_SYNCOUT_Enum; 83 #endif 84 85 /** 86 * @} 87 */ 88 89 /* Exported constants --------------------------------------------------------------------------------------*/ 90 /** @defgroup CMP_Exported_Constants CMP exported constants 91 * @{ 92 */ 93 94 /* Definitions of CMP Protection Key */ 95 #define CMP_PROTECT_KEY ((u32)0x9C3A0000) 96 97 98 /* Definitions of CMP Output Status */ 99 #define CMP_OUTPUT_HIGH ((u32)0x00008000) 100 #define CMP_OUTPUT_LOW ((u32)0x00000000) 101 102 103 /* Definitions of CMP Wakeup Control Bit */ 104 #define CMP_WUP_ENABLE ((u32)0x00004000) 105 #define CMP_WUP_DISABLE ((u32)0x00000000) 106 107 #define IS_CMP_Wakeup_Set(x) ((x == CMP_WUP_ENABLE) || (x == CMP_WUP_DISABLE)) 108 109 110 /* Definitions of CMP Output Selection for IP Trigger Source */ 111 #if (LIBCFG_CMP_65x_66x_VER) 112 #define CMP_TRIG_NONE ((u32)0x0 << 11) 113 #define CMP_TRIG_GPTM_CH0 ((u32)0x1 << 11) // CMP0 114 #define CMP_TRIG_GPTM_CH1 ((u32)0x1 << 11) // CMP1 115 116 #define IS_CMP_OutputSelection2(x) (0) 117 #if (LIBCFG_CMP2) 118 #define CMP_TRIG_GPTM_CH2 ((u32)0x1 << 11) // CMP2 119 #undef IS_CMP_OutputSelection2 120 #define IS_CMP_OutputSelection2(x) (x == CMP_TRIG_GPTM_CH2) 121 #endif 122 123 #define CMP_TRIG_GPTM_CH3 ((u32)0x2 << 11) 124 #define CMP_TRIG_SCTM ((u32)0x3 << 11) 125 #define CMP_TRIG_MCTM_CH3 ((u32)0x4 << 11) 126 #define CMP_TRIG_MCTM_BK0 ((u32)0x5 << 11) 127 #define CMP_TRIG_MCTM_BK1 ((u32)0x6 << 11) 128 #define CMP_TRIG_ADC ((u32)0x7 << 11) 129 130 #define IS_CMP_OutputSelection(x) ((x == CMP_TRIG_NONE) || \ 131 (x == CMP_TRIG_GPTM_CH0) || \ 132 (x == CMP_TRIG_GPTM_CH1) || \ 133 IS_CMP_OutputSelection2(x) || \ 134 (x == CMP_TRIG_GPTM_CH3) || \ 135 (x == CMP_TRIG_SCTM) || \ 136 (x == CMP_TRIG_MCTM_CH3) || \ 137 (x == CMP_TRIG_MCTM_BK0) || \ 138 (x == CMP_TRIG_MCTM_BK1) || \ 139 (x == CMP_TRIG_ADC)) 140 #else 141 #define CMP_TRIG_NONE ((u32)0x0 << 11) 142 #define CMP_TRIG_GPTM_CH3 ((u32)0x1 << 11) 143 #if (LIBCFG_MCTM0) 144 #define CMP_TRIG_MCTM_CH3 ((u32)0x2 << 11) 145 #define CMP_TRIG_MCTM_BK1 ((u32)0x3 << 11) 146 #endif 147 #define CMP_TRIG_ADC ((u32)0x4 << 11) 148 149 #if (LIBCFG_MCTM0) 150 #define IS_CMP_OutSelMCTM(x) ((x == CMP_TRIG_MCTM_CH3) || (x == CMP_TRIG_MCTM_BK1)) 151 #else 152 #define IS_CMP_OutSelMCTM(x) (0) 153 #endif 154 155 #define IS_CMP_OutputSelection(x) ((x == CMP_TRIG_NONE) || \ 156 (x == CMP_TRIG_GPTM_CH3) || \ 157 IS_CMP_OutSelMCTM(x) || \ 158 (x == CMP_TRIG_ADC)) 159 #endif 160 161 /* Definitions of CMP Scaler Source Selection */ 162 #define CMP_SCALER_SRC_VDDA ((u32)0x00000000) 163 164 #if (LIBCFG_CMP_NOSCALER_SRC) 165 #define IS_CMP_ScalerSource(x) ((x == CMP_SCALER_SRC_VDDA)) 166 #else 167 #define CMP_SCALER_SRC_VREF ((u32)0x00000400) 168 #define IS_CMP_ScalerSource(x) ((x == CMP_SCALER_SRC_VDDA) || (x == CMP_SCALER_SRC_VREF)) 169 #endif 170 171 172 /* Definitions of CMP Scaler Output Enable Bit */ 173 #define CMP_SCALER_OBUF_DISABLE ((u32)0x00000000) 174 #define CMP_SCALER_OBUF_ENABLE ((u32)0x00000200) 175 176 #define IS_CMP_ScalerOutputBuf(x) ((x == CMP_SCALER_OBUF_DISABLE) || (x == CMP_SCALER_OBUF_ENABLE)) 177 178 179 /* Definitions of CMP Scaler Enable Bit */ 180 #define CMP_SCALER_DISABLE ((u32)0x00000000) 181 #define CMP_SCALER_ENABLE ((u32)0x00000100) 182 183 #define IS_CMP_ScalerEnable(x) ((x == CMP_SCALER_DISABLE) || (x == CMP_SCALER_ENABLE)) 184 185 186 /* Definitions of CMP Sync Output Enable bit */ 187 #define CMP_ASYNC_OUTPUT ((u32)0x00000000) 188 #define CMP_SYNC_OUTPUT ((u32)0x00000080) 189 190 #define IS_CMP_CoutSynchronized(x) ((x == CMP_ASYNC_OUTPUT) || (x == CMP_SYNC_OUTPUT)) 191 192 193 /* Definitions of CMP Output Polarity Selection */ 194 #define CMP_NONINV_OUTPUT ((u32)0x00000000) 195 #define CMP_INV_OUTPUT ((u32)0x00000040) 196 197 #define IS_CMP_OutputPol_Set(x) ((x == CMP_NONINV_OUTPUT) || (x == CMP_INV_OUTPUT)) 198 199 200 /* Definitions of CMP Inverted Input Source Selection */ 201 #if (LIBCFG_CMP_65x_66x_VER) 202 #if (LIBCFG_CMP_POS_INPUT_SEL_V2) 203 #define CMP_INPUT_CMPnP ((u32)0x00000000) 204 #define CMP_INPUT_CMPnP0 ((u32)0x00000000) 205 #define CMP_INPUT_CMPnP1 ((u32)0x00000001) 206 #define CMP_INPUT_CMPnP2 ((u32)0x00000002) 207 #define CMP_INPUT_OPA0O ((u32)0x00000003) 208 209 #define IS_CMP_InputSelection(x) ((x == CMP_INPUT_CMPnP) || \ 210 (x == CMP_INPUT_CMPnP0) || \ 211 (x == CMP_INPUT_CMPnP1) || \ 212 (x == CMP_INPUT_CMPnP2) || \ 213 (x == CMP_INPUT_OPA0O)) 214 #elif (LIBCFG_CMP_POS_INPUT_SEL_V3) 215 #define CMP_INPUT_CMP0P ((u32)0x00000000) 216 #define CMP_INPUT_CMP0P0 ((u32)0x00000000) 217 #define CMP_INPUT_CMP1P0 ((u32)0x00000001) 218 #define CMP_INPUT_CMP1P1 ((u32)0x00000002) 219 #define CMP_INPUT_CMP1P2 ((u32)0x00000003) 220 #define CMP_INPUT_PGA0O ((u32)0x00000004) 221 #define CMP_INPUT_PGA1O ((u32)0x00000005) 222 #define CMP_INPUT_PGA2O ((u32)0x00000006) 223 #define CMP_INPUT_PGA3O ((u32)0x00000007) 224 225 #define IS_CMP_InputSelection(x) ((x == CMP_INPUT_CMP0P) || \ 226 (x == CMP_INPUT_CMP0P0) || \ 227 (x == CMP_INPUT_CMP1P0) || \ 228 (x == CMP_INPUT_CMP1P1) || \ 229 (x == CMP_INPUT_CMP1P2) || \ 230 (x == CMP_INPUT_PGA0O) || \ 231 (x == CMP_INPUT_PGA1O) || \ 232 (x == CMP_INPUT_PGA2O) || \ 233 (x == CMP_INPUT_PGA3O)) 234 #else 235 #define CMP_INPUT_CMPnP ((u32)0x00000000) 236 #define CMP_INPUT_OPA0O ((u32)0x00000001) 237 #define CMP_INPUT_OPA1O ((u32)0x00000002) 238 239 #define IS_CMP_InputSelection(x) ((x == CMP_INPUT_CMPnP) || (x == CMP_INPUT_OPA0O) || (x == CMP_INPUT_OPA1O)) 240 #endif 241 #endif 242 243 244 /* Definitions of CMP Inverted Input Source Selection */ 245 #define CMP_EXTERNAL_CN_IN ((u32)0x00000000) 246 247 #if defined(USE_HT32F66242) || defined(USE_HT32F66246) 248 #define CMP0_CMP0N_CN_IN ((u32)0x00000000) 249 #define CMP1_CMP1N_CN_IN ((u32)0x00000000) 250 251 #define CMP0_CMP1N_CN_IN ((u32)0x00000010) 252 #define CMP1_CMP0N_CN_IN ((u32)0x00000010) 253 254 #define CMP_CVREF0_CN_IN ((u32)0x00000020) 255 #define CMP_CVREF1_CN_IN ((u32)0x00000030) 256 257 #define IS_CMP_InvInputSelection(x) ((x == CMP_EXTERNAL_CN_IN) || (x == CMP0_CMP0N_CN_IN) || (x == CMP1_CMP1N_CN_IN) || \ 258 (x == CMP0_CMP1N_CN_IN) || (x == CMP1_CMP0N_CN_IN) || \ 259 (x == CMP_CVREF0_CN_IN) || \ 260 (x == CMP_CVREF1_CN_IN)) 261 #else 262 #define CMP_SCALER_CN_IN ((u32)0x00000010) 263 264 #define IS_CMP_InvInSel2(x) (0) 265 266 #if (LIBCFG_CMP_IVREF_CN_IN) 267 #define CMP_IVREF_CN_IN ((u32)0x00000020) 268 #undef IS_CMP_InvInSel2 269 #define IS_CMP_InvInSel2(x) ((x == CMP_IVREF_CN_IN)) 270 #endif 271 272 #if defined(USE_HT32F65230_40) 273 #define CMP_CMP0N_CN_IN ((u32)0x00000020) 274 #undef IS_CMP_InvInSel2 275 #define IS_CMP_InvInSel2(x) ((x == CMP_CMP0N_CN_IN)) 276 #endif 277 278 #if defined(USE_HT32F65232) 279 #define CMP0_CMP1N_CN_IN ((u32)0x00000020) 280 #define CMP1_CMP0N_CN_IN ((u32)0x00000020) 281 #undef IS_CMP_InvInSel2 282 #define IS_CMP_InvInSel2(x) ((x == CMP0_CMP1N_CN_IN)) 283 #endif 284 285 #define IS_CMP_InvInputSelection(x) ((x == CMP_EXTERNAL_CN_IN) || (x == CMP_SCALER_CN_IN) || IS_CMP_InvInSel2(x)) 286 #endif 287 288 289 /* Definitions of CMP Hysteresis Level Selection */ 290 #define CMP_NO_HYSTERESIS ((u32)0x00000000) 291 #define CMP_LOW_HYSTERESIS ((u32)0x00000004) 292 #define CMP_MID_HYSTERESIS ((u32)0x00000008) 293 #define CMP_HIGH_HYSTERESIS ((u32)0x0000000C) 294 295 #define IS_CMP_Hysteresis_Set(x) ((x == CMP_NO_HYSTERESIS) || (x == CMP_LOW_HYSTERESIS) || (x == CMP_MID_HYSTERESIS) || \ 296 (x == CMP_HIGH_HYSTERESIS)) 297 298 /* Definitions of CMP Speed Mode Selection */ 299 #define CMP_HIGH_SPEED ((u32)0x00000002) 300 #define CMP_LOW_SPEED ((u32)0x00000000) 301 302 #define IS_CMP_Speed_Set(x) ((x == CMP_HIGH_SPEED) || (x == CMP_LOW_SPEED)) 303 304 305 /* Definitions of CMP Enable bit */ 306 #define CMP_ENABLE ((u32)0x00000001) 307 308 309 /* Definitions of CMP Output Edge Interrupt Enable bit */ 310 #define CMP_INT_RE ((u32)0x00000002) 311 #define CMP_INT_FE ((u32)0x00000001) 312 313 /* Check the CMP Interrupt Parameter */ 314 #define IS_CMP_INT(x) ((x & 0xFFFFFF00) != 0x0) 315 316 317 /* Definitions of CMP Output Edge Detection Enable bit */ 318 #define CMP_RE_Detect ((u32)0x00000200) 319 #define CMP_FE_Detect ((u32)0x00000100) 320 321 #define IS_CMP_EdgeDetect(x) ((x == CMP_RE_Detect) || (x == CMP_FE_Detect)) 322 323 324 /* Definitions of CMP Output Edge Flag */ 325 #define CMP_FLAG_RE ((u32)0x00000002) 326 #define CMP_FLAG_FE ((u32)0x00000001) 327 328 /* Check the CMP flag Parameter */ 329 #define IS_CMP_FLAG(x) ((x & 0xFFFFFF00) != 0x0) 330 331 332 /* Check the CMPx Parameter */ 333 #if (LIBCFG_CMP2) 334 #define IS_CMP2(x) (x == HT_CMP2) 335 #else 336 #define IS_CMP2(x) (0) 337 #endif 338 #define IS_CMP(x) ((x == HT_CMP0) || (x == HT_CMP1) || IS_CMP2(x)) 339 340 341 /* Check the Scaler Value */ 342 #if (LIBCFG_CMP_SCALER_8BIT) 343 #define IS_SCALER_VALUE(x) (x <= 0xFF) 344 #else 345 #define IS_SCALER_VALUE(x) (x <= 0x3F) 346 #endif 347 348 #if (LIBCFG_CMP_CO) 349 #define IS_CMP_SYNC_SOURCE(x) ((x == CMP_SYNCOUT_CMPnO) || \ 350 (x == CMP_SYNCOUT_MCTM_CH0O) || \ 351 (x == CMP_SYNCOUT_MCTM_CH0NO) || \ 352 (x == CMP_SYNCOUT_MCTM_CH1O) || \ 353 (x == CMP_SYNCOUT_MCTM_CH1NO) || \ 354 (x == CMP_SYNCOUT_MCTM_CH2O) || \ 355 (x == CMP_SYNCOUT_MCTM_CH2NO) || \ 356 (x == CMP_SYNCOUT_MCTM_CH3O) || \ 357 (x == CMP_SYNCOUT_MCTM_CH3OB)) 358 #endif 359 360 /** 361 * @} 362 */ 363 364 /* Exported functions --------------------------------------------------------------------------------------*/ 365 /** @defgroup CMP_Exported_Functions CMP exported functions 366 * @{ 367 */ 368 void CMP_DeInit(HT_CMP_TypeDef* HT_CMPn); 369 void CMP_UnprotectConfig(HT_CMP_TypeDef* HT_CMPn); 370 void CMP_Init(HT_CMP_TypeDef* HT_CMPn, CMP_InitTypeDef* CMP_InitStruct); 371 void CMP_StructInit(CMP_InitTypeDef* CMP_InitStruct); 372 void CMP_Cmd(HT_CMP_TypeDef* HT_CMPn, ControlStatus NewState); 373 void CMP_IntConfig(HT_CMP_TypeDef* HT_CMPn, u32 CMP_INT_x, ControlStatus NewState); 374 void CMP_EdgeDetectConfig(HT_CMP_TypeDef* HT_CMPn, u32 CMP_xE_Detect, ControlStatus NewState); 375 FlagStatus CMP_GetFlagStatus(HT_CMP_TypeDef* HT_CMPn, u32 CMP_FLAG_x); 376 void CMP_ClearFlag(HT_CMP_TypeDef* HT_CMPn, u32 CMP_FLAG_x); 377 FlagStatus CMP_GetOutputStatus(HT_CMP_TypeDef* HT_CMPn); 378 void CMP_SetScalerValue(HT_CMP_TypeDef* HT_CMPn, u8 Scaler_Value); 379 #if (LIBCFG_CMP_CO) 380 void CMP_Output_SyncSource_Select(HT_CMP_TypeDef* HT_CMPn, CMP_SYNCOUT_Enum CMP_SYNCOUT_x); 381 #endif 382 /** 383 * @} 384 */ 385 386 387 /** 388 * @} 389 */ 390 391 /** 392 * @} 393 */ 394 395 #ifdef __cplusplus 396 } 397 #endif 398 399 #endif 400