Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
TARGET_MCU_NRF51822/sdk/source/drivers_nrf/hal/nrf_gpiote.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
| Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
| Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
| Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
| Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
| Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
| Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
| Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
| Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
| Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
| Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
| Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
| Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
| Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 32 | #ifndef NRF_GPIOTE_H__ |
| Vincent Coubard |
638:c90ae1400bf2 | 33 | #define NRF_GPIOTE_H__ |
| Vincent Coubard |
638:c90ae1400bf2 | 34 | |
| Vincent Coubard |
638:c90ae1400bf2 | 35 | #include "nrf.h" |
| Vincent Coubard |
638:c90ae1400bf2 | 36 | #include <stdint.h> |
| Vincent Coubard |
638:c90ae1400bf2 | 37 | #include <stddef.h> |
| Vincent Coubard |
638:c90ae1400bf2 | 38 | #include <stdbool.h> |
| Vincent Coubard |
638:c90ae1400bf2 | 39 | |
| Vincent Coubard |
638:c90ae1400bf2 | 40 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 41 | * @defgroup nrf_gpiote_abs GPIOTE abstraction |
| Vincent Coubard |
638:c90ae1400bf2 | 42 | * @{ |
| Vincent Coubard |
638:c90ae1400bf2 | 43 | * @ingroup nrf_gpiote |
| Vincent Coubard |
638:c90ae1400bf2 | 44 | * @brief GPIOTE abstraction for configuration of channels. |
| Vincent Coubard |
638:c90ae1400bf2 | 45 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 46 | #ifdef NRF51 |
| Vincent Coubard |
638:c90ae1400bf2 | 47 | #define NUMBER_OF_GPIO_TE 4 |
| Vincent Coubard |
638:c90ae1400bf2 | 48 | #elif defined NRF52 |
| Vincent Coubard |
638:c90ae1400bf2 | 49 | #define NUMBER_OF_GPIO_TE 8 |
| Vincent Coubard |
638:c90ae1400bf2 | 50 | #else |
| Vincent Coubard |
638:c90ae1400bf2 | 51 | #error "Chip family not specified" |
| Vincent Coubard |
638:c90ae1400bf2 | 52 | #endif |
| Vincent Coubard |
638:c90ae1400bf2 | 53 | |
| Vincent Coubard |
638:c90ae1400bf2 | 54 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 55 | * @enum nrf_gpiote_polarity_t |
| Vincent Coubard |
638:c90ae1400bf2 | 56 | * @brief Polarity for the GPIOTE channel. |
| Vincent Coubard |
638:c90ae1400bf2 | 57 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 58 | typedef enum |
| Vincent Coubard |
638:c90ae1400bf2 | 59 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 60 | NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, ///< Low to high. |
| Vincent Coubard |
638:c90ae1400bf2 | 61 | NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, ///< High to low. |
| Vincent Coubard |
638:c90ae1400bf2 | 62 | NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle ///< Toggle. |
| Vincent Coubard |
638:c90ae1400bf2 | 63 | } nrf_gpiote_polarity_t; |
| Vincent Coubard |
638:c90ae1400bf2 | 64 | |
| Vincent Coubard |
638:c90ae1400bf2 | 65 | |
| Vincent Coubard |
638:c90ae1400bf2 | 66 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 67 | * @enum nrf_gpiote_outinit_t |
| Vincent Coubard |
638:c90ae1400bf2 | 68 | * @brief Initial output value for the GPIOTE channel. |
| Vincent Coubard |
638:c90ae1400bf2 | 69 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 70 | typedef enum |
| Vincent Coubard |
638:c90ae1400bf2 | 71 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 72 | NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, ///< Low to high. |
| Vincent Coubard |
638:c90ae1400bf2 | 73 | NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High ///< High to low. |
| Vincent Coubard |
638:c90ae1400bf2 | 74 | } nrf_gpiote_outinit_t; |
| Vincent Coubard |
638:c90ae1400bf2 | 75 | |
| Vincent Coubard |
638:c90ae1400bf2 | 76 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 77 | * @brief Tasks. |
| Vincent Coubard |
638:c90ae1400bf2 | 78 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 79 | typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ |
| Vincent Coubard |
638:c90ae1400bf2 | 80 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 81 | NRF_GPIOTE_TASKS_OUT_0 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 82 | NRF_GPIOTE_TASKS_OUT_1 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[1]), /**< Out task 1.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 83 | NRF_GPIOTE_TASKS_OUT_2 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[2]), /**< Out task 2.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 84 | NRF_GPIOTE_TASKS_OUT_3 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[3]), /**< Out task 3.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 85 | /*lint -restore*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 86 | } nrf_gpiote_tasks_t; |
| Vincent Coubard |
638:c90ae1400bf2 | 87 | |
| Vincent Coubard |
638:c90ae1400bf2 | 88 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 89 | * @brief Events. |
| Vincent Coubard |
638:c90ae1400bf2 | 90 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 91 | typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ |
| Vincent Coubard |
638:c90ae1400bf2 | 92 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 93 | NRF_GPIOTE_EVENTS_IN_0 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]), /**< In event 0.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 94 | NRF_GPIOTE_EVENTS_IN_1 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[1]), /**< In event 1.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 95 | NRF_GPIOTE_EVENTS_IN_2 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[2]), /**< In event 2.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 96 | NRF_GPIOTE_EVENTS_IN_3 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[3]), /**< In event 3.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 97 | NRF_GPIOTE_EVENTS_PORT = offsetof(NRF_GPIOTE_Type, EVENTS_PORT), /**< Port event.*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 98 | /*lint -restore*/ |
| Vincent Coubard |
638:c90ae1400bf2 | 99 | } nrf_gpiote_events_t; |
| Vincent Coubard |
638:c90ae1400bf2 | 100 | |
| Vincent Coubard |
638:c90ae1400bf2 | 101 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 102 | * @enum nrf_gpiote_int_t |
| Vincent Coubard |
638:c90ae1400bf2 | 103 | * @brief GPIOTE interrupts. |
| Vincent Coubard |
638:c90ae1400bf2 | 104 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 105 | typedef enum |
| Vincent Coubard |
638:c90ae1400bf2 | 106 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 107 | NRF_GPIOTE_INT_IN0_MASK = GPIOTE_INTENSET_IN0_Msk, /**< GPIOTE interrupt from IN0. */ |
| Vincent Coubard |
638:c90ae1400bf2 | 108 | NRF_GPIOTE_INT_IN1_MASK = GPIOTE_INTENSET_IN1_Msk, /**< GPIOTE interrupt from IN1. */ |
| Vincent Coubard |
638:c90ae1400bf2 | 109 | NRF_GPIOTE_INT_IN2_MASK = GPIOTE_INTENSET_IN2_Msk, /**< GPIOTE interrupt from IN2. */ |
| Vincent Coubard |
638:c90ae1400bf2 | 110 | NRF_GPIOTE_INT_IN3_MASK = GPIOTE_INTENSET_IN3_Msk, /**< GPIOTE interrupt from IN3. */ |
| Vincent Coubard |
638:c90ae1400bf2 | 111 | NRF_GPIOTE_INT_PORT_MASK = (int)GPIOTE_INTENSET_PORT_Msk, /**< GPIOTE interrupt from PORT event. */ |
| Vincent Coubard |
638:c90ae1400bf2 | 112 | } nrf_gpiote_int_t; |
| Vincent Coubard |
638:c90ae1400bf2 | 113 | |
| Vincent Coubard |
638:c90ae1400bf2 | 114 | #define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\ |
| Vincent Coubard |
638:c90ae1400bf2 | 115 | NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK) |
| Vincent Coubard |
638:c90ae1400bf2 | 116 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 117 | * @brief Function for activating a specific GPIOTE task. |
| Vincent Coubard |
638:c90ae1400bf2 | 118 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 119 | * @param[in] task Task. |
| Vincent Coubard |
638:c90ae1400bf2 | 120 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 121 | __STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task); |
| Vincent Coubard |
638:c90ae1400bf2 | 122 | |
| Vincent Coubard |
638:c90ae1400bf2 | 123 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 124 | * @brief Function for getting the address of a specific GPIOTE task. |
| Vincent Coubard |
638:c90ae1400bf2 | 125 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 126 | * @param[in] task Task. |
| Vincent Coubard |
638:c90ae1400bf2 | 127 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 128 | * @returns Address. |
| Vincent Coubard |
638:c90ae1400bf2 | 129 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 130 | __STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task); |
| Vincent Coubard |
638:c90ae1400bf2 | 131 | |
| Vincent Coubard |
638:c90ae1400bf2 | 132 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 133 | * @brief Function for getting the state of a specific GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 134 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 135 | * @param[in] event Event. |
| Vincent Coubard |
638:c90ae1400bf2 | 136 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 137 | __STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event); |
| Vincent Coubard |
638:c90ae1400bf2 | 138 | |
| Vincent Coubard |
638:c90ae1400bf2 | 139 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 140 | * @brief Function for clearing a specific GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 141 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 142 | * @param[in] event Event. |
| Vincent Coubard |
638:c90ae1400bf2 | 143 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 144 | __STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event); |
| Vincent Coubard |
638:c90ae1400bf2 | 145 | |
| Vincent Coubard |
638:c90ae1400bf2 | 146 | /** |
| Vincent Coubard |
638:c90ae1400bf2 | 147 | * @brief Function for getting the address of a specific GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 148 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 149 | * @param[in] event Event. |
| Vincent Coubard |
638:c90ae1400bf2 | 150 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 151 | * @return Address |
| Vincent Coubard |
638:c90ae1400bf2 | 152 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 153 | __STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event); |
| Vincent Coubard |
638:c90ae1400bf2 | 154 | |
| Vincent Coubard |
638:c90ae1400bf2 | 155 | /**@brief Function for enabling interrupts. |
| Vincent Coubard |
638:c90ae1400bf2 | 156 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 157 | * @param[in] mask Interrupt mask to be enabled. |
| Vincent Coubard |
638:c90ae1400bf2 | 158 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 159 | __STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask); |
| Vincent Coubard |
638:c90ae1400bf2 | 160 | |
| Vincent Coubard |
638:c90ae1400bf2 | 161 | /**@brief Function for disabling interrupts. |
| Vincent Coubard |
638:c90ae1400bf2 | 162 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 163 | * @param[in] mask Interrupt mask to be disabled. |
| Vincent Coubard |
638:c90ae1400bf2 | 164 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 165 | __STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask); |
| Vincent Coubard |
638:c90ae1400bf2 | 166 | |
| Vincent Coubard |
638:c90ae1400bf2 | 167 | /**@brief Function for checking if interrupts are enabled. |
| Vincent Coubard |
638:c90ae1400bf2 | 168 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 169 | * @param[in] mask Mask of interrupt flags to check. |
| Vincent Coubard |
638:c90ae1400bf2 | 170 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 171 | * @return Mask with enabled interrupts. |
| Vincent Coubard |
638:c90ae1400bf2 | 172 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 173 | __STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask); |
| Vincent Coubard |
638:c90ae1400bf2 | 174 | |
| Vincent Coubard |
638:c90ae1400bf2 | 175 | /**@brief Function for enabling a GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 176 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 177 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 178 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 179 | __STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 180 | |
| Vincent Coubard |
638:c90ae1400bf2 | 181 | /**@brief Function for disabling a GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 182 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 183 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 184 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 185 | __STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 186 | |
| Vincent Coubard |
638:c90ae1400bf2 | 187 | /**@brief Function for configuring a GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 188 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 189 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 190 | * @param[in] pin Pin associated with event. |
| Vincent Coubard |
638:c90ae1400bf2 | 191 | * @param[in] polarity Transition that should generate an event. |
| Vincent Coubard |
638:c90ae1400bf2 | 192 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 193 | __STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin, |
| Vincent Coubard |
638:c90ae1400bf2 | 194 | nrf_gpiote_polarity_t polarity); |
| Vincent Coubard |
638:c90ae1400bf2 | 195 | |
| Vincent Coubard |
638:c90ae1400bf2 | 196 | /**@brief Function for getting the pin associated with a GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 197 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 198 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 199 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 200 | * @return Pin number. |
| Vincent Coubard |
638:c90ae1400bf2 | 201 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 202 | __STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 203 | |
| Vincent Coubard |
638:c90ae1400bf2 | 204 | /**@brief Function for getting the polarity associated with a GPIOTE event. |
| Vincent Coubard |
638:c90ae1400bf2 | 205 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 206 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 207 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 208 | * @return Polarity. |
| Vincent Coubard |
638:c90ae1400bf2 | 209 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 210 | __STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 211 | |
| Vincent Coubard |
638:c90ae1400bf2 | 212 | /**@brief Function for enabling a GPIOTE task. |
| Vincent Coubard |
638:c90ae1400bf2 | 213 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 214 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 215 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 216 | __STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 217 | |
| Vincent Coubard |
638:c90ae1400bf2 | 218 | /**@brief Function for disabling a GPIOTE task. |
| Vincent Coubard |
638:c90ae1400bf2 | 219 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 220 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 221 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 222 | __STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 223 | |
| Vincent Coubard |
638:c90ae1400bf2 | 224 | /**@brief Function for configuring a GPIOTE task. |
| Vincent Coubard |
638:c90ae1400bf2 | 225 | * @note Function is not configuring mode field so task is disabled after this function is called. |
| Vincent Coubard |
638:c90ae1400bf2 | 226 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 227 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 228 | * @param[in] pin Pin associated with event. |
| Vincent Coubard |
638:c90ae1400bf2 | 229 | * @param[in] polarity Transition that should generate an event. |
| Vincent Coubard |
638:c90ae1400bf2 | 230 | * @param[in] init_val Initial value of pin. |
| Vincent Coubard |
638:c90ae1400bf2 | 231 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 232 | __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin, |
| Vincent Coubard |
638:c90ae1400bf2 | 233 | nrf_gpiote_polarity_t polarity, |
| Vincent Coubard |
638:c90ae1400bf2 | 234 | nrf_gpiote_outinit_t init_val); |
| Vincent Coubard |
638:c90ae1400bf2 | 235 | |
| Vincent Coubard |
638:c90ae1400bf2 | 236 | /**@brief Function for forcing a specific state on the pin connected to GPIOTE. |
| Vincent Coubard |
638:c90ae1400bf2 | 237 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 238 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 239 | * @param[in] init_val Pin state. |
| Vincent Coubard |
638:c90ae1400bf2 | 240 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 241 | __STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val); |
| Vincent Coubard |
638:c90ae1400bf2 | 242 | |
| Vincent Coubard |
638:c90ae1400bf2 | 243 | /**@brief Function for resetting a GPIOTE task event configuration to the default state. |
| Vincent Coubard |
638:c90ae1400bf2 | 244 | * |
| Vincent Coubard |
638:c90ae1400bf2 | 245 | * @param[in] idx Task-Event index. |
| Vincent Coubard |
638:c90ae1400bf2 | 246 | */ |
| Vincent Coubard |
638:c90ae1400bf2 | 247 | __STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx); |
| Vincent Coubard |
638:c90ae1400bf2 | 248 | |
| Vincent Coubard |
638:c90ae1400bf2 | 249 | #ifndef SUPPRESS_INLINE_IMPLEMENTATION |
| Vincent Coubard |
638:c90ae1400bf2 | 250 | __STATIC_INLINE void nrf_gpiote_task_set(nrf_gpiote_tasks_t task) |
| Vincent Coubard |
638:c90ae1400bf2 | 251 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 252 | *(__IO uint32_t *)((uint32_t)NRF_GPIOTE + task) = 0x1UL; |
| Vincent Coubard |
638:c90ae1400bf2 | 253 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 254 | |
| Vincent Coubard |
638:c90ae1400bf2 | 255 | __STATIC_INLINE uint32_t nrf_gpiote_task_addr_get(nrf_gpiote_tasks_t task) |
| Vincent Coubard |
638:c90ae1400bf2 | 256 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 257 | return ((uint32_t)NRF_GPIOTE + task); |
| Vincent Coubard |
638:c90ae1400bf2 | 258 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 259 | |
| Vincent Coubard |
638:c90ae1400bf2 | 260 | __STATIC_INLINE bool nrf_gpiote_event_is_set(nrf_gpiote_events_t event) |
| Vincent Coubard |
638:c90ae1400bf2 | 261 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 262 | return (*(uint32_t *)nrf_gpiote_event_addr_get(event) == 0x1UL) ? true : false; |
| Vincent Coubard |
638:c90ae1400bf2 | 263 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 264 | |
| Vincent Coubard |
638:c90ae1400bf2 | 265 | __STATIC_INLINE void nrf_gpiote_event_clear(nrf_gpiote_events_t event) |
| Vincent Coubard |
638:c90ae1400bf2 | 266 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 267 | *(uint32_t *)nrf_gpiote_event_addr_get(event) = 0; |
| Vincent Coubard |
638:c90ae1400bf2 | 268 | #if __CORTEX_M == 0x04 |
| Vincent Coubard |
638:c90ae1400bf2 | 269 | volatile uint32_t dummy = *((volatile uint32_t *)nrf_gpiote_event_addr_get(event)); |
| Vincent Coubard |
638:c90ae1400bf2 | 270 | (void)dummy; |
| Vincent Coubard |
638:c90ae1400bf2 | 271 | #endif |
| Vincent Coubard |
638:c90ae1400bf2 | 272 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 273 | |
| Vincent Coubard |
638:c90ae1400bf2 | 274 | __STATIC_INLINE uint32_t nrf_gpiote_event_addr_get(nrf_gpiote_events_t event) |
| Vincent Coubard |
638:c90ae1400bf2 | 275 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 276 | return ((uint32_t)NRF_GPIOTE + event); |
| Vincent Coubard |
638:c90ae1400bf2 | 277 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 278 | |
| Vincent Coubard |
638:c90ae1400bf2 | 279 | __STATIC_INLINE void nrf_gpiote_int_enable(uint32_t mask) |
| Vincent Coubard |
638:c90ae1400bf2 | 280 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 281 | NRF_GPIOTE->INTENSET = mask; |
| Vincent Coubard |
638:c90ae1400bf2 | 282 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 283 | |
| Vincent Coubard |
638:c90ae1400bf2 | 284 | __STATIC_INLINE void nrf_gpiote_int_disable(uint32_t mask) |
| Vincent Coubard |
638:c90ae1400bf2 | 285 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 286 | NRF_GPIOTE->INTENCLR = mask; |
| Vincent Coubard |
638:c90ae1400bf2 | 287 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 288 | |
| Vincent Coubard |
638:c90ae1400bf2 | 289 | __STATIC_INLINE uint32_t nrf_gpiote_int_is_enabled(uint32_t mask) |
| Vincent Coubard |
638:c90ae1400bf2 | 290 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 291 | return (NRF_GPIOTE->INTENSET & mask); |
| Vincent Coubard |
638:c90ae1400bf2 | 292 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 293 | |
| Vincent Coubard |
638:c90ae1400bf2 | 294 | __STATIC_INLINE void nrf_gpiote_event_enable(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 295 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 296 | NRF_GPIOTE->CONFIG[idx] |= GPIOTE_CONFIG_MODE_Event; |
| Vincent Coubard |
638:c90ae1400bf2 | 297 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 298 | |
| Vincent Coubard |
638:c90ae1400bf2 | 299 | __STATIC_INLINE void nrf_gpiote_event_disable(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 300 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 301 | NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Event; |
| Vincent Coubard |
638:c90ae1400bf2 | 302 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 303 | |
| Vincent Coubard |
638:c90ae1400bf2 | 304 | __STATIC_INLINE void nrf_gpiote_event_configure(uint32_t idx, uint32_t pin, nrf_gpiote_polarity_t polarity) |
| Vincent Coubard |
638:c90ae1400bf2 | 305 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 306 | NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PSEL_Msk | GPIOTE_CONFIG_POLARITY_Msk); |
| Vincent Coubard |
638:c90ae1400bf2 | 307 | NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PSEL_Msk) | |
| Vincent Coubard |
638:c90ae1400bf2 | 308 | ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk); |
| Vincent Coubard |
638:c90ae1400bf2 | 309 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 310 | |
| Vincent Coubard |
638:c90ae1400bf2 | 311 | __STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 312 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 313 | return ((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_PSEL_Msk) >> GPIOTE_CONFIG_PSEL_Pos); |
| Vincent Coubard |
638:c90ae1400bf2 | 314 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 315 | |
| Vincent Coubard |
638:c90ae1400bf2 | 316 | __STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 317 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 318 | return (nrf_gpiote_polarity_t)((NRF_GPIOTE->CONFIG[idx] & GPIOTE_CONFIG_POLARITY_Msk) >> GPIOTE_CONFIG_POLARITY_Pos); |
| Vincent Coubard |
638:c90ae1400bf2 | 319 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 320 | |
| Vincent Coubard |
638:c90ae1400bf2 | 321 | __STATIC_INLINE void nrf_gpiote_task_enable(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 322 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 323 | uint32_t final_config = NRF_GPIOTE->CONFIG[idx] | GPIOTE_CONFIG_MODE_Task; |
| Vincent Coubard |
638:c90ae1400bf2 | 324 | /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens |
| Vincent Coubard |
638:c90ae1400bf2 | 325 | on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the |
| Vincent Coubard |
638:c90ae1400bf2 | 326 | correct state in GPIOTE but not in the OUT register. */ |
| Vincent Coubard |
638:c90ae1400bf2 | 327 | /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */ |
| Vincent Coubard |
638:c90ae1400bf2 | 328 | NRF_GPIOTE->CONFIG[idx] = final_config | ((31 << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PSEL_Msk); |
| Vincent Coubard |
638:c90ae1400bf2 | 329 | __NOP(); |
| Vincent Coubard |
638:c90ae1400bf2 | 330 | __NOP(); |
| Vincent Coubard |
638:c90ae1400bf2 | 331 | __NOP(); |
| Vincent Coubard |
638:c90ae1400bf2 | 332 | NRF_GPIOTE->CONFIG[idx] = final_config; |
| Vincent Coubard |
638:c90ae1400bf2 | 333 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 334 | |
| Vincent Coubard |
638:c90ae1400bf2 | 335 | __STATIC_INLINE void nrf_gpiote_task_disable(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 336 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 337 | NRF_GPIOTE->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Task; |
| Vincent Coubard |
638:c90ae1400bf2 | 338 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 339 | |
| Vincent Coubard |
638:c90ae1400bf2 | 340 | __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin, |
| Vincent Coubard |
638:c90ae1400bf2 | 341 | nrf_gpiote_polarity_t polarity, |
| Vincent Coubard |
638:c90ae1400bf2 | 342 | nrf_gpiote_outinit_t init_val) |
| Vincent Coubard |
638:c90ae1400bf2 | 343 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 344 | NRF_GPIOTE->CONFIG[idx] &= ~(GPIOTE_CONFIG_PSEL_Msk | |
| Vincent Coubard |
638:c90ae1400bf2 | 345 | GPIOTE_CONFIG_POLARITY_Msk | |
| Vincent Coubard |
638:c90ae1400bf2 | 346 | GPIOTE_CONFIG_OUTINIT_Msk); |
| Vincent Coubard |
638:c90ae1400bf2 | 347 | |
| Vincent Coubard |
638:c90ae1400bf2 | 348 | NRF_GPIOTE->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PSEL_Msk) | |
| Vincent Coubard |
638:c90ae1400bf2 | 349 | ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk) | |
| Vincent Coubard |
638:c90ae1400bf2 | 350 | ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk); |
| Vincent Coubard |
638:c90ae1400bf2 | 351 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 352 | |
| Vincent Coubard |
638:c90ae1400bf2 | 353 | __STATIC_INLINE void nrf_gpiote_task_force(uint32_t idx, nrf_gpiote_outinit_t init_val) |
| Vincent Coubard |
638:c90ae1400bf2 | 354 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 355 | NRF_GPIOTE->CONFIG[idx] = (NRF_GPIOTE->CONFIG[idx] & ~GPIOTE_CONFIG_OUTINIT_Msk) |
| Vincent Coubard |
638:c90ae1400bf2 | 356 | | ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk); |
| Vincent Coubard |
638:c90ae1400bf2 | 357 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 358 | |
| Vincent Coubard |
638:c90ae1400bf2 | 359 | __STATIC_INLINE void nrf_gpiote_te_default(uint32_t idx) |
| Vincent Coubard |
638:c90ae1400bf2 | 360 | { |
| Vincent Coubard |
638:c90ae1400bf2 | 361 | NRF_GPIOTE->CONFIG[idx] = 0; |
| Vincent Coubard |
638:c90ae1400bf2 | 362 | } |
| Vincent Coubard |
638:c90ae1400bf2 | 363 | #endif //SUPPRESS_INLINE_IMPLEMENTATION |
| Vincent Coubard |
638:c90ae1400bf2 | 364 | /** @} */ |
| Vincent Coubard |
638:c90ae1400bf2 | 365 | |
| Vincent Coubard |
638:c90ae1400bf2 | 366 | #endif |
