1 /***************************************************************************//**
\r
3 * @brief Low Energy Sensor (LESENSE) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\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
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
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
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
31 ******************************************************************************/
\r
34 #ifndef __SILICON_LABS_EM_LESENSE_H_
\r
35 #define __SILICON_LABS_EM_LESENSE_H_
\r
37 #include "em_device.h"
\r
39 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)
\r
41 #include <stdbool.h>
\r
48 /***************************************************************************//**
\r
49 * @addtogroup EM_Library
\r
51 ******************************************************************************/
\r
53 /***************************************************************************//**
\r
54 * @addtogroup LESENSE
\r
56 ******************************************************************************/
\r
58 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
64 /*******************************************************************************
\r
65 ******************************** ENUMS ************************************
\r
66 ******************************************************************************/
\r
68 /** Clock divisors for controlling the prescaling factor of the period
\r
70 * Note: these enumeration values are being used for different clock division
\r
71 * related configuration parameters (hfPresc, lfPresc, pcPresc). */
\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
88 /** New scan is started each time the period counter overflows. */
\r
89 lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,
\r
91 /** Single scan is performed when LESENSE_ScanStart() is called. */
\r
92 lesenseScanStartOneShot = LESENSE_CTRL_SCANMODE_ONESHOT,
\r
94 /** New scan is triggered by pulse on PRS channel. */
\r
95 lesenseScanStartPRS = LESENSE_CTRL_SCANMODE_PRS
\r
96 } LESENSE_ScanMode_TypeDef;
\r
100 * Note: these enumeration values are being used for different PRS related
\r
101 * configuration parameters. */
\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
111 #if defined( LESENSE_CTRL_PRSSEL_PRSCH5 )
\r
112 lesensePRSCh5 = 5, /**< PRS channel 5. */
\r
114 #if defined( LESENSE_CTRL_PRSSEL_PRSCH6 )
\r
115 lesensePRSCh6 = 6, /**< PRS channel 6. */
\r
117 #if defined( LESENSE_CTRL_PRSSEL_PRSCH7 )
\r
118 lesensePRSCh7 = 7, /**< PRS channel 7. */
\r
120 #if defined( LESENSE_CTRL_PRSSEL_PRSCH8 )
\r
121 lesensePRSCh8 = 8, /**< PRS channel 8. */
\r
123 #if defined( LESENSE_CTRL_PRSSEL_PRSCH9 )
\r
124 lesensePRSCh9 = 9, /**< PRS channel 9. */
\r
126 #if defined( LESENSE_CTRL_PRSSEL_PRSCH10 )
\r
127 lesensePRSCh10 = 10, /**< PRS channel 10.*/
\r
129 #if defined( LESENSE_CTRL_PRSSEL_PRSCH11 )
\r
130 lesensePRSCh11 = 11, /**< PRS channel 11.*/
\r
132 } LESENSE_PRSSel_TypeDef;
\r
135 /** Locations of the alternate excitation function. */
\r
138 /** Alternate excitation is mapped to the LES_ALTEX pins. */
\r
139 lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
\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
146 /** Result buffer interrupt and DMA trigger levels. */
\r
149 /** DMA and interrupt flags are set when result buffer is halffull. */
\r
150 lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
\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
157 /** Modes of operation for DMA wakeup from EM2. */
\r
160 /** No DMA wakeup from EM2. */
\r
161 lesenseDMAWakeUpDisable = LESENSE_CTRL_DMAWU_DISABLE,
\r
163 /** DMA wakeup from EM2 when data is valid in the result buffer. */
\r
164 lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
\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
176 /** Duty cycle bias module between low power and high accuracy mode. */
\r
177 lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
\r
179 /** Bias module is always in high accuracy mode. */
\r
180 lesenseBiasModeHighAcc = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
\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
187 /** Scan configuration. */
\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
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
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
202 /** The decoder state defines the channel configuration register (CHx_CONF) to
\r
204 lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
\r
205 } LESENSE_ScanConfSel_TypeDef;
\r
208 /** DAC CHx data control configuration. */
\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
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
221 /** DAC channel x conversion mode configuration. */
\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
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
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
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
242 /** DAC channel x output mode configuration. */
\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
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
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
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
263 /** DAC reference configuration. */
\r
266 /** DAC uses VDD reference. */
\r
267 lesenseDACRefVdd = LESENSE_PERCTRL_DACREF_VDD,
\r
269 /** DAC uses bandgap reference. */
\r
270 lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
\r
271 } LESENSE_DACRef_TypeDef;
\r
274 /** ACMPx control configuration. */
\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
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
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
291 /** Warm up modes. ACMP and DAC duty cycle mode configuration. */
\r
294 /** ACMPs and DACs are shut down when LESENSE is idle. */
\r
295 lesenseWarmupModeNormal = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
\r
297 /** ACMPs are kept powered up when LESENSE is idle. */
\r
298 lesenseWarmupModeACMP = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
\r
300 /** The DAC is kept powered up when LESENSE is idle. */
\r
301 lesenseWarmupModeDAC = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
\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
308 /** Decoder input source configuration. */
\r
311 /** The SENSORSTATE register is used as input to the decoder. */
\r
312 lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
\r
314 /** PRS channels are used as input to the decoder. */
\r
315 lesenseDecInputPRS = LESENSE_DECCTRL_INPUT_PRS
\r
316 } LESENSE_DecInput_TypeDef;
\r
319 /** Compare source selection for sensor sampling. */
\r
322 /** Counter output will be used in comparison. */
\r
323 lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,
\r
325 /** ACMP output will be used in comparison. */
\r
326 lesenseSampleModeACMP = LESENSE_CH_INTERACT_SAMPLE_ACMP
\r
327 } LESENSE_ChSampleMode_TypeDef;
\r
330 /** Interrupt generation setup for CHx interrupt flag. */
\r
333 /** No interrupt is generated. */
\r
334 lesenseSetIntNone = LESENSE_CH_INTERACT_SETIF_NONE,
\r
336 /** Set interrupt flag if the sensor triggers. */
\r
337 lesenseSetIntLevel = LESENSE_CH_INTERACT_SETIF_LEVEL,
\r
339 /** Set interrupt flag on positive edge of the sensor state. */
\r
340 lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
\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
347 /** Channel pin mode for the excitation phase of the scan sequence. */
\r
350 /** Channel pin is disabled. */
\r
351 lesenseChPinExDis = LESENSE_CH_INTERACT_EXMODE_DISABLE,
\r
353 /** Channel pin is configured as push-pull, driven HIGH. */
\r
354 lesenseChPinExHigh = LESENSE_CH_INTERACT_EXMODE_HIGH,
\r
356 /** Channel pin is configured as push-pull, driven LOW. */
\r
357 lesenseChPinExLow = LESENSE_CH_INTERACT_EXMODE_LOW,
\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
364 /** Channel pin mode for the idle phase of the scan sequence. */
\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
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
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
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
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
389 /** Clock used for excitation and sample delay timing. */
\r
392 /** LFACLK (LF clock) is used. */
\r
393 lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
\r
395 /** AUXHFRCO (HF clock) is used. */
\r
396 lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
\r
397 } LESENSE_ChClk_TypeDef;
\r
400 /** Compare modes for counter comparison. */
\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
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
413 /** Idle phase configuration of alternate excitation channels. */
\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
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
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
430 /** Transition action modes. */
\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
437 /** Generate pulse on LESPRS0 (if PRSCOUNT == 0). */
\r
438 lesenseTransActPRS0 = LESENSE_ST_TCONFA_PRSACT_PRS0,
\r
440 /** Generate pulse on LESPRS1 (if PRSCOUNT == 0). */
\r
441 lesenseTransActPRS1 = LESENSE_ST_TCONFA_PRSACT_PRS1,
\r
443 /** Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). */
\r
444 lesenseTransActPRS01 = LESENSE_ST_TCONFA_PRSACT_PRS01,
\r
446 /** Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). */
\r
447 lesenseTransActPRS2 = LESENSE_ST_TCONFA_PRSACT_PRS2,
\r
449 /** Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). */
\r
450 lesenseTransActPRS02 = LESENSE_ST_TCONFA_PRSACT_PRS02,
\r
452 /** Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
\r
453 lesenseTransActPRS12 = LESENSE_ST_TCONFA_PRSACT_PRS12,
\r
455 /** Generate pulse on LESPRS0, LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
\r
456 lesenseTransActPRS012 = LESENSE_ST_TCONFA_PRSACT_PRS012,
\r
458 /** Count up (if PRSCOUNT == 1). */
\r
459 lesenseTransActUp = LESENSE_ST_TCONFA_PRSACT_UP,
\r
461 /** Count down (if PRSCOUNT == 1). */
\r
462 lesenseTransActDown = LESENSE_ST_TCONFA_PRSACT_DOWN,
\r
464 /** Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
\r
465 lesenseTransActUpAndPRS2 = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
\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
472 /*******************************************************************************
\r
473 ******************************* STRUCTS ***********************************
\r
474 ******************************************************************************/
\r
476 /** Core control (LESENSE_CTRL) descriptor structure. */
\r
479 /** Select scan start mode to control how the scan start is being triggered.*/
\r
480 LESENSE_ScanMode_TypeDef scanStart;
\r
482 /** Select PRS source for scan start if scanMode is set to lesensePrsPulse. */
\r
483 LESENSE_PRSSel_TypeDef prsSel;
\r
485 /** Select scan configuration register usage strategy. */
\r
486 LESENSE_ScanConfSel_TypeDef scanConfSel;
\r
488 /** Set to true to invert ACMP0 output. */
\r
491 /** Set to true to invert ACMP1 output. */
\r
494 /** Set to true to sample both ACMPs simultaneously. */
\r
497 /** Set to true in order to to store SCANRES in RAM (accessible via RESDATA)
\r
498 * after each scan. */
\r
501 /** Set to true in order to always make LESENSE write to the result buffer,
\r
502 * even if it is full. */
\r
505 /** Select trigger conditions for interrupt and DMA. */
\r
506 LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
\r
508 /** Configure trigger condition for DMA wakeup from EM2. */
\r
509 LESENSE_DMAWakeUp_TypeDef wakeupOnDMA;
\r
511 /** Select bias mode. */
\r
512 LESENSE_BiasMode_TypeDef biasMode;
\r
514 /** Set to true to keep LESENSE running in debug mode. */
\r
516 } LESENSE_CoreCtrlDesc_TypeDef;
\r
518 /** Default configuration for LESENSE_CtrlDesc_TypeDef structure. */
\r
519 #define LESENSE_CORECTRL_DESC_DEFAULT \
\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
536 /** LESENSE timing control descriptor structure. */
\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
544 /** Default configuration for LESENSE_TimeCtrlDesc_TypeDef structure. */
\r
545 #define LESENSE_TIMECTRL_DESC_DEFAULT \
\r
547 0U /* No sensor interaction delay. */ \
\r
551 /** LESENSE peripheral control descriptor structure. */
\r
554 /** Configure DAC channel 0 data control. */
\r
555 LESENSE_ControlDACData_TypeDef dacCh0Data;
\r
557 /** Configure how LESENSE controls conversion on DAC channel 0. */
\r
558 LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
\r
560 /** Configure how LESENSE controls output on DAC channel 0. */
\r
561 LESENSE_ControlDACOut_TypeDef dacCh0OutMode;
\r
563 /** Configure DAC channel 1 data control. */
\r
564 LESENSE_ControlDACData_TypeDef dacCh1Data;
\r
566 /** Configure how LESENSE controls conversion on DAC channel 1. */
\r
567 LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
\r
569 /** Configure how LESENSE controls output on DAC channel 1. */
\r
570 LESENSE_ControlDACOut_TypeDef dacCh1OutMode;
\r
572 /** Configure the prescaling factor for the LESENSE - DAC interface.
\r
573 * Valid range: 0-31 (5bit). */
\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
580 /** Configure how LESENSE controls ACMP 0. */
\r
581 LESENSE_ControlACMP_TypeDef acmp0Mode;
\r
583 /** Configure how LESENSE controls ACMP 1. */
\r
584 LESENSE_ControlACMP_TypeDef acmp1Mode;
\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
590 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
\r
591 #define LESENSE_PERCTRL_DESC_DEFAULT \
\r
593 lesenseDACIfData, /**/ \
\r
594 lesenseDACConvModeDisable, /**/ \
\r
595 lesenseDACOutModeDisable, /**/ \
\r
596 lesenseDACIfData, /**/ \
\r
597 lesenseDACConvModeDisable, /**/ \
\r
598 lesenseDACOutModeDisable, /**/ \
\r
600 lesenseDACRefVdd, /**/ \
\r
601 lesenseACMPModeMuxThres, /**/ \
\r
602 lesenseACMPModeMuxThres, /**/ \
\r
603 lesenseWarmupModeKeepWarm, /**/ \
\r
607 /** LESENSE decoder control descriptor structure. */
\r
610 /** Select the input to the LESENSE decoder. */
\r
611 LESENSE_DecInput_TypeDef decInput;
\r
613 /** Initial state of the LESENSE decoder. */
\r
614 uint32_t initState;
\r
616 /** Set to enable the decoder to check the present state in addition
\r
617 * to the states defined in DECCONF. */
\r
620 /** When set, a transition from state x in the decoder will set interrupt flag
\r
624 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
\r
628 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
\r
632 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
\r
636 /** Set to enable hysteresis in the decoder for suppressing interrupt
\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
644 /** Select PRS channel input for bit 0 of the LESENSE decoder. */
\r
645 LESENSE_PRSSel_TypeDef prsChSel0;
\r
647 /** Select PRS channel input for bit 1 of the LESENSE decoder. */
\r
648 LESENSE_PRSSel_TypeDef prsChSel1;
\r
650 /** Select PRS channel input for bit 2 of the LESENSE decoder. */
\r
651 LESENSE_PRSSel_TypeDef prsChSel2;
\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
657 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
\r
658 #define LESENSE_DECCTRL_DESC_DEFAULT \
\r
660 lesenseDecInputSensorSt, /**/ \
\r
669 lesensePRSCh0, /**/ \
\r
670 lesensePRSCh1, /**/ \
\r
671 lesensePRSCh2, /**/ \
\r
672 lesensePRSCh3, /**/ \
\r
676 /** LESENSE module initialization structure. */
\r
679 /** LESENSE core configuration parameters. */
\r
680 LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
\r
682 /** LESENSE timing configuration parameters. */
\r
683 LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
\r
685 /** LESENSE peripheral configuration parameters. */
\r
686 LESENSE_PerCtrlDesc_TypeDef perCtrl;
\r
688 /** LESENSE decoder configuration parameters. */
\r
689 LESENSE_DecCtrlDesc_TypeDef decCtrl;
\r
690 } LESENSE_Init_TypeDef;
\r
692 /** Default configuration for LESENSE_Init_TypeDef structure. */
\r
693 #define LESENSE_INIT_DEFAULT \
\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
702 /** Channel descriptor structure. */
\r
705 /** Set to enable scan channel CHx. */
\r
708 /** Set to enable CHx pin. */
\r
711 /** Enable/disable channel interrupts after configuring all the sensor channel
\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
719 /** Configure channel pin idle setup in LESENSE idle phase. */
\r
720 LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
\r
722 /** Set to use alternate excite pin for excitation. */
\r
725 /** Set to enable the result from this channel being shifted into the decoder
\r
729 /** Set to invert the result bit stored in SCANRES register. */
\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
736 /** Select clock used for excitation timing. */
\r
737 LESENSE_ChClk_TypeDef exClk;
\r
739 /** Select clock used for sample delay timing. */
\r
740 LESENSE_ChClk_TypeDef sampleClk;
\r
742 /** Configure excitation time. Excitation will last exTime+1 excitation clock
\r
743 * cycles. Valid range: 0-63 (6 bits). */
\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
750 /** Configure measure delay. Sensor measuring is delayed for measDelay
\r
751 * excitation clock cycles. Valid range: 0-127 (7 bits). */
\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
765 /** Select if ACMP output or counter output should be used in comparison. */
\r
766 LESENSE_ChSampleMode_TypeDef sampleMode;
\r
768 /** Configure interrupt generation mode for CHx interrupt flag. */
\r
769 LESENSE_ChIntMode_TypeDef intMode;
\r
771 /** Configure decision threshold for counter comparison.
\r
772 * Valid range: 0-65535 (16 bits). */
\r
775 /** Select mode for counter comparison. */
\r
776 LESENSE_ChCompMode_TypeDef compMode;
\r
777 } LESENSE_ChDesc_TypeDef;
\r
780 /** Configuration structure for all scan channels. */
\r
783 /** Channel descriptor for all 16 channels. */
\r
784 LESENSE_ChDesc_TypeDef Ch[16];
\r
785 } LESENSE_ChAll_TypeDef;
\r
787 /** Default configuration for scan channel. */
\r
788 #define LESENSE_CH_CONF_DEFAULT \
\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
811 /** Default configuration for all sensor channels. */
\r
812 #define LESENSE_SCAN_CONF_DEFAULT \
\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
835 /** Alternate excitation descriptor structure. */
\r
838 /** Configure alternate excitation pins. If set, the corresponding alternate
\r
839 * excitation pin/signal is enabled. */
\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
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
854 } LESENSE_AltExDesc_TypeDef;
\r
857 /** Configuration structure for alternate excitation. */
\r
860 /** Select alternate excitation mapping. */
\r
861 LESENSE_AltExMap_TypeDef altExMap;
\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
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
875 LESENSE_AltExDesc_TypeDef AltEx[16];
\r
877 } LESENSE_ConfAltEx_TypeDef;
\r
880 /** Default configuration for alternate excitation channel. */
\r
881 #define LESENSE_ALTEX_CH_CONF_DEFAULT \
\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
888 /** Default configuration for all alternate excitation channels. */
\r
889 #define LESENSE_ALTEX_CONF_DEFAULT \
\r
891 lesenseAltExMapACMP, \
\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
913 /** Decoder state condition descriptor structure. */
\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
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
925 /** Configure index of state to be entered if the sensor state equals to
\r
926 * compVal. Valid range: 0-15 (4 bits). */
\r
929 /** Configure which PRS action to perform when sensor state equals to
\r
931 LESENSE_StTransAct_TypeDef prsAct;
\r
933 /** If enabled, interrupt flag is set when sensor state equals to compVal. */
\r
935 } LESENSE_DecStCond_TypeDef;
\r
937 /** Default configuration for decoder state condition. */
\r
938 #define LESENSE_ST_CONF_DEFAULT \
\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
948 /** Decoder state x configuration structure. */
\r
951 /** If enabled, the state descriptor pair in the next location will also be
\r
955 /** State condition descriptor A (high level descriptor of
\r
956 * LESENSE_STx_DECCONFA). */
\r
957 LESENSE_DecStCond_TypeDef confA;
\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
965 /** Configuration structure for the decoder. */
\r
968 /** Descriptor of the 16 decoder states. */
\r
969 LESENSE_DecStDesc_TypeDef St[16];
\r
970 } LESENSE_DecStAll_TypeDef;
\r
972 /** Default configuration for all decoder states. */
\r
973 #define LESENSE_DECODER_CONF_DEFAULT \
\r
974 { /* chain | Descriptor A | Descriptor B */ \
\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
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
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
1005 void LESENSE_StartDelaySet(uint8_t const startDelay);
\r
1007 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
\r
1008 LESENSE_ClkPresc_TypeDef const clkDiv);
\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
1025 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);
\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
1033 void LESENSE_ScanStart(void);
\r
1034 void LESENSE_ScanStop(void);
\r
1035 void LESENSE_DecoderStart(void);
\r
1036 void LESENSE_ResultBufferClear(void);
\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
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
1056 /***************************************************************************//**
\r
1058 * Stop LESENSE decoder.
\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
1066 /* Stop the decoder */
\r
1067 LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
\r
1071 /***************************************************************************//**
\r
1073 * Get the current status of LESENSE.
\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
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
1087 return LESENSE->STATUS;
\r
1091 /***************************************************************************//**
\r
1093 * Wait until the status of LESENSE is equal to what requested.
\r
1096 * This function is polling the LESENSE_STATUS register and waits until the
\r
1097 * requested combination of flags are set.
\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
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
1113 while (!(LESENSE->STATUS & flag))
\r
1118 /***************************************************************************//**
\r
1120 * Get the currently active channel index.
\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
1128 return LESENSE->CURCH;
\r
1132 /***************************************************************************//**
\r
1134 * Get the latest scan comparison result (1 bit / channel).
\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
1145 return LESENSE->SCANRES;
\r
1149 /***************************************************************************//**
\r
1151 * Get the oldest unread data from the result buffer.
\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
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
1164 return LESENSE->BUFDATA;
\r
1168 /***************************************************************************//**
\r
1170 * Get data from the result data buffer.
\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
1178 * Result data buffer index. Valid range: 0-15.
\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
1185 /* Note: masking is needed to avoid over-indexing! */
\r
1186 return LESENSE->BUF[idx & 0x0FU].DATA;
\r
1189 /***************************************************************************//**
\r
1191 * Get the current state of the LESENSE sensor.
\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
1199 return LESENSE->SENSORSTATE;
\r
1203 /***************************************************************************//**
\r
1205 * Shut off power to the LESENSE RAM, disables LESENSE.
\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
1212 * Warning! Once the LESENSE RAM is powered down, it cannot be powered up
\r
1214 ******************************************************************************/
\r
1215 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
\r
1217 /* Power down LESENSE RAM */
\r
1218 LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
\r
1222 /***************************************************************************//**
\r
1224 * Clear one or more pending LESENSE interrupts.
\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
1233 LESENSE->IFC = flags;
\r
1237 /***************************************************************************//**
\r
1239 * Enable one or more LESENSE interrupts.
\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
1248 LESENSE->IEN |= flags;
\r
1252 /***************************************************************************//**
\r
1254 * Disable one or more LESENSE interrupts.
\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
1263 LESENSE->IEN &= ~(flags);
\r
1267 /***************************************************************************//**
\r
1269 * Set one or more pending LESENSE interrupts from SW.
\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
1278 LESENSE->IFS = flags;
\r
1282 /***************************************************************************//**
\r
1284 * Get pending LESENSE interrupt flags.
\r
1287 * The event bits are not cleared by the use of this function.
\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
1295 return LESENSE->IF;
\r
1299 /***************************************************************************//**
\r
1301 * Get enabled and pending LESENSE interrupt flags.
\r
1304 * Useful for handling more interrupt sources in the same interrupt handler.
\r
1307 * The event bits are not cleared by the use of this function.
\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
1321 /* Store LESENSE->IEN in temporary variable in order to define explicit order
\r
1322 * of volatile accesses. */
\r
1323 tmp = LESENSE->IEN;
\r
1325 /* Bitwise AND of pending and enabled interrupts */
\r
1326 return LESENSE->IF & tmp;
\r
1330 /** @} (end addtogroup LESENSE) */
\r
1331 /** @} (end addtogroup EM_Library) */
\r
1333 #ifdef __cplusplus
\r
1337 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
\r
1339 #endif /* __SILICON_LABS_EM_LESENSE_H_ */
\r