mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Revision:
150:02e0a0aed4ec
Parent:
149:156823d33999
--- a/targets/TARGET_NORDIC/TARGET_NRF5/gpio_api.c	Fri Oct 28 11:17:30 2016 +0100
+++ b/targets/TARGET_NORDIC/TARGET_NRF5/gpio_api.c	Tue Nov 08 17:45:16 2016 +0000
@@ -62,6 +62,7 @@
     }
 }
 
+void GPIOTE_IRQHandler(void);// exported from nrf_drv_gpiote.c
 
 void gpio_init(gpio_t *obj, PinName pin)
 {
@@ -70,6 +71,9 @@
         return;
     }
     MBED_ASSERT((uint32_t)pin < GPIO_PIN_COUNT);
+    
+    NVIC_SetVector(GPIOTE_IRQn, (uint32_t) GPIOTE_IRQHandler);
+    
     (void) nrf_drv_gpiote_init();
 
     m_gpio_cfg[obj->pin].used_as_gpio = true;
@@ -86,8 +90,7 @@
     }
 }
 
-
-static void gpio_apply_config(uint8_t pin)
+static void gpiote_pin_uninit(uint8_t pin)
 {
     if (m_gpio_initialized & (1UL << pin)) {
         if ((m_gpio_cfg[pin].direction == PIN_OUTPUT) && (!m_gpio_cfg[pin].used_as_irq)) {
@@ -97,7 +100,10 @@
             nrf_drv_gpiote_in_uninit(pin);
         }
     }
+}
 
+static void gpio_apply_config(uint8_t pin)
+{
     if (m_gpio_cfg[pin].used_as_gpio || m_gpio_cfg[pin].used_as_irq) {
         if ((m_gpio_cfg[pin].direction == PIN_INPUT)
             || (m_gpio_cfg[pin].used_as_irq)) {
@@ -147,6 +153,9 @@
 void gpio_mode(gpio_t *obj, PinMode mode)
 {
     MBED_ASSERT(obj->pin <= GPIO_PIN_COUNT);
+    
+    gpiote_pin_uninit(obj->pin); // try to uninitialize gpio before a change.
+    
     m_gpio_cfg[obj->pin].pull = mode;
     gpio_apply_config(obj->pin);
 }
@@ -155,6 +164,9 @@
 void gpio_dir(gpio_t *obj, PinDirection direction)
 {
     MBED_ASSERT(obj->pin <= GPIO_PIN_COUNT);
+    
+    gpiote_pin_uninit(obj->pin); // try to uninitialize gpio before a change.
+    
     m_gpio_cfg[obj->pin].direction = direction;
     gpio_apply_config(obj->pin);
 }
@@ -172,6 +184,8 @@
     MBED_ASSERT((uint32_t)pin < GPIO_PIN_COUNT);
     (void) nrf_drv_gpiote_init();
 
+    gpiote_pin_uninit(pin); // try to uninitialize gpio before a change.
+    
     m_gpio_cfg[pin].used_as_irq = true;
     m_channel_ids[pin] = id;
     obj->ch            = pin;