The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

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