mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
<>
Date:
Thu Oct 27 16:45:56 2016 +0100
Revision:
128:9bcdf88f62b0
Parent:
113:f141b2784e32
Child:
139:856d2700e60b
Release 128 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

2966: Add kw24 support https://github.com/ARMmbed/mbed-os/pull/2966
3068: MultiTech mDot - clean up PeripheralPins.c and add new pin names https://github.com/ARMmbed/mbed-os/pull/3068
3089: Kinetis HAL: Remove clock initialization code from serial and ticker https://github.com/ARMmbed/mbed-os/pull/3089
2943: [NRF5] NVIC_SetVector functionality https://github.com/ARMmbed/mbed-os/pull/2943
2938: InterruptIn changes in NCS36510 HAL. https://github.com/ARMmbed/mbed-os/pull/2938
3108: Fix sleep function for NRF52. https://github.com/ARMmbed/mbed-os/pull/3108
3076: STM32F1: Correct timer master value reading https://github.com/ARMmbed/mbed-os/pull/3076
3085: Add LOWPOWERTIMER capability for NUCLEO_F303ZE https://github.com/ARMmbed/mbed-os/pull/3085
3046: [BEETLE] Update BLE stack on Beetle board https://github.com/ARMmbed/mbed-os/pull/3046
3122: [Silicon Labs] Update of Silicon Labs HAL https://github.com/ARMmbed/mbed-os/pull/3122
3022: OnSemi RAM usage fix https://github.com/ARMmbed/mbed-os/pull/3022
3121: STM32F3: Correct UART4 and UART5 defines when using DEVICE_SERIAL_ASYNCH https://github.com/ARMmbed/mbed-os/pull/3121
3142: Targets- NUMAKER_PFM_NUC47216 remove mbed 2 https://github.com/ARMmbed/mbed-os/pull/3142

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 98:8ab26030e058 1 /***************************************************************************//**
Kojto 98:8ab26030e058 2 * @file em_lesense.h
Kojto 98:8ab26030e058 3 * @brief Low Energy Sensor (LESENSE) peripheral API
<> 128:9bcdf88f62b0 4 * @version 5.0.0
Kojto 98:8ab26030e058 5 *******************************************************************************
Kojto 98:8ab26030e058 6 * @section License
<> 128:9bcdf88f62b0 7 * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b>
Kojto 98:8ab26030e058 8 *******************************************************************************
Kojto 98:8ab26030e058 9 *
Kojto 98:8ab26030e058 10 * Permission is granted to anyone to use this software for any purpose,
Kojto 98:8ab26030e058 11 * including commercial applications, and to alter it and redistribute it
Kojto 98:8ab26030e058 12 * freely, subject to the following restrictions:
Kojto 98:8ab26030e058 13 *
Kojto 98:8ab26030e058 14 * 1. The origin of this software must not be misrepresented; you must not
Kojto 98:8ab26030e058 15 * claim that you wrote the original software.
Kojto 98:8ab26030e058 16 * 2. Altered source versions must be plainly marked as such, and must not be
Kojto 98:8ab26030e058 17 * misrepresented as being the original software.
Kojto 98:8ab26030e058 18 * 3. This notice may not be removed or altered from any source distribution.
Kojto 98:8ab26030e058 19 *
Kojto 98:8ab26030e058 20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
Kojto 98:8ab26030e058 21 * obligation to support this Software. Silicon Labs is providing the
Kojto 98:8ab26030e058 22 * Software "AS IS", with no express or implied warranties of any kind,
Kojto 98:8ab26030e058 23 * including, but not limited to, any implied warranties of merchantability
Kojto 98:8ab26030e058 24 * or fitness for any particular purpose or warranties against infringement
Kojto 98:8ab26030e058 25 * of any proprietary rights of a third party.
Kojto 98:8ab26030e058 26 *
Kojto 98:8ab26030e058 27 * Silicon Labs will not be liable for any consequential, incidental, or
Kojto 98:8ab26030e058 28 * special damages, or any other relief, or for any claim by any third party,
Kojto 98:8ab26030e058 29 * arising from your use of this Software.
Kojto 98:8ab26030e058 30 *
Kojto 98:8ab26030e058 31 ******************************************************************************/
Kojto 98:8ab26030e058 32
<> 128:9bcdf88f62b0 33 #ifndef EM_LESENSE_H
<> 128:9bcdf88f62b0 34 #define EM_LESENSE_H
Kojto 98:8ab26030e058 35
Kojto 98:8ab26030e058 36 #include "em_device.h"
Kojto 98:8ab26030e058 37
<> 128:9bcdf88f62b0 38 /* LESENSE is currently only supported on Platform 1. Full support for Platform 2 LESENSE
<> 128:9bcdf88f62b0 39 will be included in the next release. */
<> 128:9bcdf88f62b0 40 #if defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) && defined(_SILICON_LABS_32B_PLATFORM_1)
Kojto 98:8ab26030e058 41 #include <stdint.h>
Kojto 98:8ab26030e058 42 #include <stdbool.h>
Kojto 98:8ab26030e058 43
Kojto 98:8ab26030e058 44 #ifdef __cplusplus
Kojto 98:8ab26030e058 45 extern "C" {
Kojto 98:8ab26030e058 46 #endif
Kojto 98:8ab26030e058 47
Kojto 98:8ab26030e058 48
Kojto 98:8ab26030e058 49 /***************************************************************************//**
<> 128:9bcdf88f62b0 50 * @addtogroup emlib
Kojto 98:8ab26030e058 51 * @{
Kojto 98:8ab26030e058 52 ******************************************************************************/
Kojto 98:8ab26030e058 53
Kojto 98:8ab26030e058 54 /***************************************************************************//**
Kojto 98:8ab26030e058 55 * @addtogroup LESENSE
Kojto 98:8ab26030e058 56 * @{
Kojto 98:8ab26030e058 57 ******************************************************************************/
Kojto 98:8ab26030e058 58
Kojto 98:8ab26030e058 59 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Kojto 98:8ab26030e058 60
Kojto 98:8ab26030e058 61
Kojto 98:8ab26030e058 62
Kojto 98:8ab26030e058 63 /** @endcond */
Kojto 98:8ab26030e058 64
Kojto 98:8ab26030e058 65 /*******************************************************************************
Kojto 98:8ab26030e058 66 ******************************** ENUMS ************************************
Kojto 98:8ab26030e058 67 ******************************************************************************/
Kojto 98:8ab26030e058 68
Kojto 98:8ab26030e058 69 /** Clock divisors for controlling the prescaling factor of the period
Kojto 98:8ab26030e058 70 * counter.
Kojto 98:8ab26030e058 71 * Note: these enumeration values are being used for different clock division
Kojto 98:8ab26030e058 72 * related configuration parameters (hfPresc, lfPresc, pcPresc). */
Kojto 98:8ab26030e058 73 typedef enum
Kojto 98:8ab26030e058 74 {
Kojto 98:8ab26030e058 75 lesenseClkDiv_1 = 0, /**< Divide clock by 1. */
Kojto 98:8ab26030e058 76 lesenseClkDiv_2 = 1, /**< Divide clock by 2. */
Kojto 98:8ab26030e058 77 lesenseClkDiv_4 = 2, /**< Divide clock by 4. */
Kojto 98:8ab26030e058 78 lesenseClkDiv_8 = 3, /**< Divide clock by 8. */
Kojto 98:8ab26030e058 79 lesenseClkDiv_16 = 4, /**< Divide clock by 16. */
Kojto 98:8ab26030e058 80 lesenseClkDiv_32 = 5, /**< Divide clock by 32. */
Kojto 98:8ab26030e058 81 lesenseClkDiv_64 = 6, /**< Divide clock by 64. */
Kojto 98:8ab26030e058 82 lesenseClkDiv_128 = 7 /**< Divide clock by 128. */
Kojto 98:8ab26030e058 83 } LESENSE_ClkPresc_TypeDef;
Kojto 98:8ab26030e058 84
Kojto 98:8ab26030e058 85
Kojto 98:8ab26030e058 86 /** Scan modes. */
Kojto 98:8ab26030e058 87 typedef enum
Kojto 98:8ab26030e058 88 {
Kojto 98:8ab26030e058 89 /** New scan is started each time the period counter overflows. */
Kojto 98:8ab26030e058 90 lesenseScanStartPeriodic = LESENSE_CTRL_SCANMODE_PERIODIC,
Kojto 98:8ab26030e058 91
Kojto 98:8ab26030e058 92 /** Single scan is performed when LESENSE_ScanStart() is called. */
Kojto 98:8ab26030e058 93 lesenseScanStartOneShot = LESENSE_CTRL_SCANMODE_ONESHOT,
Kojto 98:8ab26030e058 94
Kojto 98:8ab26030e058 95 /** New scan is triggered by pulse on PRS channel. */
Kojto 98:8ab26030e058 96 lesenseScanStartPRS = LESENSE_CTRL_SCANMODE_PRS
Kojto 98:8ab26030e058 97 } LESENSE_ScanMode_TypeDef;
Kojto 98:8ab26030e058 98
Kojto 98:8ab26030e058 99
Kojto 98:8ab26030e058 100 /** PRS sources.
Kojto 98:8ab26030e058 101 * Note: these enumeration values are being used for different PRS related
Kojto 98:8ab26030e058 102 * configuration parameters. */
Kojto 98:8ab26030e058 103 typedef enum
Kojto 98:8ab26030e058 104 {
Kojto 98:8ab26030e058 105 lesensePRSCh0 = 0, /**< PRS channel 0. */
Kojto 98:8ab26030e058 106 lesensePRSCh1 = 1, /**< PRS channel 1. */
Kojto 98:8ab26030e058 107 lesensePRSCh2 = 2, /**< PRS channel 2. */
Kojto 98:8ab26030e058 108 lesensePRSCh3 = 3, /**< PRS channel 3. */
Kojto 98:8ab26030e058 109 #if defined( LESENSE_CTRL_PRSSEL_PRSCH4 )
Kojto 98:8ab26030e058 110 lesensePRSCh4 = 4, /**< PRS channel 4. */
Kojto 98:8ab26030e058 111 #endif
Kojto 98:8ab26030e058 112 #if defined( LESENSE_CTRL_PRSSEL_PRSCH5 )
Kojto 98:8ab26030e058 113 lesensePRSCh5 = 5, /**< PRS channel 5. */
Kojto 98:8ab26030e058 114 #endif
Kojto 98:8ab26030e058 115 #if defined( LESENSE_CTRL_PRSSEL_PRSCH6 )
Kojto 98:8ab26030e058 116 lesensePRSCh6 = 6, /**< PRS channel 6. */
Kojto 98:8ab26030e058 117 #endif
Kojto 98:8ab26030e058 118 #if defined( LESENSE_CTRL_PRSSEL_PRSCH7 )
Kojto 98:8ab26030e058 119 lesensePRSCh7 = 7, /**< PRS channel 7. */
Kojto 98:8ab26030e058 120 #endif
Kojto 98:8ab26030e058 121 #if defined( LESENSE_CTRL_PRSSEL_PRSCH8 )
Kojto 98:8ab26030e058 122 lesensePRSCh8 = 8, /**< PRS channel 8. */
Kojto 98:8ab26030e058 123 #endif
Kojto 98:8ab26030e058 124 #if defined( LESENSE_CTRL_PRSSEL_PRSCH9 )
Kojto 98:8ab26030e058 125 lesensePRSCh9 = 9, /**< PRS channel 9. */
Kojto 98:8ab26030e058 126 #endif
Kojto 98:8ab26030e058 127 #if defined( LESENSE_CTRL_PRSSEL_PRSCH10 )
Kojto 98:8ab26030e058 128 lesensePRSCh10 = 10, /**< PRS channel 10.*/
Kojto 98:8ab26030e058 129 #endif
Kojto 98:8ab26030e058 130 #if defined( LESENSE_CTRL_PRSSEL_PRSCH11 )
Kojto 98:8ab26030e058 131 lesensePRSCh11 = 11, /**< PRS channel 11.*/
Kojto 98:8ab26030e058 132 #endif
Kojto 98:8ab26030e058 133 } LESENSE_PRSSel_TypeDef;
Kojto 98:8ab26030e058 134
Kojto 98:8ab26030e058 135
Kojto 98:8ab26030e058 136 /** Locations of the alternate excitation function. */
Kojto 98:8ab26030e058 137 typedef enum
Kojto 98:8ab26030e058 138 {
Kojto 98:8ab26030e058 139 /** Alternate excitation is mapped to the LES_ALTEX pins. */
Kojto 98:8ab26030e058 140 lesenseAltExMapALTEX = _LESENSE_CTRL_ALTEXMAP_ALTEX,
Kojto 98:8ab26030e058 141
Kojto 98:8ab26030e058 142 /** Alternate excitation is mapped to the pins of the other ACMP. */
Kojto 98:8ab26030e058 143 lesenseAltExMapACMP = _LESENSE_CTRL_ALTEXMAP_ACMP
Kojto 98:8ab26030e058 144 } LESENSE_AltExMap_TypeDef;
Kojto 98:8ab26030e058 145
Kojto 98:8ab26030e058 146
Kojto 98:8ab26030e058 147 /** Result buffer interrupt and DMA trigger levels. */
Kojto 98:8ab26030e058 148 typedef enum
Kojto 98:8ab26030e058 149 {
Kojto 98:8ab26030e058 150 /** DMA and interrupt flags are set when result buffer is halffull. */
Kojto 98:8ab26030e058 151 lesenseBufTrigHalf = LESENSE_CTRL_BUFIDL_HALFFULL,
Kojto 98:8ab26030e058 152
Kojto 98:8ab26030e058 153 /** DMA and interrupt flags set when result buffer is full. */
Kojto 98:8ab26030e058 154 lesenseBufTrigFull = LESENSE_CTRL_BUFIDL_FULL
Kojto 98:8ab26030e058 155 } LESENSE_BufTrigLevel_TypeDef;
Kojto 98:8ab26030e058 156
Kojto 98:8ab26030e058 157
Kojto 98:8ab26030e058 158 /** Modes of operation for DMA wakeup from EM2. */
Kojto 98:8ab26030e058 159 typedef enum
Kojto 98:8ab26030e058 160 {
Kojto 98:8ab26030e058 161 /** No DMA wakeup from EM2. */
Kojto 98:8ab26030e058 162 lesenseDMAWakeUpDisable = LESENSE_CTRL_DMAWU_DISABLE,
Kojto 98:8ab26030e058 163
Kojto 98:8ab26030e058 164 /** DMA wakeup from EM2 when data is valid in the result buffer. */
Kojto 98:8ab26030e058 165 lesenseDMAWakeUpBufValid = LESENSE_CTRL_DMAWU_BUFDATAV,
Kojto 98:8ab26030e058 166
Kojto 98:8ab26030e058 167 /** DMA wakeup from EM2 when the resultbuffer is full/halffull, depending on
Kojto 98:8ab26030e058 168 * RESBIDL configuration in LESENSE_CTRL register (selected by
Kojto 98:8ab26030e058 169 * resBufTrigLevel in LESENSE_ResBufTrigLevel_TypeDef descriptor structure). */
Kojto 98:8ab26030e058 170 lesenseDMAWakeUpBufLevel = LESENSE_CTRL_DMAWU_BUFLEVEL
Kojto 98:8ab26030e058 171 } LESENSE_DMAWakeUp_TypeDef;
Kojto 98:8ab26030e058 172
Kojto 98:8ab26030e058 173
Kojto 98:8ab26030e058 174 /** Bias modes. */
Kojto 98:8ab26030e058 175 typedef enum
Kojto 98:8ab26030e058 176 {
Kojto 98:8ab26030e058 177 /** Duty cycle bias module between low power and high accuracy mode. */
Kojto 98:8ab26030e058 178 lesenseBiasModeDutyCycle = LESENSE_BIASCTRL_BIASMODE_DUTYCYCLE,
Kojto 98:8ab26030e058 179
Kojto 98:8ab26030e058 180 /** Bias module is always in high accuracy mode. */
Kojto 98:8ab26030e058 181 lesenseBiasModeHighAcc = LESENSE_BIASCTRL_BIASMODE_HIGHACC,
Kojto 98:8ab26030e058 182
Kojto 98:8ab26030e058 183 /** Bias module is controlled by the EMU and not affected by LESENSE. */
Kojto 98:8ab26030e058 184 lesenseBiasModeDontTouch = LESENSE_BIASCTRL_BIASMODE_DONTTOUCH
Kojto 98:8ab26030e058 185 } LESENSE_BiasMode_TypeDef;
Kojto 98:8ab26030e058 186
Kojto 98:8ab26030e058 187
Kojto 98:8ab26030e058 188 /** Scan configuration. */
Kojto 98:8ab26030e058 189 typedef enum
Kojto 98:8ab26030e058 190 {
Kojto 98:8ab26030e058 191 /** The channel configuration registers (CHx_CONF) used are directly mapped to
Kojto 98:8ab26030e058 192 * the channel number. */
Kojto 98:8ab26030e058 193 lesenseScanConfDirMap = LESENSE_CTRL_SCANCONF_DIRMAP,
Kojto 98:8ab26030e058 194
Kojto 98:8ab26030e058 195 /** The channel configuration registers used are CHx+8_CONF for channels 0-7
Kojto 98:8ab26030e058 196 * and CHx-8_CONF for channels 8-15. */
Kojto 98:8ab26030e058 197 lesenseScanConfInvMap = LESENSE_CTRL_SCANCONF_INVMAP,
Kojto 98:8ab26030e058 198
Kojto 98:8ab26030e058 199 /** The channel configuration registers used toggles between CHX_SCANCONF and
Kojto 98:8ab26030e058 200 * CHX+8_SCANCONF when channel x triggers. */
Kojto 98:8ab26030e058 201 lesenseScanConfToggle = LESENSE_CTRL_SCANCONF_TOGGLE,
Kojto 98:8ab26030e058 202
Kojto 98:8ab26030e058 203 /** The decoder state defines the channel configuration register (CHx_CONF) to
Kojto 98:8ab26030e058 204 * be used. */
Kojto 98:8ab26030e058 205 lesenseScanConfDecDef = LESENSE_CTRL_SCANCONF_DECDEF
Kojto 98:8ab26030e058 206 } LESENSE_ScanConfSel_TypeDef;
Kojto 98:8ab26030e058 207
Kojto 98:8ab26030e058 208
Kojto 98:8ab26030e058 209 /** DAC CHx data control configuration. */
Kojto 98:8ab26030e058 210 typedef enum
Kojto 98:8ab26030e058 211 {
Kojto 98:8ab26030e058 212 /** DAC channel x data is defined by DAC_CHxDATA register.
Kojto 98:8ab26030e058 213 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 214 lesenseDACIfData = _LESENSE_PERCTRL_DACCH0DATA_DACDATA,
Kojto 98:8ab26030e058 215
Kojto 98:8ab26030e058 216 /** DAC channel x data is defined by ACMPTHRES in LESENSE_CHx_INTERACT.
Kojto 98:8ab26030e058 217 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 218 lesenseACMPThres = _LESENSE_PERCTRL_DACCH0DATA_ACMPTHRES
Kojto 98:8ab26030e058 219 } LESENSE_ControlDACData_TypeDef;
Kojto 98:8ab26030e058 220
Kojto 98:8ab26030e058 221
Kojto 98:8ab26030e058 222 /** DAC channel x conversion mode configuration. */
Kojto 98:8ab26030e058 223 typedef enum
Kojto 98:8ab26030e058 224 {
Kojto 98:8ab26030e058 225 /** LESENSE doesn't control DAC channel x.
Kojto 98:8ab26030e058 226 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 227 lesenseDACConvModeDisable = _LESENSE_PERCTRL_DACCH0CONV_DISABLE,
Kojto 98:8ab26030e058 228
Kojto 98:8ab26030e058 229 /** DAC channel x is driven in continuous mode.
Kojto 98:8ab26030e058 230 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 231 lesenseDACConvModeContinuous = _LESENSE_PERCTRL_DACCH0CONV_CONTINUOUS,
Kojto 98:8ab26030e058 232
Kojto 98:8ab26030e058 233 /** DAC channel x is driven in sample hold mode.
Kojto 98:8ab26030e058 234 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 235 lesenseDACConvModeSampleHold = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEHOLD,
Kojto 98:8ab26030e058 236
Kojto 98:8ab26030e058 237 /** DAC channel x is driven in sample off mode.
Kojto 98:8ab26030e058 238 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 239 lesenseDACConvModeSampleOff = _LESENSE_PERCTRL_DACCH0CONV_SAMPLEOFF
Kojto 98:8ab26030e058 240 } LESENSE_ControlDACConv_TypeDef;
Kojto 98:8ab26030e058 241
Kojto 98:8ab26030e058 242
Kojto 98:8ab26030e058 243 /** DAC channel x output mode configuration. */
Kojto 98:8ab26030e058 244 typedef enum
Kojto 98:8ab26030e058 245 {
Kojto 98:8ab26030e058 246 /** DAC CHx output to pin and ACMP/ADC disabled.
Kojto 98:8ab26030e058 247 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 248 lesenseDACOutModeDisable = _LESENSE_PERCTRL_DACCH0OUT_DISABLE,
Kojto 98:8ab26030e058 249
Kojto 98:8ab26030e058 250 /** DAC CHx output to pin enabled, output to ADC and ACMP disabled.
Kojto 98:8ab26030e058 251 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 252 lesenseDACOutModePin = _LESENSE_PERCTRL_DACCH0OUT_PIN,
Kojto 98:8ab26030e058 253
Kojto 98:8ab26030e058 254 /** DAC CHx output to pin disabled, output to ADC and ACMP enabled.
Kojto 98:8ab26030e058 255 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 256 lesenseDACOutModeADCACMP = _LESENSE_PERCTRL_DACCH0OUT_ADCACMP,
Kojto 98:8ab26030e058 257
Kojto 98:8ab26030e058 258 /** DAC CHx output to pin, ADC, and ACMP enabled.
Kojto 98:8ab26030e058 259 * Note: this value could be used for both DAC Ch0 and Ch1. */
Kojto 98:8ab26030e058 260 lesenseDACOutModePinADCACMP = _LESENSE_PERCTRL_DACCH0OUT_PINADCACMP
Kojto 98:8ab26030e058 261 } LESENSE_ControlDACOut_TypeDef;
Kojto 98:8ab26030e058 262
Kojto 98:8ab26030e058 263
Kojto 98:8ab26030e058 264 /** DAC reference configuration. */
Kojto 98:8ab26030e058 265 typedef enum
Kojto 98:8ab26030e058 266 {
Kojto 98:8ab26030e058 267 /** DAC uses VDD reference. */
Kojto 98:8ab26030e058 268 lesenseDACRefVdd = LESENSE_PERCTRL_DACREF_VDD,
Kojto 98:8ab26030e058 269
Kojto 98:8ab26030e058 270 /** DAC uses bandgap reference. */
Kojto 98:8ab26030e058 271 lesenseDACRefBandGap = LESENSE_PERCTRL_DACREF_BANDGAP
Kojto 98:8ab26030e058 272 } LESENSE_DACRef_TypeDef;
Kojto 98:8ab26030e058 273
Kojto 98:8ab26030e058 274
Kojto 98:8ab26030e058 275 /** ACMPx control configuration. */
Kojto 98:8ab26030e058 276 typedef enum
Kojto 98:8ab26030e058 277 {
Kojto 98:8ab26030e058 278 /** LESENSE does not control the ACMPx.
Kojto 98:8ab26030e058 279 * Note: this value could be used for both ACMP0 and ACMP1. */
Kojto 98:8ab26030e058 280 lesenseACMPModeDisable = _LESENSE_PERCTRL_ACMP0MODE_DISABLE,
Kojto 98:8ab26030e058 281
Kojto 98:8ab26030e058 282 /** LESENSE controls the input mux of ACMPx.
Kojto 98:8ab26030e058 283 * Note: this value could be used for both ACMP0 and ACMP1. */
Kojto 98:8ab26030e058 284 lesenseACMPModeMux = _LESENSE_PERCTRL_ACMP0MODE_MUX,
Kojto 98:8ab26030e058 285
Kojto 98:8ab26030e058 286 /** LESENSE controls the input mux of and the threshold value of ACMPx.
Kojto 98:8ab26030e058 287 * Note: this value could be used for both ACMP0 and ACMP1. */
Kojto 98:8ab26030e058 288 lesenseACMPModeMuxThres = _LESENSE_PERCTRL_ACMP0MODE_MUXTHRES
Kojto 98:8ab26030e058 289 } LESENSE_ControlACMP_TypeDef;
Kojto 98:8ab26030e058 290
Kojto 98:8ab26030e058 291
Kojto 98:8ab26030e058 292 /** Warm up modes. ACMP and DAC duty cycle mode configuration. */
Kojto 98:8ab26030e058 293 typedef enum
Kojto 98:8ab26030e058 294 {
Kojto 98:8ab26030e058 295 /** ACMPs and DACs are shut down when LESENSE is idle. */
Kojto 98:8ab26030e058 296 lesenseWarmupModeNormal = LESENSE_PERCTRL_WARMUPMODE_NORMAL,
Kojto 98:8ab26030e058 297
Kojto 98:8ab26030e058 298 /** ACMPs are kept powered up when LESENSE is idle. */
Kojto 98:8ab26030e058 299 lesenseWarmupModeACMP = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPWARM,
Kojto 98:8ab26030e058 300
Kojto 98:8ab26030e058 301 /** The DAC is kept powered up when LESENSE is idle. */
Kojto 98:8ab26030e058 302 lesenseWarmupModeDAC = LESENSE_PERCTRL_WARMUPMODE_KEEPDACWARM,
Kojto 98:8ab26030e058 303
Kojto 98:8ab26030e058 304 /** ACMPs and the DAC are kept powered up when LESENSE is idle. */
Kojto 98:8ab26030e058 305 lesenseWarmupModeKeepWarm = LESENSE_PERCTRL_WARMUPMODE_KEEPACMPDACWARM
Kojto 98:8ab26030e058 306 } LESENSE_WarmupMode_TypeDef;
Kojto 98:8ab26030e058 307
Kojto 98:8ab26030e058 308
Kojto 98:8ab26030e058 309 /** Decoder input source configuration. */
Kojto 98:8ab26030e058 310 typedef enum
Kojto 98:8ab26030e058 311 {
Kojto 98:8ab26030e058 312 /** The SENSORSTATE register is used as input to the decoder. */
Kojto 98:8ab26030e058 313 lesenseDecInputSensorSt = LESENSE_DECCTRL_INPUT_SENSORSTATE,
Kojto 98:8ab26030e058 314
Kojto 98:8ab26030e058 315 /** PRS channels are used as input to the decoder. */
Kojto 98:8ab26030e058 316 lesenseDecInputPRS = LESENSE_DECCTRL_INPUT_PRS
Kojto 98:8ab26030e058 317 } LESENSE_DecInput_TypeDef;
Kojto 98:8ab26030e058 318
Kojto 98:8ab26030e058 319
Kojto 98:8ab26030e058 320 /** Compare source selection for sensor sampling. */
Kojto 98:8ab26030e058 321 typedef enum
Kojto 98:8ab26030e058 322 {
Kojto 98:8ab26030e058 323 /** Counter output will be used in comparison. */
Kojto 98:8ab26030e058 324 lesenseSampleModeCounter = LESENSE_CH_INTERACT_SAMPLE_COUNTER,
Kojto 98:8ab26030e058 325
Kojto 98:8ab26030e058 326 /** ACMP output will be used in comparison. */
Kojto 98:8ab26030e058 327 lesenseSampleModeACMP = LESENSE_CH_INTERACT_SAMPLE_ACMP
Kojto 98:8ab26030e058 328 } LESENSE_ChSampleMode_TypeDef;
Kojto 98:8ab26030e058 329
Kojto 98:8ab26030e058 330
Kojto 98:8ab26030e058 331 /** Interrupt generation setup for CHx interrupt flag. */
Kojto 98:8ab26030e058 332 typedef enum
Kojto 98:8ab26030e058 333 {
Kojto 98:8ab26030e058 334 /** No interrupt is generated. */
Kojto 98:8ab26030e058 335 lesenseSetIntNone = LESENSE_CH_INTERACT_SETIF_NONE,
Kojto 98:8ab26030e058 336
Kojto 98:8ab26030e058 337 /** Set interrupt flag if the sensor triggers. */
Kojto 98:8ab26030e058 338 lesenseSetIntLevel = LESENSE_CH_INTERACT_SETIF_LEVEL,
Kojto 98:8ab26030e058 339
Kojto 98:8ab26030e058 340 /** Set interrupt flag on positive edge of the sensor state. */
Kojto 98:8ab26030e058 341 lesenseSetIntPosEdge = LESENSE_CH_INTERACT_SETIF_POSEDGE,
Kojto 98:8ab26030e058 342
Kojto 98:8ab26030e058 343 /** Set interrupt flag on negative edge of the sensor state. */
Kojto 98:8ab26030e058 344 lesenseSetIntNegEdge = LESENSE_CH_INTERACT_SETIF_NEGEDGE
Kojto 98:8ab26030e058 345 } LESENSE_ChIntMode_TypeDef;
Kojto 98:8ab26030e058 346
Kojto 98:8ab26030e058 347
Kojto 98:8ab26030e058 348 /** Channel pin mode for the excitation phase of the scan sequence. */
Kojto 98:8ab26030e058 349 typedef enum
Kojto 98:8ab26030e058 350 {
Kojto 98:8ab26030e058 351 /** Channel pin is disabled. */
Kojto 98:8ab26030e058 352 lesenseChPinExDis = LESENSE_CH_INTERACT_EXMODE_DISABLE,
Kojto 98:8ab26030e058 353
Kojto 98:8ab26030e058 354 /** Channel pin is configured as push-pull, driven HIGH. */
Kojto 98:8ab26030e058 355 lesenseChPinExHigh = LESENSE_CH_INTERACT_EXMODE_HIGH,
Kojto 98:8ab26030e058 356
Kojto 98:8ab26030e058 357 /** Channel pin is configured as push-pull, driven LOW. */
Kojto 98:8ab26030e058 358 lesenseChPinExLow = LESENSE_CH_INTERACT_EXMODE_LOW,
Kojto 98:8ab26030e058 359
Kojto 98:8ab26030e058 360 /** DAC output (only available on channel 0, 1, 2, 3, 12, 13, 14 and 15) */
Kojto 98:8ab26030e058 361 lesenseChPinExDACOut = LESENSE_CH_INTERACT_EXMODE_DACOUT
Kojto 98:8ab26030e058 362 } LESENSE_ChPinExMode_TypeDef;
Kojto 98:8ab26030e058 363
Kojto 98:8ab26030e058 364
Kojto 98:8ab26030e058 365 /** Channel pin mode for the idle phase of the scan sequence. */
Kojto 98:8ab26030e058 366 typedef enum
Kojto 98:8ab26030e058 367 {
Kojto 98:8ab26030e058 368 /** Channel pin is disabled in idle phase.
Kojto 98:8ab26030e058 369 * Note: this value could be used for all channels. */
Kojto 98:8ab26030e058 370 lesenseChPinIdleDis = _LESENSE_IDLECONF_CH0_DISABLE,
Kojto 98:8ab26030e058 371
Kojto 98:8ab26030e058 372 /** Channel pin is configured as push-pull, driven HIGH in idle phase.
Kojto 98:8ab26030e058 373 * Note: this value could be used for all channels. */
Kojto 98:8ab26030e058 374 lesenseChPinIdleHigh = _LESENSE_IDLECONF_CH0_HIGH,
Kojto 98:8ab26030e058 375
Kojto 98:8ab26030e058 376 /** Channel pin is configured as push-pull, driven LOW in idle phase.
Kojto 98:8ab26030e058 377 * Note: this value could be used for all channels. */
Kojto 98:8ab26030e058 378 lesenseChPinIdleLow = _LESENSE_IDLECONF_CH0_LOW,
Kojto 98:8ab26030e058 379
Kojto 98:8ab26030e058 380 /** Channel pin is connected to DAC CH0 output in idle phase.
Kojto 98:8ab26030e058 381 * Note: only applies to channel 0, 1, 2, 3. */
Kojto 98:8ab26030e058 382 lesenseChPinIdleDACCh0 = _LESENSE_IDLECONF_CH0_DACCH0,
Kojto 98:8ab26030e058 383
Kojto 98:8ab26030e058 384 /** Channel pin is connected to DAC CH1 output in idle phase.
Kojto 98:8ab26030e058 385 * Note: only applies to channel 12, 13, 14, 15. */
Kojto 98:8ab26030e058 386 lesenseChPinIdleDACCh1 = _LESENSE_IDLECONF_CH12_DACCH1
Kojto 98:8ab26030e058 387 } LESENSE_ChPinIdleMode_TypeDef;
Kojto 98:8ab26030e058 388
Kojto 98:8ab26030e058 389
Kojto 98:8ab26030e058 390 /** Clock used for excitation and sample delay timing. */
Kojto 98:8ab26030e058 391 typedef enum
Kojto 98:8ab26030e058 392 {
Kojto 98:8ab26030e058 393 /** LFACLK (LF clock) is used. */
Kojto 98:8ab26030e058 394 lesenseClkLF = _LESENSE_CH_INTERACT_EXCLK_LFACLK,
Kojto 98:8ab26030e058 395
Kojto 98:8ab26030e058 396 /** AUXHFRCO (HF clock) is used. */
Kojto 98:8ab26030e058 397 lesenseClkHF = _LESENSE_CH_INTERACT_EXCLK_AUXHFRCO
Kojto 98:8ab26030e058 398 } LESENSE_ChClk_TypeDef;
Kojto 98:8ab26030e058 399
Kojto 98:8ab26030e058 400
Kojto 98:8ab26030e058 401 /** Compare modes for counter comparison. */
Kojto 98:8ab26030e058 402 typedef enum
Kojto 98:8ab26030e058 403 {
Kojto 98:8ab26030e058 404 /** Set interrupt flag if counter value is less than CTRTHRESHOLD, or if the
Kojto 98:8ab26030e058 405 * ACMP output is 0. */
Kojto 98:8ab26030e058 406 lesenseCompModeLess = LESENSE_CH_EVAL_COMP_LESS,
Kojto 98:8ab26030e058 407
Kojto 98:8ab26030e058 408 /** Set interrupt flag if counter value is greater than, or equal to
Kojto 98:8ab26030e058 409 * CTRTHRESHOLD, or if the ACMP output is 1. */
Kojto 98:8ab26030e058 410 lesenseCompModeGreaterOrEq = LESENSE_CH_EVAL_COMP_GE
Kojto 98:8ab26030e058 411 } LESENSE_ChCompMode_TypeDef;
Kojto 98:8ab26030e058 412
Kojto 98:8ab26030e058 413
Kojto 98:8ab26030e058 414 /** Idle phase configuration of alternate excitation channels. */
Kojto 98:8ab26030e058 415 typedef enum
Kojto 98:8ab26030e058 416 {
Kojto 98:8ab26030e058 417 /** ALTEX output is disabled in idle phase.
Kojto 98:8ab26030e058 418 * Note: this value could be used for all alternate excitation channels. */
Kojto 98:8ab26030e058 419 lesenseAltExPinIdleDis = _LESENSE_ALTEXCONF_IDLECONF0_DISABLE,
Kojto 98:8ab26030e058 420
Kojto 98:8ab26030e058 421 /** ALTEX output is high in idle phase.
Kojto 98:8ab26030e058 422 * Note: this value could be used for all alternate excitation channels. */
Kojto 98:8ab26030e058 423 lesenseAltExPinIdleHigh = _LESENSE_ALTEXCONF_IDLECONF0_HIGH,
Kojto 98:8ab26030e058 424
Kojto 98:8ab26030e058 425 /** ALTEX output is low in idle phase.
Kojto 98:8ab26030e058 426 * Note: this value could be used for all alternate excitation channels. */
Kojto 98:8ab26030e058 427 lesenseAltExPinIdleLow = _LESENSE_ALTEXCONF_IDLECONF0_LOW
Kojto 98:8ab26030e058 428 } LESENSE_AltExPinIdle_TypeDef;
Kojto 98:8ab26030e058 429
Kojto 98:8ab26030e058 430
Kojto 98:8ab26030e058 431 /** Transition action modes. */
Kojto 98:8ab26030e058 432 typedef enum
Kojto 98:8ab26030e058 433 {
Kojto 98:8ab26030e058 434 /** No PRS pulses generated (if PRSCOUNT == 0).
Kojto 98:8ab26030e058 435 * Do not count (if PRSCOUNT == 1). */
Kojto 98:8ab26030e058 436 lesenseTransActNone = LESENSE_ST_TCONFA_PRSACT_NONE,
Kojto 98:8ab26030e058 437
Kojto 98:8ab26030e058 438 /** Generate pulse on LESPRS0 (if PRSCOUNT == 0). */
Kojto 98:8ab26030e058 439 lesenseTransActPRS0 = LESENSE_ST_TCONFA_PRSACT_PRS0,
Kojto 98:8ab26030e058 440
Kojto 98:8ab26030e058 441 /** Generate pulse on LESPRS1 (if PRSCOUNT == 0). */
Kojto 98:8ab26030e058 442 lesenseTransActPRS1 = LESENSE_ST_TCONFA_PRSACT_PRS1,
Kojto 98:8ab26030e058 443
Kojto 98:8ab26030e058 444 /** Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). */
Kojto 98:8ab26030e058 445 lesenseTransActPRS01 = LESENSE_ST_TCONFA_PRSACT_PRS01,
Kojto 98:8ab26030e058 446
Kojto 98:8ab26030e058 447 /** Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). */
Kojto 98:8ab26030e058 448 lesenseTransActPRS2 = LESENSE_ST_TCONFA_PRSACT_PRS2,
Kojto 98:8ab26030e058 449
Kojto 98:8ab26030e058 450 /** Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). */
Kojto 98:8ab26030e058 451 lesenseTransActPRS02 = LESENSE_ST_TCONFA_PRSACT_PRS02,
Kojto 98:8ab26030e058 452
Kojto 98:8ab26030e058 453 /** Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
Kojto 98:8ab26030e058 454 lesenseTransActPRS12 = LESENSE_ST_TCONFA_PRSACT_PRS12,
Kojto 98:8ab26030e058 455
Kojto 98:8ab26030e058 456 /** Generate pulse on LESPRS0, LESPRS1 and LESPRS2 (if PRSCOUNT == 0). */
Kojto 98:8ab26030e058 457 lesenseTransActPRS012 = LESENSE_ST_TCONFA_PRSACT_PRS012,
Kojto 98:8ab26030e058 458
Kojto 98:8ab26030e058 459 /** Count up (if PRSCOUNT == 1). */
Kojto 98:8ab26030e058 460 lesenseTransActUp = LESENSE_ST_TCONFA_PRSACT_UP,
Kojto 98:8ab26030e058 461
Kojto 98:8ab26030e058 462 /** Count down (if PRSCOUNT == 1). */
Kojto 98:8ab26030e058 463 lesenseTransActDown = LESENSE_ST_TCONFA_PRSACT_DOWN,
Kojto 98:8ab26030e058 464
Kojto 98:8ab26030e058 465 /** Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
Kojto 98:8ab26030e058 466 lesenseTransActUpAndPRS2 = LESENSE_ST_TCONFA_PRSACT_UPANDPRS2,
Kojto 98:8ab26030e058 467
Kojto 98:8ab26030e058 468 /** Count down and generate pulse on LESPRS2 (if PRSCOUNT == 1). */
Kojto 98:8ab26030e058 469 lesenseTransActDownAndPRS2 = LESENSE_ST_TCONFA_PRSACT_DOWNANDPRS2
Kojto 98:8ab26030e058 470 } LESENSE_StTransAct_TypeDef;
Kojto 98:8ab26030e058 471
Kojto 98:8ab26030e058 472
Kojto 98:8ab26030e058 473 /*******************************************************************************
Kojto 98:8ab26030e058 474 ******************************* STRUCTS ***********************************
Kojto 98:8ab26030e058 475 ******************************************************************************/
Kojto 98:8ab26030e058 476
Kojto 98:8ab26030e058 477 /** Core control (LESENSE_CTRL) descriptor structure. */
Kojto 98:8ab26030e058 478 typedef struct
Kojto 98:8ab26030e058 479 {
Kojto 98:8ab26030e058 480 /** Select scan start mode to control how the scan start is being triggered.*/
Kojto 98:8ab26030e058 481 LESENSE_ScanMode_TypeDef scanStart;
Kojto 98:8ab26030e058 482
Kojto 98:8ab26030e058 483 /** Select PRS source for scan start if scanMode is set to lesensePrsPulse. */
Kojto 98:8ab26030e058 484 LESENSE_PRSSel_TypeDef prsSel;
Kojto 98:8ab26030e058 485
Kojto 98:8ab26030e058 486 /** Select scan configuration register usage strategy. */
Kojto 98:8ab26030e058 487 LESENSE_ScanConfSel_TypeDef scanConfSel;
Kojto 98:8ab26030e058 488
Kojto 98:8ab26030e058 489 /** Set to true to invert ACMP0 output. */
Kojto 98:8ab26030e058 490 bool invACMP0;
Kojto 98:8ab26030e058 491
Kojto 98:8ab26030e058 492 /** Set to true to invert ACMP1 output. */
Kojto 98:8ab26030e058 493 bool invACMP1;
Kojto 98:8ab26030e058 494
Kojto 98:8ab26030e058 495 /** Set to true to sample both ACMPs simultaneously. */
Kojto 98:8ab26030e058 496 bool dualSample;
Kojto 98:8ab26030e058 497
Kojto 98:8ab26030e058 498 /** Set to true in order to to store SCANRES in RAM (accessible via RESDATA)
Kojto 98:8ab26030e058 499 * after each scan. */
Kojto 98:8ab26030e058 500 bool storeScanRes;
Kojto 98:8ab26030e058 501
Kojto 98:8ab26030e058 502 /** Set to true in order to always make LESENSE write to the result buffer,
Kojto 98:8ab26030e058 503 * even if it is full. */
Kojto 98:8ab26030e058 504 bool bufOverWr;
Kojto 98:8ab26030e058 505
Kojto 98:8ab26030e058 506 /** Select trigger conditions for interrupt and DMA. */
Kojto 98:8ab26030e058 507 LESENSE_BufTrigLevel_TypeDef bufTrigLevel;
Kojto 98:8ab26030e058 508
Kojto 98:8ab26030e058 509 /** Configure trigger condition for DMA wakeup from EM2. */
Kojto 98:8ab26030e058 510 LESENSE_DMAWakeUp_TypeDef wakeupOnDMA;
Kojto 98:8ab26030e058 511
Kojto 98:8ab26030e058 512 /** Select bias mode. */
Kojto 98:8ab26030e058 513 LESENSE_BiasMode_TypeDef biasMode;
Kojto 98:8ab26030e058 514
Kojto 98:8ab26030e058 515 /** Set to true to keep LESENSE running in debug mode. */
Kojto 98:8ab26030e058 516 bool debugRun;
Kojto 98:8ab26030e058 517 } LESENSE_CoreCtrlDesc_TypeDef;
Kojto 98:8ab26030e058 518
Kojto 98:8ab26030e058 519 /** Default configuration for LESENSE_CtrlDesc_TypeDef structure. */
Kojto 113:f141b2784e32 520 #define LESENSE_CORECTRL_DESC_DEFAULT \
Kojto 113:f141b2784e32 521 { \
Kojto 113:f141b2784e32 522 lesenseScanStartPeriodic, /* Start new scan each time the period counter overflows. */ \
Kojto 113:f141b2784e32 523 lesensePRSCh0, /* Default PRS channel is selected. */ \
Kojto 113:f141b2784e32 524 lesenseScanConfDirMap, /* Direct mapping SCANCONF register usage strategy. */ \
Kojto 113:f141b2784e32 525 false, /* Don't invert ACMP0 output. */ \
Kojto 113:f141b2784e32 526 false, /* Don't invert ACMP1 output. */ \
Kojto 113:f141b2784e32 527 false, /* Disable dual sampling. */ \
Kojto 113:f141b2784e32 528 true, /* Store scan result after each scan. */ \
Kojto 113:f141b2784e32 529 true, /* Overwrite result buffer register even if it is full. */ \
Kojto 113:f141b2784e32 530 lesenseBufTrigHalf, /* Trigger interrupt and DMA request if result buffer is half full. */ \
Kojto 113:f141b2784e32 531 lesenseDMAWakeUpDisable, /* Don't wake up on DMA from EM2. */ \
Kojto 113:f141b2784e32 532 lesenseBiasModeDontTouch, /* Don't touch bias configuration. */ \
Kojto 113:f141b2784e32 533 true /* Keep LESENSE running in debug mode. */ \
Kojto 113:f141b2784e32 534 }
Kojto 98:8ab26030e058 535
Kojto 98:8ab26030e058 536
Kojto 98:8ab26030e058 537 /** LESENSE timing control descriptor structure. */
Kojto 98:8ab26030e058 538 typedef struct
Kojto 98:8ab26030e058 539 {
Kojto 98:8ab26030e058 540 /** Set the number of LFACLK cycles to delay sensor interaction on
Kojto 98:8ab26030e058 541 * each channel. Valid range: 0-3 (2 bit). */
Kojto 98:8ab26030e058 542 uint8_t startDelay;
Kojto 98:8ab26030e058 543 } LESENSE_TimeCtrlDesc_TypeDef;
Kojto 98:8ab26030e058 544
Kojto 98:8ab26030e058 545 /** Default configuration for LESENSE_TimeCtrlDesc_TypeDef structure. */
Kojto 113:f141b2784e32 546 #define LESENSE_TIMECTRL_DESC_DEFAULT \
Kojto 113:f141b2784e32 547 { \
Kojto 113:f141b2784e32 548 0U /* No sensor interaction delay. */ \
Kojto 113:f141b2784e32 549 }
Kojto 98:8ab26030e058 550
Kojto 98:8ab26030e058 551
Kojto 98:8ab26030e058 552 /** LESENSE peripheral control descriptor structure. */
Kojto 98:8ab26030e058 553 typedef struct
Kojto 98:8ab26030e058 554 {
Kojto 98:8ab26030e058 555 /** Configure DAC channel 0 data control. */
Kojto 98:8ab26030e058 556 LESENSE_ControlDACData_TypeDef dacCh0Data;
Kojto 98:8ab26030e058 557
Kojto 98:8ab26030e058 558 /** Configure how LESENSE controls conversion on DAC channel 0. */
Kojto 98:8ab26030e058 559 LESENSE_ControlDACConv_TypeDef dacCh0ConvMode;
Kojto 98:8ab26030e058 560
Kojto 98:8ab26030e058 561 /** Configure how LESENSE controls output on DAC channel 0. */
Kojto 98:8ab26030e058 562 LESENSE_ControlDACOut_TypeDef dacCh0OutMode;
Kojto 98:8ab26030e058 563
Kojto 98:8ab26030e058 564 /** Configure DAC channel 1 data control. */
Kojto 98:8ab26030e058 565 LESENSE_ControlDACData_TypeDef dacCh1Data;
Kojto 98:8ab26030e058 566
Kojto 98:8ab26030e058 567 /** Configure how LESENSE controls conversion on DAC channel 1. */
Kojto 98:8ab26030e058 568 LESENSE_ControlDACConv_TypeDef dacCh1ConvMode;
Kojto 98:8ab26030e058 569
Kojto 98:8ab26030e058 570 /** Configure how LESENSE controls output on DAC channel 1. */
Kojto 98:8ab26030e058 571 LESENSE_ControlDACOut_TypeDef dacCh1OutMode;
Kojto 98:8ab26030e058 572
Kojto 98:8ab26030e058 573 /** Configure the prescaling factor for the LESENSE - DAC interface.
Kojto 98:8ab26030e058 574 * Valid range: 0-31 (5bit). */
Kojto 98:8ab26030e058 575 uint8_t dacPresc;
Kojto 98:8ab26030e058 576
Kojto 98:8ab26030e058 577 /** Configure the DAC reference to be used. Set to #lesenseDACRefVdd to use
Kojto 98:8ab26030e058 578 * VDD and set to #lesenseDACRefBandGap to use bandgap as reference. */
Kojto 98:8ab26030e058 579 LESENSE_DACRef_TypeDef dacRef;
Kojto 98:8ab26030e058 580
Kojto 98:8ab26030e058 581 /** Configure how LESENSE controls ACMP 0. */
Kojto 98:8ab26030e058 582 LESENSE_ControlACMP_TypeDef acmp0Mode;
Kojto 98:8ab26030e058 583
Kojto 98:8ab26030e058 584 /** Configure how LESENSE controls ACMP 1. */
Kojto 98:8ab26030e058 585 LESENSE_ControlACMP_TypeDef acmp1Mode;
Kojto 98:8ab26030e058 586
Kojto 98:8ab26030e058 587 /** Configure how LESENSE controls ACMPs and the DAC in idle mode. */
Kojto 98:8ab26030e058 588 LESENSE_WarmupMode_TypeDef warmupMode;
Kojto 98:8ab26030e058 589 } LESENSE_PerCtrlDesc_TypeDef;
Kojto 98:8ab26030e058 590
Kojto 98:8ab26030e058 591 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
Kojto 113:f141b2784e32 592 #define LESENSE_PERCTRL_DESC_DEFAULT \
Kojto 113:f141b2784e32 593 { \
Kojto 113:f141b2784e32 594 lesenseDACIfData, /**/ \
Kojto 113:f141b2784e32 595 lesenseDACConvModeDisable, /**/ \
Kojto 113:f141b2784e32 596 lesenseDACOutModeDisable, /**/ \
Kojto 113:f141b2784e32 597 lesenseDACIfData, /**/ \
Kojto 113:f141b2784e32 598 lesenseDACConvModeDisable, /**/ \
Kojto 113:f141b2784e32 599 lesenseDACOutModeDisable, /**/ \
Kojto 113:f141b2784e32 600 0U, /**/ \
Kojto 113:f141b2784e32 601 lesenseDACRefVdd, /**/ \
Kojto 113:f141b2784e32 602 lesenseACMPModeMuxThres, /**/ \
Kojto 113:f141b2784e32 603 lesenseACMPModeMuxThres, /**/ \
Kojto 113:f141b2784e32 604 lesenseWarmupModeKeepWarm, /**/ \
Kojto 113:f141b2784e32 605 }
Kojto 98:8ab26030e058 606
Kojto 98:8ab26030e058 607
Kojto 98:8ab26030e058 608 /** LESENSE decoder control descriptor structure. */
Kojto 98:8ab26030e058 609 typedef struct
Kojto 98:8ab26030e058 610 {
Kojto 98:8ab26030e058 611 /** Select the input to the LESENSE decoder. */
Kojto 98:8ab26030e058 612 LESENSE_DecInput_TypeDef decInput;
Kojto 98:8ab26030e058 613
Kojto 98:8ab26030e058 614 /** Initial state of the LESENSE decoder. */
Kojto 98:8ab26030e058 615 uint32_t initState;
Kojto 98:8ab26030e058 616
Kojto 98:8ab26030e058 617 /** Set to enable the decoder to check the present state in addition
Kojto 98:8ab26030e058 618 * to the states defined in DECCONF. */
Kojto 98:8ab26030e058 619 bool chkState;
Kojto 98:8ab26030e058 620
Kojto 98:8ab26030e058 621 /** When set, a transition from state x in the decoder will set interrupt flag
Kojto 98:8ab26030e058 622 * CHx. */
Kojto 98:8ab26030e058 623 bool intMap;
Kojto 98:8ab26030e058 624
Kojto 98:8ab26030e058 625 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
Kojto 98:8ab26030e058 626 * channel 0. */
Kojto 98:8ab26030e058 627 bool hystPRS0;
Kojto 98:8ab26030e058 628
Kojto 98:8ab26030e058 629 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
Kojto 98:8ab26030e058 630 * channel 1. */
Kojto 98:8ab26030e058 631 bool hystPRS1;
Kojto 98:8ab26030e058 632
Kojto 98:8ab26030e058 633 /** Set to enable hysteresis in the decoder for suppressing changes on PRS
Kojto 98:8ab26030e058 634 * channel 2. */
Kojto 98:8ab26030e058 635 bool hystPRS2;
Kojto 98:8ab26030e058 636
Kojto 98:8ab26030e058 637 /** Set to enable hysteresis in the decoder for suppressing interrupt
Kojto 98:8ab26030e058 638 * requests. */
Kojto 98:8ab26030e058 639 bool hystIRQ;
Kojto 98:8ab26030e058 640
Kojto 98:8ab26030e058 641 /** Set to enable count mode on decoder PRS channels 0 and 1 to produce
Kojto 98:8ab26030e058 642 * outputs which can be used by a PCNT to count up or down. */
Kojto 98:8ab26030e058 643 bool prsCount;
Kojto 98:8ab26030e058 644
Kojto 98:8ab26030e058 645 /** Select PRS channel input for bit 0 of the LESENSE decoder. */
Kojto 98:8ab26030e058 646 LESENSE_PRSSel_TypeDef prsChSel0;
Kojto 98:8ab26030e058 647
Kojto 98:8ab26030e058 648 /** Select PRS channel input for bit 1 of the LESENSE decoder. */
Kojto 98:8ab26030e058 649 LESENSE_PRSSel_TypeDef prsChSel1;
Kojto 98:8ab26030e058 650
Kojto 98:8ab26030e058 651 /** Select PRS channel input for bit 2 of the LESENSE decoder. */
Kojto 98:8ab26030e058 652 LESENSE_PRSSel_TypeDef prsChSel2;
Kojto 98:8ab26030e058 653
Kojto 98:8ab26030e058 654 /** Select PRS channel input for bit 3 of the LESENSE decoder. */
Kojto 98:8ab26030e058 655 LESENSE_PRSSel_TypeDef prsChSel3;
Kojto 98:8ab26030e058 656 } LESENSE_DecCtrlDesc_TypeDef;
Kojto 98:8ab26030e058 657
Kojto 98:8ab26030e058 658 /** Default configuration for LESENSE_PerCtrl_TypeDef structure. */
Kojto 113:f141b2784e32 659 #define LESENSE_DECCTRL_DESC_DEFAULT \
Kojto 113:f141b2784e32 660 { \
Kojto 113:f141b2784e32 661 lesenseDecInputSensorSt, /**/ \
Kojto 113:f141b2784e32 662 0U, /**/ \
Kojto 113:f141b2784e32 663 false, /**/ \
Kojto 113:f141b2784e32 664 true, /**/ \
Kojto 113:f141b2784e32 665 true, /**/ \
Kojto 113:f141b2784e32 666 true, /**/ \
Kojto 113:f141b2784e32 667 true, /**/ \
Kojto 113:f141b2784e32 668 true, /**/ \
Kojto 113:f141b2784e32 669 false, /**/ \
Kojto 113:f141b2784e32 670 lesensePRSCh0, /**/ \
Kojto 113:f141b2784e32 671 lesensePRSCh1, /**/ \
Kojto 113:f141b2784e32 672 lesensePRSCh2, /**/ \
Kojto 113:f141b2784e32 673 lesensePRSCh3, /**/ \
Kojto 113:f141b2784e32 674 }
Kojto 98:8ab26030e058 675
Kojto 98:8ab26030e058 676
Kojto 98:8ab26030e058 677 /** LESENSE module initialization structure. */
Kojto 98:8ab26030e058 678 typedef struct
Kojto 98:8ab26030e058 679 {
Kojto 98:8ab26030e058 680 /** LESENSE core configuration parameters. */
Kojto 98:8ab26030e058 681 LESENSE_CoreCtrlDesc_TypeDef coreCtrl;
Kojto 98:8ab26030e058 682
Kojto 98:8ab26030e058 683 /** LESENSE timing configuration parameters. */
Kojto 98:8ab26030e058 684 LESENSE_TimeCtrlDesc_TypeDef timeCtrl;
Kojto 98:8ab26030e058 685
Kojto 98:8ab26030e058 686 /** LESENSE peripheral configuration parameters. */
Kojto 98:8ab26030e058 687 LESENSE_PerCtrlDesc_TypeDef perCtrl;
Kojto 98:8ab26030e058 688
Kojto 98:8ab26030e058 689 /** LESENSE decoder configuration parameters. */
Kojto 98:8ab26030e058 690 LESENSE_DecCtrlDesc_TypeDef decCtrl;
Kojto 98:8ab26030e058 691 } LESENSE_Init_TypeDef;
Kojto 98:8ab26030e058 692
Kojto 98:8ab26030e058 693 /** Default configuration for LESENSE_Init_TypeDef structure. */
Kojto 113:f141b2784e32 694 #define LESENSE_INIT_DEFAULT \
Kojto 113:f141b2784e32 695 { \
Kojto 113:f141b2784e32 696 .coreCtrl = LESENSE_CORECTRL_DESC_DEFAULT, /* Default core control parameters. */ \
Kojto 113:f141b2784e32 697 .timeCtrl = LESENSE_TIMECTRL_DESC_DEFAULT, /* Default time control parameters. */ \
Kojto 113:f141b2784e32 698 .perCtrl = LESENSE_PERCTRL_DESC_DEFAULT, /* Default peripheral control parameters. */ \
Kojto 113:f141b2784e32 699 .decCtrl = LESENSE_DECCTRL_DESC_DEFAULT /* Default decoder control parameters. */ \
Kojto 113:f141b2784e32 700 }
Kojto 98:8ab26030e058 701
Kojto 98:8ab26030e058 702
Kojto 98:8ab26030e058 703 /** Channel descriptor structure. */
Kojto 98:8ab26030e058 704 typedef struct
Kojto 98:8ab26030e058 705 {
Kojto 98:8ab26030e058 706 /** Set to enable scan channel CHx. */
Kojto 98:8ab26030e058 707 bool enaScanCh;
Kojto 98:8ab26030e058 708
Kojto 98:8ab26030e058 709 /** Set to enable CHx pin. */
Kojto 98:8ab26030e058 710 bool enaPin;
Kojto 98:8ab26030e058 711
Kojto 98:8ab26030e058 712 /** Enable/disable channel interrupts after configuring all the sensor channel
Kojto 98:8ab26030e058 713 * parameters. */
Kojto 98:8ab26030e058 714 bool enaInt;
Kojto 98:8ab26030e058 715
Kojto 98:8ab26030e058 716 /** Configure channel pin mode for the excitation phase of the scan sequence.
Kojto 98:8ab26030e058 717 * Note: OPAOUT is only available on channels 2, 3, 4, and 5. */
Kojto 98:8ab26030e058 718 LESENSE_ChPinExMode_TypeDef chPinExMode;
Kojto 98:8ab26030e058 719
Kojto 98:8ab26030e058 720 /** Configure channel pin idle setup in LESENSE idle phase. */
Kojto 98:8ab26030e058 721 LESENSE_ChPinIdleMode_TypeDef chPinIdleMode;
Kojto 98:8ab26030e058 722
Kojto 98:8ab26030e058 723 /** Set to use alternate excite pin for excitation. */
Kojto 98:8ab26030e058 724 bool useAltEx;
Kojto 98:8ab26030e058 725
Kojto 98:8ab26030e058 726 /** Set to enable the result from this channel being shifted into the decoder
Kojto 98:8ab26030e058 727 * register. */
Kojto 98:8ab26030e058 728 bool shiftRes;
Kojto 98:8ab26030e058 729
Kojto 98:8ab26030e058 730 /** Set to invert the result bit stored in SCANRES register. */
Kojto 98:8ab26030e058 731 bool invRes;
Kojto 98:8ab26030e058 732
Kojto 98:8ab26030e058 733 /** Set to store the counter value in RAM (accessible via RESDATA) and make
Kojto 98:8ab26030e058 734 * the comparison result available in the SCANRES register. */
Kojto 98:8ab26030e058 735 bool storeCntRes;
Kojto 98:8ab26030e058 736
Kojto 98:8ab26030e058 737 /** Select clock used for excitation timing. */
Kojto 98:8ab26030e058 738 LESENSE_ChClk_TypeDef exClk;
Kojto 98:8ab26030e058 739
Kojto 98:8ab26030e058 740 /** Select clock used for sample delay timing. */
Kojto 98:8ab26030e058 741 LESENSE_ChClk_TypeDef sampleClk;
Kojto 98:8ab26030e058 742
Kojto 98:8ab26030e058 743 /** Configure excitation time. Excitation will last exTime+1 excitation clock
Kojto 98:8ab26030e058 744 * cycles. Valid range: 0-63 (6 bits). */
Kojto 98:8ab26030e058 745 uint8_t exTime;
Kojto 98:8ab26030e058 746
Kojto 98:8ab26030e058 747 /** Configure sample delay. Sampling will occur after sampleDelay+1 sample
Kojto 98:8ab26030e058 748 * clock cycles. Valid range: 0-127 (7 bits). */
Kojto 98:8ab26030e058 749 uint8_t sampleDelay;
Kojto 98:8ab26030e058 750
Kojto 98:8ab26030e058 751 /** Configure measure delay. Sensor measuring is delayed for measDelay
Kojto 98:8ab26030e058 752 * excitation clock cycles. Valid range: 0-127 (7 bits). */
Kojto 98:8ab26030e058 753 uint8_t measDelay;
Kojto 98:8ab26030e058 754
Kojto 98:8ab26030e058 755 /** Configure ACMP threshold.
Kojto 98:8ab26030e058 756 * If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseDACIfData,
Kojto 98:8ab26030e058 757 * acmpThres defines the 12-bit DAC data in the corresponding data register
Kojto 98:8ab26030e058 758 * of the DAC interface (DACn_CH0DATA and DACn_CH1DATA).
Kojto 98:8ab26030e058 759 * In this case, the valid range is: 0-4095 (12 bits).
Kojto 98:8ab26030e058 760 * If perCtrl.dacCh0Data or perCtrl.dacCh1Data is set to #lesenseACMPThres,
Kojto 98:8ab26030e058 761 * acmpThres defines the 6-bit Vdd scaling factor of ACMP negative input
Kojto 98:8ab26030e058 762 * (VDDLEVEL in ACMP_INPUTSEL register).
Kojto 98:8ab26030e058 763 * In this case, the valid range is: 0-63 (6 bits). */
Kojto 98:8ab26030e058 764 uint16_t acmpThres;
Kojto 98:8ab26030e058 765
Kojto 98:8ab26030e058 766 /** Select if ACMP output or counter output should be used in comparison. */
Kojto 98:8ab26030e058 767 LESENSE_ChSampleMode_TypeDef sampleMode;
Kojto 98:8ab26030e058 768
Kojto 98:8ab26030e058 769 /** Configure interrupt generation mode for CHx interrupt flag. */
Kojto 98:8ab26030e058 770 LESENSE_ChIntMode_TypeDef intMode;
Kojto 98:8ab26030e058 771
Kojto 98:8ab26030e058 772 /** Configure decision threshold for counter comparison.
Kojto 98:8ab26030e058 773 * Valid range: 0-65535 (16 bits). */
Kojto 98:8ab26030e058 774 uint16_t cntThres;
Kojto 98:8ab26030e058 775
Kojto 98:8ab26030e058 776 /** Select mode for counter comparison. */
Kojto 98:8ab26030e058 777 LESENSE_ChCompMode_TypeDef compMode;
Kojto 98:8ab26030e058 778 } LESENSE_ChDesc_TypeDef;
Kojto 98:8ab26030e058 779
Kojto 98:8ab26030e058 780
Kojto 98:8ab26030e058 781 /** Configuration structure for all scan channels. */
Kojto 98:8ab26030e058 782 typedef struct
Kojto 98:8ab26030e058 783 {
Kojto 98:8ab26030e058 784 /** Channel descriptor for all 16 channels. */
Kojto 98:8ab26030e058 785 LESENSE_ChDesc_TypeDef Ch[16];
Kojto 98:8ab26030e058 786 } LESENSE_ChAll_TypeDef;
Kojto 98:8ab26030e058 787
Kojto 98:8ab26030e058 788 /** Default configuration for scan channel. */
Kojto 113:f141b2784e32 789 #define LESENSE_CH_CONF_DEFAULT \
Kojto 113:f141b2784e32 790 { \
Kojto 113:f141b2784e32 791 true, /* Enable scan channel. */ \
Kojto 113:f141b2784e32 792 true, /* Enable the assigned pin on scan channel. */ \
Kojto 113:f141b2784e32 793 true, /* Enable interrupts on channel. */ \
Kojto 113:f141b2784e32 794 lesenseChPinExHigh, /* Channel pin is high during the excitation period. */ \
Kojto 113:f141b2784e32 795 lesenseChPinIdleLow, /* Channel pin is low during the idle period. */ \
Kojto 113:f141b2784e32 796 false, /* Don't use alternate excitation pins for excitation. */ \
Kojto 113:f141b2784e32 797 false, /* Disabled to shift results from this channel to the decoder register. */ \
Kojto 113:f141b2784e32 798 false, /* Disabled to invert the scan result bit. */ \
Kojto 113:f141b2784e32 799 false, /* Disabled to store counter value in the result buffer. */ \
Kojto 113:f141b2784e32 800 lesenseClkLF, /* Use the LF clock for excitation timing. */ \
Kojto 113:f141b2784e32 801 lesenseClkLF, /* Use the LF clock for sample timing. */ \
Kojto 113:f141b2784e32 802 0x03U, /* Excitation time is set to 3(+1) excitation clock cycles. */ \
Kojto 113:f141b2784e32 803 0x09U, /* Sample delay is set to 9(+1) sample clock cycles. */ \
Kojto 113:f141b2784e32 804 0x06U, /* Measure delay is set to 6 excitation clock cycles.*/ \
Kojto 113:f141b2784e32 805 0x00U, /* ACMP threshold has been set to 0. */ \
Kojto 113:f141b2784e32 806 lesenseSampleModeACMP, /* ACMP output will be used in comparison. */ \
Kojto 113:f141b2784e32 807 lesenseSetIntNone, /* No interrupt is generated by the channel. */ \
Kojto 113:f141b2784e32 808 0xFFU, /* Counter threshold has bee set to 0xFF. */ \
Kojto 113:f141b2784e32 809 lesenseCompModeLess /* Compare mode has been set to trigger interrupt on "less". */ \
Kojto 113:f141b2784e32 810 }
Kojto 98:8ab26030e058 811
Kojto 98:8ab26030e058 812 /** Default configuration for all sensor channels. */
Kojto 113:f141b2784e32 813 #define LESENSE_SCAN_CONF_DEFAULT \
Kojto 113:f141b2784e32 814 { \
Kojto 113:f141b2784e32 815 { \
Kojto 113:f141b2784e32 816 LESENSE_CH_CONF_DEFAULT, /* Scan channel 0. */ \
Kojto 113:f141b2784e32 817 LESENSE_CH_CONF_DEFAULT, /* Scan channel 1. */ \
Kojto 113:f141b2784e32 818 LESENSE_CH_CONF_DEFAULT, /* Scan channel 2. */ \
Kojto 113:f141b2784e32 819 LESENSE_CH_CONF_DEFAULT, /* Scan channel 3. */ \
Kojto 113:f141b2784e32 820 LESENSE_CH_CONF_DEFAULT, /* Scan channel 4. */ \
Kojto 113:f141b2784e32 821 LESENSE_CH_CONF_DEFAULT, /* Scan channel 5. */ \
Kojto 113:f141b2784e32 822 LESENSE_CH_CONF_DEFAULT, /* Scan channel 6. */ \
Kojto 113:f141b2784e32 823 LESENSE_CH_CONF_DEFAULT, /* Scan channel 7. */ \
Kojto 113:f141b2784e32 824 LESENSE_CH_CONF_DEFAULT, /* Scan channel 8. */ \
Kojto 113:f141b2784e32 825 LESENSE_CH_CONF_DEFAULT, /* Scan channel 9. */ \
Kojto 113:f141b2784e32 826 LESENSE_CH_CONF_DEFAULT, /* Scan channel 10. */ \
Kojto 113:f141b2784e32 827 LESENSE_CH_CONF_DEFAULT, /* Scan channel 11. */ \
Kojto 113:f141b2784e32 828 LESENSE_CH_CONF_DEFAULT, /* Scan channel 12. */ \
Kojto 113:f141b2784e32 829 LESENSE_CH_CONF_DEFAULT, /* Scan channel 13. */ \
Kojto 113:f141b2784e32 830 LESENSE_CH_CONF_DEFAULT, /* Scan channel 14. */ \
Kojto 113:f141b2784e32 831 LESENSE_CH_CONF_DEFAULT, /* Scan channel 15. */ \
Kojto 113:f141b2784e32 832 } \
Kojto 113:f141b2784e32 833 }
Kojto 98:8ab26030e058 834
Kojto 98:8ab26030e058 835
Kojto 98:8ab26030e058 836 /** Alternate excitation descriptor structure. */
Kojto 98:8ab26030e058 837 typedef struct
Kojto 98:8ab26030e058 838 {
Kojto 98:8ab26030e058 839 /** Configure alternate excitation pins. If set, the corresponding alternate
Kojto 98:8ab26030e058 840 * excitation pin/signal is enabled. */
Kojto 98:8ab26030e058 841 bool enablePin;
Kojto 98:8ab26030e058 842
Kojto 98:8ab26030e058 843 /** Configure idle phase setup of alternate excitation pins.
Kojto 98:8ab26030e058 844 The idleConf parameter is not valid when altExMap==lesenseAltExMapACMP. */
Kojto 98:8ab26030e058 845 LESENSE_AltExPinIdle_TypeDef idleConf;
Kojto 98:8ab26030e058 846
Kojto 98:8ab26030e058 847 /** Configure how to control the external alternate excitation pins. Only
Kojto 98:8ab26030e058 848 * applies if altExMap has been set to lesenseAltExMapALTEX.
Kojto 98:8ab26030e058 849 * If true, the excitation happens on the corresponding alternate excitation
Kojto 98:8ab26030e058 850 * pin during the excitation periods of all enabled channels.
Kojto 98:8ab26030e058 851 * If false, the excitation happens on the corresponding alternate excitation
Kojto 98:8ab26030e058 852 * pin ONLY during the excitation period of the corresponding channel.
Kojto 98:8ab26030e058 853 * The alwaysEx parameter is not valid when altExMap==lesenseAltExMapACMP. */
Kojto 98:8ab26030e058 854 bool alwaysEx;
Kojto 98:8ab26030e058 855 } LESENSE_AltExDesc_TypeDef;
Kojto 98:8ab26030e058 856
Kojto 98:8ab26030e058 857
Kojto 98:8ab26030e058 858 /** Configuration structure for alternate excitation. */
Kojto 98:8ab26030e058 859 typedef struct
Kojto 98:8ab26030e058 860 {
Kojto 98:8ab26030e058 861 /** Select alternate excitation mapping. */
Kojto 98:8ab26030e058 862 LESENSE_AltExMap_TypeDef altExMap;
Kojto 98:8ab26030e058 863
Kojto 98:8ab26030e058 864 /** Alternate excitation channel descriptors.
Kojto 98:8ab26030e058 865 * When altExMap==lesenseAltExMapALTEX only the 8 first descriptors are used.
Kojto 98:8ab26030e058 866 * In this mode they describe the configuration of the LES_ALTEX0-7 pins.
Kojto 98:8ab26030e058 867 * When altExMap==lesenseAltExMapACMP all 16 descriptors are used. In this
Kojto 98:8ab26030e058 868 * mode they describe the configuration of the 16 possible ACMP0-1 excitation
Kojto 98:8ab26030e058 869 * channels. Please refer to the user manual for a complete mapping of the
Kojto 98:8ab26030e058 870 * routing.
Kojto 98:8ab26030e058 871 * NOTE:
Kojto 98:8ab26030e058 872 * Some parameters in the descriptors are not valid when
Kojto 98:8ab26030e058 873 * altExMap==lesenseAltExMapACMP. Please refer to the definition of the
Kojto 98:8ab26030e058 874 * LESENSE_AltExDesc_TypeDef structure for details regarding which parameters
Kojto 98:8ab26030e058 875 * are valid. */
Kojto 98:8ab26030e058 876 LESENSE_AltExDesc_TypeDef AltEx[16];
Kojto 98:8ab26030e058 877
Kojto 98:8ab26030e058 878 } LESENSE_ConfAltEx_TypeDef;
Kojto 98:8ab26030e058 879
Kojto 98:8ab26030e058 880
Kojto 98:8ab26030e058 881 /** Default configuration for alternate excitation channel. */
Kojto 113:f141b2784e32 882 #define LESENSE_ALTEX_CH_CONF_DEFAULT \
Kojto 113:f141b2784e32 883 { \
Kojto 113:f141b2784e32 884 true, /* Alternate excitation enabled.*/ \
Kojto 113:f141b2784e32 885 lesenseAltExPinIdleDis,/* Alternate excitation pin is disabled in idle. */ \
Kojto 113:f141b2784e32 886 false /* Excite only for corresponding channel. */ \
Kojto 113:f141b2784e32 887 }
Kojto 98:8ab26030e058 888
Kojto 98:8ab26030e058 889 /** Default configuration for all alternate excitation channels. */
Kojto 113:f141b2784e32 890 #define LESENSE_ALTEX_CONF_DEFAULT \
Kojto 113:f141b2784e32 891 { \
Kojto 113:f141b2784e32 892 lesenseAltExMapACMP, \
Kojto 113:f141b2784e32 893 { \
Kojto 113:f141b2784e32 894 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 0. */ \
Kojto 113:f141b2784e32 895 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 1. */ \
Kojto 113:f141b2784e32 896 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 2. */ \
Kojto 113:f141b2784e32 897 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 3. */ \
Kojto 113:f141b2784e32 898 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 4. */ \
Kojto 113:f141b2784e32 899 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 5. */ \
Kojto 113:f141b2784e32 900 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 6. */ \
Kojto 113:f141b2784e32 901 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 7. */ \
Kojto 113:f141b2784e32 902 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 8. */ \
Kojto 113:f141b2784e32 903 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 9. */ \
Kojto 113:f141b2784e32 904 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 10. */ \
Kojto 113:f141b2784e32 905 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 11. */ \
Kojto 113:f141b2784e32 906 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 12. */ \
Kojto 113:f141b2784e32 907 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 13. */ \
Kojto 113:f141b2784e32 908 LESENSE_ALTEX_CH_CONF_DEFAULT, /* Alternate excitation channel 14. */ \
Kojto 113:f141b2784e32 909 LESENSE_ALTEX_CH_CONF_DEFAULT /* Alternate excitation channel 15. */ \
Kojto 113:f141b2784e32 910 } \
Kojto 113:f141b2784e32 911 }
Kojto 98:8ab26030e058 912
Kojto 98:8ab26030e058 913
Kojto 98:8ab26030e058 914 /** Decoder state condition descriptor structure. */
Kojto 98:8ab26030e058 915 typedef struct
Kojto 98:8ab26030e058 916 {
Kojto 98:8ab26030e058 917 /** Configure compare value. State transition is triggered when sensor state
Kojto 98:8ab26030e058 918 * equals to this value. Valid range: 0-15 (4 bits). */
Kojto 98:8ab26030e058 919 uint8_t compVal;
Kojto 98:8ab26030e058 920
Kojto 98:8ab26030e058 921 /** Configure compare mask. Set bit X to exclude sensor X from evaluation.
Kojto 98:8ab26030e058 922 * Note: decoder can handle sensor inputs from up to 4 sensors, therefore
Kojto 98:8ab26030e058 923 * this mask is 4 bit long. */
Kojto 98:8ab26030e058 924 uint8_t compMask;
Kojto 98:8ab26030e058 925
Kojto 98:8ab26030e058 926 /** Configure index of state to be entered if the sensor state equals to
Kojto 98:8ab26030e058 927 * compVal. Valid range: 0-15 (4 bits). */
Kojto 98:8ab26030e058 928 uint8_t nextState;
Kojto 98:8ab26030e058 929
Kojto 98:8ab26030e058 930 /** Configure which PRS action to perform when sensor state equals to
Kojto 98:8ab26030e058 931 * compVal. */
Kojto 98:8ab26030e058 932 LESENSE_StTransAct_TypeDef prsAct;
Kojto 98:8ab26030e058 933
Kojto 98:8ab26030e058 934 /** If enabled, interrupt flag is set when sensor state equals to compVal. */
Kojto 98:8ab26030e058 935 bool setInt;
Kojto 98:8ab26030e058 936 } LESENSE_DecStCond_TypeDef;
Kojto 98:8ab26030e058 937
Kojto 98:8ab26030e058 938 /** Default configuration for decoder state condition. */
Kojto 113:f141b2784e32 939 #define LESENSE_ST_CONF_DEFAULT \
Kojto 113:f141b2784e32 940 { \
Kojto 113:f141b2784e32 941 0x0FU, /* Compare value set to 0x0F. */ \
Kojto 113:f141b2784e32 942 0x00U, /* All decoder inputs masked. */ \
Kojto 113:f141b2784e32 943 0U, /* Next state is state 0. */ \
Kojto 113:f141b2784e32 944 lesenseTransActNone, /* No PRS action performed on compare match. */ \
Kojto 113:f141b2784e32 945 false /* No interrupt triggered on compare match. */ \
Kojto 113:f141b2784e32 946 }
Kojto 98:8ab26030e058 947
Kojto 98:8ab26030e058 948
Kojto 98:8ab26030e058 949 /** Decoder state x configuration structure. */
Kojto 98:8ab26030e058 950 typedef struct
Kojto 98:8ab26030e058 951 {
Kojto 98:8ab26030e058 952 /** If enabled, the state descriptor pair in the next location will also be
Kojto 98:8ab26030e058 953 * evaluated. */
Kojto 98:8ab26030e058 954 bool chainDesc;
Kojto 98:8ab26030e058 955
Kojto 98:8ab26030e058 956 /** State condition descriptor A (high level descriptor of
Kojto 98:8ab26030e058 957 * LESENSE_STx_DECCONFA). */
Kojto 98:8ab26030e058 958 LESENSE_DecStCond_TypeDef confA;
Kojto 98:8ab26030e058 959
Kojto 98:8ab26030e058 960 /** State condition descriptor B (high level descriptor of
Kojto 98:8ab26030e058 961 * LESENSE_STx_DECCONFB). */
Kojto 98:8ab26030e058 962 LESENSE_DecStCond_TypeDef confB;
Kojto 98:8ab26030e058 963 } LESENSE_DecStDesc_TypeDef;
Kojto 98:8ab26030e058 964
Kojto 98:8ab26030e058 965
Kojto 98:8ab26030e058 966 /** Configuration structure for the decoder. */
Kojto 98:8ab26030e058 967 typedef struct
Kojto 98:8ab26030e058 968 {
Kojto 98:8ab26030e058 969 /** Descriptor of the 16 decoder states. */
Kojto 98:8ab26030e058 970 LESENSE_DecStDesc_TypeDef St[16];
Kojto 98:8ab26030e058 971 } LESENSE_DecStAll_TypeDef;
Kojto 98:8ab26030e058 972
Kojto 98:8ab26030e058 973 /** Default configuration for all decoder states. */
Kojto 113:f141b2784e32 974 #define LESENSE_DECODER_CONF_DEFAULT \
Kojto 113:f141b2784e32 975 { /* chain | Descriptor A | Descriptor B */ \
Kojto 113:f141b2784e32 976 { \
Kojto 113:f141b2784e32 977 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 0. */ \
Kojto 113:f141b2784e32 978 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 1. */ \
Kojto 113:f141b2784e32 979 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 2. */ \
Kojto 113:f141b2784e32 980 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 3. */ \
Kojto 113:f141b2784e32 981 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 4. */ \
Kojto 113:f141b2784e32 982 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 5. */ \
Kojto 113:f141b2784e32 983 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 6. */ \
Kojto 113:f141b2784e32 984 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 7. */ \
Kojto 113:f141b2784e32 985 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 8. */ \
Kojto 113:f141b2784e32 986 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 9. */ \
Kojto 113:f141b2784e32 987 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 10. */ \
Kojto 113:f141b2784e32 988 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 11. */ \
Kojto 113:f141b2784e32 989 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 12. */ \
Kojto 113:f141b2784e32 990 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 13. */ \
Kojto 113:f141b2784e32 991 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT }, /* Decoder state 14. */ \
Kojto 113:f141b2784e32 992 { false, LESENSE_ST_CONF_DEFAULT, LESENSE_ST_CONF_DEFAULT } /* Decoder state 15. */ \
Kojto 113:f141b2784e32 993 } \
Kojto 113:f141b2784e32 994 }
Kojto 98:8ab26030e058 995
Kojto 98:8ab26030e058 996 /*******************************************************************************
Kojto 98:8ab26030e058 997 ***************************** PROTOTYPES **********************************
Kojto 98:8ab26030e058 998 ******************************************************************************/
Kojto 98:8ab26030e058 999 void LESENSE_Init(LESENSE_Init_TypeDef const *init, bool const reqReset);
Kojto 98:8ab26030e058 1000 void LESENSE_Reset(void);
Kojto 98:8ab26030e058 1001
Kojto 98:8ab26030e058 1002 uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t const scanFreq);
Kojto 98:8ab26030e058 1003 void LESENSE_ScanModeSet(LESENSE_ScanMode_TypeDef const scanMode,
Kojto 98:8ab26030e058 1004 bool const start);
Kojto 98:8ab26030e058 1005
Kojto 98:8ab26030e058 1006 void LESENSE_StartDelaySet(uint8_t const startDelay);
Kojto 98:8ab26030e058 1007
Kojto 98:8ab26030e058 1008 void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef const clk,
Kojto 98:8ab26030e058 1009 LESENSE_ClkPresc_TypeDef const clkDiv);
Kojto 98:8ab26030e058 1010
Kojto 98:8ab26030e058 1011 void LESENSE_ChannelAllConfig(LESENSE_ChAll_TypeDef const *confChAll);
Kojto 98:8ab26030e058 1012 void LESENSE_ChannelConfig(LESENSE_ChDesc_TypeDef const *confCh,
Kojto 98:8ab26030e058 1013 uint32_t const chIdx);
Kojto 98:8ab26030e058 1014 void LESENSE_ChannelEnable(uint8_t const chIdx,
Kojto 98:8ab26030e058 1015 bool const enaScanCh,
Kojto 98:8ab26030e058 1016 bool const enaPin);
Kojto 98:8ab26030e058 1017 void LESENSE_ChannelEnableMask(uint16_t chMask, uint16_t pinMask);
Kojto 98:8ab26030e058 1018 void LESENSE_ChannelTimingSet(uint8_t const chIdx,
Kojto 98:8ab26030e058 1019 uint8_t const exTime,
Kojto 98:8ab26030e058 1020 uint8_t const sampleDelay,
Kojto 98:8ab26030e058 1021 uint8_t const measDelay);
Kojto 98:8ab26030e058 1022 void LESENSE_ChannelThresSet(uint8_t const chIdx,
Kojto 98:8ab26030e058 1023 uint16_t const acmpThres,
Kojto 98:8ab26030e058 1024 uint16_t const cntThres);
Kojto 98:8ab26030e058 1025
Kojto 98:8ab26030e058 1026 void LESENSE_AltExConfig(LESENSE_ConfAltEx_TypeDef const *confAltEx);
Kojto 98:8ab26030e058 1027
Kojto 98:8ab26030e058 1028 void LESENSE_DecoderStateAllConfig(LESENSE_DecStAll_TypeDef const *confDecStAll);
Kojto 98:8ab26030e058 1029 void LESENSE_DecoderStateConfig(LESENSE_DecStDesc_TypeDef const *confDecSt,
Kojto 98:8ab26030e058 1030 uint32_t const decSt);
Kojto 98:8ab26030e058 1031 void LESENSE_DecoderStateSet(uint32_t decSt);
Kojto 98:8ab26030e058 1032 uint32_t LESENSE_DecoderStateGet(void);
Kojto 98:8ab26030e058 1033
Kojto 98:8ab26030e058 1034 void LESENSE_ScanStart(void);
Kojto 98:8ab26030e058 1035 void LESENSE_ScanStop(void);
Kojto 98:8ab26030e058 1036 void LESENSE_DecoderStart(void);
Kojto 98:8ab26030e058 1037 void LESENSE_ResultBufferClear(void);
Kojto 98:8ab26030e058 1038
Kojto 98:8ab26030e058 1039
Kojto 98:8ab26030e058 1040 /***************************************************************************//**
Kojto 98:8ab26030e058 1041 * @brief
Kojto 98:8ab26030e058 1042 * Stop LESENSE decoder.
Kojto 98:8ab26030e058 1043 *
Kojto 98:8ab26030e058 1044 * @details
Kojto 98:8ab26030e058 1045 * This function disables the LESENSE decoder by setting the command to the
Kojto 98:8ab26030e058 1046 * LESENSE_DECCTRL register.
Kojto 98:8ab26030e058 1047 ******************************************************************************/
Kojto 98:8ab26030e058 1048 __STATIC_INLINE void LESENSE_DecoderStop(void)
Kojto 98:8ab26030e058 1049 {
Kojto 98:8ab26030e058 1050 /* Stop the decoder */
Kojto 98:8ab26030e058 1051 LESENSE->DECCTRL |= LESENSE_DECCTRL_DISABLE;
Kojto 98:8ab26030e058 1052 }
Kojto 98:8ab26030e058 1053
Kojto 98:8ab26030e058 1054
Kojto 98:8ab26030e058 1055 /***************************************************************************//**
Kojto 98:8ab26030e058 1056 * @brief
Kojto 98:8ab26030e058 1057 * Get the current status of LESENSE.
Kojto 98:8ab26030e058 1058 *
Kojto 98:8ab26030e058 1059 * @return
Kojto 98:8ab26030e058 1060 * This function returns the value of LESENSE_STATUS register that
Kojto 98:8ab26030e058 1061 * contains the OR combination of the following status bits:
Kojto 98:8ab26030e058 1062 * @li LESENSE_STATUS_RESV - Result data valid. Set when data is available
Kojto 98:8ab26030e058 1063 * in the result buffer. Cleared when the buffer is empty.
Kojto 98:8ab26030e058 1064 * @li LESENSE_STATUS_RESFULL - Result buffer full. Set when the result
Kojto 98:8ab26030e058 1065 * buffer is full.
Kojto 98:8ab26030e058 1066 * @li LESENSE_STATUS_RUNNING - LESENSE is active.
Kojto 98:8ab26030e058 1067 * @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
Kojto 98:8ab26030e058 1068 ******************************************************************************/
Kojto 98:8ab26030e058 1069 __STATIC_INLINE uint32_t LESENSE_StatusGet(void)
Kojto 98:8ab26030e058 1070 {
Kojto 98:8ab26030e058 1071 return LESENSE->STATUS;
Kojto 98:8ab26030e058 1072 }
Kojto 98:8ab26030e058 1073
Kojto 98:8ab26030e058 1074
Kojto 98:8ab26030e058 1075 /***************************************************************************//**
Kojto 98:8ab26030e058 1076 * @brief
Kojto 98:8ab26030e058 1077 * Wait until the status of LESENSE is equal to what requested.
Kojto 98:8ab26030e058 1078 *
Kojto 98:8ab26030e058 1079 * @details
Kojto 98:8ab26030e058 1080 * This function is polling the LESENSE_STATUS register and waits until the
Kojto 98:8ab26030e058 1081 * requested combination of flags are set.
Kojto 98:8ab26030e058 1082 *
Kojto 98:8ab26030e058 1083 * @param[in] flag
Kojto 98:8ab26030e058 1084 * The OR combination of the following status bits:
Kojto 98:8ab26030e058 1085 * @li LESENSE_STATUS_BUFDATAV - Result data valid. Set when data is available
Kojto 98:8ab26030e058 1086 * in the result buffer. Cleared when the buffer is empty.
Kojto 98:8ab26030e058 1087 * @li LESENSE_STATUS_BUFHALFFULL - Result buffer half full. Set when the
Kojto 98:8ab26030e058 1088 * result buffer is half full.
Kojto 98:8ab26030e058 1089 * @li LESENSE_STATUS_BUFFULL - Result buffer full. Set when the result
Kojto 98:8ab26030e058 1090 * buffer is full.
Kojto 98:8ab26030e058 1091 * @li LESENSE_STATUS_RUNNING - LESENSE is active.
Kojto 98:8ab26030e058 1092 * @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
Kojto 98:8ab26030e058 1093 * @li LESENSE_STATUS_DACACTIVE - The DAC interface is currently active.
Kojto 98:8ab26030e058 1094 ******************************************************************************/
Kojto 98:8ab26030e058 1095 __STATIC_INLINE void LESENSE_StatusWait(uint32_t flag)
Kojto 98:8ab26030e058 1096 {
Kojto 98:8ab26030e058 1097 while (!(LESENSE->STATUS & flag))
Kojto 98:8ab26030e058 1098 ;
Kojto 98:8ab26030e058 1099 }
Kojto 98:8ab26030e058 1100
Kojto 98:8ab26030e058 1101
Kojto 98:8ab26030e058 1102 /***************************************************************************//**
Kojto 98:8ab26030e058 1103 * @brief
Kojto 98:8ab26030e058 1104 * Get the currently active channel index.
Kojto 98:8ab26030e058 1105 *
Kojto 98:8ab26030e058 1106 * @return
Kojto 98:8ab26030e058 1107 * This function returns the value of LESENSE_CHINDEX register that
Kojto 98:8ab26030e058 1108 * contains the index of the currently active channel (0-15).
Kojto 98:8ab26030e058 1109 ******************************************************************************/
Kojto 98:8ab26030e058 1110 __STATIC_INLINE uint32_t LESENSE_ChannelActiveGet(void)
Kojto 98:8ab26030e058 1111 {
Kojto 98:8ab26030e058 1112 return LESENSE->CURCH;
Kojto 98:8ab26030e058 1113 }
Kojto 98:8ab26030e058 1114
Kojto 98:8ab26030e058 1115
Kojto 98:8ab26030e058 1116 /***************************************************************************//**
Kojto 98:8ab26030e058 1117 * @brief
Kojto 98:8ab26030e058 1118 * Get the latest scan comparison result (1 bit / channel).
Kojto 98:8ab26030e058 1119 *
Kojto 98:8ab26030e058 1120 * @return
Kojto 98:8ab26030e058 1121 * This function returns the value of LESENSE_SCANRES register that
Kojto 98:8ab26030e058 1122 * contains the comparison result of the last scan on all channels.
Kojto 98:8ab26030e058 1123 * Bit x is set if a comparison triggered on channel x, which means that the
Kojto 98:8ab26030e058 1124 * LESENSE counter met the comparison criteria set in LESENSE_CHx_EVAL by
Kojto 98:8ab26030e058 1125 * COMPMODE and CNTTHRES.
Kojto 98:8ab26030e058 1126 ******************************************************************************/
Kojto 98:8ab26030e058 1127 __STATIC_INLINE uint32_t LESENSE_ScanResultGet(void)
Kojto 98:8ab26030e058 1128 {
Kojto 98:8ab26030e058 1129 return LESENSE->SCANRES;
Kojto 98:8ab26030e058 1130 }
Kojto 98:8ab26030e058 1131
Kojto 98:8ab26030e058 1132
Kojto 98:8ab26030e058 1133 /***************************************************************************//**
Kojto 98:8ab26030e058 1134 * @brief
Kojto 98:8ab26030e058 1135 * Get the oldest unread data from the result buffer.
Kojto 98:8ab26030e058 1136 *
Kojto 98:8ab26030e058 1137 * @note
Kojto 98:8ab26030e058 1138 * Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
Kojto 98:8ab26030e058 1139 * STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return
Kojto 98:8ab26030e058 1140 * undefined value.
Kojto 98:8ab26030e058 1141 *
Kojto 98:8ab26030e058 1142 * @return
Kojto 98:8ab26030e058 1143 * This function returns the value of LESENSE_RESDATA register that
Kojto 98:8ab26030e058 1144 * contains the oldest unread counter result from the result buffer.
Kojto 98:8ab26030e058 1145 ******************************************************************************/
Kojto 98:8ab26030e058 1146 __STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
Kojto 98:8ab26030e058 1147 {
Kojto 98:8ab26030e058 1148 return LESENSE->BUFDATA;
Kojto 98:8ab26030e058 1149 }
Kojto 98:8ab26030e058 1150
Kojto 98:8ab26030e058 1151
Kojto 98:8ab26030e058 1152 /***************************************************************************//**
Kojto 98:8ab26030e058 1153 * @brief
Kojto 98:8ab26030e058 1154 * Get data from the result data buffer.
Kojto 98:8ab26030e058 1155 *
Kojto 98:8ab26030e058 1156 * @note
Kojto 98:8ab26030e058 1157 * Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
Kojto 98:8ab26030e058 1158 * STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return
Kojto 98:8ab26030e058 1159 * undefined value.
Kojto 98:8ab26030e058 1160 *
Kojto 98:8ab26030e058 1161 * @param[in] idx
Kojto 98:8ab26030e058 1162 * Result data buffer index. Valid range: 0-15.
Kojto 98:8ab26030e058 1163 *
Kojto 98:8ab26030e058 1164 * @return
Kojto 98:8ab26030e058 1165 * This function returns the selected word from the result data buffer.
Kojto 98:8ab26030e058 1166 ******************************************************************************/
Kojto 98:8ab26030e058 1167 __STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
Kojto 98:8ab26030e058 1168 {
Kojto 98:8ab26030e058 1169 /* Note: masking is needed to avoid over-indexing! */
Kojto 98:8ab26030e058 1170 return LESENSE->BUF[idx & 0x0FU].DATA;
Kojto 98:8ab26030e058 1171 }
Kojto 98:8ab26030e058 1172
Kojto 98:8ab26030e058 1173 /***************************************************************************//**
Kojto 98:8ab26030e058 1174 * @brief
Kojto 98:8ab26030e058 1175 * Get the current state of the LESENSE sensor.
Kojto 98:8ab26030e058 1176 *
Kojto 98:8ab26030e058 1177 * @return
Kojto 98:8ab26030e058 1178 * This function returns the value of LESENSE_SENSORSTATE register that
Kojto 98:8ab26030e058 1179 * represents the current state of the LESENSE sensor.
Kojto 98:8ab26030e058 1180 ******************************************************************************/
Kojto 98:8ab26030e058 1181 __STATIC_INLINE uint32_t LESENSE_SensorStateGet(void)
Kojto 98:8ab26030e058 1182 {
Kojto 98:8ab26030e058 1183 return LESENSE->SENSORSTATE;
Kojto 98:8ab26030e058 1184 }
Kojto 98:8ab26030e058 1185
Kojto 98:8ab26030e058 1186
Kojto 98:8ab26030e058 1187 /***************************************************************************//**
Kojto 98:8ab26030e058 1188 * @brief
Kojto 98:8ab26030e058 1189 * Shut off power to the LESENSE RAM, disables LESENSE.
Kojto 98:8ab26030e058 1190 *
Kojto 98:8ab26030e058 1191 * @details
Kojto 98:8ab26030e058 1192 * This function shuts off the LESENSE RAM in order to decrease the leakage
Kojto 113:f141b2784e32 1193 * current of the mcu if LESENSE is not used in your application.
Kojto 98:8ab26030e058 1194 *
Kojto 98:8ab26030e058 1195 * @note
Kojto 98:8ab26030e058 1196 * Warning! Once the LESENSE RAM is powered down, it cannot be powered up
Kojto 98:8ab26030e058 1197 * again.
Kojto 98:8ab26030e058 1198 ******************************************************************************/
Kojto 98:8ab26030e058 1199 __STATIC_INLINE void LESENSE_RAMPowerDown(void)
Kojto 98:8ab26030e058 1200 {
Kojto 98:8ab26030e058 1201 /* Power down LESENSE RAM */
Kojto 98:8ab26030e058 1202 LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
Kojto 98:8ab26030e058 1203 }
Kojto 98:8ab26030e058 1204
Kojto 98:8ab26030e058 1205
Kojto 98:8ab26030e058 1206 /***************************************************************************//**
Kojto 98:8ab26030e058 1207 * @brief
Kojto 98:8ab26030e058 1208 * Clear one or more pending LESENSE interrupts.
Kojto 98:8ab26030e058 1209 *
Kojto 98:8ab26030e058 1210 * @param[in] flags
Kojto 98:8ab26030e058 1211 * Pending LESENSE interrupt sources to clear. Use a set of interrupt flags
Kojto 98:8ab26030e058 1212 * OR-ed together to clear multiple interrupt sources of the LESENSE module
Kojto 98:8ab26030e058 1213 * (LESENSE_IF_nnn).
Kojto 98:8ab26030e058 1214 ******************************************************************************/
Kojto 98:8ab26030e058 1215 __STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
Kojto 98:8ab26030e058 1216 {
Kojto 98:8ab26030e058 1217 LESENSE->IFC = flags;
Kojto 98:8ab26030e058 1218 }
Kojto 98:8ab26030e058 1219
Kojto 98:8ab26030e058 1220
Kojto 98:8ab26030e058 1221 /***************************************************************************//**
Kojto 98:8ab26030e058 1222 * @brief
Kojto 98:8ab26030e058 1223 * Enable one or more LESENSE interrupts.
Kojto 98:8ab26030e058 1224 *
Kojto 98:8ab26030e058 1225 * @param[in] flags
Kojto 98:8ab26030e058 1226 * LESENSE interrupt sources to enable. Use a set of interrupt flags OR-ed
Kojto 98:8ab26030e058 1227 * together to enable multiple interrupt sources of the LESENSE module
Kojto 98:8ab26030e058 1228 * (LESENSE_IF_nnn).
Kojto 98:8ab26030e058 1229 ******************************************************************************/
Kojto 98:8ab26030e058 1230 __STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
Kojto 98:8ab26030e058 1231 {
Kojto 98:8ab26030e058 1232 LESENSE->IEN |= flags;
Kojto 98:8ab26030e058 1233 }
Kojto 98:8ab26030e058 1234
Kojto 98:8ab26030e058 1235
Kojto 98:8ab26030e058 1236 /***************************************************************************//**
Kojto 98:8ab26030e058 1237 * @brief
Kojto 98:8ab26030e058 1238 * Disable one or more LESENSE interrupts.
Kojto 98:8ab26030e058 1239 *
Kojto 98:8ab26030e058 1240 * @param[in] flags
Kojto 98:8ab26030e058 1241 * LESENSE interrupt sources to disable. Use a set of interrupt flags OR-ed
Kojto 98:8ab26030e058 1242 * together to disable multiple interrupt sources of the LESENSE module
Kojto 98:8ab26030e058 1243 * (LESENSE_IF_nnn).
Kojto 98:8ab26030e058 1244 ******************************************************************************/
Kojto 98:8ab26030e058 1245 __STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
Kojto 98:8ab26030e058 1246 {
Kojto 113:f141b2784e32 1247 LESENSE->IEN &= ~flags;
Kojto 98:8ab26030e058 1248 }
Kojto 98:8ab26030e058 1249
Kojto 98:8ab26030e058 1250
Kojto 98:8ab26030e058 1251 /***************************************************************************//**
Kojto 98:8ab26030e058 1252 * @brief
Kojto 98:8ab26030e058 1253 * Set one or more pending LESENSE interrupts from SW.
Kojto 98:8ab26030e058 1254 *
Kojto 98:8ab26030e058 1255 * @param[in] flags
Kojto 98:8ab26030e058 1256 * LESENSE interrupt sources to set to pending. Use a set of interrupt
Kojto 98:8ab26030e058 1257 * flags OR-ed together to set multiple interrupt sources of the LESENSE
Kojto 98:8ab26030e058 1258 * module (LESENSE_IFS_nnn).
Kojto 98:8ab26030e058 1259 ******************************************************************************/
Kojto 98:8ab26030e058 1260 __STATIC_INLINE void LESENSE_IntSet(uint32_t flags)
Kojto 98:8ab26030e058 1261 {
Kojto 98:8ab26030e058 1262 LESENSE->IFS = flags;
Kojto 98:8ab26030e058 1263 }
Kojto 98:8ab26030e058 1264
Kojto 98:8ab26030e058 1265
Kojto 98:8ab26030e058 1266 /***************************************************************************//**
Kojto 98:8ab26030e058 1267 * @brief
Kojto 98:8ab26030e058 1268 * Get pending LESENSE interrupt flags.
Kojto 98:8ab26030e058 1269 *
Kojto 98:8ab26030e058 1270 * @note
Kojto 98:8ab26030e058 1271 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 1272 *
Kojto 98:8ab26030e058 1273 * @return
Kojto 98:8ab26030e058 1274 * Pending LESENSE interrupt sources. The OR combination of valid interrupt
Kojto 98:8ab26030e058 1275 * flags of the LESENSE module (LESENSE_IF_nnn).
Kojto 98:8ab26030e058 1276 ******************************************************************************/
Kojto 98:8ab26030e058 1277 __STATIC_INLINE uint32_t LESENSE_IntGet(void)
Kojto 98:8ab26030e058 1278 {
Kojto 98:8ab26030e058 1279 return LESENSE->IF;
Kojto 98:8ab26030e058 1280 }
Kojto 98:8ab26030e058 1281
Kojto 98:8ab26030e058 1282
Kojto 98:8ab26030e058 1283 /***************************************************************************//**
Kojto 98:8ab26030e058 1284 * @brief
Kojto 98:8ab26030e058 1285 * Get enabled and pending LESENSE interrupt flags.
Kojto 98:8ab26030e058 1286 *
Kojto 98:8ab26030e058 1287 * @details
Kojto 98:8ab26030e058 1288 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 98:8ab26030e058 1289 *
Kojto 98:8ab26030e058 1290 * @note
Kojto 98:8ab26030e058 1291 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 1292 *
Kojto 98:8ab26030e058 1293 * @return
Kojto 98:8ab26030e058 1294 * Pending and enabled LESENSE interrupt sources.
Kojto 98:8ab26030e058 1295 * The return value is the bitwise AND combination of
Kojto 98:8ab26030e058 1296 * - the OR combination of enabled interrupt sources in LESENSE_IEN_nnn
Kojto 98:8ab26030e058 1297 * register (LESENSE_IEN_nnn) and
Kojto 98:8ab26030e058 1298 * - the OR combination of valid interrupt flags of the LESENSE module
Kojto 98:8ab26030e058 1299 * (LESENSE_IF_nnn).
Kojto 98:8ab26030e058 1300 ******************************************************************************/
Kojto 98:8ab26030e058 1301 __STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
Kojto 98:8ab26030e058 1302 {
Kojto 98:8ab26030e058 1303 uint32_t tmp;
Kojto 98:8ab26030e058 1304
Kojto 98:8ab26030e058 1305 /* Store LESENSE->IEN in temporary variable in order to define explicit order
Kojto 98:8ab26030e058 1306 * of volatile accesses. */
Kojto 98:8ab26030e058 1307 tmp = LESENSE->IEN;
Kojto 98:8ab26030e058 1308
Kojto 98:8ab26030e058 1309 /* Bitwise AND of pending and enabled interrupts */
Kojto 98:8ab26030e058 1310 return LESENSE->IF & tmp;
Kojto 98:8ab26030e058 1311 }
Kojto 98:8ab26030e058 1312
Kojto 98:8ab26030e058 1313
Kojto 98:8ab26030e058 1314 /** @} (end addtogroup LESENSE) */
<> 128:9bcdf88f62b0 1315 /** @} (end addtogroup emlib) */
Kojto 98:8ab26030e058 1316
Kojto 98:8ab26030e058 1317 #ifdef __cplusplus
Kojto 98:8ab26030e058 1318 }
Kojto 98:8ab26030e058 1319 #endif
Kojto 98:8ab26030e058 1320
Kojto 98:8ab26030e058 1321 #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
Kojto 98:8ab26030e058 1322
<> 128:9bcdf88f62b0 1323 #endif /* EM_LESENSE_H */