/***************************************************************************//** * @brief * Configure all (16) LESENSE sensor channels. * * @details * This function configures all the sensor channels of LESENSE interface. * Please refer to the configuration parameter type definition * (LESENSE_ChAll_TypeDef) for more details. * * @note * Channels can be configured individually using LESENSE_ChannelConfig() * function. * Notice that pins used by the LESENSE module must be properly configured * by the user explicitly, in order for the LESENSE to work as intended. * (When configuring pins, one should remember to consider the sequence of * configuration, in order to avoid unintended pulses/glitches on output * pins.) * * @param[in] confChAll * Configuration structure for all (16) LESENSE sensor channels. ******************************************************************************/ void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll) { uint32_t i; /* Iterate through all the 16 channels */ for (i = 0U; i < 16U; ++i) { /* Configure scan channels. */ LESENSE_ChannelConfig(&confChAll->Ch[i], i); } }
/**************************************************************************//** * @brief Sets up the ACMP *****************************************************************************/ void setupACMP(void) { /* Configuration structure for ACMP */ static const ACMP_Init_TypeDef acmpInit = { .fullBias = false, .halfBias = false, .biasProg = 0x6, /* Experiment with higher value if sensor doesn't work */ .interruptOnFallingEdge = false, .interruptOnRisingEdge = false, .warmTime = acmpWarmTime256, /* Warmuptime should be longer than 10 micro s */ .hysteresisLevel = acmpHysteresisLevel0, .inactiveValue = false, .lowPowerReferenceEnabled = false, .vddLevel = 0x00, /* Controlled by LESENSE */ .enable = false }; /* Initialize ACMP */ ACMP_Init(ACMP0, &acmpInit); /* Disable ACMP0 out to a pin. */ ACMP_GPIOSetup(ACMP0, 0, false, false); /* Set up ACMP negSel to VDD, posSel is controlled by LESENSE. */ ACMP_ChannelSet(ACMP0, acmpChannelVDD, acmpChannel0); /* LESENSE controls ACMP thus ACMP_Enable(ACMP0) should NOT be called in order * to ensure lower current consumption. */ } /**************************************************************************//** * @brief Sets up the LESENSE *****************************************************************************/ void setupLESENSE(void) { /* LESENSE configuration structure */ static const LESENSE_Init_TypeDef initLesense = { .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, .perCtrl = { .dacCh0Data = lesenseDACIfData, .dacCh0ConvMode = lesenseDACConvModeDisable, .dacCh0OutMode = lesenseDACOutModeDisable, .dacCh1Data = lesenseDACIfData, .dacCh1ConvMode = lesenseDACConvModeDisable, .dacCh1OutMode = lesenseDACOutModeDisable, .dacPresc = 0, .dacRef = lesenseDACRefBandGap, .acmp0Mode = lesenseACMPModeMuxThres, /* LESENSE controls the threshold value (VDDLEVEL) of ACMP0 */ .acmp1Mode = lesenseACMPModeMuxThres, /* LESENSE controls the threshold value (VDDLEVEL) of ACMP1 */ .warmupMode = lesenseWarmupModeNormal /* The analog comparators are shut down when LESENSE is idle */ }, .decCtrl = LESENSE_DECCTRL_DESC_DEFAULT }; /* Channel configuration */ static const LESENSE_ChDesc_TypeDef initLesenseCh = { .enaScanCh = true, /* Enable scan on this channel */ .enaPin = false, .enaInt = false, .chPinExMode = lesenseChPinExHigh, /* Pin is high when excitating */ .chPinIdleMode = lesenseChPinIdleDis, /* Pin idle when channel idle */ .useAltEx = true, /* Use alternative excitation pin */ .shiftRes = true, /* Result is shifted into the decoder register */ .invRes = false, .storeCntRes = true, .exClk = lesenseClkHF, /* Use HF clock for excitation timing */ .sampleClk = lesenseClkHF, /* Use HF clock for sample timing */ .exTime = 0x1F, /* Clk cycles to excite emitter and decoder */ .sampleDelay = 0x1F, /* Clc cycles to wait before sampling comparator */ .measDelay = 0x00, .acmpThres = 0x0F, /* Initial comperator threshold */ .sampleMode = lesenseSampleModeACMP, .intMode = lesenseSetIntNone, .cntThres = 0x0000, .compMode = lesenseCompModeLess }; /* Alternate excitation channels configuration */ static const LESENSE_ConfAltEx_TypeDef initAltEx = { .altExMap = lesenseAltExMapALTEX, .AltEx[0] = { .enablePin = true, .idleConf = lesenseAltExPinIdleDis, .alwaysEx = true /* Connected to IR sensor */ }, .AltEx[1] = { .enablePin = true, .idleConf = lesenseAltExPinIdleDis, .alwaysEx = false /* Connected to IR LED */ } }; /* Initialize LESENSE interface _with_ RESET. */ LESENSE_Init(&initLesense, true); /* Configure channels */ LESENSE_ChannelConfig(&initLesenseCh, 0); LESENSE_ChannelConfig(&initLesenseCh, 1); /* Configure alternate excitation channels */ LESENSE_AltExConfig(&initAltEx); /* State machine proximity sensor setup */ LESENSE_DecStDesc_TypeDef decConf = { .chainDesc = false, .confA = { .compVal = 0x1, /* Trigger transition when scan result = compVal */ .compMask = 0xC, /* Mask out the upper two bits */ .nextState = STATE_1, .prsAct = lesenseTransActNone, .setInt = true }, .confB = { .compVal = 0x1, .compMask = 0xC, .nextState = STATE_1, .prsAct = lesenseTransActNone, .setInt = true } };