EFM32 Zero Gecko Software Documentation  efm32zg-doc-4.2.1
em_lesense.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __SILICON_LABS_EM_LESENSE_H__
34 #define __SILICON_LABS_EM_LESENSE_H__
35 
36 #include "em_device.h"
37 
38 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 /***************************************************************************/
52 /***************************************************************************/
63 /*******************************************************************************
64  ******************************** ENUMS ************************************
65  ******************************************************************************/
66 
71 typedef enum
72 {
73  lesenseClkDiv_1 = 0,
74  lesenseClkDiv_2 = 1,
75  lesenseClkDiv_4 = 2,
76  lesenseClkDiv_8 = 3,
77  lesenseClkDiv_16 = 4,
78  lesenseClkDiv_32 = 5,
79  lesenseClkDiv_64 = 6,
80  lesenseClkDiv_128 = 7
81 } LESENSE_ClkPresc_TypeDef;
82 
83 
85 typedef enum
86 {
88  lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,
89 
91  lesenseScanStartOneShot = LESENSE_CTRL_SCANMODE_ONESHOT,
92 
94  lesenseScanStartPRS = LESENSE_CTRL_SCANMODE_PRS
95 } LESENSE_ScanMode_TypeDef;
96 
97 
101 typedef enum
102 {
103  lesensePRSCh0 = 0,
104  lesensePRSCh1 = 1,
105  lesensePRSCh2 = 2,
106  lesensePRSCh3 = 3,
107 #if defined( LESENSE_CTRL_PRSSEL_PRSCH4 )
108  lesensePRSCh4 = 4,
109 #endif
110 #if defined( LESENSE_CTRL_PRSSEL_PRSCH5 )
111  lesensePRSCh5 = 5,
112 #endif
113 #if defined( LESENSE_CTRL_PRSSEL_PRSCH6 )
114  lesensePRSCh6 = 6,
115 #endif
116 #if defined( LESENSE_CTRL_PRSSEL_PRSCH7 )
117  lesensePRSCh7 = 7,
118 #endif
119 #if defined( LESENSE_CTRL_PRSSEL_PRSCH8 )
120  lesensePRSCh8 = 8,
121 #endif
122 #if defined( LESENSE_CTRL_PRSSEL_PRSCH9 )
123  lesensePRSCh9 = 9,
124 #endif
125 #if defined( LESENSE_CTRL_PRSSEL_PRSCH10 )
126  lesensePRSCh10 = 10,
127 #endif
128 #if defined( LESENSE_CTRL_PRSSEL_PRSCH11 )
129  lesensePRSCh11 = 11,
130 #endif
131 } LESENSE_PRSSel_TypeDef;
132 
133 
135 typedef enum
136 {
138  lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
139 
141  lesenseAltExMapACMP = _LESENSE_CTRL_ALTEXMAP_ACMP
142 } LESENSE_AltExMap_TypeDef;
143 
144 
146 typedef enum
147 {
149  lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
150 
152  lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL
153 } LESENSE_BufTrigLevel_TypeDef;
154 
155 
157 typedef enum
158 {
160  lesenseDMAWakeUpDisable = LESENSE_CTRL_DMAWU_DISABLE,
161 
163  lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
164 
168  lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL
169 } LESENSE_DMAWakeUp_TypeDef;
170 
171 
173 typedef enum
174 {
176  lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
177 
179  lesenseBiasModeHighAcc = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
180 
182  lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH
183 } LESENSE_BiasMode_TypeDef;
184 
185 
187 typedef enum
188 {
191  lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,
192 
195  lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,
196 
199  lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,
200 
203  lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
204 } LESENSE_ScanConfSel_TypeDef;
205 
206 
208 typedef enum
209 {
212  lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,
213 
216  lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES
217 } LESENSE_ControlDACData_TypeDef;
218 
219 
221 typedef enum
222 {
225  lesenseDACConvModeDisable = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,
226 
229  lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,
230 
233  lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,
234 
237  lesenseDACConvModeSampleOff = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF
238 } LESENSE_ControlDACConv_TypeDef;
239 
240 
242 typedef enum
243 {
246  lesenseDACOutModeDisable = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,
247 
250  lesenseDACOutModePin = _LESENSE_PERCTRL_DACCH0OUT_PIN,
251 
254  lesenseDACOutModeADCACMP = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,
255 
258  lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP
259 } LESENSE_ControlDACOut_TypeDef;
260 
261 
263 typedef enum
264 {
266  lesenseDACRefVdd = LESENSE_PERCTRL_DACREF_VDD,
267 
269  lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
270 } LESENSE_DACRef_TypeDef;
271 
272 
274 typedef enum
275 {
278  lesenseACMPModeDisable = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,
279 
282  lesenseACMPModeMux = _LESENSE_PERCTRL_ACMP0MODE_MUX,
283 
286  lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES
287 } LESENSE_ControlACMP_TypeDef;
288 
289 
291 typedef enum
292 {
294  lesenseWarmupModeNormal = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
295 
297  lesenseWarmupModeACMP = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
298 
300  lesenseWarmupModeDAC = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
301 
303  lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM
304 } LESENSE_WarmupMode_TypeDef;
305 
306 
308 typedef enum
309 {
311  lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
312 
314  lesenseDecInputPRS = LESENSE_DECCTRL_INPUT_PRS
315 } LESENSE_DecInput_TypeDef;
316 
317 
319 typedef enum
320 {
322  lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,
323 
325  lesenseSampleModeACMP = LESENSE_CH_INTERACT_SAMPLE_ACMP
326 } LESENSE_ChSampleMode_TypeDef;
327 
328 
330 typedef enum
331 {
333  lesenseSetIntNone = LESENSE_CH_INTERACT_SETIF_NONE,
334 
336  lesenseSetIntLevel = LESENSE_CH_INTERACT_SETIF_LEVEL,
337 
339  lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
340 
342  lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE
343 } LESENSE_ChIntMode_TypeDef;
344 
345 
347 typedef enum
348 {
350  lesenseChPinExDis = LESENSE_CH_INTERACT_EXMODE_DISABLE,
351 
353  lesenseChPinExHigh = LESENSE_CH_INTERACT_EXMODE_HIGH,
354 
356  lesenseChPinExLow = LESENSE_CH_INTERACT_EXMODE_LOW,
357 
359  lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT
360 } LESENSE_ChPinExMode_TypeDef;
361 
362 
364 typedef enum
365 {
368  lesenseChPinIdleDis = _LESENSE_IDLECONF_CH0_DISABLE,
369 
372  lesenseChPinIdleHigh = _LESENSE_IDLECONF_CH0_HIGH,
373 
376  lesenseChPinIdleLow = _LESENSE_IDLECONF_CH0_LOW,
377 
380  lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,
381 
384  lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1
385 } LESENSE_ChPinIdleMode_TypeDef;
386 
387 
389 typedef enum
390 {
392  lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
393 
395  lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
396 } LESENSE_ChClk_TypeDef;
397 
398 
400 typedef enum
401 {
404  lesenseCompModeLess = LESENSE_CH_EVAL_COMP_LESS,
405 
408  lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE
409 } LESENSE_ChCompMode_TypeDef;
410 
411 
413 typedef enum
414 {
417  lesenseAltExPinIdleDis = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,
418 
421  lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,
422 
425  lesenseAltExPinIdleLow = _LESENSE_ALTEXCONF_IDLECONF0_LOW
426 } LESENSE_AltExPinIdle_TypeDef;
427 
428 
430 typedef enum
431 {
434  lesenseTransActNone = LESENSE_ST_TCONFA_PRSACT_NONE,
435 
437  lesenseTransActPRS0 = LESENSE_ST_TCONFA_PRSACT_PRS0,
438 
440  lesenseTransActPRS1 = LESENSE_ST_TCONFA_PRSACT_PRS1,
441 
443  lesenseTransActPRS01 = LESENSE_ST_TCONFA_PRSACT_PRS01,
444 
446  lesenseTransActPRS2 = LESENSE_ST_TCONFA_PRSACT_PRS2,
447 
449  lesenseTransActPRS02 = LESENSE_ST_TCONFA_PRSACT_PRS02,
450 
452  lesenseTransActPRS12 = LESENSE_ST_TCONFA_PRSACT_PRS12,
453 
455  lesenseTransActPRS012 = LESENSE_ST_TCONFA_PRSACT_PRS012,
456 
458  lesenseTransActUp = LESENSE_ST_TCONFA_PRSACT_UP,
459 
461  lesenseTransActDown = LESENSE_ST_TCONFA_PRSACT_DOWN,
462 
464  lesenseTransActUpAndPRS2 = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
465 
467  lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2
468 } LESENSE_StTransAct_TypeDef;
469 
470 
471 /*******************************************************************************
472  ******************************* STRUCTS ***********************************
473  ******************************************************************************/
474 
476 typedef struct
477 {
479  LESENSE_ScanMode_TypeDef scanStart;
480 
482  LESENSE_PRSSel_TypeDef prsSel;
483 
485  LESENSE_ScanConfSel_TypeDef scanConfSel;
486 
488  bool invACMP0;
489 
491  bool invACMP1;
492 
494  bool dualSample;
495 
498  bool storeScanRes;
499 
502  bool bufOverWr;
503 
505  LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
506 
508  LESENSE_DMAWakeUp_TypeDef wakeupOnDMA;
509 
511  LESENSE_BiasMode_TypeDef biasMode;
512 
514  bool debugRun;
515 } LESENSE_CoreCtrlDesc_TypeDef;
516 
518 #define LESENSE_CORECTRL_DESC_DEFAULT \
519 { \
520  lesenseScanStartPeriodic, /* Start new scan each time the period counter overflows. */ \
521  lesensePRSCh0, /* Default PRS channel is selected. */ \
522  lesenseScanConfDirMap, /* Direct mapping SCANCONF register usage strategy. */ \
523  false, /* Don't invert ACMP0 output. */ \
524  false, /* Don't invert ACMP1 output. */ \
525  false, /* Disable dual sampling. */ \
526  true, /* Store scan result after each scan. */ \
527  true, /* Overwrite result buffer register even if it is full. */ \
528  lesenseBufTrigHalf, /* Trigger interrupt and DMA request if result buffer is half full. */ \
529  lesenseDMAWakeUpDisable, /* Don't wake up on DMA from EM2. */ \
530  lesenseBiasModeDontTouch, /* Don't touch bias configuration. */ \
531  true /* Keep LESENSE running in debug mode. */ \
532 }
533 
534 
536 typedef struct
537 {
540  uint8_t startDelay;
541 } LESENSE_TimeCtrlDesc_TypeDef;
542 
544 #define LESENSE_TIMECTRL_DESC_DEFAULT \
545 { \
546  0U /* No sensor interaction delay. */ \
547 }
548 
549 
551 typedef struct
552 {
554  LESENSE_ControlDACData_TypeDef dacCh0Data;
555 
557  LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
558 
560  LESENSE_ControlDACOut_TypeDef dacCh0OutMode;
561 
563  LESENSE_ControlDACData_TypeDef dacCh1Data;
564 
566  LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
567 
569  LESENSE_ControlDACOut_TypeDef dacCh1OutMode;
570 
573  uint8_t dacPresc;
574 
577  LESENSE_DACRef_TypeDef dacRef;
578 
580  LESENSE_ControlACMP_TypeDef acmp0Mode;
581 
583  LESENSE_ControlACMP_TypeDef acmp1Mode;
584 
586  LESENSE_WarmupMode_TypeDef warmupMode;
587 } LESENSE_PerCtrlDesc_TypeDef;
588 
590 #define LESENSE_PERCTRL_DESC_DEFAULT \
591 { \
592  lesenseDACIfData, \
593  lesenseDACConvModeDisable, \
594  lesenseDACOutModeDisable, \
595  lesenseDACIfData, \
596  lesenseDACConvModeDisable, \
597  lesenseDACOutModeDisable, \
598  0U, \
599  lesenseDACRefVdd, \
600  lesenseACMPModeMuxThres, \
601  lesenseACMPModeMuxThres, \
602  lesenseWarmupModeKeepWarm, \
603 }
604 
605 
607 typedef struct
608 {
610  LESENSE_DecInput_TypeDef decInput;
611 
613  uint32_t initState;
614 
617  bool chkState;
618 
621  bool intMap;
622 
625  bool hystPRS0;
626 
629  bool hystPRS1;
630 
633  bool hystPRS2;
634 
637  bool hystIRQ;
638 
641  bool prsCount;
642 
644  LESENSE_PRSSel_TypeDef prsChSel0;
645 
647  LESENSE_PRSSel_TypeDef prsChSel1;
648 
650  LESENSE_PRSSel_TypeDef prsChSel2;
651 
653  LESENSE_PRSSel_TypeDef prsChSel3;
654 } LESENSE_DecCtrlDesc_TypeDef;
655 
657 #define LESENSE_DECCTRL_DESC_DEFAULT \
658 { \
659  lesenseDecInputSensorSt, \
660  0U, \
661  false, \
662  true, \
663  true, \
664  true, \
665  true, \
666  true, \
667  false, \
668  lesensePRSCh0, \
669  lesensePRSCh1, \
670  lesensePRSCh2, \
671  lesensePRSCh3, \
672 }
673 
674 
676 typedef struct
677 {
679  LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
680 
682  LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
683 
685  LESENSE_PerCtrlDesc_TypeDef perCtrl;
686 
688  LESENSE_DecCtrlDesc_TypeDef decCtrl;
689 } LESENSE_Init_TypeDef;
690 
692 #define LESENSE_INIT_DEFAULT \
693 { \
694  .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */ \
695  .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */ \
696  .perCtrl = LESENSE_PERCTRL_DESC_DEFAULT, /* Default peripheral control parameters. */ \
697  .decCtrl = LESENSE_DECCTRL_DESC_DEFAULT /* Default decoder control parameters. */ \
698 }
699 
700 
702 typedef struct
703 {
705  bool enaScanCh;
706 
708  bool enaPin;
709 
712  bool enaInt;
713 
716  LESENSE_ChPinExMode_TypeDef chPinExMode;
717 
719  LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
720 
722  bool useAltEx;
723 
726  bool shiftRes;
727 
729  bool invRes;
730 
733  bool storeCntRes;
734 
736  LESENSE_ChClk_TypeDef exClk;
737 
739  LESENSE_ChClk_TypeDef sampleClk;
740 
743  uint8_t exTime;
744 
747  uint8_t sampleDelay;
748 
751  uint8_t measDelay;
752 
762  uint16_t acmpThres;
763 
765  LESENSE_ChSampleMode_TypeDef sampleMode;
766 
768  LESENSE_ChIntMode_TypeDef intMode;
769 
772  uint16_t cntThres;
773 
775  LESENSE_ChCompMode_TypeDef compMode;
776 } LESENSE_ChDesc_TypeDef;
777 
778 
780 typedef struct
781 {
783  LESENSE_ChDesc_TypeDef Ch[16];
784 } LESENSE_ChAll_TypeDef;
785 
787 #define LESENSE_CH_CONF_DEFAULT \
788 { \
789  true, /* Enable scan channel. */ \
790  true, /* Enable the assigned pin on scan channel. */ \
791  true, /* Enable interrupts on channel. */ \
792  lesenseChPinExHigh, /* Channel pin is high during the excitation period. */ \
793  lesenseChPinIdleLow, /* Channel pin is low during the idle period. */ \
794  false, /* Don't use alternate excitation pins for excitation. */ \
795  false, /* Disabled to shift results from this channel to the decoder register. */ \
796  false, /* Disabled to invert the scan result bit. */ \
797  false, /* Disabled to store counter value in the result buffer. */ \
798  lesenseClkLF, /* Use the LF clock for excitation timing. */ \
799  lesenseClkLF, /* Use the LF clock for sample timing. */ \
800  0x03U, /* Excitation time is set to 3(+1) excitation clock cycles. */ \
801  0x09U, /* Sample delay is set to 9(+1) sample clock cycles. */ \
802  0x06U, /* Measure delay is set to 6 excitation clock cycles.*/ \
803  0x00U, /* ACMP threshold has been set to 0. */ \
804  lesenseSampleModeACMP, /* ACMP output will be used in comparison. */ \
805  lesenseSetIntNone, /* No interrupt is generated by the channel. */ \
806  0xFFU, /* Counter threshold has bee set to 0xFF. */ \
807  lesenseCompModeLess /* Compare mode has been set to trigger interrupt on "less". */ \
808 }
809 
811 #define LESENSE_SCAN_CONF_DEFAULT \
812 { \
813  { \
814  LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */ \
815  LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */ \
816  LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */ \
817  LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */ \
818  LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */ \
819  LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */ \
820  LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */ \
821  LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */ \
822  LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */ \
823  LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */ \
824  LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \
825  LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \
826  LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \
827  LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \
828  LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \
829  LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \
830  } \
831 }
832 
833 
835 typedef struct
836 {
839  bool enablePin;
840 
843  LESENSE_AltExPinIdle_TypeDef idleConf;
844 
852  bool alwaysEx;
853 } LESENSE_AltExDesc_TypeDef;
854 
855 
857 typedef struct
858 {
860  LESENSE_AltExMap_TypeDef altExMap;
861 
874  LESENSE_AltExDesc_TypeDef AltEx[16];
875 
876 } LESENSE_ConfAltEx_TypeDef;
877 
878 
880 #define LESENSE_ALTEX_CH_CONF_DEFAULT \
881 { \
882  true, /* Alternate excitation enabled.*/ \
883  lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \
884  false /* Excite only for corresponding channel. */ \
885 }
886 
888 #define LESENSE_ALTEX_CONF_DEFAULT \
889 { \
890  lesenseAltExMapACMP, \
891  { \
892  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */ \
893  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */ \
894  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */ \
895  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */ \
896  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */ \
897  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */ \
898  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */ \
899  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */ \
900  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */ \
901  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */ \
902  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
903  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
904  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
905  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
906  LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
907  LESENSE_ALTEX_CH_CONF_DEFAULT /* Alternate excitation channel 15. */ \
908  } \
909 }
910 
911 
913 typedef struct
914 {
917  uint8_t compVal;
918 
922  uint8_t compMask;
923 
926  uint8_t nextState;
927 
930  LESENSE_StTransAct_TypeDef prsAct;
931 
933  bool setInt;
934 } LESENSE_DecStCond_TypeDef;
935 
937 #define LESENSE_ST_CONF_DEFAULT \
938 { \
939  0x0FU, /* Compare value set to 0x0F. */ \
940  0x00U, /* All decoder inputs masked. */ \
941  0U, /* Next state is state 0. */ \
942  lesenseTransActNone, /* No PRS action performed on compare match. */ \
943  false /* No interrupt triggered on compare match. */ \
944 }
945 
946 
948 typedef struct
949 {
952  bool chainDesc;
953 
956  LESENSE_DecStCond_TypeDef confA;
957 
960  LESENSE_DecStCond_TypeDef confB;
961 } LESENSE_DecStDesc_TypeDef;
962 
963 
965 typedef struct
966 {
968  LESENSE_DecStDesc_TypeDef St[16];
969 } LESENSE_DecStAll_TypeDef;
970 
972 #define LESENSE_DECODER_CONF_DEFAULT \
973 { /* chain | Descriptor A | Descriptor B */ \
974  { \
975  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */ \
976  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */ \
977  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */ \
978  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */ \
979  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */ \
980  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */ \
981  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */ \
982  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */ \
983  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */ \
984  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */ \
985  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */ \
986  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */ \
987  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */ \
988  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */ \
989  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */ \
990  { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT } /* Decoder state 15. */ \
991  } \
992 }
993 
994 /*******************************************************************************
995  ***************************** PROTOTYPES **********************************
996  ******************************************************************************/
997 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset);
998 void LESENSE_Reset(void);
999 
1000 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq);
1001 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,
1002  bool const start);
1003 
1004 void LESENSE_StartDelaySet(uint8_t const startDelay);
1005 
1006 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
1007  LESENSE_ClkPresc_TypeDef const clkDiv);
1008 
1009 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll);
1010 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,
1011  uint32_t const chIdx);
1012 void LESENSE_ChannelEnable(uint8_t const chIdx,
1013  bool const enaScanCh,
1014  bool const enaPin);
1015 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);
1016 void LESENSE_ChannelTimingSet(uint8_t const chIdx,
1017  uint8_t const exTime,
1018  uint8_t const sampleDelay,
1019  uint8_t const measDelay);
1020 void LESENSE_ChannelThresSet(uint8_t const chIdx,
1021  uint16_t const acmpThres,
1022  uint16_t const cntThres);
1023 
1024 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);
1025 
1026 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll);
1027 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,
1028  uint32_t const decSt);
1029 void LESENSE_DecoderStateSet(uint32_t decSt);
1030 uint32_t LESENSE_DecoderStateGet(void);
1031 
1032 void LESENSE_ScanStart(void);
1033 void LESENSE_ScanStop(void);
1034 void LESENSE_DecoderStart(void);
1035 void LESENSE_ResultBufferClear(void);
1036 
1037 
1038 /***************************************************************************/
1046 __STATIC_INLINE void LESENSE_DecoderStop(void)
1047 {
1048  /* Stop the decoder */
1049  LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
1050 }
1051 
1052 
1053 /***************************************************************************/
1067 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)
1068 {
1069  return LESENSE->STATUS;
1070 }
1071 
1072 
1073 /***************************************************************************/
1093 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)
1094 {
1095  while (!(LESENSE->STATUS & flag))
1096  ;
1097 }
1098 
1099 
1100 /***************************************************************************/
1108 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)
1109 {
1110  return LESENSE->CURCH;
1111 }
1112 
1113 
1114 /***************************************************************************/
1125 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)
1126 {
1127  return LESENSE->SCANRES;
1128 }
1129 
1130 
1131 /***************************************************************************/
1144 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
1145 {
1146  return LESENSE->BUFDATA;
1147 }
1148 
1149 
1150 /***************************************************************************/
1165 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
1166 {
1167  /* Note: masking is needed to avoid over-indexing! */
1168  return LESENSE->BUF[idx & 0x0FU].DATA;
1169 }
1170 
1171 /***************************************************************************/
1179 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)
1180 {
1181  return LESENSE->SENSORSTATE;
1182 }
1183 
1184 
1185 /***************************************************************************/
1197 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
1198 {
1199  /* Power down LESENSE RAM */
1200  LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
1201 }
1202 
1203 
1204 /***************************************************************************/
1213 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
1214 {
1215  LESENSE->IFC = flags;
1216 }
1217 
1218 
1219 /***************************************************************************/
1228 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
1229 {
1230  LESENSE->IEN |= flags;
1231 }
1232 
1233 
1234 /***************************************************************************/
1243 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
1244 {
1245  LESENSE->IEN &= ~flags;
1246 }
1247 
1248 
1249 /***************************************************************************/
1258 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)
1259 {
1260  LESENSE->IFS = flags;
1261 }
1262 
1263 
1264 /***************************************************************************/
1275 __STATIC_INLINE uint32_t LESENSE_IntGet(void)
1276 {
1277  return LESENSE->IF;
1278 }
1279 
1280 
1281 /***************************************************************************/
1299 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
1300 {
1301  uint32_t tmp;
1302 
1303  /* Store LESENSE->IEN in temporary variable in order to define explicit order
1304  * of volatile accesses. */
1305  tmp = LESENSE->IEN;
1306 
1307  /* Bitwise AND of pending and enabled interrupts */
1308  return LESENSE->IF & tmp;
1309 }
1310 
1311 
1315 #ifdef __cplusplus
1316 }
1317 #endif
1318 
1319 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
1320 
1321 #endif /* __SILICON_LABS_EM_LESENSE_H__ */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.