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