added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
bogdanm
Date:
Thu Oct 01 15:25:22 2015 +0300
Revision:
0:9b334a45a8ff
Child:
50:a417edff4437
Initial commit on mbed-dev

Replaces mbed-src (now inactive)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 2 * @file em_lesense.c
bogdanm 0:9b334a45a8ff 3 * @brief Low Energy Sensor (LESENSE) Peripheral API
bogdanm 0:9b334a45a8ff 4 * @version 3.20.12
bogdanm 0:9b334a45a8ff 5 *******************************************************************************
bogdanm 0:9b334a45a8ff 6 * @section License
bogdanm 0:9b334a45a8ff 7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
bogdanm 0:9b334a45a8ff 8 *******************************************************************************
bogdanm 0:9b334a45a8ff 9 *
bogdanm 0:9b334a45a8ff 10 * Permission is granted to anyone to use this software for any purpose,
bogdanm 0:9b334a45a8ff 11 * including commercial applications, and to alter it and redistribute it
bogdanm 0:9b334a45a8ff 12 * freely, subject to the following restrictions:
bogdanm 0:9b334a45a8ff 13 *
bogdanm 0:9b334a45a8ff 14 * 1. The origin of this software must not be misrepresented; you must not
bogdanm 0:9b334a45a8ff 15 * claim that you wrote the original software.
bogdanm 0:9b334a45a8ff 16 * 2. Altered source versions must be plainly marked as such, and must not be
bogdanm 0:9b334a45a8ff 17 * misrepresented as being the original software.
bogdanm 0:9b334a45a8ff 18 * 3. This notice may not be removed or altered from any source distribution.
bogdanm 0:9b334a45a8ff 19 *
bogdanm 0:9b334a45a8ff 20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
bogdanm 0:9b334a45a8ff 21 * obligation to support this Software. Silicon Labs is providing the
bogdanm 0:9b334a45a8ff 22 * Software "AS IS", with no express or implied warranties of any kind,
bogdanm 0:9b334a45a8ff 23 * including, but not limited to, any implied warranties of merchantability
bogdanm 0:9b334a45a8ff 24 * or fitness for any particular purpose or warranties against infringement
bogdanm 0:9b334a45a8ff 25 * of any proprietary rights of a third party.
bogdanm 0:9b334a45a8ff 26 *
bogdanm 0:9b334a45a8ff 27 * Silicon Labs will not be liable for any consequential, incidental, or
bogdanm 0:9b334a45a8ff 28 * special damages, or any other relief, or for any claim by any third party,
bogdanm 0:9b334a45a8ff 29 * arising from your use of this Software.
bogdanm 0:9b334a45a8ff 30 *
bogdanm 0:9b334a45a8ff 31 ******************************************************************************/
bogdanm 0:9b334a45a8ff 32
bogdanm 0:9b334a45a8ff 33
bogdanm 0:9b334a45a8ff 34 #include "em_lesense.h"
bogdanm 0:9b334a45a8ff 35 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0)
bogdanm 0:9b334a45a8ff 36 #include "em_assert.h"
bogdanm 0:9b334a45a8ff 37 #include "em_bitband.h"
bogdanm 0:9b334a45a8ff 38 #include "em_cmu.h"
bogdanm 0:9b334a45a8ff 39
bogdanm 0:9b334a45a8ff 40 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
bogdanm 0:9b334a45a8ff 41 #ifndef UINT32_MAX
bogdanm 0:9b334a45a8ff 42 #define UINT32_MAX ((uint32_t)(0xFFFFFFFF))
bogdanm 0:9b334a45a8ff 43 #endif
bogdanm 0:9b334a45a8ff 44 /** @endcond */
bogdanm 0:9b334a45a8ff 45
bogdanm 0:9b334a45a8ff 46 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 47 * @addtogroup EM_Library
bogdanm 0:9b334a45a8ff 48 * @{
bogdanm 0:9b334a45a8ff 49 ******************************************************************************/
bogdanm 0:9b334a45a8ff 50
bogdanm 0:9b334a45a8ff 51 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 52 * @addtogroup LESENSE
bogdanm 0:9b334a45a8ff 53 * @brief Low Energy Sensor (LESENSE) Peripheral API
bogdanm 0:9b334a45a8ff 54 * @{
bogdanm 0:9b334a45a8ff 55 ******************************************************************************/
bogdanm 0:9b334a45a8ff 56
bogdanm 0:9b334a45a8ff 57 /*******************************************************************************
bogdanm 0:9b334a45a8ff 58 ************************** LOCAL FUNCTIONS ********************************
bogdanm 0:9b334a45a8ff 59 ******************************************************************************/
bogdanm 0:9b334a45a8ff 60
bogdanm 0:9b334a45a8ff 61
bogdanm 0:9b334a45a8ff 62 /*******************************************************************************
bogdanm 0:9b334a45a8ff 63 ************************** GLOBAL FUNCTIONS *******************************
bogdanm 0:9b334a45a8ff 64 ******************************************************************************/
bogdanm 0:9b334a45a8ff 65
bogdanm 0:9b334a45a8ff 66 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 67 * @brief
bogdanm 0:9b334a45a8ff 68 * Initialize the LESENSE module.
bogdanm 0:9b334a45a8ff 69 *
bogdanm 0:9b334a45a8ff 70 * @details
bogdanm 0:9b334a45a8ff 71 * This function configures the main parameters of the LESENSE interface.
bogdanm 0:9b334a45a8ff 72 * Please refer to the initialization parameter type definition
bogdanm 0:9b334a45a8ff 73 * (@ref LESENSE_Init_TypeDef) for more details.
bogdanm 0:9b334a45a8ff 74 *
bogdanm 0:9b334a45a8ff 75 * @note
bogdanm 0:9b334a45a8ff 76 * @ref LESENSE_Init() has been designed for initializing LESENSE once in an
bogdanm 0:9b334a45a8ff 77 * operation cycle. Be aware of the effects of reconfiguration if using this
bogdanm 0:9b334a45a8ff 78 * function from multiple sources in your code. This function has not been
bogdanm 0:9b334a45a8ff 79 * designed to be re-entrant.
bogdanm 0:9b334a45a8ff 80 * Requesting reset by setting @p reqReset to true is required in each reset
bogdanm 0:9b334a45a8ff 81 * or power-on cycle in order to configure the default values of the RAM
bogdanm 0:9b334a45a8ff 82 * mapped LESENSE registers.
bogdanm 0:9b334a45a8ff 83 * Notice that GPIO pins used by the LESENSE module must be properly
bogdanm 0:9b334a45a8ff 84 * configured by the user explicitly, in order for the LESENSE to work as
bogdanm 0:9b334a45a8ff 85 * intended.
bogdanm 0:9b334a45a8ff 86 * (When configuring pins, one should remember to consider the sequence of
bogdanm 0:9b334a45a8ff 87 * configuration, in order to avoid unintended pulses/glitches on output
bogdanm 0:9b334a45a8ff 88 * pins.)
bogdanm 0:9b334a45a8ff 89 *
bogdanm 0:9b334a45a8ff 90 * @param[in] init
bogdanm 0:9b334a45a8ff 91 * LESENSE initialization structure.
bogdanm 0:9b334a45a8ff 92 *
bogdanm 0:9b334a45a8ff 93 * @param[in] reqReset
bogdanm 0:9b334a45a8ff 94 * Request to call @ref LESENSE_Reset() first in order to initialize all
bogdanm 0:9b334a45a8ff 95 * LESENSE registers with the default value.
bogdanm 0:9b334a45a8ff 96 ******************************************************************************/
bogdanm 0:9b334a45a8ff 97 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset)
bogdanm 0:9b334a45a8ff 98 {
bogdanm 0:9b334a45a8ff 99 /* Sanity check of initialization values */
bogdanm 0:9b334a45a8ff 100 EFM_ASSERT((uint32_t)init->timeCtrl.startDelay < 4U);
bogdanm 0:9b334a45a8ff 101 EFM_ASSERT((uint32_t)init->perCtrl.dacPresc < 32U);
bogdanm 0:9b334a45a8ff 102
bogdanm 0:9b334a45a8ff 103 /* Reset LESENSE registers if requested. */
bogdanm 0:9b334a45a8ff 104 if (reqReset)
bogdanm 0:9b334a45a8ff 105 {
bogdanm 0:9b334a45a8ff 106 LESENSE_Reset();
bogdanm 0:9b334a45a8ff 107 }
bogdanm 0:9b334a45a8ff 108
bogdanm 0:9b334a45a8ff 109 /* Set sensor start delay for each channel. */
bogdanm 0:9b334a45a8ff 110 LESENSE_StartDelaySet((uint32_t)init->timeCtrl.startDelay);
bogdanm 0:9b334a45a8ff 111
bogdanm 0:9b334a45a8ff 112 /* LESENSE core control configuration.
bogdanm 0:9b334a45a8ff 113 * Set PRS source, SCANCONF register usage strategy, interrupt and
bogdanm 0:9b334a45a8ff 114 * DMA trigger level condition, DMA wakeup condition, bias mode,
bogdanm 0:9b334a45a8ff 115 * enable/disable to sample both ACMPs simultaneously, enable/disable to store
bogdanm 0:9b334a45a8ff 116 * SCANRES in CNT_RES after each scan, enable/disable to always write to the
bogdanm 0:9b334a45a8ff 117 * result buffer, even if it is full, enable/disable LESENSE running in debug
bogdanm 0:9b334a45a8ff 118 * mode. */
bogdanm 0:9b334a45a8ff 119 LESENSE->CTRL = ((uint32_t)init->coreCtrl.prsSel <<
bogdanm 0:9b334a45a8ff 120 _LESENSE_CTRL_PRSSEL_SHIFT) |
bogdanm 0:9b334a45a8ff 121 (uint32_t)init->coreCtrl.scanConfSel |
bogdanm 0:9b334a45a8ff 122 (uint32_t)init->coreCtrl.bufTrigLevel |
bogdanm 0:9b334a45a8ff 123 (uint32_t)init->coreCtrl.wakeupOnDMA |
bogdanm 0:9b334a45a8ff 124 ((uint32_t)init->coreCtrl.invACMP0 <<
bogdanm 0:9b334a45a8ff 125 _LESENSE_CTRL_ACMP0INV_SHIFT) |
bogdanm 0:9b334a45a8ff 126 ((uint32_t)init->coreCtrl.invACMP1 <<
bogdanm 0:9b334a45a8ff 127 _LESENSE_CTRL_ACMP1INV_SHIFT) |
bogdanm 0:9b334a45a8ff 128 ((uint32_t)init->coreCtrl.dualSample <<
bogdanm 0:9b334a45a8ff 129 _LESENSE_CTRL_DUALSAMPLE_SHIFT) |
bogdanm 0:9b334a45a8ff 130 ((uint32_t)init->coreCtrl.storeScanRes <<
bogdanm 0:9b334a45a8ff 131 _LESENSE_CTRL_STRSCANRES_SHIFT) |
bogdanm 0:9b334a45a8ff 132 ((uint32_t)init->coreCtrl.bufOverWr <<
bogdanm 0:9b334a45a8ff 133 _LESENSE_CTRL_BUFOW_SHIFT) |
bogdanm 0:9b334a45a8ff 134 ((uint32_t)init->coreCtrl.debugRun <<
bogdanm 0:9b334a45a8ff 135 _LESENSE_CTRL_DEBUGRUN_SHIFT);
bogdanm 0:9b334a45a8ff 136
bogdanm 0:9b334a45a8ff 137 /* Set scan mode in the CTRL register using the provided function, don't
bogdanm 0:9b334a45a8ff 138 * start scanning immediately. */
bogdanm 0:9b334a45a8ff 139 LESENSE_ScanModeSet((LESENSE_ScanMode_TypeDef)init->coreCtrl.scanStart, false);
bogdanm 0:9b334a45a8ff 140
bogdanm 0:9b334a45a8ff 141 /* LESENSE peripheral control configuration.
bogdanm 0:9b334a45a8ff 142 * Set DAC0 and DAC1 data source, conversion mode, output mode. Set DAC
bogdanm 0:9b334a45a8ff 143 * prescaler and reference. Set ACMP0 and ACMP1 control mode. Set ACMP and DAC
bogdanm 0:9b334a45a8ff 144 * duty cycle (warm up) mode. */
bogdanm 0:9b334a45a8ff 145 LESENSE->PERCTRL = ((uint32_t)init->perCtrl.dacCh0Data <<
bogdanm 0:9b334a45a8ff 146 _LESENSE_PERCTRL_DACCH0DATA_SHIFT) |
bogdanm 0:9b334a45a8ff 147 ((uint32_t)init->perCtrl.dacCh0ConvMode <<
bogdanm 0:9b334a45a8ff 148 _LESENSE_PERCTRL_DACCH0CONV_SHIFT) |
bogdanm 0:9b334a45a8ff 149 ((uint32_t)init->perCtrl.dacCh0OutMode <<
bogdanm 0:9b334a45a8ff 150 _LESENSE_PERCTRL_DACCH0OUT_SHIFT) |
bogdanm 0:9b334a45a8ff 151 ((uint32_t)init->perCtrl.dacCh1Data <<
bogdanm 0:9b334a45a8ff 152 _LESENSE_PERCTRL_DACCH1DATA_SHIFT) |
bogdanm 0:9b334a45a8ff 153 ((uint32_t)init->perCtrl.dacCh1ConvMode <<
bogdanm 0:9b334a45a8ff 154 _LESENSE_PERCTRL_DACCH1CONV_SHIFT) |
bogdanm 0:9b334a45a8ff 155 ((uint32_t)init->perCtrl.dacCh1OutMode <<
bogdanm 0:9b334a45a8ff 156 _LESENSE_PERCTRL_DACCH1OUT_SHIFT) |
bogdanm 0:9b334a45a8ff 157 ((uint32_t)init->perCtrl.dacPresc <<
bogdanm 0:9b334a45a8ff 158 _LESENSE_PERCTRL_DACPRESC_SHIFT) |
bogdanm 0:9b334a45a8ff 159 (uint32_t)init->perCtrl.dacRef |
bogdanm 0:9b334a45a8ff 160 ((uint32_t)init->perCtrl.acmp0Mode <<
bogdanm 0:9b334a45a8ff 161 _LESENSE_PERCTRL_ACMP0MODE_SHIFT) |
bogdanm 0:9b334a45a8ff 162 ((uint32_t)init->perCtrl.acmp1Mode <<
bogdanm 0:9b334a45a8ff 163 _LESENSE_PERCTRL_ACMP1MODE_SHIFT) |
bogdanm 0:9b334a45a8ff 164 (uint32_t)init->perCtrl.warmupMode;
bogdanm 0:9b334a45a8ff 165
bogdanm 0:9b334a45a8ff 166 /* LESENSE decoder general control configuration.
bogdanm 0:9b334a45a8ff 167 * Set decoder input source, select PRS input for decoder bits.
bogdanm 0:9b334a45a8ff 168 * Enable/disable the decoder to check the present state.
bogdanm 0:9b334a45a8ff 169 * Enable/disable decoder to channel interrupt mapping.
bogdanm 0:9b334a45a8ff 170 * Enable/disable decoder hysteresis on PRS output.
bogdanm 0:9b334a45a8ff 171 * Enable/disable decoder hysteresis on count events.
bogdanm 0:9b334a45a8ff 172 * Enable/disable decoder hysteresis on interrupt requests.
bogdanm 0:9b334a45a8ff 173 * Enable/disable count mode on LESPRS0 and LESPRS1. */
bogdanm 0:9b334a45a8ff 174 LESENSE->DECCTRL = (uint32_t)init->decCtrl.decInput |
bogdanm 0:9b334a45a8ff 175 ((uint32_t)init->decCtrl.prsChSel0 <<
bogdanm 0:9b334a45a8ff 176 _LESENSE_DECCTRL_PRSSEL0_SHIFT) |
bogdanm 0:9b334a45a8ff 177 ((uint32_t)init->decCtrl.prsChSel1 <<
bogdanm 0:9b334a45a8ff 178 _LESENSE_DECCTRL_PRSSEL1_SHIFT) |
bogdanm 0:9b334a45a8ff 179 ((uint32_t)init->decCtrl.prsChSel2 <<
bogdanm 0:9b334a45a8ff 180 _LESENSE_DECCTRL_PRSSEL2_SHIFT) |
bogdanm 0:9b334a45a8ff 181 ((uint32_t)init->decCtrl.prsChSel3 <<
bogdanm 0:9b334a45a8ff 182 _LESENSE_DECCTRL_PRSSEL3_SHIFT) |
bogdanm 0:9b334a45a8ff 183 ((uint32_t)init->decCtrl.chkState <<
bogdanm 0:9b334a45a8ff 184 _LESENSE_DECCTRL_ERRCHK_SHIFT) |
bogdanm 0:9b334a45a8ff 185 ((uint32_t)init->decCtrl.intMap <<
bogdanm 0:9b334a45a8ff 186 _LESENSE_DECCTRL_INTMAP_SHIFT) |
bogdanm 0:9b334a45a8ff 187 ((uint32_t)init->decCtrl.hystPRS0 <<
bogdanm 0:9b334a45a8ff 188 _LESENSE_DECCTRL_HYSTPRS0_SHIFT) |
bogdanm 0:9b334a45a8ff 189 ((uint32_t)init->decCtrl.hystPRS1 <<
bogdanm 0:9b334a45a8ff 190 _LESENSE_DECCTRL_HYSTPRS1_SHIFT) |
bogdanm 0:9b334a45a8ff 191 ((uint32_t)init->decCtrl.hystPRS2 <<
bogdanm 0:9b334a45a8ff 192 _LESENSE_DECCTRL_HYSTPRS2_SHIFT) |
bogdanm 0:9b334a45a8ff 193 ((uint32_t)init->decCtrl.hystIRQ <<
bogdanm 0:9b334a45a8ff 194 _LESENSE_DECCTRL_HYSTIRQ_SHIFT) |
bogdanm 0:9b334a45a8ff 195 ((uint32_t)init->decCtrl.prsCount <<
bogdanm 0:9b334a45a8ff 196 _LESENSE_DECCTRL_PRSCNT_SHIFT);
bogdanm 0:9b334a45a8ff 197
bogdanm 0:9b334a45a8ff 198 /* Set initial LESENSE decoder state. */
bogdanm 0:9b334a45a8ff 199 LESENSE_DecoderStateSet((uint32_t)init->decCtrl.initState);
bogdanm 0:9b334a45a8ff 200
bogdanm 0:9b334a45a8ff 201 /* LESENSE bias control configuration. */
bogdanm 0:9b334a45a8ff 202 LESENSE->BIASCTRL = (uint32_t)init->coreCtrl.biasMode;
bogdanm 0:9b334a45a8ff 203 }
bogdanm 0:9b334a45a8ff 204
bogdanm 0:9b334a45a8ff 205
bogdanm 0:9b334a45a8ff 206 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 207 * @brief
bogdanm 0:9b334a45a8ff 208 * Set scan frequency for periodic scanning.
bogdanm 0:9b334a45a8ff 209 *
bogdanm 0:9b334a45a8ff 210 * @details
bogdanm 0:9b334a45a8ff 211 * This function only applies to LESENSE if period counter is being used as
bogdanm 0:9b334a45a8ff 212 * a trigger for scan start.
bogdanm 0:9b334a45a8ff 213 * The calculation is based on the following formula:
bogdanm 0:9b334a45a8ff 214 * Fscan = LFACLKles / ((1+PCTOP)*2^PCPRESC)
bogdanm 0:9b334a45a8ff 215 *
bogdanm 0:9b334a45a8ff 216 * @note
bogdanm 0:9b334a45a8ff 217 * Note that the calculation does not necessarily result in the requested
bogdanm 0:9b334a45a8ff 218 * scan frequency due to integer division. Check the return value for the
bogdanm 0:9b334a45a8ff 219 * resulted scan frequency.
bogdanm 0:9b334a45a8ff 220 *
bogdanm 0:9b334a45a8ff 221 * @param[in] refFreq
bogdanm 0:9b334a45a8ff 222 * Select reference LFACLK clock frequency in Hz. If set to 0, the current
bogdanm 0:9b334a45a8ff 223 * clock frequency is being used as a reference.
bogdanm 0:9b334a45a8ff 224 *
bogdanm 0:9b334a45a8ff 225 * @param[in] scanFreq
bogdanm 0:9b334a45a8ff 226 * Set the desired scan frequency in Hz.
bogdanm 0:9b334a45a8ff 227 *
bogdanm 0:9b334a45a8ff 228 * @return
bogdanm 0:9b334a45a8ff 229 * Frequency in Hz calculated and set by this function. Users can use this to
bogdanm 0:9b334a45a8ff 230 * compare the requested and set values.
bogdanm 0:9b334a45a8ff 231 ******************************************************************************/
bogdanm 0:9b334a45a8ff 232 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq)
bogdanm 0:9b334a45a8ff 233 {
bogdanm 0:9b334a45a8ff 234 uint32_t tmp;
bogdanm 0:9b334a45a8ff 235 uint32_t pcPresc = 0UL; /* Period counter prescaler. */
bogdanm 0:9b334a45a8ff 236 uint32_t clkDiv = 1UL; /* Clock divisor value (2^pcPresc). */
bogdanm 0:9b334a45a8ff 237 uint32_t pcTop = 63UL; /* Period counter top value (max. 63). */
bogdanm 0:9b334a45a8ff 238 uint32_t calcScanFreq; /* Variable for testing the calculation algorithm. */
bogdanm 0:9b334a45a8ff 239
bogdanm 0:9b334a45a8ff 240
bogdanm 0:9b334a45a8ff 241 /* If refFreq is set to 0, the currently configured reference clock is
bogdanm 0:9b334a45a8ff 242 * assumed. */
bogdanm 0:9b334a45a8ff 243 if (!refFreq)
bogdanm 0:9b334a45a8ff 244 {
bogdanm 0:9b334a45a8ff 245 refFreq = CMU_ClockFreqGet(cmuClock_LESENSE);
bogdanm 0:9b334a45a8ff 246 }
bogdanm 0:9b334a45a8ff 247
bogdanm 0:9b334a45a8ff 248 /* Max. value of pcPresc is 128, thus using reference frequency less than
bogdanm 0:9b334a45a8ff 249 * 33554431Hz (33.554431MHz), the frequency calculation in the while loop
bogdanm 0:9b334a45a8ff 250 * below will not overflow. */
bogdanm 0:9b334a45a8ff 251 EFM_ASSERT(refFreq < ((uint32_t)UINT32_MAX / 128UL));
bogdanm 0:9b334a45a8ff 252
bogdanm 0:9b334a45a8ff 253 /* Sanity check of scan frequency value. */
bogdanm 0:9b334a45a8ff 254 EFM_ASSERT((scanFreq > 0U) && (scanFreq <= refFreq));
bogdanm 0:9b334a45a8ff 255
bogdanm 0:9b334a45a8ff 256 /* Calculate the minimum necessary prescaler value in order to provide the
bogdanm 0:9b334a45a8ff 257 * biggest possible resolution for setting scan frequency.
bogdanm 0:9b334a45a8ff 258 * Maximum number of calculation cycles is 7 (value of lesenseClkDiv_128). */
bogdanm 0:9b334a45a8ff 259 while ((refFreq / ((uint32_t)scanFreq * clkDiv) > (pcTop + 1UL)) &&
bogdanm 0:9b334a45a8ff 260 (pcPresc < lesenseClkDiv_128))
bogdanm 0:9b334a45a8ff 261 {
bogdanm 0:9b334a45a8ff 262 ++pcPresc;
bogdanm 0:9b334a45a8ff 263 clkDiv = (uint32_t)1UL << pcPresc;
bogdanm 0:9b334a45a8ff 264 }
bogdanm 0:9b334a45a8ff 265
bogdanm 0:9b334a45a8ff 266 /* Calculate pcTop value. */
bogdanm 0:9b334a45a8ff 267 pcTop = ((uint32_t)refFreq / ((uint32_t)scanFreq * clkDiv)) - 1UL;
bogdanm 0:9b334a45a8ff 268
bogdanm 0:9b334a45a8ff 269 /* Clear current PCPRESC and PCTOP settings. Be aware of the effect of
bogdanm 0:9b334a45a8ff 270 * non-atomic Read-Modify-Write on LESENSE->TIMCRTL. */
bogdanm 0:9b334a45a8ff 271 tmp = LESENSE->TIMCTRL & (~(_LESENSE_TIMCTRL_PCPRESC_MASK)&
bogdanm 0:9b334a45a8ff 272 ~(_LESENSE_TIMCTRL_PCTOP_MASK));
bogdanm 0:9b334a45a8ff 273
bogdanm 0:9b334a45a8ff 274 /* Set new values in tmp while reserving other settings. */
bogdanm 0:9b334a45a8ff 275 tmp |= ((uint32_t)pcPresc << _LESENSE_TIMCTRL_PCPRESC_SHIFT) |
bogdanm 0:9b334a45a8ff 276 ((uint32_t)pcTop << _LESENSE_TIMCTRL_PCTOP_SHIFT);
bogdanm 0:9b334a45a8ff 277
bogdanm 0:9b334a45a8ff 278 /* Set values in LESENSE_TIMCTRL register. */
bogdanm 0:9b334a45a8ff 279 LESENSE->TIMCTRL = tmp;
bogdanm 0:9b334a45a8ff 280
bogdanm 0:9b334a45a8ff 281 /* For testing the calculation algorithm. */
bogdanm 0:9b334a45a8ff 282 calcScanFreq = ((uint32_t)refFreq / ((uint32_t)(1UL + pcTop) * clkDiv));
bogdanm 0:9b334a45a8ff 283
bogdanm 0:9b334a45a8ff 284 return calcScanFreq;
bogdanm 0:9b334a45a8ff 285 }
bogdanm 0:9b334a45a8ff 286
bogdanm 0:9b334a45a8ff 287
bogdanm 0:9b334a45a8ff 288 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 289 * @brief
bogdanm 0:9b334a45a8ff 290 * Set scan mode of the LESENSE channels.
bogdanm 0:9b334a45a8ff 291 *
bogdanm 0:9b334a45a8ff 292 * @details
bogdanm 0:9b334a45a8ff 293 * This function configures how the scan start is being triggered. It can be
bogdanm 0:9b334a45a8ff 294 * used for re-configuring the scan mode while running the application but it
bogdanm 0:9b334a45a8ff 295 * is also used by LESENSE_Init() for initialization.
bogdanm 0:9b334a45a8ff 296 *
bogdanm 0:9b334a45a8ff 297 * @note
bogdanm 0:9b334a45a8ff 298 * Users can configure the scan mode by LESENSE_Init() function, but only with
bogdanm 0:9b334a45a8ff 299 * a significant overhead. This simple function serves the purpose of
bogdanm 0:9b334a45a8ff 300 * controlling this parameter after the channel has been configured.
bogdanm 0:9b334a45a8ff 301 * Please be aware the effects of the non-atomic Read-Modify-Write cycle!
bogdanm 0:9b334a45a8ff 302 *
bogdanm 0:9b334a45a8ff 303 * @param[in] scanMode
bogdanm 0:9b334a45a8ff 304 * Select where to map LESENSE alternate excitation channels.
bogdanm 0:9b334a45a8ff 305 * @li lesenseScanStartPeriodic - New scan is started each time the period
bogdanm 0:9b334a45a8ff 306 * counter overflows.
bogdanm 0:9b334a45a8ff 307 * @li lesenseScanStartOneShot - Single scan is performed when
bogdanm 0:9b334a45a8ff 308 * LESENSE_ScanStart() is called.
bogdanm 0:9b334a45a8ff 309 * @li lesenseScanStartPRS - New scan is triggered by pulse on PRS channel.
bogdanm 0:9b334a45a8ff 310 *
bogdanm 0:9b334a45a8ff 311 * @param[in] start
bogdanm 0:9b334a45a8ff 312 * If true, LESENSE_ScanStart() is immediately issued after configuration.
bogdanm 0:9b334a45a8ff 313 ******************************************************************************/
bogdanm 0:9b334a45a8ff 314 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,
bogdanm 0:9b334a45a8ff 315 bool const start)
bogdanm 0:9b334a45a8ff 316 {
bogdanm 0:9b334a45a8ff 317 uint32_t tmp; /* temporary storage of the CTRL register value */
bogdanm 0:9b334a45a8ff 318
bogdanm 0:9b334a45a8ff 319
bogdanm 0:9b334a45a8ff 320 /* Save the CTRL register value to tmp.
bogdanm 0:9b334a45a8ff 321 * Please be aware the effects of the non-atomic Read-Modify-Write cycle! */
bogdanm 0:9b334a45a8ff 322 tmp = LESENSE->CTRL & ~(_LESENSE_CTRL_SCANMODE_MASK);
bogdanm 0:9b334a45a8ff 323 /* Setting the requested scanMode to the CTRL register. Casting signed int
bogdanm 0:9b334a45a8ff 324 * (enum) to unsigned long (uint32_t). */
bogdanm 0:9b334a45a8ff 325 tmp |= (uint32_t)scanMode;
bogdanm 0:9b334a45a8ff 326
bogdanm 0:9b334a45a8ff 327 /* Write the new value to the CTRL register. */
bogdanm 0:9b334a45a8ff 328 LESENSE->CTRL = tmp;
bogdanm 0:9b334a45a8ff 329
bogdanm 0:9b334a45a8ff 330 /* Start sensor scanning if requested. */
bogdanm 0:9b334a45a8ff 331 if (start)
bogdanm 0:9b334a45a8ff 332 {
bogdanm 0:9b334a45a8ff 333 LESENSE_ScanStart();
bogdanm 0:9b334a45a8ff 334 }
bogdanm 0:9b334a45a8ff 335 }
bogdanm 0:9b334a45a8ff 336
bogdanm 0:9b334a45a8ff 337
bogdanm 0:9b334a45a8ff 338 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 339 * @brief
bogdanm 0:9b334a45a8ff 340 * Set start delay of sensor interaction on each channel.
bogdanm 0:9b334a45a8ff 341 *
bogdanm 0:9b334a45a8ff 342 * @details
bogdanm 0:9b334a45a8ff 343 * This function sets start delay of sensor interaction on each channel.
bogdanm 0:9b334a45a8ff 344 * It can be used for adjusting the start delay while running the application
bogdanm 0:9b334a45a8ff 345 * but it is also used by LESENSE_Init() for initialization.
bogdanm 0:9b334a45a8ff 346 *
bogdanm 0:9b334a45a8ff 347 * @note
bogdanm 0:9b334a45a8ff 348 * Users can configure the start delay by LESENSE_Init() function, but only
bogdanm 0:9b334a45a8ff 349 * with a significant overhead. This simple function serves the purpose of
bogdanm 0:9b334a45a8ff 350 * controlling this parameter after the channel has been configured.
bogdanm 0:9b334a45a8ff 351 * Please be aware the effects of the non-atomic Read-Modify-Write cycle!
bogdanm 0:9b334a45a8ff 352 *
bogdanm 0:9b334a45a8ff 353 * @param[in] startDelay
bogdanm 0:9b334a45a8ff 354 * Number of LFACLK cycles to delay. Valid range: 0-3 (2 bit).
bogdanm 0:9b334a45a8ff 355 ******************************************************************************/
bogdanm 0:9b334a45a8ff 356 void LESENSE_StartDelaySet(uint8_t const startDelay)
bogdanm 0:9b334a45a8ff 357 {
bogdanm 0:9b334a45a8ff 358 uint32_t tmp; /* temporary storage of the TIMCTRL register value */
bogdanm 0:9b334a45a8ff 359
bogdanm 0:9b334a45a8ff 360
bogdanm 0:9b334a45a8ff 361 /* Sanity check of startDelay. */
bogdanm 0:9b334a45a8ff 362 EFM_ASSERT(startDelay < 4U);
bogdanm 0:9b334a45a8ff 363
bogdanm 0:9b334a45a8ff 364 /* Save the TIMCTRL register value to tmp.
bogdanm 0:9b334a45a8ff 365 * Please be aware the effects of the non-atomic Read-Modify-Write cycle! */
bogdanm 0:9b334a45a8ff 366 tmp = LESENSE->TIMCTRL & ~(_LESENSE_TIMCTRL_STARTDLY_MASK);
bogdanm 0:9b334a45a8ff 367 /* Setting the requested startDelay to the TIMCTRL register. */
bogdanm 0:9b334a45a8ff 368 tmp |= (uint32_t)startDelay << _LESENSE_TIMCTRL_STARTDLY_SHIFT;
bogdanm 0:9b334a45a8ff 369
bogdanm 0:9b334a45a8ff 370 /* Write the new value to the TIMCTRL register. */
bogdanm 0:9b334a45a8ff 371 LESENSE->TIMCTRL = tmp;
bogdanm 0:9b334a45a8ff 372 }
bogdanm 0:9b334a45a8ff 373
bogdanm 0:9b334a45a8ff 374
bogdanm 0:9b334a45a8ff 375 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 376 * @brief
bogdanm 0:9b334a45a8ff 377 * Set clock division for LESENSE timers.
bogdanm 0:9b334a45a8ff 378 *
bogdanm 0:9b334a45a8ff 379 * @details
bogdanm 0:9b334a45a8ff 380 * Use this function to configure the clock division for the LESENSE timers
bogdanm 0:9b334a45a8ff 381 * used for excitation timing.
bogdanm 0:9b334a45a8ff 382 * The division setting is global, but the clock source can be selected for
bogdanm 0:9b334a45a8ff 383 * each channel using LESENSE_ChannelConfig() function, please refer to the
bogdanm 0:9b334a45a8ff 384 * documentation of it for more details.
bogdanm 0:9b334a45a8ff 385 *
bogdanm 0:9b334a45a8ff 386 * @note
bogdanm 0:9b334a45a8ff 387 * If AUXHFRCO is used for excitation timing, LFACLK can not exceed 500kHz.
bogdanm 0:9b334a45a8ff 388 * LFACLK can not exceed 50kHz if the ACMP threshold level (ACMPTHRES) is not
bogdanm 0:9b334a45a8ff 389 * equal for all channels.
bogdanm 0:9b334a45a8ff 390 *
bogdanm 0:9b334a45a8ff 391 * @param[in] clk
bogdanm 0:9b334a45a8ff 392 * Select clock to prescale.
bogdanm 0:9b334a45a8ff 393 * @li lesenseClkHF - set AUXHFRCO clock divisor for HF timer.
bogdanm 0:9b334a45a8ff 394 * @li lesenseClkLF - set LFACLKles clock divisor for LF timer.
bogdanm 0:9b334a45a8ff 395 *
bogdanm 0:9b334a45a8ff 396 * @param[in] clkDiv
bogdanm 0:9b334a45a8ff 397 * Clock divisor value. Valid range depends on the @p clk value.
bogdanm 0:9b334a45a8ff 398 ******************************************************************************/
bogdanm 0:9b334a45a8ff 399 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
bogdanm 0:9b334a45a8ff 400 LESENSE_ClkPresc_TypeDef const clkDiv)
bogdanm 0:9b334a45a8ff 401 {
bogdanm 0:9b334a45a8ff 402 uint32_t tmp;
bogdanm 0:9b334a45a8ff 403
bogdanm 0:9b334a45a8ff 404
bogdanm 0:9b334a45a8ff 405 /* Select clock to prescale */
bogdanm 0:9b334a45a8ff 406 switch (clk)
bogdanm 0:9b334a45a8ff 407 {
bogdanm 0:9b334a45a8ff 408 case lesenseClkHF:
bogdanm 0:9b334a45a8ff 409 {
bogdanm 0:9b334a45a8ff 410 /* Sanity check of clock divisor for HF clock. */
bogdanm 0:9b334a45a8ff 411 EFM_ASSERT((uint32_t)clkDiv <= lesenseClkDiv_8);
bogdanm 0:9b334a45a8ff 412
bogdanm 0:9b334a45a8ff 413 /* Clear current AUXPRESC settings. */
bogdanm 0:9b334a45a8ff 414 tmp = LESENSE->TIMCTRL & ~(_LESENSE_TIMCTRL_AUXPRESC_MASK);
bogdanm 0:9b334a45a8ff 415
bogdanm 0:9b334a45a8ff 416 /* Set new values in tmp while reserving other settings. */
bogdanm 0:9b334a45a8ff 417 tmp |= ((uint32_t)clkDiv << _LESENSE_TIMCTRL_AUXPRESC_SHIFT);
bogdanm 0:9b334a45a8ff 418
bogdanm 0:9b334a45a8ff 419 /* Set values in LESENSE_TIMCTRL register. */
bogdanm 0:9b334a45a8ff 420 LESENSE->TIMCTRL = tmp;
bogdanm 0:9b334a45a8ff 421 }
bogdanm 0:9b334a45a8ff 422 break;
bogdanm 0:9b334a45a8ff 423
bogdanm 0:9b334a45a8ff 424 case lesenseClkLF:
bogdanm 0:9b334a45a8ff 425 {
bogdanm 0:9b334a45a8ff 426 /* Clear current LFPRESC settings. */
bogdanm 0:9b334a45a8ff 427 tmp = LESENSE->TIMCTRL & ~(_LESENSE_TIMCTRL_LFPRESC_MASK);
bogdanm 0:9b334a45a8ff 428
bogdanm 0:9b334a45a8ff 429 /* Set new values in tmp while reserving other settings. */
bogdanm 0:9b334a45a8ff 430 tmp |= ((uint32_t)clkDiv << _LESENSE_TIMCTRL_LFPRESC_SHIFT);
bogdanm 0:9b334a45a8ff 431
bogdanm 0:9b334a45a8ff 432 /* Set values in LESENSE_TIMCTRL register. */
bogdanm 0:9b334a45a8ff 433 LESENSE->TIMCTRL = tmp;
bogdanm 0:9b334a45a8ff 434 }
bogdanm 0:9b334a45a8ff 435 break;
bogdanm 0:9b334a45a8ff 436
bogdanm 0:9b334a45a8ff 437 default:
bogdanm 0:9b334a45a8ff 438 {
bogdanm 0:9b334a45a8ff 439 EFM_ASSERT(0);
bogdanm 0:9b334a45a8ff 440 }
bogdanm 0:9b334a45a8ff 441 break;
bogdanm 0:9b334a45a8ff 442 }
bogdanm 0:9b334a45a8ff 443 }
bogdanm 0:9b334a45a8ff 444
bogdanm 0:9b334a45a8ff 445
bogdanm 0:9b334a45a8ff 446 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 447 * @brief
bogdanm 0:9b334a45a8ff 448 * Configure all (16) LESENSE sensor channels.
bogdanm 0:9b334a45a8ff 449 *
bogdanm 0:9b334a45a8ff 450 * @details
bogdanm 0:9b334a45a8ff 451 * This function configures all the sensor channels of LESENSE interface.
bogdanm 0:9b334a45a8ff 452 * Please refer to the configuration parameter type definition
bogdanm 0:9b334a45a8ff 453 * (LESENSE_ChAll_TypeDef) for more details.
bogdanm 0:9b334a45a8ff 454 *
bogdanm 0:9b334a45a8ff 455 * @note
bogdanm 0:9b334a45a8ff 456 * Channels can be configured individually using LESENSE_ChannelConfig()
bogdanm 0:9b334a45a8ff 457 * function.
bogdanm 0:9b334a45a8ff 458 * Notice that pins used by the LESENSE module must be properly configured
bogdanm 0:9b334a45a8ff 459 * by the user explicitly, in order for the LESENSE to work as intended.
bogdanm 0:9b334a45a8ff 460 * (When configuring pins, one should remember to consider the sequence of
bogdanm 0:9b334a45a8ff 461 * configuration, in order to avoid unintended pulses/glitches on output
bogdanm 0:9b334a45a8ff 462 * pins.)
bogdanm 0:9b334a45a8ff 463 *
bogdanm 0:9b334a45a8ff 464 * @param[in] confChAll
bogdanm 0:9b334a45a8ff 465 * Configuration structure for all (16) LESENSE sensor channels.
bogdanm 0:9b334a45a8ff 466 ******************************************************************************/
bogdanm 0:9b334a45a8ff 467 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll)
bogdanm 0:9b334a45a8ff 468 {
bogdanm 0:9b334a45a8ff 469 uint32_t i;
bogdanm 0:9b334a45a8ff 470
bogdanm 0:9b334a45a8ff 471
bogdanm 0:9b334a45a8ff 472 /* Iterate through all the 16 channels */
bogdanm 0:9b334a45a8ff 473 for (i = 0U; i < 16U; ++i)
bogdanm 0:9b334a45a8ff 474 {
bogdanm 0:9b334a45a8ff 475 /* Configure scan channels. */
bogdanm 0:9b334a45a8ff 476 LESENSE_ChannelConfig(&confChAll->Ch[i], i);
bogdanm 0:9b334a45a8ff 477 }
bogdanm 0:9b334a45a8ff 478 }
bogdanm 0:9b334a45a8ff 479
bogdanm 0:9b334a45a8ff 480
bogdanm 0:9b334a45a8ff 481 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 482 * @brief
bogdanm 0:9b334a45a8ff 483 * Configure a single LESENSE sensor channel.
bogdanm 0:9b334a45a8ff 484 *
bogdanm 0:9b334a45a8ff 485 * @details
bogdanm 0:9b334a45a8ff 486 * This function configures a single sensor channel of the LESENSE interface.
bogdanm 0:9b334a45a8ff 487 * Please refer to the configuration parameter type definition
bogdanm 0:9b334a45a8ff 488 * (LESENSE_ChDesc_TypeDef) for more details.
bogdanm 0:9b334a45a8ff 489 *
bogdanm 0:9b334a45a8ff 490 * @note
bogdanm 0:9b334a45a8ff 491 * This function has been designed to minimize the effects of sensor channel
bogdanm 0:9b334a45a8ff 492 * reconfiguration while LESENSE is in operation, however one shall be aware
bogdanm 0:9b334a45a8ff 493 * of these effects and the right timing of calling this function.
bogdanm 0:9b334a45a8ff 494 * Parameter @p useAltEx must be true in the channel configuration in order to
bogdanm 0:9b334a45a8ff 495 * use alternate excitation pins.
bogdanm 0:9b334a45a8ff 496 *
bogdanm 0:9b334a45a8ff 497 * @param[in] confCh
bogdanm 0:9b334a45a8ff 498 * Configuration structure for a single LESENSE sensor channel.
bogdanm 0:9b334a45a8ff 499 *
bogdanm 0:9b334a45a8ff 500 * @param[in] chIdx
bogdanm 0:9b334a45a8ff 501 * Channel index to configure (0-15).
bogdanm 0:9b334a45a8ff 502 ******************************************************************************/
bogdanm 0:9b334a45a8ff 503 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,
bogdanm 0:9b334a45a8ff 504 uint32_t const chIdx)
bogdanm 0:9b334a45a8ff 505 {
bogdanm 0:9b334a45a8ff 506 uint32_t tmp; /* Service variable. */
bogdanm 0:9b334a45a8ff 507
bogdanm 0:9b334a45a8ff 508
bogdanm 0:9b334a45a8ff 509 /* Sanity check of configuration parameters */
bogdanm 0:9b334a45a8ff 510 EFM_ASSERT(chIdx < 16U);
bogdanm 0:9b334a45a8ff 511 EFM_ASSERT(confCh->exTime < 64U);
bogdanm 0:9b334a45a8ff 512 EFM_ASSERT(confCh->sampleDelay < 128U);
bogdanm 0:9b334a45a8ff 513 EFM_ASSERT(confCh->measDelay < 128U);
bogdanm 0:9b334a45a8ff 514 /* Not a complete assert, as the max. value of acmpThres depends on other
bogdanm 0:9b334a45a8ff 515 * configuration parameters, check the parameter description of acmpThres for
bogdanm 0:9b334a45a8ff 516 * for more details! */
bogdanm 0:9b334a45a8ff 517 EFM_ASSERT(confCh->acmpThres < 4096U);
bogdanm 0:9b334a45a8ff 518 EFM_ASSERT(!(confCh->chPinExMode == lesenseChPinExDACOut &&
bogdanm 0:9b334a45a8ff 519 (chIdx != 2U) && (chIdx != 3U) && (chIdx != 4U) && (chIdx != 5U)));
bogdanm 0:9b334a45a8ff 520 EFM_ASSERT(!(confCh->chPinIdleMode == lesenseChPinIdleDACCh1 &&
bogdanm 0:9b334a45a8ff 521 ((chIdx != 12U) && (chIdx != 13U) && (chIdx != 14U) && (chIdx != 15U))));
bogdanm 0:9b334a45a8ff 522 EFM_ASSERT(!(confCh->chPinIdleMode == lesenseChPinIdleDACCh0 &&
bogdanm 0:9b334a45a8ff 523 ((chIdx != 0U) && (chIdx != 1U) && (chIdx != 2U) && (chIdx != 3U))));
bogdanm 0:9b334a45a8ff 524
bogdanm 0:9b334a45a8ff 525
bogdanm 0:9b334a45a8ff 526 /* Configure chIdx setup in LESENSE idle phase.
bogdanm 0:9b334a45a8ff 527 * Read-modify-write in order to support reconfiguration during LESENSE
bogdanm 0:9b334a45a8ff 528 * operation. */
bogdanm 0:9b334a45a8ff 529 tmp = (LESENSE->IDLECONF & ~((uint32_t)0x3UL << (chIdx * 2UL)));
bogdanm 0:9b334a45a8ff 530 tmp |= ((uint32_t)confCh->chPinIdleMode << (chIdx * 2UL));
bogdanm 0:9b334a45a8ff 531 LESENSE->IDLECONF = tmp;
bogdanm 0:9b334a45a8ff 532
bogdanm 0:9b334a45a8ff 533 /* Channel specific timing configuration on scan channel chIdx.
bogdanm 0:9b334a45a8ff 534 * Set excitation time, sampling delay, measurement delay. */
bogdanm 0:9b334a45a8ff 535 LESENSE_ChannelTimingSet(chIdx,
bogdanm 0:9b334a45a8ff 536 (uint32_t)confCh->exTime,
bogdanm 0:9b334a45a8ff 537 (uint32_t)confCh->sampleDelay,
bogdanm 0:9b334a45a8ff 538 (uint32_t)confCh->measDelay);
bogdanm 0:9b334a45a8ff 539
bogdanm 0:9b334a45a8ff 540 /* Channel specific configuration of clocks, sample mode, excitation pin mode
bogdanm 0:9b334a45a8ff 541 * alternate excitation usage and interrupt mode on scan channel chIdx in
bogdanm 0:9b334a45a8ff 542 * LESENSE_CHchIdx_INTERACT. */
bogdanm 0:9b334a45a8ff 543 LESENSE->CH[chIdx].INTERACT = ((uint32_t)confCh->exClk <<
bogdanm 0:9b334a45a8ff 544 _LESENSE_CH_INTERACT_EXCLK_SHIFT) |
bogdanm 0:9b334a45a8ff 545 ((uint32_t)confCh->sampleClk <<
bogdanm 0:9b334a45a8ff 546 _LESENSE_CH_INTERACT_SAMPLECLK_SHIFT) |
bogdanm 0:9b334a45a8ff 547 (uint32_t)confCh->sampleMode |
bogdanm 0:9b334a45a8ff 548 (uint32_t)confCh->intMode |
bogdanm 0:9b334a45a8ff 549 (uint32_t)confCh->chPinExMode |
bogdanm 0:9b334a45a8ff 550 ((uint32_t)confCh->useAltEx <<
bogdanm 0:9b334a45a8ff 551 _LESENSE_CH_INTERACT_ALTEX_SHIFT);
bogdanm 0:9b334a45a8ff 552
bogdanm 0:9b334a45a8ff 553 /* Configure channel specific counter comparison mode, optional result
bogdanm 0:9b334a45a8ff 554 * forwarding to decoder, optional counter value storing and optional result
bogdanm 0:9b334a45a8ff 555 * inverting on scan channel chIdx in LESENSE_CHchIdx_EVAL. */
bogdanm 0:9b334a45a8ff 556 LESENSE->CH[chIdx].EVAL = (uint32_t)confCh->compMode |
bogdanm 0:9b334a45a8ff 557 ((uint32_t)confCh->shiftRes <<
bogdanm 0:9b334a45a8ff 558 _LESENSE_CH_EVAL_DECODE_SHIFT) |
bogdanm 0:9b334a45a8ff 559 ((uint32_t)confCh->storeCntRes <<
bogdanm 0:9b334a45a8ff 560 _LESENSE_CH_EVAL_STRSAMPLE_SHIFT) |
bogdanm 0:9b334a45a8ff 561 ((uint32_t)confCh->invRes <<
bogdanm 0:9b334a45a8ff 562 _LESENSE_CH_EVAL_SCANRESINV_SHIFT);
bogdanm 0:9b334a45a8ff 563
bogdanm 0:9b334a45a8ff 564 /* Configure analog comparator (ACMP) threshold and decision threshold for
bogdanm 0:9b334a45a8ff 565 * counter separately with the function provided for that. */
bogdanm 0:9b334a45a8ff 566 LESENSE_ChannelThresSet(chIdx,
bogdanm 0:9b334a45a8ff 567 (uint32_t)confCh->acmpThres,
bogdanm 0:9b334a45a8ff 568 (uint32_t)confCh->cntThres);
bogdanm 0:9b334a45a8ff 569
bogdanm 0:9b334a45a8ff 570 /* Enable/disable interrupts on channel.
bogdanm 0:9b334a45a8ff 571 * Note: BITBAND_Peripheral() function is used for setting/clearing single
bogdanm 0:9b334a45a8ff 572 * bit peripheral register bitfields. Read the function description in
bogdanm 0:9b334a45a8ff 573 * efm32_bitband.h for more details. */
bogdanm 0:9b334a45a8ff 574 BITBAND_Peripheral(&(LESENSE->IEN),
bogdanm 0:9b334a45a8ff 575 (uint32_t)chIdx,
bogdanm 0:9b334a45a8ff 576 (uint32_t)confCh->enaInt);
bogdanm 0:9b334a45a8ff 577
bogdanm 0:9b334a45a8ff 578 /* Enable/disable CHchIdx pin. */
bogdanm 0:9b334a45a8ff 579 BITBAND_Peripheral(&(LESENSE->ROUTE),
bogdanm 0:9b334a45a8ff 580 (uint32_t)chIdx,
bogdanm 0:9b334a45a8ff 581 (uint32_t)confCh->enaPin);
bogdanm 0:9b334a45a8ff 582
bogdanm 0:9b334a45a8ff 583 /* Enable/disable scan channel chIdx. */
bogdanm 0:9b334a45a8ff 584 BITBAND_Peripheral(&(LESENSE->CHEN),
bogdanm 0:9b334a45a8ff 585 (uint32_t)chIdx,
bogdanm 0:9b334a45a8ff 586 (uint32_t)confCh->enaScanCh);
bogdanm 0:9b334a45a8ff 587 }
bogdanm 0:9b334a45a8ff 588
bogdanm 0:9b334a45a8ff 589
bogdanm 0:9b334a45a8ff 590 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 591 * @brief
bogdanm 0:9b334a45a8ff 592 * Configure the LESENSE alternate excitation modes.
bogdanm 0:9b334a45a8ff 593 *
bogdanm 0:9b334a45a8ff 594 * @details
bogdanm 0:9b334a45a8ff 595 * This function configures the alternate excitation channels of the LESENSE
bogdanm 0:9b334a45a8ff 596 * interface. Please refer to the configuration parameter type definition
bogdanm 0:9b334a45a8ff 597 * (LESENSE_ConfAltEx_TypeDef) for more details.
bogdanm 0:9b334a45a8ff 598 *
bogdanm 0:9b334a45a8ff 599 * @note
bogdanm 0:9b334a45a8ff 600 * Parameter @p useAltEx must be true in the channel configuration structrure
bogdanm 0:9b334a45a8ff 601 * (LESENSE_ChDesc_TypeDef) in order to use alternate excitation pins on the
bogdanm 0:9b334a45a8ff 602 * channel.
bogdanm 0:9b334a45a8ff 603 *
bogdanm 0:9b334a45a8ff 604 * @param[in] confAltEx
bogdanm 0:9b334a45a8ff 605 * Configuration structure for LESENSE alternate excitation pins.
bogdanm 0:9b334a45a8ff 606 ******************************************************************************/
bogdanm 0:9b334a45a8ff 607 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx)
bogdanm 0:9b334a45a8ff 608 {
bogdanm 0:9b334a45a8ff 609 uint32_t i;
bogdanm 0:9b334a45a8ff 610 uint32_t tmp;
bogdanm 0:9b334a45a8ff 611
bogdanm 0:9b334a45a8ff 612
bogdanm 0:9b334a45a8ff 613 /* Configure alternate excitation mapping.
bogdanm 0:9b334a45a8ff 614 * Atomic read-modify-write using BITBAND_Peripheral function in order to
bogdanm 0:9b334a45a8ff 615 * support reconfiguration during LESENSE operation. */
bogdanm 0:9b334a45a8ff 616 BITBAND_Peripheral(&(LESENSE->CTRL),
bogdanm 0:9b334a45a8ff 617 _LESENSE_CTRL_ALTEXMAP_SHIFT,
bogdanm 0:9b334a45a8ff 618 (uint32_t)confAltEx->altExMap);
bogdanm 0:9b334a45a8ff 619
bogdanm 0:9b334a45a8ff 620 switch (confAltEx->altExMap)
bogdanm 0:9b334a45a8ff 621 {
bogdanm 0:9b334a45a8ff 622 case lesenseAltExMapALTEX:
bogdanm 0:9b334a45a8ff 623 /* Iterate through the 8 possible alternate excitation pin descriptors. */
bogdanm 0:9b334a45a8ff 624 for (i = 0U; i < 8U; ++i)
bogdanm 0:9b334a45a8ff 625 {
bogdanm 0:9b334a45a8ff 626 /* Enable/disable alternate excitation pin i.
bogdanm 0:9b334a45a8ff 627 * Atomic read-modify-write using BITBAND_Peripheral function in order to
bogdanm 0:9b334a45a8ff 628 * support reconfiguration during LESENSE operation. */
bogdanm 0:9b334a45a8ff 629 BITBAND_Peripheral(&(LESENSE->ROUTE),
bogdanm 0:9b334a45a8ff 630 (16UL + i),
bogdanm 0:9b334a45a8ff 631 (uint32_t)confAltEx->AltEx[i].enablePin);
bogdanm 0:9b334a45a8ff 632
bogdanm 0:9b334a45a8ff 633 /* Setup the idle phase state of alternate excitation pin i.
bogdanm 0:9b334a45a8ff 634 * Read-modify-write in order to support reconfiguration during LESENSE
bogdanm 0:9b334a45a8ff 635 * operation. */
bogdanm 0:9b334a45a8ff 636 tmp = (LESENSE->ALTEXCONF & ~((uint32_t)0x3UL << (i * 2UL)));
bogdanm 0:9b334a45a8ff 637 tmp |= ((uint32_t)confAltEx->AltEx[i].idleConf << (i * 2UL));
bogdanm 0:9b334a45a8ff 638 LESENSE->ALTEXCONF = tmp;
bogdanm 0:9b334a45a8ff 639
bogdanm 0:9b334a45a8ff 640 /* Enable/disable always excite on channel i */
bogdanm 0:9b334a45a8ff 641 BITBAND_Peripheral(&(LESENSE->ALTEXCONF),
bogdanm 0:9b334a45a8ff 642 (16UL + i),
bogdanm 0:9b334a45a8ff 643 (uint32_t)confAltEx->AltEx[i].alwaysEx);
bogdanm 0:9b334a45a8ff 644 }
bogdanm 0:9b334a45a8ff 645 break;
bogdanm 0:9b334a45a8ff 646
bogdanm 0:9b334a45a8ff 647 case lesenseAltExMapACMP:
bogdanm 0:9b334a45a8ff 648 /* Iterate through all the 16 alternate excitation channels */
bogdanm 0:9b334a45a8ff 649 for (i = 0U; i < 16U; ++i)
bogdanm 0:9b334a45a8ff 650 {
bogdanm 0:9b334a45a8ff 651 /* Enable/disable alternate ACMP excitation channel pin i. */
bogdanm 0:9b334a45a8ff 652 /* Atomic read-modify-write using BITBAND_Peripheral function in order to
bogdanm 0:9b334a45a8ff 653 * support reconfiguration during LESENSE operation. */
bogdanm 0:9b334a45a8ff 654 BITBAND_Peripheral(&(LESENSE->ROUTE),
bogdanm 0:9b334a45a8ff 655 i,
bogdanm 0:9b334a45a8ff 656 (uint32_t)confAltEx->AltEx[i].enablePin);
bogdanm 0:9b334a45a8ff 657 }
bogdanm 0:9b334a45a8ff 658 break;
bogdanm 0:9b334a45a8ff 659 default:
bogdanm 0:9b334a45a8ff 660 /* Illegal value. */
bogdanm 0:9b334a45a8ff 661 EFM_ASSERT(0);
bogdanm 0:9b334a45a8ff 662 }
bogdanm 0:9b334a45a8ff 663 }
bogdanm 0:9b334a45a8ff 664
bogdanm 0:9b334a45a8ff 665
bogdanm 0:9b334a45a8ff 666 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 667 * @brief
bogdanm 0:9b334a45a8ff 668 * Enable/disable LESENSE scan channel and the pin assigned to it.
bogdanm 0:9b334a45a8ff 669 *
bogdanm 0:9b334a45a8ff 670 * @details
bogdanm 0:9b334a45a8ff 671 * Use this function to enable/disable a selected LESENSE scan channel and the
bogdanm 0:9b334a45a8ff 672 * pin assigned to.
bogdanm 0:9b334a45a8ff 673 *
bogdanm 0:9b334a45a8ff 674 * @note
bogdanm 0:9b334a45a8ff 675 * Users can enable/disable scan channels and the channel pin by
bogdanm 0:9b334a45a8ff 676 * LESENSE_ChannelConfig() function, but only with a significant overhead.
bogdanm 0:9b334a45a8ff 677 * This simple function serves the purpose of controlling these parameters
bogdanm 0:9b334a45a8ff 678 * after the channel has been configured.
bogdanm 0:9b334a45a8ff 679 *
bogdanm 0:9b334a45a8ff 680 * @param[in] chIdx
bogdanm 0:9b334a45a8ff 681 * Identifier of the scan channel. Valid range: 0-15.
bogdanm 0:9b334a45a8ff 682 *
bogdanm 0:9b334a45a8ff 683 * @param[in] enaScanCh
bogdanm 0:9b334a45a8ff 684 * Enable/disable the selected scan channel by setting this parameter to
bogdanm 0:9b334a45a8ff 685 * true/false respectively.
bogdanm 0:9b334a45a8ff 686 *
bogdanm 0:9b334a45a8ff 687 * @param[in] enaPin
bogdanm 0:9b334a45a8ff 688 * Enable/disable the pin assigned to the channel selected by @p chIdx.
bogdanm 0:9b334a45a8ff 689 ******************************************************************************/
bogdanm 0:9b334a45a8ff 690 void LESENSE_ChannelEnable(uint8_t const chIdx,
bogdanm 0:9b334a45a8ff 691 bool const enaScanCh,
bogdanm 0:9b334a45a8ff 692 bool const enaPin)
bogdanm 0:9b334a45a8ff 693 {
bogdanm 0:9b334a45a8ff 694 /* Enable/disable the assigned pin of scan channel chIdx.
bogdanm 0:9b334a45a8ff 695 * Note: BITBAND_Peripheral() function is used for setting/clearing single
bogdanm 0:9b334a45a8ff 696 * bit peripheral register bitfields. Read the function description in
bogdanm 0:9b334a45a8ff 697 * efm32_bitband.h for more details. */
bogdanm 0:9b334a45a8ff 698 BITBAND_Peripheral(&(LESENSE->ROUTE),
bogdanm 0:9b334a45a8ff 699 (uint32_t)chIdx,
bogdanm 0:9b334a45a8ff 700 (uint32_t)enaPin);
bogdanm 0:9b334a45a8ff 701
bogdanm 0:9b334a45a8ff 702 /* Enable/disable scan channel chIdx. */
bogdanm 0:9b334a45a8ff 703 BITBAND_Peripheral(&(LESENSE->CHEN),
bogdanm 0:9b334a45a8ff 704 (uint32_t)chIdx,
bogdanm 0:9b334a45a8ff 705 (uint32_t)enaScanCh);
bogdanm 0:9b334a45a8ff 706 }
bogdanm 0:9b334a45a8ff 707
bogdanm 0:9b334a45a8ff 708
bogdanm 0:9b334a45a8ff 709 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 710 * @brief
bogdanm 0:9b334a45a8ff 711 * Enable/disable LESENSE scan channel and the pin assigned to it.
bogdanm 0:9b334a45a8ff 712 *
bogdanm 0:9b334a45a8ff 713 * @details
bogdanm 0:9b334a45a8ff 714 * Use this function to enable/disable LESENSE scan channels and the pins
bogdanm 0:9b334a45a8ff 715 * assigned to them using a mask.
bogdanm 0:9b334a45a8ff 716 *
bogdanm 0:9b334a45a8ff 717 * @note
bogdanm 0:9b334a45a8ff 718 * Users can enable/disable scan channels and channel pins by using
bogdanm 0:9b334a45a8ff 719 * LESENSE_ChannelAllConfig() function, but only with a significant overhead.
bogdanm 0:9b334a45a8ff 720 * This simple function serves the purpose of controlling these parameters
bogdanm 0:9b334a45a8ff 721 * after the channel has been configured.
bogdanm 0:9b334a45a8ff 722 *
bogdanm 0:9b334a45a8ff 723 * @param[in] chMask
bogdanm 0:9b334a45a8ff 724 * Set the corresponding bit to 1 to enable, 0 to disable the selected scan
bogdanm 0:9b334a45a8ff 725 * channel.
bogdanm 0:9b334a45a8ff 726 *
bogdanm 0:9b334a45a8ff 727 * @param[in] pinMask
bogdanm 0:9b334a45a8ff 728 * Set the corresponding bit to 1 to enable, 0 to disable the pin on selected
bogdanm 0:9b334a45a8ff 729 * channel.
bogdanm 0:9b334a45a8ff 730 ******************************************************************************/
bogdanm 0:9b334a45a8ff 731 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask)
bogdanm 0:9b334a45a8ff 732 {
bogdanm 0:9b334a45a8ff 733 /* Enable/disable all channels at once according to the mask. */
bogdanm 0:9b334a45a8ff 734 LESENSE->CHEN = chMask;
bogdanm 0:9b334a45a8ff 735 /* Enable/disable all channel pins at once according to the mask. */
bogdanm 0:9b334a45a8ff 736 LESENSE->ROUTE = pinMask;
bogdanm 0:9b334a45a8ff 737 }
bogdanm 0:9b334a45a8ff 738
bogdanm 0:9b334a45a8ff 739
bogdanm 0:9b334a45a8ff 740 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 741 * @brief
bogdanm 0:9b334a45a8ff 742 * Set LESENSE channel timing parameters.
bogdanm 0:9b334a45a8ff 743 *
bogdanm 0:9b334a45a8ff 744 * @details
bogdanm 0:9b334a45a8ff 745 * Use this function to set timing parameters on a selected LESENSE channel.
bogdanm 0:9b334a45a8ff 746 *
bogdanm 0:9b334a45a8ff 747 * @note
bogdanm 0:9b334a45a8ff 748 * Users can configure the channel timing parameters by
bogdanm 0:9b334a45a8ff 749 * LESENSE_ChannelConfig() function, but only with a significant overhead.
bogdanm 0:9b334a45a8ff 750 * This simple function serves the purpose of controlling these parameters
bogdanm 0:9b334a45a8ff 751 * after the channel has been configured.
bogdanm 0:9b334a45a8ff 752 *
bogdanm 0:9b334a45a8ff 753 * @param[in] chIdx
bogdanm 0:9b334a45a8ff 754 * Identifier of the scan channel. Valid range: 0-15.
bogdanm 0:9b334a45a8ff 755 *
bogdanm 0:9b334a45a8ff 756 * @param[in] exTime
bogdanm 0:9b334a45a8ff 757 * Excitation time on chIdx. Excitation will last exTime+1 excitation clock
bogdanm 0:9b334a45a8ff 758 * cycles. Valid range: 0-63 (6 bits).
bogdanm 0:9b334a45a8ff 759 *
bogdanm 0:9b334a45a8ff 760 * @param[in] sampleDelay
bogdanm 0:9b334a45a8ff 761 * Sample delay on chIdx. Sampling will occur after sampleDelay+1 sample clock
bogdanm 0:9b334a45a8ff 762 * cycles. Valid range: 0-127 (7 bits).
bogdanm 0:9b334a45a8ff 763 *
bogdanm 0:9b334a45a8ff 764 * @param[in] measDelay
bogdanm 0:9b334a45a8ff 765 * Measure delay on chIdx. Sensor measuring is delayed for measDelay+1
bogdanm 0:9b334a45a8ff 766 * excitation clock cycles. Valid range: 0-127 (7 bits).
bogdanm 0:9b334a45a8ff 767 ******************************************************************************/
bogdanm 0:9b334a45a8ff 768 void LESENSE_ChannelTimingSet(uint8_t const chIdx,
bogdanm 0:9b334a45a8ff 769 uint8_t const exTime,
bogdanm 0:9b334a45a8ff 770 uint8_t const sampleDelay,
bogdanm 0:9b334a45a8ff 771 uint8_t const measDelay)
bogdanm 0:9b334a45a8ff 772 {
bogdanm 0:9b334a45a8ff 773 /* Sanity check of parameters. */
bogdanm 0:9b334a45a8ff 774 EFM_ASSERT(exTime < 64U);
bogdanm 0:9b334a45a8ff 775 EFM_ASSERT(sampleDelay < 128U);
bogdanm 0:9b334a45a8ff 776 EFM_ASSERT(measDelay < 128U);
bogdanm 0:9b334a45a8ff 777
bogdanm 0:9b334a45a8ff 778 /* Channel specific timing configuration on scan channel chIdx.
bogdanm 0:9b334a45a8ff 779 * Setting excitation time, sampling delay, measurement delay. */
bogdanm 0:9b334a45a8ff 780 LESENSE->CH[chIdx].TIMING = ((uint32_t)exTime <<
bogdanm 0:9b334a45a8ff 781 _LESENSE_CH_TIMING_EXTIME_SHIFT) |
bogdanm 0:9b334a45a8ff 782 ((uint32_t)sampleDelay <<
bogdanm 0:9b334a45a8ff 783 _LESENSE_CH_TIMING_SAMPLEDLY_SHIFT) |
bogdanm 0:9b334a45a8ff 784 ((uint32_t)measDelay <<
bogdanm 0:9b334a45a8ff 785 _LESENSE_CH_TIMING_MEASUREDLY_SHIFT);
bogdanm 0:9b334a45a8ff 786 }
bogdanm 0:9b334a45a8ff 787
bogdanm 0:9b334a45a8ff 788
bogdanm 0:9b334a45a8ff 789 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 790 * @brief
bogdanm 0:9b334a45a8ff 791 * Set LESENSE channel threshold parameters.
bogdanm 0:9b334a45a8ff 792 *
bogdanm 0:9b334a45a8ff 793 * @details
bogdanm 0:9b334a45a8ff 794 * Use this function to set threshold parameters on a selected LESENSE
bogdanm 0:9b334a45a8ff 795 * channel.
bogdanm 0:9b334a45a8ff 796 *
bogdanm 0:9b334a45a8ff 797 * @note
bogdanm 0:9b334a45a8ff 798 * Users can configure the channel threshold parameters by
bogdanm 0:9b334a45a8ff 799 * LESENSE_ChannelConfig() function, but only with a significant overhead.
bogdanm 0:9b334a45a8ff 800 * This simple function serves the purpose of controlling these parameters
bogdanm 0:9b334a45a8ff 801 * after the channel has been configured.
bogdanm 0:9b334a45a8ff 802 *
bogdanm 0:9b334a45a8ff 803 * @param[in] chIdx
bogdanm 0:9b334a45a8ff 804 * Identifier of the scan channel. Valid range: 0-15.
bogdanm 0:9b334a45a8ff 805 *
bogdanm 0:9b334a45a8ff 806 * @param[in] acmpThres
bogdanm 0:9b334a45a8ff 807 * ACMP threshold.
bogdanm 0:9b334a45a8ff 808 * @li If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to
bogdanm 0:9b334a45a8ff 809 * #lesenseDACIfData, acmpThres defines the 12-bit DAC data in the
bogdanm 0:9b334a45a8ff 810 * corresponding data register of the DAC interface (DACn_CH0DATA and
bogdanm 0:9b334a45a8ff 811 * DACn_CH1DATA). In this case, the valid range is: 0-4095 (12 bits).
bogdanm 0:9b334a45a8ff 812 *
bogdanm 0:9b334a45a8ff 813 * @li If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to
bogdanm 0:9b334a45a8ff 814 * #lesenseACMPThres, acmpThres defines the 6-bit Vdd scaling factor of ACMP
bogdanm 0:9b334a45a8ff 815 * negative input (VDDLEVEL in ACMP_INPUTSEL register). In this case, the
bogdanm 0:9b334a45a8ff 816 * valid range is: 0-63 (6 bits).
bogdanm 0:9b334a45a8ff 817 *
bogdanm 0:9b334a45a8ff 818 * @param[in] cntThres
bogdanm 0:9b334a45a8ff 819 * Decision threshold for counter comparison.
bogdanm 0:9b334a45a8ff 820 * Valid range: 0-65535 (16 bits).
bogdanm 0:9b334a45a8ff 821 ******************************************************************************/
bogdanm 0:9b334a45a8ff 822 void LESENSE_ChannelThresSet(uint8_t const chIdx,
bogdanm 0:9b334a45a8ff 823 uint16_t const acmpThres,
bogdanm 0:9b334a45a8ff 824 uint16_t const cntThres)
bogdanm 0:9b334a45a8ff 825 {
bogdanm 0:9b334a45a8ff 826 uint32_t tmp; /* temporary storage */
bogdanm 0:9b334a45a8ff 827
bogdanm 0:9b334a45a8ff 828
bogdanm 0:9b334a45a8ff 829 /* Sanity check for acmpThres only, cntThres is 16bit value. */
bogdanm 0:9b334a45a8ff 830 EFM_ASSERT(acmpThres < 4096U);
bogdanm 0:9b334a45a8ff 831 /* Sanity check for LESENSE channel id. */
bogdanm 0:9b334a45a8ff 832 EFM_ASSERT(chIdx < 16);
bogdanm 0:9b334a45a8ff 833
bogdanm 0:9b334a45a8ff 834 /* Save the INTERACT register value of channel chIdx to tmp.
bogdanm 0:9b334a45a8ff 835 * Please be aware the effects of the non-atomic Read-Modify-Write cycle! */
bogdanm 0:9b334a45a8ff 836 tmp = LESENSE->CH[chIdx].INTERACT & ~(_LESENSE_CH_INTERACT_ACMPTHRES_MASK);
bogdanm 0:9b334a45a8ff 837 /* Set the ACMP threshold value to the INTERACT register of channel chIdx. */
bogdanm 0:9b334a45a8ff 838 tmp |= (uint32_t)acmpThres << _LESENSE_CH_INTERACT_ACMPTHRES_SHIFT;
bogdanm 0:9b334a45a8ff 839 /* Write the new value to the INTERACT register. */
bogdanm 0:9b334a45a8ff 840 LESENSE->CH[chIdx].INTERACT = tmp;
bogdanm 0:9b334a45a8ff 841
bogdanm 0:9b334a45a8ff 842 /* Save the EVAL register value of channel chIdx to tmp.
bogdanm 0:9b334a45a8ff 843 * Please be aware the effects of the non-atomic Read-Modify-Write cycle! */
bogdanm 0:9b334a45a8ff 844 tmp = LESENSE->CH[chIdx].EVAL & ~(_LESENSE_CH_EVAL_COMPTHRES_MASK);
bogdanm 0:9b334a45a8ff 845 /* Set the counter threshold value to the INTERACT register of channel chIdx. */
bogdanm 0:9b334a45a8ff 846 tmp |= (uint32_t)cntThres << _LESENSE_CH_EVAL_COMPTHRES_SHIFT;
bogdanm 0:9b334a45a8ff 847 /* Write the new value to the EVAL register. */
bogdanm 0:9b334a45a8ff 848 LESENSE->CH[chIdx].EVAL = tmp;
bogdanm 0:9b334a45a8ff 849 }
bogdanm 0:9b334a45a8ff 850
bogdanm 0:9b334a45a8ff 851
bogdanm 0:9b334a45a8ff 852 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 853 * @brief
bogdanm 0:9b334a45a8ff 854 * Configure all LESENSE decoder states.
bogdanm 0:9b334a45a8ff 855 *
bogdanm 0:9b334a45a8ff 856 * @details
bogdanm 0:9b334a45a8ff 857 * This function configures all the decoder states of the LESENSE interface.
bogdanm 0:9b334a45a8ff 858 * Please refer to the configuration parameter type definition
bogdanm 0:9b334a45a8ff 859 * (LESENSE_DecStAll_TypeDef) for more details.
bogdanm 0:9b334a45a8ff 860 *
bogdanm 0:9b334a45a8ff 861 * @note
bogdanm 0:9b334a45a8ff 862 * Decoder states can be configured individually using
bogdanm 0:9b334a45a8ff 863 * LESENSE_DecoderStateConfig() function.
bogdanm 0:9b334a45a8ff 864 *
bogdanm 0:9b334a45a8ff 865 * @param[in] confDecStAll
bogdanm 0:9b334a45a8ff 866 * Configuration structure for all (16) LESENSE decoder states.
bogdanm 0:9b334a45a8ff 867 ******************************************************************************/
bogdanm 0:9b334a45a8ff 868 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll)
bogdanm 0:9b334a45a8ff 869 {
bogdanm 0:9b334a45a8ff 870 uint32_t i;
bogdanm 0:9b334a45a8ff 871
bogdanm 0:9b334a45a8ff 872
bogdanm 0:9b334a45a8ff 873 /* Iterate through all the 16 decoder states. */
bogdanm 0:9b334a45a8ff 874 for (i = 0U; i < 16U; ++i)
bogdanm 0:9b334a45a8ff 875 {
bogdanm 0:9b334a45a8ff 876 /* Configure decoder state i. */
bogdanm 0:9b334a45a8ff 877 LESENSE_DecoderStateConfig(&confDecStAll->St[i], i);
bogdanm 0:9b334a45a8ff 878 }
bogdanm 0:9b334a45a8ff 879 }
bogdanm 0:9b334a45a8ff 880
bogdanm 0:9b334a45a8ff 881
bogdanm 0:9b334a45a8ff 882 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 883 * @brief
bogdanm 0:9b334a45a8ff 884 * Configure a single LESENSE decoder state.
bogdanm 0:9b334a45a8ff 885 *
bogdanm 0:9b334a45a8ff 886 * @details
bogdanm 0:9b334a45a8ff 887 * This function configures a single decoder state of the LESENSE interface.
bogdanm 0:9b334a45a8ff 888 * Please refer to the configuration parameter type definition
bogdanm 0:9b334a45a8ff 889 * (LESENSE_DecStDesc_TypeDef) for more details.
bogdanm 0:9b334a45a8ff 890 *
bogdanm 0:9b334a45a8ff 891 * @param[in] confDecSt
bogdanm 0:9b334a45a8ff 892 * Configuration structure for a single LESENSE decoder state.
bogdanm 0:9b334a45a8ff 893 *
bogdanm 0:9b334a45a8ff 894 * @param[in] decSt
bogdanm 0:9b334a45a8ff 895 * Decoder state index to configure (0-15).
bogdanm 0:9b334a45a8ff 896 ******************************************************************************/
bogdanm 0:9b334a45a8ff 897 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,
bogdanm 0:9b334a45a8ff 898 uint32_t const decSt)
bogdanm 0:9b334a45a8ff 899 {
bogdanm 0:9b334a45a8ff 900 /* Sanity check of configuration parameters */
bogdanm 0:9b334a45a8ff 901 EFM_ASSERT(decSt < 16U);
bogdanm 0:9b334a45a8ff 902 EFM_ASSERT((uint32_t)confDecSt->confA.compMask < 16U);
bogdanm 0:9b334a45a8ff 903 EFM_ASSERT((uint32_t)confDecSt->confA.compVal < 16U);
bogdanm 0:9b334a45a8ff 904 EFM_ASSERT((uint32_t)confDecSt->confA.nextState < 16U);
bogdanm 0:9b334a45a8ff 905 EFM_ASSERT((uint32_t)confDecSt->confB.compMask < 16U);
bogdanm 0:9b334a45a8ff 906 EFM_ASSERT((uint32_t)confDecSt->confB.compVal < 16U);
bogdanm 0:9b334a45a8ff 907 EFM_ASSERT((uint32_t)confDecSt->confB.nextState < 16U);
bogdanm 0:9b334a45a8ff 908
bogdanm 0:9b334a45a8ff 909 /* Configure state descriptor A (LESENSE_STi_TCONFA) for decoder state i.
bogdanm 0:9b334a45a8ff 910 * Setting sensor compare value, sensor mask, next state index,
bogdanm 0:9b334a45a8ff 911 * transition action, interrupt flag option and state descriptor chaining
bogdanm 0:9b334a45a8ff 912 * configurations. */
bogdanm 0:9b334a45a8ff 913 LESENSE->ST[decSt].TCONFA = (uint32_t)confDecSt->confA.prsAct |
bogdanm 0:9b334a45a8ff 914 ((uint32_t)confDecSt->confA.compMask <<
bogdanm 0:9b334a45a8ff 915 _LESENSE_ST_TCONFA_MASK_SHIFT) |
bogdanm 0:9b334a45a8ff 916 ((uint32_t)confDecSt->confA.compVal <<
bogdanm 0:9b334a45a8ff 917 _LESENSE_ST_TCONFA_COMP_SHIFT) |
bogdanm 0:9b334a45a8ff 918 ((uint32_t)confDecSt->confA.nextState <<
bogdanm 0:9b334a45a8ff 919 _LESENSE_ST_TCONFA_NEXTSTATE_SHIFT) |
bogdanm 0:9b334a45a8ff 920 ((uint32_t)confDecSt->confA.setInt <<
bogdanm 0:9b334a45a8ff 921 _LESENSE_ST_TCONFA_SETIF_SHIFT) |
bogdanm 0:9b334a45a8ff 922 ((uint32_t)confDecSt->chainDesc <<
bogdanm 0:9b334a45a8ff 923 _LESENSE_ST_TCONFA_CHAIN_SHIFT);
bogdanm 0:9b334a45a8ff 924
bogdanm 0:9b334a45a8ff 925 /* Configure state descriptor Bi (LESENSE_STi_TCONFB).
bogdanm 0:9b334a45a8ff 926 * Setting sensor compare value, sensor mask, next state index, transition
bogdanm 0:9b334a45a8ff 927 * action and interrupt flag option configurations. */
bogdanm 0:9b334a45a8ff 928 LESENSE->ST[decSt].TCONFB = (uint32_t)confDecSt->confB.prsAct |
bogdanm 0:9b334a45a8ff 929 ((uint32_t)confDecSt->confB.compMask <<
bogdanm 0:9b334a45a8ff 930 _LESENSE_ST_TCONFB_MASK_SHIFT) |
bogdanm 0:9b334a45a8ff 931 ((uint32_t)confDecSt->confB.compVal <<
bogdanm 0:9b334a45a8ff 932 _LESENSE_ST_TCONFB_COMP_SHIFT) |
bogdanm 0:9b334a45a8ff 933 ((uint32_t)confDecSt->confB.nextState <<
bogdanm 0:9b334a45a8ff 934 _LESENSE_ST_TCONFB_NEXTSTATE_SHIFT) |
bogdanm 0:9b334a45a8ff 935 ((uint32_t)confDecSt->confB.setInt <<
bogdanm 0:9b334a45a8ff 936 _LESENSE_ST_TCONFB_SETIF_SHIFT);
bogdanm 0:9b334a45a8ff 937 }
bogdanm 0:9b334a45a8ff 938
bogdanm 0:9b334a45a8ff 939
bogdanm 0:9b334a45a8ff 940 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 941 * @brief
bogdanm 0:9b334a45a8ff 942 * Set LESENSE decoder state.
bogdanm 0:9b334a45a8ff 943 *
bogdanm 0:9b334a45a8ff 944 * @details
bogdanm 0:9b334a45a8ff 945 * This function can be used for setting the initial state of the LESENSE
bogdanm 0:9b334a45a8ff 946 * decoder.
bogdanm 0:9b334a45a8ff 947 *
bogdanm 0:9b334a45a8ff 948 * @note
bogdanm 0:9b334a45a8ff 949 * Make sure the LESENSE decoder state is initialized by this function before
bogdanm 0:9b334a45a8ff 950 * enabling the decoder!
bogdanm 0:9b334a45a8ff 951 *
bogdanm 0:9b334a45a8ff 952 * @param[in] decSt
bogdanm 0:9b334a45a8ff 953 * Decoder state to set as current state. Valid range: 0-15
bogdanm 0:9b334a45a8ff 954 ******************************************************************************/
bogdanm 0:9b334a45a8ff 955 void LESENSE_DecoderStateSet(uint32_t decSt)
bogdanm 0:9b334a45a8ff 956 {
bogdanm 0:9b334a45a8ff 957 EFM_ASSERT(decSt < 16U);
bogdanm 0:9b334a45a8ff 958
bogdanm 0:9b334a45a8ff 959 LESENSE->DECSTATE = decSt & _LESENSE_DECSTATE_DECSTATE_MASK;
bogdanm 0:9b334a45a8ff 960 }
bogdanm 0:9b334a45a8ff 961
bogdanm 0:9b334a45a8ff 962
bogdanm 0:9b334a45a8ff 963 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 964 * @brief
bogdanm 0:9b334a45a8ff 965 * Get the current state of the LESENSE decoder.
bogdanm 0:9b334a45a8ff 966 *
bogdanm 0:9b334a45a8ff 967 * @return
bogdanm 0:9b334a45a8ff 968 * This function returns the value of LESENSE_DECSTATE register that
bogdanm 0:9b334a45a8ff 969 * represents the current state of the LESENSE decoder.
bogdanm 0:9b334a45a8ff 970 ******************************************************************************/
bogdanm 0:9b334a45a8ff 971 uint32_t LESENSE_DecoderStateGet(void)
bogdanm 0:9b334a45a8ff 972 {
bogdanm 0:9b334a45a8ff 973 return LESENSE->DECSTATE & _LESENSE_DECSTATE_DECSTATE_MASK;
bogdanm 0:9b334a45a8ff 974 }
bogdanm 0:9b334a45a8ff 975
bogdanm 0:9b334a45a8ff 976
bogdanm 0:9b334a45a8ff 977 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 978 * @brief
bogdanm 0:9b334a45a8ff 979 * Start scanning of sensors.
bogdanm 0:9b334a45a8ff 980 *
bogdanm 0:9b334a45a8ff 981 * @note
bogdanm 0:9b334a45a8ff 982 * This function will wait for any pending previous write operation to the
bogdanm 0:9b334a45a8ff 983 * CMD register to complete before accessing the CMD register. It will also
bogdanm 0:9b334a45a8ff 984 * wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 985 * returning. Each write operation to the CMD register may take up to 3 LF
bogdanm 0:9b334a45a8ff 986 * clock cycles, so the user should expect some delay. The user may implement
bogdanm 0:9b334a45a8ff 987 * a separate function to write multiple command bits in the CMD register
bogdanm 0:9b334a45a8ff 988 * in one single operation in order to optimize an application.
bogdanm 0:9b334a45a8ff 989 ******************************************************************************/
bogdanm 0:9b334a45a8ff 990 void LESENSE_ScanStart(void)
bogdanm 0:9b334a45a8ff 991 {
bogdanm 0:9b334a45a8ff 992 /* Wait for any pending previous write operation to the CMD register to
bogdanm 0:9b334a45a8ff 993 complete before accessing the CMD register. */
bogdanm 0:9b334a45a8ff 994 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 995
bogdanm 0:9b334a45a8ff 996 /* Start scanning of sensors */
bogdanm 0:9b334a45a8ff 997 LESENSE->CMD = LESENSE_CMD_START;
bogdanm 0:9b334a45a8ff 998
bogdanm 0:9b334a45a8ff 999 /* Wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1000 returning. */
bogdanm 0:9b334a45a8ff 1001 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1002 }
bogdanm 0:9b334a45a8ff 1003
bogdanm 0:9b334a45a8ff 1004
bogdanm 0:9b334a45a8ff 1005 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 1006 * @brief
bogdanm 0:9b334a45a8ff 1007 * Stop scanning of sensors.
bogdanm 0:9b334a45a8ff 1008 *
bogdanm 0:9b334a45a8ff 1009 * @note
bogdanm 0:9b334a45a8ff 1010 * This function will wait for any pending previous write operation to the
bogdanm 0:9b334a45a8ff 1011 * CMD register to complete before accessing the CMD register. It will also
bogdanm 0:9b334a45a8ff 1012 * wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1013 * returning. Each write operation to the CMD register may take up to 3 LF
bogdanm 0:9b334a45a8ff 1014 * clock cycles, so the user should expect some delay. The user may implement
bogdanm 0:9b334a45a8ff 1015 * a separate function to write multiple command bits in the CMD register
bogdanm 0:9b334a45a8ff 1016 * in one single operation in order to optimize an application.
bogdanm 0:9b334a45a8ff 1017 *
bogdanm 0:9b334a45a8ff 1018 * @note
bogdanm 0:9b334a45a8ff 1019 * If issued during a scan, the command takes effect after scan completion.
bogdanm 0:9b334a45a8ff 1020 ******************************************************************************/
bogdanm 0:9b334a45a8ff 1021 void LESENSE_ScanStop(void)
bogdanm 0:9b334a45a8ff 1022 {
bogdanm 0:9b334a45a8ff 1023 /* Wait for any pending previous write operation to the CMD register to
bogdanm 0:9b334a45a8ff 1024 complete before accessing the CMD register. */
bogdanm 0:9b334a45a8ff 1025 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1026
bogdanm 0:9b334a45a8ff 1027 /* Stop scanning of sensors */
bogdanm 0:9b334a45a8ff 1028 LESENSE->CMD = LESENSE_CMD_STOP;
bogdanm 0:9b334a45a8ff 1029
bogdanm 0:9b334a45a8ff 1030 /* Wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1031 returning. */
bogdanm 0:9b334a45a8ff 1032 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1033 }
bogdanm 0:9b334a45a8ff 1034
bogdanm 0:9b334a45a8ff 1035
bogdanm 0:9b334a45a8ff 1036 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 1037 * @brief
bogdanm 0:9b334a45a8ff 1038 * Start LESENSE decoder.
bogdanm 0:9b334a45a8ff 1039 *
bogdanm 0:9b334a45a8ff 1040 * @note
bogdanm 0:9b334a45a8ff 1041 * This function will wait for any pending previous write operation to the
bogdanm 0:9b334a45a8ff 1042 * CMD register to complete before accessing the CMD register. It will also
bogdanm 0:9b334a45a8ff 1043 * wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1044 * returning. Each write operation to the CMD register may take up to 3 LF
bogdanm 0:9b334a45a8ff 1045 * clock cycles, so the user should expect some delay. The user may implement
bogdanm 0:9b334a45a8ff 1046 * a separate function to write multiple command bits in the CMD register
bogdanm 0:9b334a45a8ff 1047 * in one single operation in order to optimize an application.
bogdanm 0:9b334a45a8ff 1048 ******************************************************************************/
bogdanm 0:9b334a45a8ff 1049 void LESENSE_DecoderStart(void)
bogdanm 0:9b334a45a8ff 1050 {
bogdanm 0:9b334a45a8ff 1051 /* Wait for any pending previous write operation to the CMD register to
bogdanm 0:9b334a45a8ff 1052 complete before accessing the CMD register. */
bogdanm 0:9b334a45a8ff 1053 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1054
bogdanm 0:9b334a45a8ff 1055 /* Start decoder */
bogdanm 0:9b334a45a8ff 1056 LESENSE->CMD = LESENSE_CMD_DECODE;
bogdanm 0:9b334a45a8ff 1057
bogdanm 0:9b334a45a8ff 1058 /* Wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1059 returning. */
bogdanm 0:9b334a45a8ff 1060 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1061 }
bogdanm 0:9b334a45a8ff 1062
bogdanm 0:9b334a45a8ff 1063
bogdanm 0:9b334a45a8ff 1064 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 1065 * @brief
bogdanm 0:9b334a45a8ff 1066 * Clear result buffer.
bogdanm 0:9b334a45a8ff 1067 *
bogdanm 0:9b334a45a8ff 1068 * @note
bogdanm 0:9b334a45a8ff 1069 * This function will wait for any pending previous write operation to the
bogdanm 0:9b334a45a8ff 1070 * CMD register to complete before accessing the CMD register. It will also
bogdanm 0:9b334a45a8ff 1071 * wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1072 * returning. Each write operation to the CMD register may take up to 3 LF
bogdanm 0:9b334a45a8ff 1073 * clock cycles, so the user should expect some delay. The user may implement
bogdanm 0:9b334a45a8ff 1074 * a separate function to write multiple command bits in the CMD register
bogdanm 0:9b334a45a8ff 1075 * in one single operation in order to optimize an application.
bogdanm 0:9b334a45a8ff 1076 ******************************************************************************/
bogdanm 0:9b334a45a8ff 1077 void LESENSE_ResultBufferClear(void)
bogdanm 0:9b334a45a8ff 1078 {
bogdanm 0:9b334a45a8ff 1079 /* Wait for any pending previous write operation to the CMD register to
bogdanm 0:9b334a45a8ff 1080 complete before accessing the CMD register. */
bogdanm 0:9b334a45a8ff 1081 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1082
bogdanm 0:9b334a45a8ff 1083 LESENSE->CMD = LESENSE_CMD_CLEARBUF;
bogdanm 0:9b334a45a8ff 1084
bogdanm 0:9b334a45a8ff 1085 /* Wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1086 returning. */
bogdanm 0:9b334a45a8ff 1087 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1088 }
bogdanm 0:9b334a45a8ff 1089
bogdanm 0:9b334a45a8ff 1090
bogdanm 0:9b334a45a8ff 1091 /***************************************************************************//**
bogdanm 0:9b334a45a8ff 1092 * @brief
bogdanm 0:9b334a45a8ff 1093 * Reset the LESENSE module.
bogdanm 0:9b334a45a8ff 1094 *
bogdanm 0:9b334a45a8ff 1095 * @details
bogdanm 0:9b334a45a8ff 1096 * Use this function to reset the LESENSE registers.
bogdanm 0:9b334a45a8ff 1097 *
bogdanm 0:9b334a45a8ff 1098 * @note
bogdanm 0:9b334a45a8ff 1099 * Resetting LESENSE registers is required in each reset or power-on cycle in
bogdanm 0:9b334a45a8ff 1100 * order to configure the default values of the RAM mapped LESENSE registers.
bogdanm 0:9b334a45a8ff 1101 * LESENSE_Reset() can be called on initialization by setting the @p reqReset
bogdanm 0:9b334a45a8ff 1102 * parameter to true in LESENSE_Init().
bogdanm 0:9b334a45a8ff 1103 ******************************************************************************/
bogdanm 0:9b334a45a8ff 1104 void LESENSE_Reset(void)
bogdanm 0:9b334a45a8ff 1105 {
bogdanm 0:9b334a45a8ff 1106 uint32_t i;
bogdanm 0:9b334a45a8ff 1107
bogdanm 0:9b334a45a8ff 1108
bogdanm 0:9b334a45a8ff 1109 /* Disable all LESENSE interrupts first */
bogdanm 0:9b334a45a8ff 1110 LESENSE->IEN = _LESENSE_IEN_RESETVALUE;
bogdanm 0:9b334a45a8ff 1111
bogdanm 0:9b334a45a8ff 1112 /* Clear all pending LESENSE interrupts */
bogdanm 0:9b334a45a8ff 1113 LESENSE->IFC = _LESENSE_IFC_MASK;
bogdanm 0:9b334a45a8ff 1114
bogdanm 0:9b334a45a8ff 1115 /* Stop the decoder */
bogdanm 0:9b334a45a8ff 1116 LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
bogdanm 0:9b334a45a8ff 1117
bogdanm 0:9b334a45a8ff 1118 /* Wait for any pending previous write operation to the CMD register to
bogdanm 0:9b334a45a8ff 1119 complete before accessing the CMD register. */
bogdanm 0:9b334a45a8ff 1120 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1121 /* Stop sensor scan and clear result buffer */
bogdanm 0:9b334a45a8ff 1122 LESENSE->CMD = (LESENSE_CMD_STOP | LESENSE_CMD_CLEARBUF);
bogdanm 0:9b334a45a8ff 1123
bogdanm 0:9b334a45a8ff 1124 /* Reset LESENSE configuration registers */
bogdanm 0:9b334a45a8ff 1125 LESENSE->CTRL = _LESENSE_CTRL_RESETVALUE;
bogdanm 0:9b334a45a8ff 1126 LESENSE->PERCTRL = _LESENSE_PERCTRL_RESETVALUE;
bogdanm 0:9b334a45a8ff 1127 LESENSE->DECCTRL = _LESENSE_DECCTRL_RESETVALUE;
bogdanm 0:9b334a45a8ff 1128 LESENSE->BIASCTRL = _LESENSE_BIASCTRL_RESETVALUE;
bogdanm 0:9b334a45a8ff 1129 LESENSE->CHEN = _LESENSE_CHEN_RESETVALUE;
bogdanm 0:9b334a45a8ff 1130 LESENSE->IDLECONF = _LESENSE_IDLECONF_RESETVALUE;
bogdanm 0:9b334a45a8ff 1131 LESENSE->ALTEXCONF = _LESENSE_ALTEXCONF_RESETVALUE;
bogdanm 0:9b334a45a8ff 1132
bogdanm 0:9b334a45a8ff 1133 /* Disable LESENSE to control GPIO pins */
bogdanm 0:9b334a45a8ff 1134 LESENSE->ROUTE = _LESENSE_ROUTE_RESETVALUE;
bogdanm 0:9b334a45a8ff 1135
bogdanm 0:9b334a45a8ff 1136 /* Reset all channel configuration registers */
bogdanm 0:9b334a45a8ff 1137 for (i = 0U; i < 16U; ++i)
bogdanm 0:9b334a45a8ff 1138 {
bogdanm 0:9b334a45a8ff 1139 LESENSE->CH[i].TIMING = _LESENSE_CH_TIMING_RESETVALUE;
bogdanm 0:9b334a45a8ff 1140 LESENSE->CH[i].INTERACT = _LESENSE_CH_INTERACT_RESETVALUE;
bogdanm 0:9b334a45a8ff 1141 LESENSE->CH[i].EVAL = _LESENSE_CH_EVAL_RESETVALUE;
bogdanm 0:9b334a45a8ff 1142 }
bogdanm 0:9b334a45a8ff 1143
bogdanm 0:9b334a45a8ff 1144 /* Reset all decoder state configuration registers */
bogdanm 0:9b334a45a8ff 1145 for (i = 0U; i < 16U; ++i)
bogdanm 0:9b334a45a8ff 1146 {
bogdanm 0:9b334a45a8ff 1147 LESENSE->ST[i].TCONFA = _LESENSE_ST_TCONFA_RESETVALUE;
bogdanm 0:9b334a45a8ff 1148 LESENSE->ST[i].TCONFB = _LESENSE_ST_TCONFB_RESETVALUE;
bogdanm 0:9b334a45a8ff 1149 }
bogdanm 0:9b334a45a8ff 1150 /* Wait for the write operation to the CMD register to complete before
bogdanm 0:9b334a45a8ff 1151 returning. */
bogdanm 0:9b334a45a8ff 1152 while (LESENSE_SYNCBUSY_CMD & LESENSE->SYNCBUSY);
bogdanm 0:9b334a45a8ff 1153 }
bogdanm 0:9b334a45a8ff 1154
bogdanm 0:9b334a45a8ff 1155
bogdanm 0:9b334a45a8ff 1156 /** @} (end addtogroup LESENSE) */
bogdanm 0:9b334a45a8ff 1157 /** @} (end addtogroup EM_Library) */
bogdanm 0:9b334a45a8ff 1158
bogdanm 0:9b334a45a8ff 1159 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */