]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_lesense.h
e6e5000549dc84af323146405d0a76638a5cf20a
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_lesense.h
1 /***************************************************************************//**\r
2  * @file em_lesense.h\r
3  * @brief Low Energy Sensor (LESENSE) peripheral API\r
4  * @version 4.2.1\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\r
10  * Permission is granted to anyone to use this software for any purpose,\r
11  * including commercial applications, and to alter it and redistribute it\r
12  * freely, subject to the following restrictions:\r
13  *\r
14  * 1. The origin of this software must not be misrepresented; you must not\r
15  *    claim that you wrote the original software.\r
16  * 2. Altered source versions must be plainly marked as such, and must not be\r
17  *    misrepresented as being the original software.\r
18  * 3. This notice may not be removed or altered from any source distribution.\r
19  *\r
20  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no\r
21  * obligation to support this Software. Silicon Labs is providing the\r
22  * Software "AS IS", with no express or implied warranties of any kind,\r
23  * including, but not limited to, any implied warranties of merchantability\r
24  * or fitness for any particular purpose or warranties against infringement\r
25  * of any proprietary rights of a third party.\r
26  *\r
27  * Silicon Labs will not be liable for any consequential, incidental, or\r
28  * special damages, or any other relief, or for any claim by any third party,\r
29  * arising from your use of this Software.\r
30  *\r
31  ******************************************************************************/\r
32 \r
33 #ifndef __SILICON_LABS_EM_LESENSE_H__\r
34 #define __SILICON_LABS_EM_LESENSE_H__\r
35 \r
36 #include "em_device.h"\r
37 \r
38 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)\r
39 #include <stdint.h>\r
40 #include <stdbool.h>\r
41 \r
42 #ifdef __cplusplus\r
43 extern "C" {\r
44 #endif\r
45 \r
46 \r
47 /***************************************************************************//**\r
48  * @addtogroup EM_Library\r
49  * @{\r
50  ******************************************************************************/\r
51 \r
52 /***************************************************************************//**\r
53  * @addtogroup LESENSE\r
54  * @{\r
55  ******************************************************************************/\r
56 \r
57 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */\r
58 \r
59 \r
60 \r
61 /** @endcond */\r
62 \r
63 /*******************************************************************************\r
64  ********************************   ENUMS   ************************************\r
65  ******************************************************************************/\r
66 \r
67 /** Clock divisors for controlling the prescaling factor of the period\r
68  *  counter.\r
69  *  Note: these enumeration values are being used for different clock division\r
70  *  related configuration parameters (hfPresc, lfPresc, pcPresc). */\r
71 typedef enum\r
72 {\r
73   lesenseClkDiv_1   = 0, /**< Divide clock by 1. */\r
74   lesenseClkDiv_2   = 1, /**< Divide clock by 2. */\r
75   lesenseClkDiv_4   = 2, /**< Divide clock by 4. */\r
76   lesenseClkDiv_8   = 3, /**< Divide clock by 8. */\r
77   lesenseClkDiv_16  = 4, /**< Divide clock by 16. */\r
78   lesenseClkDiv_32  = 5, /**< Divide clock by 32. */\r
79   lesenseClkDiv_64  = 6, /**< Divide clock by 64. */\r
80   lesenseClkDiv_128 = 7  /**< Divide clock by 128. */\r
81 } LESENSE_ClkPresc_TypeDef;\r
82 \r
83 \r
84 /** Scan modes. */\r
85 typedef enum\r
86 {\r
87   /** New scan is started each time the period counter overflows. */\r
88   lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,\r
89 \r
90   /** Single scan is performed when LESENSE_ScanStart() is called. */\r
91   lesenseScanStartOneShot  = LESENSE_CTRL_SCANMODE_ONESHOT,\r
92 \r
93   /** New scan is triggered by pulse on PRS channel. */\r
94   lesenseScanStartPRS      = LESENSE_CTRL_SCANMODE_PRS\r
95 } LESENSE_ScanMode_TypeDef;\r
96 \r
97 \r
98 /** PRS sources.\r
99  *  Note: these enumeration values are being used for different PRS related\r
100  *  configuration parameters. */\r
101 typedef enum\r
102 {\r
103   lesensePRSCh0     = 0, /**< PRS channel 0. */\r
104   lesensePRSCh1     = 1, /**< PRS channel 1. */\r
105   lesensePRSCh2     = 2, /**< PRS channel 2. */\r
106   lesensePRSCh3     = 3, /**< PRS channel 3. */\r
107 #if defined( LESENSE_CTRL_PRSSEL_PRSCH4 )\r
108   lesensePRSCh4     = 4, /**< PRS channel 4. */\r
109 #endif\r
110 #if defined( LESENSE_CTRL_PRSSEL_PRSCH5 )\r
111   lesensePRSCh5     = 5, /**< PRS channel 5. */\r
112 #endif\r
113 #if defined( LESENSE_CTRL_PRSSEL_PRSCH6 )\r
114   lesensePRSCh6     = 6, /**< PRS channel 6. */\r
115 #endif\r
116 #if defined( LESENSE_CTRL_PRSSEL_PRSCH7 )\r
117   lesensePRSCh7     = 7,  /**< PRS channel 7. */\r
118 #endif\r
119 #if defined( LESENSE_CTRL_PRSSEL_PRSCH8 )\r
120   lesensePRSCh8     = 8,  /**< PRS channel 8. */\r
121 #endif\r
122 #if defined( LESENSE_CTRL_PRSSEL_PRSCH9 )\r
123   lesensePRSCh9     = 9,  /**< PRS channel 9. */\r
124 #endif\r
125 #if defined( LESENSE_CTRL_PRSSEL_PRSCH10 )\r
126   lesensePRSCh10    = 10, /**< PRS channel 10.*/\r
127 #endif\r
128 #if defined( LESENSE_CTRL_PRSSEL_PRSCH11 )\r
129   lesensePRSCh11    = 11, /**< PRS channel 11.*/\r
130 #endif\r
131 } LESENSE_PRSSel_TypeDef;\r
132 \r
133 \r
134 /** Locations of the alternate excitation function. */\r
135 typedef enum\r
136 {\r
137   /** Alternate excitation is mapped to the LES_ALTEX pins. */\r
138   lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,\r
139 \r
140   /** Alternate excitation is mapped to the pins of the other ACMP. */\r
141   lesenseAltExMapACMP  = _LESENSE_CTRL_ALTEXMAP_ACMP\r
142 } LESENSE_AltExMap_TypeDef;\r
143 \r
144 \r
145 /** Result buffer interrupt and DMA trigger levels. */\r
146 typedef enum\r
147 {\r
148   /** DMA and interrupt flags are set when result buffer is halffull. */\r
149   lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,\r
150 \r
151   /** DMA and interrupt flags set when result buffer is full. */\r
152   lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL\r
153 } LESENSE_BufTrigLevel_TypeDef;\r
154 \r
155 \r
156 /** Modes of operation for DMA wakeup from EM2. */\r
157 typedef enum\r
158 {\r
159   /** No DMA wakeup from EM2. */\r
160   lesenseDMAWakeUpDisable  = LESENSE_CTRL_DMAWU_DISABLE,\r
161 \r
162   /** DMA wakeup from EM2 when data is valid in the result buffer. */\r
163   lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,\r
164 \r
165   /** DMA wakeup from EM2 when the resultbuffer is full/halffull, depending on\r
166    *  RESBIDL configuration in LESENSE_CTRL register (selected by\r
167    *  resBufTrigLevel in LESENSE_ResBufTrigLevel_TypeDef descriptor structure). */\r
168   lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL\r
169 } LESENSE_DMAWakeUp_TypeDef;\r
170 \r
171 \r
172 /** Bias modes. */\r
173 typedef enum\r
174 {\r
175   /** Duty cycle bias module between low power and high accuracy mode. */\r
176   lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,\r
177 \r
178   /** Bias module is always in high accuracy mode. */\r
179   lesenseBiasModeHighAcc   = LESENSE_BIASCTRL_BIASMODE_HIGHACC,\r
180 \r
181   /** Bias module is controlled by the EMU and not affected by LESENSE. */\r
182   lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH\r
183 } LESENSE_BiasMode_TypeDef;\r
184 \r
185 \r
186 /** Scan configuration. */\r
187 typedef enum\r
188 {\r
189   /** The channel configuration registers (CHx_CONF) used are directly mapped to\r
190    *  the channel number. */\r
191   lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,\r
192 \r
193   /** The channel configuration registers used are CHx+8_CONF for channels 0-7\r
194    *  and CHx-8_CONF for channels 8-15. */\r
195   lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,\r
196 \r
197   /** The channel configuration registers used toggles between CHX_SCANCONF and\r
198    *  CHX+8_SCANCONF when channel x triggers. */\r
199   lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,\r
200 \r
201   /** The decoder state defines the channel configuration register (CHx_CONF) to\r
202    *  be used. */\r
203   lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF\r
204 } LESENSE_ScanConfSel_TypeDef;\r
205 \r
206 \r
207 /** DAC CHx data control configuration. */\r
208 typedef enum\r
209 {\r
210   /** DAC channel x data is defined by DAC_CHxDATA register.\r
211    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
212   lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,\r
213 \r
214   /** DAC channel x data is defined by ACMPTHRES in LESENSE_CHx_INTERACT.\r
215    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
216   lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES\r
217 } LESENSE_ControlDACData_TypeDef;\r
218 \r
219 \r
220 /** DAC channel x conversion mode configuration. */\r
221 typedef enum\r
222 {\r
223   /** LESENSE doesn't control DAC channel x.\r
224    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
225   lesenseDACConvModeDisable    = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,\r
226 \r
227   /** DAC channel x is driven in continuous mode.\r
228    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
229   lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,\r
230 \r
231   /** DAC channel x is driven in sample hold mode.\r
232    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
233   lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,\r
234 \r
235   /** DAC channel x is driven in sample off mode.\r
236    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
237   lesenseDACConvModeSampleOff  = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF\r
238 } LESENSE_ControlDACConv_TypeDef;\r
239 \r
240 \r
241 /** DAC channel x output mode configuration. */\r
242 typedef enum\r
243 {\r
244   /** DAC CHx output to pin and ACMP/ADC disabled.\r
245    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
246   lesenseDACOutModeDisable    = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,\r
247 \r
248   /** DAC CHx output to pin enabled, output to ADC and ACMP disabled.\r
249    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
250   lesenseDACOutModePin        = _LESENSE_PERCTRL_DACCH0OUT_PIN,\r
251 \r
252   /** DAC CHx output to pin disabled, output to ADC and ACMP enabled.\r
253    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
254   lesenseDACOutModeADCACMP    = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,\r
255 \r
256   /** DAC CHx output to pin, ADC, and ACMP enabled.\r
257    *  Note: this value could be used for both DAC Ch0 and Ch1. */\r
258   lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP\r
259 } LESENSE_ControlDACOut_TypeDef;\r
260 \r
261 \r
262 /**  DAC reference configuration. */\r
263 typedef enum\r
264 {\r
265   /** DAC uses VDD reference. */\r
266   lesenseDACRefVdd     = LESENSE_PERCTRL_DACREF_VDD,\r
267 \r
268   /** DAC uses bandgap reference. */\r
269   lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP\r
270 } LESENSE_DACRef_TypeDef;\r
271 \r
272 \r
273 /** ACMPx control configuration. */\r
274 typedef enum\r
275 {\r
276   /** LESENSE does not control the ACMPx.\r
277    *  Note: this value could be used for both ACMP0 and ACMP1. */\r
278   lesenseACMPModeDisable  = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,\r
279 \r
280   /** LESENSE controls the input mux of ACMPx.\r
281    *  Note: this value could be used for both ACMP0 and ACMP1. */\r
282   lesenseACMPModeMux      = _LESENSE_PERCTRL_ACMP0MODE_MUX,\r
283 \r
284   /** LESENSE controls the input mux of and the threshold value of ACMPx.\r
285    *  Note: this value could be used for both ACMP0 and ACMP1. */\r
286   lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES\r
287 } LESENSE_ControlACMP_TypeDef;\r
288 \r
289 \r
290 /** Warm up modes. ACMP and DAC duty cycle mode configuration. */\r
291 typedef enum\r
292 {\r
293   /** ACMPs and DACs are shut down when LESENSE is idle. */\r
294   lesenseWarmupModeNormal   = LESENSE_PERCTRL_WARMUPMODE_NORMAL,\r
295 \r
296   /** ACMPs are kept powered up when LESENSE is idle. */\r
297   lesenseWarmupModeACMP     = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,\r
298 \r
299   /** The DAC is kept powered up when LESENSE is idle. */\r
300   lesenseWarmupModeDAC      = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,\r
301 \r
302   /** ACMPs and the DAC are kept powered up when LESENSE is idle. */\r
303   lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM\r
304 } LESENSE_WarmupMode_TypeDef;\r
305 \r
306 \r
307 /** Decoder input source configuration. */\r
308 typedef enum\r
309 {\r
310   /** The SENSORSTATE register is used as input to the decoder. */\r
311   lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,\r
312 \r
313   /** PRS channels are used as input to the decoder. */\r
314   lesenseDecInputPRS      = LESENSE_DECCTRL_INPUT_PRS\r
315 } LESENSE_DecInput_TypeDef;\r
316 \r
317 \r
318 /** Compare source selection for sensor sampling. */\r
319 typedef enum\r
320 {\r
321   /** Counter output will be used in comparison. */\r
322   lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,\r
323 \r
324   /** ACMP output will be used in comparison. */\r
325   lesenseSampleModeACMP    = LESENSE_CH_INTERACT_SAMPLE_ACMP\r
326 } LESENSE_ChSampleMode_TypeDef;\r
327 \r
328 \r
329 /** Interrupt generation setup for CHx interrupt flag. */\r
330 typedef enum\r
331 {\r
332   /** No interrupt is generated. */\r
333   lesenseSetIntNone    = LESENSE_CH_INTERACT_SETIF_NONE,\r
334 \r
335   /** Set interrupt flag if the sensor triggers. */\r
336   lesenseSetIntLevel   = LESENSE_CH_INTERACT_SETIF_LEVEL,\r
337 \r
338   /** Set interrupt flag on positive edge of the sensor state. */\r
339   lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,\r
340 \r
341   /** Set interrupt flag on negative edge of the sensor state. */\r
342   lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE\r
343 } LESENSE_ChIntMode_TypeDef;\r
344 \r
345 \r
346 /** Channel pin mode for the excitation phase of the scan sequence. */\r
347 typedef enum\r
348 {\r
349   /** Channel pin is disabled. */\r
350   lesenseChPinExDis    = LESENSE_CH_INTERACT_EXMODE_DISABLE,\r
351 \r
352   /** Channel pin is configured as push-pull, driven HIGH. */\r
353   lesenseChPinExHigh   = LESENSE_CH_INTERACT_EXMODE_HIGH,\r
354 \r
355   /** Channel pin is configured as push-pull, driven LOW. */\r
356   lesenseChPinExLow    = LESENSE_CH_INTERACT_EXMODE_LOW,\r
357 \r
358   /** DAC output (only available on channel 0, 1, 2, 3, 12, 13, 14 and 15) */\r
359   lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT\r
360 } LESENSE_ChPinExMode_TypeDef;\r
361 \r
362 \r
363 /** Channel pin mode for the idle phase of the scan sequence. */\r
364 typedef enum\r
365 {\r
366   /** Channel pin is disabled in idle phase.\r
367    *  Note: this value could be used for all channels. */\r
368   lesenseChPinIdleDis    = _LESENSE_IDLECONF_CH0_DISABLE,\r
369 \r
370   /** Channel pin is configured as push-pull, driven HIGH in idle phase.\r
371    *  Note: this value could be used for all channels. */\r
372   lesenseChPinIdleHigh   = _LESENSE_IDLECONF_CH0_HIGH,\r
373 \r
374   /** Channel pin is configured as push-pull, driven LOW in idle phase.\r
375    *  Note: this value could be used for all channels. */\r
376   lesenseChPinIdleLow    = _LESENSE_IDLECONF_CH0_LOW,\r
377 \r
378   /** Channel pin is connected to DAC CH0 output in idle phase.\r
379    *  Note: only applies to channel 0, 1, 2, 3. */\r
380   lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,\r
381 \r
382   /** Channel pin is connected to DAC CH1 output in idle phase.\r
383    *  Note: only applies to channel 12, 13, 14, 15. */\r
384   lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1\r
385 } LESENSE_ChPinIdleMode_TypeDef;\r
386 \r
387 \r
388 /** Clock used for excitation and sample delay timing. */\r
389 typedef enum\r
390 {\r
391   /** LFACLK (LF clock) is used. */\r
392   lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,\r
393 \r
394   /** AUXHFRCO (HF clock) is used. */\r
395   lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO\r
396 } LESENSE_ChClk_TypeDef;\r
397 \r
398 \r
399 /** Compare modes for counter comparison. */\r
400 typedef enum\r
401 {\r
402   /** Set interrupt flag if counter value is less than CTRTHRESHOLD, or if the\r
403    *  ACMP output is 0. */\r
404   lesenseCompModeLess        = LESENSE_CH_EVAL_COMP_LESS,\r
405 \r
406   /** Set interrupt flag if counter value is greater than, or equal to\r
407    *  CTRTHRESHOLD, or if the ACMP output is 1. */\r
408   lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE\r
409 } LESENSE_ChCompMode_TypeDef;\r
410 \r
411 \r
412 /** Idle phase configuration of alternate excitation channels. */\r
413 typedef enum\r
414 {\r
415   /** ALTEX output is disabled in idle phase.\r
416    *  Note: this value could be used for all alternate excitation channels. */\r
417   lesenseAltExPinIdleDis  = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,\r
418 \r
419   /** ALTEX output is high in idle phase.\r
420    *  Note: this value could be used for all alternate excitation channels. */\r
421   lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,\r
422 \r
423   /** ALTEX output is low in idle phase.\r
424    *  Note: this value could be used for all alternate excitation channels. */\r
425   lesenseAltExPinIdleLow  = _LESENSE_ALTEXCONF_IDLECONF0_LOW\r
426 } LESENSE_AltExPinIdle_TypeDef;\r
427 \r
428 \r
429 /** Transition action modes. */\r
430 typedef enum\r
431 {\r
432   /** No PRS pulses generated (if PRSCOUNT == 0).\r
433    *  Do not count (if PRSCOUNT == 1). */\r
434   lesenseTransActNone        = LESENSE_ST_TCONFA_PRSACT_NONE,\r
435 \r
436   /** Generate pulse on LESPRS0 (if PRSCOUNT == 0). */\r
437   lesenseTransActPRS0        = LESENSE_ST_TCONFA_PRSACT_PRS0,\r
438 \r
439   /** Generate pulse on LESPRS1 (if PRSCOUNT == 0). */\r
440   lesenseTransActPRS1        = LESENSE_ST_TCONFA_PRSACT_PRS1,\r
441 \r
442   /** Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). */\r
443   lesenseTransActPRS01       = LESENSE_ST_TCONFA_PRSACT_PRS01,\r
444 \r
445   /** Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). */\r
446   lesenseTransActPRS2        = LESENSE_ST_TCONFA_PRSACT_PRS2,\r
447 \r
448   /** Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). */\r
449   lesenseTransActPRS02       = LESENSE_ST_TCONFA_PRSACT_PRS02,\r
450 \r
451   /** Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */\r
452   lesenseTransActPRS12       = LESENSE_ST_TCONFA_PRSACT_PRS12,\r
453 \r
454   /** Generate pulse on LESPRS0, LESPRS1 and LESPRS2  (if PRSCOUNT == 0). */\r
455   lesenseTransActPRS012      = LESENSE_ST_TCONFA_PRSACT_PRS012,\r
456 \r
457   /** Count up (if PRSCOUNT == 1). */\r
458   lesenseTransActUp          = LESENSE_ST_TCONFA_PRSACT_UP,\r
459 \r
460   /** Count down (if PRSCOUNT == 1). */\r
461   lesenseTransActDown        = LESENSE_ST_TCONFA_PRSACT_DOWN,\r
462 \r
463   /** Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). */\r
464   lesenseTransActUpAndPRS2   = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,\r
465 \r
466   /** Count down and generate pulse on LESPRS2 (if PRSCOUNT == 1). */\r
467   lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2\r
468 } LESENSE_StTransAct_TypeDef;\r
469 \r
470 \r
471 /*******************************************************************************\r
472  *******************************   STRUCTS   ***********************************\r
473  ******************************************************************************/\r
474 \r
475 /** Core control (LESENSE_CTRL) descriptor structure. */\r
476 typedef struct\r
477 {\r
478   /** Select scan start mode to control how the scan start is being triggered.*/\r
479   LESENSE_ScanMode_TypeDef     scanStart;\r
480 \r
481   /** Select PRS source for scan start if scanMode is set to lesensePrsPulse. */\r
482   LESENSE_PRSSel_TypeDef       prsSel;\r
483 \r
484   /** Select scan configuration register usage strategy. */\r
485   LESENSE_ScanConfSel_TypeDef  scanConfSel;\r
486 \r
487   /** Set to true to invert ACMP0 output. */\r
488   bool                         invACMP0;\r
489 \r
490   /** Set to true to invert ACMP1 output. */\r
491   bool                         invACMP1;\r
492 \r
493   /** Set to true to sample both ACMPs simultaneously. */\r
494   bool                         dualSample;\r
495 \r
496   /** Set to true in order to to store SCANRES in RAM (accessible via RESDATA)\r
497    *  after each scan. */\r
498   bool                         storeScanRes;\r
499 \r
500   /** Set to true in order to always make LESENSE write to the result buffer,\r
501    *  even if it is full. */\r
502   bool                         bufOverWr;\r
503 \r
504   /** Select trigger conditions for interrupt and DMA. */\r
505   LESENSE_BufTrigLevel_TypeDef bufTrigLevel;\r
506 \r
507   /** Configure trigger condition for DMA wakeup from EM2. */\r
508   LESENSE_DMAWakeUp_TypeDef    wakeupOnDMA;\r
509 \r
510   /** Select bias mode. */\r
511   LESENSE_BiasMode_TypeDef     biasMode;\r
512 \r
513   /** Set to true to keep LESENSE running in debug mode. */\r
514   bool                         debugRun;\r
515 } LESENSE_CoreCtrlDesc_TypeDef;\r
516 \r
517 /** Default configuration for LESENSE_CtrlDesc_TypeDef structure. */\r
518 #define LESENSE_CORECTRL_DESC_DEFAULT                                                               \\r
519 {                                                                                                   \\r
520   lesenseScanStartPeriodic,  /* Start new scan each time the period counter overflows. */           \\r
521   lesensePRSCh0,             /* Default PRS channel is selected. */                                 \\r
522   lesenseScanConfDirMap,     /* Direct mapping SCANCONF register usage strategy. */                 \\r
523   false,                     /* Don't invert ACMP0 output. */                                       \\r
524   false,                     /* Don't invert ACMP1 output. */                                       \\r
525   false,                     /* Disable dual sampling. */                                           \\r
526   true,                      /* Store scan result after each scan. */                               \\r
527   true,                      /* Overwrite result buffer register even if it is full. */             \\r
528   lesenseBufTrigHalf,        /* Trigger interrupt and DMA request if result buffer is half full. */ \\r
529   lesenseDMAWakeUpDisable,   /* Don't wake up on DMA from EM2. */                                   \\r
530   lesenseBiasModeDontTouch,  /* Don't touch bias configuration. */                                  \\r
531   true                       /* Keep LESENSE running in debug mode. */                              \\r
532 }\r
533 \r
534 \r
535 /** LESENSE timing control descriptor structure. */\r
536 typedef struct\r
537 {\r
538   /** Set the number of LFACLK cycles to delay sensor interaction on\r
539    *  each channel. Valid range: 0-3 (2 bit). */\r
540   uint8_t startDelay;\r
541 } LESENSE_TimeCtrlDesc_TypeDef;\r
542 \r
543 /** Default configuration for LESENSE_TimeCtrlDesc_TypeDef structure. */\r
544 #define LESENSE_TIMECTRL_DESC_DEFAULT   \\r
545 {                                       \\r
546   0U /* No sensor interaction delay. */ \\r
547 }\r
548 \r
549 \r
550 /** LESENSE peripheral control descriptor structure. */\r
551 typedef struct\r
552 {\r
553   /** Configure DAC channel 0 data control. */\r
554   LESENSE_ControlDACData_TypeDef dacCh0Data;\r
555 \r
556   /** Configure how LESENSE controls conversion on DAC channel 0. */\r
557   LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;\r
558 \r
559   /** Configure how LESENSE controls output on DAC channel 0. */\r
560   LESENSE_ControlDACOut_TypeDef  dacCh0OutMode;\r
561 \r
562   /** Configure DAC channel 1 data control. */\r
563   LESENSE_ControlDACData_TypeDef dacCh1Data;\r
564 \r
565   /** Configure how LESENSE controls conversion on DAC channel 1. */\r
566   LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;\r
567 \r
568   /** Configure how LESENSE controls output on DAC channel 1. */\r
569   LESENSE_ControlDACOut_TypeDef  dacCh1OutMode;\r
570 \r
571   /** Configure the prescaling factor for the LESENSE - DAC interface.\r
572    *  Valid range: 0-31 (5bit). */\r
573   uint8_t                        dacPresc;\r
574 \r
575   /** Configure the DAC reference to be used. Set to #lesenseDACRefVdd to use\r
576    *  VDD and set to #lesenseDACRefBandGap to use bandgap as reference. */\r
577   LESENSE_DACRef_TypeDef         dacRef;\r
578 \r
579   /** Configure how LESENSE controls ACMP 0. */\r
580   LESENSE_ControlACMP_TypeDef    acmp0Mode;\r
581 \r
582   /** Configure how LESENSE controls ACMP 1. */\r
583   LESENSE_ControlACMP_TypeDef    acmp1Mode;\r
584 \r
585   /** Configure how LESENSE controls ACMPs and the DAC in idle mode. */\r
586   LESENSE_WarmupMode_TypeDef     warmupMode;\r
587 } LESENSE_PerCtrlDesc_TypeDef;\r
588 \r
589 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */\r
590 #define LESENSE_PERCTRL_DESC_DEFAULT  \\r
591 {                                     \\r
592   lesenseDACIfData,          /**/     \\r
593   lesenseDACConvModeDisable, /**/     \\r
594   lesenseDACOutModeDisable,  /**/     \\r
595   lesenseDACIfData,          /**/     \\r
596   lesenseDACConvModeDisable, /**/     \\r
597   lesenseDACOutModeDisable,  /**/     \\r
598   0U,                        /**/     \\r
599   lesenseDACRefVdd,          /**/     \\r
600   lesenseACMPModeMuxThres,   /**/     \\r
601   lesenseACMPModeMuxThres,   /**/     \\r
602   lesenseWarmupModeKeepWarm, /**/     \\r
603 }\r
604 \r
605 \r
606 /** LESENSE decoder control descriptor structure. */\r
607 typedef struct\r
608 {\r
609   /** Select the input to the LESENSE decoder. */\r
610   LESENSE_DecInput_TypeDef decInput;\r
611 \r
612   /** Initial state of the LESENSE decoder. */\r
613   uint32_t                 initState;\r
614 \r
615   /** Set to enable the decoder to check the present state in addition\r
616    *  to the states defined in DECCONF. */\r
617   bool                     chkState;\r
618 \r
619   /** When set, a transition from state x in the decoder will set interrupt flag\r
620    *  CHx. */\r
621   bool                     intMap;\r
622 \r
623   /** Set to enable hysteresis in the decoder for suppressing changes on PRS\r
624    *  channel 0. */\r
625   bool                     hystPRS0;\r
626 \r
627   /** Set to enable hysteresis in the decoder for suppressing changes on PRS\r
628    *  channel 1. */\r
629   bool                     hystPRS1;\r
630 \r
631   /** Set to enable hysteresis in the decoder for suppressing changes on PRS\r
632    *  channel 2. */\r
633   bool                     hystPRS2;\r
634 \r
635   /** Set to enable hysteresis in the decoder for suppressing interrupt\r
636    *  requests. */\r
637   bool                     hystIRQ;\r
638 \r
639   /** Set to enable count mode on decoder PRS channels 0 and 1 to produce\r
640    *  outputs which can be used by a PCNT to count up or down. */\r
641   bool                     prsCount;\r
642 \r
643   /** Select PRS channel input for bit 0 of the LESENSE decoder. */\r
644   LESENSE_PRSSel_TypeDef   prsChSel0;\r
645 \r
646   /** Select PRS channel input for bit 1 of the LESENSE decoder. */\r
647   LESENSE_PRSSel_TypeDef   prsChSel1;\r
648 \r
649   /** Select PRS channel input for bit 2 of the LESENSE decoder. */\r
650   LESENSE_PRSSel_TypeDef   prsChSel2;\r
651 \r
652   /** Select PRS channel input for bit 3 of the LESENSE decoder. */\r
653   LESENSE_PRSSel_TypeDef   prsChSel3;\r
654 } LESENSE_DecCtrlDesc_TypeDef;\r
655 \r
656 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */\r
657 #define LESENSE_DECCTRL_DESC_DEFAULT  \\r
658 {                                     \\r
659   lesenseDecInputSensorSt, /**/       \\r
660   0U,                      /**/       \\r
661   false,                   /**/       \\r
662   true,                    /**/       \\r
663   true,                    /**/       \\r
664   true,                    /**/       \\r
665   true,                    /**/       \\r
666   true,                    /**/       \\r
667   false,                   /**/       \\r
668   lesensePRSCh0,           /**/       \\r
669   lesensePRSCh1,           /**/       \\r
670   lesensePRSCh2,           /**/       \\r
671   lesensePRSCh3,           /**/       \\r
672 }\r
673 \r
674 \r
675 /** LESENSE module initialization structure. */\r
676 typedef struct\r
677 {\r
678   /** LESENSE core configuration parameters. */\r
679   LESENSE_CoreCtrlDesc_TypeDef coreCtrl;\r
680 \r
681   /** LESENSE timing configuration parameters. */\r
682   LESENSE_TimeCtrlDesc_TypeDef timeCtrl;\r
683 \r
684   /** LESENSE peripheral configuration parameters. */\r
685   LESENSE_PerCtrlDesc_TypeDef  perCtrl;\r
686 \r
687   /** LESENSE decoder configuration parameters. */\r
688   LESENSE_DecCtrlDesc_TypeDef  decCtrl;\r
689 } LESENSE_Init_TypeDef;\r
690 \r
691 /** Default configuration for LESENSE_Init_TypeDef structure. */\r
692 #define LESENSE_INIT_DEFAULT                                                              \\r
693 {                                                                                         \\r
694   .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */       \\r
695   .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */       \\r
696   .perCtrl  = LESENSE_PERCTRL_DESC_DEFAULT,  /* Default peripheral control parameters. */ \\r
697   .decCtrl  = LESENSE_DECCTRL_DESC_DEFAULT   /* Default decoder control parameters. */    \\r
698 }\r
699 \r
700 \r
701 /** Channel descriptor structure. */\r
702 typedef struct\r
703 {\r
704   /** Set to enable scan channel CHx. */\r
705   bool                          enaScanCh;\r
706 \r
707   /** Set to enable CHx pin. */\r
708   bool                          enaPin;\r
709 \r
710   /** Enable/disable channel interrupts after configuring all the sensor channel\r
711    *  parameters. */\r
712   bool                          enaInt;\r
713 \r
714   /** Configure channel pin mode for the excitation phase of the scan sequence.\r
715    *  Note: OPAOUT is only available on channels 2, 3, 4, and 5. */\r
716   LESENSE_ChPinExMode_TypeDef   chPinExMode;\r
717 \r
718   /** Configure channel pin idle setup in LESENSE idle phase. */\r
719   LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;\r
720 \r
721   /** Set to use alternate excite pin for excitation. */\r
722   bool                          useAltEx;\r
723 \r
724   /** Set to enable the result from this channel being shifted into the decoder\r
725    *  register. */\r
726   bool                          shiftRes;\r
727 \r
728   /** Set to invert the result bit stored in SCANRES register. */\r
729   bool                          invRes;\r
730 \r
731   /** Set to store the counter value in RAM (accessible via RESDATA) and make\r
732    *  the comparison result available in the SCANRES register. */\r
733   bool                          storeCntRes;\r
734 \r
735   /** Select clock used for excitation timing. */\r
736   LESENSE_ChClk_TypeDef         exClk;\r
737 \r
738   /** Select clock used for sample delay timing. */\r
739   LESENSE_ChClk_TypeDef         sampleClk;\r
740 \r
741   /** Configure excitation time. Excitation will last exTime+1 excitation clock\r
742    *  cycles. Valid range: 0-63 (6 bits). */\r
743   uint8_t                       exTime;\r
744 \r
745   /** Configure sample delay. Sampling will occur after sampleDelay+1 sample\r
746    *  clock cycles. Valid range: 0-127 (7 bits). */\r
747   uint8_t                       sampleDelay;\r
748 \r
749   /** Configure measure delay. Sensor measuring is delayed for measDelay\r
750    *  excitation clock cycles. Valid range: 0-127 (7 bits). */\r
751   uint8_t                       measDelay;\r
752 \r
753   /** Configure ACMP threshold.\r
754    *  If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseDACIfData,\r
755    *  acmpThres defines the 12-bit DAC data in the corresponding data register\r
756    *  of the DAC interface (DACn_CH0DATA and DACn_CH1DATA).\r
757    *  In this case, the valid range is: 0-4095 (12 bits).\r
758    *  If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseACMPThres,\r
759    *  acmpThres defines the 6-bit Vdd scaling factor of ACMP negative input\r
760    *  (VDDLEVEL in ACMP_INPUTSEL register).\r
761    *  In this case, the valid range is: 0-63 (6 bits). */\r
762   uint16_t                     acmpThres;\r
763 \r
764   /** Select if ACMP output or counter output should be used in comparison. */\r
765   LESENSE_ChSampleMode_TypeDef sampleMode;\r
766 \r
767   /** Configure interrupt generation mode for CHx interrupt flag. */\r
768   LESENSE_ChIntMode_TypeDef    intMode;\r
769 \r
770   /** Configure decision threshold for counter comparison.\r
771    *  Valid range: 0-65535 (16 bits). */\r
772   uint16_t                     cntThres;\r
773 \r
774   /** Select mode for counter comparison. */\r
775   LESENSE_ChCompMode_TypeDef   compMode;\r
776 } LESENSE_ChDesc_TypeDef;\r
777 \r
778 \r
779 /** Configuration structure for all scan channels. */\r
780 typedef struct\r
781 {\r
782   /** Channel descriptor for all 16 channels. */\r
783   LESENSE_ChDesc_TypeDef Ch[16];\r
784 } LESENSE_ChAll_TypeDef;\r
785 \r
786 /** Default configuration for scan channel. */\r
787 #define LESENSE_CH_CONF_DEFAULT                                                                     \\r
788 {                                                                                                   \\r
789   true,                  /* Enable scan channel. */                                                 \\r
790   true,                  /* Enable the assigned pin on scan channel. */                             \\r
791   true,                  /* Enable interrupts on channel. */                                        \\r
792   lesenseChPinExHigh,    /* Channel pin is high during the excitation period. */                    \\r
793   lesenseChPinIdleLow,   /* Channel pin is low during the idle period. */                           \\r
794   false,                 /* Don't use alternate excitation pins for excitation. */                  \\r
795   false,                 /* Disabled to shift results from this channel to the decoder register. */ \\r
796   false,                 /* Disabled to invert the scan result bit. */                              \\r
797   false,                 /* Disabled to store counter value in the result buffer. */                \\r
798   lesenseClkLF,          /* Use the LF clock for excitation timing. */                              \\r
799   lesenseClkLF,          /* Use the LF clock for sample timing. */                                  \\r
800   0x03U,                 /* Excitation time is set to 3(+1) excitation clock cycles. */             \\r
801   0x09U,                 /* Sample delay is set to 9(+1) sample clock cycles. */                    \\r
802   0x06U,                 /* Measure delay is set to 6 excitation clock cycles.*/                    \\r
803   0x00U,                 /* ACMP threshold has been set to 0. */                                    \\r
804   lesenseSampleModeACMP, /* ACMP output will be used in comparison. */                              \\r
805   lesenseSetIntNone,     /* No interrupt is generated by the channel. */                            \\r
806   0xFFU,                 /* Counter threshold has bee set to 0xFF. */                               \\r
807   lesenseCompModeLess    /* Compare mode has been set to trigger interrupt on "less". */            \\r
808 }\r
809 \r
810 /** Default configuration for all sensor channels. */\r
811 #define LESENSE_SCAN_CONF_DEFAULT                   \\r
812 {                                                   \\r
813   {                                                 \\r
814     LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */  \\r
815     LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */  \\r
816     LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */  \\r
817     LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */  \\r
818     LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */  \\r
819     LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */  \\r
820     LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */  \\r
821     LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */  \\r
822     LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */  \\r
823     LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */  \\r
824     LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \\r
825     LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \\r
826     LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \\r
827     LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \\r
828     LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \\r
829     LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \\r
830   }                                                 \\r
831 }\r
832 \r
833 \r
834 /** Alternate excitation descriptor structure. */\r
835 typedef struct\r
836 {\r
837   /** Configure alternate excitation pins. If set, the corresponding alternate\r
838    *  excitation pin/signal is enabled. */\r
839   bool                         enablePin;\r
840 \r
841   /** Configure idle phase setup of alternate excitation pins.\r
842    The idleConf parameter is not valid when altExMap==lesenseAltExMapACMP. */\r
843   LESENSE_AltExPinIdle_TypeDef idleConf;\r
844 \r
845   /** Configure how to control the external alternate excitation pins. Only\r
846   *  applies if altExMap has been set to lesenseAltExMapALTEX.\r
847   *  If true, the excitation happens on the corresponding alternate excitation\r
848   *  pin during the excitation periods of all enabled channels.\r
849   *  If false, the excitation happens on the corresponding alternate excitation\r
850   *  pin ONLY during the excitation period of the corresponding channel.\r
851   *  The alwaysEx parameter is not valid when altExMap==lesenseAltExMapACMP. */\r
852   bool                         alwaysEx;\r
853 } LESENSE_AltExDesc_TypeDef;\r
854 \r
855 \r
856 /** Configuration structure for alternate excitation. */\r
857 typedef struct\r
858 {\r
859   /** Select alternate excitation mapping. */\r
860   LESENSE_AltExMap_TypeDef  altExMap;\r
861 \r
862   /** Alternate excitation channel descriptors.\r
863    *  When altExMap==lesenseAltExMapALTEX only the 8 first descriptors are used.\r
864    *  In this mode they describe the configuration of the LES_ALTEX0-7 pins.\r
865    *  When altExMap==lesenseAltExMapACMP all 16 descriptors are used. In this\r
866    *  mode they describe the configuration of the 16 possible ACMP0-1 excitation\r
867    *  channels. Please refer to the user manual for a complete mapping of the\r
868    *  routing.\r
869    *  NOTE:\r
870    *  Some parameters in the descriptors are not valid when\r
871    *  altExMap==lesenseAltExMapACMP. Please refer to the definition of the\r
872    *  LESENSE_AltExDesc_TypeDef structure for details regarding which parameters\r
873    *  are valid. */\r
874   LESENSE_AltExDesc_TypeDef AltEx[16];\r
875 \r
876 } LESENSE_ConfAltEx_TypeDef;\r
877 \r
878 \r
879 /** Default configuration for alternate excitation channel. */\r
880 #define LESENSE_ALTEX_CH_CONF_DEFAULT                                        \\r
881 {                                                                            \\r
882   true,                  /* Alternate excitation enabled.*/                  \\r
883   lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \\r
884   false                  /* Excite only for corresponding channel. */        \\r
885 }\r
886 \r
887 /** Default configuration for all alternate excitation channels. */\r
888 #define LESENSE_ALTEX_CONF_DEFAULT                                        \\r
889 {                                                                         \\r
890   lesenseAltExMapACMP,                                                    \\r
891   {                                                                       \\r
892     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */  \\r
893     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */  \\r
894     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */  \\r
895     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */  \\r
896     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */  \\r
897     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */  \\r
898     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */  \\r
899     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */  \\r
900     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */  \\r
901     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */  \\r
902     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \\r
903     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \\r
904     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \\r
905     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \\r
906     LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \\r
907     LESENSE_ALTEX_CH_CONF_DEFAULT  /* Alternate excitation channel 15. */ \\r
908   }                                                                       \\r
909 }\r
910 \r
911 \r
912 /** Decoder state condition descriptor structure. */\r
913 typedef struct\r
914 {\r
915   /** Configure compare value. State transition is triggered when sensor state\r
916    *  equals to this value. Valid range: 0-15 (4 bits). */\r
917   uint8_t                    compVal;\r
918 \r
919   /** Configure compare mask. Set bit X to exclude sensor X from evaluation.\r
920    *  Note: decoder can handle sensor inputs from up to 4 sensors, therefore\r
921    *  this mask is 4 bit long. */\r
922   uint8_t                    compMask;\r
923 \r
924   /** Configure index of state to be entered if the sensor state equals to\r
925    *  compVal. Valid range: 0-15 (4 bits). */\r
926   uint8_t                    nextState;\r
927 \r
928   /** Configure which PRS action to perform when sensor state equals to\r
929    *  compVal. */\r
930   LESENSE_StTransAct_TypeDef prsAct;\r
931 \r
932   /** If enabled, interrupt flag is set when sensor state equals to compVal. */\r
933   bool                       setInt;\r
934 } LESENSE_DecStCond_TypeDef;\r
935 \r
936 /** Default configuration for decoder state condition. */\r
937 #define LESENSE_ST_CONF_DEFAULT                                        \\r
938 {                                                                      \\r
939   0x0FU,               /* Compare value set to 0x0F. */                \\r
940   0x00U,               /* All decoder inputs masked. */                \\r
941   0U,                  /* Next state is state 0. */                    \\r
942   lesenseTransActNone, /* No PRS action performed on compare match. */ \\r
943   false                /* No interrupt triggered on compare match. */  \\r
944 }\r
945 \r
946 \r
947 /** Decoder state x configuration structure. */\r
948 typedef struct\r
949 {\r
950   /** If enabled, the state descriptor pair in the next location will also be\r
951    *  evaluated. */\r
952   bool                      chainDesc;\r
953 \r
954   /** State condition descriptor A (high level descriptor of\r
955    *  LESENSE_STx_DECCONFA). */\r
956   LESENSE_DecStCond_TypeDef confA;\r
957 \r
958   /** State condition descriptor B (high level descriptor of\r
959    *  LESENSE_STx_DECCONFB). */\r
960   LESENSE_DecStCond_TypeDef confB;\r
961 } LESENSE_DecStDesc_TypeDef;\r
962 \r
963 \r
964 /** Configuration structure for the decoder. */\r
965 typedef struct\r
966 {\r
967   /** Descriptor of the 16 decoder states. */\r
968   LESENSE_DecStDesc_TypeDef St[16];\r
969 } LESENSE_DecStAll_TypeDef;\r
970 \r
971 /** Default configuration for all decoder states. */\r
972 #define LESENSE_DECODER_CONF_DEFAULT                                                     \\r
973 {  /* chain |   Descriptor A         |   Descriptor B   */                               \\r
974   {                                                                                      \\r
975     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */  \\r
976     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */  \\r
977     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */  \\r
978     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */  \\r
979     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */  \\r
980     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */  \\r
981     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */  \\r
982     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */  \\r
983     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */  \\r
984     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */  \\r
985     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */ \\r
986     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */ \\r
987     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */ \\r
988     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */ \\r
989     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */ \\r
990     { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }  /* Decoder state 15. */ \\r
991   }                                                                                      \\r
992 }\r
993 \r
994 /*******************************************************************************\r
995  *****************************   PROTOTYPES   **********************************\r
996  ******************************************************************************/\r
997 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset);\r
998 void LESENSE_Reset(void);\r
999 \r
1000 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq);\r
1001 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,\r
1002                          bool const start);\r
1003 \r
1004 void LESENSE_StartDelaySet(uint8_t const startDelay);\r
1005 \r
1006 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,\r
1007                        LESENSE_ClkPresc_TypeDef const clkDiv);\r
1008 \r
1009 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll);\r
1010 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,\r
1011                            uint32_t const chIdx);\r
1012 void LESENSE_ChannelEnable(uint8_t const chIdx,\r
1013                            bool const enaScanCh,\r
1014                            bool const enaPin);\r
1015 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);\r
1016 void LESENSE_ChannelTimingSet(uint8_t const chIdx,\r
1017                               uint8_t const exTime,\r
1018                               uint8_t const sampleDelay,\r
1019                               uint8_t const measDelay);\r
1020 void LESENSE_ChannelThresSet(uint8_t const chIdx,\r
1021                              uint16_t const acmpThres,\r
1022                              uint16_t const cntThres);\r
1023 \r
1024 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);\r
1025 \r
1026 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll);\r
1027 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,\r
1028                                 uint32_t const decSt);\r
1029 void LESENSE_DecoderStateSet(uint32_t decSt);\r
1030 uint32_t LESENSE_DecoderStateGet(void);\r
1031 \r
1032 void LESENSE_ScanStart(void);\r
1033 void LESENSE_ScanStop(void);\r
1034 void LESENSE_DecoderStart(void);\r
1035 void LESENSE_ResultBufferClear(void);\r
1036 \r
1037 \r
1038 /***************************************************************************//**\r
1039  * @brief\r
1040  *   Stop LESENSE decoder.\r
1041  *\r
1042  * @details\r
1043  *   This function disables the LESENSE decoder by setting the command to the\r
1044  *   LESENSE_DECCTRL register.\r
1045  ******************************************************************************/\r
1046 __STATIC_INLINE void LESENSE_DecoderStop(void)\r
1047 {\r
1048   /* Stop the decoder */\r
1049   LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;\r
1050 }\r
1051 \r
1052 \r
1053 /***************************************************************************//**\r
1054  * @brief\r
1055  *   Get the current status of LESENSE.\r
1056  *\r
1057  * @return\r
1058  *   This function returns the value of LESENSE_STATUS register that\r
1059  *   contains the OR combination of the following status bits:\r
1060  *   @li LESENSE_STATUS_RESV - Result data valid. Set when data is available\r
1061  *   in the result buffer. Cleared when the buffer is empty.\r
1062  *   @li LESENSE_STATUS_RESFULL - Result buffer full. Set when the result\r
1063  *   buffer is full.\r
1064  *   @li LESENSE_STATUS_RUNNING - LESENSE is active.\r
1065  *   @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.\r
1066  ******************************************************************************/\r
1067 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)\r
1068 {\r
1069   return LESENSE->STATUS;\r
1070 }\r
1071 \r
1072 \r
1073 /***************************************************************************//**\r
1074  * @brief\r
1075  *   Wait until the status of LESENSE is equal to what requested.\r
1076  *\r
1077  * @details\r
1078  *   This function is polling the LESENSE_STATUS register and waits until the\r
1079  *   requested combination of flags are set.\r
1080  *\r
1081  * @param[in] flag\r
1082  *   The OR combination of the following status bits:\r
1083  *   @li LESENSE_STATUS_BUFDATAV - Result data valid. Set when data is available\r
1084  *   in the result buffer. Cleared when the buffer is empty.\r
1085  *   @li LESENSE_STATUS_BUFHALFFULL - Result buffer half full. Set when the\r
1086  *   result buffer is half full.\r
1087  *   @li LESENSE_STATUS_BUFFULL - Result buffer full. Set when the result\r
1088  *   buffer is full.\r
1089  *   @li LESENSE_STATUS_RUNNING - LESENSE is active.\r
1090  *   @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.\r
1091  *   @li LESENSE_STATUS_DACACTIVE - The DAC interface is currently active.\r
1092  ******************************************************************************/\r
1093 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)\r
1094 {\r
1095   while (!(LESENSE->STATUS & flag))\r
1096     ;\r
1097 }\r
1098 \r
1099 \r
1100 /***************************************************************************//**\r
1101  * @brief\r
1102  *   Get the currently active channel index.\r
1103  *\r
1104  * @return\r
1105  *   This function returns the value of LESENSE_CHINDEX register that\r
1106  *   contains the index of the currently active channel (0-15).\r
1107  ******************************************************************************/\r
1108 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)\r
1109 {\r
1110   return LESENSE->CURCH;\r
1111 }\r
1112 \r
1113 \r
1114 /***************************************************************************//**\r
1115  * @brief\r
1116  *   Get the latest scan comparison result (1 bit / channel).\r
1117  *\r
1118  * @return\r
1119  *   This function returns the value of LESENSE_SCANRES register that\r
1120  *   contains the comparison result of the last scan on all channels.\r
1121  *   Bit x is set if a comparison triggered on channel x, which means that the\r
1122  *   LESENSE counter met the comparison criteria set in LESENSE_CHx_EVAL by\r
1123  *   COMPMODE and CNTTHRES.\r
1124  ******************************************************************************/\r
1125 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)\r
1126 {\r
1127   return LESENSE->SCANRES;\r
1128 }\r
1129 \r
1130 \r
1131 /***************************************************************************//**\r
1132  * @brief\r
1133  *   Get the oldest unread data from the result buffer.\r
1134  *\r
1135  * @note\r
1136  *   Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or\r
1137  *   STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return\r
1138  *   undefined value.\r
1139  *\r
1140  * @return\r
1141  *   This function returns the value of LESENSE_RESDATA register that\r
1142  *   contains the oldest unread counter result from the result buffer.\r
1143  ******************************************************************************/\r
1144 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)\r
1145 {\r
1146   return LESENSE->BUFDATA;\r
1147 }\r
1148 \r
1149 \r
1150 /***************************************************************************//**\r
1151  * @brief\r
1152  *   Get data from the result data buffer.\r
1153  *\r
1154  * @note\r
1155  *   Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or\r
1156  *   STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return\r
1157  *   undefined value.\r
1158  *\r
1159  * @param[in] idx\r
1160  *   Result data buffer index. Valid range: 0-15.\r
1161  *\r
1162  * @return\r
1163  *   This function returns the selected word from the result data buffer.\r
1164  ******************************************************************************/\r
1165 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)\r
1166 {\r
1167   /* Note: masking is needed to avoid over-indexing! */\r
1168   return LESENSE->BUF[idx & 0x0FU].DATA;\r
1169 }\r
1170 \r
1171 /***************************************************************************//**\r
1172  * @brief\r
1173  *   Get the current state of the LESENSE sensor.\r
1174  *\r
1175  * @return\r
1176  *   This function returns the value of LESENSE_SENSORSTATE register that\r
1177  *   represents the current state of the LESENSE sensor.\r
1178  ******************************************************************************/\r
1179 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)\r
1180 {\r
1181   return LESENSE->SENSORSTATE;\r
1182 }\r
1183 \r
1184 \r
1185 /***************************************************************************//**\r
1186  * @brief\r
1187  *   Shut off power to the LESENSE RAM, disables LESENSE.\r
1188  *\r
1189  * @details\r
1190  *   This function shuts off the LESENSE RAM in order to decrease the leakage\r
1191  *   current of the mcu if LESENSE is not used in your application.\r
1192  *\r
1193  * @note\r
1194  *   Warning! Once the LESENSE RAM is powered down, it cannot be powered up\r
1195  *   again.\r
1196  ******************************************************************************/\r
1197 __STATIC_INLINE void LESENSE_RAMPowerDown(void)\r
1198 {\r
1199   /* Power down LESENSE RAM */\r
1200   LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;\r
1201 }\r
1202 \r
1203 \r
1204 /***************************************************************************//**\r
1205  * @brief\r
1206  *   Clear one or more pending LESENSE interrupts.\r
1207  *\r
1208  * @param[in] flags\r
1209  *   Pending LESENSE interrupt sources to clear. Use a set of interrupt flags\r
1210  *   OR-ed together to clear multiple interrupt sources of the LESENSE module\r
1211  *   (LESENSE_IF_nnn).\r
1212  ******************************************************************************/\r
1213 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)\r
1214 {\r
1215   LESENSE->IFC = flags;\r
1216 }\r
1217 \r
1218 \r
1219 /***************************************************************************//**\r
1220  * @brief\r
1221  *   Enable one or more LESENSE interrupts.\r
1222  *\r
1223  * @param[in] flags\r
1224  *   LESENSE interrupt sources to enable. Use a set of interrupt flags OR-ed\r
1225  *   together to enable multiple interrupt sources of the LESENSE module\r
1226  *   (LESENSE_IF_nnn).\r
1227  ******************************************************************************/\r
1228 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)\r
1229 {\r
1230   LESENSE->IEN |= flags;\r
1231 }\r
1232 \r
1233 \r
1234 /***************************************************************************//**\r
1235  * @brief\r
1236  *   Disable one or more LESENSE interrupts.\r
1237  *\r
1238  * @param[in] flags\r
1239  *   LESENSE interrupt sources to disable. Use a set of interrupt flags OR-ed\r
1240  *   together to disable multiple interrupt sources of the LESENSE module\r
1241  *   (LESENSE_IF_nnn).\r
1242  ******************************************************************************/\r
1243 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)\r
1244 {\r
1245   LESENSE->IEN &= ~flags;\r
1246 }\r
1247 \r
1248 \r
1249 /***************************************************************************//**\r
1250  * @brief\r
1251  *   Set one or more pending LESENSE interrupts from SW.\r
1252  *\r
1253  * @param[in] flags\r
1254  *   LESENSE interrupt sources to set to pending. Use a set of interrupt\r
1255  *   flags OR-ed together to set multiple interrupt sources of the LESENSE\r
1256  *   module (LESENSE_IFS_nnn).\r
1257  ******************************************************************************/\r
1258 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)\r
1259 {\r
1260   LESENSE->IFS = flags;\r
1261 }\r
1262 \r
1263 \r
1264 /***************************************************************************//**\r
1265  * @brief\r
1266  *   Get pending LESENSE interrupt flags.\r
1267  *\r
1268  * @note\r
1269  *   The event bits are not cleared by the use of this function.\r
1270  *\r
1271  * @return\r
1272  *   Pending LESENSE interrupt sources. The OR combination of valid interrupt\r
1273  *   flags of the LESENSE module (LESENSE_IF_nnn).\r
1274  ******************************************************************************/\r
1275 __STATIC_INLINE uint32_t LESENSE_IntGet(void)\r
1276 {\r
1277   return LESENSE->IF;\r
1278 }\r
1279 \r
1280 \r
1281 /***************************************************************************//**\r
1282  * @brief\r
1283  *   Get enabled and pending LESENSE interrupt flags.\r
1284  *\r
1285  * @details\r
1286  *   Useful for handling more interrupt sources in the same interrupt handler.\r
1287  *\r
1288  * @note\r
1289  *   The event bits are not cleared by the use of this function.\r
1290  *\r
1291  * @return\r
1292  *   Pending and enabled LESENSE interrupt sources.\r
1293  *   The return value is the bitwise AND combination of\r
1294  *   - the OR combination of enabled interrupt sources in LESENSE_IEN_nnn\r
1295  *   register (LESENSE_IEN_nnn) and\r
1296  *   - the OR combination of valid interrupt flags of the LESENSE module\r
1297  *   (LESENSE_IF_nnn).\r
1298  ******************************************************************************/\r
1299 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)\r
1300 {\r
1301   uint32_t tmp;\r
1302 \r
1303   /* Store LESENSE->IEN in temporary variable in order to define explicit order\r
1304    * of volatile accesses. */\r
1305   tmp = LESENSE->IEN;\r
1306 \r
1307   /* Bitwise AND of pending and enabled interrupts */\r
1308   return LESENSE->IF & tmp;\r
1309 }\r
1310 \r
1311 \r
1312 /** @} (end addtogroup LESENSE) */\r
1313 /** @} (end addtogroup EM_Library) */\r
1314 \r
1315 #ifdef __cplusplus\r
1316 }\r
1317 #endif\r
1318 \r
1319 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */\r
1320 \r
1321 #endif /* __SILICON_LABS_EM_LESENSE_H__ */\r