EFM32 Jade Gecko 12 Software Documentation  efm32jg12-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 {
64  vcmpWarmTime4Cycles = _VCMP_CTRL_WARMTIME_4CYCLES,
66  vcmpWarmTime8Cycles = _VCMP_CTRL_WARMTIME_8CYCLES,
68  vcmpWarmTime16Cycles = _VCMP_CTRL_WARMTIME_16CYCLES,
70  vcmpWarmTime32Cycles = _VCMP_CTRL_WARMTIME_32CYCLES,
72  vcmpWarmTime64Cycles = _VCMP_CTRL_WARMTIME_64CYCLES,
74  vcmpWarmTime128Cycles = _VCMP_CTRL_WARMTIME_128CYCLES,
76  vcmpWarmTime256Cycles = _VCMP_CTRL_WARMTIME_256CYCLES,
78  vcmpWarmTime512Cycles = _VCMP_CTRL_WARMTIME_512CYCLES
79 } VCMP_WarmTime_TypeDef;
80 
82 typedef enum
83 {
85  vcmpHystNone,
88  vcmpHyst20mV
89 } VCMP_Hysteresis_TypeDef;
90 
91 /*******************************************************************************
92  ******************************* STRUCTS ***********************************
93  ******************************************************************************/
94 
96 typedef struct
97 {
99  bool halfBias;
102  int biasProg;
104  bool irqFalling;
106  bool irqRising;
108  VCMP_WarmTime_TypeDef warmup;
110  VCMP_Hysteresis_TypeDef hyst;
112  int inactive;
114  bool lowPowerRef;
117  int triggerLevel;
119  bool enable;
120 } VCMP_Init_TypeDef;
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 */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.