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