Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Thu Apr 30 08:34:37 2015 +0100
Revision:
112:737b08b3b995
Parent:
103:138bdc859cc9
Synchronized with git rev 4ae92f89
Author: Rohit Grover
porting to v8.0 of the SDK

Who changed what in which revision?

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