em_lesense.h

Go to the documentation of this file.
00001 /***************************************************************************/
00034 #ifndef __EM_LESENSE_H
00035 #define __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   lesensePRSCh4     = 4, 
00109   lesensePRSCh5     = 5, 
00110   lesensePRSCh6     = 6, 
00111   lesensePRSCh7     = 7  
00112 } LESENSE_PRSSel_TypeDef;
00113 
00114 
00116 typedef enum
00117 {
00119   lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
00120 
00122   lesenseAltExMapACMP  = _LESENSE_CTRL_ALTEXMAP_ACMP
00123 } LESENSE_AltExMap_TypeDef;
00124 
00125 
00127 typedef enum
00128 {
00130   lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
00131 
00133   lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL
00134 } LESENSE_BufTrigLevel_TypeDef;
00135 
00136 
00138 typedef enum
00139 {
00141   lesenseDMAWakeUpDisable  = LESENSE_CTRL_DMAWU_DISABLE,
00142 
00144   lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
00145 
00149   lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL
00150 } LESENSE_DMAWakeUp_TypeDef;
00151 
00152 
00154 typedef enum
00155 {
00157   lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
00158 
00160   lesenseBiasModeHighAcc   = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
00161 
00163   lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH
00164 } LESENSE_BiasMode_TypeDef;
00165 
00166 
00168 typedef enum
00169 {
00172   lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,
00173 
00176   lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,
00177 
00180   lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,
00181 
00184   lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
00185 } LESENSE_ScanConfSel_TypeDef;
00186 
00187 
00189 typedef enum
00190 {
00193   lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,
00194 
00197   lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES
00198 } LESENSE_ControlDACData_TypeDef;
00199 
00200 
00202 typedef enum
00203 {
00206   lesenseDACConvModeDisable    = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,
00207 
00210   lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,
00211 
00214   lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,
00215 
00218   lesenseDACConvModeSampleOff  = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF
00219 } LESENSE_ControlDACConv_TypeDef;
00220 
00221 
00223 typedef enum
00224 {
00227   lesenseDACOutModeDisable    = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,
00228 
00231   lesenseDACOutModePin        = _LESENSE_PERCTRL_DACCH0OUT_PIN,
00232 
00235   lesenseDACOutModeADCACMP    = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,
00236 
00239   lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP
00240 } LESENSE_ControlDACOut_TypeDef;
00241 
00242 
00244 typedef enum
00245 {
00247   lesenseDACRefVdd     = LESENSE_PERCTRL_DACREF_VDD,
00248 
00250   lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
00251 } LESENSE_DACRef_TypeDef;
00252 
00253 
00255 typedef enum
00256 {
00259   lesenseACMPModeDisable  = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,
00260 
00263   lesenseACMPModeMux      = _LESENSE_PERCTRL_ACMP0MODE_MUX,
00264 
00267   lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES
00268 } LESENSE_ControlACMP_TypeDef;
00269 
00270 
00272 typedef enum
00273 {
00275   lesenseWarmupModeNormal   = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
00276 
00278   lesenseWarmupModeACMP     = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
00279 
00281   lesenseWarmupModeDAC      = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
00282 
00284   lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM
00285 } LESENSE_WarmupMode_TypeDef;
00286 
00287 
00289 typedef enum
00290 {
00292   lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
00293 
00295   lesenseDecInputPRS      = LESENSE_DECCTRL_INPUT_PRS
00296 } LESENSE_DecInput_TypeDef;
00297 
00298 
00300 typedef enum
00301 {
00303   lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,
00304 
00306   lesenseSampleModeACMP    = LESENSE_CH_INTERACT_SAMPLE_ACMP
00307 } LESENSE_ChSampleMode_TypeDef;
00308 
00309 
00311 typedef enum
00312 {
00314   lesenseSetIntNone    = LESENSE_CH_INTERACT_SETIF_NONE,
00315 
00317   lesenseSetIntLevel   = LESENSE_CH_INTERACT_SETIF_LEVEL,
00318 
00320   lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
00321 
00323   lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE
00324 } LESENSE_ChIntMode_TypeDef;
00325 
00326 
00328 typedef enum
00329 {
00331   lesenseChPinExDis    = LESENSE_CH_INTERACT_EXMODE_DISABLE,
00332 
00334   lesenseChPinExHigh   = LESENSE_CH_INTERACT_EXMODE_HIGH,
00335 
00337   lesenseChPinExLow    = LESENSE_CH_INTERACT_EXMODE_LOW,
00338 
00340   lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT
00341 } LESENSE_ChPinExMode_TypeDef;
00342 
00343 
00345 typedef enum
00346 {
00349   lesenseChPinIdleDis    = _LESENSE_IDLECONF_CH0_DISABLE,
00350 
00353   lesenseChPinIdleHigh   = _LESENSE_IDLECONF_CH0_HIGH,
00354 
00357   lesenseChPinIdleLow    = _LESENSE_IDLECONF_CH0_LOW,
00358 
00361   lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,
00362 
00365   lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1
00366 } LESENSE_ChPinIdleMode_TypeDef;
00367 
00368 
00370 typedef enum
00371 {
00373   lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
00374 
00376   lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
00377 } LESENSE_ChClk_TypeDef;
00378 
00379 
00381 typedef enum
00382 {
00385   lesenseCompModeLess        = LESENSE_CH_EVAL_COMP_LESS,
00386 
00389   lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE
00390 } LESENSE_ChCompMode_TypeDef;
00391 
00392 
00394 typedef enum
00395 {
00398   lesenseAltExPinIdleDis  = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,
00399 
00402   lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,
00403 
00406   lesenseAltExPinIdleLow  = _LESENSE_ALTEXCONF_IDLECONF0_LOW
00407 } LESENSE_AltExPinIdle_TypeDef;
00408 
00409 
00411 typedef enum
00412 {
00415   lesenseTransActNone        = LESENSE_ST_TCONFA_PRSACT_NONE,
00416 
00418   lesenseTransActPRS0        = LESENSE_ST_TCONFA_PRSACT_PRS0,
00419 
00421   lesenseTransActPRS1        = LESENSE_ST_TCONFA_PRSACT_PRS1,
00422 
00424   lesenseTransActPRS01       = LESENSE_ST_TCONFA_PRSACT_PRS01,
00425 
00427   lesenseTransActPRS2        = LESENSE_ST_TCONFA_PRSACT_PRS2,
00428 
00430   lesenseTransActPRS02       = LESENSE_ST_TCONFA_PRSACT_PRS02,
00431 
00433   lesenseTransActPRS12       = LESENSE_ST_TCONFA_PRSACT_PRS12,
00434 
00436   lesenseTransActPRS012      = LESENSE_ST_TCONFA_PRSACT_PRS012,
00437 
00439   lesenseTransActUp          = LESENSE_ST_TCONFA_PRSACT_UP,
00440 
00442   lesenseTransActDown        = LESENSE_ST_TCONFA_PRSACT_DOWN,
00443 
00445   lesenseTransActUpAndPRS2   = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
00446 
00448   lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2
00449 } LESENSE_StTransAct_TypeDef;
00450 
00451 
00452 /*******************************************************************************
00453  *******************************   STRUCTS   ***********************************
00454  ******************************************************************************/
00455 
00457 typedef struct
00458 {
00460   LESENSE_ScanMode_TypeDef     scanStart;
00461 
00463   LESENSE_PRSSel_TypeDef       prsSel;
00464 
00466   LESENSE_ScanConfSel_TypeDef  scanConfSel;
00467 
00469   bool                         invACMP0;
00470 
00472   bool                         invACMP1;
00473 
00475   bool                         dualSample;
00476 
00479   bool                         storeScanRes;
00480 
00483   bool                         bufOverWr;
00484 
00486   LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
00487 
00489   LESENSE_DMAWakeUp_TypeDef    wakeupOnDMA;
00490 
00492   LESENSE_BiasMode_TypeDef     biasMode;
00493 
00495   bool                         debugRun;
00496 } LESENSE_CoreCtrlDesc_TypeDef;
00497 
00499 #define LESENSE_CORECTRL_DESC_DEFAULT                                                                 \
00500   {                                                                                                   \
00501     lesenseScanStartPeriodic,  /* Start new scan each time the period counter overflows. */           \
00502     lesensePRSCh0,             /* Default PRS channel is selected. */                                 \
00503     lesenseScanConfDirMap,     /* Direct mapping SCANCONF register usage strategy. */                 \
00504     false,                     /* Don't invert ACMP0 output. */                                       \
00505     false,                     /* Don't invert ACMP1 output. */                                       \
00506     false,                     /* Disable dual sampling. */                                           \
00507     true,                      /* Store scan result after each scan. */                               \
00508     true,                      /* Overwrite result buffer register even if it is full. */             \
00509     lesenseBufTrigHalf,        /* Trigger interrupt and DMA request if result buffer is half full. */ \
00510     lesenseDMAWakeUpDisable,   /* Don't wake up on DMA from EM2. */                                   \
00511     lesenseBiasModeDontTouch,  /* Don't touch bias configuration. */                                  \
00512     true                       /* Keep LESENSE running in debug mode. */                              \
00513   }
00514 
00515 
00517 typedef struct
00518 {
00521   uint8_t startDelay;
00522 } LESENSE_TimeCtrlDesc_TypeDef;
00523 
00525 #define LESENSE_TIMECTRL_DESC_DEFAULT     \
00526   {                                       \
00527     0U /* No sensor interaction delay. */ \
00528   }
00529 
00530 
00532 typedef struct
00533 {
00535   LESENSE_ControlDACData_TypeDef dacCh0Data;
00536 
00538   LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
00539 
00541   LESENSE_ControlDACOut_TypeDef  dacCh0OutMode;
00542 
00544   LESENSE_ControlDACData_TypeDef dacCh1Data;
00545 
00547   LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
00548 
00550   LESENSE_ControlDACOut_TypeDef  dacCh1OutMode;
00551 
00554   uint8_t                        dacPresc;
00555 
00558   LESENSE_DACRef_TypeDef         dacRef;
00559 
00561   LESENSE_ControlACMP_TypeDef    acmp0Mode;
00562 
00564   LESENSE_ControlACMP_TypeDef    acmp1Mode;
00565 
00567   LESENSE_WarmupMode_TypeDef     warmupMode;
00568 } LESENSE_PerCtrlDesc_TypeDef;
00569 
00571 #define LESENSE_PERCTRL_DESC_DEFAULT \
00572   {                                  \
00573     lesenseDACIfData,            \
00574     lesenseDACConvModeDisable,   \
00575     lesenseDACOutModeDisable,    \
00576     lesenseDACIfData,            \
00577     lesenseDACConvModeDisable,   \
00578     lesenseDACOutModeDisable,    \
00579     0U,                          \
00580     lesenseDACRefVdd,            \
00581     lesenseACMPModeMuxThres,     \
00582     lesenseACMPModeMuxThres,     \
00583     lesenseWarmupModeKeepWarm,   \
00584   }
00585 
00586 
00588 typedef struct
00589 {
00591   LESENSE_DecInput_TypeDef decInput;
00592 
00594   uint32_t                 initState;
00595 
00598   bool                     chkState;
00599 
00602   bool                     intMap;
00603 
00606   bool                     hystPRS0;
00607 
00610   bool                     hystPRS1;
00611 
00614   bool                     hystPRS2;
00615 
00618   bool                     hystIRQ;
00619 
00622   bool                     prsCount;
00623 
00625   LESENSE_PRSSel_TypeDef   prsChSel0;
00626 
00628   LESENSE_PRSSel_TypeDef   prsChSel1;
00629 
00631   LESENSE_PRSSel_TypeDef   prsChSel2;
00632 
00634   LESENSE_PRSSel_TypeDef   prsChSel3;
00635 } LESENSE_DecCtrlDesc_TypeDef;
00636 
00638 #define LESENSE_DECCTRL_DESC_DEFAULT \
00639   {                                  \
00640     lesenseDecInputSensorSt,     \
00641     0U,                          \
00642     false,                       \
00643     true,                        \
00644     true,                        \
00645     true,                        \
00646     true,                        \
00647     true,                        \
00648     false,                       \
00649     lesensePRSCh0,               \
00650     lesensePRSCh1,               \
00651     lesensePRSCh2,               \
00652     lesensePRSCh3,               \
00653   }
00654 
00655 
00657 typedef struct
00658 {
00660   LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
00661 
00663   LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
00664 
00666   LESENSE_PerCtrlDesc_TypeDef  perCtrl;
00667 
00669   LESENSE_DecCtrlDesc_TypeDef  decCtrl;
00670 } LESENSE_Init_TypeDef;
00671 
00673 #define LESENSE_INIT_DEFAULT                        \
00674   {                                                 \
00675     .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */ \
00676     .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */ \
00677     .perCtrl  = LESENSE_PERCTRL_DESC_DEFAULT,  /* Default peripheral control parameters. */ \
00678     .decCtrl  = LESENSE_DECCTRL_DESC_DEFAULT   /* Default decoder control parameters. */ \
00679   }
00680 
00681 
00683 typedef struct
00684 {
00686   bool                          enaScanCh;
00687 
00689   bool                          enaPin;
00690 
00693   bool                          enaInt;
00694 
00697   LESENSE_ChPinExMode_TypeDef   chPinExMode;
00698 
00700   LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
00701 
00703   bool                          useAltEx;
00704 
00707   bool                          shiftRes;
00708 
00710   bool                          invRes;
00711 
00714   bool                          storeCntRes;
00715 
00717   LESENSE_ChClk_TypeDef         exClk;
00718 
00720   LESENSE_ChClk_TypeDef         sampleClk;
00721 
00724   uint8_t                       exTime;
00725 
00728   uint8_t                       sampleDelay;
00729 
00732   uint8_t                       measDelay;
00733 
00743   uint16_t                     acmpThres;
00744 
00746   LESENSE_ChSampleMode_TypeDef sampleMode;
00747 
00749   LESENSE_ChIntMode_TypeDef    intMode;
00750 
00753   uint16_t                     cntThres;
00754 
00756   LESENSE_ChCompMode_TypeDef   compMode;
00757 } LESENSE_ChDesc_TypeDef;
00758 
00759 
00761 typedef struct
00762 {
00764   LESENSE_ChDesc_TypeDef Ch[16];
00765 } LESENSE_ChAll_TypeDef;
00766 
00768 #define LESENSE_CH_CONF_DEFAULT                                                                       \
00769   {                                                                                                   \
00770     true,                  /* Enable scan channel. */                                                 \
00771     true,                  /* Enable the assigned pin on scan channel. */                             \
00772     true,                  /* Enable interrupts on channel. */                                        \
00773     lesenseChPinExHigh,    /* Channel pin is high during the excitation period. */                    \
00774     lesenseChPinIdleLow,   /* Channel pin is low during the idle period. */                           \
00775     false,                 /* Don't use alternate excitation pins for excitation. */                  \
00776     false,                 /* Disabled to shift results from this channel to the decoder register. */ \
00777     false,                 /* Disabled to invert the scan result bit. */                              \
00778     false,                 /* Disabled to store counter value in the result buffer. */                \
00779     lesenseClkLF,          /* Use the LF clock for excitation timing. */                              \
00780     lesenseClkLF,          /* Use the LF clock for sample timing. */                                  \
00781     0x03U,                 /* Excitation time is set to 3(+1) excitation clock cycles. */             \
00782     0x09U,                 /* Sample delay is set to 9(+1) sample clock cycles. */                    \
00783     0x06U,                 /* Measure delay is set to 6 excitation clock cycles.*/                    \
00784     0x00U,                 /* ACMP threshold has been set to 0. */                                    \
00785     lesenseSampleModeACMP, /* ACMP output will be used in comparison. */                              \
00786     lesenseSetIntNone,     /* No interrupt is generated by the channel. */                            \
00787     0xFFU,                 /* Counter threshold has bee set to 0xFF. */                               \
00788     lesenseCompModeLess    /* Compare mode has been set to trigger interrupt on "less". */            \
00789   }
00790 
00792 #define LESENSE_SCAN_CONF_DEFAULT                     \
00793   {                                                   \
00794     {                                                 \
00795       LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */  \
00796       LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */  \
00797       LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */  \
00798       LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */  \
00799       LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */  \
00800       LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */  \
00801       LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */  \
00802       LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */  \
00803       LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */  \
00804       LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */  \
00805       LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \
00806       LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \
00807       LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \
00808       LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \
00809       LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \
00810       LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \
00811     }                                                 \
00812   }
00813 
00814 
00816 typedef struct
00817 {
00820   bool                         enablePin;
00821 
00824   LESENSE_AltExPinIdle_TypeDef idleConf;
00825 
00833   bool                         alwaysEx;
00834 } LESENSE_AltExDesc_TypeDef;
00835 
00836 
00838 typedef struct
00839 {
00841   LESENSE_AltExMap_TypeDef  altExMap;
00842 
00855   LESENSE_AltExDesc_TypeDef AltEx[16];
00856 
00857 } LESENSE_ConfAltEx_TypeDef;
00858 
00859 
00861 #define LESENSE_ALTEX_CH_CONF_DEFAULT                                          \
00862   {                                                                            \
00863     true,                  /* Alternate excitation enabled.*/                  \
00864     lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \
00865     false                  /* Excite only for corresponding channel. */        \
00866   }
00867 
00869 #define LESENSE_ALTEX_CONF_DEFAULT                                         \
00870   {                                                                        \
00871     lesenseAltExMapACMP,                                                   \
00872     {                                                                      \
00873       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */ \
00874       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */ \
00875       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */ \
00876       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */ \
00877       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */ \
00878       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */ \
00879       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */ \
00880       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */ \
00881       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */ \
00882       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */ \
00883       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
00884       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
00885       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
00886       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
00887       LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
00888       LESENSE_ALTEX_CH_CONF_DEFAULT  /* Alternate excitation channel 15. */ \
00889     }                                                                      \
00890   }
00891 
00892 
00894 typedef struct
00895 {
00898   uint8_t                    compVal;
00899 
00903   uint8_t                    compMask;
00904 
00907   uint8_t                    nextState;
00908 
00911   LESENSE_StTransAct_TypeDef prsAct;
00912 
00914   bool                       setInt;
00915 } LESENSE_DecStCond_TypeDef;
00916 
00918 #define LESENSE_ST_CONF_DEFAULT                                          \
00919   {                                                                      \
00920     0x0FU,               /* Compare value set to 0x0F. */                \
00921     0x00U,               /* All decoder inputs masked. */                \
00922     0U,                  /* Next state is state 0. */                    \
00923     lesenseTransActNone, /* No PRS action performed on compare match. */ \
00924     false                /* No interrupt triggered on compare match. */  \
00925   }
00926 
00927 
00929 typedef struct
00930 {
00933   bool                      chainDesc;
00934 
00937   LESENSE_DecStCond_TypeDef confA;
00938 
00941   LESENSE_DecStCond_TypeDef confB;
00942 } LESENSE_DecStDesc_TypeDef;
00943 
00944 
00946 typedef struct
00947 {
00949   LESENSE_DecStDesc_TypeDef St[16];
00950 } LESENSE_DecStAll_TypeDef;
00951 
00953 #define LESENSE_DECODER_CONF_DEFAULT                                                                                 \
00954   {  /* chain |   Descriptor A         |   Descriptor B   */ \
00955     {                                                                                                                \
00956       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */                            \
00957       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */                            \
00958       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */                            \
00959       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */                            \
00960       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */                            \
00961       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */                            \
00962       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */                            \
00963       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */                            \
00964       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */                            \
00965       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */                            \
00966       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */                           \
00967       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */                           \
00968       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */                           \
00969       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */                           \
00970       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */                           \
00971       { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT } /* Decoder state 15. */                            \
00972     }                                                                                                                \
00973   }
00974 
00975 /*******************************************************************************
00976  *****************************   PROTOTYPES   **********************************
00977  ******************************************************************************/
00978 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset);
00979 void LESENSE_Reset(void);
00980 
00981 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq);
00982 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,
00983                          bool const start);
00984 
00985 void LESENSE_StartDelaySet(uint8_t const startDelay);
00986 
00987 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
00988                        LESENSE_ClkPresc_TypeDef const clkDiv);
00989 
00990 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll);
00991 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,
00992                            uint32_t const chIdx);
00993 void LESENSE_ChannelEnable(uint8_t const chIdx,
00994                            bool const enaScanCh,
00995                            bool const enaPin);
00996 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);
00997 void LESENSE_ChannelTimingSet(uint8_t const chIdx,
00998                               uint8_t const exTime,
00999                               uint8_t const sampleDelay,
01000                               uint8_t const measDelay);
01001 void LESENSE_ChannelThresSet(uint8_t const chIdx,
01002                              uint16_t const acmpThres,
01003                              uint16_t const cntThres);
01004 
01005 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);
01006 
01007 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll);
01008 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,
01009                                 uint32_t const decSt);
01010 void LESENSE_DecoderStateSet(uint32_t decSt);
01011 uint32_t LESENSE_DecoderStateGet(void);
01012 
01013 void LESENSE_ScanStart(void);
01014 void LESENSE_ScanStop(void);
01015 void LESENSE_DecoderStart(void);
01016 void LESENSE_ResultBufferClear(void);
01017 
01018 __STATIC_INLINE void LESENSE_DecoderStop(void);
01019 __STATIC_INLINE uint32_t LESENSE_StatusGet(void);
01020 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag);
01021 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void);
01022 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void);
01023 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void);
01024 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx);
01025 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void);
01026 __STATIC_INLINE void LESENSE_RAMPowerDown(void);
01027 
01028 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags);
01029 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags);
01030 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags);
01031 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags);
01032 __STATIC_INLINE uint32_t LESENSE_IntGet(void);
01033 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void);
01034 
01035 
01036 /***************************************************************************/
01044 __STATIC_INLINE void LESENSE_DecoderStop(void)
01045 {
01046   /* Stop the decoder */
01047   LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
01048 }
01049 
01050 
01051 /***************************************************************************/
01065 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)
01066 {
01067   return LESENSE->STATUS;
01068 }
01069 
01070 
01071 /***************************************************************************/
01091 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)
01092 {
01093   while (!(LESENSE->STATUS & flag))
01094     ;
01095 }
01096 
01097 
01098 /***************************************************************************/
01106 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)
01107 {
01108   return LESENSE->CURCH;
01109 }
01110 
01111 
01112 /***************************************************************************/
01123 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)
01124 {
01125   return LESENSE->SCANRES;
01126 }
01127 
01128 
01129 /***************************************************************************/
01142 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
01143 {
01144   return LESENSE->BUFDATA;
01145 }
01146 
01147 
01148 /***************************************************************************/
01163 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
01164 {
01165   /* Note: masking is needed to avoid over-indexing! */
01166   return LESENSE->BUF[idx & 0x0FU].DATA;
01167 }
01168 
01169 /***************************************************************************/
01177 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)
01178 {
01179   return LESENSE->SENSORSTATE;
01180 }
01181 
01182 
01183 /***************************************************************************/
01195 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
01196 {
01197   /* Power down LESENSE RAM */
01198   LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
01199 }
01200 
01201 
01202 /***************************************************************************/
01211 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
01212 {
01213   LESENSE->IFC = flags;
01214 }
01215 
01216 
01217 /***************************************************************************/
01226 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
01227 {
01228   LESENSE->IEN |= flags;
01229 }
01230 
01231 
01232 /***************************************************************************/
01241 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
01242 {
01243   LESENSE->IEN &= ~(flags);
01244 }
01245 
01246 
01247 /***************************************************************************/
01256 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)
01257 {
01258   LESENSE->IFS = flags;
01259 }
01260 
01261 
01262 /***************************************************************************/
01273 __STATIC_INLINE uint32_t LESENSE_IntGet(void)
01274 {
01275   return LESENSE->IF;
01276 }
01277 
01278 
01279 /***************************************************************************/
01297 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
01298 {
01299   uint32_t tmp;
01300 
01301   /* Store LESENSE->IEN in temporary variable in order to define explicit order
01302    * of volatile accesses. */
01303   tmp = LESENSE->IEN;
01304 
01305   /* Bitwise AND of pending and enabled interrupts */
01306   return LESENSE->IF & tmp;
01307 }
01308 
01309 
01313 #ifdef __cplusplus
01314 }
01315 #endif
01316 
01317 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
01318 
01319 #endif /* __EM_LESENSE_H */