The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Tue Feb 02 14:43:35 2016 +0000
Revision:
113:f141b2784e32
Parent:
98:8ab26030e058
Child:
128:9bcdf88f62b0
Release 113 of the mbed library

Changes:
- new targets - Silabs Perl Gecko, TY51822
- Silabs - emlib update to 4.1.0, various bugfixes as result
- STM B96B_F446VE - add async serial support
- Freescale KLXX - rtc lock fix
- LPC11U68 and LPC1549 - pwm bugfixes - duty cycle

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