Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.
source/nordic_sdk/components/drivers_nrf/hal/nrf_gpiote.h@28:041dac1366b2, 2016-04-07 (annotated)
- Committer:
- vcoubard
- Date:
- Thu Apr 07 17:37:56 2016 +0100
- Revision:
- 28:041dac1366b2
- Parent:
- 20:a90c48eb1d30
- Child:
- 29:286940b7ee5a
Synchronized with git rev 012b8118
Author: Liyou Zhou
Pull in files from sdk 10.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 28:041dac1366b2 | 1 | /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. |
vcoubard | 28:041dac1366b2 | 2 | * |
vcoubard | 28:041dac1366b2 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
vcoubard | 28:041dac1366b2 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
vcoubard | 28:041dac1366b2 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
vcoubard | 28:041dac1366b2 | 6 | * |
vcoubard | 28:041dac1366b2 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
vcoubard | 28:041dac1366b2 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
vcoubard | 28:041dac1366b2 | 9 | * the file. |
vcoubard | 28:041dac1366b2 | 10 | * |
Vincent Coubard |
0:f2542974c862 | 11 | */ |
Vincent Coubard |
0:f2542974c862 | 12 | #ifndef NRF_GPIOTE_H__ |
Vincent Coubard |
0:f2542974c862 | 13 | #define NRF_GPIOTE_H__ |
Vincent Coubard |
0:f2542974c862 | 14 | |
Vincent Coubard |
0:f2542974c862 | 15 | #include "nrf.h" |
vcoubard | 1:ebc0e0ef0a11 | 16 | #include <stdint.h> |
vcoubard | 1:ebc0e0ef0a11 | 17 | #include <stddef.h> |
vcoubard | 1:ebc0e0ef0a11 | 18 | #include <stdbool.h> |
Vincent Coubard |
0:f2542974c862 | 19 | |
Vincent Coubard |
0:f2542974c862 | 20 | /** |
vcoubard | 1:ebc0e0ef0a11 | 21 | * @defgroup nrf_gpiote_abs GPIOTE abstraction |
Vincent Coubard |
0:f2542974c862 | 22 | * @{ |
vcoubard | 1:ebc0e0ef0a11 | 23 | * @ingroup nrf_gpiote |
Vincent Coubard |
0:f2542974c862 | 24 | * @brief GPIOTE abstraction for configuration of channels. |
Vincent Coubard |
0:f2542974c862 | 25 | */ |
vcoubard | 28:041dac1366b2 | 26 | #ifdef NRF51 |
vcoubard | 1:ebc0e0ef0a11 | 27 | #define NUMBER_OF_GPIO_TE 4 |
vcoubard | 28:041dac1366b2 | 28 | #elif defined NRF52 |
vcoubard | 28:041dac1366b2 | 29 | #define NUMBER_OF_GPIO_TE 8 |
vcoubard | 28:041dac1366b2 | 30 | #else |
vcoubard | 28:041dac1366b2 | 31 | #error "Chip family not specified" |
vcoubard | 28:041dac1366b2 | 32 | #endif |
Vincent Coubard |
0:f2542974c862 | 33 | |
Vincent Coubard |
0:f2542974c862 | 34 | /** |
Vincent Coubard |
0:f2542974c862 | 35 | * @enum nrf_gpiote_polarity_t |
vcoubard | 1:ebc0e0ef0a11 | 36 | * @brief Polarity for the GPIOTE channel. |
Vincent Coubard |
0:f2542974c862 | 37 | */ |
Vincent Coubard |
0:f2542974c862 | 38 | typedef enum |
Vincent Coubard |
0:f2542974c862 | 39 | { |
vcoubard | 1:ebc0e0ef0a11 | 40 | NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high. |
vcoubard | 1:ebc0e0ef0a11 | 41 | NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low. |
vcoubard | 1:ebc0e0ef0a11 | 42 | NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle. |
Vincent Coubard |
0:f2542974c862 | 43 | } nrf_gpiote_polarity_t; |
Vincent Coubard |
0:f2542974c862 | 44 | |
Vincent Coubard |
0:f2542974c862 | 45 | |
Vincent Coubard |
0:f2542974c862 | 46 | /** |
Vincent Coubard |
0:f2542974c862 | 47 | * @enum nrf_gpiote_outinit_t |
vcoubard | 1:ebc0e0ef0a11 | 48 | * @brief Initial output value for the GPIOTE channel. |
vcoubard | 1:ebc0e0ef0a11 | 49 | */ |
vcoubard | 1:ebc0e0ef0a11 | 50 | typedef enum |
vcoubard | 1:ebc0e0ef0a11 | 51 | { |
vcoubard | 1:ebc0e0ef0a11 | 52 | NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high. |
vcoubard | 1:ebc0e0ef0a11 | 53 | NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low. |
vcoubard | 1:ebc0e0ef0a11 | 54 | } nrf_gpiote_outinit_t; |
vcoubard | 1:ebc0e0ef0a11 | 55 | |
vcoubard | 1:ebc0e0ef0a11 | 56 | /** |
vcoubard | 1:ebc0e0ef0a11 | 57 | * @brief Tasks. |
vcoubard | 1:ebc0e0ef0a11 | 58 | */ |
vcoubard | 1:ebc0e0ef0a11 | 59 | typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ |
vcoubard | 1:ebc0e0ef0a11 | 60 | { |
vcoubard | 1:ebc0e0ef0a11 | 61 | NRF_GPIOTE_TASKS_OUT_0 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0.*/ |
vcoubard | 1:ebc0e0ef0a11 | 62 | NRF_GPIOTE_TASKS_OUT_1 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[1]), /**< Out task 1.*/ |
vcoubard | 1:ebc0e0ef0a11 | 63 | NRF_GPIOTE_TASKS_OUT_2 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[2]), /**< Out task 2.*/ |
vcoubard | 1:ebc0e0ef0a11 | 64 | NRF_GPIOTE_TASKS_OUT_3 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[3]), /**< Out task 3.*/ |
vcoubard | 1:ebc0e0ef0a11 | 65 | /*lint -restore*/ |
vcoubard | 1:ebc0e0ef0a11 | 66 | } nrf_gpiote_tasks_t; |
vcoubard | 1:ebc0e0ef0a11 | 67 | |
vcoubard | 1:ebc0e0ef0a11 | 68 | /** |
vcoubard | 1:ebc0e0ef0a11 | 69 | * @brief Events. |
vcoubard | 1:ebc0e0ef0a11 | 70 | */ |
vcoubard | 1:ebc0e0ef0a11 | 71 | typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ |
vcoubard | 1:ebc0e0ef0a11 | 72 | { |
vcoubard | 1:ebc0e0ef0a11 | 73 | NRF_GPIOTE_EVENTS_IN_0 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]), /**< In event 0.*/ |
vcoubard | 1:ebc0e0ef0a11 | 74 | NRF_GPIOTE_EVENTS_IN_1 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[1]), /**< In event 1.*/ |
vcoubard | 1:ebc0e0ef0a11 | 75 | NRF_GPIOTE_EVENTS_IN_2 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[2]), /**< In event 2.*/ |
vcoubard | 1:ebc0e0ef0a11 | 76 | NRF_GPIOTE_EVENTS_IN_3 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[3]), /**< In event 3.*/ |
vcoubard | 1:ebc0e0ef0a11 | 77 | NRF_GPIOTE_EVENTS_PORT = offsetof(NRF_GPIOTE_Type, EVENTS_PORT), /**< Port event.*/ |
vcoubard | 1:ebc0e0ef0a11 | 78 | /*lint -restore*/ |
vcoubard | 1:ebc0e0ef0a11 | 79 | } nrf_gpiote_events_t; |
vcoubard | 1:ebc0e0ef0a11 | 80 | |
vcoubard | 1:ebc0e0ef0a11 | 81 | /** |
vcoubard | 1:ebc0e0ef0a11 | 82 | * @enum nrf_gpiote_int_t |
vcoubard | 1:ebc0e0ef0a11 | 83 | * @brief GPIOTE interrupts. |
Vincent Coubard |
0:f2542974c862 | 84 | */ |
Vincent Coubard |
0:f2542974c862 | 85 | typedef enum |
Vincent Coubard |
0:f2542974c862 | 86 | { |
vcoubard | 1:ebc0e0ef0a11 | 87 | NRF_GPIOTE_INT_IN0_MASK = GPIOTE_INTENSET_IN0_Msk, /**< GPIOTE interrupt from IN0. */ |
vcoubard | 1:ebc0e0ef0a11 | 88 | NRF_GPIOTE_INT_IN1_MASK = GPIOTE_INTENSET_IN1_Msk, /**< GPIOTE interrupt from IN1. */ |
vcoubard | 1:ebc0e0ef0a11 | 89 | NRF_GPIOTE_INT_IN2_MASK = GPIOTE_INTENSET_IN2_Msk, /**< GPIOTE interrupt from IN2. */ |
vcoubard | 1:ebc0e0ef0a11 | 90 | NRF_GPIOTE_INT_IN3_MASK = GPIOTE_INTENSET_IN3_Msk, /**< GPIOTE interrupt from IN3. */ |
vcoubard | 1:ebc0e0ef0a11 | 91 | NRF_GPIOTE_INT_PORT_MASK = (int)GPIOTE_INTENSET_PORT_Msk, /**< GPIOTE interrupt from PORT event. */ |
vcoubard | 1:ebc0e0ef0a11 | 92 | } nrf_gpiote_int_t; |
vcoubard | 1:ebc0e0ef0a11 | 93 | |
vcoubard | 1:ebc0e0ef0a11 | 94 | #define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\ |
vcoubard | 1:ebc0e0ef0a11 | 95 | NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK) |
vcoubard | 1:ebc0e0ef0a11 | 96 | /** |
vcoubard | 1:ebc0e0ef0a11 | 97 | * @brief Function for activating a specific GPIOTE task. |
vcoubard | 1:ebc0e0ef0a11 | 98 | * |
vcoubard | 1:ebc0e0ef0a11 | 99 | * @param[in] task Task. |
vcoubard | 1:ebc0e0ef0a11 | 100 | */ |
vcoubard | 1:ebc0e0ef0a11 | 101 | __STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task); |
Vincent Coubard |
0:f2542974c862 | 102 | |
vcoubard | 1:ebc0e0ef0a11 | 103 | /** |
vcoubard | 1:ebc0e0ef0a11 | 104 | * @brief Function for getting the address of a specific GPIOTE task. |
vcoubard | 1:ebc0e0ef0a11 | 105 | * |
vcoubard | 1:ebc0e0ef0a11 | 106 | * @param[in] task Task. |
vcoubard | 1:ebc0e0ef0a11 | 107 | * |
vcoubard | 1:ebc0e0ef0a11 | 108 | * @returns Address. |
vcoubard | 1:ebc0e0ef0a11 | 109 | */ |
vcoubard | 1:ebc0e0ef0a11 | 110 | __STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task); |
vcoubard | 1:ebc0e0ef0a11 | 111 | |
vcoubard | 1:ebc0e0ef0a11 | 112 | /** |
vcoubard | 1:ebc0e0ef0a11 | 113 | * @brief Function for getting the state of a specific GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 114 | * |
vcoubard | 1:ebc0e0ef0a11 | 115 | * @param[in] event Event. |
vcoubard | 1:ebc0e0ef0a11 | 116 | */ |
vcoubard | 1:ebc0e0ef0a11 | 117 | __STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event); |
vcoubard | 1:ebc0e0ef0a11 | 118 | |
vcoubard | 1:ebc0e0ef0a11 | 119 | /** |
vcoubard | 1:ebc0e0ef0a11 | 120 | * @brief Function for clearing a specific GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 121 | * |
vcoubard | 1:ebc0e0ef0a11 | 122 | * @param[in] event Event. |
vcoubard | 1:ebc0e0ef0a11 | 123 | */ |
vcoubard | 1:ebc0e0ef0a11 | 124 | __STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event); |
Vincent Coubard |
0:f2542974c862 | 125 | |
Vincent Coubard |
0:f2542974c862 | 126 | /** |
vcoubard | 1:ebc0e0ef0a11 | 127 | * @brief Function for getting the address of a specific GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 128 | * |
vcoubard | 1:ebc0e0ef0a11 | 129 | * @param[in] event Event. |
vcoubard | 1:ebc0e0ef0a11 | 130 | * |
vcoubard | 1:ebc0e0ef0a11 | 131 | * @return Address |
vcoubard | 1:ebc0e0ef0a11 | 132 | */ |
vcoubard | 1:ebc0e0ef0a11 | 133 | __STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event); |
vcoubard | 1:ebc0e0ef0a11 | 134 | |
vcoubard | 1:ebc0e0ef0a11 | 135 | /**@brief Function for enabling interrupts. |
vcoubard | 1:ebc0e0ef0a11 | 136 | * |
vcoubard | 1:ebc0e0ef0a11 | 137 | * @param[in] mask Interrupt mask to be enabled. |
vcoubard | 1:ebc0e0ef0a11 | 138 | */ |
vcoubard | 1:ebc0e0ef0a11 | 139 | __STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask); |
vcoubard | 1:ebc0e0ef0a11 | 140 | |
vcoubard | 1:ebc0e0ef0a11 | 141 | /**@brief Function for disabling interrupts. |
vcoubard | 1:ebc0e0ef0a11 | 142 | * |
vcoubard | 1:ebc0e0ef0a11 | 143 | * @param[in] mask Interrupt mask to be disabled. |
vcoubard | 1:ebc0e0ef0a11 | 144 | */ |
vcoubard | 1:ebc0e0ef0a11 | 145 | __STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask); |
vcoubard | 1:ebc0e0ef0a11 | 146 | |
vcoubard | 1:ebc0e0ef0a11 | 147 | /**@brief Function for checking if interrupts are enabled. |
vcoubard | 1:ebc0e0ef0a11 | 148 | * |
vcoubard | 1:ebc0e0ef0a11 | 149 | * @param[in] mask Mask of interrupt flags to check. |
Vincent Coubard |
0:f2542974c862 | 150 | * |
vcoubard | 1:ebc0e0ef0a11 | 151 | * @return Mask with enabled interrupts. |
vcoubard | 1:ebc0e0ef0a11 | 152 | */ |
vcoubard | 1:ebc0e0ef0a11 | 153 | __STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask); |
vcoubard | 1:ebc0e0ef0a11 | 154 | |
vcoubard | 1:ebc0e0ef0a11 | 155 | /**@brief Function for enabling a GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 156 | * |
vcoubard | 1:ebc0e0ef0a11 | 157 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 158 | */ |
vcoubard | 1:ebc0e0ef0a11 | 159 | __STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 160 | |
vcoubard | 1:ebc0e0ef0a11 | 161 | /**@brief Function for disabling a GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 162 | * |
vcoubard | 1:ebc0e0ef0a11 | 163 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 164 | */ |
vcoubard | 1:ebc0e0ef0a11 | 165 | __STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 166 | |
vcoubard | 1:ebc0e0ef0a11 | 167 | /**@brief Function for configuring a GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 168 | * |
vcoubard | 1:ebc0e0ef0a11 | 169 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 170 | * @param[in] pin Pin associated with event. |
vcoubard | 1:ebc0e0ef0a11 | 171 | * @param[in] polarity Transition that should generate an event. |
vcoubard | 1:ebc0e0ef0a11 | 172 | */ |
vcoubard | 1:ebc0e0ef0a11 | 173 | __STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin, |
vcoubard | 1:ebc0e0ef0a11 | 174 | nrf_gpiote_polarity_t polarity); |
vcoubard | 1:ebc0e0ef0a11 | 175 | |
vcoubard | 1:ebc0e0ef0a11 | 176 | /**@brief Function for getting the pin associated with a GPIOTE event. |
Vincent Coubard |
0:f2542974c862 | 177 | * |
vcoubard | 1:ebc0e0ef0a11 | 178 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 179 | * |
vcoubard | 1:ebc0e0ef0a11 | 180 | * @return Pin number. |
vcoubard | 1:ebc0e0ef0a11 | 181 | */ |
vcoubard | 1:ebc0e0ef0a11 | 182 | __STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 183 | |
vcoubard | 1:ebc0e0ef0a11 | 184 | /**@brief Function for getting the polarity associated with a GPIOTE event. |
vcoubard | 1:ebc0e0ef0a11 | 185 | * |
vcoubard | 1:ebc0e0ef0a11 | 186 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 187 | * |
vcoubard | 1:ebc0e0ef0a11 | 188 | * @return Polarity. |
vcoubard | 1:ebc0e0ef0a11 | 189 | */ |
vcoubard | 1:ebc0e0ef0a11 | 190 | __STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 191 | |
vcoubard | 1:ebc0e0ef0a11 | 192 | /**@brief Function for enabling a GPIOTE task. |
vcoubard | 1:ebc0e0ef0a11 | 193 | * |
vcoubard | 1:ebc0e0ef0a11 | 194 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 195 | */ |
vcoubard | 1:ebc0e0ef0a11 | 196 | __STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 197 | |
vcoubard | 1:ebc0e0ef0a11 | 198 | /**@brief Function for disabling a GPIOTE task. |
vcoubard | 1:ebc0e0ef0a11 | 199 | * |
vcoubard | 1:ebc0e0ef0a11 | 200 | * @param[in] idx Task-Event index. |
Vincent Coubard |
0:f2542974c862 | 201 | */ |
vcoubard | 1:ebc0e0ef0a11 | 202 | __STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 203 | |
vcoubard | 1:ebc0e0ef0a11 | 204 | /**@brief Function for configuring a GPIOTE task. |
vcoubard | 28:041dac1366b2 | 205 | * @note Function is not configuring mode field so task is disabled after this function is called. |
vcoubard | 1:ebc0e0ef0a11 | 206 | * |
vcoubard | 1:ebc0e0ef0a11 | 207 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 208 | * @param[in] pin Pin associated with event. |
vcoubard | 1:ebc0e0ef0a11 | 209 | * @param[in] polarity Transition that should generate an event. |
vcoubard | 1:ebc0e0ef0a11 | 210 | * @param[in] init_val Initial value of pin. |
vcoubard | 1:ebc0e0ef0a11 | 211 | */ |
vcoubard | 1:ebc0e0ef0a11 | 212 | __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin, |
vcoubard | 1:ebc0e0ef0a11 | 213 | nrf_gpiote_polarity_t polarity, |
vcoubard | 1:ebc0e0ef0a11 | 214 | nrf_gpiote_outinit_t init_val); |
vcoubard | 1:ebc0e0ef0a11 | 215 | |
vcoubard | 1:ebc0e0ef0a11 | 216 | /**@brief Function for forcing a specific state on the pin connected to GPIOTE. |
vcoubard | 1:ebc0e0ef0a11 | 217 | * |
vcoubard | 1:ebc0e0ef0a11 | 218 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 219 | * @param[in] init_val Pin state. |
vcoubard | 1:ebc0e0ef0a11 | 220 | */ |
vcoubard | 1:ebc0e0ef0a11 | 221 | __STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val); |
vcoubard | 1:ebc0e0ef0a11 | 222 | |
vcoubard | 1:ebc0e0ef0a11 | 223 | /**@brief Function for resetting a GPIOTE task event configuration to the default state. |
vcoubard | 1:ebc0e0ef0a11 | 224 | * |
vcoubard | 1:ebc0e0ef0a11 | 225 | * @param[in] idx Task-Event index. |
vcoubard | 1:ebc0e0ef0a11 | 226 | */ |
vcoubard | 1:ebc0e0ef0a11 | 227 | __STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx); |
vcoubard | 1:ebc0e0ef0a11 | 228 | |
vcoubard | 1:ebc0e0ef0a11 | 229 | #ifndef SUPPRESS_INLINE_IMPLEMENTATION |
vcoubard | 1:ebc0e0ef0a11 | 230 | __STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task) |
Vincent Coubard |
0:f2542974c862 | 231 | { |
vcoubard | 1:ebc0e0ef0a11 | 232 | *(__IO uint32_t *)((uint32_t)NRF_GPIOTE + task) = 0x1UL; |
Vincent Coubard |
0:f2542974c862 | 233 | } |
Vincent Coubard |
0:f2542974c862 | 234 | |
vcoubard | 1:ebc0e0ef0a11 | 235 | __STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task) |
vcoubard | 1:ebc0e0ef0a11 | 236 | { |
vcoubard | 1:ebc0e0ef0a11 | 237 | return ((uint32_t)NRF_GPIOTE + task); |
vcoubard | 1:ebc0e0ef0a11 | 238 | } |
vcoubard | 1:ebc0e0ef0a11 | 239 | |
vcoubard | 1:ebc0e0ef0a11 | 240 | __STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event) |
vcoubard | 1:ebc0e0ef0a11 | 241 | { |
vcoubard | 1:ebc0e0ef0a11 | 242 | return (*(uint32_t *)nrf_gpiote_event_addr_get(event) == 0x1UL) ? true : false; |
vcoubard | 1:ebc0e0ef0a11 | 243 | } |
vcoubard | 1:ebc0e0ef0a11 | 244 | |
vcoubard | 1:ebc0e0ef0a11 | 245 | __STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event) |
vcoubard | 1:ebc0e0ef0a11 | 246 | { |
vcoubard | 1:ebc0e0ef0a11 | 247 | *(uint32_t *)nrf_gpiote_event_addr_get(event) = 0; |
vcoubard | 28:041dac1366b2 | 248 | #if __CORTEX_M == 0x04 |
vcoubard | 28:041dac1366b2 | 249 | volatile uint32_t dummy = *((volatile uint32_t *)nrf_gpiote_event_addr_get(event)); |
vcoubard | 28:041dac1366b2 | 250 | (void)dummy; |
vcoubard | 28:041dac1366b2 | 251 | #endif |
vcoubard | 1:ebc0e0ef0a11 | 252 | } |
vcoubard | 1:ebc0e0ef0a11 | 253 | |
vcoubard | 1:ebc0e0ef0a11 | 254 | __STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event) |
vcoubard | 1:ebc0e0ef0a11 | 255 | { |
vcoubard | 1:ebc0e0ef0a11 | 256 | return ((uint32_t)NRF_GPIOTE + event); |
vcoubard | 1:ebc0e0ef0a11 | 257 | } |
vcoubard | 1:ebc0e0ef0a11 | 258 | |
vcoubard | 1:ebc0e0ef0a11 | 259 | __STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask) |
vcoubard | 1:ebc0e0ef0a11 | 260 | { |
vcoubard | 1:ebc0e0ef0a11 | 261 | NRF_GPIOTE->INTENSET = mask; |
vcoubard | 1:ebc0e0ef0a11 | 262 | } |
vcoubard | 1:ebc0e0ef0a11 | 263 | |
vcoubard | 1:ebc0e0ef0a11 | 264 | __STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask) |
vcoubard | 1:ebc0e0ef0a11 | 265 | { |
vcoubard | 1:ebc0e0ef0a11 | 266 | NRF_GPIOTE->INTENCLR = mask; |
vcoubard | 1:ebc0e0ef0a11 | 267 | } |
vcoubard | 1:ebc0e0ef0a11 | 268 | |
vcoubard | 1:ebc0e0ef0a11 | 269 | __STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask) |
vcoubard | 1:ebc0e0ef0a11 | 270 | { |
vcoubard | 1:ebc0e0ef0a11 | 271 | return (NRF_GPIOTE->INTENSET & mask); |
vcoubard | 1:ebc0e0ef0a11 | 272 | } |
Vincent Coubard |
0:f2542974c862 | 273 | |
vcoubard | 1:ebc0e0ef0a11 | 274 | __STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 275 | { |
vcoubard | 1:ebc0e0ef0a11 | 276 | NRF_GPIOTE->CONFIG[idx] |= GPIOTE_CONFIG_MODE_Event; |
vcoubard | 1:ebc0e0ef0a11 | 277 | } |
vcoubard | 1:ebc0e0ef0a11 | 278 | |
vcoubard | 1:ebc0e0ef0a11 | 279 | __STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 280 | { |
vcoubard | 1:ebc0e0ef0a11 | 281 | NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Event; |
vcoubard | 1:ebc0e0ef0a11 | 282 | } |
vcoubard | 1:ebc0e0ef0a11 | 283 | |
vcoubard | 1:ebc0e0ef0a11 | 284 | __STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin, nrf_gpiote_polarity_t polarity) |
vcoubard | 1:ebc0e0ef0a11 | 285 | { |
vcoubard | 1:ebc0e0ef0a11 | 286 | NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PSEL_Msk | GPIOTE_CONFIG_POLARITY_Msk); |
vcoubard | 1:ebc0e0ef0a11 | 287 | NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PSEL_Msk) | |
vcoubard | 1:ebc0e0ef0a11 | 288 | ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk); |
vcoubard | 1:ebc0e0ef0a11 | 289 | } |
vcoubard | 1:ebc0e0ef0a11 | 290 | |
vcoubard | 1:ebc0e0ef0a11 | 291 | __STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 292 | { |
vcoubard | 1:ebc0e0ef0a11 | 293 | return ((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_PSEL_Msk) >> GPIOTE_CONFIG_PSEL_Pos); |
vcoubard | 1:ebc0e0ef0a11 | 294 | } |
vcoubard | 1:ebc0e0ef0a11 | 295 | |
vcoubard | 1:ebc0e0ef0a11 | 296 | __STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 297 | { |
vcoubard | 1:ebc0e0ef0a11 | 298 | return (nrf_gpiote_polarity_t)((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_POLARITY_Msk) >> GPIOTE_CONFIG_POLARITY_Pos); |
vcoubard | 1:ebc0e0ef0a11 | 299 | } |
vcoubard | 1:ebc0e0ef0a11 | 300 | |
vcoubard | 1:ebc0e0ef0a11 | 301 | __STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 302 | { |
vcoubard | 1:ebc0e0ef0a11 | 303 | uint32_t final_config = NRF_GPIOTE->CONFIG[idx] | GPIOTE_CONFIG_MODE_Task; |
vcoubard | 1:ebc0e0ef0a11 | 304 | /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens |
vcoubard | 1:ebc0e0ef0a11 | 305 | on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the |
vcoubard | 1:ebc0e0ef0a11 | 306 | correct state in GPIOTE but not in the OUT register. */ |
vcoubard | 1:ebc0e0ef0a11 | 307 | /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ |
vcoubard | 1:ebc0e0ef0a11 | 308 | NRF_GPIOTE->CONFIG[idx] = final_config | ((31 << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PSEL_Msk); |
Vincent Coubard |
0:f2542974c862 | 309 | __NOP(); |
Vincent Coubard |
0:f2542974c862 | 310 | __NOP(); |
Vincent Coubard |
0:f2542974c862 | 311 | __NOP(); |
vcoubard | 1:ebc0e0ef0a11 | 312 | NRF_GPIOTE->CONFIG[idx] = final_config; |
vcoubard | 1:ebc0e0ef0a11 | 313 | } |
vcoubard | 1:ebc0e0ef0a11 | 314 | |
vcoubard | 1:ebc0e0ef0a11 | 315 | __STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 316 | { |
vcoubard | 1:ebc0e0ef0a11 | 317 | NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Task; |
Vincent Coubard |
0:f2542974c862 | 318 | } |
Vincent Coubard |
0:f2542974c862 | 319 | |
vcoubard | 1:ebc0e0ef0a11 | 320 | __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin, |
vcoubard | 1:ebc0e0ef0a11 | 321 | nrf_gpiote_polarity_t polarity, |
vcoubard | 1:ebc0e0ef0a11 | 322 | nrf_gpiote_outinit_t init_val) |
vcoubard | 1:ebc0e0ef0a11 | 323 | { |
vcoubard | 1:ebc0e0ef0a11 | 324 | NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PSEL_Msk | |
vcoubard | 1:ebc0e0ef0a11 | 325 | GPIOTE_CONFIG_POLARITY_Msk | |
vcoubard | 1:ebc0e0ef0a11 | 326 | GPIOTE_CONFIG_OUTINIT_Msk); |
Vincent Coubard |
0:f2542974c862 | 327 | |
vcoubard | 1:ebc0e0ef0a11 | 328 | NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PSEL_Msk) | |
vcoubard | 1:ebc0e0ef0a11 | 329 | ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk) | |
vcoubard | 1:ebc0e0ef0a11 | 330 | ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk); |
Vincent Coubard |
0:f2542974c862 | 331 | } |
Vincent Coubard |
0:f2542974c862 | 332 | |
vcoubard | 1:ebc0e0ef0a11 | 333 | __STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val) |
vcoubard | 1:ebc0e0ef0a11 | 334 | { |
vcoubard | 28:041dac1366b2 | 335 | NRF_GPIOTE->CONFIG[idx] = (NRF_GPIOTE->CONFIG[idx] & ~GPIOTE_CONFIG_OUTINIT_Msk) |
vcoubard | 28:041dac1366b2 | 336 | | ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk); |
vcoubard | 1:ebc0e0ef0a11 | 337 | } |
Vincent Coubard |
0:f2542974c862 | 338 | |
vcoubard | 1:ebc0e0ef0a11 | 339 | __STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx) |
vcoubard | 1:ebc0e0ef0a11 | 340 | { |
vcoubard | 1:ebc0e0ef0a11 | 341 | NRF_GPIOTE->CONFIG[idx] = 0; |
vcoubard | 1:ebc0e0ef0a11 | 342 | } |
vcoubard | 1:ebc0e0ef0a11 | 343 | #endif //SUPPRESS_INLINE_IMPLEMENTATION |
Vincent Coubard |
0:f2542974c862 | 344 | /** @} */ |
Vincent Coubard |
0:f2542974c862 | 345 | |
vcoubard | 1:ebc0e0ef0a11 | 346 | #endif |