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