nrf_gpiote.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /**
  2. * Copyright (c) 2015 - 2018, 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_GPIOTE_H__
  41. #define NRF_GPIOTE_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_gpiote_hal GPIOTE HAL
  48. * @{
  49. * @ingroup nrf_gpiote
  50. * @brief Hardware access layer for managing the GPIOTE peripheral.
  51. */
  52. #ifdef GPIOTE_CONFIG_PORT_Msk
  53. #define GPIOTE_CONFIG_PORT_PIN_Msk (GPIOTE_CONFIG_PORT_Msk | GPIOTE_CONFIG_PSEL_Msk)
  54. #else
  55. #define GPIOTE_CONFIG_PORT_PIN_Msk GPIOTE_CONFIG_PSEL_Msk
  56. #endif
  57. /**
  58. * @enum nrf_gpiote_polarity_t
  59. * @brief Polarity for the GPIOTE channel.
  60. */
  61. typedef enum
  62. {
  63. NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high.
  64. NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low.
  65. NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle.
  66. } nrf_gpiote_polarity_t;
  67. /**
  68. * @enum nrf_gpiote_outinit_t
  69. * @brief Initial output value for the GPIOTE channel.
  70. */
  71. typedef enum
  72. {
  73. NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high.
  74. NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low.
  75. } nrf_gpiote_outinit_t;
  76. /**
  77. * @brief Tasks.
  78. */
  79. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  80. {
  81. NRF_GPIOTE_TASKS_OUT_0 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0.*/
  82. NRF_GPIOTE_TASKS_OUT_1 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[1]), /**< Out task 1.*/
  83. NRF_GPIOTE_TASKS_OUT_2 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[2]), /**< Out task 2.*/
  84. NRF_GPIOTE_TASKS_OUT_3 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[3]), /**< Out task 3.*/
  85. #if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
  86. NRF_GPIOTE_TASKS_OUT_4 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[4]), /**< Out task 4.*/
  87. NRF_GPIOTE_TASKS_OUT_5 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[5]), /**< Out task 5.*/
  88. NRF_GPIOTE_TASKS_OUT_6 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[6]), /**< Out task 6.*/
  89. NRF_GPIOTE_TASKS_OUT_7 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[7]), /**< Out task 7.*/
  90. #endif
  91. #if defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
  92. NRF_GPIOTE_TASKS_SET_0 = offsetof(NRF_GPIOTE_Type, TASKS_SET[0]), /**< Set task 0.*/
  93. NRF_GPIOTE_TASKS_SET_1 = offsetof(NRF_GPIOTE_Type, TASKS_SET[1]), /**< Set task 1.*/
  94. NRF_GPIOTE_TASKS_SET_2 = offsetof(NRF_GPIOTE_Type, TASKS_SET[2]), /**< Set task 2.*/
  95. NRF_GPIOTE_TASKS_SET_3 = offsetof(NRF_GPIOTE_Type, TASKS_SET[3]), /**< Set task 3.*/
  96. NRF_GPIOTE_TASKS_SET_4 = offsetof(NRF_GPIOTE_Type, TASKS_SET[4]), /**< Set task 4.*/
  97. NRF_GPIOTE_TASKS_SET_5 = offsetof(NRF_GPIOTE_Type, TASKS_SET[5]), /**< Set task 5.*/
  98. NRF_GPIOTE_TASKS_SET_6 = offsetof(NRF_GPIOTE_Type, TASKS_SET[6]), /**< Set task 6.*/
  99. NRF_GPIOTE_TASKS_SET_7 = offsetof(NRF_GPIOTE_Type, TASKS_SET[7]), /**< Set task 7.*/
  100. #endif
  101. #if defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
  102. NRF_GPIOTE_TASKS_CLR_0 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[0]), /**< Clear task 0.*/
  103. NRF_GPIOTE_TASKS_CLR_1 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[1]), /**< Clear task 1.*/
  104. NRF_GPIOTE_TASKS_CLR_2 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[2]), /**< Clear task 2.*/
  105. NRF_GPIOTE_TASKS_CLR_3 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[3]), /**< Clear task 3.*/
  106. NRF_GPIOTE_TASKS_CLR_4 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[4]), /**< Clear task 4.*/
  107. NRF_GPIOTE_TASKS_CLR_5 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[5]), /**< Clear task 5.*/
  108. NRF_GPIOTE_TASKS_CLR_6 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[6]), /**< Clear task 6.*/
  109. NRF_GPIOTE_TASKS_CLR_7 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[7]), /**< Clear task 7.*/
  110. #endif
  111. /*lint -restore*/
  112. } nrf_gpiote_tasks_t;
  113. /**
  114. * @brief Events.
  115. */
  116. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  117. {
  118. NRF_GPIOTE_EVENTS_IN_0 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]), /**< In event 0.*/
  119. NRF_GPIOTE_EVENTS_IN_1 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[1]), /**< In event 1.*/
  120. NRF_GPIOTE_EVENTS_IN_2 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[2]), /**< In event 2.*/
  121. NRF_GPIOTE_EVENTS_IN_3 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[3]), /**< In event 3.*/
  122. #if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
  123. NRF_GPIOTE_EVENTS_IN_4 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[4]), /**< In event 4.*/
  124. NRF_GPIOTE_EVENTS_IN_5 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[5]), /**< In event 5.*/
  125. NRF_GPIOTE_EVENTS_IN_6 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[6]), /**< In event 6.*/
  126. NRF_GPIOTE_EVENTS_IN_7 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[7]), /**< In event 7.*/
  127. #endif
  128. NRF_GPIOTE_EVENTS_PORT = offsetof(NRF_GPIOTE_Type, EVENTS_PORT), /**< Port event.*/
  129. /*lint -restore*/
  130. } nrf_gpiote_events_t;
  131. /**
  132. * @enum nrf_gpiote_int_t
  133. * @brief GPIOTE interrupts.
  134. */
  135. typedef enum
  136. {
  137. NRF_GPIOTE_INT_IN0_MASK = GPIOTE_INTENSET_IN0_Msk, /**< GPIOTE interrupt from IN0. */
  138. NRF_GPIOTE_INT_IN1_MASK = GPIOTE_INTENSET_IN1_Msk, /**< GPIOTE interrupt from IN1. */
  139. NRF_GPIOTE_INT_IN2_MASK = GPIOTE_INTENSET_IN2_Msk, /**< GPIOTE interrupt from IN2. */
  140. NRF_GPIOTE_INT_IN3_MASK = GPIOTE_INTENSET_IN3_Msk, /**< GPIOTE interrupt from IN3. */
  141. #if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
  142. NRF_GPIOTE_INT_IN4_MASK = GPIOTE_INTENSET_IN4_Msk, /**< GPIOTE interrupt from IN4. */
  143. NRF_GPIOTE_INT_IN5_MASK = GPIOTE_INTENSET_IN5_Msk, /**< GPIOTE interrupt from IN5. */
  144. NRF_GPIOTE_INT_IN6_MASK = GPIOTE_INTENSET_IN6_Msk, /**< GPIOTE interrupt from IN6. */
  145. NRF_GPIOTE_INT_IN7_MASK = GPIOTE_INTENSET_IN7_Msk, /**< GPIOTE interrupt from IN7. */
  146. #endif
  147. NRF_GPIOTE_INT_PORT_MASK = (int)GPIOTE_INTENSET_PORT_Msk, /**< GPIOTE interrupt from PORT event. */
  148. } nrf_gpiote_int_t;
  149. #define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\
  150. NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK)
  151. #if (GPIOTE_CH_NUM > 4)
  152. #undef NRF_GPIOTE_INT_IN_MASK
  153. #define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\
  154. NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK |\
  155. NRF_GPIOTE_INT_IN4_MASK | NRF_GPIOTE_INT_IN5_MASK |\
  156. NRF_GPIOTE_INT_IN6_MASK | NRF_GPIOTE_INT_IN7_MASK)
  157. #endif
  158. /**
  159. * @brief Function for activating a specific GPIOTE task.
  160. *
  161. * @param[in] task Task.
  162. */
  163. __STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task);
  164. /**
  165. * @brief Function for getting the address of a specific GPIOTE task.
  166. *
  167. * @param[in] task Task.
  168. *
  169. * @returns Address.
  170. */
  171. __STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task);
  172. /**
  173. * @brief Function for getting the state of a specific GPIOTE event.
  174. *
  175. * @param[in] event Event.
  176. */
  177. __STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event);
  178. /**
  179. * @brief Function for clearing a specific GPIOTE event.
  180. *
  181. * @param[in] event Event.
  182. */
  183. __STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event);
  184. /**
  185. * @brief Function for getting the address of a specific GPIOTE event.
  186. *
  187. * @param[in] event Event.
  188. *
  189. * @return Address
  190. */
  191. __STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event);
  192. /**@brief Function for enabling interrupts.
  193. *
  194. * @param[in] mask Interrupt mask to be enabled.
  195. */
  196. __STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask);
  197. /**@brief Function for disabling interrupts.
  198. *
  199. * @param[in] mask Interrupt mask to be disabled.
  200. */
  201. __STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask);
  202. /**@brief Function for checking if interrupts are enabled.
  203. *
  204. * @param[in] mask Mask of interrupt flags to check.
  205. *
  206. * @return Mask with enabled interrupts.
  207. */
  208. __STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask);
  209. /**@brief Function for enabling a GPIOTE event.
  210. *
  211. * @param[in] idx Task-Event index.
  212. */
  213. __STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx);
  214. /**@brief Function for disabling a GPIOTE event.
  215. *
  216. * @param[in] idx Task-Event index.
  217. */
  218. __STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx);
  219. /**@brief Function for configuring a GPIOTE event.
  220. *
  221. * @param[in] idx Task-Event index.
  222. * @param[in] pin Pin associated with event.
  223. * @param[in] polarity Transition that should generate an event.
  224. */
  225. __STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin,
  226. nrf_gpiote_polarity_t polarity);
  227. /**@brief Function for getting the pin associated with a GPIOTE event.
  228. *
  229. * @param[in] idx Task-Event index.
  230. *
  231. * @return Pin number.
  232. */
  233. __STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx);
  234. /**@brief Function for getting the polarity associated with a GPIOTE event.
  235. *
  236. * @param[in] idx Task-Event index.
  237. *
  238. * @return Polarity.
  239. */
  240. __STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx);
  241. /**@brief Function for enabling a GPIOTE task.
  242. *
  243. * @param[in] idx Task-Event index.
  244. */
  245. __STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx);
  246. /**@brief Function for disabling a GPIOTE task.
  247. *
  248. * @param[in] idx Task-Event index.
  249. */
  250. __STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx);
  251. /**@brief Function for configuring a GPIOTE task.
  252. * @note Function is not configuring mode field so task is disabled after this function is called.
  253. *
  254. * @param[in] idx Task-Event index.
  255. * @param[in] pin Pin associated with event.
  256. * @param[in] polarity Transition that should generate an event.
  257. * @param[in] init_val Initial value of the pin.
  258. */
  259. __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin,
  260. nrf_gpiote_polarity_t polarity,
  261. nrf_gpiote_outinit_t init_val);
  262. /**@brief Function for forcing a specific state on the pin connected to GPIOTE.
  263. *
  264. * @param[in] idx Task-Event index.
  265. * @param[in] init_val Pin state.
  266. */
  267. __STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val);
  268. /**@brief Function for resetting a GPIOTE task event configuration to the default state.
  269. *
  270. * @param[in] idx Task-Event index.
  271. */
  272. __STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx);
  273. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  274. __STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task)
  275. {
  276. *(__IO uint32_t *)((uint32_t)NRF_GPIOTE + task) = 0x1UL;
  277. }
  278. __STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task)
  279. {
  280. return ((uint32_t)NRF_GPIOTE + task);
  281. }
  282. __STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event)
  283. {
  284. return (*(uint32_t *)nrf_gpiote_event_addr_get(event) == 0x1UL) ? true : false;
  285. }
  286. __STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event)
  287. {
  288. *(uint32_t *)nrf_gpiote_event_addr_get(event) = 0;
  289. #if __CORTEX_M == 0x04
  290. volatile uint32_t dummy = *((volatile uint32_t *)nrf_gpiote_event_addr_get(event));
  291. (void)dummy;
  292. #endif
  293. }
  294. __STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event)
  295. {
  296. return ((uint32_t)NRF_GPIOTE + event);
  297. }
  298. __STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask)
  299. {
  300. NRF_GPIOTE->INTENSET = mask;
  301. }
  302. __STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask)
  303. {
  304. NRF_GPIOTE->INTENCLR = mask;
  305. }
  306. __STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask)
  307. {
  308. return (NRF_GPIOTE->INTENSET & mask);
  309. }
  310. __STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx)
  311. {
  312. NRF_GPIOTE->CONFIG[idx] |= GPIOTE_CONFIG_MODE_Event;
  313. }
  314. __STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx)
  315. {
  316. NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Event;
  317. }
  318. __STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin, nrf_gpiote_polarity_t polarity)
  319. {
  320. NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk | GPIOTE_CONFIG_POLARITY_Msk);
  321. NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
  322. ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk);
  323. }
  324. __STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx)
  325. {
  326. return ((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_PORT_PIN_Msk) >> GPIOTE_CONFIG_PSEL_Pos);
  327. }
  328. __STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx)
  329. {
  330. return (nrf_gpiote_polarity_t)((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_POLARITY_Msk) >> GPIOTE_CONFIG_POLARITY_Pos);
  331. }
  332. __STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx)
  333. {
  334. uint32_t final_config = NRF_GPIOTE->CONFIG[idx] | GPIOTE_CONFIG_MODE_Task;
  335. #ifdef NRF51
  336. /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
  337. on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the
  338. correct state in GPIOTE but not in the OUT register. */
  339. /* Configure channel to not existing, not connected to the pin, and configure as a tasks that will set it to proper level */
  340. NRF_GPIOTE->CONFIG[idx] = final_config | (((31) << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk);
  341. __NOP();
  342. __NOP();
  343. __NOP();
  344. #endif
  345. NRF_GPIOTE->CONFIG[idx] = final_config;
  346. }
  347. __STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx)
  348. {
  349. NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Task;
  350. }
  351. __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin,
  352. nrf_gpiote_polarity_t polarity,
  353. nrf_gpiote_outinit_t init_val)
  354. {
  355. NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk |
  356. GPIOTE_CONFIG_POLARITY_Msk |
  357. GPIOTE_CONFIG_OUTINIT_Msk);
  358. NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
  359. ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk) |
  360. ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk);
  361. }
  362. __STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val)
  363. {
  364. NRF_GPIOTE->CONFIG[idx] = (NRF_GPIOTE->CONFIG[idx] & ~GPIOTE_CONFIG_OUTINIT_Msk)
  365. | ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk);
  366. }
  367. __STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx)
  368. {
  369. NRF_GPIOTE->CONFIG[idx] = 0;
  370. }
  371. #endif //SUPPRESS_INLINE_IMPLEMENTATION
  372. /** @} */
  373. #ifdef __cplusplus
  374. }
  375. #endif
  376. #endif