35 #if defined(ACMP_COUNT) && (ACMP_COUNT > 0)
61 #define ACMP_REF_VALID(ref) ((ref) == ACMP0)
62 #elif (ACMP_COUNT == 2)
63 #define ACMP_REF_VALID(ref) (((ref) == ACMP0) || ((ref) == ACMP1))
65 #error Undefined number of analog comparators (ACMP).
70 #if defined(_ACMP_ROUTE_LOCATION_LOC3)
71 #define _ACMP_ROUTE_LOCATION_MAX _ACMP_ROUTE_LOCATION_LOC3
72 #elif defined(_ACMP_ROUTE_LOCATION_LOC2)
73 #define _ACMP_ROUTE_LOCATION_MAX _ACMP_ROUTE_LOCATION_LOC2
74 #elif defined(_ACMP_ROUTE_LOCATION_LOC1)
75 #define _ACMP_ROUTE_LOCATION_MAX _ACMP_ROUTE_LOCATION_LOC1
76 #elif defined(_ACMP_ROUTELOC0_OUTLOC_LOC31)
77 #define _ACMP_ROUTE_LOCATION_MAX _ACMP_ROUTELOC0_OUTLOC_LOC31
79 #error Undefined max route locations
109 void ACMP_CapsenseInit(ACMP_TypeDef *acmp,
const ACMP_CapsenseInit_TypeDef *init)
112 EFM_ASSERT(ACMP_REF_VALID(acmp));
115 #if defined(_ACMP_INPUTSEL_VDDLEVEL_MASK)
116 EFM_ASSERT(init->vddLevel < 64);
118 EFM_ASSERT(init->vddLevelLow < 64);
119 EFM_ASSERT(init->vddLevelHigh < 64);
123 EFM_ASSERT(init->biasProg <=
124 (_ACMP_CTRL_BIASPROG_MASK >> _ACMP_CTRL_BIASPROG_SHIFT));
127 acmp->CTRL = (init->fullBias << _ACMP_CTRL_FULLBIAS_SHIFT)
128 #
if defined(_ACMP_CTRL_HALFBIAS_MASK)
129 | (init->halfBias << _ACMP_CTRL_HALFBIAS_SHIFT)
131 | (init->biasProg << _ACMP_CTRL_BIASPROG_SHIFT)
132 #if defined(_ACMP_CTRL_WARMTIME_MASK)
133 | (init->warmTime << _ACMP_CTRL_WARMTIME_SHIFT)
135 #
if defined(_ACMP_CTRL_HYSTSEL_MASK)
136 | (init->hysteresisLevel << _ACMP_CTRL_HYSTSEL_SHIFT)
138 #
if defined(_ACMP_CTRL_ACCURACY_MASK)
139 | ACMP_CTRL_ACCURACY_HIGH
143 #if defined(_ACMP_HYSTERESIS0_MASK)
144 acmp->HYSTERESIS0 = (init->vddLevelHigh << _ACMP_HYSTERESIS0_DIVVA_SHIFT)
145 | (init->hysteresisLevel_0 << _ACMP_HYSTERESIS0_HYST_SHIFT);
146 acmp->HYSTERESIS1 = (init->vddLevelLow << _ACMP_HYSTERESIS1_DIVVA_SHIFT)
147 | (init->hysteresisLevel_1 << _ACMP_HYSTERESIS1_HYST_SHIFT);
151 acmp->INPUTSEL = (init->resistor << _ACMP_INPUTSEL_CSRESSEL_SHIFT)
152 | ACMP_INPUTSEL_CSRESEN
153 #
if defined(_ACMP_INPUTSEL_LPREF_MASK)
154 | (init->lowPowerReferenceEnabled << _ACMP_INPUTSEL_LPREF_SHIFT)
156 #
if defined(_ACMP_INPUTSEL_VDDLEVEL_MASK)
157 | (init->vddLevel << _ACMP_INPUTSEL_VDDLEVEL_SHIFT)
159 #
if defined(ACMP_INPUTSEL_NEGSEL_CAPSENSE)
160 | ACMP_INPUTSEL_NEGSEL_CAPSENSE
162 | ACMP_INPUTSEL_VASEL_VDD
163 | ACMP_INPUTSEL_NEGSEL_VADIV
185 void ACMP_CapsenseChannelSet(ACMP_TypeDef *acmp, ACMP_Channel_TypeDef channel)
188 EFM_ASSERT(ACMP_REF_VALID(acmp));
190 #if defined(_ACMP_INPUTSEL_POSSEL_CH7)
192 EFM_ASSERT(channel <= _ACMP_INPUTSEL_POSSEL_CH7);
193 #elif defined(_ACMP_INPUTSEL_POSSEL_BUS4XCH31)
195 EFM_ASSERT(channel <= _ACMP_INPUTSEL_POSSEL_BUS4XCH31);
200 channel << _ACMP_INPUTSEL_POSSEL_SHIFT);
210 void ACMP_Disable(ACMP_TypeDef *acmp)
213 EFM_ASSERT(ACMP_REF_VALID(acmp));
215 acmp->CTRL &= ~ACMP_CTRL_EN;
225 void ACMP_Enable(ACMP_TypeDef *acmp)
228 EFM_ASSERT(ACMP_REF_VALID(acmp));
230 acmp->CTRL |= ACMP_CTRL_EN;
233 #if defined(_ACMP_EXTIFCTRL_MASK)
250 void ACMP_ExternalInputSelect(ACMP_TypeDef *acmp, ACMP_ExternalInput_Typedef aport)
252 acmp->EXTIFCTRL = (aport << _ACMP_EXTIFCTRL_APORTSEL_SHIFT)
254 while (!(acmp->STATUS & ACMP_STATUS_EXTIFACT))
270 void ACMP_Reset(ACMP_TypeDef *acmp)
273 EFM_ASSERT(ACMP_REF_VALID(acmp));
275 acmp->CTRL = _ACMP_CTRL_RESETVALUE;
276 acmp->INPUTSEL = _ACMP_INPUTSEL_RESETVALUE;
277 #if defined(_ACMP_HYSTERESIS0_HYST_MASK)
278 acmp->HYSTERESIS0 = _ACMP_HYSTERESIS0_RESETVALUE;
279 acmp->HYSTERESIS1 = _ACMP_HYSTERESIS1_RESETVALUE;
281 acmp->IEN = _ACMP_IEN_RESETVALUE;
282 acmp->IFC = _ACMP_IF_MASK;
305 void ACMP_GPIOSetup(ACMP_TypeDef *acmp, uint32_t location,
bool enable,
bool invert)
308 EFM_ASSERT(ACMP_REF_VALID(acmp));
311 EFM_ASSERT(location <= _ACMP_ROUTE_LOCATION_MAX);
315 invert << _ACMP_CTRL_GPIOINV_SHIFT);
317 #if defined(_ACMP_ROUTE_MASK)
318 acmp->ROUTE = (location << _ACMP_ROUTE_LOCATION_SHIFT)
319 | (enable << _ACMP_ROUTE_ACMPPEN_SHIFT);
321 #if defined(_ACMP_ROUTELOC0_MASK)
322 acmp->ROUTELOC0 = location << _ACMP_ROUTELOC0_OUTLOC_SHIFT;
323 acmp->ROUTEPEN = enable ? ACMP_ROUTEPEN_OUTPEN : 0;
340 void ACMP_ChannelSet(ACMP_TypeDef *acmp, ACMP_Channel_TypeDef negSel,
341 ACMP_Channel_TypeDef posSel)
344 EFM_ASSERT(ACMP_REF_VALID(acmp));
347 #if defined(_ACMP_INPUTSEL_NEGSEL_DAC0CH1)
348 EFM_ASSERT(negSel <= _ACMP_INPUTSEL_NEGSEL_DAC0CH1);
349 #elif defined(_ACMP_INPUTSEL_NEGSEL_CAPSENSE)
350 EFM_ASSERT(negSel <= _ACMP_INPUTSEL_NEGSEL_CAPSENSE);
353 #if defined(_ACMP_INPUTSEL_POSSEL_CH7)
354 EFM_ASSERT(posSel <= _ACMP_INPUTSEL_POSSEL_CH7);
357 acmp->INPUTSEL = (acmp->INPUTSEL & ~(_ACMP_INPUTSEL_POSSEL_MASK
358 | _ACMP_INPUTSEL_NEGSEL_MASK))
359 | (negSel << _ACMP_INPUTSEL_NEGSEL_SHIFT)
360 | (posSel << _ACMP_INPUTSEL_POSSEL_SHIFT);
374 void ACMP_Init(ACMP_TypeDef *acmp,
const ACMP_Init_TypeDef *init)
377 EFM_ASSERT(ACMP_REF_VALID(acmp));
380 EFM_ASSERT(init->biasProg <=
381 (_ACMP_CTRL_BIASPROG_MASK >> _ACMP_CTRL_BIASPROG_SHIFT));
388 acmp->CTRL = (init->fullBias << _ACMP_CTRL_FULLBIAS_SHIFT)
389 #
if defined(_ACMP_CTRL_HALFBIAS_MASK)
390 | (init->halfBias << _ACMP_CTRL_HALFBIAS_SHIFT)
392 | (init->biasProg << _ACMP_CTRL_BIASPROG_SHIFT)
393 | (init->interruptOnFallingEdge << _ACMP_CTRL_IFALL_SHIFT)
394 | (init->interruptOnRisingEdge << _ACMP_CTRL_IRISE_SHIFT)
395 #if defined(_ACMP_CTRL_INPUTRANGE_MASK)
396 | (init->inputRange << _ACMP_CTRL_INPUTRANGE_SHIFT)
398 #
if defined(_ACMP_CTRL_ACCURACY_MASK)
399 | (init->accuracy << _ACMP_CTRL_ACCURACY_SHIFT)
401 #
if defined(_ACMP_CTRL_PWRSEL_MASK)
402 | (init->powerSource << _ACMP_CTRL_PWRSEL_SHIFT)
404 #
if defined(_ACMP_CTRL_WARMTIME_MASK)
405 | (init->warmTime << _ACMP_CTRL_WARMTIME_SHIFT)
407 #
if defined(_ACMP_CTRL_HYSTSEL_MASK)
408 | (init->hysteresisLevel << _ACMP_CTRL_HYSTSEL_SHIFT)
410 | (init->inactiveValue << _ACMP_CTRL_INACTVAL_SHIFT);
413 #
if defined(_ACMP_INPUTSEL_VLPSEL_MASK)
414 | (init->vlpInput << _ACMP_INPUTSEL_VLPSEL_SHIFT)
416 #
if defined(_ACMP_INPUTSEL_LPREF_MASK)
417 | (init->lowPowerReferenceEnabled << _ACMP_INPUTSEL_LPREF_SHIFT)
419 #
if defined(_ACMP_INPUTSEL_VDDLEVEL_MASK)
420 | (init->vddLevel << _ACMP_INPUTSEL_VDDLEVEL_SHIFT)
428 #if defined(_ACMP_INPUTSEL_VASEL_MASK)
440 void ACMP_VASetup(ACMP_TypeDef *acmp,
const ACMP_VAConfig_TypeDef *vaconfig)
442 EFM_ASSERT(vaconfig->div0 < 64);
443 EFM_ASSERT(vaconfig->div1 < 64);
446 vaconfig->input << _ACMP_INPUTSEL_VASEL_SHIFT);
448 vaconfig->div0 << _ACMP_HYSTERESIS0_DIVVA_SHIFT);
450 vaconfig->div1 << _ACMP_HYSTERESIS1_DIVVA_SHIFT);
454 #if defined(_ACMP_INPUTSEL_VBSEL_MASK)
466 void ACMP_VBSetup(ACMP_TypeDef *acmp,
const ACMP_VBConfig_TypeDef *vbconfig)
468 EFM_ASSERT(vbconfig->div0 < 64);
469 EFM_ASSERT(vbconfig->div1 < 64);
472 vbconfig->input << _ACMP_INPUTSEL_VBSEL_SHIFT);
474 vbconfig->div0 << _ACMP_HYSTERESIS0_DIVVB_SHIFT);
476 vbconfig->div1 << _ACMP_HYSTERESIS1_DIVVB_SHIFT);
Emlib peripheral API "assert" implementation.
RAM and peripheral bit-field set and clear API.
Analog Comparator (ACMP) peripheral API.
__STATIC_INLINE void BUS_RegMaskedWrite(volatile uint32_t *addr, uint32_t mask, uint32_t val)
Perform peripheral register masked clear and value write.
__STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a peripheral register.