1 //////////////////////////////////////////////////////////////////////////////// 2 /// @file hal_comp.h 3 /// @author AE TEAM 4 /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE COMP 5 /// FIRMWARE LIBRARY. 6 //////////////////////////////////////////////////////////////////////////////// 7 /// @attention 8 /// 9 /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE 10 /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE 11 /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR 12 /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH 13 /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN 14 /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS. 15 /// 16 /// <H2><CENTER>© COPYRIGHT MINDMOTION </CENTER></H2> 17 //////////////////////////////////////////////////////////////////////////////// 18 19 // Define to prevent recursive inclusion 20 #ifndef __HAL_COMP_H 21 #define __HAL_COMP_H 22 23 24 // Files includes 25 #include "reg_common.h" 26 #include "reg_comp.h" 27 28 //////////////////////////////////////////////////////////////////////////////// 29 /// @addtogroup MM32_Hardware_Abstract_Layer 30 /// @{ 31 32 //////////////////////////////////////////////////////////////////////////////// 33 /// @defgroup COMP_HAL 34 /// @brief COMP HAL modules 35 /// @{ 36 //////////////////////////////////////////////////////////////////////////////// 37 /// @defgroup COMP_Exported_Types 38 /// @{ 39 40 //////////////////////////////////////////////////////////////////////////////// 41 /// @brief COMP_InvertingInput 42 //////////////////////////////////////////////////////////////////////////////// 43 typedef enum { 44 COMP_InvertingInput_IO0 = COMP_CSR_INM_0, ///< INM0 as COMP inverting input 45 COMP_InvertingInput_IO1 = COMP_CSR_INM_1, ///< INM1 as COMP inverting input 46 COMP_InvertingInput_IO2 = COMP_CSR_INM_2, ///< INM2 as COMP inverting input 47 COMP_InvertingInput_CRV = COMP_CSR_INM_3, ///< INM3 as COMP inverting input 48 COMP_InvertingInput_IO3 = COMP_CSR_INM_3, ///< INM3 as COMP inverting input 49 } EM_COMP_InvertingInput; 50 51 //////////////////////////////////////////////////////////////////////////////// 52 /// @brief COMP_NonInvertingInput 53 //////////////////////////////////////////////////////////////////////////////// 54 typedef enum { 55 COMP_NonInvertingInput_IO0 = COMP_CSR_INP_INP0, ///< INP0 as COMP non-inverting input 56 COMP_NonInvertingInput_IO1 = COMP_CSR_INP_INP1, ///< INP1 as COMP non-inverting input 57 COMP_NonInvertingInput_IO2 = COMP_CSR_INP_INP2, ///< INP2 as COMP non-inverting input 58 COMP_NonInvertingInput_IO3 = COMP_CSR_INP_INP3, ///< INP3 as COMP non-inverting input 59 } EM_COMP_NonInvertingInput; 60 61 //////////////////////////////////////////////////////////////////////////////// 62 /// @brief COMP_Output 63 //////////////////////////////////////////////////////////////////////////////// 64 typedef enum { 65 COMP_Output_None = 0x00000000, ///< No output 66 COMP_Output_TIM1BKIN = COMP_CSR_OUT_TIM1_BRAKE, ///< Timer1 brake input 67 COMP_Output_TIM1OCREFCLR = COMP_CSR_OUT_TIM1_OCREFCLR, ///< Timer1 ocrefclear input 68 COMP_Output_TIM1IC1 = COMP_CSR_OUT_TIM1_CAPTURE1, ///< Timer1 input capture 1 69 COMP_Output_TIM2IC4 = COMP_CSR_OUT_TIM2_CAPTURE4, ///< Timer2 input capture 4 70 COMP_Output_TIM2OCREFCLR = COMP_CSR_OUT_TIM2_OCREFCLR, ///< Timer2 ocrefclear input 71 COMP_Output_TIM3IC1 = COMP_CSR_OUT_TIM3_CAPTURE1, ///< Timer3 input capture 1 72 COMP_Output_TIM3OCREFCLR = COMP_CSR_OUT_TIM3_OCREFCLR ///< Timer3 ocrefclear input 73 } EM_COMP_Output; 74 75 //////////////////////////////////////////////////////////////////////////////// 76 /// @brief COMP_OutputPoloarity 77 //////////////////////////////////////////////////////////////////////////////// 78 typedef enum { 79 COMP_NonInverted = 0x00000000, ///< COMP non-inverting output 80 COMP_OutputPol_NonInverted = 0x00000000, 81 COMP_Inverted = 0x00008000, ///< COMP inverting output 82 COMP_OutputPol_Inverted = 0x00008000 83 } EM_COMP_OutputPol; 84 85 //////////////////////////////////////////////////////////////////////////////// 86 /// @brief COMP_Hysteresis 87 //////////////////////////////////////////////////////////////////////////////// 88 typedef enum { 89 COMP_Hysteresis_No = COMP_CSR_HYST_0, ///< Hysteresis Voltage: 0mV 90 COMP_Hysteresis_Low = COMP_CSR_HYST_15, ///< Hysteresis Voltage: 15mV 91 COMP_Hysteresis_Medium = COMP_CSR_HYST_30, ///< Hysteresis Voltage: 30mV 92 COMP_Hysteresis_High = COMP_CSR_HYST_90 ///< Hysteresis Voltage: 90mV 93 } EM_COMP_Hysteresis; 94 typedef enum { 95 COMP_Filter_0_Period = COMP_CSR_OFLT_0, ///< filter is ((u32)0x00000000) 96 COMP_Filter_2_Period = COMP_CSR_OFLT_1, ///< filter is ((u32)0x00040000) 97 COMP_Filter_4_Period = COMP_CSR_OFLT_2, ///< filter is ((u32)0x00080000) 98 COMP_Filter_8_Period = COMP_CSR_OFLT_3, ///< filter is ((u32)0x000C0000) 99 COMP_Filter_16_Period = COMP_CSR_OFLT_4, ///< filter is ((u32)0x00100000) 100 COMP_Filter_32_Period = COMP_CSR_OFLT_5, ///< filter is ((u32)0x00140000) 101 COMP_Filter_64_Period = COMP_CSR_OFLT_6, ///< filter is ((u32)0x00180000) 102 COMP_Filter_128_Period = COMP_CSR_OFLT_7, ///< filter is ((u32)0x001C0000) 103 } EM_COMP_FILT; 104 //////////////////////////////////////////////////////////////////////////////// 105 /// @brief COMP_Mode 106 //////////////////////////////////////////////////////////////////////////////// 107 typedef enum { 108 COMP_Mode_HighSpeed = COMP_CSR_MODE_HIGHRATE, ///< Comparator high rate mode 109 COMP_Mode_MediumSpeed = COMP_CSR_MODE_MEDIUMRATE, ///< Comparator medium rate mode 110 COMP_Mode_LowPower = COMP_CSR_MODE_LOWPOWER, ///< Comparator low power mode 111 COMP_Mode_UltraLowPower = COMP_CSR_MODE_LOWESTPOWER ///< Comparator lowest power mode 112 } EM_COMP_Mode; 113 114 //////////////////////////////////////////////////////////////////////////////// 115 /// @brief COMP_OutputLevel 116 //////////////////////////////////////////////////////////////////////////////// 117 typedef enum { 118 COMP_OutputLevel_High = COMP_CSR_OUT, ///< High output 119 COMP_OutputLevel_Low = 0x00000000 ///< Low output 120 } EM_COMP_OutputLevel; 121 122 //////////////////////////////////////////////////////////////////////////////// 123 /// @brief COMP Init structure definition 124 //////////////////////////////////////////////////////////////////////////////// 125 typedef struct { 126 union { 127 u32 COMP_InvertingInput; 128 u32 Invert; ///< Selects the inverting input of the comparator. 129 }; 130 union { 131 u32 COMP_NonInvertingInput; 132 u32 NonInvert; ///< Selects the non inverting input of the comparator. 133 }; 134 union { 135 u32 COMP_Output; 136 u32 Output; ///< Selects the output redirection of the comparator. 137 u32 BlankingSrce; ///< Selects the output blanking source of the comparator. 138 }; 139 union { 140 u32 COMP_OutputPol; 141 u32 OutputPol; ///< Selects the output polarity of the comparator. 142 }; 143 union { 144 u32 COMP_Hysteresis; 145 u32 Hysteresis; ///< Selects the hysteresis voltage of the comparator. 146 }; 147 union { 148 u32 COMP_Mode; 149 u32 Mode; ///< Selects the operating mode of the comparator and allows 150 }; 151 union { 152 u32 COMP_Filter; 153 u32 OFLT; ///< to adjust the speed/consumption. 154 }; 155 } COMP_InitTypeDef; 156 157 158 159 typedef struct { 160 161 FunctionalState COMP_Poll_En; ///< Selects the inverting input of the comparator. 162 163 u32 COMP_Poll_Ch; ///< Selects the non inverting input of the comparator. 164 u32 COMP_Poll_Fixn; ///< Selects the output redirection of the comparator. 165 u32 COMP_Poll_Period; ///< Selects the output polarity of the comparator. 166 u32 COMP_Poll_Pout; ///< Selects the hysteresis voltage of the comparator. 167 168 } COMP_POLL_InitTypeDef; 169 /// @} 170 171 //////////////////////////////////////////////////////////////////////////////// 172 /// @defgroup COMP_Exported_Constants 173 /// @{ 174 //////////////////////////////////////////////////////////////////////////////// 175 /// @brief COMP Init structure definition 176 //////////////////////////////////////////////////////////////////////////////// 177 typedef enum { 178 COMP1 = (0x00000C), ///< Select comparator 1 179 COMP2 = (0x000010), ///< Select comparator 2 180 } COMP_Selection_TypeDef; 181 182 #define COMP_BlankingSrce_None ((u32)0x00000000) 183 #define COMP_CSR_CLEAR_MASK ((u32)0x00000003) 184 185 #define COMP_CSR_COMPSW1 ((u32)0x00000002) 186 187 /// @} 188 189 //////////////////////////////////////////////////////////////////////////////// 190 ///@defgroup COMP_Exported_Variables 191 /// @{ 192 #ifdef _HAL_COMP_C_ 193 194 #define GLOBAL 195 #else 196 #define GLOBAL extern 197 #endif 198 199 #undef GLOBAL 200 /// @} 201 202 //////////////////////////////////////////////////////////////////////////////// 203 /// @defgroup COMP_Exported_Functions 204 /// @{ 205 206 207 void COMP_DeInit(COMP_Selection_TypeDef selection); 208 void COMP_Init(COMP_Selection_TypeDef selection, COMP_InitTypeDef* init_struct); 209 void COMP_StructInit(COMP_InitTypeDef* init_struct); 210 void COMP_Cmd(COMP_Selection_TypeDef selection, FunctionalState state); 211 void COMP_SwitchCmd(COMP_Selection_TypeDef selection, FunctionalState state); 212 void COMP_LockConfig(COMP_Selection_TypeDef selection); 213 214 u32 COMP_GetOutputLevel(COMP_Selection_TypeDef selection); 215 216 void COMP_SetCrv(u8 crv_select, u8 crv_level); 217 #define SET_COMP_CRV COMP_SetCrv 218 219 220 /// @} 221 222 /// @} 223 224 /// @} 225 226 //////////////////////////////////////////////////////////////////////////////// 227 #endif //__HAL_COMP_H 228 //////////////////////////////////////////////////////////////////////////////// 229