mbed library sources, with proposed I2C for Seed Arch BLE - not working -

Dependents:   Seeed_Barometer_Sensor_Example

Fork of mbed-src by mbed official

Revision:
15:4892fe388435
Parent:
13:0645d8841f51
Child:
35:371630885ad6
diff -r 096882eb0961 -r 4892fe388435 api/InterruptIn.h
--- a/api/InterruptIn.h	Mon Aug 05 14:54:27 2013 +0000
+++ b/api/InterruptIn.h	Wed Aug 07 16:43:59 2013 +0300
@@ -24,6 +24,7 @@
 #include "gpio_irq_api.h"
 
 #include "FunctionPointer.h"
+#include "CallChain.h"
 
 namespace mbed {
 
@@ -72,37 +73,167 @@
     /** Attach a function to call when a rising edge occurs on the input
      *
      *  @param fptr A pointer to a void function, or 0 to set as none
+     *
+     *  @returns
+     *  The function object created for 'fptr'
      */
-    void rise(void (*fptr)(void));
+    pFunctionPointer_t rise(void (*fptr)(void));
+
+    /** Add a function to be called when a rising edge occurs at the end of the call chain
+     *
+     *  @param fptr the function to add
+     *
+     *  @returns
+     *  The function object created for 'fptr'
+     */
+    pFunctionPointer_t rise_add(void (*fptr)(void)) {
+        return rise_add_common(fptr);
+    }
+
+    /** Add a function to be called when a rising edge occurs at the beginning of the call chain
+     *
+     *  @param fptr the function to add
+     *
+     *  @returns
+     *  The function object created for 'fptr'
+     */
+    pFunctionPointer_t rise_add_front(void (*fptr)(void)) {
+        return rise_add_common(fptr, true);
+    }
 
     /** Attach a member function to call when a rising edge occurs on the input
      *
      *  @param tptr pointer to the object to call the member function on
      *  @param mptr pointer to the member function to be called
+     *
+     *  @returns
+     *  The function object created for 'tptr' and 'mptr'
+     */
+    template<typename T>
+    pFunctionPointer_t rise(T* tptr, void (T::*mptr)(void)) {
+        _rise.clear();
+        pFunctionPointer_t pf = _rise.add(tptr, mptr);
+        gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
+        return pf;
+    }
+
+    /** Add a function to be called when a rising edge occurs at the end of the call chain
+     *
+     *  @param tptr pointer to the object to call the member function on
+     *  @param mptr pointer to the member function to be called
+     *
+     *  @returns
+     *  The function object created for 'tptr' and 'mptr'
      */
     template<typename T>
-    void rise(T* tptr, void (T::*mptr)(void)) {
-        _rise.attach(tptr, mptr);
-        gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
+    pFunctionPointer_t rise_add(T* tptr, void (T::*mptr)(void)) {
+        return rise_add_common(tptr, mptr);
     }
 
+    /** Add a function to be called when a rising edge occurs at the beginning of the call chain
+     *
+     *  @param tptr pointer to the object to call the member function on
+     *  @param mptr pointer to the member function to be called
+     *
+     *  @returns
+     *  The function object created for 'tptr' and 'mptr'
+     */
+    template<typename T>
+    pFunctionPointer_t rise_add_front(T* tptr, void (T::*mptr)(void)) {
+        return rise_add_common(tptr, mptr, true);
+    }
+
+    /** Remove a function from the list of functions to be called when a rising edge occurs
+     *
+     *  @param pf the function object to remove
+     *
+     *  @returns
+     *  true if the function was found and removed, false otherwise
+     */
+    bool rise_remove(pFunctionPointer_t pf);
+
     /** Attach a function to call when a falling edge occurs on the input
      *
      *  @param fptr A pointer to a void function, or 0 to set as none
+     *
+     *  @returns
+     *  The function object created for 'fptr'
      */
-    void fall(void (*fptr)(void));
+    pFunctionPointer_t fall(void (*fptr)(void));
+
+     /** Add a function to be called when a falling edge occurs at the end of the call chain
+     *
+     *  @param fptr the function to add
+     *
+     *  @returns
+     *  The function object created for 'fptr'
+     */   
+    pFunctionPointer_t fall_add(void (*fptr)(void)) {
+        return fall_add_common(fptr);
+    }
+
+    /** Add a function to be called when a falling edge occurs at the beginning of the call chain
+     *
+     *  @param fptr the function to add
+     *
+     *  @returns
+     *  The function object created for 'fptr'
+     */
+    pFunctionPointer_t fall_add_front(void (*fptr)(void)) {
+        return fall_add_common(fptr, true);
+    }
 
     /** Attach a member function to call when a falling edge occurs on the input
      *
      *  @param tptr pointer to the object to call the member function on
      *  @param mptr pointer to the member function to be called
+     *
+     *  @returns
+     *  The function object created for 'tptr' and 'mptr'
+     */
+    template<typename T>
+    pFunctionPointer_t fall(T* tptr, void (T::*mptr)(void)) {
+        _fall.clear();
+        pFunctionPointer_t pf = _fall.add(tptr, mptr);
+        gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
+        return pf;
+    }
+
+    /** Add a function to be called when a falling edge occurs at the end of the call chain
+     *
+     *  @param tptr pointer to the object to call the member function on
+     *  @param mptr pointer to the member function to be called
+     *
+     *  @returns
+     *  The function object created for 'tptr' and 'mptr'
      */
     template<typename T>
-    void fall(T* tptr, void (T::*mptr)(void)) {
-        _fall.attach(tptr, mptr);
-        gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
+    pFunctionPointer_t fall_add(T* tptr, void (T::*mptr)(void)) {
+        return fall_add_common(tptr, mptr);
     }
 
+    /** Add a function to be called when a falling edge occurs at the beginning of the call chain
+     *
+     *  @param tptr pointer to the object to call the member function on
+     *  @param mptr pointer to the member function to be called
+     *
+     *  @returns
+     *  The function object created for 'tptr' and 'mptr'
+     */
+    template<typename T>
+    pFunctionPointer_t fall_add_front(T* tptr, void (T::*mptr)(void)) {
+        return fall_add_common(tptr, mptr, true);
+    }
+
+    /** Remove a function from the list of functions to be called when a falling edge occurs
+     *
+     *  @param pf the function object to remove
+     *
+     *  @returns
+     *  true if the function was found and removed, false otherwise
+     */
+    bool fall_remove(pFunctionPointer_t pf);
+
     /** Set the input pin mode
      *
      *  @param mode PullUp, PullDown, PullNone
@@ -112,11 +243,27 @@
     static void _irq_handler(uint32_t id, gpio_irq_event event);
 
 protected:
+    pFunctionPointer_t rise_add_common(void (*fptr)(void), bool front=false);
+    pFunctionPointer_t fall_add_common(void (*fptr)(void), bool front=false);
+
+    template<typename T>
+    pFunctionPointer_t rise_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
+        pFunctionPointer_t pf = front ? _rise.add_front(tptr, mptr) : _rise.add(tptr, mptr);
+        gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
+        return pf;
+    }
+    template<typename T>
+    pFunctionPointer_t fall_add_common(T* tptr, void (T::*mptr)(void), bool front=false) {
+        pFunctionPointer_t pf = front ? _fall.add_front(tptr, mptr) : _fall.add(tptr, mptr);
+        gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
+        return pf;
+    }
+
     gpio_t gpio;
     gpio_irq_t gpio_irq;
 
-    FunctionPointer _rise;
-    FunctionPointer _fall;
+    CallChain _rise;
+    CallChain _fall;
 };
 
 } // namespace mbed