nrf_lpcomp.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /**
  2. * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF_LPCOMP_H_
  41. #define NRF_LPCOMP_H_
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_lpcomp_hal LPCOMP HAL
  48. * @{
  49. * @ingroup nrf_lpcomp
  50. * @brief Hardware access layer for managing the Low Power Comparator (LPCOMP) peripheral.
  51. */
  52. /** @brief LPCOMP reference selection. */
  53. typedef enum
  54. {
  55. #if (LPCOMP_REFSEL_RESOLUTION == 8) || defined(__NRFX_DOXYGEN__)
  56. NRF_LPCOMP_REF_SUPPLY_1_8 = LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling, /**< Use supply with a 1/8 prescaler as reference. */
  57. NRF_LPCOMP_REF_SUPPLY_2_8 = LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling, /**< Use supply with a 2/8 prescaler as reference. */
  58. NRF_LPCOMP_REF_SUPPLY_3_8 = LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling, /**< Use supply with a 3/8 prescaler as reference. */
  59. NRF_LPCOMP_REF_SUPPLY_4_8 = LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling, /**< Use supply with a 4/8 prescaler as reference. */
  60. NRF_LPCOMP_REF_SUPPLY_5_8 = LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling, /**< Use supply with a 5/8 prescaler as reference. */
  61. NRF_LPCOMP_REF_SUPPLY_6_8 = LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling, /**< Use supply with a 6/8 prescaler as reference. */
  62. NRF_LPCOMP_REF_SUPPLY_7_8 = LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling, /**< Use supply with a 7/8 prescaler as reference. */
  63. #elif (LPCOMP_REFSEL_RESOLUTION == 16) || defined(__NRFX_DOXYGEN__)
  64. NRF_LPCOMP_REF_SUPPLY_1_8 = LPCOMP_REFSEL_REFSEL_Ref1_8Vdd, /**< Use supply with a 1/8 prescaler as reference. */
  65. NRF_LPCOMP_REF_SUPPLY_2_8 = LPCOMP_REFSEL_REFSEL_Ref2_8Vdd, /**< Use supply with a 2/8 prescaler as reference. */
  66. NRF_LPCOMP_REF_SUPPLY_3_8 = LPCOMP_REFSEL_REFSEL_Ref3_8Vdd, /**< Use supply with a 3/8 prescaler as reference. */
  67. NRF_LPCOMP_REF_SUPPLY_4_8 = LPCOMP_REFSEL_REFSEL_Ref4_8Vdd, /**< Use supply with a 4/8 prescaler as reference. */
  68. NRF_LPCOMP_REF_SUPPLY_5_8 = LPCOMP_REFSEL_REFSEL_Ref5_8Vdd, /**< Use supply with a 5/8 prescaler as reference. */
  69. NRF_LPCOMP_REF_SUPPLY_6_8 = LPCOMP_REFSEL_REFSEL_Ref6_8Vdd, /**< Use supply with a 6/8 prescaler as reference. */
  70. NRF_LPCOMP_REF_SUPPLY_7_8 = LPCOMP_REFSEL_REFSEL_Ref7_8Vdd, /**< Use supply with a 7/8 prescaler as reference. */
  71. NRF_LPCOMP_REF_SUPPLY_1_16 = LPCOMP_REFSEL_REFSEL_Ref1_16Vdd, /**< Use supply with a 1/16 prescaler as reference. */
  72. NRF_LPCOMP_REF_SUPPLY_3_16 = LPCOMP_REFSEL_REFSEL_Ref3_16Vdd, /**< Use supply with a 3/16 prescaler as reference. */
  73. NRF_LPCOMP_REF_SUPPLY_5_16 = LPCOMP_REFSEL_REFSEL_Ref5_16Vdd, /**< Use supply with a 5/16 prescaler as reference. */
  74. NRF_LPCOMP_REF_SUPPLY_7_16 = LPCOMP_REFSEL_REFSEL_Ref7_16Vdd, /**< Use supply with a 7/16 prescaler as reference. */
  75. NRF_LPCOMP_REF_SUPPLY_9_16 = LPCOMP_REFSEL_REFSEL_Ref9_16Vdd, /**< Use supply with a 9/16 prescaler as reference. */
  76. NRF_LPCOMP_REF_SUPPLY_11_16 = LPCOMP_REFSEL_REFSEL_Ref11_16Vdd, /**< Use supply with a 11/16 prescaler as reference. */
  77. NRF_LPCOMP_REF_SUPPLY_13_16 = LPCOMP_REFSEL_REFSEL_Ref13_16Vdd, /**< Use supply with a 13/16 prescaler as reference. */
  78. NRF_LPCOMP_REF_SUPPLY_15_16 = LPCOMP_REFSEL_REFSEL_Ref15_16Vdd, /**< Use supply with a 15/16 prescaler as reference. */
  79. #endif
  80. NRF_LPCOMP_REF_EXT_REF0 = LPCOMP_REFSEL_REFSEL_ARef |
  81. (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference0 << 16), /**< External reference 0. */
  82. NRF_LPCOMP_CONFIG_REF_EXT_REF1 = LPCOMP_REFSEL_REFSEL_ARef |
  83. (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference1 << 16), /**< External reference 1. */
  84. } nrf_lpcomp_ref_t;
  85. /** @brief LPCOMP input selection. */
  86. typedef enum
  87. {
  88. NRF_LPCOMP_INPUT_0 = LPCOMP_PSEL_PSEL_AnalogInput0, /**< Input 0. */
  89. NRF_LPCOMP_INPUT_1 = LPCOMP_PSEL_PSEL_AnalogInput1, /**< Input 1. */
  90. NRF_LPCOMP_INPUT_2 = LPCOMP_PSEL_PSEL_AnalogInput2, /**< Input 2. */
  91. NRF_LPCOMP_INPUT_3 = LPCOMP_PSEL_PSEL_AnalogInput3, /**< Input 3. */
  92. NRF_LPCOMP_INPUT_4 = LPCOMP_PSEL_PSEL_AnalogInput4, /**< Input 4. */
  93. NRF_LPCOMP_INPUT_5 = LPCOMP_PSEL_PSEL_AnalogInput5, /**< Input 5. */
  94. NRF_LPCOMP_INPUT_6 = LPCOMP_PSEL_PSEL_AnalogInput6, /**< Input 6. */
  95. NRF_LPCOMP_INPUT_7 = LPCOMP_PSEL_PSEL_AnalogInput7 /**< Input 7. */
  96. } nrf_lpcomp_input_t;
  97. /** @brief LPCOMP detection type selection. */
  98. typedef enum
  99. {
  100. NRF_LPCOMP_DETECT_CROSS = LPCOMP_ANADETECT_ANADETECT_Cross, /**< Generate ANADETEC on crossing, both upwards and downwards crossing. */
  101. NRF_LPCOMP_DETECT_UP = LPCOMP_ANADETECT_ANADETECT_Up, /**< Generate ANADETEC on upwards crossing only. */
  102. NRF_LPCOMP_DETECT_DOWN = LPCOMP_ANADETECT_ANADETECT_Down /**< Generate ANADETEC on downwards crossing only. */
  103. } nrf_lpcomp_detect_t;
  104. /** @brief LPCOMP tasks. */
  105. typedef enum
  106. {
  107. NRF_LPCOMP_TASK_START = offsetof(NRF_LPCOMP_Type, TASKS_START), /**< LPCOMP start sampling task. */
  108. NRF_LPCOMP_TASK_STOP = offsetof(NRF_LPCOMP_Type, TASKS_STOP), /**< LPCOMP stop sampling task. */
  109. NRF_LPCOMP_TASK_SAMPLE = offsetof(NRF_LPCOMP_Type, TASKS_SAMPLE) /**< Sample comparator value. */
  110. } nrf_lpcomp_task_t;
  111. /** @brief LPCOMP events. */
  112. typedef enum
  113. {
  114. NRF_LPCOMP_EVENT_READY = offsetof(NRF_LPCOMP_Type, EVENTS_READY), /**< LPCOMP is ready and output is valid. */
  115. NRF_LPCOMP_EVENT_DOWN = offsetof(NRF_LPCOMP_Type, EVENTS_DOWN), /**< Input voltage crossed the threshold going down. */
  116. NRF_LPCOMP_EVENT_UP = offsetof(NRF_LPCOMP_Type, EVENTS_UP), /**< Input voltage crossed the threshold going up. */
  117. NRF_LPCOMP_EVENT_CROSS = offsetof(NRF_LPCOMP_Type, EVENTS_CROSS) /**< Input voltage crossed the threshold in any direction. */
  118. } nrf_lpcomp_event_t;
  119. /** @brief LPCOMP shortcut masks. */
  120. typedef enum
  121. {
  122. NRF_LPCOMP_SHORT_CROSS_STOP_MASK = LPCOMP_SHORTS_CROSS_STOP_Msk, /*!< Shortcut between CROSS event and STOP task. */
  123. NRF_LPCOMP_SHORT_UP_STOP_MASK = LPCOMP_SHORTS_UP_STOP_Msk, /*!< Shortcut between UP event and STOP task. */
  124. NRF_LPCOMP_SHORT_DOWN_STOP_MASK = LPCOMP_SHORTS_DOWN_STOP_Msk, /*!< Shortcut between DOWN event and STOP task. */
  125. NRF_LPCOMP_SHORT_READY_STOP_MASK = LPCOMP_SHORTS_READY_STOP_Msk, /*!< Shortcut between READY event and STOP task. */
  126. NRF_LPCOMP_SHORT_READY_SAMPLE_MASK = LPCOMP_SHORTS_READY_SAMPLE_Msk /*!< Shortcut between READY event and SAMPLE task. */
  127. } nrf_lpcomp_short_mask_t;
  128. #ifdef LPCOMP_FEATURE_HYST_PRESENT
  129. /** @brief LPCOMP hysteresis. */
  130. typedef enum
  131. {
  132. NRF_LPCOMP_HYST_NOHYST = LPCOMP_HYST_HYST_NoHyst, /**< Comparator hysteresis disabled. */
  133. NRF_LPCOMP_HYST_50mV = LPCOMP_HYST_HYST_Hyst50mV /**< Comparator hysteresis enabled (typically 50 mV). */
  134. }nrf_lpcomp_hysteresis_t;
  135. #endif // LPCOMP_FEATURE_HYST_PRESENT
  136. /** @brief LPCOMP configuration. */
  137. typedef struct
  138. {
  139. nrf_lpcomp_ref_t reference; /**< LPCOMP reference. */
  140. nrf_lpcomp_detect_t detection; /**< LPCOMP detection type. */
  141. #ifdef LPCOMP_FEATURE_HYST_PRESENT
  142. nrf_lpcomp_hysteresis_t hyst; /**< LPCOMP hysteresis. */
  143. #endif // LPCOMP_FEATURE_HYST_PRESENT
  144. } nrf_lpcomp_config_t;
  145. /** Default LPCOMP configuration. */
  146. #define NRF_LPCOMP_CONFIG_DEFAULT { NRF_LPCOMP_REF_SUPPLY_FOUR_EIGHT, NRF_LPCOMP_DETECT_DOWN }
  147. /**
  148. * @brief Function for configuring LPCOMP.
  149. *
  150. * This function powers on LPCOMP and configures it. LPCOMP is in DISABLE state after configuration,
  151. * so it must be enabled before using it. All shorts are inactive, events are cleared, and LPCOMP is stopped.
  152. *
  153. * @param[in] p_config Configuration.
  154. */
  155. __STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config);
  156. /**
  157. * @brief Function for selecting the LPCOMP input.
  158. *
  159. * This function selects the active input of LPCOMP.
  160. *
  161. * @param[in] input Input to be selected.
  162. */
  163. __STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input);
  164. /**
  165. * @brief Function for enabling the Low Power Comparator.
  166. *
  167. * This function enables LPCOMP.
  168. */
  169. __STATIC_INLINE void nrf_lpcomp_enable(void);
  170. /**
  171. * @brief Function for disabling the Low Power Comparator.
  172. *
  173. * This function disables LPCOMP.
  174. */
  175. __STATIC_INLINE void nrf_lpcomp_disable(void);
  176. /**
  177. * @brief Function for getting the last LPCOMP compare result.
  178. *
  179. * @return The last compare result. If 0 then VIN+ < VIN-, if 1 then the opposite.
  180. */
  181. __STATIC_INLINE uint32_t nrf_lpcomp_result_get(void);
  182. /**
  183. * @brief Function for enabling interrupts from LPCOMP.
  184. *
  185. * @param[in] int_mask Mask of interrupts to be enabled.
  186. *
  187. * @sa nrf_lpcomp_int_disable
  188. * @sa nrf_lpcomp_int_enable_check
  189. */
  190. __STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t int_mask);
  191. /**
  192. * @brief Function for disabling interrupts from LPCOMP.
  193. *
  194. * @param[in] int_mask Mask of interrupts to be disabled.
  195. *
  196. * @sa nrf_lpcomp_int_enable
  197. * @sa nrf_lpcomp_int_enable_check
  198. */
  199. __STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t int_mask);
  200. /**
  201. * @brief Function for getting the enabled interrupts of LPCOMP.
  202. *
  203. * @param[in] int_mask Mask of interrupts to be checked.
  204. *
  205. * @retval true Any of interrupts of the specified mask are enabled.
  206. * @retval false None interrupt specified by the mask are enabled.
  207. *
  208. * @sa nrf_lpcomp_int_enable
  209. * @sa nrf_lpcomp_int_disable
  210. */
  211. __STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t int_mask);
  212. /**
  213. * @brief Function for getting the address of the specified LPCOMP task register.
  214. *
  215. * @param[in] task LPCOMP task.
  216. *
  217. * @return The address of the specified LPCOMP task.
  218. */
  219. __STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t task);
  220. /**
  221. * @brief Function for getting the address of the specified LPCOMP event register.
  222. *
  223. * @param[in] event LPCOMP event.
  224. *
  225. * @return The address of the specified LPCOMP event.
  226. */
  227. __STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t event);
  228. /**
  229. * @brief Function for setting LPCOMP shorts.
  230. *
  231. * @param[in] mask Mask of shortcuts.
  232. */
  233. __STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t mask);
  234. /**
  235. * @brief Function for clearing LPCOMP shorts by mask.
  236. *
  237. * @param[in] mask Mask of shortcuts.
  238. */
  239. __STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t mask);
  240. /**
  241. * @brief Function for setting the specified LPCOMP task.
  242. *
  243. * @param[in] task LPCOMP task to be set.
  244. */
  245. __STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t task);
  246. /**
  247. * @brief Function for clearing the specified LPCOMP event.
  248. *
  249. * @param[in] event LPCOMP event to be cleared.
  250. */
  251. __STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t event);
  252. /**
  253. * @brief Function for retrieving the state of the LPCOMP event.
  254. *
  255. * @param[in] event Event to be checked.
  256. *
  257. * @retval true The event has been generated.
  258. * @retval false The event has not been generated.
  259. */
  260. __STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t event);
  261. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  262. __STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config)
  263. {
  264. NRF_LPCOMP->TASKS_STOP = 1;
  265. NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos;
  266. NRF_LPCOMP->REFSEL =
  267. (p_config->reference << LPCOMP_REFSEL_REFSEL_Pos) & LPCOMP_REFSEL_REFSEL_Msk;
  268. //If external source is choosen extract analog reference index.
  269. if ((p_config->reference & LPCOMP_REFSEL_REFSEL_ARef)==LPCOMP_REFSEL_REFSEL_ARef)
  270. {
  271. uint32_t extref = p_config->reference >> 16;
  272. NRF_LPCOMP->EXTREFSEL = (extref << LPCOMP_EXTREFSEL_EXTREFSEL_Pos) &
  273. LPCOMP_EXTREFSEL_EXTREFSEL_Msk;
  274. }
  275. NRF_LPCOMP->ANADETECT =
  276. (p_config->detection << LPCOMP_ANADETECT_ANADETECT_Pos) & LPCOMP_ANADETECT_ANADETECT_Msk;
  277. #ifdef LPCOMP_FEATURE_HYST_PRESENT
  278. NRF_LPCOMP->HYST = ((p_config->hyst) << LPCOMP_HYST_HYST_Pos) & LPCOMP_HYST_HYST_Msk;
  279. #endif //LPCOMP_FEATURE_HYST_PRESENT
  280. NRF_LPCOMP->SHORTS = 0;
  281. NRF_LPCOMP->INTENCLR = LPCOMP_INTENCLR_CROSS_Msk | LPCOMP_INTENCLR_UP_Msk |
  282. LPCOMP_INTENCLR_DOWN_Msk | LPCOMP_INTENCLR_READY_Msk;
  283. }
  284. __STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input)
  285. {
  286. uint32_t lpcomp_enable_state = NRF_LPCOMP->ENABLE;
  287. NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos;
  288. NRF_LPCOMP->PSEL =
  289. ((uint32_t)input << LPCOMP_PSEL_PSEL_Pos) | (NRF_LPCOMP->PSEL & ~LPCOMP_PSEL_PSEL_Msk);
  290. NRF_LPCOMP->ENABLE = lpcomp_enable_state;
  291. }
  292. __STATIC_INLINE void nrf_lpcomp_enable(void)
  293. {
  294. NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled << LPCOMP_ENABLE_ENABLE_Pos;
  295. NRF_LPCOMP->EVENTS_READY = 0;
  296. NRF_LPCOMP->EVENTS_DOWN = 0;
  297. NRF_LPCOMP->EVENTS_UP = 0;
  298. NRF_LPCOMP->EVENTS_CROSS = 0;
  299. }
  300. __STATIC_INLINE void nrf_lpcomp_disable(void)
  301. {
  302. NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos;
  303. }
  304. __STATIC_INLINE uint32_t nrf_lpcomp_result_get(void)
  305. {
  306. return (uint32_t)NRF_LPCOMP->RESULT;
  307. }
  308. __STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t int_mask)
  309. {
  310. NRF_LPCOMP->INTENSET = int_mask;
  311. }
  312. __STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t int_mask)
  313. {
  314. NRF_LPCOMP->INTENCLR = int_mask;
  315. }
  316. __STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t int_mask)
  317. {
  318. return (NRF_LPCOMP->INTENSET & int_mask); // when read this register will return the value of INTEN.
  319. }
  320. __STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t task)
  321. {
  322. return (uint32_t *)((uint8_t *)NRF_LPCOMP + task);
  323. }
  324. __STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t event)
  325. {
  326. return (uint32_t *)((uint8_t *)NRF_LPCOMP + event);
  327. }
  328. __STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t short_mask)
  329. {
  330. NRF_LPCOMP->SHORTS |= short_mask;
  331. }
  332. __STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t short_mask)
  333. {
  334. NRF_LPCOMP->SHORTS &= ~short_mask;
  335. }
  336. __STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t task)
  337. {
  338. *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + (uint32_t)task) ) = 1;
  339. }
  340. __STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t event)
  341. {
  342. *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + (uint32_t)event) ) = 0;
  343. #if __CORTEX_M == 0x04
  344. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_LPCOMP + (uint32_t)event));
  345. (void)dummy;
  346. #endif
  347. }
  348. __STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t event)
  349. {
  350. return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + (uint32_t)event));
  351. }
  352. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  353. /** @} */
  354. #ifdef __cplusplus
  355. }
  356. #endif
  357. #endif // NRF_LPCOMP_H_