em_lesense.h 53 KB

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