efm32_lesense.h 53 KB

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