EFM32 Wonder Gecko Software Documentation  efm32wg-doc-5.1.2
em_vcmp.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_VCMP_H
34 #define EM_VCMP_H
35 
36 #include "em_device.h"
37 #if defined(VCMP_COUNT) && (VCMP_COUNT > 0)
38 
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
56 /*******************************************************************************
57  ******************************** ENUMS ************************************
58  ******************************************************************************/
59 
61 typedef enum
62 {
80 
82 typedef enum
83 {
90 
91 /*******************************************************************************
92  ******************************* STRUCTS ***********************************
93  ******************************************************************************/
94 
96 typedef struct
97 {
99  bool halfBias;
102  int biasProg;
106  bool irqRising;
112  int inactive;
119  bool enable;
121 
123 #define VCMP_INIT_DEFAULT \
124 { \
125  true, \
126  0x7, \
127  false, \
128  false, \
129  vcmpWarmTime4Cycles, \
130  vcmpHystNone, \
131  0, \
132  true, \
133  39, \
134  true, \
135 }
136 
137 /*******************************************************************************
138  ***************************** PROTOTYPES **********************************
139  ******************************************************************************/
140 
141 void VCMP_Init(const VCMP_Init_TypeDef *vcmpInit);
142 void VCMP_LowPowerRefSet(bool enable);
143 void VCMP_TriggerSet(int level);
144 
145 /***************************************************************************/
149 __STATIC_INLINE void VCMP_Enable(void)
150 {
151  VCMP->CTRL |= VCMP_CTRL_EN;
152 }
153 
154 
155 /***************************************************************************/
159 __STATIC_INLINE void VCMP_Disable(void)
160 {
161  VCMP->CTRL &= ~VCMP_CTRL_EN;
162 }
163 
164 
165 /***************************************************************************/
175 __STATIC_INLINE uint32_t VCMP_VoltageToLevel(float v)
176 {
177  return (uint32_t)((v - (float)1.667) / (float)0.034);
178 }
179 
180 
181 /***************************************************************************/
186 __STATIC_INLINE bool VCMP_VDDLower(void)
187 {
188  if (VCMP->STATUS & VCMP_STATUS_VCMPOUT)
189  {
190  return false;
191  }
192  else
193  {
194  return true;
195  }
196 }
197 
198 
199 /***************************************************************************/
204 __STATIC_INLINE bool VCMP_VDDHigher(void)
205 {
206  if (VCMP->STATUS & VCMP_STATUS_VCMPOUT)
207  {
208  return true;
209  }
210  else
211  {
212  return false;
213  }
214 }
215 
216 
217 /***************************************************************************/
221 __STATIC_INLINE bool VCMP_Ready(void)
222 {
223  if (VCMP->STATUS & VCMP_STATUS_VCMPACT)
224  {
225  return true;
226  }
227  else
228  {
229  return false;
230  }
231 }
232 
233 
234 /***************************************************************************/
243 __STATIC_INLINE void VCMP_IntClear(uint32_t flags)
244 {
245  VCMP->IFC = flags;
246 }
247 
248 
249 /***************************************************************************/
258 __STATIC_INLINE void VCMP_IntSet(uint32_t flags)
259 {
260  VCMP->IFS = flags;
261 }
262 
263 
264 /***************************************************************************/
273 __STATIC_INLINE void VCMP_IntDisable(uint32_t flags)
274 {
275  VCMP->IEN &= ~flags;
276 }
277 
278 
279 /***************************************************************************/
288 __STATIC_INLINE void VCMP_IntEnable(uint32_t flags)
289 {
290  VCMP->IEN |= flags;
291 }
292 
293 
294 /***************************************************************************/
305 __STATIC_INLINE uint32_t VCMP_IntGet(void)
306 {
307  return VCMP->IF;
308 }
309 
310 
311 /***************************************************************************/
329 __STATIC_INLINE uint32_t VCMP_IntGetEnabled(void)
330 {
331  uint32_t tmp = 0U;
332 
333  /* Store VCMP->IEN in temporary variable in order to define explicit order
334  * of volatile accesses. */
335  tmp = VCMP->IEN;
336 
337  /* Bitwise AND of pending and enabled interrupts */
338  return VCMP->IF & tmp;
339 }
340 
344 #ifdef __cplusplus
345 }
346 #endif
347 
348 #endif /* defined(VCMP_COUNT) && (VCMP_COUNT > 0) */
349 #endif /* EM_VCMP_H */
__STATIC_INLINE void VCMP_IntEnable(uint32_t flags)
Enable one or more VCMP interrupts.
Definition: em_vcmp.h:288
#define _VCMP_CTRL_WARMTIME_128CYCLES
Definition: efm32wg_vcmp.h:83
void VCMP_Init(const VCMP_Init_TypeDef *vcmpInit)
Configure and enable Voltage Comparator.
Definition: em_vcmp.c:60
__STATIC_INLINE void VCMP_IntSet(uint32_t flags)
Set one or more pending VCMP interrupts from SW.
Definition: em_vcmp.h:258
#define VCMP_STATUS_VCMPOUT
Definition: efm32wg_vcmp.h:136
#define _VCMP_CTRL_WARMTIME_16CYCLES
Definition: efm32wg_vcmp.h:80
VCMP_Hysteresis_TypeDef hyst
Definition: em_vcmp.h:110
__STATIC_INLINE bool VCMP_VDDHigher(void)
Returns true, if Voltage Comparator indicated VDD > trigger level, else false.
Definition: em_vcmp.h:204
VCMP_WarmTime_TypeDef
Definition: em_vcmp.h:61
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__STATIC_INLINE void VCMP_IntClear(uint32_t flags)
Clear one or more pending VCMP interrupts.
Definition: em_vcmp.h:243
__STATIC_INLINE void VCMP_Disable(void)
Disable Voltage Comparator.
Definition: em_vcmp.h:159
#define _VCMP_CTRL_WARMTIME_4CYCLES
Definition: efm32wg_vcmp.h:78
__STATIC_INLINE void VCMP_IntDisable(uint32_t flags)
Disable one or more VCMP interrupts.
Definition: em_vcmp.h:273
void VCMP_TriggerSet(int level)
Configure trigger level of voltage comparator.
Definition: em_vcmp.c:175
__STATIC_INLINE bool VCMP_Ready(void)
VCMP output is ready.
Definition: em_vcmp.h:221
#define VCMP
#define _VCMP_CTRL_WARMTIME_256CYCLES
Definition: efm32wg_vcmp.h:84
#define _VCMP_CTRL_WARMTIME_512CYCLES
Definition: efm32wg_vcmp.h:85
void VCMP_LowPowerRefSet(bool enable)
Enable or disable Low Power Reference setting.
Definition: em_vcmp.c:155
__STATIC_INLINE void VCMP_Enable(void)
Enable Voltage Comparator.
Definition: em_vcmp.h:149
__STATIC_INLINE uint32_t VCMP_IntGet(void)
Get pending VCMP interrupt flags.
Definition: em_vcmp.h:305
#define _VCMP_CTRL_WARMTIME_64CYCLES
Definition: efm32wg_vcmp.h:82
#define _VCMP_CTRL_WARMTIME_8CYCLES
Definition: efm32wg_vcmp.h:79
__STATIC_INLINE uint32_t VCMP_VoltageToLevel(float v)
Calculate voltage to trigger level.
Definition: em_vcmp.h:175
VCMP_WarmTime_TypeDef warmup
Definition: em_vcmp.h:108
__STATIC_INLINE bool VCMP_VDDLower(void)
Returns true, if Voltage Comparator indicated VDD < trigger level, else false.
Definition: em_vcmp.h:186
#define VCMP_STATUS_VCMPACT
Definition: efm32wg_vcmp.h:131
#define _VCMP_CTRL_WARMTIME_32CYCLES
Definition: efm32wg_vcmp.h:81
#define VCMP_CTRL_EN
Definition: efm32wg_vcmp.h:60
VCMP_Hysteresis_TypeDef
Definition: em_vcmp.h:82
__STATIC_INLINE uint32_t VCMP_IntGetEnabled(void)
Get enabled and pending VCMP interrupt flags.
Definition: em_vcmp.h:329