mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: targets/TARGET_Silicon_Labs/TARGET_EFM32/emlib/src/em_lesense.c
- Revision:
- 179:b0033dcd6934
- Parent:
- 161:2cc1468da177
--- a/targets/TARGET_Silicon_Labs/TARGET_EFM32/emlib/src/em_lesense.c Thu Nov 23 11:57:25 2017 +0000 +++ b/targets/TARGET_Silicon_Labs/TARGET_EFM32/emlib/src/em_lesense.c Thu Dec 07 14:01:42 2017 +0000 @@ -1,9 +1,9 @@ /***************************************************************************//** * @file em_lesense.c * @brief Low Energy Sensor (LESENSE) Peripheral API - * @version 5.1.2 + * @version 5.3.3 ******************************************************************************* - * @section License + * # License * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b> ******************************************************************************* * @@ -79,7 +79,6 @@ ************************** LOCAL FUNCTIONS ******************************** ******************************************************************************/ - /******************************************************************************* ************************** GLOBAL FUNCTIONS ******************************* ******************************************************************************/ @@ -124,8 +123,7 @@ #endif /* Reset LESENSE registers if requested. */ - if (reqReset) - { + if (reqReset) { LESENSE_Reset(); } @@ -166,27 +164,32 @@ * Set DAC0 and DAC1 data source, conversion mode, output mode. Set DAC * prescaler and reference. Set ACMP0 and ACMP1 control mode. Set ACMP and DAC * duty cycle (warm up) mode. */ - LESENSE->PERCTRL = - ((uint32_t)init->perCtrl.dacCh0Data << _LESENSE_PERCTRL_DACCH0DATA_SHIFT) - | ((uint32_t)init->perCtrl.dacCh1Data << _LESENSE_PERCTRL_DACCH1DATA_SHIFT) + LESENSE->PERCTRL = 0 +#if defined(_LESENSE_PERCTRL_DACCH0EN_MASK) + | ((uint32_t)init->perCtrl.dacCh0En << _LESENSE_PERCTRL_DACCH0EN_SHIFT) + | ((uint32_t)init->perCtrl.dacCh1En << _LESENSE_PERCTRL_DACCH1EN_SHIFT) +#endif + | ((uint32_t)init->perCtrl.dacCh0Data << _LESENSE_PERCTRL_DACCH0DATA_SHIFT) + | ((uint32_t)init->perCtrl.dacCh1Data << _LESENSE_PERCTRL_DACCH1DATA_SHIFT) #if defined(_LESENSE_PERCTRL_DACCH0CONV_MASK) - | ((uint32_t)init->perCtrl.dacCh0ConvMode << _LESENSE_PERCTRL_DACCH0CONV_SHIFT) - | ((uint32_t)init->perCtrl.dacCh0OutMode << _LESENSE_PERCTRL_DACCH0OUT_SHIFT) - | ((uint32_t)init->perCtrl.dacCh1ConvMode << _LESENSE_PERCTRL_DACCH1CONV_SHIFT) - | ((uint32_t)init->perCtrl.dacCh1OutMode << _LESENSE_PERCTRL_DACCH1OUT_SHIFT) - | ((uint32_t)init->perCtrl.dacPresc << _LESENSE_PERCTRL_DACPRESC_SHIFT) - | (uint32_t)init->perCtrl.dacRef -#endif - | ((uint32_t)init->perCtrl.acmp0Mode << _LESENSE_PERCTRL_ACMP0MODE_SHIFT) - | ((uint32_t)init->perCtrl.acmp1Mode << _LESENSE_PERCTRL_ACMP1MODE_SHIFT) -#if defined(_LESENSE_PERCTRL_ACMP0INV_MASK) - | ((uint32_t)init->coreCtrl.invACMP0 << _LESENSE_PERCTRL_ACMP0INV_SHIFT) - | ((uint32_t)init->coreCtrl.invACMP1 << _LESENSE_PERCTRL_ACMP1INV_SHIFT) + | ((uint32_t)init->perCtrl.dacCh0ConvMode << _LESENSE_PERCTRL_DACCH0CONV_SHIFT) + | ((uint32_t)init->perCtrl.dacCh0OutMode << _LESENSE_PERCTRL_DACCH0OUT_SHIFT) + | ((uint32_t)init->perCtrl.dacCh1ConvMode << _LESENSE_PERCTRL_DACCH1CONV_SHIFT) + | ((uint32_t)init->perCtrl.dacCh1OutMode << _LESENSE_PERCTRL_DACCH1OUT_SHIFT) + | ((uint32_t)init->perCtrl.dacPresc << _LESENSE_PERCTRL_DACPRESC_SHIFT) + | (uint32_t)init->perCtrl.dacRef #endif #if defined(_LESENSE_PERCTRL_DACCONVTRIG_MASK) - | ((uint32_t)init->perCtrl.dacScan << _LESENSE_PERCTRL_DACCONVTRIG_SHIFT) + | ((uint32_t)init->perCtrl.dacStartupHalf << _LESENSE_PERCTRL_DACSTARTUP_SHIFT) + | ((uint32_t)init->perCtrl.dacScan << _LESENSE_PERCTRL_DACCONVTRIG_SHIFT) #endif - | (uint32_t)init->perCtrl.warmupMode; + | ((uint32_t)init->perCtrl.acmp0Mode << _LESENSE_PERCTRL_ACMP0MODE_SHIFT) + | ((uint32_t)init->perCtrl.acmp1Mode << _LESENSE_PERCTRL_ACMP1MODE_SHIFT) +#if defined(_LESENSE_PERCTRL_ACMP0INV_MASK) + | ((uint32_t)init->coreCtrl.invACMP0 << _LESENSE_PERCTRL_ACMP0INV_SHIFT) + | ((uint32_t)init->coreCtrl.invACMP1 << _LESENSE_PERCTRL_ACMP1INV_SHIFT) +#endif + | (uint32_t)init->perCtrl.warmupMode; /* LESENSE decoder general control configuration. * Set decoder input source, select PRS input for decoder bits. @@ -217,7 +220,6 @@ LESENSE->BIASCTRL = (uint32_t)init->coreCtrl.biasMode; } - /***************************************************************************//** * @brief * Set scan frequency for periodic scanning. @@ -252,11 +254,9 @@ uint32_t pcTop = 63UL; /* Period counter top value (max. 63). */ uint32_t calcScanFreq; /* Variable for testing the calculation algorithm. */ - /* If refFreq is set to 0, the currently configured reference clock is * assumed. */ - if (!refFreq) - { + if (!refFreq) { refFreq = CMU_ClockFreqGet(cmuClock_LESENSE); } @@ -272,8 +272,7 @@ * biggest possible resolution for setting scan frequency. * Maximum number of calculation cycles is 7 (value of lesenseClkDiv_128). */ while ((refFreq / ((uint32_t)scanFreq * clkDiv) > (pcTop + 1UL)) - && (pcPresc < lesenseClkDiv_128)) - { + && (pcPresc < lesenseClkDiv_128)) { ++pcPresc; clkDiv = (uint32_t)1UL << pcPresc; } @@ -299,7 +298,6 @@ return calcScanFreq; } - /***************************************************************************//** * @brief * Set scan mode of the LESENSE channels. @@ -331,7 +329,6 @@ { uint32_t tmp; /* temporary storage of the CTRL register value */ - /* Save the CTRL register value to tmp. * Please be aware the effects of the non-atomic Read-Modify-Write cycle! */ tmp = LESENSE->CTRL & ~(_LESENSE_CTRL_SCANMODE_MASK); @@ -343,13 +340,11 @@ LESENSE->CTRL = tmp; /* Start sensor scanning if requested. */ - if (start) - { + if (start) { LESENSE_ScanStart(); } } - /***************************************************************************//** * @brief * Set start delay of sensor interaction on each channel. @@ -372,7 +367,6 @@ { uint32_t tmp; /* temporary storage of the TIMCTRL register value */ - /* Sanity check of startDelay. */ EFM_ASSERT(startDelay < 4U); @@ -386,7 +380,6 @@ LESENSE->TIMCTRL = tmp; } - /***************************************************************************//** * @brief * Set clock division for LESENSE timers. @@ -416,10 +409,8 @@ { uint32_t tmp; - /* Select clock to prescale */ - switch (clk) - { + switch (clk) { case lesenseClkHF: /* Sanity check of clock divisor for HF clock. */ EFM_ASSERT((uint32_t)clkDiv <= lesenseClkDiv_8); @@ -451,7 +442,6 @@ } } - /***************************************************************************//** * @brief * Configure all (16) LESENSE sensor channels. @@ -478,14 +468,12 @@ uint32_t i; /* Iterate through all the 16 channels */ - for (i = 0U; i < LESENSE_NUM_CHANNELS; ++i) - { + for (i = 0U; i < LESENSE_NUM_CHANNELS; ++i) { /* Configure scan channels. */ LESENSE_ChannelConfig(&confChAll->Ch[i], i); } } - /***************************************************************************//** * @brief * Configure a single LESENSE sensor channel. @@ -513,7 +501,6 @@ { uint32_t tmp; /* Service variable. */ - /* Sanity check of configuration parameters */ EFM_ASSERT(chIdx < LESENSE_NUM_CHANNELS); EFM_ASSERT(confCh->exTime <= (_LESENSE_CH_TIMING_EXTIME_MASK >> _LESENSE_CH_TIMING_EXTIME_SHIFT)); @@ -527,8 +514,7 @@ * configuration parameters, check the parameter description of acmpThres for * for more details! */ EFM_ASSERT(confCh->acmpThres < 4096U); - if (confCh->chPinExMode == lesenseChPinExDACOut) - { + if (confCh->chPinExMode == lesenseChPinExDACOut) { EFM_ASSERT((0x1 << chIdx) & DACOUT_SUPPORT); } @@ -563,25 +549,25 @@ * alternate excitation usage and interrupt mode on scan channel chIdx in * LESENSE_CHchIdx_INTERACT. */ LESENSE->CH[chIdx].INTERACT = - ((uint32_t)confCh->exClk << _LESENSE_CH_INTERACT_EXCLK_SHIFT) - | ((uint32_t)confCh->sampleClk << _LESENSE_CH_INTERACT_SAMPLECLK_SHIFT) - | (uint32_t)confCh->sampleMode - | (uint32_t)confCh->intMode - | (uint32_t)confCh->chPinExMode - | ((uint32_t)confCh->useAltEx << _LESENSE_CH_INTERACT_ALTEX_SHIFT); + ((uint32_t)confCh->exClk << _LESENSE_CH_INTERACT_EXCLK_SHIFT) + | ((uint32_t)confCh->sampleClk << _LESENSE_CH_INTERACT_SAMPLECLK_SHIFT) + | (uint32_t)confCh->sampleMode + | (uint32_t)confCh->intMode + | (uint32_t)confCh->chPinExMode + | ((uint32_t)confCh->useAltEx << _LESENSE_CH_INTERACT_ALTEX_SHIFT); /* Configure channel specific counter comparison mode, optional result * forwarding to decoder, optional counter value storing and optional result * inverting on scan channel chIdx in LESENSE_CHchIdx_EVAL. */ LESENSE->CH[chIdx].EVAL = - (uint32_t)confCh->compMode - | ((uint32_t)confCh->shiftRes << _LESENSE_CH_EVAL_DECODE_SHIFT) - | ((uint32_t)confCh->storeCntRes << _LESENSE_CH_EVAL_STRSAMPLE_SHIFT) - | ((uint32_t)confCh->invRes << _LESENSE_CH_EVAL_SCANRESINV_SHIFT) + (uint32_t)confCh->compMode + | ((uint32_t)confCh->shiftRes << _LESENSE_CH_EVAL_DECODE_SHIFT) + | ((uint32_t)confCh->storeCntRes << _LESENSE_CH_EVAL_STRSAMPLE_SHIFT) + | ((uint32_t)confCh->invRes << _LESENSE_CH_EVAL_SCANRESINV_SHIFT) #if defined(_LESENSE_CH_EVAL_MODE_MASK) - | ((uint32_t)confCh->evalMode << _LESENSE_CH_EVAL_MODE_SHIFT) + | ((uint32_t)confCh->evalMode << _LESENSE_CH_EVAL_MODE_SHIFT) #endif - ; + ; /* Configure analog comparator (ACMP) threshold and decision threshold for * counter separately with the function provided for that. */ @@ -599,7 +585,6 @@ BUS_RegBitWrite(&LESENSE->CHEN, chIdx, confCh->enaScanCh); } - /***************************************************************************//** * @brief * Configure the LESENSE alternate excitation modes. @@ -622,7 +607,6 @@ uint32_t i; uint32_t tmp; - /* Configure alternate excitation mapping. * Atomic read-modify-write using BUS_RegBitWrite function in order to * support reconfiguration during LESENSE operation. */ @@ -630,12 +614,10 @@ _LESENSE_CTRL_ALTEXMAP_SHIFT, confAltEx->altExMap); - switch (confAltEx->altExMap) - { + switch (confAltEx->altExMap) { case lesenseAltExMapALTEX: /* Iterate through the 8 possible alternate excitation pin descriptors. */ - for (i = 0U; i < 8U; ++i) - { + for (i = 0U; i < 8U; ++i) { /* Enable/disable alternate excitation pin i. * Atomic read-modify-write using BUS_RegBitWrite function in order to * support reconfiguration during LESENSE operation. */ @@ -663,8 +645,7 @@ case lesenseAltExMapCH: #endif /* Iterate through all the 16 alternate excitation channels */ - for (i = 0U; i < 16U; ++i) - { + for (i = 0U; i < 16U; ++i) { /* Enable/disable alternate ACMP excitation channel pin i. */ /* Atomic read-modify-write using BUS_RegBitWrite function in order to * support reconfiguration during LESENSE operation. */ @@ -680,7 +661,6 @@ } } - /***************************************************************************//** * @brief * Enable/disable LESENSE scan channel and the pin assigned to it. @@ -719,7 +699,6 @@ BUS_RegBitWrite(&LESENSE->CHEN, chIdx, enaScanCh); } - /***************************************************************************//** * @brief * Enable/disable LESENSE scan channel and the pin assigned to it. @@ -750,7 +729,6 @@ GENERIC_LESENSE_ROUTE = pinMask; } - /***************************************************************************//** * @brief * Set LESENSE channel timing parameters. @@ -795,12 +773,11 @@ /* Channel specific timing configuration on scan channel chIdx. * Setting excitation time, sampling delay, measurement delay. */ LESENSE->CH[chIdx].TIMING = - ((uint32_t)exTime << _LESENSE_CH_TIMING_EXTIME_SHIFT) - | ((uint32_t)sampleDelay << _LESENSE_CH_TIMING_SAMPLEDLY_SHIFT) - | ((uint32_t)measDelay << _LESENSE_CH_TIMING_MEASUREDLY_SHIFT); + ((uint32_t)exTime << _LESENSE_CH_TIMING_EXTIME_SHIFT) + | ((uint32_t)sampleDelay << _LESENSE_CH_TIMING_SAMPLEDLY_SHIFT) + | ((uint32_t)measDelay << _LESENSE_CH_TIMING_MEASUREDLY_SHIFT); } - /***************************************************************************//** * @brief * Set LESENSE channel threshold parameters. @@ -840,7 +817,6 @@ { uint32_t tmp; /* temporary storage */ - /* Sanity check for acmpThres only, cntThres is 16bit value. */ EFM_ASSERT(acmpThres < 4096U); /* Sanity check for LESENSE channel id. */ @@ -1001,14 +977,12 @@ uint32_t i; /* Iterate through all the 16 or 32 decoder states. */ - for (i = 0U; i < LESENSE_NUM_DECODER_STATES; ++i) - { + for (i = 0U; i < LESENSE_NUM_DECODER_STATES; ++i) { /* Configure decoder state i. */ LESENSE_DecoderStateConfig(&confDecStAll->St[i], i); } } - /***************************************************************************//** * @brief * Configure a single LESENSE decoder state. @@ -1052,14 +1026,13 @@ * Setting sensor compare value, sensor mask, next state index, transition * action and interrupt flag option configurations. */ LESENSE->ST[decSt].TCONFB = - (uint32_t)confDecSt->confB.prsAct + (uint32_t)confDecSt->confB.prsAct | ((uint32_t)confDecSt->confB.compMask << _LESENSE_ST_TCONFB_MASK_SHIFT) | ((uint32_t)confDecSt->confB.compVal << _LESENSE_ST_TCONFB_COMP_SHIFT) | ((uint32_t)confDecSt->confB.nextState << _LESENSE_ST_TCONFB_NEXTSTATE_SHIFT) | ((uint32_t)confDecSt->confB.setInt << _LESENSE_ST_TCONFB_SETIF_SHIFT); } - /***************************************************************************//** * @brief * Set LESENSE decoder state. @@ -1083,7 +1056,6 @@ LESENSE->DECSTATE = decSt & _LESENSE_DECSTATE_DECSTATE_MASK; } - /***************************************************************************//** * @brief * Get the current state of the LESENSE decoder. @@ -1149,7 +1121,6 @@ ; } - /***************************************************************************//** * @brief * Stop scanning of sensors. @@ -1182,7 +1153,6 @@ ; } - /***************************************************************************//** * @brief * Start LESENSE decoder. @@ -1212,7 +1182,6 @@ ; } - /***************************************************************************//** * @brief * Clear result buffer. @@ -1241,7 +1210,6 @@ ; } - /***************************************************************************//** * @brief * Reset the LESENSE module. @@ -1297,16 +1265,14 @@ #endif /* Reset all channel configuration registers */ - for (i = 0U; i < LESENSE_NUM_CHANNELS; ++i) - { + for (i = 0U; i < LESENSE_NUM_CHANNELS; ++i) { LESENSE->CH[i].TIMING = _LESENSE_CH_TIMING_RESETVALUE; LESENSE->CH[i].INTERACT = _LESENSE_CH_INTERACT_RESETVALUE; LESENSE->CH[i].EVAL = _LESENSE_CH_EVAL_RESETVALUE; } /* Reset all decoder state configuration registers */ - for (i = 0U; i < LESENSE_NUM_DECODER_STATES; ++i) - { + for (i = 0U; i < LESENSE_NUM_DECODER_STATES; ++i) { LESENSE->ST[i].TCONFA = _LESENSE_ST_TCONFA_RESETVALUE; LESENSE->ST[i].TCONFB = _LESENSE_ST_TCONFB_RESETVALUE; } @@ -1317,7 +1283,6 @@ ; } - /** @} (end addtogroup LESENSE) */ /** @} (end addtogroup emlib) */