1 /***************************************************************************//**
2  * @file
3  * @brief Low Energy Sensor (LESENSE) peripheral API
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef EM_LESENSE_H
32 #define EM_LESENSE_H
33 
34 #include "em_device.h"
35 
36 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)
37 #include <stdint.h>
38 #include <stdbool.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /***************************************************************************//**
45  * @addtogroup lesense
46  * @{
47  ******************************************************************************/
48 
49 /** Number of decoder states supported by current device. */
50 #define LESENSE_NUM_DECODER_STATES   (_LESENSE_DECSTATE_DECSTATE_MASK + 1)
51 
52 /** Number of LESENSE channels. */
53 #define LESENSE_NUM_CHANNELS         16
54 
55 /*******************************************************************************
56  ********************************   ENUMS   ************************************
57  ******************************************************************************/
58 
59 /** Clock divisors for controlling the prescaling factor of the period counter.
60  *  Note: These enumeration values are used for different clock division
61  *  related configuration parameters (hfPresc, lfPresc, pcPresc). */
62 typedef enum {
63   lesenseClkDiv_1   = 0, /**< Divide clock by 1. */
64   lesenseClkDiv_2   = 1, /**< Divide clock by 2. */
65   lesenseClkDiv_4   = 2, /**< Divide clock by 4. */
66   lesenseClkDiv_8   = 3, /**< Divide clock by 8. */
67   lesenseClkDiv_16  = 4, /**< Divide clock by 16. */
68   lesenseClkDiv_32  = 5, /**< Divide clock by 32. */
69   lesenseClkDiv_64  = 6, /**< Divide clock by 64. */
70   lesenseClkDiv_128 = 7  /**< Divide clock by 128. */
71 } LESENSE_ClkPresc_TypeDef;
72 
73 /** Scan modes. */
74 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
75 typedef enum {
76   /** New scan is started each time the period counter overflows. */
77   lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,
78 
79   /** Single scan is performed when LESENSE_ScanStart() is called. */
80   lesenseScanStartOneShot  = LESENSE_CTRL_SCANMODE_ONESHOT,
81 
82   /** New scan is triggered by pulse on PRS channel. */
83   lesenseScanStartPRS      = LESENSE_CTRL_SCANMODE_PRS
84 } LESENSE_ScanMode_TypeDef;
85 #else
86 typedef enum {
87   /** New scan is started each time the period counter overflows. */
88   lesenseScanStartPeriodic = LESENSE_CFG_SCANMODE_PERIODIC,
89 
90   /** Single scan is performed when LESENSE_ScanStart() is called. */
91   lesenseScanStartOneShot  = LESENSE_CFG_SCANMODE_ONESHOT,
92 
93   /** New scan is triggered by pulse on PRS channel. */
94   lesenseScanStartPRS      = LESENSE_CFG_SCANMODE_PRS
95 } LESENSE_ScanMode_TypeDef;
96 #endif
97 
98 /** PRS sources. */
99 /**  Note: These enumeration values are being used for different PRS related
100  *  configuration parameters. */
101 typedef enum {
102   lesensePRSCh0     = 0, /**< PRS channel 0. */
103   lesensePRSCh1     = 1, /**< PRS channel 1. */
104   lesensePRSCh2     = 2, /**< PRS channel 2. */
105   lesensePRSCh3     = 3, /**< PRS channel 3. */
106 #if defined(LESENSE_CTRL_PRSSEL_PRSCH4) || defined(_SILICON_LABS_32B_SERIES_2)
107   lesensePRSCh4     = 4, /**< PRS channel 4. */
108 #endif
109 #if defined(LESENSE_CTRL_PRSSEL_PRSCH5) || defined(_SILICON_LABS_32B_SERIES_2)
110   lesensePRSCh5     = 5, /**< PRS channel 5. */
111 #endif
112 #if defined(LESENSE_CTRL_PRSSEL_PRSCH6) || defined(_SILICON_LABS_32B_SERIES_2)
113   lesensePRSCh6     = 6, /**< PRS channel 6. */
114 #endif
115 #if defined(LESENSE_CTRL_PRSSEL_PRSCH7) || defined(_SILICON_LABS_32B_SERIES_2)
116   lesensePRSCh7     = 7,  /**< PRS channel 7. */
117 #endif
118 #if defined(LESENSE_CTRL_PRSSEL_PRSCH8) || defined(_SILICON_LABS_32B_SERIES_2)
119   lesensePRSCh8     = 8,  /**< PRS channel 8. */
120 #endif
121 #if defined(LESENSE_CTRL_PRSSEL_PRSCH9) || defined(_SILICON_LABS_32B_SERIES_2)
122   lesensePRSCh9     = 9,  /**< PRS channel 9. */
123 #endif
124 #if defined(LESENSE_CTRL_PRSSEL_PRSCH10) || defined(_SILICON_LABS_32B_SERIES_2)
125   lesensePRSCh10    = 10, /**< PRS channel 10.*/
126 #endif
127 #if defined(LESENSE_CTRL_PRSSEL_PRSCH11) || defined(_SILICON_LABS_32B_SERIES_2)
128   lesensePRSCh11    = 11, /**< PRS channel 11.*/
129 #endif
130 } LESENSE_PRSSel_TypeDef;
131 
132 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
133 /** Locations of the alternate excitation function. */
134 typedef enum {
135   /** Alternate excitation is mapped to the LES_ALTEX pins. */
136   lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
137 
138 #if defined(_LESENSE_CTRL_ALTEXMAP_ACMP)
139   /** Alternate excitation is mapped to the pins of the other ACMP. */
140   lesenseAltExMapACMP  = _LESENSE_CTRL_ALTEXMAP_ACMP,
141 #endif
142 
143 #if defined(_LESENSE_CTRL_ALTEXMAP_CH)
144   /** Alternative excitation is mapped to the pin of LESENSE channel
145    * (X+8 mod 16) where X is the active channel. */
146   lesenseAltExMapCH  = _LESENSE_CTRL_ALTEXMAP_CH,
147 #endif
148 } LESENSE_AltExMap_TypeDef;
149 #endif
150 
151 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
152 /** Result buffer interrupt and DMA trigger levels. */
153 typedef enum {
154   /** DMA and interrupt flags are set when the result buffer is half-full. */
155   lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
156 
157   /** DMA and interrupt flags set when the result buffer is full. */
158   lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL
159 } LESENSE_BufTrigLevel_TypeDef;
160 #endif
161 
162 /** Modes of operation for DMA wakeup from EM2. */
163 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
164 typedef enum {
165   /** No DMA wakeup from EM2. */
166   lesenseDMAWakeUpDisable  = LESENSE_CTRL_DMAWU_DISABLE,
167 
168   /** DMA wakeup from EM2 when data is valid in the result buffer. */
169   lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
170 
171   /** DMA wakeup from EM2 when the result buffer is full/half-full, depending on
172    *  RESBIDL configuration in the LESENSE_CTRL register (selected by the
173    *  resBufTrigLevel in LESENSE_ResBufTrigLevel_TypeDef descriptor structure). */
174   lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL
175 } LESENSE_DMAWakeUp_TypeDef;
176 #else
177 typedef enum {
178   /** No DMA wakeup from EM2. */
179   lesenseDMAWakeUpDisable  = LESENSE_CFG_DMAWU_DISABLE,
180 
181   /** DMA wakeup from EM2. */
182   lesenseDMAWakeUpEnable = LESENSE_CFG_DMAWU_ENABLE,
183 } LESENSE_DMAWakeUp_TypeDef;
184 #endif
185 
186 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
187 /** Bias modes. */
188 typedef enum {
189   /** Duty cycle bias module between low power and high accuracy mode. */
190   lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
191 
192   /** Bias module is always in high accuracy mode. */
193   lesenseBiasModeHighAcc   = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
194 
195   /** Bias module is controlled by EMU and not affected by the LESENSE. */
196   lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH
197 } LESENSE_BiasMode_TypeDef;
198 #endif
199 
200 /** Scan configuration. */
201 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
202 typedef enum {
203   /** Channel configuration registers (CHx_CONF) used are directly mapped to
204    *  the channel number. */
205   lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,
206 
207   /** Channel configuration registers used are CHx+8_CONF for channels 0-7
208    *  and CHx-8_CONF for channels 8-15. */
209   lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,
210 
211   /** Channel configuration registers used toggles between CHX_SCANCONF and
212    *  CHX+8_SCANCONF when channel x triggers. */
213   lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,
214 
215   /** Decoder state defines the channel configuration register (CHx_CONF) to
216    *  be used. */
217   lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
218 } LESENSE_ScanConfSel_TypeDef;
219 #else
220 typedef enum {
221   /** Channel configuration registers (CHx_CONF) used are directly mapped to
222    *  the channel number. */
223   lesenseScanConfDirMap = LESENSE_CFG_SCANCONF_DIRMAP,
224 
225   /** Channel configuration registers used are CHx+8_CONF for channels 0-7
226    *  and CHx-8_CONF for channels 8-15. */
227   lesenseScanConfInvMap = LESENSE_CFG_SCANCONF_INVMAP,
228 
229   /** Channel configuration registers used toggles between CHX_SCANCONF and
230    *  CHX+8_SCANCONF when channel x triggers. */
231   lesenseScanConfToggle = LESENSE_CFG_SCANCONF_TOGGLE,
232 
233   /** Decoder state defines the channel configuration register (CHx_CONF) to
234    *  be used. */
235   lesenseScanConfDecDef = LESENSE_CFG_SCANCONF_DECDEF
236 } LESENSE_ScanConfSel_TypeDef;
237 #endif
238 
239 /** DAC CHx data control configuration. */
240 typedef enum {
241   /** DAC channel x data is defined by the DAC_CHxDATA register.
242   *  Note: this value could be used for both DAC Ch0 and Ch1. */
243   lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,
244 
245 #if defined(_LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES)
246   /** DAC channel x data is defined by the ACMPTHRES in LESENSE_CHx_INTERACT.
247    *  Note: This value could be used for both DAC Ch0 and Ch1. */
248   lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES,
249 #endif
250 
251 #if defined(_LESENSE_PERCTRL_DACCH0DATA_THRES)
252   /** DAC channel x data is defined by the THRES in LESENSE_CHx_INTERACT.
253    *  Note: This value could be used for both DAC Ch0 and Ch1. */
254   lesenseThres     = _LESENSE_PERCTRL_DACCH0DATA_THRES,
255 #endif
256 } LESENSE_ControlDACData_TypeDef;
257 
258 #if defined(_LESENSE_PERCTRL_DACCH0CONV_MASK)
259 /** DAC channel x conversion mode configuration. */
260 typedef enum {
261   /** LESENSE does not control the DAC channel x.
262    *  Note: This value could be used for both DAC Ch0 and Ch1. */
263   lesenseDACConvModeDisable    = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,
264 
265   /** DAC channel x is driven in continuous mode.
266    *  Note: This value could be used for both DAC Ch0 and Ch1. */
267   lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,
268 
269   /** DAC channel x is driven in sample hold mode.
270    *  Note: This value could be used for both DAC Ch0 and Ch1. */
271   lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,
272 
273   /** DAC channel x is driven in sample off mode.
274    *  Note: This value could be used for both DAC Ch0 and Ch1. */
275   lesenseDACConvModeSampleOff  = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF
276 } LESENSE_ControlDACConv_TypeDef;
277 #endif
278 
279 #if defined(_LESENSE_PERCTRL_DACCH0OUT_MASK)
280 /** DAC channel x output mode configuration. */
281 typedef enum {
282   /** DAC CHx output to pin and ACMP/ADC disabled.
283    *  Note: This value could be used for both DAC Ch0 and Ch1. */
284   lesenseDACOutModeDisable    = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,
285 
286   /** DAC CHx output to pin enabled, output to ADC and ACMP disabled.
287    *  Note: This value could be used for both DAC Ch0 and Ch1. */
288   lesenseDACOutModePin        = _LESENSE_PERCTRL_DACCH0OUT_PIN,
289 
290   /** DAC CHx output to pin disabled, output to ADC and ACMP enabled.
291    *  Note: This value could be used for both DAC Ch0 and Ch1. */
292   lesenseDACOutModeADCACMP    = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,
293 
294   /** DAC CHx output to pin, ADC, and ACMP enabled.
295    *  Note: This value could be used for both DAC Ch0 and Ch1. */
296   lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP
297 } LESENSE_ControlDACOut_TypeDef;
298 #endif
299 
300 #if defined(_LESENSE_PERCTRL_DACREF_MASK)
301 /**  DAC reference configuration. */
302 typedef enum {
303   /** DAC uses VDD reference. */
304   lesenseDACRefVdd     = LESENSE_PERCTRL_DACREF_VDD,
305 
306   /** DAC uses band gap reference. */
307   lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
308 } LESENSE_DACRef_TypeDef;
309 #endif
310 
311 /** ACMPx control configuration. */
312 typedef enum {
313   /** LESENSE does not control ACMPx.
314    *  Note: This value could be used for both ACMP0 and ACMP1. */
315 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
316   lesenseACMPModeDisable  = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,
317 #endif
318 
319   /** LESENSE controls input mux of ACMPx.
320    *  Note: This value could be used for both ACMP0 and ACMP1. */
321   lesenseACMPModeMux      = _LESENSE_PERCTRL_ACMP0MODE_MUX,
322 
323   /** LESENSE controls input mux of and threshold value of ACMPx.
324    *  Note: This value could be used for both ACMP0 and ACMP1. */
325   lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES
326 } LESENSE_ControlACMP_TypeDef;
327 
328 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
329 /** Warm up modes. ACMP and DAC duty cycle mode configuration. */
330 typedef enum {
331   /** ACMPs and DACs are shut down when LESENSE is idle. */
332   lesenseWarmupModeNormal   = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
333 
334   /** ACMPs are kept powered up when LESENSE is idle. */
335   lesenseWarmupModeACMP     = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
336 
337   /** DAC is kept powered up when LESENSE is idle. */
338   lesenseWarmupModeDAC      = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
339 
340   /** ACMPs and DAC are kept powered up when LESENSE is idle. */
341   lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM
342 } LESENSE_WarmupMode_TypeDef;
343 #endif
344 
345 /** Decoder input source configuration. */
346 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
347 typedef enum {
348   /** SENSORSTATE register is used as input to the decoder. */
349   lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
350 
351   /** PRS channels are used as input to the decoder. */
352   lesenseDecInputPRS      = LESENSE_DECCTRL_INPUT_PRS
353 } LESENSE_DecInput_TypeDef;
354 #else
355   /** Ocelot only provides SENSORSTATE as input for the decoder. */
356 #endif
357 
358 /** Compare source selection for sensor sampling. */
359 typedef enum {
360   /** Counter output will be used in comparison. */
361 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
362   lesenseSampleModeCounter = 0x0 << _LESENSE_CH_INTERACT_SAMPLE_SHIFT,
363 #else
364   lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_ACMPCOUNT,
365 #endif
366 
367   /** ACMP output will be used in comparison. */
368   lesenseSampleModeACMP    = LESENSE_CH_INTERACT_SAMPLE_ACMP,
369 
370 #if defined(LESENSE_CH_INTERACT_SAMPLE_ADC)
371   /** ADC output will be used in comparison. */
372   lesenseSampleModeADC     = LESENSE_CH_INTERACT_SAMPLE_ADC,
373 
374   /** Differential ADC output will be used in comparison. */
375   lesenseSampleModeADCDiff = LESENSE_CH_INTERACT_SAMPLE_ADCDIFF,
376 #endif
377 } LESENSE_ChSampleMode_TypeDef;
378 
379 /** Interrupt generation setup for CHx interrupt flag. */
380 typedef enum {
381   /** No interrupt is generated. */
382   lesenseSetIntNone    = LESENSE_CH_INTERACT_SETIF_NONE,
383 
384   /** Set interrupt flag if the sensor triggers. */
385   lesenseSetIntLevel   = LESENSE_CH_INTERACT_SETIF_LEVEL,
386 
387   /** Set interrupt flag on positive edge of the sensor state. */
388   lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
389 
390   /** Set interrupt flag on negative edge of the sensor state. */
391   lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE
392 } LESENSE_ChIntMode_TypeDef;
393 
394 /** Channel pin mode for the excitation phase of the scan sequence. */
395 typedef enum {
396   /** Channel pin is disabled. */
397   lesenseChPinExDis    = LESENSE_CH_INTERACT_EXMODE_DISABLE,
398 
399   /** Channel pin is configured as push-pull, driven HIGH. */
400   lesenseChPinExHigh   = LESENSE_CH_INTERACT_EXMODE_HIGH,
401 
402   /** Channel pin is configured as push-pull, driven LOW. */
403   lesenseChPinExLow    = LESENSE_CH_INTERACT_EXMODE_LOW,
404 
405   /** DAC output (only available on channel 0, 1, 2, 3, 12, 13, 14 and 15) */
406   lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT
407 } LESENSE_ChPinExMode_TypeDef;
408 
409 /** Channel pin mode for the idle phase of scan sequence. */
410 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
411 typedef enum {
412   /** Channel pin is disabled in idle phase.
413    *  Note: This value could be used for all channels. */
414   lesenseChPinIdleDis    = _LESENSE_IDLECONF_CH0_DISABLE,
415 
416   /** Channel pin is configured as push-pull, driven HIGH in idle phase.
417    *  Note: This value could be used for all channels. */
418   lesenseChPinIdleHigh   = _LESENSE_IDLECONF_CH0_HIGH,
419 
420   /** Channel pin is configured as push-pull, driven LOW in idle phase.
421    *  Note: This value could be used for all channels. */
422   lesenseChPinIdleLow    = _LESENSE_IDLECONF_CH0_LOW,
423 
424 #if defined(_LESENSE_IDLECONF_CH0_DAC)
425   /** Channel pin is connected to DAC output in idle phase.
426    *  Note: This value could be used for all channels. */
427   lesenseChPinIdleDACC   = _LESENSE_IDLECONF_CH0_DAC
428 #else
429   /** Channel pin is connected to DAC CH0 output in idle phase.
430    *  Note: Only applies to channel 0, 1, 2, 3. */
431   lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,
432 
433   /** Channel pin is connected to DAC CH1 output in idle phase.
434    *  Note: Only applies to channel 12, 13, 14, 15. */
435   lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1,
436 #endif
437 } LESENSE_ChPinIdleMode_TypeDef;
438 #else
439 typedef enum {
440   /** Channel pin is disabled in idle phase.
441    *  Note: This value could be used for all channels. */
442   lesenseChPinIdleDis = _LESENSE_IDLECONF_CHIDLE0_DISABLE,
443 
444   /** Channel pin is configured as push-pull, driven HIGH in idle phase.
445    *  Note: This value could be used for all channels. */
446   lesenseChPinIdleHigh   = _LESENSE_IDLECONF_CHIDLE0_HIGH,
447 
448   /** Channel pin is configured as push-pull, driven LOW in idle phase.
449    *  Note: This value could be used for all channels. */
450   lesenseChPinIdleLow    = _LESENSE_IDLECONF_CHIDLE0_LOW,
451 
452   /** Channel pin is connected to DAC output in idle phase.
453    *  Note: This value could be used for all channels. */
454   lesenseChPinIdleDACC   = _LESENSE_IDLECONF_CHIDLE0_DAC
455 } LESENSE_ChPinIdleMode_TypeDef;
456 #endif
457 
458 /** Clock used for excitation and sample delay timing. */
459 typedef enum {
460   /** LFACLK (LF clock) is used. */
461   lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
462 
463   /** AUXHFRCO (HF clock) is used. */
464   lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
465 } LESENSE_ChClk_TypeDef;
466 
467 /** Compare modes for counter comparison. */
468 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
469 typedef enum {
470   /** Comparison evaluates to 1 if sensor data is less than the counter
471    *  threshold, or if ACMP output is 0. */
472   lesenseCompModeLess        = LESENSE_CH_EVAL_COMP_LESS,
473 
474   /** Comparison evaluates to 1 if sensor data is greater than, or equal to
475    *  the counter threshold, or if the ACMP output is 1. */
476   lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE
477 } LESENSE_ChCompMode_TypeDef;
478 #else
479 typedef enum {
480   /** Comparison evaluates to 1 if sensor data is less than the counter
481    *  threshold, or if ACMP output is 0. */
482   lesenseCompModeLess        = LESENSE_CH_EVALCFG_COMP_LESS,
483 
484   /** Comparison evaluates to 1 if sensor data is greater than, or equal to
485    *  the counter threshold, or if the ACMP output is 1. */
486   lesenseCompModeGreaterOrEq = LESENSE_CH_EVALCFG_COMP_GE
487 } LESENSE_ChCompMode_TypeDef;
488 #endif
489 
490 /** Sensor evaluation modes. */
491 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
492 #if defined(_LESENSE_CH_EVAL_MODE_MASK)
493 typedef enum {
494   /** Threshold comparison evaluation mode. In this mode, sensor data
495    *  is compared to the configured threshold value. Two possible comparison
496    *  operators can be used on sensor data, either >= (GE) or < (LT).
497    *  Which operator to use is given using the
498    *  @ref LESENSE_ChDesc_TypeDef::compMode member. */
499   lesenseEvalModeThreshold        = _LESENSE_CH_EVAL_MODE_THRES,
500 
501   /** Sliding window evaluation mode. In this mode, sensor data is
502    *  evaluated against upper and lower limits of a window range. The
503    *  windows range is defined by a base value and a window size. */
504   lesenseEvalModeSlidingWindow    = _LESENSE_CH_EVAL_MODE_SLIDINGWIN,
505 
506   /** Step detection evaluation mode. In this mode, the sensor data is compared
507    *  to the sensor data from the previous measurement. Sensor evaluation
508    *  will result in a "1" if the difference between current measurement
509    *  and previous one is greater than a configurable "step size". If the
510    *  difference is less than the configured step size then sensor
511    *  evaluation will result in a "0". */
512   lesenseEvalModeStepDetection    = _LESENSE_CH_EVAL_MODE_STEPDET,
513 } LESENSE_ChEvalMode_TypeDef;
514 #endif
515 #else
516 typedef enum {
517   /** Threshold comparison evaluation mode. In this mode, sensor data
518    *  is compared to the configured threshold value. Two possible comparison
519    *  operators can be used on sensor data, either >= (GE) or < (LT).
520    *  Which operator to use is given using the
521    *  @ref LESENSE_ChDesc_TypeDef::compMode member. */
522   lesenseEvalModeThreshold        = _LESENSE_CH_EVALCFG_MODE_THRES,
523 
524   /** Sliding window evaluation mode. In this mode, sensor data is
525    *  evaluated against upper and lower limits of a window range. The
526    *  windows range is defined by a base value and a window size. */
527   lesenseEvalModeSlidingWindow    = _LESENSE_CH_EVALCFG_MODE_SLIDINGWIN,
528 
529   /** Step detection evaluation mode. In this mode, the sensor data is compared
530    *  to the sensor data from the previous measurement. Sensor evaluation
531    *  will result in a "1" if the difference between current measurement
532    *  and previous one is greater than a configurable "step size". If the
533    *  difference is less than the configured step size then sensor
534    *  evaluation will result in a "0". */
535   lesenseEvalModeStepDetection    = _LESENSE_CH_EVALCFG_MODE_STEPDET,
536 } LESENSE_ChEvalMode_TypeDef;
537 #endif
538 
539 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
540 /** Idle phase configuration of the alternate excitation channels. */
541 typedef enum {
542   /** ALTEX output is disabled in idle phase.
543    *  Note: This value could be used for all the alternate excitation channels. */
544   lesenseAltExPinIdleDis  = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,
545 
546   /** ALTEX output is high in idle phase.
547    *  Note: This value could be used for all the alternate excitation channels. */
548   lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,
549 
550   /** ALTEX output is low in idle phase.
551    *  Note: This value could be used for all the alternate excitation channels. */
552   lesenseAltExPinIdleLow  = _LESENSE_ALTEXCONF_IDLECONF0_LOW
553 } LESENSE_AltExPinIdle_TypeDef;
554 #endif
555 
556 /** Transition action modes. */
557 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
558 typedef enum {
559   /** No PRS pulses generated (if PRSCOUNT == 0).
560    *  Do not count (if PRSCOUNT == 1). */
561   lesenseTransActNone        = LESENSE_ST_TCONFA_PRSACT_NONE,
562 
563   /** Generate pulse on LESPRS0 (if PRSCOUNT == 0). */
564   lesenseTransActPRS0        = LESENSE_ST_TCONFA_PRSACT_PRS0,
565 
566   /** Generate pulse on LESPRS1 (if PRSCOUNT == 0). */
567   lesenseTransActPRS1        = LESENSE_ST_TCONFA_PRSACT_PRS1,
568 
569   /** Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). */
570   lesenseTransActPRS01       = LESENSE_ST_TCONFA_PRSACT_PRS01,
571 
572   /** Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). */
573   lesenseTransActPRS2        = LESENSE_ST_TCONFA_PRSACT_PRS2,
574 
575   /** Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). */
576   lesenseTransActPRS02       = LESENSE_ST_TCONFA_PRSACT_PRS02,
577 
578   /** Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
579   lesenseTransActPRS12       = LESENSE_ST_TCONFA_PRSACT_PRS12,
580 
581   /** Generate pulse on LESPRS0, LESPRS1 and LESPRS2  (if PRSCOUNT == 0). */
582   lesenseTransActPRS012      = LESENSE_ST_TCONFA_PRSACT_PRS012,
583 
584   /** Count up (if PRSCOUNT == 1). */
585   lesenseTransActUp          = LESENSE_ST_TCONFA_PRSACT_UP,
586 
587   /** Count down (if PRSCOUNT == 1). */
588   lesenseTransActDown        = LESENSE_ST_TCONFA_PRSACT_DOWN,
589 
590   /** Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
591   lesenseTransActUpAndPRS2   = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
592 
593   /** Count down and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
594   lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2
595 } LESENSE_StTransAct_TypeDef;
596 #else
597 typedef enum {
598   /** No PRS pulses generated (if PRSCOUNT == 0).
599    *  Do not count (if PRSCOUNT == 1). */
600   lesenseTransActNone        = LESENSE_ST_ARC_PRSACT_NONE,
601 
602   /** Generate pulse on LESPRS0 (if PRSCOUNT == 0). */
603   lesenseTransActPRS0        = LESENSE_ST_ARC_PRSACT_PRS0,
604 
605   /** Generate pulse on LESPRS1 (if PRSCOUNT == 0). */
606   lesenseTransActPRS1        = LESENSE_ST_ARC_PRSACT_PRS1,
607 
608   /** Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). */
609   lesenseTransActPRS01       = LESENSE_ST_ARC_PRSACT_PRS01,
610 
611   /** Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). */
612   lesenseTransActPRS2        = LESENSE_ST_ARC_PRSACT_PRS2,
613 
614   /** Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). */
615   lesenseTransActPRS02       = LESENSE_ST_ARC_PRSACT_PRS02,
616 
617   /** Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
618   lesenseTransActPRS12       = LESENSE_ST_ARC_PRSACT_PRS12,
619 
620   /** Generate pulse on LESPRS0, LESPRS1 and LESPRS2  (if PRSCOUNT == 0). */
621   lesenseTransActPRS012      = LESENSE_ST_ARC_PRSACT_PRS012,
622 
623   /** Count up (if PRSCOUNT == 1). */
624   lesenseTransActUp          = LESENSE_ST_ARC_PRSACT_UP,
625 
626   /** Count down (if PRSCOUNT == 1). */
627   lesenseTransActDown        = LESENSE_ST_ARC_PRSACT_DOWN,
628 
629   /** Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
630   lesenseTransActUpAndPRS2   = LESENSE_ST_ARC_PRSACT_UPANDPRS2,
631 
632   /** Count down and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
633   lesenseTransActDownAndPRS2 = LESENSE_ST_ARC_PRSACT_DOWNANDPRS2
634 } LESENSE_StTransAct_TypeDef;
635 #endif
636 
637 /*******************************************************************************
638  *******************************   STRUCTS   ***********************************
639  ******************************************************************************/
640 
641 /** Core control (LESENSE_CTRL/CFG) descriptor structure. */
642 typedef struct {
643   /** Select scan start mode to control how the scan start is being triggered.*/
644   LESENSE_ScanMode_TypeDef     scanStart;
645 
646   /** Select PRS source for scan start if scanMode is set to lesensePrsPulse. */
647   LESENSE_PRSSel_TypeDef       prsSel;
648 
649   /** Select scan configuration register usage strategy. */
650   LESENSE_ScanConfSel_TypeDef  scanConfSel;
651 
652   /** Set to true to invert ACMP0 output. */
653   bool                         invACMP0;
654 
655   /** Set to true to invert ACMP1 output. */
656   bool                         invACMP1;
657 
658   /** Set to true to sample both ACMPs simultaneously. */
659   bool                         dualSample;
660 
661   /** Set to true in order to store SCANRES in the RAM (accessible via RESDATA)
662    *  after each scan. */
663   bool                         storeScanRes;
664 
665 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
666   /** Set to true in order to always make LESENSE write to the result buffer,
667    *  even if it is full. */
668   bool                         bufOverWr;
669 #endif
670 
671 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
672   /** Select trigger conditions for the interrupt and DMA. */
673   LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
674 #else
675   /** Select result FIFO interrupt and DMA trigger level.*/
676   uint8_t                      fifoTrigLevel;
677 #endif
678 
679   /** Configure trigger condition for the DMA wakeup from EM2. */
680   LESENSE_DMAWakeUp_TypeDef    wakeupOnDMA;
681 
682 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
683   /** Select bias mode. */
684   LESENSE_BiasMode_TypeDef     biasMode;
685 #endif
686 
687   /** Set to true to keep LESENSE running in the debug mode. */
688   bool                         debugRun;
689 } LESENSE_CoreCtrlDesc_TypeDef;
690 
691 /** Default configuration for LESENSE_CtrlDesc_TypeDef structure. */
692 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
693 #define LESENSE_CORECTRL_DESC_DEFAULT                                                               \
694   {                                                                                                 \
695     lesenseScanStartPeriodic,/* Start new scan each time the period counter overflows. */           \
696     lesensePRSCh0,           /* Default PRS channel is selected. */                                 \
697     lesenseScanConfDirMap,   /* Direct mapping SCANCONF register usage strategy. */                 \
698     false,                   /* Do not invert ACMP0 output. */                                      \
699     false,                   /* Do not invert ACMP1 output. */                                      \
700     false,                   /* Disable dual sampling. */                                           \
701     true,                    /* Store scan result after each scan. */                               \
702     true,                    /* Overwrite result buffer register even if it is full. */             \
703     lesenseBufTrigHalf,      /* Trigger interrupt and DMA request if result buffer is half full. */ \
704     lesenseDMAWakeUpDisable, /* Do not wake up on DMA from EM2. */                                  \
705     lesenseBiasModeDontTouch,/* Do not touch bias configuration. */                                 \
706     true                     /* Keep LESENSE running in debug mode. */                              \
707   }
708 #else
709 #define LESENSE_CORECTRL_DESC_DEFAULT                                                                \
710   {                                                                                                  \
711     lesenseScanStartPeriodic,/* Start new scan each time the period counter overflows. */            \
712     lesensePRSCh0,           /* Default PRS channel is selected. */                                  \
713     lesenseScanConfDirMap,   /* Direct mapping SCANCONF register usage strategy. */                  \
714     false,                   /* Do not invert ACMP0 output. */                                       \
715     false,                   /* Do not invert ACMP1 output. */                                       \
716     false,                   /* Disable dual sampling. */                                            \
717     true,                    /* Store scan result after each scan. */                                \
718     15u,                     /* Default value for the fifo trigger level */ \
719     lesenseDMAWakeUpDisable, /* Do not wake up on DMA from EM2. */                                   \
720     true                     /* Keep LESENSE running in debug mode. */                               \
721   }
722 #endif
723 
724 /** LESENSE timing control descriptor structure. */
725 typedef struct {
726   /** Set number of LFACLK cycles to delay sensor interaction on
727    *  each channel. Valid range: 0-3 (2 bit). */
728   uint8_t startDelay;
729 
730   /**
731    * Set to true do delay startup of AUXHFRCO until the system enters
732    * excite phase. This will reduce the time AUXHFRCO is enabled and
733    * reduce power usage. */
734   bool    delayAuxStartup;
735 } LESENSE_TimeCtrlDesc_TypeDef;
736 
737 /** Default configuration for LESENSE_TimeCtrlDesc_TypeDef structure. */
738 #define LESENSE_TIMECTRL_DESC_DEFAULT              \
739   {                                                \
740     0U, /* No sensor interaction delay. */         \
741     false /* Do not delay the AUXHFRCO startup. */ \
742   }
743 
744 /** LESENSE peripheral control descriptor structure. */
745 typedef struct {
746   /** Configure DAC channel 0 data control. */
747   LESENSE_ControlDACData_TypeDef dacCh0Data;
748 
749 #if defined(_LESENSE_PERCTRL_DACCH0CONV_MASK)
750   /** Configure how LESENSE controls conversion on DAC channel 0. */
751   LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
752 #endif
753 
754 #if defined(_LESENSE_PERCTRL_DACCH0OUT_MASK)
755   /** Configure how LESENSE controls output on DAC channel 0. */
756   LESENSE_ControlDACOut_TypeDef  dacCh0OutMode;
757 #endif
758 
759 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
760   /** Configure DAC channel 1 data control. */
761   LESENSE_ControlDACData_TypeDef dacCh1Data;
762 #endif
763 
764 #if defined(_LESENSE_PERCTRL_DACCH1CONV_MASK)
765   /** Configure how LESENSE controls conversion on DAC channel 1. */
766   LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
767 #endif
768 
769 #if defined(_LESENSE_PERCTRL_DACCH1OUT_MASK)
770   /** Configure how LESENSE controls output on DAC channel 1. */
771   LESENSE_ControlDACOut_TypeDef  dacCh1OutMode;
772 #endif
773 
774 #if defined(_LESENSE_PERCTRL_DACPRESC_MASK)
775   /** Configure the prescaling factor for the LESENSE - DAC interface.
776    *  Valid range: 0-31 (5-bit). */
777   uint8_t                        dacPresc;
778 #endif
779 
780 #if defined(_LESENSE_PERCTRL_DACREF_MASK)
781   /** Configure the DAC reference to be used. Set to #lesenseDACRefVdd to use
782    *  VDD and set to #lesenseDACRefBandGap to use band gap as reference. */
783   LESENSE_DACRef_TypeDef         dacRef;
784 #endif
785 
786   /** Configure how LESENSE controls ACMP 0. */
787   LESENSE_ControlACMP_TypeDef    acmp0Mode;
788 
789   /** Configure how LESENSE controls ACMP 1. */
790   LESENSE_ControlACMP_TypeDef    acmp1Mode;
791 
792 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
793   /** Configure how LESENSE controls ACMPs and DAC in idle mode. */
794   LESENSE_WarmupMode_TypeDef     warmupMode;
795 #endif
796 
797 #if defined(_LESENSE_PERCTRL_DACCONVTRIG_MASK)
798   /** When set to true the DAC is only enabled once for each scan. When
799    *  set to false the DAC is enabled before every channel measurement. */
800   bool                           dacScan;
801 #endif
802 
803 #if defined(_LESENSE_PERCTRL_DACSTARTUP_MASK)
804   /** When set to true the DAC is started a half clock cycle before sensor
805   *  interaction starts. When set to false, a full clock cycle is used. */
806   bool                           dacStartupHalf;
807 #endif
808 
809 #if defined(_LESENSE_PERCTRL_DACCH0EN_MASK)
810   /** When set to true, LESENSE controls DAC channel 0. */
811   bool                           dacCh0En;
812 #endif
813 
814 #if defined(_LESENSE_PERCTRL_DACCH1EN_MASK)
815   /** When set to true, LESENSE controls DAC channel 1. */
816   bool                           dacCh1En;
817 #endif
818 } LESENSE_PerCtrlDesc_TypeDef;
819 
820 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
821 #if defined(_SILICON_LABS_32B_SERIES_0)
822 #define LESENSE_PERCTRL_DESC_DEFAULT                                                                 \
823   {                                                                                                  \
824     lesenseDACIfData,         /* DAC channel 0 data is defined by DAC_CH0DATA register */            \
825     lesenseDACConvModeDisable,/* LESENSE does not control DAC CH0. */                                \
826     lesenseDACOutModeDisable, /* DAC channel 0 output to pin disabled. */                            \
827     lesenseDACIfData,         /* DAC channel 1 data is defined by DAC_CH1DATA register */            \
828     lesenseDACConvModeDisable,/* LESENSE does not control DAC CH1. */                                \
829     lesenseDACOutModeDisable, /* DAC channel 1 output to pin disabled. */                            \
830     0U,                       /* DAC prescaling factor of 1 (0+1). */                                \
831     lesenseDACRefVdd,         /* DAC uses VDD reference. */                                          \
832     lesenseACMPModeMuxThres,  /* LESENSE controls input mux and threshold value of ACMP0.         */ \
833     lesenseACMPModeMuxThres,  /* LESENSE controls input mux and threshold value of ACMP1.         */ \
834     lesenseWarmupModeKeepWarm /* Keep both ACMPs and DAC powered up when LESENSE is idle. */         \
835   }
836 #elif defined(_SILICON_LABS_32B_SERIES_1)
837 #define LESENSE_PERCTRL_DESC_DEFAULT                                                                 \
838   {                                                                                                  \
839     lesenseDACIfData,         /* DAC channel 0 data is defined by DAC_CH0DATA register. */           \
840     lesenseDACIfData,         /* DAC channel 1 data is defined by DAC_CH1DATA register. */           \
841     lesenseACMPModeMuxThres,  /* LESENSE controls input mux and threshold value of ACMP0.         */ \
842     lesenseACMPModeMuxThres,  /* LESENSE controls input mux and threshold value of ACMP1.         */ \
843     lesenseWarmupModeKeepWarm,/* Keep both ACMPs and DAC powered up when LESENSE is idle.     */     \
844     false,                    /* DAC is enabled for before every channel measurement. */             \
845     false,                    /* DAC is enabled a full clock cycle before sensor interaction */      \
846     false,                    /* LESENSE does not control DAC channel 0. */                          \
847     false                     /* LESENSE does not control DAC channel 1. */                          \
848   }
849 #else
850 #define LESENSE_PERCTRL_DESC_DEFAULT                                                                 \
851   {                                                                                                  \
852     lesenseDACIfData,         /* DAC channel 0 data is defined by DAC_CH0DATA register. */           \
853     lesenseACMPModeMuxThres,  /* LESENSE controls input mux and threshold value of ACMP0.         */ \
854     lesenseACMPModeMuxThres,  /* LESENSE controls input mux and threshold value of ACMP1.         */ \
855     false,                    /* DAC is enabled for before every channel measurement. */             \
856     false,                    /* DAC is enabled a full clock cycle before sensor interaction */      \
857   }
858 #endif
859 
860 /** LESENSE decoder control descriptor structure. */
861 typedef struct {
862 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
863   /** Select input to the LESENSE decoder. */
864   LESENSE_DecInput_TypeDef decInput;
865 
866   /** Initial state of the LESENSE decoder. */
867   uint32_t                 initState;
868 #endif
869 
870   /** Set to enable decoder to check the present state in addition
871    *  to the states defined in TCONF. */
872   bool                     chkState;
873 
874   /** When set, a transition from state x in decoder will set the interrupt flag
875    *  CHx. */
876   bool                     intMap;
877 
878   /** Set to enable hysteresis in decoder for suppressing the changes on PRS
879    *  channel 0. */
880   bool                     hystPRS0;
881 
882   /** Set to enable hysteresis in decoder for suppressing the changes on PRS
883    *  channel 1. */
884   bool                     hystPRS1;
885 
886   /** Set to enable hysteresis in decoder for suppressing the changes on PRS
887    *  channel 2. */
888   bool                     hystPRS2;
889 
890   /** Set to enable hysteresis in decoder for suppressing the interrupt
891    *  requests. */
892   bool                     hystIRQ;
893 
894   /** Set to enable count mode on decoder PRS channels 0 and 1 to produce
895    *  outputs which can be used by a PCNT to count up or down. */
896   bool                     prsCount;
897 
898 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
899   /** Select PRS channel input for bit 0 of LESENSE decoder. */
900   LESENSE_PRSSel_TypeDef   prsChSel0;
901 
902   /** Select PRS channel input for bit 1 of LESENSE decoder. */
903   LESENSE_PRSSel_TypeDef   prsChSel1;
904 
905   /** Select PRS channel input for bit 2 of LESENSE decoder. */
906   LESENSE_PRSSel_TypeDef   prsChSel2;
907 
908   /** Select PRS channel input for bit 3 of LESENSE decoder. */
909   LESENSE_PRSSel_TypeDef   prsChSel3;
910 #endif
911 } LESENSE_DecCtrlDesc_TypeDef;
912 
913 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
914 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
915 #define LESENSE_DECCTRL_DESC_DEFAULT                                                         \
916   {                                                                                          \
917     lesenseDecInputSensorSt, /* SENSORSTATE register is used as input to decoder.         */ \
918     0U,                      /* State 0 is the initial state of decoder. */                  \
919     false,                   /* Disable check of current state. */                           \
920     true,                    /* Enable channel x % 16 interrupt on state x change. */        \
921     true,                    /* Enable decoder hysteresis on PRS0 output. */                 \
922     true,                    /* Enable decoder hysteresis on PRS1 output. */                 \
923     true,                    /* Enable decoder hysteresis on PRS2 output. */                 \
924     true,                    /* Enable decoder hysteresis on PRS3 output. */                 \
925     false,                   /* Disable count mode on decoder PRS channels 0 and 1*/         \
926     lesensePRSCh0,           /* PRS Channel 0 as input for bit 0 of LESENSE decoder. */      \
927     lesensePRSCh1,           /* PRS Channel 1 as input for bit 1 of LESENSE decoder. */      \
928     lesensePRSCh2,           /* PRS Channel 2 as input for bit 2 of LESENSE decoder. */      \
929     lesensePRSCh3,           /* PRS Channel 3 as input for bit 3 of LESENSE decoder. */      \
930   }
931 #else
932 #define LESENSE_DECCTRL_DESC_DEFAULT                                                    \
933   {                                                                                     \
934     false,                   /* Disable check of current state. */                      \
935     true,                    /* Enable channel x % 16 interrupt on state x change. */   \
936     true,                    /* Enable decoder hysteresis on PRS0 output. */            \
937     true,                    /* Enable decoder hysteresis on PRS1 output. */            \
938     true,                    /* Enable decoder hysteresis on PRS2 output. */            \
939     true,                    /* Enable decoder hysteresis on PRS3 output. */            \
940     false,                   /* Disable count mode on decoder PRS channels 0 and 1*/    \
941   }
942 #endif
943 
944 /** LESENSE module initialization structure. */
945 typedef struct {
946   /** LESENSE core configuration parameters. */
947   LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
948 
949   /** LESENSE timing configuration parameters. */
950   LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
951 
952   /** LESENSE peripheral configuration parameters. */
953   LESENSE_PerCtrlDesc_TypeDef  perCtrl;
954 
955   /** LESENSE decoder configuration parameters. */
956   LESENSE_DecCtrlDesc_TypeDef  decCtrl;
957 } LESENSE_Init_TypeDef;
958 
959 /** Default configuration for LESENSE_Init_TypeDef structure. */
960 #define LESENSE_INIT_DEFAULT                                                                \
961   {                                                                                         \
962     .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */       \
963     .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */       \
964     .perCtrl  = LESENSE_PERCTRL_DESC_DEFAULT,  /* Default peripheral control parameters. */ \
965     .decCtrl  = LESENSE_DECCTRL_DESC_DEFAULT   /* Default decoder control parameters. */    \
966   }
967 
968 /** Channel descriptor structure. */
969 typedef struct {
970   /** Set to enable scan channel CHx. */
971   bool                          enaScanCh;
972 
973   /** Set to enable CHx pin. */
974   bool                          enaPin;
975 
976   /** Enable/disable channel interrupts after configuring all the sensor channel
977    *  parameters. */
978   bool                          enaInt;
979 
980   /** Configure channel pin mode for the excitation phase of the scan sequence.
981    *  Note: OPAOUT is only available on channels 2, 3, 4, and 5. */
982   LESENSE_ChPinExMode_TypeDef   chPinExMode;
983 
984   /** Configure channel pin idle setup in LESENSE idle phase. */
985   LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
986 
987   /** Set to use alternate excite pin for excitation. */
988   bool                          useAltEx;
989 
990   /** Set to enable result from this channel being shifted into the decoder
991    *  register. */
992   bool                          shiftRes;
993 
994   /** Set to invert result bit stored in the SCANRES register. */
995   bool                          invRes;
996 
997   /** Set to store counter value in the RAM (accessible via RESDATA) and make
998    *  the comparison result available in the SCANRES register. */
999   bool                          storeCntRes;
1000 
1001   /** Select clock used for the excitation timing. */
1002   LESENSE_ChClk_TypeDef         exClk;
1003 
1004   /** Select clock used for the sample delay timing. */
1005   LESENSE_ChClk_TypeDef         sampleClk;
1006 
1007   /** Configure the excitation time. Excitation will last exTime+1 excitation clock
1008    *  cycles. Valid range: 0-63 (6 bits). */
1009   uint8_t                       exTime;
1010 
1011   /** Configure the sample delay. Sampling will occur after sampleDelay+1 sample
1012    *  clock cycles. Valid range: 0-127 (7 bits) or 0-255 (8 bits) depending on
1013    *  device. */
1014   uint8_t                       sampleDelay;
1015 
1016   /** Configure the measure delay. Sensor measuring is delayed for measDelay
1017    *  excitation clock cycles. Valid range: 0-127 (7 bits) or 0-1023 (10 bits)
1018    *  depending on device. */
1019   uint16_t                       measDelay;
1020 
1021   /** Configure the ACMP threshold or the DAC data.
1022    *  If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseDACIfData,
1023    *  acmpThres defines the 12-bit DAC data in the corresponding data register
1024    *  of DAC interface (DACn_CH0DATA and DACn_CH1DATA).
1025    *  In this case, the valid range is: 0-4095 (12 bits).
1026    *  If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to lesenseACMPThres,
1027    *  acmpThres defines the 6-bit Vdd scaling factor of ACMP negative input
1028    *  (VDDLEVEL in ACMP_INPUTSEL register).
1029    *  In this case, the valid range is: 0-63 (6 bits). */
1030   uint16_t                     acmpThres;
1031 
1032   /** Select if the ACMP output, the ADC output or the counter output should be used in
1033    *  comparison. */
1034   LESENSE_ChSampleMode_TypeDef sampleMode;
1035 
1036   /** Configure the interrupt generation mode for the CHx interrupt flag. */
1037   LESENSE_ChIntMode_TypeDef    intMode;
1038 
1039   /** Configure the decision threshold for the sensor data comparison.
1040    *  Valid range: 0-65535 (16 bits). */
1041   uint16_t                     cntThres;
1042 
1043   /** Select the mode for counter comparison. */
1044   LESENSE_ChCompMode_TypeDef   compMode;
1045 
1046 #if defined(_LESENSE_CH_EVAL_MODE_MASK) || defined(_SILICON_LABS_32B_SERIES_2)
1047   /** Select the sensor evaluation mode. */
1048   LESENSE_ChEvalMode_TypeDef   evalMode;
1049 #endif
1050 } LESENSE_ChDesc_TypeDef;
1051 
1052 /** Configuration structure for all the scan channels. */
1053 typedef struct {
1054   /** Channel descriptor for all the LESENSE channels. */
1055   LESENSE_ChDesc_TypeDef Ch[LESENSE_NUM_CHANNELS];
1056 } LESENSE_ChAll_TypeDef;
1057 
1058 /** Default configuration for the scan channel. */
1059 #if defined(_LESENSE_CH_EVAL_MODE_MASK) || defined(_SILICON_LABS_32B_SERIES_2)
1060 #define LESENSE_CH_CONF_DEFAULT                                                                         \
1061   {                                                                                                     \
1062     false,                   /* Disable scan channel. */                                                \
1063     false,                   /* Disable assigned pin on scan channel. */                                \
1064     false,                   /* Disable interrupts on channel. */                                       \
1065     lesenseChPinExDis,       /* Channel pin is disabled during excitation period. */                    \
1066     lesenseChPinIdleDis,     /* Channel pin is disabled during idle period. */                          \
1067     false,                   /* Do not use alternate excitation pins for excitation. */                 \
1068     false,                   /* Disabled to shift results from this channel to decoder register.     */ \
1069     false,                   /* Disabled to invert scan result bit. */                                  \
1070     false,                   /* Disabled to store counter value in result buffer. */                    \
1071     lesenseClkLF,            /* Use LF clock for excitation timing. */                                  \
1072     lesenseClkLF,            /* Use LF clock for sample timing. */                                      \
1073     0x00U,                   /* Excitation time is set to 0(+1) excitation clock cycles. */             \
1074     0x00U,                   /* Sample delay is set to 0(+1) sample clock cycles. */                    \
1075     0x00U,                   /* Measure delay is set to 0 excitation clock cycles.*/                    \
1076     0x00U,                   /* ACMP threshold has been set to 0. */                                    \
1077     lesenseSampleModeACMP,   /* ACMP output will be used in comparison. */                              \
1078     lesenseSetIntNone,       /* No interrupt is generated by the channel. */                            \
1079     0x00U,                   /* Counter threshold has bee set to 0x00. */                               \
1080     lesenseCompModeLess,     /* Compare mode has been set to trigger interrupt on "less". */            \
1081     lesenseEvalModeThreshold /* Evaluation mode has been set to trigger interrupt on threshold. */      \
1082   }
1083 #else
1084 #define LESENSE_CH_CONF_DEFAULT                                                                         \
1085   {                                                                                                     \
1086     false,                   /* Disable scan channel. */                                                \
1087     false,                   /* Disable assigned pin on scan channel. */                                \
1088     false,                   /* Disable interrupts on channel. */                                       \
1089     lesenseChPinExDis,       /* Channel pin is disabled during excitation period. */                    \
1090     lesenseChPinIdleDis,     /* Channel pin is disabled during idle period. */                          \
1091     false,                   /* Do not use alternate excitation pins for excitation. */                 \
1092     false,                   /* Disabled to shift results from this channel to decoder register.     */ \
1093     false,                   /* Disabled to invert scan result bit. */                                  \
1094     false,                   /* Disabled to store counter value in result buffer. */                    \
1095     lesenseClkLF,            /* Use LF clock for excitation timing. */                                  \
1096     lesenseClkLF,            /* Use LF clock for sample timing. */                                      \
1097     0x00U,                   /* Excitation time is set to 0(+1) excitation clock cycles. */             \
1098     0x00U,                   /* Sample delay is set to 0(+1) sample clock cycles. */                    \
1099     0x00U,                   /* Measure delay is set to 0 excitation clock cycles.*/                    \
1100     0x00U,                   /* ACMP threshold has been set to 0. */                                    \
1101     lesenseSampleModeACMP,   /* ACMP output will be used in comparison. */                              \
1102     lesenseSetIntNone,       /* No interrupt is generated by the channel. */                            \
1103     0x00U,                   /* Counter threshold has bee set to 0x00. */                               \
1104     lesenseCompModeLess      /* Compare mode has been set to trigger interrupt on "less". */            \
1105   }
1106 #endif
1107 
1108 /** Default configuration for all the sensor channels. */
1109 #define LESENSE_SCAN_CONF_DEFAULT                     \
1110   {                                                   \
1111     {                                                 \
1112       LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */  \
1113       LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */  \
1114       LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */  \
1115       LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */  \
1116       LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */  \
1117       LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */  \
1118       LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */  \
1119       LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */  \
1120       LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */  \
1121       LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */  \
1122       LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \
1123       LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \
1124       LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \
1125       LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \
1126       LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \
1127       LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \
1128     }                                                 \
1129   }
1130 
1131 /** Alternate excitation descriptor structure. */
1132 typedef struct {
1133   /** Configure alternate excitation pins. If set, the corresponding alternate
1134    *  excitation pin/signal is enabled. */
1135   bool                         enablePin;
1136 
1137 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1138   /** Configure idle phase setup of alternate excitation pins.
1139      The idleConf parameter is not valid when altExMap==lesenseAltExMapACMP. */
1140   LESENSE_AltExPinIdle_TypeDef idleConf;
1141 
1142   /** Configure how to control external alternate excitation pins. Only
1143    *  applies if altExMap has been set to lesenseAltExMapALTEX.
1144    *  If true, excitation happens on the corresponding alternate excitation
1145    *  pin during excitation periods of all the enabled channels.
1146    *  If false, excitation happens on the corresponding alternate excitation
1147    *  pin ONLY during excitation period of the corresponding channel.
1148    *  The alwaysEx parameter is not valid when altExMap==lesenseAltExMapACMP. */
1149   bool                         alwaysEx;
1150 #endif
1151 } LESENSE_AltExDesc_TypeDef;
1152 
1153 /** Configuration structure for the alternate excitation. */
1154 typedef struct {
1155 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1156   /** Select alternate excitation mapping. */
1157   LESENSE_AltExMap_TypeDef  altExMap;
1158 #endif
1159 
1160   /** Alternate excitation channel descriptors.
1161    *  When altExMap==lesenseAltExMapALTEX, only the 8 first descriptors are used.
1162    *  In this mode they describe the configuration of LES_ALTEX0-7 pins.
1163    *  When altExMap==lesenseAltExMapACMP, all 16 descriptors are used. In this
1164    *  mode they describe the configuration of the 16 possible ACMP0-1 excitation
1165    *  channels. Please refer to the user manual for a complete mapping of
1166    *  routing.
1167    *  NOTE:
1168    *  Some parameters in the descriptors are not valid when
1169    *  altExMap==lesenseAltExMapACMP. Refer to the definition of the
1170    *  LESENSE_AltExDesc_TypeDef structure for details regarding which parameters
1171    *  are valid. */
1172   LESENSE_AltExDesc_TypeDef AltEx[16];
1173 } LESENSE_ConfAltEx_TypeDef;
1174 
1175 /** Default configuration for the alternate excitation channel. */
1176 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1177 #define LESENSE_ALTEX_CH_CONF_DEFAULT                                          \
1178   {                                                                            \
1179     false,               /* Alternate excitation disabled.*/                   \
1180     lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \
1181     false                /* Excite only for corresponding channel. */          \
1182   }
1183 #else
1184 #define LESENSE_ALTEX_CH_CONF_DEFAULT                     \
1185   {                                                       \
1186     false             /* Alternate excitation disabled.*/ \
1187   }
1188 #endif
1189 
1190 /** Default configuration for all the alternate excitation channels. */
1191 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1192 #if defined(_LESENSE_CTRL_ALTEXMAP_ACMP)
1193 #define LESENSE_ALTEX_CONF_DEFAULT                                          \
1194   {                                                                         \
1195     lesenseAltExMapACMP,                                                    \
1196     {                                                                       \
1197       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */  \
1198       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */  \
1199       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */  \
1200       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */  \
1201       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */  \
1202       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */  \
1203       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */  \
1204       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */  \
1205       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */  \
1206       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */  \
1207       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
1208       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
1209       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
1210       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
1211       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
1212       LESENSE_ALTEX_CH_CONF_DEFAULT  /* Alternate excitation channel 15. */ \
1213     }                                                                       \
1214   }
1215 #else
1216 #define LESENSE_ALTEX_CONF_DEFAULT                                          \
1217   {                                                                         \
1218     lesenseAltExMapCH,                                                      \
1219     {                                                                       \
1220       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */  \
1221       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */  \
1222       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */  \
1223       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */  \
1224       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */  \
1225       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */  \
1226       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */  \
1227       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */  \
1228       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */  \
1229       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */  \
1230       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
1231       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
1232       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
1233       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
1234       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
1235       LESENSE_ALTEX_CH_CONF_DEFAULT  /* Alternate excitation channel 15. */ \
1236     }                                                                       \
1237   }
1238 #endif
1239 #else
1240 #define LESENSE_ALTEX_CONF_DEFAULT                                          \
1241   {                                                                         \
1242     {                                                                       \
1243       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */  \
1244       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */  \
1245       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */  \
1246       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */  \
1247       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */  \
1248       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */  \
1249       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */  \
1250       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */  \
1251       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */  \
1252       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */  \
1253       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
1254       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
1255       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
1256       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
1257       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
1258       LESENSE_ALTEX_CH_CONF_DEFAULT /* Alternate excitation channel 15. */  \
1259     }                                                                       \
1260   }
1261 #endif
1262 
1263 /** Decoder state condition descriptor structure. */
1264 typedef struct {
1265   /** Configure compare value. State transition is triggered when the sensor state
1266    *  equals to this value. Valid range: 0-15 (4 bits). */
1267   uint8_t                    compVal;
1268 
1269   /** Configure compare mask. Set bit X to exclude sensor X from evaluation.
1270    *  Note: decoder can handle sensor inputs from up to 4 sensors; therefore,
1271    *  this mask is 4 bit long. */
1272   uint8_t                    compMask;
1273 
1274 #if defined(_SILICON_LABS_32B_SERIES_2)
1275   /** Configure index of the current state when evaluation is done.
1276    *  Valid range: 0-15 (4 bits). */
1277   uint8_t                    curState;
1278 #endif
1279 
1280   /** Configure index of state to be entered if the sensor state equals to
1281    *  compVal. Valid range: 0-15 (4 bits). */
1282   uint8_t                    nextState;
1283 
1284   /** Configure which PRS action to perform when the sensor state equals to
1285    *  compVal. */
1286   LESENSE_StTransAct_TypeDef prsAct;
1287 
1288   /** If enabled, interrupt flag is set when sensor state equals to compVal. */
1289   bool                       setInt;
1290 } LESENSE_DecStCond_TypeDef;
1291 
1292 /** Default configuration for the decoder state condition. */
1293 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1294 #define LESENSE_ST_CONF_DEFAULT                                          \
1295   {                                                                      \
1296     0x0FU,             /* Compare value set to 0x0F. */                  \
1297     0x00U,             /* All decoder inputs masked. */                  \
1298     0U,                /* Next state is state 0. */                      \
1299     lesenseTransActNone, /* No PRS action performed on compare match. */ \
1300     false              /* No interrupt triggered on compare match. */    \
1301   }
1302 #else
1303 #define LESENSE_ST_CONF_DEFAULT                                          \
1304   {                                                                      \
1305     0x0FU,               /* Compare value set to 0x0F. */                \
1306     0x00U,               /* All decoder inputs masked. */                \
1307     0U,                  /* Current state must be state 0. */            \
1308     0U,                  /* Next state is state 0. */                    \
1309     lesenseTransActNone, /* No PRS action performed on compare match. */ \
1310     false                /* No interrupt triggered on compare match. */  \
1311   }
1312 #endif
1313 
1314 /** Decoder state x configuration structure. */
1315 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1316 typedef struct {
1317   /** If enabled, the state descriptor pair in next location will also be
1318    *  evaluated. */
1319   bool                      chainDesc;
1320 
1321   /** State condition descriptor A (high level descriptor of
1322    *  LESENSE_STx_DECCONFA). */
1323   LESENSE_DecStCond_TypeDef confA;
1324 
1325   /** State condition descriptor B (high level descriptor of
1326    *  LESENSE_STx_DECCONFB). */
1327   LESENSE_DecStCond_TypeDef confB;
1328 } LESENSE_DecStDesc_TypeDef;
1329 #else
1330 typedef LESENSE_DecStCond_TypeDef LESENSE_DecStDesc_TypeDef;
1331 #endif
1332 
1333 /** Configuration structure for decoder. */
1334 typedef struct {
1335   /** Descriptor of the 16 or 32 decoder states depending on the device. */
1336   LESENSE_DecStDesc_TypeDef St[LESENSE_NUM_DECODER_STATES];
1337 } LESENSE_DecStAll_TypeDef;
1338 
1339 /** Default configuration for all decoder states. */
1340 #if defined(_SILICON_LABS_32B_SERIES_0)
1341 #define LESENSE_DECODER_CONF_DEFAULT                                                       \
1342   { /* chain |   Descriptor A         |   Descriptor B   */                                \
1343     {                                                                                      \
1344       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */  \
1345       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */  \
1346       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */  \
1347       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */  \
1348       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */  \
1349       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */  \
1350       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */  \
1351       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */  \
1352       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */  \
1353       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */  \
1354       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */ \
1355       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */ \
1356       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */ \
1357       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */ \
1358       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */ \
1359       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }  /* Decoder state 15. */ \
1360     }                                                                                      \
1361   }
1362 #elif defined(_SILICON_LABS_32B_SERIES_1)
1363 #define LESENSE_DECODER_CONF_DEFAULT                                                       \
1364   { /* chain |   Descriptor A         |   Descriptor B   */                                \
1365     {                                                                                      \
1366       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */  \
1367       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */  \
1368       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */  \
1369       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */  \
1370       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */  \
1371       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */  \
1372       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */  \
1373       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */  \
1374       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */  \
1375       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */  \
1376       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */ \
1377       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */ \
1378       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */ \
1379       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */ \
1380       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */ \
1381       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 15. */ \
1382       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 16. */ \
1383       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 17. */ \
1384       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 18. */ \
1385       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 19. */ \
1386       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 20. */ \
1387       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 21. */ \
1388       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 22. */ \
1389       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 23. */ \
1390       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 24. */ \
1391       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 25. */ \
1392       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 26. */ \
1393       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 27. */ \
1394       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 28. */ \
1395       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 29. */ \
1396       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 30. */ \
1397       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }  /* Decoder state 31. */ \
1398     }                                                                                      \
1399   }
1400 #else
1401 #define LESENSE_DECODER_CONF_DEFAULT                   \
1402   {                                                    \
1403     {                                                  \
1404       LESENSE_ST_CONF_DEFAULT, /* Decoder state 0. */  \
1405       LESENSE_ST_CONF_DEFAULT, /* Decoder state 1. */  \
1406       LESENSE_ST_CONF_DEFAULT, /* Decoder state 2. */  \
1407       LESENSE_ST_CONF_DEFAULT, /* Decoder state 3. */  \
1408       LESENSE_ST_CONF_DEFAULT, /* Decoder state 4. */  \
1409       LESENSE_ST_CONF_DEFAULT, /* Decoder state 5. */  \
1410       LESENSE_ST_CONF_DEFAULT, /* Decoder state 6. */  \
1411       LESENSE_ST_CONF_DEFAULT, /* Decoder state 7. */  \
1412       LESENSE_ST_CONF_DEFAULT, /* Decoder state 8. */  \
1413       LESENSE_ST_CONF_DEFAULT, /* Decoder state 9. */  \
1414       LESENSE_ST_CONF_DEFAULT, /* Decoder state 10. */ \
1415       LESENSE_ST_CONF_DEFAULT, /* Decoder state 11. */ \
1416       LESENSE_ST_CONF_DEFAULT, /* Decoder state 12. */ \
1417       LESENSE_ST_CONF_DEFAULT, /* Decoder state 13. */ \
1418       LESENSE_ST_CONF_DEFAULT, /* Decoder state 14. */ \
1419       LESENSE_ST_CONF_DEFAULT, /* Decoder state 15. */ \
1420       LESENSE_ST_CONF_DEFAULT, /* Decoder state 16. */ \
1421       LESENSE_ST_CONF_DEFAULT, /* Decoder state 17. */ \
1422       LESENSE_ST_CONF_DEFAULT, /* Decoder state 18. */ \
1423       LESENSE_ST_CONF_DEFAULT, /* Decoder state 19. */ \
1424       LESENSE_ST_CONF_DEFAULT, /* Decoder state 20. */ \
1425       LESENSE_ST_CONF_DEFAULT, /* Decoder state 21. */ \
1426       LESENSE_ST_CONF_DEFAULT, /* Decoder state 22. */ \
1427       LESENSE_ST_CONF_DEFAULT, /* Decoder state 23. */ \
1428       LESENSE_ST_CONF_DEFAULT, /* Decoder state 24. */ \
1429       LESENSE_ST_CONF_DEFAULT, /* Decoder state 25. */ \
1430       LESENSE_ST_CONF_DEFAULT, /* Decoder state 26. */ \
1431       LESENSE_ST_CONF_DEFAULT, /* Decoder state 27. */ \
1432       LESENSE_ST_CONF_DEFAULT, /* Decoder state 28. */ \
1433       LESENSE_ST_CONF_DEFAULT, /* Decoder state 29. */ \
1434       LESENSE_ST_CONF_DEFAULT, /* Decoder state 30. */ \
1435       LESENSE_ST_CONF_DEFAULT  /* Decoder state 31. */ \
1436     }                                                  \
1437   }
1438 #endif
1439 
1440 /*******************************************************************************
1441  *****************************   PROTOTYPES   **********************************
1442  ******************************************************************************/
1443 void LESENSE_Init(const LESENSE_Init_TypeDef * init, bool reqReset);
1444 void LESENSE_Reset(void);
1445 
1446 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t scanFreq);
1447 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef scanMode, bool start);
1448 void LESENSE_StartDelaySet(uint8_t startDelay);
1449 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef clk,
1450                        LESENSE_ClkPresc_TypeDef clkDiv);
1451 
1452 void LESENSE_ChannelAllConfig(const LESENSE_ChAll_TypeDef * confChAll);
1453 void LESENSE_ChannelConfig(const LESENSE_ChDesc_TypeDef * confCh,
1454                            uint32_t chIdx);
1455 void LESENSE_ChannelEnable(uint8_t chIdx,
1456                            bool enaScanCh,
1457                            bool enaPin);
1458 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);
1459 void LESENSE_ChannelTimingSet(uint8_t chIdx,
1460                               uint8_t exTime,
1461                               uint8_t sampleDelay,
1462                               uint16_t measDelay);
1463 void LESENSE_ChannelThresSet(uint8_t chIdx,
1464                              uint16_t acmpThres,
1465                              uint16_t cntThres);
1466 #if defined(_LESENSE_CH_EVAL_MODE_MASK) || defined(_SILICON_LABS_32B_SERIES_2)
1467 void LESENSE_ChannelSlidingWindow(uint8_t chIdx,
1468                                   uint32_t windowSize,
1469                                   uint32_t initValue);
1470 void LESENSE_ChannelStepDetection(uint8_t chIdx,
1471                                   uint32_t stepSize,
1472                                   uint32_t initValue);
1473 void LESENSE_WindowSizeSet(uint32_t windowSize);
1474 void LESENSE_StepSizeSet(uint32_t stepSize);
1475 #endif
1476 
1477 void LESENSE_AltExConfig(const LESENSE_ConfAltEx_TypeDef * confAltEx);
1478 
1479 void LESENSE_DecoderStateAllConfig(const LESENSE_DecStAll_TypeDef * confDecStAll);
1480 void LESENSE_DecoderStateConfig(const LESENSE_DecStDesc_TypeDef * confDecSt,
1481                                 uint32_t decSt);
1482 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1483 void LESENSE_DecoderStateSet(uint32_t decSt);
1484 #endif
1485 uint32_t LESENSE_DecoderStateGet(void);
1486 #if defined(_LESENSE_PRSCTRL_MASK)
1487 void LESENSE_DecoderPrsOut(bool enable, uint32_t decMask, uint32_t decCmp);
1488 #endif
1489 
1490 void LESENSE_ScanStart(void);
1491 void LESENSE_ScanStop(void);
1492 void LESENSE_DecoderStart(void);
1493 void LESENSE_ResultBufferClear(void);
1494 
1495 /***************************************************************************//**
1496  * @brief
1497  *   Stop LESENSE decoder.
1498  *
1499  * @details
1500  *   Disables LESENSE decoder by setting the command to
1501  *   LESENSE_DECCTRL register.
1502  ******************************************************************************/
LESENSE_DecoderStop(void)1503 __STATIC_INLINE void LESENSE_DecoderStop(void)
1504 {
1505   /* Stop decoder */
1506 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1507   LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
1508 #else
1509   LESENSE->DECCTRL |= LESENSE_DECCTRL_DECDIS;
1510 #endif
1511 }
1512 
1513 /***************************************************************************//**
1514  * @brief
1515  *   Get the current status of LESENSE.
1516  *
1517  * @return
1518  *   Returns the value of the LESENSE_STATUS register that
1519  *   contains the OR combination of the following status bits for EFR series 0/1:
1520  *   @li LESENSE_STATUS_BUFDATAV - Result data valid. Set when data is available
1521  *   in result buffer. Cleared when buffer is empty.
1522  *   @li LESENSE_STATUS_BUFFULL - Result buffer full. Set when result
1523  *   buffer is full.
1524  *   @li LESENSE_STATUS_BUFHALFFULL - Result buffer half full. Set when
1525  *   result buffer is half full.
1526  *   @li LESENSE_STATUS_RUNNING - LESENSE is active.
1527  *   @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
1528  *
1529  *   The OR combination of the following status bits for EFR series 2:
1530  *   @li LESENSE_STATUS_RESFIFOV - Result Fifo valid. Set when data is available
1531  *   in result Fifo. Cleared when Fifo is empty.
1532  *   @li LESENSE_STATUS_RESFIFOFULL - Result Fifo full. Set when result
1533  *   Fifo is full.
1534  *   @li LESENSE_STATUS_RUNNING - LESENSE is active.
1535  *   @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
1536  *   @li LESENSE_STATUS_FLUSHING - Fifo flushing
1537  *   @li LESENSE_STATUS_READBUSY - Fifo Read busy
1538  ******************************************************************************/
LESENSE_StatusGet(void)1539 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)
1540 {
1541   return LESENSE->STATUS;
1542 }
1543 
1544 /***************************************************************************//**
1545  * @brief
1546  *   Wait until status of LESENSE is equal to what was requested.
1547  *
1548  * @details
1549  *   Polls LESENSE_STATUS register and waits until
1550  *   requested combination of flags are set.
1551  *
1552  * @param[in] flag
1553  *   The OR combination of the following status bits for EFR series 0/1:
1554  *   @li LESENSE_STATUS_BUFDATAV - Result data valid. Set when data is available
1555  *   in result buffer. Cleared when buffer is empty.
1556  *   @li LESENSE_STATUS_BUFHALFFULL - Result buffer half full. Set when
1557  *   result buffer is half full.
1558  *   @li LESENSE_STATUS_BUFFULL - Result buffer full. Set when result
1559  *   buffer is full.
1560  *   @li LESENSE_STATUS_RUNNING - LESENSE is active.
1561  *   @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
1562  *   @li LESENSE_STATUS_DACACTIVE - The DAC interface is currently active.
1563 
1564  *   The OR combination of the following status bits for EFR series 2:
1565  *   @li LESENSE_STATUS_RESFIFOV - Result Fifo valid. Set when data is available
1566  *   in result Fifo. Cleared when Fifo is empty.
1567  *   @li LESENSE_STATUS_RESFIFOFULL - Result Fifo full. Set when result
1568  *   Fifo is full.
1569  *   @li LESENSE_STATUS_RUNNING - LESENSE is active.
1570  *   @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
1571  *   @li LESENSE_STATUS_FLUSHING - Fifo flushing
1572  *   @li LESENSE_STATUS_READBUSY - Fifo Read busy
1573  ******************************************************************************/
LESENSE_StatusWait(uint32_t flag)1574 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)
1575 {
1576   while (!(LESENSE->STATUS & flag))
1577     ;
1578 }
1579 
1580 /***************************************************************************//**
1581  * @brief
1582  *   Get the currently active channel index.
1583  *
1584  * @return
1585  *   Returns the value of the LESENSE_CHINDEX register that
1586  *   contains the index of currently active channel (0-15).
1587  ******************************************************************************/
LESENSE_ChannelActiveGet(void)1588 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)
1589 {
1590   return LESENSE->CURCH;
1591 }
1592 
1593 /***************************************************************************//**
1594  * @brief
1595  *   Get the latest scan comparison result (1 bit / channel).
1596  *
1597  * @return
1598  *   Returns the value of the LESENSE_SCANRES register that
1599  *   contains the comparison result of last scan on all channels.
1600  *   Bit x is set if a comparison triggered on channel x, which means that
1601  *   LESENSE counter met the comparison criteria set in LESENSE_CHx_EVAL by
1602  *   COMPMODE and CNTTHRES.
1603  ******************************************************************************/
LESENSE_ScanResultGet(void)1604 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)
1605 {
1606   return LESENSE->SCANRES & _LESENSE_SCANRES_SCANRES_MASK;
1607 }
1608 
1609 /***************************************************************************//**
1610  * @brief
1611  *   Get the oldest unread data from result buffer.
1612  *
1613  * @note
1614  *   Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
1615  *   the STRSCANRES bit is set in LESENSE_CTRL; otherwise, returns the
1616  *   undefined value.
1617  *
1618  * @return
1619  *   Returns the value of LESENSE_RESDATA register that
1620  *   contains the oldest unread counter result from result buffer.
1621  ******************************************************************************/
LESENSE_ScanResultDataGet(void)1622 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
1623 {
1624 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1625   return LESENSE->BUFDATA;
1626 #else
1627   return LESENSE->RESFIFO;
1628 #endif
1629 }
1630 
1631 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1632 /***************************************************************************//**
1633  * @brief
1634  *   Get the data from result data buffer.
1635  *
1636  * @note
1637  *   Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
1638  *   the STRSCANRES bit is set in LESENSE_CTRL; otherwise, returns the
1639  *   undefined value.
1640  *
1641  * @param[in] idx
1642  *   Result data buffer index. Valid range: 0-15.
1643  *
1644  * @return
1645  *   Returns the selected word from the result data buffer.
1646  ******************************************************************************/
LESENSE_ScanResultDataBufferGet(uint32_t idx)1647 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
1648 {
1649   /* Note: masking is needed to avoid over-indexing! */
1650   return LESENSE->BUF[idx & 0x0FU].DATA;
1651 }
1652 #endif
1653 
1654 /***************************************************************************//**
1655  * @brief
1656  *   Get the current state of LESENSE sensor.
1657  *
1658  * @return
1659  *   Returns the value of LESENSE_SENSORSTATE register that
1660  *   represents the current state of the LESENSE sensor.
1661  ******************************************************************************/
LESENSE_SensorStateGet(void)1662 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)
1663 {
1664   return LESENSE->SENSORSTATE;
1665 }
1666 
1667 #if defined(LESENSE_POWERDOWN_RAM)
1668 /***************************************************************************//**
1669  * @brief
1670  *   Shut off the power to the LESENSE RAM, disables LESENSE.
1671  *
1672  * @details
1673  *   Shuts off the LESENSE RAM in order to decrease leakage
1674  *   current of MCU if LESENSE is not used in your application.
1675  *
1676  * @note
1677  *   Warning! Once LESENSE RAM is powered down, it cannot be powered up
1678  *   again.
1679  ******************************************************************************/
LESENSE_RAMPowerDown(void)1680 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
1681 {
1682   /* Power down the LESENSE RAM */
1683   LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
1684 }
1685 #endif
1686 
1687 /***************************************************************************//**
1688  * @brief
1689  *   Clear one or more pending LESENSE interrupts.
1690  *
1691  * @param[in] flags
1692  *   Pending LESENSE interrupt sources to clear. Use a set of interrupt flags
1693  *   OR-ed together to clear multiple interrupt sources of LESENSE module
1694  *   (LESENSE_IF_nnn).
1695  ******************************************************************************/
LESENSE_IntClear(uint32_t flags)1696 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
1697 {
1698 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1699   LESENSE->IFC = flags;
1700 #else
1701   LESENSE->IF_CLR = flags;
1702 #endif
1703 }
1704 
1705 /***************************************************************************//**
1706  * @brief
1707  *   Enable one or more LESENSE interrupts.
1708  *
1709  * @param[in] flags
1710  *   LESENSE interrupt sources to enable. Use a set of interrupt flags OR-ed
1711  *   together to enable multiple interrupt sources of LESENSE module
1712  *   (LESENSE_IF_nnn).
1713  ******************************************************************************/
LESENSE_IntEnable(uint32_t flags)1714 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
1715 {
1716 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1717   LESENSE->IEN |= flags;
1718 #else
1719   LESENSE->IEN_SET = flags;
1720 #endif
1721 }
1722 
1723 /***************************************************************************//**
1724  * @brief
1725  *   Disable one or more LESENSE interrupts.
1726  *
1727  * @param[in] flags
1728  *   LESENSE interrupt sources to disable. Use a set of interrupt flags OR-ed
1729  *   together to disable multiple interrupt sources of LESENSE module
1730  *   (LESENSE_IF_nnn).
1731  ******************************************************************************/
LESENSE_IntDisable(uint32_t flags)1732 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
1733 {
1734 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1735   LESENSE->IEN &= ~flags;
1736 #else
1737   LESENSE->IEN_CLR = flags;
1738 #endif
1739 }
1740 
1741 /***************************************************************************//**
1742  * @brief
1743  *   Set one or more pending LESENSE interrupts from SW.
1744  *
1745  * @param[in] flags
1746  *   LESENSE interrupt sources to set to pending. Use a set of interrupt
1747  *   flags OR-ed together to set multiple interrupt sources of LESENSE
1748  *   module (LESENSE_IFS_nnn).
1749  ******************************************************************************/
LESENSE_IntSet(uint32_t flags)1750 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)
1751 {
1752 #if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
1753   LESENSE->IFS = flags;
1754 #else
1755   LESENSE->IF_SET = flags;
1756 #endif
1757 }
1758 
1759 /***************************************************************************//**
1760  * @brief
1761  *   Get pending LESENSE interrupt flags.
1762  *
1763  * @note
1764  *   Event bits are not cleared by the use of this function.
1765  *
1766  * @return
1767  *   Pending LESENSE interrupt sources. The OR combination of valid interrupt
1768  *   flags of the LESENSE module (LESENSE_IF_nnn).
1769  ******************************************************************************/
LESENSE_IntGet(void)1770 __STATIC_INLINE uint32_t LESENSE_IntGet(void)
1771 {
1772   return LESENSE->IF;
1773 }
1774 
1775 /***************************************************************************//**
1776  * @brief
1777  *   Get enabled and pending LESENSE interrupt flags.
1778  *
1779  * @details
1780  *   Useful for handling more interrupt sources in the same interrupt handler.
1781  *
1782  * @note
1783  *   Event bits are not cleared by the use of this function.
1784  *
1785  * @return
1786  *   Pending and enabled LESENSE interrupt sources.
1787  *   Return value is the bitwise AND combination of
1788  *   - the OR combination of enabled interrupt sources in LESENSE_IEN_nnn
1789  *   register (LESENSE_IEN_nnn) and
1790  *   - the OR combination of valid interrupt flags of LESENSE module
1791  *   (LESENSE_IF_nnn).
1792  ******************************************************************************/
LESENSE_IntGetEnabled(void)1793 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
1794 {
1795   uint32_t tmp;
1796 
1797   /* Store LESENSE->IEN in temporary variable in order to define explicit order
1798    * of volatile accesses. */
1799   tmp = LESENSE->IEN;
1800 
1801   /* Bitwise AND of pending and enabled interrupts */
1802   return LESENSE->IF & tmp;
1803 }
1804 
1805 /** @} (end addtogroup lesense) */
1806 
1807 #ifdef __cplusplus
1808 }
1809 #endif
1810 
1811 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
1812 
1813 #endif /* EM_LESENSE_H */
1814