project for nrf51822 qfab
Dependencies: eddystone_URL mbed
Fork of eddystone_URL by
nRF51822/nordic/app_common/app_gpiote.c@0:76dfa9657d9d, 2014-11-12 (annotated)
- Committer:
- jksoft
- Date:
- Wed Nov 12 02:40:34 2014 +0000
- Revision:
- 0:76dfa9657d9d
????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:76dfa9657d9d | 2 | * |
jksoft | 0:76dfa9657d9d | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 0:76dfa9657d9d | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 0:76dfa9657d9d | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 0:76dfa9657d9d | 6 | * |
jksoft | 0:76dfa9657d9d | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 0:76dfa9657d9d | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 0:76dfa9657d9d | 9 | * the file. |
jksoft | 0:76dfa9657d9d | 10 | * |
jksoft | 0:76dfa9657d9d | 11 | */ |
jksoft | 0:76dfa9657d9d | 12 | |
jksoft | 0:76dfa9657d9d | 13 | #if NEED_APP_GPIOTE /* disabled by default */ |
jksoft | 0:76dfa9657d9d | 14 | |
jksoft | 0:76dfa9657d9d | 15 | #include "app_gpiote.h" |
jksoft | 0:76dfa9657d9d | 16 | #include <stdlib.h> |
jksoft | 0:76dfa9657d9d | 17 | #include <string.h> |
jksoft | 0:76dfa9657d9d | 18 | #include "app_util.h" |
jksoft | 0:76dfa9657d9d | 19 | #include "app_util_platform.h" |
jksoft | 0:76dfa9657d9d | 20 | #include "nrf_error.h" |
jksoft | 0:76dfa9657d9d | 21 | #include "nrf_gpio.h" |
jksoft | 0:76dfa9657d9d | 22 | |
jksoft | 0:76dfa9657d9d | 23 | |
jksoft | 0:76dfa9657d9d | 24 | /**@brief GPIOTE user type. */ |
jksoft | 0:76dfa9657d9d | 25 | typedef struct |
jksoft | 0:76dfa9657d9d | 26 | { |
jksoft | 0:76dfa9657d9d | 27 | uint32_t pins_mask; /**< Mask defining which pins user wants to monitor. */ |
jksoft | 0:76dfa9657d9d | 28 | uint32_t pins_low_to_high_mask; /**< Mask defining which pins will generate events to this user when toggling low->high. */ |
jksoft | 0:76dfa9657d9d | 29 | uint32_t pins_high_to_low_mask; /**< Mask defining which pins will generate events to this user when toggling high->low. */ |
jksoft | 0:76dfa9657d9d | 30 | uint32_t sense_high_pins; /**< Mask defining which pins are configured to generate GPIOTE interrupt on transition to high level. */ |
jksoft | 0:76dfa9657d9d | 31 | app_gpiote_event_handler_t event_handler; /**< Pointer to function to be executed when an event occurs. */ |
jksoft | 0:76dfa9657d9d | 32 | } gpiote_user_t; |
jksoft | 0:76dfa9657d9d | 33 | |
jksoft | 0:76dfa9657d9d | 34 | STATIC_ASSERT(sizeof(gpiote_user_t) <= GPIOTE_USER_NODE_SIZE); |
jksoft | 0:76dfa9657d9d | 35 | STATIC_ASSERT(sizeof(gpiote_user_t) % 4 == 0); |
jksoft | 0:76dfa9657d9d | 36 | |
jksoft | 0:76dfa9657d9d | 37 | static uint32_t m_enabled_users_mask; /**< Mask for tracking which users are enabled. */ |
jksoft | 0:76dfa9657d9d | 38 | static uint8_t m_user_array_size; /**< Size of user array. */ |
jksoft | 0:76dfa9657d9d | 39 | static uint8_t m_user_count; /**< Number of registered users. */ |
jksoft | 0:76dfa9657d9d | 40 | static gpiote_user_t * mp_users = NULL; /**< Array of GPIOTE users. */ |
jksoft | 0:76dfa9657d9d | 41 | |
jksoft | 0:76dfa9657d9d | 42 | |
jksoft | 0:76dfa9657d9d | 43 | /**@brief Function for toggling sense level for specified pins. |
jksoft | 0:76dfa9657d9d | 44 | * |
jksoft | 0:76dfa9657d9d | 45 | * @param[in] p_user Pointer to user structure. |
jksoft | 0:76dfa9657d9d | 46 | * @param[in] pins Bitmask specifying for which pins the sense level is to be toggled. |
jksoft | 0:76dfa9657d9d | 47 | */ |
jksoft | 0:76dfa9657d9d | 48 | static void sense_level_toggle(gpiote_user_t * p_user, uint32_t pins) |
jksoft | 0:76dfa9657d9d | 49 | { |
jksoft | 0:76dfa9657d9d | 50 | uint32_t pin_no; |
jksoft | 0:76dfa9657d9d | 51 | |
jksoft | 0:76dfa9657d9d | 52 | for (pin_no = 0; pin_no < NO_OF_PINS; pin_no++) |
jksoft | 0:76dfa9657d9d | 53 | { |
jksoft | 0:76dfa9657d9d | 54 | uint32_t pin_mask = (1 << pin_no); |
jksoft | 0:76dfa9657d9d | 55 | |
jksoft | 0:76dfa9657d9d | 56 | if ((pins & pin_mask) != 0) |
jksoft | 0:76dfa9657d9d | 57 | { |
jksoft | 0:76dfa9657d9d | 58 | uint32_t sense; |
jksoft | 0:76dfa9657d9d | 59 | |
jksoft | 0:76dfa9657d9d | 60 | // Invert sensing. |
jksoft | 0:76dfa9657d9d | 61 | if ((p_user->sense_high_pins & pin_mask) == 0) |
jksoft | 0:76dfa9657d9d | 62 | { |
jksoft | 0:76dfa9657d9d | 63 | sense = GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos; |
jksoft | 0:76dfa9657d9d | 64 | p_user->sense_high_pins |= pin_mask; |
jksoft | 0:76dfa9657d9d | 65 | } |
jksoft | 0:76dfa9657d9d | 66 | else |
jksoft | 0:76dfa9657d9d | 67 | { |
jksoft | 0:76dfa9657d9d | 68 | sense = GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos; |
jksoft | 0:76dfa9657d9d | 69 | p_user->sense_high_pins &= ~pin_mask; |
jksoft | 0:76dfa9657d9d | 70 | } |
jksoft | 0:76dfa9657d9d | 71 | |
jksoft | 0:76dfa9657d9d | 72 | NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk; |
jksoft | 0:76dfa9657d9d | 73 | NRF_GPIO->PIN_CNF[pin_no] |= sense; |
jksoft | 0:76dfa9657d9d | 74 | } |
jksoft | 0:76dfa9657d9d | 75 | } |
jksoft | 0:76dfa9657d9d | 76 | } |
jksoft | 0:76dfa9657d9d | 77 | |
jksoft | 0:76dfa9657d9d | 78 | |
jksoft | 0:76dfa9657d9d | 79 | /**@brief Function for handling the GPIOTE interrupt. |
jksoft | 0:76dfa9657d9d | 80 | */ |
jksoft | 0:76dfa9657d9d | 81 | void GPIOTE_IRQHandler(void) |
jksoft | 0:76dfa9657d9d | 82 | { |
jksoft | 0:76dfa9657d9d | 83 | uint8_t i; |
jksoft | 0:76dfa9657d9d | 84 | uint32_t pins_changed; |
jksoft | 0:76dfa9657d9d | 85 | uint32_t pins_state = NRF_GPIO->IN; |
jksoft | 0:76dfa9657d9d | 86 | |
jksoft | 0:76dfa9657d9d | 87 | // Clear event. |
jksoft | 0:76dfa9657d9d | 88 | NRF_GPIOTE->EVENTS_PORT = 0; |
jksoft | 0:76dfa9657d9d | 89 | |
jksoft | 0:76dfa9657d9d | 90 | // Check all users. |
jksoft | 0:76dfa9657d9d | 91 | for (i = 0; i < m_user_count; i++) |
jksoft | 0:76dfa9657d9d | 92 | { |
jksoft | 0:76dfa9657d9d | 93 | gpiote_user_t * p_user = &mp_users[i]; |
jksoft | 0:76dfa9657d9d | 94 | |
jksoft | 0:76dfa9657d9d | 95 | // Check if user is enabled. |
jksoft | 0:76dfa9657d9d | 96 | if (((1 << i) & m_enabled_users_mask) != 0) |
jksoft | 0:76dfa9657d9d | 97 | { |
jksoft | 0:76dfa9657d9d | 98 | uint32_t transition_pins; |
jksoft | 0:76dfa9657d9d | 99 | uint32_t event_low_to_high; |
jksoft | 0:76dfa9657d9d | 100 | uint32_t event_high_to_low; |
jksoft | 0:76dfa9657d9d | 101 | |
jksoft | 0:76dfa9657d9d | 102 | // Find set of pins on which there has been a transition. |
jksoft | 0:76dfa9657d9d | 103 | transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask; |
jksoft | 0:76dfa9657d9d | 104 | |
jksoft | 0:76dfa9657d9d | 105 | // Toggle SENSE level for all pins that have changed state. |
jksoft | 0:76dfa9657d9d | 106 | sense_level_toggle(p_user, transition_pins); |
jksoft | 0:76dfa9657d9d | 107 | |
jksoft | 0:76dfa9657d9d | 108 | // Second read after setting sense. |
jksoft | 0:76dfa9657d9d | 109 | // Check if any pins have changed while serving this interrupt. |
jksoft | 0:76dfa9657d9d | 110 | pins_changed = NRF_GPIO->IN ^ pins_state; |
jksoft | 0:76dfa9657d9d | 111 | if (pins_changed) |
jksoft | 0:76dfa9657d9d | 112 | { |
jksoft | 0:76dfa9657d9d | 113 | // Transition pins detected in late stage. |
jksoft | 0:76dfa9657d9d | 114 | uint32_t late_transition_pins; |
jksoft | 0:76dfa9657d9d | 115 | |
jksoft | 0:76dfa9657d9d | 116 | pins_state |= pins_changed; |
jksoft | 0:76dfa9657d9d | 117 | |
jksoft | 0:76dfa9657d9d | 118 | // Find set of pins on which there has been a transition. |
jksoft | 0:76dfa9657d9d | 119 | late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask; |
jksoft | 0:76dfa9657d9d | 120 | |
jksoft | 0:76dfa9657d9d | 121 | // Toggle SENSE level for all pins that have changed state in last phase. |
jksoft | 0:76dfa9657d9d | 122 | sense_level_toggle(p_user, late_transition_pins); |
jksoft | 0:76dfa9657d9d | 123 | |
jksoft | 0:76dfa9657d9d | 124 | // Update pins that has changed state since the interrupt occurred. |
jksoft | 0:76dfa9657d9d | 125 | transition_pins |= late_transition_pins; |
jksoft | 0:76dfa9657d9d | 126 | } |
jksoft | 0:76dfa9657d9d | 127 | |
jksoft | 0:76dfa9657d9d | 128 | // Call user event handler if an event has occurred. |
jksoft | 0:76dfa9657d9d | 129 | event_high_to_low = (~pins_state & p_user->pins_high_to_low_mask) & transition_pins; |
jksoft | 0:76dfa9657d9d | 130 | event_low_to_high = (pins_state & p_user->pins_low_to_high_mask) & transition_pins; |
jksoft | 0:76dfa9657d9d | 131 | |
jksoft | 0:76dfa9657d9d | 132 | if ((event_low_to_high | event_high_to_low) != 0) |
jksoft | 0:76dfa9657d9d | 133 | { |
jksoft | 0:76dfa9657d9d | 134 | p_user->event_handler(event_low_to_high, event_high_to_low); |
jksoft | 0:76dfa9657d9d | 135 | } |
jksoft | 0:76dfa9657d9d | 136 | } |
jksoft | 0:76dfa9657d9d | 137 | } |
jksoft | 0:76dfa9657d9d | 138 | } |
jksoft | 0:76dfa9657d9d | 139 | |
jksoft | 0:76dfa9657d9d | 140 | |
jksoft | 0:76dfa9657d9d | 141 | /**@brief Function for sense disabling for all pins for specified user. |
jksoft | 0:76dfa9657d9d | 142 | * |
jksoft | 0:76dfa9657d9d | 143 | * @param[in] user_id User id. |
jksoft | 0:76dfa9657d9d | 144 | */ |
jksoft | 0:76dfa9657d9d | 145 | static void pins_sense_disable(app_gpiote_user_id_t user_id) |
jksoft | 0:76dfa9657d9d | 146 | { |
jksoft | 0:76dfa9657d9d | 147 | uint32_t pin_no; |
jksoft | 0:76dfa9657d9d | 148 | |
jksoft | 0:76dfa9657d9d | 149 | for (pin_no = 0; pin_no < 32; pin_no++) |
jksoft | 0:76dfa9657d9d | 150 | { |
jksoft | 0:76dfa9657d9d | 151 | if ((mp_users[user_id].pins_mask & (1 << pin_no)) != 0) |
jksoft | 0:76dfa9657d9d | 152 | { |
jksoft | 0:76dfa9657d9d | 153 | NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk; |
jksoft | 0:76dfa9657d9d | 154 | NRF_GPIO->PIN_CNF[pin_no] |= GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos; |
jksoft | 0:76dfa9657d9d | 155 | } |
jksoft | 0:76dfa9657d9d | 156 | } |
jksoft | 0:76dfa9657d9d | 157 | } |
jksoft | 0:76dfa9657d9d | 158 | |
jksoft | 0:76dfa9657d9d | 159 | |
jksoft | 0:76dfa9657d9d | 160 | uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer) |
jksoft | 0:76dfa9657d9d | 161 | { |
jksoft | 0:76dfa9657d9d | 162 | if (p_buffer == NULL) |
jksoft | 0:76dfa9657d9d | 163 | { |
jksoft | 0:76dfa9657d9d | 164 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 0:76dfa9657d9d | 165 | } |
jksoft | 0:76dfa9657d9d | 166 | |
jksoft | 0:76dfa9657d9d | 167 | // Check that buffer is correctly aligned. |
jksoft | 0:76dfa9657d9d | 168 | if (!is_word_aligned(p_buffer)) |
jksoft | 0:76dfa9657d9d | 169 | { |
jksoft | 0:76dfa9657d9d | 170 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 0:76dfa9657d9d | 171 | } |
jksoft | 0:76dfa9657d9d | 172 | |
jksoft | 0:76dfa9657d9d | 173 | // Initialize file globals. |
jksoft | 0:76dfa9657d9d | 174 | mp_users = (gpiote_user_t *)p_buffer; |
jksoft | 0:76dfa9657d9d | 175 | m_user_array_size = max_users; |
jksoft | 0:76dfa9657d9d | 176 | m_user_count = 0; |
jksoft | 0:76dfa9657d9d | 177 | m_enabled_users_mask = 0; |
jksoft | 0:76dfa9657d9d | 178 | |
jksoft | 0:76dfa9657d9d | 179 | memset(mp_users, 0, m_user_array_size * sizeof(gpiote_user_t)); |
jksoft | 0:76dfa9657d9d | 180 | |
jksoft | 0:76dfa9657d9d | 181 | // Initialize GPIOTE interrupt (will not be enabled until app_gpiote_user_enable() is called). |
jksoft | 0:76dfa9657d9d | 182 | NRF_GPIOTE->INTENCLR = 0xFFFFFFFF; |
jksoft | 0:76dfa9657d9d | 183 | |
jksoft | 0:76dfa9657d9d | 184 | NVIC_ClearPendingIRQ(GPIOTE_IRQn); |
jksoft | 0:76dfa9657d9d | 185 | NVIC_SetPriority(GPIOTE_IRQn, APP_IRQ_PRIORITY_HIGH); |
jksoft | 0:76dfa9657d9d | 186 | NVIC_EnableIRQ(GPIOTE_IRQn); |
jksoft | 0:76dfa9657d9d | 187 | |
jksoft | 0:76dfa9657d9d | 188 | return NRF_SUCCESS; |
jksoft | 0:76dfa9657d9d | 189 | } |
jksoft | 0:76dfa9657d9d | 190 | |
jksoft | 0:76dfa9657d9d | 191 | |
jksoft | 0:76dfa9657d9d | 192 | uint32_t app_gpiote_user_register(app_gpiote_user_id_t * p_user_id, |
jksoft | 0:76dfa9657d9d | 193 | uint32_t pins_low_to_high_mask, |
jksoft | 0:76dfa9657d9d | 194 | uint32_t pins_high_to_low_mask, |
jksoft | 0:76dfa9657d9d | 195 | app_gpiote_event_handler_t event_handler) |
jksoft | 0:76dfa9657d9d | 196 | { |
jksoft | 0:76dfa9657d9d | 197 | // Check state and parameters. |
jksoft | 0:76dfa9657d9d | 198 | if (mp_users == NULL) |
jksoft | 0:76dfa9657d9d | 199 | { |
jksoft | 0:76dfa9657d9d | 200 | return NRF_ERROR_INVALID_STATE; |
jksoft | 0:76dfa9657d9d | 201 | } |
jksoft | 0:76dfa9657d9d | 202 | if (event_handler == NULL) |
jksoft | 0:76dfa9657d9d | 203 | { |
jksoft | 0:76dfa9657d9d | 204 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 0:76dfa9657d9d | 205 | } |
jksoft | 0:76dfa9657d9d | 206 | if (m_user_count >= m_user_array_size) |
jksoft | 0:76dfa9657d9d | 207 | { |
jksoft | 0:76dfa9657d9d | 208 | return NRF_ERROR_NO_MEM; |
jksoft | 0:76dfa9657d9d | 209 | } |
jksoft | 0:76dfa9657d9d | 210 | |
jksoft | 0:76dfa9657d9d | 211 | // Allocate new user. |
jksoft | 0:76dfa9657d9d | 212 | mp_users[m_user_count].pins_mask = pins_low_to_high_mask | pins_high_to_low_mask; |
jksoft | 0:76dfa9657d9d | 213 | mp_users[m_user_count].pins_low_to_high_mask = pins_low_to_high_mask; |
jksoft | 0:76dfa9657d9d | 214 | mp_users[m_user_count].pins_high_to_low_mask = pins_high_to_low_mask; |
jksoft | 0:76dfa9657d9d | 215 | mp_users[m_user_count].event_handler = event_handler; |
jksoft | 0:76dfa9657d9d | 216 | |
jksoft | 0:76dfa9657d9d | 217 | *p_user_id = m_user_count++; |
jksoft | 0:76dfa9657d9d | 218 | |
jksoft | 0:76dfa9657d9d | 219 | // Make sure SENSE is disabled for all pins. |
jksoft | 0:76dfa9657d9d | 220 | pins_sense_disable(*p_user_id); |
jksoft | 0:76dfa9657d9d | 221 | |
jksoft | 0:76dfa9657d9d | 222 | return NRF_SUCCESS; |
jksoft | 0:76dfa9657d9d | 223 | } |
jksoft | 0:76dfa9657d9d | 224 | |
jksoft | 0:76dfa9657d9d | 225 | |
jksoft | 0:76dfa9657d9d | 226 | uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id) |
jksoft | 0:76dfa9657d9d | 227 | { |
jksoft | 0:76dfa9657d9d | 228 | uint32_t pin_no; |
jksoft | 0:76dfa9657d9d | 229 | uint32_t pins_state; |
jksoft | 0:76dfa9657d9d | 230 | |
jksoft | 0:76dfa9657d9d | 231 | // Check state and parameters. |
jksoft | 0:76dfa9657d9d | 232 | if (mp_users == NULL) |
jksoft | 0:76dfa9657d9d | 233 | { |
jksoft | 0:76dfa9657d9d | 234 | return NRF_ERROR_INVALID_STATE; |
jksoft | 0:76dfa9657d9d | 235 | } |
jksoft | 0:76dfa9657d9d | 236 | if (user_id >= m_user_count) |
jksoft | 0:76dfa9657d9d | 237 | { |
jksoft | 0:76dfa9657d9d | 238 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 0:76dfa9657d9d | 239 | } |
jksoft | 0:76dfa9657d9d | 240 | |
jksoft | 0:76dfa9657d9d | 241 | // Clear any pending event. |
jksoft | 0:76dfa9657d9d | 242 | NRF_GPIOTE->EVENTS_PORT = 0; |
jksoft | 0:76dfa9657d9d | 243 | pins_state = NRF_GPIO->IN; |
jksoft | 0:76dfa9657d9d | 244 | |
jksoft | 0:76dfa9657d9d | 245 | // Enable user. |
jksoft | 0:76dfa9657d9d | 246 | if (m_enabled_users_mask == 0) |
jksoft | 0:76dfa9657d9d | 247 | { |
jksoft | 0:76dfa9657d9d | 248 | NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk; |
jksoft | 0:76dfa9657d9d | 249 | } |
jksoft | 0:76dfa9657d9d | 250 | m_enabled_users_mask |= (1 << user_id); |
jksoft | 0:76dfa9657d9d | 251 | |
jksoft | 0:76dfa9657d9d | 252 | // Enable sensing for all pins for specified user. |
jksoft | 0:76dfa9657d9d | 253 | mp_users[user_id].sense_high_pins = 0; |
jksoft | 0:76dfa9657d9d | 254 | for (pin_no = 0; pin_no < 32; pin_no++) |
jksoft | 0:76dfa9657d9d | 255 | { |
jksoft | 0:76dfa9657d9d | 256 | uint32_t pin_mask = (1 << pin_no); |
jksoft | 0:76dfa9657d9d | 257 | |
jksoft | 0:76dfa9657d9d | 258 | if ((mp_users[user_id].pins_mask & pin_mask) != 0) |
jksoft | 0:76dfa9657d9d | 259 | { |
jksoft | 0:76dfa9657d9d | 260 | uint32_t sense; |
jksoft | 0:76dfa9657d9d | 261 | |
jksoft | 0:76dfa9657d9d | 262 | if ((pins_state & pin_mask) != 0) |
jksoft | 0:76dfa9657d9d | 263 | { |
jksoft | 0:76dfa9657d9d | 264 | sense = GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos; |
jksoft | 0:76dfa9657d9d | 265 | } |
jksoft | 0:76dfa9657d9d | 266 | else |
jksoft | 0:76dfa9657d9d | 267 | { |
jksoft | 0:76dfa9657d9d | 268 | sense = GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos; |
jksoft | 0:76dfa9657d9d | 269 | mp_users[user_id].sense_high_pins |= pin_mask; |
jksoft | 0:76dfa9657d9d | 270 | } |
jksoft | 0:76dfa9657d9d | 271 | |
jksoft | 0:76dfa9657d9d | 272 | NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk; |
jksoft | 0:76dfa9657d9d | 273 | NRF_GPIO->PIN_CNF[pin_no] |= sense; |
jksoft | 0:76dfa9657d9d | 274 | } |
jksoft | 0:76dfa9657d9d | 275 | } |
jksoft | 0:76dfa9657d9d | 276 | |
jksoft | 0:76dfa9657d9d | 277 | return NRF_SUCCESS; |
jksoft | 0:76dfa9657d9d | 278 | } |
jksoft | 0:76dfa9657d9d | 279 | |
jksoft | 0:76dfa9657d9d | 280 | |
jksoft | 0:76dfa9657d9d | 281 | uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id) |
jksoft | 0:76dfa9657d9d | 282 | { |
jksoft | 0:76dfa9657d9d | 283 | // Check state and parameters. |
jksoft | 0:76dfa9657d9d | 284 | if (mp_users == NULL) |
jksoft | 0:76dfa9657d9d | 285 | { |
jksoft | 0:76dfa9657d9d | 286 | return NRF_ERROR_INVALID_STATE; |
jksoft | 0:76dfa9657d9d | 287 | } |
jksoft | 0:76dfa9657d9d | 288 | if (user_id >= m_user_count) |
jksoft | 0:76dfa9657d9d | 289 | { |
jksoft | 0:76dfa9657d9d | 290 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 0:76dfa9657d9d | 291 | } |
jksoft | 0:76dfa9657d9d | 292 | |
jksoft | 0:76dfa9657d9d | 293 | // Disable sensing for all pins for specified user. |
jksoft | 0:76dfa9657d9d | 294 | pins_sense_disable(user_id); |
jksoft | 0:76dfa9657d9d | 295 | |
jksoft | 0:76dfa9657d9d | 296 | // Disable user. |
jksoft | 0:76dfa9657d9d | 297 | m_enabled_users_mask &= ~(1UL << user_id); |
jksoft | 0:76dfa9657d9d | 298 | if (m_enabled_users_mask == 0) |
jksoft | 0:76dfa9657d9d | 299 | { |
jksoft | 0:76dfa9657d9d | 300 | NRF_GPIOTE->INTENCLR = GPIOTE_INTENSET_PORT_Msk; |
jksoft | 0:76dfa9657d9d | 301 | } |
jksoft | 0:76dfa9657d9d | 302 | |
jksoft | 0:76dfa9657d9d | 303 | return NRF_SUCCESS; |
jksoft | 0:76dfa9657d9d | 304 | } |
jksoft | 0:76dfa9657d9d | 305 | |
jksoft | 0:76dfa9657d9d | 306 | |
jksoft | 0:76dfa9657d9d | 307 | uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins) |
jksoft | 0:76dfa9657d9d | 308 | { |
jksoft | 0:76dfa9657d9d | 309 | gpiote_user_t * p_user; |
jksoft | 0:76dfa9657d9d | 310 | |
jksoft | 0:76dfa9657d9d | 311 | // Check state and parameters. |
jksoft | 0:76dfa9657d9d | 312 | if (mp_users == NULL) |
jksoft | 0:76dfa9657d9d | 313 | { |
jksoft | 0:76dfa9657d9d | 314 | return NRF_ERROR_INVALID_STATE; |
jksoft | 0:76dfa9657d9d | 315 | } |
jksoft | 0:76dfa9657d9d | 316 | if (user_id >= m_user_count) |
jksoft | 0:76dfa9657d9d | 317 | { |
jksoft | 0:76dfa9657d9d | 318 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 0:76dfa9657d9d | 319 | } |
jksoft | 0:76dfa9657d9d | 320 | |
jksoft | 0:76dfa9657d9d | 321 | // Get pins. |
jksoft | 0:76dfa9657d9d | 322 | p_user = &mp_users[user_id]; |
jksoft | 0:76dfa9657d9d | 323 | *p_pins = NRF_GPIO->IN & p_user->pins_mask; |
jksoft | 0:76dfa9657d9d | 324 | |
jksoft | 0:76dfa9657d9d | 325 | return NRF_SUCCESS; |
jksoft | 0:76dfa9657d9d | 326 | } |
jksoft | 0:76dfa9657d9d | 327 | |
jksoft | 0:76dfa9657d9d | 328 | #if defined(SVCALL_AS_NORMAL_FUNCTION) || defined(SER_CONNECTIVITY) |
jksoft | 0:76dfa9657d9d | 329 | uint32_t app_gpiote_input_event_handler_register(const uint8_t channel, |
jksoft | 0:76dfa9657d9d | 330 | const uint32_t pin, |
jksoft | 0:76dfa9657d9d | 331 | const uint32_t polarity, |
jksoft | 0:76dfa9657d9d | 332 | app_gpiote_input_event_handler_t event_handler) |
jksoft | 0:76dfa9657d9d | 333 | { |
jksoft | 0:76dfa9657d9d | 334 | (void)sense_level_toggle(NULL, pin); |
jksoft | 0:76dfa9657d9d | 335 | return NRF_ERROR_NOT_SUPPORTED; |
jksoft | 0:76dfa9657d9d | 336 | } |
jksoft | 0:76dfa9657d9d | 337 | |
jksoft | 0:76dfa9657d9d | 338 | uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel) |
jksoft | 0:76dfa9657d9d | 339 | { |
jksoft | 0:76dfa9657d9d | 340 | return NRF_ERROR_NOT_SUPPORTED; |
jksoft | 0:76dfa9657d9d | 341 | } |
jksoft | 0:76dfa9657d9d | 342 | |
jksoft | 0:76dfa9657d9d | 343 | uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler) |
jksoft | 0:76dfa9657d9d | 344 | { |
jksoft | 0:76dfa9657d9d | 345 | return NRF_ERROR_NOT_SUPPORTED; |
jksoft | 0:76dfa9657d9d | 346 | } |
jksoft | 0:76dfa9657d9d | 347 | |
jksoft | 0:76dfa9657d9d | 348 | uint32_t app_gpiote_end_irq_event_handler_unregister(void) |
jksoft | 0:76dfa9657d9d | 349 | { |
jksoft | 0:76dfa9657d9d | 350 | return NRF_ERROR_NOT_SUPPORTED; |
jksoft | 0:76dfa9657d9d | 351 | } |
jksoft | 0:76dfa9657d9d | 352 | |
jksoft | 0:76dfa9657d9d | 353 | uint32_t app_gpiote_enable_interrupts(void) |
jksoft | 0:76dfa9657d9d | 354 | { |
jksoft | 0:76dfa9657d9d | 355 | return NRF_ERROR_NOT_SUPPORTED; |
jksoft | 0:76dfa9657d9d | 356 | } |
jksoft | 0:76dfa9657d9d | 357 | |
jksoft | 0:76dfa9657d9d | 358 | uint32_t app_gpiote_disable_interrupts(void) |
jksoft | 0:76dfa9657d9d | 359 | { |
jksoft | 0:76dfa9657d9d | 360 | return NRF_ERROR_NOT_SUPPORTED; |
jksoft | 0:76dfa9657d9d | 361 | } |
jksoft | 0:76dfa9657d9d | 362 | #endif // SVCALL_AS_NORMAL_FUNCTION || SER_CONNECTIVITY |
jksoft | 0:76dfa9657d9d | 363 | |
jksoft | 0:76dfa9657d9d | 364 | #endif // #if NEED_APP_GPIOTE |