em_lesense.h

Go to the documentation of this file.
00001 /***************************************************************************/
00034 #ifndef __SILICON_LABS_EM_LESENSE_H_
00035 #define __SILICON_LABS_EM_LESENSE_H_
00036 
00037 #include "em_device.h"
00038 
00039 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)
00040 #include <stdint.h>
00041 #include <stdbool.h>
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 
00048 /***************************************************************************/
00053 /***************************************************************************/
00064 /*******************************************************************************
00065  ********************************   ENUMS   ************************************
00066  ******************************************************************************/
00067 
00072 typedef enum
00073 {
00074   lesenseClkDiv_1   = 0, 
00075   lesenseClkDiv_2   = 1, 
00076   lesenseClkDiv_4   = 2, 
00077   lesenseClkDiv_8   = 3, 
00078   lesenseClkDiv_16  = 4, 
00079   lesenseClkDiv_32  = 5, 
00080   lesenseClkDiv_64  = 6, 
00081   lesenseClkDiv_128 = 7  
00082 } LESENSE_ClkPresc_TypeDef;
00083 
00084 
00086 typedef enum
00087 {
00089   lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,
00090 
00092   lesenseScanStartOneShot  = LESENSE_CTRL_SCANMODE_ONESHOT,
00093 
00095   lesenseScanStartPRS      = LESENSE_CTRL_SCANMODE_PRS
00096 } LESENSE_ScanMode_TypeDef;
00097 
00098 
00102 typedef enum
00103 {
00104   lesensePRSCh0     = 0, 
00105   lesensePRSCh1     = 1, 
00106   lesensePRSCh2     = 2, 
00107   lesensePRSCh3     = 3, 
00108 #if defined( LESENSE_CTRL_PRSSEL_PRSCH4 )
00109   lesensePRSCh4     = 4, 
00110 #endif
00111 #if defined( LESENSE_CTRL_PRSSEL_PRSCH5 )
00112   lesensePRSCh5     = 5, 
00113 #endif
00114 #if defined( LESENSE_CTRL_PRSSEL_PRSCH6 )
00115   lesensePRSCh6     = 6, 
00116 #endif
00117 #if defined( LESENSE_CTRL_PRSSEL_PRSCH7 )
00118   lesensePRSCh7     = 7,  
00119 #endif
00120 #if defined( LESENSE_CTRL_PRSSEL_PRSCH8 )
00121   lesensePRSCh8     = 8,  
00122 #endif
00123 #if defined( LESENSE_CTRL_PRSSEL_PRSCH9 )
00124   lesensePRSCh9     = 9,  
00125 #endif
00126 #if defined( LESENSE_CTRL_PRSSEL_PRSCH10 )
00127   lesensePRSCh10    = 10, 
00128 #endif
00129 #if defined( LESENSE_CTRL_PRSSEL_PRSCH11 )
00130   lesensePRSCh11    = 11, 
00131 #endif
00132 } LESENSE_PRSSel_TypeDef;
00133 
00134 
00136 typedef enum
00137 {
00139   lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
00140 
00142   lesenseAltExMapACMP  = _LESENSE_CTRL_ALTEXMAP_ACMP
00143 } LESENSE_AltExMap_TypeDef;
00144 
00145 
00147 typedef enum
00148 {
00150   lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
00151 
00153   lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL
00154 } LESENSE_BufTrigLevel_TypeDef;
00155 
00156 
00158 typedef enum
00159 {
00161   lesenseDMAWakeUpDisable  = LESENSE_CTRL_DMAWU_DISABLE,
00162 
00164   lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
00165 
00169   lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL
00170 } LESENSE_DMAWakeUp_TypeDef;
00171 
00172 
00174 typedef enum
00175 {
00177   lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
00178 
00180   lesenseBiasModeHighAcc   = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
00181 
00183   lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH
00184 } LESENSE_BiasMode_TypeDef;
00185 
00186 
00188 typedef enum
00189 {
00192   lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,
00193 
00196   lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,
00197 
00200   lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,
00201 
00204   lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
00205 } LESENSE_ScanConfSel_TypeDef;
00206 
00207 
00209 typedef enum
00210 {
00213   lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,
00214 
00217   lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES
00218 } LESENSE_ControlDACData_TypeDef;
00219 
00220 
00222 typedef enum
00223 {
00226   lesenseDACConvModeDisable    = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,
00227 
00230   lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,
00231 
00234   lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,
00235 
00238   lesenseDACConvModeSampleOff  = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF
00239 } LESENSE_ControlDACConv_TypeDef;
00240 
00241 
00243 typedef enum
00244 {
00247   lesenseDACOutModeDisable    = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,
00248 
00251   lesenseDACOutModePin        = _LESENSE_PERCTRL_DACCH0OUT_PIN,
00252 
00255   lesenseDACOutModeADCACMP    = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,
00256 
00259   lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP
00260 } LESENSE_ControlDACOut_TypeDef;
00261 
00262 
00264 typedef enum
00265 {
00267   lesenseDACRefVdd     = LESENSE_PERCTRL_DACREF_VDD,
00268 
00270   lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
00271 } LESENSE_DACRef_TypeDef;
00272 
00273 
00275 typedef enum
00276 {
00279   lesenseACMPModeDisable  = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,
00280 
00283   lesenseACMPModeMux      = _LESENSE_PERCTRL_ACMP0MODE_MUX,
00284 
00287   lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES
00288 } LESENSE_ControlACMP_TypeDef;
00289 
00290 
00292 typedef enum
00293 {
00295   lesenseWarmupModeNormal   = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
00296 
00298   lesenseWarmupModeACMP     = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
00299 
00301   lesenseWarmupModeDAC      = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
00302 
00304   lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM
00305 } LESENSE_WarmupMode_TypeDef;
00306 
00307 
00309 typedef enum
00310 {
00312   lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
00313 
00315   lesenseDecInputPRS      = LESENSE_DECCTRL_INPUT_PRS
00316 } LESENSE_DecInput_TypeDef;
00317 
00318 
00320 typedef enum
00321 {
00323   lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,
00324 
00326   lesenseSampleModeACMP    = LESENSE_CH_INTERACT_SAMPLE_ACMP
00327 } LESENSE_ChSampleMode_TypeDef;
00328 
00329 
00331 typedef enum
00332 {
00334   lesenseSetIntNone    = LESENSE_CH_INTERACT_SETIF_NONE,
00335 
00337   lesenseSetIntLevel   = LESENSE_CH_INTERACT_SETIF_LEVEL,
00338 
00340   lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
00341 
00343   lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE
00344 } LESENSE_ChIntMode_TypeDef;
00345 
00346 
00348 typedef enum
00349 {
00351   lesenseChPinExDis    = LESENSE_CH_INTERACT_EXMODE_DISABLE,
00352 
00354   lesenseChPinExHigh   = LESENSE_CH_INTERACT_EXMODE_HIGH,
00355 
00357   lesenseChPinExLow    = LESENSE_CH_INTERACT_EXMODE_LOW,
00358 
00360   lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT
00361 } LESENSE_ChPinExMode_TypeDef;
00362 
00363 
00365 typedef enum
00366 {
00369   lesenseChPinIdleDis    = _LESENSE_IDLECONF_CH0_DISABLE,
00370 
00373   lesenseChPinIdleHigh   = _LESENSE_IDLECONF_CH0_HIGH,
00374 
00377   lesenseChPinIdleLow    = _LESENSE_IDLECONF_CH0_LOW,
00378 
00381   lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,
00382 
00385   lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1
00386 } LESENSE_ChPinIdleMode_TypeDef;
00387 
00388 
00390 typedef enum
00391 {
00393   lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
00394 
00396   lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
00397 } LESENSE_ChClk_TypeDef;
00398 
00399 
00401 typedef enum
00402 {
00405   lesenseCompModeLess        = LESENSE_CH_EVAL_COMP_LESS,
00406 
00409   lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE
00410 } LESENSE_ChCompMode_TypeDef;
00411 
00412 
00414 typedef enum
00415 {
00418   lesenseAltExPinIdleDis  = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,
00419 
00422   lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,
00423 
00426   lesenseAltExPinIdleLow  = _LESENSE_ALTEXCONF_IDLECONF0_LOW
00427 } LESENSE_AltExPinIdle_TypeDef;
00428 
00429 
00431 typedef enum
00432 {
00435   lesenseTransActNone        = LESENSE_ST_TCONFA_PRSACT_NONE,
00436 
00438   lesenseTransActPRS0        = LESENSE_ST_TCONFA_PRSACT_PRS0,
00439 
00441   lesenseTransActPRS1        = LESENSE_ST_TCONFA_PRSACT_PRS1,
00442 
00444   lesenseTransActPRS01       = LESENSE_ST_TCONFA_PRSACT_PRS01,
00445 
00447   lesenseTransActPRS2        = LESENSE_ST_TCONFA_PRSACT_PRS2,
00448 
00450   lesenseTransActPRS02       = LESENSE_ST_TCONFA_PRSACT_PRS02,
00451 
00453   lesenseTransActPRS12       = LESENSE_ST_TCONFA_PRSACT_PRS12,
00454 
00456   lesenseTransActPRS012      = LESENSE_ST_TCONFA_PRSACT_PRS012,
00457 
00459   lesenseTransActUp          = LESENSE_ST_TCONFA_PRSACT_UP,
00460 
00462   lesenseTransActDown        = LESENSE_ST_TCONFA_PRSACT_DOWN,
00463 
00465   lesenseTransActUpAndPRS2   = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
00466 
00468   lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2
00469 } LESENSE_StTransAct_TypeDef;
00470 
00471 
00472 /*******************************************************************************
00473  *******************************   STRUCTS   ***********************************
00474  ******************************************************************************/
00475 
00477 typedef struct
00478 {
00480   LESENSE_ScanMode_TypeDef     scanStart;
00481 
00483   LESENSE_PRSSel_TypeDef       prsSel;
00484 
00486   LESENSE_ScanConfSel_TypeDef  scanConfSel;
00487 
00489   bool                         invACMP0;
00490 
00492   bool                         invACMP1;
00493 
00495   bool                         dualSample;
00496 
00499   bool                         storeScanRes;
00500 
00503   bool                         bufOverWr;
00504 
00506   LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
00507 
00509   LESENSE_DMAWakeUp_TypeDef    wakeupOnDMA;
00510 
00512   LESENSE_BiasMode_TypeDef     biasMode;
00513 
00515   bool                         debugRun;
00516 } LESENSE_CoreCtrlDesc_TypeDef;
00517 
00519 #define LESENSE_CORECTRL_DESC_DEFAULT                                                                 \
00520   {                                                                                                   \
00521     lesenseScanStartPeriodic,  /* Start new scan each time the period counter overflows. */           \
00522     lesensePRSCh0,             /* Default PRS channel is selected. */                                 \
00523     lesenseScanConfDirMap,     /* Direct mapping SCANCONF register usage strategy. */                 \
00524     false,                     /* Don't invert ACMP0 output. */                                       \
00525     false,                     /* Don't invert ACMP1 output. */                                       \
00526     false,                     /* Disable dual sampling. */                                           \
00527     true,                      /* Store scan result after each scan. */                               \
00528     true,                      /* Overwrite result buffer register even if it is full. */             \
00529     lesenseBufTrigHalf,        /* Trigger interrupt and DMA request if result buffer is half full. */ \
00530     lesenseDMAWakeUpDisable,   /* Don't wake up on DMA from EM2. */                                   \
00531     lesenseBiasModeDontTouch,  /* Don't touch bias configuration. */                                  \
00532     true                       /* Keep LESENSE running in debug mode. */                              \
00533   }
00534 
00535 
00537 typedef struct
00538 {
00541   uint8_t startDelay;
00542 } LESENSE_TimeCtrlDesc_TypeDef;
00543 
00545 #define LESENSE_TIMECTRL_DESC_DEFAULT     \
00546   {                                       \
00547     0U /* No sensor interaction delay. */ \
00548   }
00549 
00550 
00552 typedef struct
00553 {
00555   LESENSE_ControlDACData_TypeDef dacCh0Data;
00556 
00558   LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
00559 
00561   LESENSE_ControlDACOut_TypeDef  dacCh0OutMode;
00562 
00564   LESENSE_ControlDACData_TypeDef dacCh1Data;
00565 
00567   LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
00568 
00570   LESENSE_ControlDACOut_TypeDef  dacCh1OutMode;
00571 
00574   uint8_t                        dacPresc;
00575 
00578   LESENSE_DACRef_TypeDef         dacRef;
00579 
00581   LESENSE_ControlACMP_TypeDef    acmp0Mode;
00582 
00584   LESENSE_ControlACMP_TypeDef    acmp1Mode;
00585 
00587   LESENSE_WarmupMode_TypeDef     warmupMode;
00588 } LESENSE_PerCtrlDesc_TypeDef;
00589 
00591 #define LESENSE_PERCTRL_DESC_DEFAULT \
00592   {                                  \
00593     lesenseDACIfData,            \
00594     lesenseDACConvModeDisable,   \
00595     lesenseDACOutModeDisable,    \
00596     lesenseDACIfData,            \
00597     lesenseDACConvModeDisable,   \
00598     lesenseDACOutModeDisable,    \
00599     0U,                          \
00600     lesenseDACRefVdd,            \
00601     lesenseACMPModeMuxThres,     \
00602     lesenseACMPModeMuxThres,     \
00603     lesenseWarmupModeKeepWarm,   \
00604   }
00605 
00606 
00608 typedef struct
00609 {
00611   LESENSE_DecInput_TypeDef decInput;
00612 
00614   uint32_t                 initState;
00615 
00618   bool                     chkState;
00619 
00622   bool                     intMap;
00623 
00626   bool                     hystPRS0;
00627 
00630   bool                     hystPRS1;
00631 
00634   bool                     hystPRS2;
00635 
00638   bool                     hystIRQ;
00639 
00642   bool                     prsCount;
00643 
00645   LESENSE_PRSSel_TypeDef   prsChSel0;
00646 
00648   LESENSE_PRSSel_TypeDef   prsChSel1;
00649 
00651   LESENSE_PRSSel_TypeDef   prsChSel2;
00652 
00654   LESENSE_PRSSel_TypeDef   prsChSel3;
00655 } LESENSE_DecCtrlDesc_TypeDef;
00656 
00658 #define LESENSE_DECCTRL_DESC_DEFAULT \
00659   {                                  \
00660     lesenseDecInputSensorSt,     \
00661     0U,                          \
00662     false,                       \
00663     true,                        \
00664     true,                        \
00665     true,                        \
00666     true,                        \
00667     true,                        \
00668     false,                       \
00669     lesensePRSCh0,               \
00670     lesensePRSCh1,               \
00671     lesensePRSCh2,               \
00672     lesensePRSCh3,               \
00673   }
00674 
00675 
00677 typedef struct
00678 {
00680   LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
00681 
00683   LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
00684 
00686   LESENSE_PerCtrlDesc_TypeDef  perCtrl;
00687 
00689   LESENSE_DecCtrlDesc_TypeDef  decCtrl;
00690 } LESENSE_Init_TypeDef;
00691 
00693 #define LESENSE_INIT_DEFAULT                        \
00694   {                                                 \
00695     .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */ \
00696     .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */ \
00697     .perCtrl  = LESENSE_PERCTRL_DESC_DEFAULT,  /* Default peripheral control parameters. */ \
00698     .decCtrl  = LESENSE_DECCTRL_DESC_DEFAULT   /* Default decoder control parameters. */ \
00699   }
00700 
00701 
00703 typedef struct
00704 {
00706   bool                          enaScanCh;
00707 
00709   bool                          enaPin;
00710 
00713   bool                          enaInt;
00714 
00717   LESENSE_ChPinExMode_TypeDef   chPinExMode;
00718 
00720   LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
00721 
00723   bool                          useAltEx;
00724 
00727   bool                          shiftRes;
00728 
00730   bool                          invRes;
00731 
00734   bool                          storeCntRes;
00735 
00737   LESENSE_ChClk_TypeDef         exClk;
00738 
00740   LESENSE_ChClk_TypeDef         sampleClk;
00741 
00744   uint8_t                       exTime;
00745 
00748   uint8_t                       sampleDelay;
00749 
00752   uint8_t                       measDelay;
00753 
00763   uint16_t                     acmpThres;
00764 
00766   LESENSE_ChSampleMode_TypeDef sampleMode;
00767 
00769   LESENSE_ChIntMode_TypeDef    intMode;
00770 
00773   uint16_t                     cntThres;
00774 
00776   LESENSE_ChCompMode_TypeDef   compMode;
00777 } LESENSE_ChDesc_TypeDef;
00778 
00779 
00781 typedef struct
00782 {
00784   LESENSE_ChDesc_TypeDef Ch[16];
00785 } LESENSE_ChAll_TypeDef;
00786 
00788 #define LESENSE_CH_CONF_DEFAULT                                                                       \
00789   {                                                                                                   \
00790     true,                  /* Enable scan channel. */                                                 \
00791     true,                  /* Enable the assigned pin on scan channel. */                             \
00792     true,                  /* Enable interrupts on channel. */                                        \
00793     lesenseChPinExHigh,    /* Channel pin is high during the excitation period. */                    \
00794     lesenseChPinIdleLow,   /* Channel pin is low during the idle period. */                           \
00795     false,                 /* Don't use alternate excitation pins for excitation. */                  \
00796     false,                 /* Disabled to shift results from this channel to the decoder register. */ \
00797     false,                 /* Disabled to invert the scan result bit. */                              \
00798     false,                 /* Disabled to store counter value in the result buffer. */                \
00799     lesenseClkLF,          /* Use the LF clock for excitation timing. */                              \
00800     lesenseClkLF,          /* Use the LF clock for sample timing. */                                  \
00801     0x03U,                 /* Excitation time is set to 3(+1) excitation clock cycles. */             \
00802     0x09U,                 /* Sample delay is set to 9(+1) sample clock cycles. */                    \
00803     0x06U,                 /* Measure delay is set to 6 excitation clock cycles.*/                    \
00804     0x00U,                 /* ACMP threshold has been set to 0. */                                    \
00805     lesenseSampleModeACMP, /* ACMP output will be used in comparison. */                              \
00806     lesenseSetIntNone,     /* No interrupt is generated by the channel. */                            \
00807     0xFFU,                 /* Counter threshold has bee set to 0xFF. */                               \
00808     lesenseCompModeLess    /* Compare mode has been set to trigger interrupt on "less". */            \
00809   }
00810 
00812 #define LESENSE_SCAN_CONF_DEFAULT                     \
00813   {                                                   \
00814     {                                                 \
00815       LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */  \
00816       LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */  \
00817       LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */  \
00818       LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */  \
00819       LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */  \
00820       LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */  \
00821       LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */  \
00822       LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */  \
00823       LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */  \
00824       LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */  \
00825       LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \
00826       LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \
00827       LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \
00828       LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \
00829       LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \
00830       LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \
00831     }                                                 \
00832   }
00833 
00834 
00836 typedef struct
00837 {
00840   bool                         enablePin;
00841 
00844   LESENSE_AltExPinIdle_TypeDef idleConf;
00845 
00853   bool                         alwaysEx;
00854 } LESENSE_AltExDesc_TypeDef;
00855 
00856 
00858 typedef struct
00859 {
00861   LESENSE_AltExMap_TypeDef  altExMap;
00862 
00875   LESENSE_AltExDesc_TypeDef AltEx[16];
00876 
00877 } LESENSE_ConfAltEx_TypeDef;
00878 
00879 
00881 #define LESENSE_ALTEX_CH_CONF_DEFAULT                                          \
00882   {                                                                            \
00883     true,                  /* Alternate excitation enabled.*/                  \
00884     lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \
00885     false                  /* Excite only for corresponding channel. */        \
00886   }
00887 
00889 #define LESENSE_ALTEX_CONF_DEFAULT                                         \
00890   {                                                                        \
00891     lesenseAltExMapACMP,                                                   \
00892     {                                                                      \
00893       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */ \
00894       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */ \
00895       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */ \
00896       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */ \
00897       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */ \
00898       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */ \
00899       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */ \
00900       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */ \
00901       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */ \
00902       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */ \
00903       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
00904       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
00905       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
00906       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
00907       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
00908       LESENSE_ALTEX_CH_CONF_DEFAULT  /* Alternate excitation channel 15. */ \
00909     }                                                                      \
00910   }
00911 
00912 
00914 typedef struct
00915 {
00918   uint8_t                    compVal;
00919 
00923   uint8_t                    compMask;
00924 
00927   uint8_t                    nextState;
00928 
00931   LESENSE_StTransAct_TypeDef prsAct;
00932 
00934   bool                       setInt;
00935 } LESENSE_DecStCond_TypeDef;
00936 
00938 #define LESENSE_ST_CONF_DEFAULT                                          \
00939   {                                                                      \
00940     0x0FU,               /* Compare value set to 0x0F. */                \
00941     0x00U,               /* All decoder inputs masked. */                \
00942     0U,                  /* Next state is state 0. */                    \
00943     lesenseTransActNone, /* No PRS action performed on compare match. */ \
00944     false                /* No interrupt triggered on compare match. */  \
00945   }
00946 
00947 
00949 typedef struct
00950 {
00953   bool                      chainDesc;
00954 
00957   LESENSE_DecStCond_TypeDef confA;
00958 
00961   LESENSE_DecStCond_TypeDef confB;
00962 } LESENSE_DecStDesc_TypeDef;
00963 
00964 
00966 typedef struct
00967 {
00969   LESENSE_DecStDesc_TypeDef St[16];
00970 } LESENSE_DecStAll_TypeDef;
00971 
00973 #define LESENSE_DECODER_CONF_DEFAULT                                                                                 \
00974   {  /* chain |   Descriptor A         |   Descriptor B   */ \
00975     {                                                                                                                \
00976       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */                            \
00977       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */                            \
00978       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */                            \
00979       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */                            \
00980       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */                            \
00981       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */                            \
00982       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */                            \
00983       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */                            \
00984       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */                            \
00985       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */                            \
00986       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */                           \
00987       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */                           \
00988       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */                           \
00989       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */                           \
00990       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */                           \
00991       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT } /* Decoder state 15. */                            \
00992     }                                                                                                                \
00993   }
00994 
00995 /*******************************************************************************
00996  *****************************   PROTOTYPES   **********************************
00997  ******************************************************************************/
00998 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset);
00999 void LESENSE_Reset(void);
01000 
01001 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq);
01002 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,
01003                          bool const start);
01004 
01005 void LESENSE_StartDelaySet(uint8_t const startDelay);
01006 
01007 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
01008                        LESENSE_ClkPresc_TypeDef const clkDiv);
01009 
01010 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll);
01011 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,
01012                            uint32_t const chIdx);
01013 void LESENSE_ChannelEnable(uint8_t const chIdx,
01014                            bool const enaScanCh,
01015                            bool const enaPin);
01016 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);
01017 void LESENSE_ChannelTimingSet(uint8_t const chIdx,
01018                               uint8_t const exTime,
01019                               uint8_t const sampleDelay,
01020                               uint8_t const measDelay);
01021 void LESENSE_ChannelThresSet(uint8_t const chIdx,
01022                              uint16_t const acmpThres,
01023                              uint16_t const cntThres);
01024 
01025 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);
01026 
01027 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll);
01028 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,
01029                                 uint32_t const decSt);
01030 void LESENSE_DecoderStateSet(uint32_t decSt);
01031 uint32_t LESENSE_DecoderStateGet(void);
01032 
01033 void LESENSE_ScanStart(void);
01034 void LESENSE_ScanStop(void);
01035 void LESENSE_DecoderStart(void);
01036 void LESENSE_ResultBufferClear(void);
01037 
01038 __STATIC_INLINE void LESENSE_DecoderStop(void);
01039 __STATIC_INLINE uint32_t LESENSE_StatusGet(void);
01040 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag);
01041 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void);
01042 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void);
01043 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void);
01044 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx);
01045 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void);
01046 __STATIC_INLINE void LESENSE_RAMPowerDown(void);
01047 
01048 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags);
01049 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags);
01050 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags);
01051 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags);
01052 __STATIC_INLINE uint32_t LESENSE_IntGet(void);
01053 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void);
01054 
01055 
01056 /***************************************************************************/
01064 __STATIC_INLINE void LESENSE_DecoderStop(void)
01065 {
01066   /* Stop the decoder */
01067   LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
01068 }
01069 
01070 
01071 /***************************************************************************/
01085 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)
01086 {
01087   return LESENSE->STATUS;
01088 }
01089 
01090 
01091 /***************************************************************************/
01111 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)
01112 {
01113   while (!(LESENSE->STATUS & flag))
01114     ;
01115 }
01116 
01117 
01118 /***************************************************************************/
01126 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)
01127 {
01128   return LESENSE->CURCH;
01129 }
01130 
01131 
01132 /***************************************************************************/
01143 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)
01144 {
01145   return LESENSE->SCANRES;
01146 }
01147 
01148 
01149 /***************************************************************************/
01162 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
01163 {
01164   return LESENSE->BUFDATA;
01165 }
01166 
01167 
01168 /***************************************************************************/
01183 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
01184 {
01185   /* Note: masking is needed to avoid over-indexing! */
01186   return LESENSE->BUF[idx & 0x0FU].DATA;
01187 }
01188 
01189 /***************************************************************************/
01197 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)
01198 {
01199   return LESENSE->SENSORSTATE;
01200 }
01201 
01202 
01203 /***************************************************************************/
01215 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
01216 {
01217   /* Power down LESENSE RAM */
01218   LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
01219 }
01220 
01221 
01222 /***************************************************************************/
01231 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
01232 {
01233   LESENSE->IFC = flags;
01234 }
01235 
01236 
01237 /***************************************************************************/
01246 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
01247 {
01248   LESENSE->IEN |= flags;
01249 }
01250 
01251 
01252 /***************************************************************************/
01261 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
01262 {
01263   LESENSE->IEN &= ~(flags);
01264 }
01265 
01266 
01267 /***************************************************************************/
01276 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)
01277 {
01278   LESENSE->IFS = flags;
01279 }
01280 
01281 
01282 /***************************************************************************/
01293 __STATIC_INLINE uint32_t LESENSE_IntGet(void)
01294 {
01295   return LESENSE->IF;
01296 }
01297 
01298 
01299 /***************************************************************************/
01317 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
01318 {
01319   uint32_t tmp;
01320 
01321   /* Store LESENSE->IEN in temporary variable in order to define explicit order
01322    * of volatile accesses. */
01323   tmp = LESENSE->IEN;
01324 
01325   /* Bitwise AND of pending and enabled interrupts */
01326   return LESENSE->IF & tmp;
01327 }
01328 
01329 
01333 #ifdef __cplusplus
01334 }
01335 #endif
01336 
01337 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
01338 
01339 #endif /* __SILICON_LABS_EM_LESENSE_H_ */