efm32_lesense.h 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Low Energy Sensor (LESENSE) peripheral API for EFM32 TG/GG devices.
  4. * @author Energy Micro AS
  5. * @version 2.3.2
  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. lesensePRSCh0, /* 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. LESENSE->CMD = LESENSE_CMD_CLEARBUF;
  836. }
  837. /***************************************************************************//**
  838. * @brief
  839. * Get the current status of LESENSE.
  840. *
  841. * @return
  842. * This function returns the value of LESENSE_STATUS register that
  843. * contains the OR combination of the following status bits:
  844. * @li LESENSE_STATUS_RESV - Result data valid. Set when data is available
  845. * in the result buffer. Cleared when the buffer is empty.
  846. * @li LESENSE_STATUS_RESFULL - Result buffer full. Set when the result
  847. * buffer is full.
  848. * @li LESENSE_STATUS_RUNNING - LESENSE is active.
  849. * @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
  850. ******************************************************************************/
  851. static __INLINE uint32_t LESENSE_StatusGet(void)
  852. {
  853. return LESENSE->STATUS;
  854. }
  855. /***************************************************************************//**
  856. * @brief
  857. * Wait until the status of LESENSE is equal to what requested.
  858. *
  859. * @details
  860. * This function is polling the LESENSE_STATUS register and waits until the
  861. * requested combination of flags are set.
  862. *
  863. * @param[in] flag
  864. * The OR combination of the following status bits:
  865. * @li LESENSE_STATUS_BUFDATAV - Result data valid. Set when data is available
  866. * in the result buffer. Cleared when the buffer is empty.
  867. * @li LESENSE_STATUS_BUFHALFFULL - Result buffer half full. Set when the
  868. * result buffer is half full.
  869. * @li LESENSE_STATUS_BUFFULL - Result buffer full. Set when the result
  870. * buffer is full.
  871. * @li LESENSE_STATUS_RUNNING - LESENSE is active.
  872. * @li LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
  873. * @li LESENSE_STATUS_DACACTIVE - The DAC interface is currently active.
  874. ******************************************************************************/
  875. static __INLINE void LESENSE_StatusWait(uint32_t flag)
  876. {
  877. while (!(LESENSE->STATUS & flag))
  878. ;
  879. }
  880. /***************************************************************************//**
  881. * @brief
  882. * Get the currently active channel index.
  883. *
  884. * @return
  885. * This function returns the value of LESENSE_CHINDEX register that
  886. * contains the index of the currently active channel (0-15).
  887. ******************************************************************************/
  888. static __INLINE uint32_t LESENSE_ChannelActiveGet(void)
  889. {
  890. return LESENSE->CURCH;
  891. }
  892. /***************************************************************************//**
  893. * @brief
  894. * Get the latest scan comparison result (1 bit / channel).
  895. *
  896. * @return
  897. * This function returns the value of LESENSE_SCANRES register that
  898. * contains the comparison result of the last scan on all channels.
  899. * Bit x is set if a comparison triggered on channel x, which means that the
  900. * LESENSE counter met the comparison criteria set in LESENSE_CHx_EVAL by
  901. * COMPMODE and CNTTHRES.
  902. ******************************************************************************/
  903. static __INLINE uint32_t LESENSE_ScanResultGet(void)
  904. {
  905. return LESENSE->SCANRES;
  906. }
  907. /***************************************************************************//**
  908. * @brief
  909. * Get the oldest unread data from the result buffer.
  910. *
  911. * @note
  912. * Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
  913. * STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return
  914. * undefined value.
  915. *
  916. * @return
  917. * This function returns the value of LESENSE_RESDATA register that
  918. * contains the oldest unread counter result from the result buffer.
  919. ******************************************************************************/
  920. static __INLINE uint32_t LESENSE_ScanResultDataGet(void)
  921. {
  922. return LESENSE->BUFDATA;
  923. }
  924. /***************************************************************************//**
  925. * @brief
  926. * Get data from the result data buffer.
  927. *
  928. * @note
  929. * Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or
  930. * STRSCANRES bit is set in LESENSE_CTRL, otherwise this function will return
  931. * undefined value.
  932. *
  933. * @param[in]
  934. * Result data buffer index. Valid range: 0-15.
  935. *
  936. * @return
  937. * This function returns the selected word from the result data buffer.
  938. ******************************************************************************/
  939. static __INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
  940. {
  941. /* Note: masking is needed to avoid over-indexing! */
  942. return LESENSE->BUF[idx & 0x0FU].DATA;
  943. }
  944. /***************************************************************************//**
  945. * @brief
  946. * Get the current state of the LESENSE sensor.
  947. *
  948. * @return
  949. * This function returns the value of LESENSE_SENSORSTATE register that
  950. * represents the current state of the LESENSE sensor.
  951. ******************************************************************************/
  952. static __INLINE uint32_t LESENSE_SensorStateGet(void)
  953. {
  954. return LESENSE->SENSORSTATE;
  955. }
  956. /***************************************************************************//**
  957. * @brief
  958. * Shut off power to the LESENSE RAM, disables LESENSE.
  959. *
  960. * @details
  961. * This function shuts off the LESENSE RAM in order to decrease the leakage
  962. * current of EFM32 if LESENSE is not used in your application.
  963. *
  964. * @note
  965. * Warning! Once the LESENSE RAM is powered down, it cannot be powered up
  966. * again.
  967. ******************************************************************************/
  968. static __INLINE void LESENSE_RAMPowerDown(void)
  969. {
  970. /* Power down LESENSE RAM */
  971. LESENSE->POWERDOWN = LESENSE_POWERDOWN_RAM;
  972. }
  973. /***************************************************************************//**
  974. * @brief
  975. * Clear one or more pending LESENSE interrupts.
  976. *
  977. * @param[in] flags
  978. * Pending LESENSE interrupt sources to clear. Use a set of interrupt flags
  979. * OR-ed together to clear multiple interrupt sources of the LESENSE module
  980. * (LESENSE_IF_nnn).
  981. ******************************************************************************/
  982. static __INLINE void LESENSE_IntClear(uint32_t flags)
  983. {
  984. LESENSE->IFC = flags;
  985. }
  986. /***************************************************************************//**
  987. * @brief
  988. * Enable one or more LESENSE interrupts.
  989. *
  990. * @param[in] flags
  991. * LESENSE interrupt sources to enable. Use a set of interrupt flags OR-ed
  992. * together to enable multiple interrupt sources of the LESENSE module
  993. * (LESENSE_IF_nnn).
  994. ******************************************************************************/
  995. static __INLINE void LESENSE_IntEnable(uint32_t flags)
  996. {
  997. LESENSE->IEN |= flags;
  998. }
  999. /***************************************************************************//**
  1000. * @brief
  1001. * Disable one or more LESENSE interrupts.
  1002. *
  1003. * @param[in] flags
  1004. * LESENSE interrupt sources to disable. Use a set of interrupt flags OR-ed
  1005. * together to disable multiple interrupt sources of the LESENSE module
  1006. * (LESENSE_IF_nnn).
  1007. ******************************************************************************/
  1008. static __INLINE void LESENSE_IntDisable(uint32_t flags)
  1009. {
  1010. LESENSE->IEN &= ~(flags);
  1011. }
  1012. /***************************************************************************//**
  1013. * @brief
  1014. * Set one or more pending LESENSE interrupts from SW.
  1015. *
  1016. * @param[in] flags
  1017. * LESENSE interrupt sources to set to pending. Use a set of interrupt
  1018. * flags OR-ed together to set multiple interrupt sources of the LESENSE
  1019. * module (LESENSE_IFS_nnn).
  1020. ******************************************************************************/
  1021. static __INLINE void LESENSE_IntSet(uint32_t flags)
  1022. {
  1023. LESENSE->IFS = flags;
  1024. }
  1025. /***************************************************************************//**
  1026. * @brief
  1027. * Get pending LESENSE interrupt flags.
  1028. *
  1029. * @note
  1030. * The event bits are not cleared by the use of this function.
  1031. *
  1032. * @return
  1033. * Pending LESENSE interrupt sources. The OR combination of valid interrupt
  1034. * flags of the LESENSE module (LESENSE_IF_nnn).
  1035. ******************************************************************************/
  1036. static __INLINE uint32_t LESENSE_IntGet(void)
  1037. {
  1038. return LESENSE->IF;
  1039. }
  1040. /***************************************************************************//**
  1041. * @brief
  1042. * Get enabled and pending LESENSE interrupt flags.
  1043. *
  1044. * @details
  1045. * Useful for handling more interrupt sources in the same interrupt handler.
  1046. *
  1047. * @note
  1048. * The event bits are not cleared by the use of this function.
  1049. *
  1050. * @return
  1051. * Pending and enabled LESENSE interrupt sources.
  1052. * The return value is the bitwise AND combination of
  1053. * - the OR combination of enabled interrupt sources in LESENSE_IEN_nnn
  1054. * register (LESENSE_IEN_nnn) and
  1055. * - the OR combination of valid interrupt flags of the LESENSE module
  1056. * (LESENSE_IF_nnn).
  1057. ******************************************************************************/
  1058. static __INLINE uint32_t LESENSE_IntGetEnabled(void)
  1059. {
  1060. uint32_t tmp = 0U;
  1061. /* Store LESENSE->IEN in temporary variable in order to define explicit order
  1062. * of volatile accesses. */
  1063. tmp = LESENSE->IEN;
  1064. /* Bitwise AND of pending and enabled interrupts */
  1065. return LESENSE->IF & tmp;
  1066. }
  1067. /** @} (end addtogroup LESENSE) */
  1068. /** @} (end addtogroup EFM32_Library) */
  1069. #ifdef __cplusplus
  1070. }
  1071. #endif
  1072. #endif /* defined(LESENSE_COUNT) && (LESENSE_COUNT > 0) */
  1073. #endif /* __EFM32_LESENSE_H */