1 /*! 2 * @file apm32f0xx_comp.h 3 * 4 * @brief This file contains all the functions prototypes for the COMP firmware library 5 * 6 * @version V1.0.3 7 * 8 * @date 2022-09-20 9 * 10 * @attention 11 * 12 * Copyright (C) 2020-2022 Geehy Semiconductor 13 * 14 * You may not use this file except in compliance with the 15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE). 16 * 17 * The program is only for reference, which is distributed in the hope 18 * that it will be useful and instructional for customers to develop 19 * their software. Unless required by applicable law or agreed to in 20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT 21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions 23 * and limitations under the License. 24 */ 25 26 /* Define to prevent recursive inclusion */ 27 #ifndef __APM32F0XX_COMP_H 28 #define __APM32F0XX_COMP_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* Includes */ 35 #include "apm32f0xx.h" 36 37 /** @addtogroup APM32F0xx_StdPeriphDriver 38 @{ 39 */ 40 41 /** @addtogroup COMP_Driver 42 @{ 43 */ 44 45 /** @defgroup COMP_Macros Macros 46 @{ 47 */ 48 49 /* Macros description */ 50 #define COMP_CSTS_COMP1OUT ((uint32_t)0x00004000) /*!< COMP1 output state */ 51 #define COMP_CSTS_COMP2OUT ((uint32_t)0x40000000) /*!< COMP2 output state */ 52 #define COMP_OUTPUTLEVEL_HIGH ((uint32_t)0x00004000) /*!< COMP output level vaild high */ 53 #define COMP_OUTPUTLEVEL_LOW ((uint32_t)0x00000000) /*!< COMP output level vaild low */ 54 55 /**@} end of group COMP_Macros */ 56 57 /** @defgroup COMP_Enumerations Enumerations 58 @{ 59 */ 60 61 /** 62 * @brief COMP_Selection 63 */ 64 typedef enum 65 { 66 COMP_SELECT_COMP1 = ((uint32_t)0x00000000), /*!< COMP1 */ 67 COMP_SELECT_COMP2 = ((uint32_t)0x00000010) /*!< COMP2 */ 68 } COMP_SELECT_T; 69 70 /** 71 * @brief COMP_InvertingInput 72 */ 73 typedef enum 74 { 75 COMP_INVERTING_INPUT_1_4VREFINT = 0x00, /*!< 1/4 of VREFINT */ 76 COMP_INVERTING_INPUT_1_2VREFINT = 0x01, /*!< 1/2 of VREFINT */ 77 COMP_INVERTING_INPUT_3_4VREFINT = 0x02, /*!< 3/4 of VREFINT */ 78 COMP_INVERTING_INPUT_VREFINT = 0x03, /*!< VREFINT */ 79 COMP_INVERTING_INPUT_DAC1 = 0x04, /*!< COMP1_INM4 (PA4 with DAC_OUT1 if enabled) */ 80 COMP_INVERTING_INPUT_DAC2 = 0x05, /*!< COMP1_INM5 (PA5 with DAC_OUT2 if present and enabled, only for APM32F072 and APM32F091 devices) */ 81 COMP_INVERTING_INPUT_IO = 0x06, /*!< COMP1_INM6 (PA0) */ 82 } COMP_INVERTING_INPUT_T; 83 84 /** 85 * @brief COMP_Output 86 */ 87 typedef enum 88 { 89 COMP_OUTPUT_NONE = 0x00, /*!< no selection */ 90 COMP_OUTPUT_TIM1BKIN = 0x01, /*!< Timer 1 break input */ 91 COMP_OUTPUT_TIM1IC1 = 0x02, /*!< Timer 1 Input capture 1 */ 92 COMP_OUTPUT_TIM1OCREFCLR = 0x03, /*!< Timer 1 OCrefclear input */ 93 COMP_OUTPUT_TIM2IC4 = 0x04, /*!< Timer 2 input capture 4 */ 94 COMP_OUTPUT_TIM2OCREFCLR = 0x05, /*!< Timer 2 OCrefclear input */ 95 COMP_OUTPUT_TIM3IC1 = 0x06, /*!< Timer 3 input capture 1 */ 96 COMP_OUTPUT_TIM3OCREFCLR = 0x07, /*!< Timer 3 OCrefclear input */ 97 } COMP_OUTPUT_T; 98 99 /** 100 * @brief COMP_OutputPolarity 101 */ 102 typedef enum 103 { 104 COMP_OUTPUTPOL_NONINVERTED, /*!< output is not inverted */ 105 COMP_OUTPUTPOL_INVERTED /*!< output is inverted */ 106 } COMP_OUTPUTPOL_T; 107 108 /** 109 * @brief COMP_Hysteresis 110 */ 111 typedef enum 112 { 113 COMP_HYSTERRSIS_NO = 0x00, /*!< No hysteresis */ 114 COMP_HYSTERRSIS_LOW = 0x01, /*!< Low hysteresis */ 115 COMP_HYSTERRSIS_MEDIUM = 0x02, /*!< Medium hysteresis */ 116 COMP_HYSTERRSIS_HIGH = 0x03, /*!< High hysteresis */ 117 } COMP_HYSTERRSIS_T; 118 119 /** 120 * @brief COMP_Mode 121 */ 122 typedef enum 123 { 124 COMP_MODE_HIGHSPEED = 0x00, /*!< High speed / full power */ 125 COMP_MODE_MEDIUMSPEED = 0x01, /*!< Medium speed / medium power */ 126 COMP_MODE_LOWPOWER = 0x02, /*!< Low speed / low-power */ 127 COMP_MODE_VERYLOW = 0x03 /*!< Very-low speed / ultra-low power */ 128 } COMP_MODE_T; 129 130 /**@} end of group COMP_Enumerations*/ 131 132 /** @defgroup COMP_Structures Structures 133 @{ 134 */ 135 136 /** 137 * @brief OMP Config structure definition 138 */ 139 typedef struct 140 { 141 COMP_INVERTING_INPUT_T invertingInput; /*!< Comparator inverting input selection */ 142 COMP_OUTPUT_T output; /*!< Comparator output selection */ 143 COMP_OUTPUTPOL_T outputPol; /*!< Comparator output polarity */ 144 COMP_HYSTERRSIS_T hysterrsis; /*!< Comparator hysteresis */ 145 COMP_MODE_T mode; /*!< Comparator mode */ 146 } COMP_Config_T; 147 148 /**@} end of group COMP_Structures */ 149 150 /** @defgroup COMP_Variables Variables 151 @{ 152 */ 153 154 /**@} end of group COMP_Variables */ 155 156 /** @defgroup COMP_Functions Functions 157 @{ 158 */ 159 160 /* COMP configuration */ 161 void COMP_Reset(void); 162 void COMP_Config(COMP_SELECT_T compSelect, COMP_Config_T* compConfig); 163 void COMP_ConfigStructInit(COMP_Config_T* compConfig); 164 void COMP_Enable(COMP_SELECT_T compSelect); 165 void COMP_Disable(COMP_SELECT_T compSelect); 166 void COMP_EnableSwitch(void); 167 void COMP_DisableSwitch(void); 168 uint32_t COMP_ReadOutPutLevel(COMP_SELECT_T compSelect); 169 170 /* Window mode control */ 171 void COMP_EnableWindow(void); 172 void COMP_DisnableWindow(void); 173 174 /* COMP configuration locking */ 175 void COMP_ConfigLOCK(COMP_SELECT_T compSelect); 176 177 #ifdef __cplusplus 178 } 179 #endif 180 181 #endif /* __APM32F0XX_COMP_H */ 182 183 /**@} end of group COMP_Functions */ 184 /**@} end of group COMP_Driver */ 185 /**@} end of group APM32F0xx_StdPeriphDriver */ 186