1 /***************************************************************************//**
\r
3 * @brief Low Energy Sensor (LESENSE) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 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
33 #ifndef __SILICON_LABS_EM_LESENSE_H__
\r
34 #define __SILICON_LABS_EM_LESENSE_H__
\r
36 #include "em_device.h"
\r
38 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)
\r
40 #include <stdbool.h>
\r
47 /***************************************************************************//**
\r
48 * @addtogroup EM_Library
\r
50 ******************************************************************************/
\r
52 /***************************************************************************//**
\r
53 * @addtogroup LESENSE
\r
55 ******************************************************************************/
\r
57 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
63 /*******************************************************************************
\r
64 ******************************** ENUMS ************************************
\r
65 ******************************************************************************/
\r
67 /** Clock divisors for controlling the prescaling factor of the period
\r
69 * Note: these enumeration values are being used for different clock division
\r
70 * related configuration parameters (hfPresc, lfPresc, pcPresc). */
\r
73 lesenseClkDiv_1 = 0, /**< Divide clock by 1. */
\r
74 lesenseClkDiv_2 = 1, /**< Divide clock by 2. */
\r
75 lesenseClkDiv_4 = 2, /**< Divide clock by 4. */
\r
76 lesenseClkDiv_8 = 3, /**< Divide clock by 8. */
\r
77 lesenseClkDiv_16 = 4, /**< Divide clock by 16. */
\r
78 lesenseClkDiv_32 = 5, /**< Divide clock by 32. */
\r
79 lesenseClkDiv_64 = 6, /**< Divide clock by 64. */
\r
80 lesenseClkDiv_128 = 7 /**< Divide clock by 128. */
\r
81 } LESENSE_ClkPresc_TypeDef;
\r
87 /** New scan is started each time the period counter overflows. */
\r
88 lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,
\r
90 /** Single scan is performed when LESENSE_ScanStart() is called. */
\r
91 lesenseScanStartOneShot = LESENSE_CTRL_SCANMODE_ONESHOT,
\r
93 /** New scan is triggered by pulse on PRS channel. */
\r
94 lesenseScanStartPRS = LESENSE_CTRL_SCANMODE_PRS
\r
95 } LESENSE_ScanMode_TypeDef;
\r
99 * Note: these enumeration values are being used for different PRS related
\r
100 * configuration parameters. */
\r
103 lesensePRSCh0 = 0, /**< PRS channel 0. */
\r
104 lesensePRSCh1 = 1, /**< PRS channel 1. */
\r
105 lesensePRSCh2 = 2, /**< PRS channel 2. */
\r
106 lesensePRSCh3 = 3, /**< PRS channel 3. */
\r
107 #if defined( LESENSE_CTRL_PRSSEL_PRSCH4 )
\r
108 lesensePRSCh4 = 4, /**< PRS channel 4. */
\r
110 #if defined( LESENSE_CTRL_PRSSEL_PRSCH5 )
\r
111 lesensePRSCh5 = 5, /**< PRS channel 5. */
\r
113 #if defined( LESENSE_CTRL_PRSSEL_PRSCH6 )
\r
114 lesensePRSCh6 = 6, /**< PRS channel 6. */
\r
116 #if defined( LESENSE_CTRL_PRSSEL_PRSCH7 )
\r
117 lesensePRSCh7 = 7, /**< PRS channel 7. */
\r
119 #if defined( LESENSE_CTRL_PRSSEL_PRSCH8 )
\r
120 lesensePRSCh8 = 8, /**< PRS channel 8. */
\r
122 #if defined( LESENSE_CTRL_PRSSEL_PRSCH9 )
\r
123 lesensePRSCh9 = 9, /**< PRS channel 9. */
\r
125 #if defined( LESENSE_CTRL_PRSSEL_PRSCH10 )
\r
126 lesensePRSCh10 = 10, /**< PRS channel 10.*/
\r
128 #if defined( LESENSE_CTRL_PRSSEL_PRSCH11 )
\r
129 lesensePRSCh11 = 11, /**< PRS channel 11.*/
\r
131 } LESENSE_PRSSel_TypeDef;
\r
134 /** Locations of the alternate excitation function. */
\r
137 /** Alternate excitation is mapped to the LES_ALTEX pins. */
\r
138 lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
\r
140 /** Alternate excitation is mapped to the pins of the other ACMP. */
\r
141 lesenseAltExMapACMP = _LESENSE_CTRL_ALTEXMAP_ACMP
\r
142 } LESENSE_AltExMap_TypeDef;
\r
145 /** Result buffer interrupt and DMA trigger levels. */
\r
148 /** DMA and interrupt flags are set when result buffer is halffull. */
\r
149 lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
\r
151 /** DMA and interrupt flags set when result buffer is full. */
\r
152 lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL
\r
153 } LESENSE_BufTrigLevel_TypeDef;
\r
156 /** Modes of operation for DMA wakeup from EM2. */
\r
159 /** No DMA wakeup from EM2. */
\r
160 lesenseDMAWakeUpDisable = LESENSE_CTRL_DMAWU_DISABLE,
\r
162 /** DMA wakeup from EM2 when data is valid in the result buffer. */
\r
163 lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
\r
165 /** DMA wakeup from EM2 when the resultbuffer is full/halffull, depending on
\r
166 * RESBIDL configuration in LESENSE_CTRL register (selected by
\r
167 * resBufTrigLevel in LESENSE_ResBufTrigLevel_TypeDef descriptor structure). */
\r
168 lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL
\r
169 } LESENSE_DMAWakeUp_TypeDef;
\r
175 /** Duty cycle bias module between low power and high accuracy mode. */
\r
176 lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
\r
178 /** Bias module is always in high accuracy mode. */
\r
179 lesenseBiasModeHighAcc = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
\r
181 /** Bias module is controlled by the EMU and not affected by LESENSE. */
\r
182 lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH
\r
183 } LESENSE_BiasMode_TypeDef;
\r
186 /** Scan configuration. */
\r
189 /** The channel configuration registers (CHx_CONF) used are directly mapped to
\r
190 * the channel number. */
\r
191 lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,
\r
193 /** The channel configuration registers used are CHx+8_CONF for channels 0-7
\r
194 * and CHx-8_CONF for channels 8-15. */
\r
195 lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,
\r
197 /** The channel configuration registers used toggles between CHX_SCANCONF and
\r
198 * CHX+8_SCANCONF when channel x triggers. */
\r
199 lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,
\r
201 /** The decoder state defines the channel configuration register (CHx_CONF) to
\r
203 lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
\r
204 } LESENSE_ScanConfSel_TypeDef;
\r
207 /** DAC CHx data control configuration. */
\r
210 /** DAC channel x data is defined by DAC_CHxDATA register.
\r
211 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
212 lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,
\r
214 /** DAC channel x data is defined by ACMPTHRES in LESENSE_CHx_INTERACT.
\r
215 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
216 lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES
\r
217 } LESENSE_ControlDACData_TypeDef;
\r
220 /** DAC channel x conversion mode configuration. */
\r
223 /** LESENSE doesn't control DAC channel x.
\r
224 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
225 lesenseDACConvModeDisable = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,
\r
227 /** DAC channel x is driven in continuous mode.
\r
228 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
229 lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,
\r
231 /** DAC channel x is driven in sample hold mode.
\r
232 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
233 lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,
\r
235 /** DAC channel x is driven in sample off mode.
\r
236 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
237 lesenseDACConvModeSampleOff = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF
\r
238 } LESENSE_ControlDACConv_TypeDef;
\r
241 /** DAC channel x output mode configuration. */
\r
244 /** DAC CHx output to pin and ACMP/ADC disabled.
\r
245 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
246 lesenseDACOutModeDisable = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,
\r
248 /** DAC CHx output to pin enabled, output to ADC and ACMP disabled.
\r
249 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
250 lesenseDACOutModePin = _LESENSE_PERCTRL_DACCH0OUT_PIN,
\r
252 /** DAC CHx output to pin disabled, output to ADC and ACMP enabled.
\r
253 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
254 lesenseDACOutModeADCACMP = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,
\r
256 /** DAC CHx output to pin, ADC, and ACMP enabled.
\r
257 * Note: this value could be used for both DAC Ch0 and Ch1. */
\r
258 lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP
\r
259 } LESENSE_ControlDACOut_TypeDef;
\r
262 /** DAC reference configuration. */
\r
265 /** DAC uses VDD reference. */
\r
266 lesenseDACRefVdd = LESENSE_PERCTRL_DACREF_VDD,
\r
268 /** DAC uses bandgap reference. */
\r
269 lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
\r
270 } LESENSE_DACRef_TypeDef;
\r
273 /** ACMPx control configuration. */
\r
276 /** LESENSE does not control the ACMPx.
\r
277 * Note: this value could be used for both ACMP0 and ACMP1. */
\r
278 lesenseACMPModeDisable = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,
\r
280 /** LESENSE controls the input mux of ACMPx.
\r
281 * Note: this value could be used for both ACMP0 and ACMP1. */
\r
282 lesenseACMPModeMux = _LESENSE_PERCTRL_ACMP0MODE_MUX,
\r
284 /** LESENSE controls the input mux of and the threshold value of ACMPx.
\r
285 * Note: this value could be used for both ACMP0 and ACMP1. */
\r
286 lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES
\r
287 } LESENSE_ControlACMP_TypeDef;
\r
290 /** Warm up modes. ACMP and DAC duty cycle mode configuration. */
\r
293 /** ACMPs and DACs are shut down when LESENSE is idle. */
\r
294 lesenseWarmupModeNormal = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
\r
296 /** ACMPs are kept powered up when LESENSE is idle. */
\r
297 lesenseWarmupModeACMP = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
\r
299 /** The DAC is kept powered up when LESENSE is idle. */
\r
300 lesenseWarmupModeDAC = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
\r
302 /** ACMPs and the DAC are kept powered up when LESENSE is idle. */
\r
303 lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM
\r
304 } LESENSE_WarmupMode_TypeDef;
\r
307 /** Decoder input source configuration. */
\r
310 /** The SENSORSTATE register is used as input to the decoder. */
\r
311 lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
\r
313 /** PRS channels are used as input to the decoder. */
\r
314 lesenseDecInputPRS = LESENSE_DECCTRL_INPUT_PRS
\r
315 } LESENSE_DecInput_TypeDef;
\r
318 /** Compare source selection for sensor sampling. */
\r
321 /** Counter output will be used in comparison. */
\r
322 lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,
\r
324 /** ACMP output will be used in comparison. */
\r
325 lesenseSampleModeACMP = LESENSE_CH_INTERACT_SAMPLE_ACMP
\r
326 } LESENSE_ChSampleMode_TypeDef;
\r
329 /** Interrupt generation setup for CHx interrupt flag. */
\r
332 /** No interrupt is generated. */
\r
333 lesenseSetIntNone = LESENSE_CH_INTERACT_SETIF_NONE,
\r
335 /** Set interrupt flag if the sensor triggers. */
\r
336 lesenseSetIntLevel = LESENSE_CH_INTERACT_SETIF_LEVEL,
\r
338 /** Set interrupt flag on positive edge of the sensor state. */
\r
339 lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
\r
341 /** Set interrupt flag on negative edge of the sensor state. */
\r
342 lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE
\r
343 } LESENSE_ChIntMode_TypeDef;
\r
346 /** Channel pin mode for the excitation phase of the scan sequence. */
\r
349 /** Channel pin is disabled. */
\r
350 lesenseChPinExDis = LESENSE_CH_INTERACT_EXMODE_DISABLE,
\r
352 /** Channel pin is configured as push-pull, driven HIGH. */
\r
353 lesenseChPinExHigh = LESENSE_CH_INTERACT_EXMODE_HIGH,
\r
355 /** Channel pin is configured as push-pull, driven LOW. */
\r
356 lesenseChPinExLow = LESENSE_CH_INTERACT_EXMODE_LOW,
\r
358 /** DAC output (only available on channel 0, 1, 2, 3, 12, 13, 14 and 15) */
\r
359 lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT
\r
360 } LESENSE_ChPinExMode_TypeDef;
\r
363 /** Channel pin mode for the idle phase of the scan sequence. */
\r
366 /** Channel pin is disabled in idle phase.
\r
367 * Note: this value could be used for all channels. */
\r
368 lesenseChPinIdleDis = _LESENSE_IDLECONF_CH0_DISABLE,
\r
370 /** Channel pin is configured as push-pull, driven HIGH in idle phase.
\r
371 * Note: this value could be used for all channels. */
\r
372 lesenseChPinIdleHigh = _LESENSE_IDLECONF_CH0_HIGH,
\r
374 /** Channel pin is configured as push-pull, driven LOW in idle phase.
\r
375 * Note: this value could be used for all channels. */
\r
376 lesenseChPinIdleLow = _LESENSE_IDLECONF_CH0_LOW,
\r
378 /** Channel pin is connected to DAC CH0 output in idle phase.
\r
379 * Note: only applies to channel 0, 1, 2, 3. */
\r
380 lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,
\r
382 /** Channel pin is connected to DAC CH1 output in idle phase.
\r
383 * Note: only applies to channel 12, 13, 14, 15. */
\r
384 lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1
\r
385 } LESENSE_ChPinIdleMode_TypeDef;
\r
388 /** Clock used for excitation and sample delay timing. */
\r
391 /** LFACLK (LF clock) is used. */
\r
392 lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
\r
394 /** AUXHFRCO (HF clock) is used. */
\r
395 lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
\r
396 } LESENSE_ChClk_TypeDef;
\r
399 /** Compare modes for counter comparison. */
\r
402 /** Set interrupt flag if counter value is less than CTRTHRESHOLD, or if the
\r
403 * ACMP output is 0. */
\r
404 lesenseCompModeLess = LESENSE_CH_EVAL_COMP_LESS,
\r
406 /** Set interrupt flag if counter value is greater than, or equal to
\r
407 * CTRTHRESHOLD, or if the ACMP output is 1. */
\r
408 lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE
\r
409 } LESENSE_ChCompMode_TypeDef;
\r
412 /** Idle phase configuration of alternate excitation channels. */
\r
415 /** ALTEX output is disabled in idle phase.
\r
416 * Note: this value could be used for all alternate excitation channels. */
\r
417 lesenseAltExPinIdleDis = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,
\r
419 /** ALTEX output is high in idle phase.
\r
420 * Note: this value could be used for all alternate excitation channels. */
\r
421 lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,
\r
423 /** ALTEX output is low in idle phase.
\r
424 * Note: this value could be used for all alternate excitation channels. */
\r
425 lesenseAltExPinIdleLow = _LESENSE_ALTEXCONF_IDLECONF0_LOW
\r
426 } LESENSE_AltExPinIdle_TypeDef;
\r
429 /** Transition action modes. */
\r
432 /** No PRS pulses generated (if PRSCOUNT == 0).
\r
433 * Do not count (if PRSCOUNT == 1). */
\r
434 lesenseTransActNone = LESENSE_ST_TCONFA_PRSACT_NONE,
\r
436 /** Generate pulse on LESPRS0 (if PRSCOUNT == 0). */
\r
437 lesenseTransActPRS0 = LESENSE_ST_TCONFA_PRSACT_PRS0,
\r
439 /** Generate pulse on LESPRS1 (if PRSCOUNT == 0). */
\r
440 lesenseTransActPRS1 = LESENSE_ST_TCONFA_PRSACT_PRS1,
\r
442 /** Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). */
\r
443 lesenseTransActPRS01 = LESENSE_ST_TCONFA_PRSACT_PRS01,
\r
445 /** Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). */
\r
446 lesenseTransActPRS2 = LESENSE_ST_TCONFA_PRSACT_PRS2,
\r
448 /** Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). */
\r
449 lesenseTransActPRS02 = LESENSE_ST_TCONFA_PRSACT_PRS02,
\r
451 /** Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
\r
452 lesenseTransActPRS12 = LESENSE_ST_TCONFA_PRSACT_PRS12,
\r
454 /** Generate pulse on LESPRS0, LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
\r
455 lesenseTransActPRS012 = LESENSE_ST_TCONFA_PRSACT_PRS012,
\r
457 /** Count up (if PRSCOUNT == 1). */
\r
458 lesenseTransActUp = LESENSE_ST_TCONFA_PRSACT_UP,
\r
460 /** Count down (if PRSCOUNT == 1). */
\r
461 lesenseTransActDown = LESENSE_ST_TCONFA_PRSACT_DOWN,
\r
463 /** Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
\r
464 lesenseTransActUpAndPRS2 = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
\r
466 /** Count down and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
\r
467 lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2
\r
468 } LESENSE_StTransAct_TypeDef;
\r
471 /*******************************************************************************
\r
472 ******************************* STRUCTS ***********************************
\r
473 ******************************************************************************/
\r
475 /** Core control (LESENSE_CTRL) descriptor structure. */
\r
478 /** Select scan start mode to control how the scan start is being triggered.*/
\r
479 LESENSE_ScanMode_TypeDef scanStart;
\r
481 /** Select PRS source for scan start if scanMode is set to lesensePrsPulse. */
\r
482 LESENSE_PRSSel_TypeDef prsSel;
\r
484 /** Select scan configuration register usage strategy. */
\r
485 LESENSE_ScanConfSel_TypeDef scanConfSel;
\r
487 /** Set to true to invert ACMP0 output. */
\r
490 /** Set to true to invert ACMP1 output. */
\r
493 /** Set to true to sample both ACMPs simultaneously. */
\r
496 /** Set to true in order to to store SCANRES in RAM (accessible via RESDATA)
\r
497 * after each scan. */
\r
500 /** Set to true in order to always make LESENSE write to the result buffer,
\r
501 * even if it is full. */
\r
504 /** Select trigger conditions for interrupt and DMA. */
\r
505 LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
\r
507 /** Configure trigger condition for DMA wakeup from EM2. */
\r
508 LESENSE_DMAWakeUp_TypeDef wakeupOnDMA;
\r
510 /** Select bias mode. */
\r
511 LESENSE_BiasMode_TypeDef biasMode;
\r
513 /** Set to true to keep LESENSE running in debug mode. */
\r
515 } LESENSE_CoreCtrlDesc_TypeDef;
\r
517 /** Default configuration for LESENSE_CtrlDesc_TypeDef structure. */
\r
518 #define LESENSE_CORECTRL_DESC_DEFAULT \
\r
520 lesenseScanStartPeriodic, /* Start new scan each time the period counter overflows. */ \
\r
521 lesensePRSCh0, /* Default PRS channel is selected. */ \
\r
522 lesenseScanConfDirMap, /* Direct mapping SCANCONF register usage strategy. */ \
\r
523 false, /* Don't invert ACMP0 output. */ \
\r
524 false, /* Don't invert ACMP1 output. */ \
\r
525 false, /* Disable dual sampling. */ \
\r
526 true, /* Store scan result after each scan. */ \
\r
527 true, /* Overwrite result buffer register even if it is full. */ \
\r
528 lesenseBufTrigHalf, /* Trigger interrupt and DMA request if result buffer is half full. */ \
\r
529 lesenseDMAWakeUpDisable, /* Don't wake up on DMA from EM2. */ \
\r
530 lesenseBiasModeDontTouch, /* Don't touch bias configuration. */ \
\r
531 true /* Keep LESENSE running in debug mode. */ \
\r
535 /** LESENSE timing control descriptor structure. */
\r
538 /** Set the number of LFACLK cycles to delay sensor interaction on
\r
539 * each channel. Valid range: 0-3 (2 bit). */
\r
540 uint8_t startDelay;
\r
541 } LESENSE_TimeCtrlDesc_TypeDef;
\r
543 /** Default configuration for LESENSE_TimeCtrlDesc_TypeDef structure. */
\r
544 #define LESENSE_TIMECTRL_DESC_DEFAULT \
\r
546 0U /* No sensor interaction delay. */ \
\r
550 /** LESENSE peripheral control descriptor structure. */
\r
553 /** Configure DAC channel 0 data control. */
\r
554 LESENSE_ControlDACData_TypeDef dacCh0Data;
\r
556 /** Configure how LESENSE controls conversion on DAC channel 0. */
\r
557 LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
\r
559 /** Configure how LESENSE controls output on DAC channel 0. */
\r
560 LESENSE_ControlDACOut_TypeDef dacCh0OutMode;
\r
562 /** Configure DAC channel 1 data control. */
\r
563 LESENSE_ControlDACData_TypeDef dacCh1Data;
\r
565 /** Configure how LESENSE controls conversion on DAC channel 1. */
\r
566 LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
\r
568 /** Configure how LESENSE controls output on DAC channel 1. */
\r
569 LESENSE_ControlDACOut_TypeDef dacCh1OutMode;
\r
571 /** Configure the prescaling factor for the LESENSE - DAC interface.
\r
572 * Valid range: 0-31 (5bit). */
\r
575 /** Configure the DAC reference to be used. Set to #lesenseDACRefVdd to use
\r
576 * VDD and set to #lesenseDACRefBandGap to use bandgap as reference. */
\r
577 LESENSE_DACRef_TypeDef dacRef;
\r
579 /** Configure how LESENSE controls ACMP 0. */
\r
580 LESENSE_ControlACMP_TypeDef acmp0Mode;
\r
582 /** Configure how LESENSE controls ACMP 1. */
\r
583 LESENSE_ControlACMP_TypeDef acmp1Mode;
\r
585 /** Configure how LESENSE controls ACMPs and the DAC in idle mode. */
\r
586 LESENSE_WarmupMode_TypeDef warmupMode;
\r
587 } LESENSE_PerCtrlDesc_TypeDef;
\r
589 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
\r
590 #define LESENSE_PERCTRL_DESC_DEFAULT \
\r
592 lesenseDACIfData, /**/ \
\r
593 lesenseDACConvModeDisable, /**/ \
\r
594 lesenseDACOutModeDisable, /**/ \
\r
595 lesenseDACIfData, /**/ \
\r
596 lesenseDACConvModeDisable, /**/ \
\r
597 lesenseDACOutModeDisable, /**/ \
\r
599 lesenseDACRefVdd, /**/ \
\r
600 lesenseACMPModeMuxThres, /**/ \
\r
601 lesenseACMPModeMuxThres, /**/ \
\r
602 lesenseWarmupModeKeepWarm, /**/ \
\r
606 /** LESENSE decoder control descriptor structure. */
\r
609 /** Select the input to the LESENSE decoder. */
\r
610 LESENSE_DecInput_TypeDef decInput;
\r
612 /** Initial state of the LESENSE decoder. */
\r
613 uint32_t initState;
\r
615 /** Set to enable the decoder to check the present state in addition
\r
616 * to the states defined in DECCONF. */
\r
619 /** When set, a transition from state x in the decoder will set interrupt flag
\r
623 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
\r
627 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
\r
631 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
\r
635 /** Set to enable hysteresis in the decoder for suppressing interrupt
\r
639 /** Set to enable count mode on decoder PRS channels 0 and 1 to produce
\r
640 * outputs which can be used by a PCNT to count up or down. */
\r
643 /** Select PRS channel input for bit 0 of the LESENSE decoder. */
\r
644 LESENSE_PRSSel_TypeDef prsChSel0;
\r
646 /** Select PRS channel input for bit 1 of the LESENSE decoder. */
\r
647 LESENSE_PRSSel_TypeDef prsChSel1;
\r
649 /** Select PRS channel input for bit 2 of the LESENSE decoder. */
\r
650 LESENSE_PRSSel_TypeDef prsChSel2;
\r
652 /** Select PRS channel input for bit 3 of the LESENSE decoder. */
\r
653 LESENSE_PRSSel_TypeDef prsChSel3;
\r
654 } LESENSE_DecCtrlDesc_TypeDef;
\r
656 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
\r
657 #define LESENSE_DECCTRL_DESC_DEFAULT \
\r
659 lesenseDecInputSensorSt, /**/ \
\r
668 lesensePRSCh0, /**/ \
\r
669 lesensePRSCh1, /**/ \
\r
670 lesensePRSCh2, /**/ \
\r
671 lesensePRSCh3, /**/ \
\r
675 /** LESENSE module initialization structure. */
\r
678 /** LESENSE core configuration parameters. */
\r
679 LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
\r
681 /** LESENSE timing configuration parameters. */
\r
682 LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
\r
684 /** LESENSE peripheral configuration parameters. */
\r
685 LESENSE_PerCtrlDesc_TypeDef perCtrl;
\r
687 /** LESENSE decoder configuration parameters. */
\r
688 LESENSE_DecCtrlDesc_TypeDef decCtrl;
\r
689 } LESENSE_Init_TypeDef;
\r
691 /** Default configuration for LESENSE_Init_TypeDef structure. */
\r
692 #define LESENSE_INIT_DEFAULT \
\r
694 .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */ \
\r
695 .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */ \
\r
696 .perCtrl = LESENSE_PERCTRL_DESC_DEFAULT, /* Default peripheral control parameters. */ \
\r
697 .decCtrl = LESENSE_DECCTRL_DESC_DEFAULT /* Default decoder control parameters. */ \
\r
701 /** Channel descriptor structure. */
\r
704 /** Set to enable scan channel CHx. */
\r
707 /** Set to enable CHx pin. */
\r
710 /** Enable/disable channel interrupts after configuring all the sensor channel
\r
714 /** Configure channel pin mode for the excitation phase of the scan sequence.
\r
715 * Note: OPAOUT is only available on channels 2, 3, 4, and 5. */
\r
716 LESENSE_ChPinExMode_TypeDef chPinExMode;
\r
718 /** Configure channel pin idle setup in LESENSE idle phase. */
\r
719 LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
\r
721 /** Set to use alternate excite pin for excitation. */
\r
724 /** Set to enable the result from this channel being shifted into the decoder
\r
728 /** Set to invert the result bit stored in SCANRES register. */
\r
731 /** Set to store the counter value in RAM (accessible via RESDATA) and make
\r
732 * the comparison result available in the SCANRES register. */
\r
735 /** Select clock used for excitation timing. */
\r
736 LESENSE_ChClk_TypeDef exClk;
\r
738 /** Select clock used for sample delay timing. */
\r
739 LESENSE_ChClk_TypeDef sampleClk;
\r
741 /** Configure excitation time. Excitation will last exTime+1 excitation clock
\r
742 * cycles. Valid range: 0-63 (6 bits). */
\r
745 /** Configure sample delay. Sampling will occur after sampleDelay+1 sample
\r
746 * clock cycles. Valid range: 0-127 (7 bits). */
\r
747 uint8_t sampleDelay;
\r
749 /** Configure measure delay. Sensor measuring is delayed for measDelay
\r
750 * excitation clock cycles. Valid range: 0-127 (7 bits). */
\r
753 /** Configure ACMP threshold.
\r
754 * If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseDACIfData,
\r
755 * acmpThres defines the 12-bit DAC data in the corresponding data register
\r
756 * of the DAC interface (DACn_CH0DATA and DACn_CH1DATA).
\r
757 * In this case, the valid range is: 0-4095 (12 bits).
\r
758 * If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseACMPThres,
\r
759 * acmpThres defines the 6-bit Vdd scaling factor of ACMP negative input
\r
760 * (VDDLEVEL in ACMP_INPUTSEL register).
\r
761 * In this case, the valid range is: 0-63 (6 bits). */
\r
762 uint16_t acmpThres;
\r
764 /** Select if ACMP output or counter output should be used in comparison. */
\r
765 LESENSE_ChSampleMode_TypeDef sampleMode;
\r
767 /** Configure interrupt generation mode for CHx interrupt flag. */
\r
768 LESENSE_ChIntMode_TypeDef intMode;
\r
770 /** Configure decision threshold for counter comparison.
\r
771 * Valid range: 0-65535 (16 bits). */
\r
774 /** Select mode for counter comparison. */
\r
775 LESENSE_ChCompMode_TypeDef compMode;
\r
776 } LESENSE_ChDesc_TypeDef;
\r
779 /** Configuration structure for all scan channels. */
\r
782 /** Channel descriptor for all 16 channels. */
\r
783 LESENSE_ChDesc_TypeDef Ch[16];
\r
784 } LESENSE_ChAll_TypeDef;
\r
786 /** Default configuration for scan channel. */
\r
787 #define LESENSE_CH_CONF_DEFAULT \
\r
789 true, /* Enable scan channel. */ \
\r
790 true, /* Enable the assigned pin on scan channel. */ \
\r
791 true, /* Enable interrupts on channel. */ \
\r
792 lesenseChPinExHigh, /* Channel pin is high during the excitation period. */ \
\r
793 lesenseChPinIdleLow, /* Channel pin is low during the idle period. */ \
\r
794 false, /* Don't use alternate excitation pins for excitation. */ \
\r
795 false, /* Disabled to shift results from this channel to the decoder register. */ \
\r
796 false, /* Disabled to invert the scan result bit. */ \
\r
797 false, /* Disabled to store counter value in the result buffer. */ \
\r
798 lesenseClkLF, /* Use the LF clock for excitation timing. */ \
\r
799 lesenseClkLF, /* Use the LF clock for sample timing. */ \
\r
800 0x03U, /* Excitation time is set to 3(+1) excitation clock cycles. */ \
\r
801 0x09U, /* Sample delay is set to 9(+1) sample clock cycles. */ \
\r
802 0x06U, /* Measure delay is set to 6 excitation clock cycles.*/ \
\r
803 0x00U, /* ACMP threshold has been set to 0. */ \
\r
804 lesenseSampleModeACMP, /* ACMP output will be used in comparison. */ \
\r
805 lesenseSetIntNone, /* No interrupt is generated by the channel. */ \
\r
806 0xFFU, /* Counter threshold has bee set to 0xFF. */ \
\r
807 lesenseCompModeLess /* Compare mode has been set to trigger interrupt on "less". */ \
\r
810 /** Default configuration for all sensor channels. */
\r
811 #define LESENSE_SCAN_CONF_DEFAULT \
\r
814 LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */ \
\r
815 LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */ \
\r
816 LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */ \
\r
817 LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */ \
\r
818 LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */ \
\r
819 LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */ \
\r
820 LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */ \
\r
821 LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */ \
\r
822 LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */ \
\r
823 LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */ \
\r
824 LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \
\r
825 LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \
\r
826 LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \
\r
827 LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \
\r
828 LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \
\r
829 LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \
\r
834 /** Alternate excitation descriptor structure. */
\r
837 /** Configure alternate excitation pins. If set, the corresponding alternate
\r
838 * excitation pin/signal is enabled. */
\r
841 /** Configure idle phase setup of alternate excitation pins.
\r
842 The idleConf parameter is not valid when altExMap==lesenseAltExMapACMP. */
\r
843 LESENSE_AltExPinIdle_TypeDef idleConf;
\r
845 /** Configure how to control the external alternate excitation pins. Only
\r
846 * applies if altExMap has been set to lesenseAltExMapALTEX.
\r
847 * If true, the excitation happens on the corresponding alternate excitation
\r
848 * pin during the excitation periods of all enabled channels.
\r
849 * If false, the excitation happens on the corresponding alternate excitation
\r
850 * pin ONLY during the excitation period of the corresponding channel.
\r
851 * The alwaysEx parameter is not valid when altExMap==lesenseAltExMapACMP. */
\r
853 } LESENSE_AltExDesc_TypeDef;
\r
856 /** Configuration structure for alternate excitation. */
\r
859 /** Select alternate excitation mapping. */
\r
860 LESENSE_AltExMap_TypeDef altExMap;
\r
862 /** Alternate excitation channel descriptors.
\r
863 * When altExMap==lesenseAltExMapALTEX only the 8 first descriptors are used.
\r
864 * In this mode they describe the configuration of the LES_ALTEX0-7 pins.
\r
865 * When altExMap==lesenseAltExMapACMP all 16 descriptors are used. In this
\r
866 * mode they describe the configuration of the 16 possible ACMP0-1 excitation
\r
867 * channels. Please refer to the user manual for a complete mapping of the
\r
870 * Some parameters in the descriptors are not valid when
\r
871 * altExMap==lesenseAltExMapACMP. Please refer to the definition of the
\r
872 * LESENSE_AltExDesc_TypeDef structure for details regarding which parameters
\r
874 LESENSE_AltExDesc_TypeDef AltEx[16];
\r
876 } LESENSE_ConfAltEx_TypeDef;
\r
879 /** Default configuration for alternate excitation channel. */
\r
880 #define LESENSE_ALTEX_CH_CONF_DEFAULT \
\r
882 true, /* Alternate excitation enabled.*/ \
\r
883 lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \
\r
884 false /* Excite only for corresponding channel. */ \
\r
887 /** Default configuration for all alternate excitation channels. */
\r
888 #define LESENSE_ALTEX_CONF_DEFAULT \
\r
890 lesenseAltExMapACMP, \
\r
892 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */ \
\r
893 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */ \
\r
894 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */ \
\r
895 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */ \
\r
896 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */ \
\r
897 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */ \
\r
898 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */ \
\r
899 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */ \
\r
900 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */ \
\r
901 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */ \
\r
902 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
\r
903 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
\r
904 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
\r
905 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
\r
906 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
\r
907 LESENSE_ALTEX_CH_CONF_DEFAULT /* Alternate excitation channel 15. */ \
\r
912 /** Decoder state condition descriptor structure. */
\r
915 /** Configure compare value. State transition is triggered when sensor state
\r
916 * equals to this value. Valid range: 0-15 (4 bits). */
\r
919 /** Configure compare mask. Set bit X to exclude sensor X from evaluation.
\r
920 * Note: decoder can handle sensor inputs from up to 4 sensors, therefore
\r
921 * this mask is 4 bit long. */
\r
924 /** Configure index of state to be entered if the sensor state equals to
\r
925 * compVal. Valid range: 0-15 (4 bits). */
\r
928 /** Configure which PRS action to perform when sensor state equals to
\r
930 LESENSE_StTransAct_TypeDef prsAct;
\r
932 /** If enabled, interrupt flag is set when sensor state equals to compVal. */
\r
934 } LESENSE_DecStCond_TypeDef;
\r
936 /** Default configuration for decoder state condition. */
\r
937 #define LESENSE_ST_CONF_DEFAULT \
\r
939 0x0FU, /* Compare value set to 0x0F. */ \
\r
940 0x00U, /* All decoder inputs masked. */ \
\r
941 0U, /* Next state is state 0. */ \
\r
942 lesenseTransActNone, /* No PRS action performed on compare match. */ \
\r
943 false /* No interrupt triggered on compare match. */ \
\r
947 /** Decoder state x configuration structure. */
\r
950 /** If enabled, the state descriptor pair in the next location will also be
\r
954 /** State condition descriptor A (high level descriptor of
\r
955 * LESENSE_STx_DECCONFA). */
\r
956 LESENSE_DecStCond_TypeDef confA;
\r
958 /** State condition descriptor B (high level descriptor of
\r
959 * LESENSE_STx_DECCONFB). */
\r
960 LESENSE_DecStCond_TypeDef confB;
\r
961 } LESENSE_DecStDesc_TypeDef;
\r
964 /** Configuration structure for the decoder. */
\r
967 /** Descriptor of the 16 decoder states. */
\r
968 LESENSE_DecStDesc_TypeDef St[16];
\r
969 } LESENSE_DecStAll_TypeDef;
\r
971 /** Default configuration for all decoder states. */
\r
972 #define LESENSE_DECODER_CONF_DEFAULT \
\r
973 { /* chain | Descriptor A | Descriptor B */ \
\r
975 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */ \
\r
976 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */ \
\r
977 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */ \
\r
978 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */ \
\r
979 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */ \
\r
980 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */ \
\r
981 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */ \
\r
982 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */ \
\r
983 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */ \
\r
984 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */ \
\r
985 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */ \
\r
986 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */ \
\r
987 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */ \
\r
988 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */ \
\r
989 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */ \
\r
990 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT } /* Decoder state 15. */ \
\r
994 /*******************************************************************************
\r
995 ***************************** PROTOTYPES **********************************
\r
996 ******************************************************************************/
\r
997 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset);
\r
998 void LESENSE_Reset(void);
\r
1000 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq);
\r
1001 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,
\r
1002 bool const start);
\r
1004 void LESENSE_StartDelaySet(uint8_t const startDelay);
\r
1006 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
\r
1007 LESENSE_ClkPresc_TypeDef const clkDiv);
\r
1009 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll);
\r
1010 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,
\r
1011 uint32_t const chIdx);
\r
1012 void LESENSE_ChannelEnable(uint8_t const chIdx,
\r
1013 bool const enaScanCh,
\r
1014 bool const enaPin);
\r
1015 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);
\r
1016 void LESENSE_ChannelTimingSet(uint8_t const chIdx,
\r
1017 uint8_t const exTime,
\r
1018 uint8_t const sampleDelay,
\r
1019 uint8_t const measDelay);
\r
1020 void LESENSE_ChannelThresSet(uint8_t const chIdx,
\r
1021 uint16_t const acmpThres,
\r
1022 uint16_t const cntThres);
\r
1024 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);
\r
1026 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll);
\r
1027 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,
\r
1028 uint32_t const decSt);
\r
1029 void LESENSE_DecoderStateSet(uint32_t decSt);
\r
1030 uint32_t LESENSE_DecoderStateGet(void);
\r
1032 void LESENSE_ScanStart(void);
\r
1033 void LESENSE_ScanStop(void);
\r
1034 void LESENSE_DecoderStart(void);
\r
1035 void LESENSE_ResultBufferClear(void);
\r
1038 /***************************************************************************//**
\r
1040 * Stop LESENSE decoder.
\r
1043 * This function disables the LESENSE decoder by setting the command to the
\r
1044 * LESENSE_DECCTRL register.
\r
1045 ******************************************************************************/
\r
1046 __STATIC_INLINE void LESENSE_DecoderStop(void)
\r
1048 /* Stop the decoder */
\r
1049 LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
\r
1053 /***************************************************************************//**
\r
1055 * Get the current status of LESENSE.
\r
1058 * This function returns the value of LESENSE_STATUS register that
\r
1059 * contains the OR combination of the following status bits:
\r
1060 * @li LESENSE_STATUS_RESV - Result data valid. Set when data is available
\r
1061 * in the result buffer. Cleared when the buffer is empty.
\r
1062 * @li LESENSE_STATUS_RESFULL - Result buffer full. Set when the result
\r
1064 * @li LESENSE_STATUS_RUNNING - LESENSE is active.
\r
1065 * @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
\r
1066 ******************************************************************************/
\r
1067 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)
\r
1069 return LESENSE->STATUS;
\r
1073 /***************************************************************************//**
\r
1075 * Wait until the status of LESENSE is equal to what requested.
\r
1078 * This function is polling the LESENSE_STATUS register and waits until the
\r
1079 * requested combination of flags are set.
\r
1082 * The OR combination of the following status bits:
\r
1083 * @li LESENSE_STATUS_BUFDATAV - Result data valid. Set when data is available
\r
1084 * in the result buffer. Cleared when the buffer is empty.
\r
1085 * @li LESENSE_STATUS_BUFHALFFULL - Result buffer half full. Set when the
\r
1086 * result buffer is half full.
\r
1087 * @li LESENSE_STATUS_BUFFULL - Result buffer full. Set when the result
\r
1089 * @li LESENSE_STATUS_RUNNING - LESENSE is active.
\r
1090 * @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
\r
1091 * @li LESENSE_STATUS_DACACTIVE - The DAC interface is currently active.
\r
1092 ******************************************************************************/
\r
1093 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)
\r
1095 while (!(LESENSE->STATUS & flag))
\r
1100 /***************************************************************************//**
\r
1102 * Get the currently active channel index.
\r
1105 * This function returns the value of LESENSE_CHINDEX register that
\r
1106 * contains the index of the currently active channel (0-15).
\r
1107 ******************************************************************************/
\r
1108 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)
\r
1110 return LESENSE->CURCH;
\r
1114 /***************************************************************************//**
\r
1116 * Get the latest scan comparison result (1 bit / channel).
\r
1119 * This function returns the value of LESENSE_SCANRES register that
\r
1120 * contains the comparison result of the last scan on all channels.
\r
1121 * Bit x is set if a comparison triggered on channel x, which means that the
\r
1122 * LESENSE counter met the comparison criteria set in LESENSE_CHx_EVAL by
\r
1123 * COMPMODE and CNTTHRES.
\r
1124 ******************************************************************************/
\r
1125 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)
\r
1127 return LESENSE->SCANRES;
\r
1131 /***************************************************************************//**
\r
1133 * Get the oldest unread data from the result buffer.
\r
1136 * Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
\r
1137 * STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return
\r
1138 * undefined value.
\r
1141 * This function returns the value of LESENSE_RESDATA register that
\r
1142 * contains the oldest unread counter result from the result buffer.
\r
1143 ******************************************************************************/
\r
1144 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
\r
1146 return LESENSE->BUFDATA;
\r
1150 /***************************************************************************//**
\r
1152 * Get data from the result data buffer.
\r
1155 * Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
\r
1156 * STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return
\r
1157 * undefined value.
\r
1160 * Result data buffer index. Valid range: 0-15.
\r
1163 * This function returns the selected word from the result data buffer.
\r
1164 ******************************************************************************/
\r
1165 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
\r
1167 /* Note: masking is needed to avoid over-indexing! */
\r
1168 return LESENSE->BUF[idx & 0x0FU].DATA;
\r
1171 /***************************************************************************//**
\r
1173 * Get the current state of the LESENSE sensor.
\r
1176 * This function returns the value of LESENSE_SENSORSTATE register that
\r
1177 * represents the current state of the LESENSE sensor.
\r
1178 ******************************************************************************/
\r
1179 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)
\r
1181 return LESENSE->SENSORSTATE;
\r
1185 /***************************************************************************//**
\r
1187 * Shut off power to the LESENSE RAM, disables LESENSE.
\r
1190 * This function shuts off the LESENSE RAM in order to decrease the leakage
\r
1191 * current of the mcu if LESENSE is not used in your application.
\r
1194 * Warning! Once the LESENSE RAM is powered down, it cannot be powered up
\r
1196 ******************************************************************************/
\r
1197 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
\r
1199 /* Power down LESENSE RAM */
\r
1200 LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
\r
1204 /***************************************************************************//**
\r
1206 * Clear one or more pending LESENSE interrupts.
\r
1208 * @param[in] flags
\r
1209 * Pending LESENSE interrupt sources to clear. Use a set of interrupt flags
\r
1210 * OR-ed together to clear multiple interrupt sources of the LESENSE module
\r
1211 * (LESENSE_IF_nnn).
\r
1212 ******************************************************************************/
\r
1213 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
\r
1215 LESENSE->IFC = flags;
\r
1219 /***************************************************************************//**
\r
1221 * Enable one or more LESENSE interrupts.
\r
1223 * @param[in] flags
\r
1224 * LESENSE interrupt sources to enable. Use a set of interrupt flags OR-ed
\r
1225 * together to enable multiple interrupt sources of the LESENSE module
\r
1226 * (LESENSE_IF_nnn).
\r
1227 ******************************************************************************/
\r
1228 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
\r
1230 LESENSE->IEN |= flags;
\r
1234 /***************************************************************************//**
\r
1236 * Disable one or more LESENSE interrupts.
\r
1238 * @param[in] flags
\r
1239 * LESENSE interrupt sources to disable. Use a set of interrupt flags OR-ed
\r
1240 * together to disable multiple interrupt sources of the LESENSE module
\r
1241 * (LESENSE_IF_nnn).
\r
1242 ******************************************************************************/
\r
1243 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
\r
1245 LESENSE->IEN &= ~flags;
\r
1249 /***************************************************************************//**
\r
1251 * Set one or more pending LESENSE interrupts from SW.
\r
1253 * @param[in] flags
\r
1254 * LESENSE interrupt sources to set to pending. Use a set of interrupt
\r
1255 * flags OR-ed together to set multiple interrupt sources of the LESENSE
\r
1256 * module (LESENSE_IFS_nnn).
\r
1257 ******************************************************************************/
\r
1258 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)
\r
1260 LESENSE->IFS = flags;
\r
1264 /***************************************************************************//**
\r
1266 * Get pending LESENSE interrupt flags.
\r
1269 * The event bits are not cleared by the use of this function.
\r
1272 * Pending LESENSE interrupt sources. The OR combination of valid interrupt
\r
1273 * flags of the LESENSE module (LESENSE_IF_nnn).
\r
1274 ******************************************************************************/
\r
1275 __STATIC_INLINE uint32_t LESENSE_IntGet(void)
\r
1277 return LESENSE->IF;
\r
1281 /***************************************************************************//**
\r
1283 * Get enabled and pending LESENSE interrupt flags.
\r
1286 * Useful for handling more interrupt sources in the same interrupt handler.
\r
1289 * The event bits are not cleared by the use of this function.
\r
1292 * Pending and enabled LESENSE interrupt sources.
\r
1293 * The return value is the bitwise AND combination of
\r
1294 * - the OR combination of enabled interrupt sources in LESENSE_IEN_nnn
\r
1295 * register (LESENSE_IEN_nnn) and
\r
1296 * - the OR combination of valid interrupt flags of the LESENSE module
\r
1297 * (LESENSE_IF_nnn).
\r
1298 ******************************************************************************/
\r
1299 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
\r
1303 /* Store LESENSE->IEN in temporary variable in order to define explicit order
\r
1304 * of volatile accesses. */
\r
1305 tmp = LESENSE->IEN;
\r
1307 /* Bitwise AND of pending and enabled interrupts */
\r
1308 return LESENSE->IF & tmp;
\r
1312 /** @} (end addtogroup LESENSE) */
\r
1313 /** @} (end addtogroup EM_Library) */
\r
1315 #ifdef __cplusplus
\r
1319 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
\r
1321 #endif /* __SILICON_LABS_EM_LESENSE_H__ */
\r