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