/**************************************************************************//** * @brief Setup the ACMP *****************************************************************************/ void setupACMP(void) { /* ACMP configuration constant table. */ static const ACMP_Init_TypeDef initACMP = { .fullBias = false, /* fullBias */ .halfBias = true, /* halfBias */ .biasProg = 0x0, /* biasProg */ .interruptOnFallingEdge = false, /* interrupt on rising edge */ .interruptOnRisingEdge = false, /* interrupt on falling edge */ //.interruptOnFallingEdge = true, /* interrupt on rising edge */ //.interruptOnRisingEdge = true, /* interrupt on falling edge */ .warmTime = acmpWarmTime4, /* 512 cycle warmup to be safe */ .hysteresisLevel = acmpHysteresisLevel0, /* No Hysteresis */ .inactiveValue = false, /* inactive value */ .lowPowerReferenceEnabled = true, /* low power reference */ .vddLevel = 32, /* VDD level : VDD/2 */ .enable = false /* Don't request enabling. */ }; /* Configure ACMP. */ ACMP_Init(ACMP1, &initACMP); /* Disable ACMP0 out to a pin. */ ACMP_GPIOSetup(ACMP1, 0, false, false); /* Set up ACMP negSel to VDD, posSel is controlled by LESENSE. */ ACMP_ChannelSet(ACMP1, acmpChannelVDD, acmpChannel0); /* LESENSE controls ACMP thus ACMP_Enable(ACMP0) should NOT be called in order * to ensure lower current consumption. */ #ifdef DEBUG_ACMP ACMP_ChannelSet(ACMP1, acmpChannelVDD, acmpChannel2); ACMP1->IEN = 1; ACMP_Enable(ACMP1); NVIC_ClearPendingIRQ(ACMP0_IRQn); NVIC_EnableIRQ(ACMP0_IRQn); #endif } #ifdef DEBUG_ACMP // ACMP IRQ Handler is shared between ACMP0 and ACMP1 void ACMP0_IRQHandler(void) { PRINTF("%s\r\n",__func__); ACMP1->IFC = 1; NVIC_ClearPendingIRQ(ACMP0_IRQn); }
/**************************************************************************//** * @brief Setup the ACMP *****************************************************************************/ void CAPLESENSE_setupACMP(void) { /* ACMP capsense configuration constant table. */ static const ACMP_CapsenseInit_TypeDef initACMP = { .fullBias = false, .halfBias = false, .biasProg = 0x7, .warmTime = acmpWarmTime512, .hysteresisLevel = acmpHysteresisLevel7, .resistor = acmpResistor0, .lowPowerReferenceEnabled = false, .vddLevel = 0x3D, .enable = false }; /* Configure ACMP locations, ACMP output to pin disabled. */ ACMP_GPIOSetup(ACMP0, 0, false, false); ACMP_GPIOSetup(ACMP1, 0, false, false); /* Initialize ACMPs in capacitive sense mode. */ ACMP_CapsenseInit(ACMP0, &initACMP); ACMP_CapsenseInit(ACMP1, &initACMP); /* Don't enable ACMP, LESENSE controls it! */ } /**************************************************************************//** * @brief Setup the LESENSE for capavitive sensing * @param sleep * If true, go into sleep mode. *****************************************************************************/ void CAPLESENSE_setupLESENSE(bool sleep) { uint8_t i; static bool init = true; /* Array for storing the calibration values. */ static uint16_t capsenseCalibrateVals[4]; /* LESENSE channel configuration constant table in sense mode. */ static const LESENSE_ChAll_TypeDef initChsSense = LESENSE_CAPSENSE_SCAN_CONF_SENSE; /* LESENSE channel configuration constant table in sleep mode. */ static const LESENSE_ChAll_TypeDef initChsSleep = LESENSE_CAPSENSE_SCAN_CONF_SLEEP; /* LESENSE central configuration constant table. */ static const LESENSE_Init_TypeDef initLESENSE = { .coreCtrl = { .scanStart = lesenseScanStartPeriodic, .prsSel = lesensePRSCh0, .scanConfSel = lesenseScanConfDirMap, .invACMP0 = false, .invACMP1 = false, .dualSample = false, .storeScanRes = false, .bufOverWr = true, .bufTrigLevel = lesenseBufTrigHalf, .wakeupOnDMA = lesenseDMAWakeUpDisable, .biasMode = lesenseBiasModeDutyCycle, .debugRun = false }, .timeCtrl = { .startDelay = 0U }, .perCtrl =
/**************************************************************************//** * @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 } };
/**************************************************************************//** * @brief Setup the ACMP *****************************************************************************/ void setupACMP(void) { /* ACMP configuration constant table. */ static const ACMP_Init_TypeDef initACMP = { .fullBias = false, /* fullBias */ .halfBias = true, /* halfBias */ .biasProg = 0x0, /* biasProg */ .interruptOnFallingEdge = false, /* interrupt on rising edge */ .interruptOnRisingEdge = false, /* interrupt on falling edge */ .warmTime = acmpWarmTime512, /* 512 cycle warmup to be safe */ .hysteresisLevel = acmpHysteresisLevel5, /* hysteresis level 5 */ .inactiveValue = false, /* inactive value */ .lowPowerReferenceEnabled = false, /* low power reference */ .vddLevel = 0x00, /* VDD level */ .enable = false /* Don't request enabling. */ }; /* Configure ACMP. */ ACMP_Init(ACMP0, &initACMP); /* 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 Setup the LESENSE *****************************************************************************/ void setupLESENSE(void) { /* LESENSE channel configuration constant table. */ static const LESENSE_ChAll_TypeDef initChs = LESENSE_LIGHTSENSE_SCAN_CONF; /* LESENSE alternate excitation channel configuration constant table. */ static const LESENSE_ConfAltEx_TypeDef initAltEx = LESENSE_LIGHTSENSE_ALTEX_CONF; /* LESENSE central configuration constant table. */ static const LESENSE_Init_TypeDef initLESENSE = { .coreCtrl = { .scanStart = lesenseScanStartPeriodic, .prsSel = lesensePRSCh0, .scanConfSel = lesenseScanConfDirMap, .invACMP0 = false, .invACMP1 = false, .dualSample = false, .storeScanRes = false, .bufOverWr = true, .bufTrigLevel = lesenseBufTrigHalf, .wakeupOnDMA = lesenseDMAWakeUpDisable, .biasMode = lesenseBiasModeDutyCycle, .debugRun = false }, .timeCtrl = { .startDelay = 0U }, .perCtrl = { .dacCh0Data = lesenseDACIfData, .dacCh0ConvMode = lesenseDACConvModeDisable, .dacCh0OutMode = lesenseDACOutModeDisable, .dacCh1Data = lesenseDACIfData, .dacCh1ConvMode = lesenseDACConvModeDisable, .dacCh1OutMode = lesenseDACOutModeDisable, .dacPresc = 0U, .dacRef = lesenseDACRefBandGap, .acmp0Mode = lesenseACMPModeMuxThres, .acmp1Mode = lesenseACMPModeMuxThres, .warmupMode = lesenseWarmupModeNormal }, .decCtrl =